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 = di = dc = dy = dz = "";
var dest = [];
var tmp = "";
function getClinics(type,val)
{
	if (type == "spec") dt = val;
	expList(type,val);
	if (dt) $.getScript("/ajax.php?a=cl&d=" + dt,setClinics);
	return false;
}
function setClinics()
{
	tmp = "";
	if (dest)
	{
		for (var x in dest)
		{
			tmp += "<li><a>" + x + "</a><ul class='listZab'>";
			for (var y = 0; y < dest[x].length; y++) tmp += "<li><a href='" + dest[x][y][0] + "'>" + dest[x][y][1] + "</a></li>";
			tmp += "</ul></li>";
		}
	}
	if (tmp)
	{
		$("#resn").removeClass("circNumb2");
		$("#resn").addClass("circNumb");
		tmp = "<ul class='listCity'>" + tmp + "</ul>";
		$("#resl").html(tmp);
	}
	else
	{
		$("#resn").removeClass("circNumb");
		$("#resn").addClass("circNumb2");
		$("#resl").html("Выберите специализацию");
	}
}
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");
	if ($("#" + type + "_" + val).hasClass("hid") || $("#_" + type + "_" + val).hasClass("lsel")) dc = [type,val];
	else dc = [];
	return false;
}
function getResorts(type,val)
{
	if (type == "spec")
	{
		di = val;
		if (dy) $("#_" + dy[0] + "_" + dy[1]).toggleClass("lsel");
		if (dy[1] == val)
		{
			dy = "";
			di = "";
		}
		else
		{
			$("#_" + type + "_" + val).toggleClass("lsel");
			dy = [type,val];
		}
	}
	if (type == "type")
	{
		dt = val;
		if (dz) $("#_" + dz[0] + "_" + dz[1]).toggleClass("lsel");
		if (dz[1] == val)
		{
			dz = "";
			dt = "";
		}
		else
		{
			$("#_" + type + "_" + val).toggleClass("lsel");
			dz = [type,val];
		}
	}
	if (dt || di) $.getScript("/ajax.php?a=rl&d=" + di + "&t=" + dt,setResorts);
	return false;
}
function setResorts()
{
	tmp = "";
	if (dest)
	{
		for (var x in dest)
		{
			tmp += "<li><a>" + x + "</a><ul class='listZab'>";
			for (var y = 0; y < dest[x].length; y++) tmp += "<li><a href='" + dest[x][y][0] + "'>" + dest[x][y][1] + "</a></li>";
			tmp += "</ul></li>";
		}
	}
	if (tmp)
	{
		$("#resn").removeClass("circNumb2");
		$("#resn").addClass("circNumb");
		tmp = "<ul class='listCity'>" + tmp + "</ul>";
		$("#resl").html(tmp);
	}
	else
	{
		$("#resn").removeClass("circNumb");
		$("#resn").addClass("circNumb2");
		$("#resl").html("Курортов не найдено");
	}
}
function openProgramm(el)
{
	window.open(el.href,el.target,"left=" + ((myWidth >> 1) - 210) + ",top=" + ((myHeight >> 1) - 250) + ",scrollbars=yes,width=420,height=500,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","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 openHOrder(el)
{
	window.open(el.href,el.target,"left=" + ((myWidth >> 1) - 295) + ",top=" + ((myHeight >> 1) - 135) + ",scrollbars=yes,width=590,height=470,resizable=no,toolbar=0,location=0,status=0,menubar=0,directories=0").focus();
	return false;
}
function openPha(id,w,h)
{
	window.open("/phalbum.php?id=" + id,"_pha","scrollbars=yes,width=" + ((w ? w : 462) + 20) + ",height=" + ((h ? h : 300) + 50) + ",resizable=no,toolbar=0,location=0,status=0,menubar=0,directories=0").focus();
	return false;
}
function nextPha(el)
{
	document.images["php"].src = "/ph.php?pic=" + (el.href.substr(0,7) == "http://" ? el.href.substr(el.href.substr(7).indexOf("/") + 8) : el.href) + "&h=250";
	tmp = $("#phList").find("a.pgrs");
	if (tmp.size()) for (x = 0; x < tmp.size(); x++) tmp.get(x).className = "pgr";
	var next_id = 0;
	tmp = $("#phList").find("a.pgr");
	if (tmp.size()) for (x = 0; x < tmp.size(); x++)
	{
		if (!next_id) next_id = tmp.get(x).id.substr(4);
		if (tmp.get(x).id == el.id && x < tmp.size() - 1) next_id = tmp.get(x + 1).id.substr(4);
	}
	if (next_id) document.images["php"].setAttribute("pha",next_id);
	el.className = "pgrs";
	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 (!mf.code.value.match(/^\d{4}$/) && error==0) {
	    alert('Введите, пожалуйста, четыре цифры кода');
		  mf.code.focus();
		  error=1;
	    }
	    if (error==0) {
//		document.getElementById('send_form').style.display = 'none'
	       mf.submit();
hs.close();
//				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 openHotelImg()
{
     var tmp = document.getElementById("hotel_img");
    if (!tmp) return false;
     checkWideScreen();
     tmp.style.left = (myLeft + (myWidth >> 1) - 300) + "px";
     tmp.style.top = (myTop + (myHeight >> 1) - 240) + "px";
     tmp.style.display = "block";
     return false;
}

/* 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.className = "pgj";
     i++;
}
currentRefPage = document.getElementById("ref_page" + page);
if (currentRefPage)
{
	currentRefPage.className = "pgjs";
}
}

function ShowDumbPage(page)
{
	ShowPage(page);
	var tmp = document.getElementById("hotel_img");
	if (!tmp) return false;
	checkWideScreen();
	var tt = (myTop + (myHeight >> 1) - 200);
	tmp.style.top = tt + "px";
	tmp.style.left = (myLeft + (myWidth >> 1) - 310) + "px";
	tmp.style.display = "block";
//	if (tt + tmp.offsetHeight > myTop + myHeight - 30) tmp.style.top = (myTop + myHeight - 30 - tmp.offsetHeight) + "px";
	return false;
}

var currentSpecTour=1;
function ShowSpecTour(tour_id, is_manual_change) {
	
	if(tour_id!=currentSpecTour) {
		if(is_manual_change)
			clearInterval(intervalId);
		
		$("#tour"+currentSpecTour).fadeOut("fast",
			function(){
				$("#tour"+tour_id).fadeIn("fast");
			}
		);	
		$("#p_tour"+currentSpecTour).toggleClass("current");
		$("#p_tour"+tour_id).toggleClass("current");
		
		currentSpecTour = tour_id;
	}
	return false;
}
function NextTour() {
	if(currentSpecTour==num_pages)
		next = 1;
	else
		next = currentSpecTour+1;
	
	ShowSpecTour(next, false);
}
