myWidth = 0, myHeight = 0;
myTop = 0, myLeft = 0;

$(document).ready(function(){
	$(window).resize(function(){
		checkWideScreen();
	});
	checkWideScreen();
});
function checkWideScreen(){
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    myTop = window.pageYOffset;
    myLeft = window.pageXOffset;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    myTop = document.documentElement.scrollTop;
    myLeft = document.documentElement.scrollLeft;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    myTop = document.body.scrollTop;
    myLeft = document.body.scrollLeft;
  }
  $("#res").attr("width",myWidth > 1400 ? "1400px" : (myWidth >= 1000 ? myWidth + "px" : "1000px"));
  if ($("#res").attr("offsetHeight") < myHeight) $("#res").css("height",myHeight + "px");
}

var dt = dc = dz = "";
var dest = [];
var tmp = "";
function getHotels(type,val)
{
	if (type == "city")
	{
		dt = val;
		if (dz) $("#_" + dz[0] + "_" + dz[1]).toggleClass("lsel");
		$("#_" + type + "_" + val).toggleClass("lsel");
		dz = [type,val];
	}
	$("#res2").html("");
	$("#res4").html("");
	if (dt) $.getScript("/ajax.php?a=hl&d=" + dt,setHotels);
	return false;
}
function setHotels()
{
	tmp = "";
	if (dest && dest[0])
	{
		for (var x in dest[0])
		{
			tmp += "<li><a href='" + dest[0][x][0] + "'>" + dest[0][x][1] + " 5*</a></li>";
		}
	}
	if (tmp)
	{
		$("#res1").removeClass("circNumb2");
		$("#res1").addClass("circNumb");
		tmp = "<h2 class=pd8>*****</h2><ul class='listCity not'>" + tmp + "</ul>";
		$("#res2").html(tmp);
	}
	else
	{
		$("#res1").removeClass("circNumb");
		$("#res1").addClass("circNumb2");
		$("#res2").html("<br>Отелей не найдено");
	}

	tmp = "";
	if (dest && dest[1])
	{
		for (var x in dest[1])
		{
			tmp += "<li><a href='" + dest[1][x][0] + "'>" + dest[1][x][1] + " 4*</a></li>";
		}
	}
	if (tmp)
	{
		$("#res1").removeClass("circNumb2");
		$("#res1").addClass("circNumb");
		tmp = "<h2 class=pd8>****</h2><ul class='listCity not'>" + tmp + "</ul>";
		if (dest[0]) $("#res4").html(tmp);
		else $("#res2").html(tmp);
	}
	else if (!dest[0])
	{
		$("#res3").removeClass("circNumb");
		$("#res3").addClass("circNumb2");
		$("#res4").html("<br>Отелей не найдено");
	}
}
function expList(type,val)
{
	if (dc && (dc[0] != type || dc[1] != val) && !$("#" + dc[0] + "_" + dc[1]).hasClass("hid"))
	{
		$("#" + dc[0] + "_" + dc[1]).toggleClass("hid");
		$("#_" + dc[0] + "_" + dc[1]).toggleClass("lsel");
	}
	$("#" + type + "_" + val).toggleClass("hid");
	$("#_" + type + "_" + val).toggleClass("lsel");
	dc = [type,val];
	return false;
}
function openHOrder(el)
{
	window.open(el.href+"?ref=" + escape(location.href),el.target,"left=" + ((myWidth >> 1) - 295) + ",top=" + ((myHeight >> 1) - 185) + ",scrollbars=yes,width=590,height=470,resizable=no,toolbar=0,location=0,status=0,menubar=0,directories=0").focus();
	return false;
}
function openAOrder(el)
{
	window.open(el.href+"?ref=" + escape(location.href),el.target,"left=" + ((myWidth >> 1) - 350) + ",top=" + ((myHeight >> 1) - 250) + ",scrollbars=yes,width=700,height=600,resizable=no,toolbar=0,location=0,status=0,menubar=0,directories=0").focus();
	return false;
}
function openForm()
{
//	window.open("/sendmail.phtml?ref=" + escape(location.href),"_form","left=" + ((myWidth >> 1) - 250) + ",top=" + ((myHeight >> 1) - 200) + ",toolbar=no,bar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=300").focus();
	document.images["_cap"].src = "/captcha.php?id=" + Math.random();
	var tmp = document.getElementById("send_form");
	checkWideScreen();
	tmp.style.left = (myLeft + (myWidth >> 1) - 265) + "px";
	tmp.style.top = (myTop + (myHeight >> 1) - 160) + "px";
	tmp.style.display = "block";
	return false;
}
	function CheckForm(){
	  var error=0;
	  var mf=document.forms['zakaz'];
	    if (mf.fio.value=='' && error==0) {
	      alert('Заполните, пожалуйста, поле \"ФИО\"');
		  mf.fio.focus();
		  error=1;
	    }
		if (mf.email.value=='' && error==0) {
	      alert('Укажите, пожалуйста, \"E-mail\"');
		  mf.email.focus();
		  error=1;
	    }
		if (mf.about.value=='' && error==0) {
	      alert('Введите, пожалуйста, текст сообщения');
		  mf.about.focus();
		  error=1;
	    }
		if (error==0 && mf.phone.value=='' && (isEmail() == false)){
			error=1;
			mf.email.focus();
		}
		if (!mf.code.value.match(/^\d{4}$/) && error==0) {
	    alert('Введите, пожалуйста, четыре цифры кода');
		  mf.code.focus();
		  error=1;
	    }
	    if (error==0) {
	       //mf.submit();
				script = document.createElement("script");
				script.src = "/sendmail.phtml?fio="+mf.fio.value+"&email="+mf.email.value+"&ref="+escape(location.href)+"&code="+mf.code.value+"&phone="+mf.phone.value+"&about="+mf.about.value;
				document.body.appendChild(script);
	    }
	 }
	 function isEmail() {

		var strEmail = document.forms[0].elements("email").value;
		//Данная функция проверяет строку strEmail на соответствие формату почтового адреса.
		//При этом строка разбивается на составные части:
		//имя_пользователя@сервер

		if (strEmail=="") {
			alert("Введите, пожалуйста, E-mail");
			document.forms[0].elements("email").focus();
			return false;
		}

		var letters="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		var numbers="0123456789";

		var name="";
		var server="";
		var strings=new Array();

		//разделяем строку на имя пользователя и имя сервера
		strings=strEmail.split("@");
		if (strings.length==1) {
			alert("Ошибка: e-mail должен содержать символ @");
			document.forms[0].elements("email").focus();
			return false;
		} else if (strings.length==2) {
			name=strings[0];
			server=strings[1];
		} else {
			alert("Ошибка: e-mail не может содержать более одного символа @");
			document.forms[0].elements("email").focus();
			return false;
		}

		//проверка имени на допустимость символов
		if (!isValid(name,letters+numbers+"._-")) {
			alert("Недопустимые символы в имени пользовател\я");
			document.forms[0].elements("email").focus();
			return false;
		}

		//разделяем имя сервера на составные части
		strings=server.split(".");
		if (strings.length<2) {
			alert("Нераспознанный e-mail");
			document.forms[0].elements("email").focus();
			return false;
		}
		//проверяем каждую часть на допустимые символы
		for (i=0;i<strings.length;i++) {
			if (!isValid(strings[i],letters+numbers+"_-")) {
				alert("Нераспознанный e-mail");
				document.forms[0].elements("email").focus();
				return false;
			}
		}

		return true;

	}

	function isValid(what,chars) {
		//проверяет, что все символы из what принадлежат множеству chars
		//если what пустая - ошибка
		while (what.charAt(0)==" ") {
			what=what.substring(1);
		}
		if (what=="") {
			return false;
		}
		bool1=false;
		for (count1=0; (count1<what.length)&&(!bool1);count1++) {
			bool2=false;
			for (count2=0; (count2<chars.length)&&(!bool2);count2++) {
				if (what.charCodeAt(count1)==chars.charCodeAt(count2)) {
					bool2=true;
				}
			}
			if (!bool2) {
				bool1=true;
			}
		}
		return !bool1;
	}





















