
function closeDiv(div) {
	div.parentNode.removeChild(div);
	document.getElementById("div_0").parentNode.removeChild(document.getElementById("div_0"));
}
function sendCallbackRequest(number, name) {
	if (number=="") {
		alert("Введите номер телефона");
	}else{
		closeDiv(document.getElementById("div_phone"));
		sendXmlHttpRequest("../callback.php", scrCallBack, "?phone="+number+"&name="+name, "GET");
	}
}
function scrCallBack() {
	try {
		if (request.readyState == 4) {
			if (request.status == 200) {
				json = eval("(" + request.responseText + ")");
				if (json.status==1) {
					alert("Спасибо, мы перезвоним Вам в ближайшее время");
				}else{
					alert("Извините, произошла ошибка!\nПроверьте правильность ввода номера или попробуйте позже.");
				}
			} else {
				alert("Error:\n" + request.statusText);
			}
		}
	} catch (e) {
		alert('Caught Exception: ' + e.description);
	}
}
function callback(){
	var div_0=document.createElement("DIV");
	div_0.id="div_0";
	div_0.style.width="100%";
	div_0.style.height=document.body.clientHeight+"px";
	div_0.style.position="absolute";
	div_0.style.backgroundColor="black";
	div_0.style.opacity="0.4";
	document.body.appendChild(div_0);
	div_0.style.left="0px";
	div_0.style.top="0px";
	var div=document.createElement("DIV");
	div.id="div_phone";
	div.style.position="absolute";
	div.style.border="1px solid black";
	div.style.backgroundColor="lightgrey";
	div.style.padding="5px";
	div.style.textAlign="center";
	document.body.appendChild(div);
	div.innerHTML="<form action='../callback.php' onsubmit='sendCallbackRequest(document.getElementById(\"phone_number\").value, document.getElementById(\"customer_name\").value);return false;'><fieldset><legend style='font-weight:bold;font-size:16px;'>Обратный звонок</legend><p><b>Занят телефон? Не отвечает консультант?</b></p><p>Укажите Ваш номер телефона и наши сотрудники<br>свяжутся с Вами в самое ближайшее время</p><table><tr><td style='text-align:right;'><label for='phone_number'>Номер телефона:</label></td><td><input type='text' style='text-align:center' id='phone_number'></td></tr><tr><td style='text-align:right;'><label for='customer_name'>Имя:</label></td><td><input type='text' style='text-align:center' id='customer_name'></td></tr></table><br><div><input type='submit' value='ОК' style='float:left;width:50%'><input type='reset' value='Отмена' onclick='closeDiv(document.getElementById(\"div_phone\"));'  style='float:right;width:50%'></div></fieldset></form>";
	div.style.left=screen.width/2-div.clientWidth/2+"px";
	div.style.top=getBodyScrollTop()+screen.height*0.7/2-div.clientHeight/2+"px";
	document.getElementById("phone_number").focus();
}