/* function for news pager by Kovtun Maxim  */
function ShowPage(page) {
i = 1;
while (currentPage = document.getElementById("news_page" + i)) {
	if (currentPage.style.display == "block")
		currentPage.style.display = "none";
	i++;
}
currentPage = document.getElementById("news_page" + page);
currentPage.style.display = "block";
i = 1;

while (currentRefPage = document.getElementById("ref_page" + i)) {
	currentRefPage.style.color = "#605B5B";
	currentRefPage.style.cursor = "pointer";
	currentRefPage.style.textDecoration = "none";

    currentRefPage.style.background = "#C3C8C1";

	i++;
}
currentRefPage = document.getElementById("ref_page" + page);
currentRefPage.style.color = "black";
currentRefPage.style.cursor = "default";
currentRefPage.style.textDecoration = "none";

currentRefPage.style.background = "#7661B2";
}



function openHotelImg()
{
//	window.open("/sendmail.phtml?ref=" + escape(location.href),"_form","toolbar=no,bar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=300").focus();
	//document.images["_cap"].src = "/captcha.php?id=" + Math.random();
	var tmp = document.getElementById("hotel_img");
	checkWideScreen();
	tmp.style.left = (myLeft + (myWidth >> 1) - 300) + "px";
	tmp.style.top = (myTop + (myHeight >> 1) - 240) + "px";
	tmp.style.display = "block";
	return false;
}