bV=parseInt(navigator.appVersion);
dom=(!document.layers && !document.all && bV>=4) ? true : false;
ie4 = (document.all)? true:false;
level1=0;
level2=0;
var pr=0;

function OVER(num, level)
{
	clearTimeout(pr);
	if (level==1)
	{
		level1=num;
		level2=0;
	}
	else 
	if (level==2)
	{
		level2=num;
	}
	
	for (i=0; i<b.length; i++)
	{
		if ((b[i]!=level1) && (b[i]!=level2))
		if (document.getElementById("m"+b[i])) document.getElementById("m"+b[i]).style.visibility="hidden";
	}
	if (document.getElementById("m"+num)) document.getElementById("m"+num).style.visibility="visible";
}

function OUT()
{
	for (i=0; i<b.length; i++)
	eval("document.all.m"+b[i]).style.visibility="hidden";
	clearTimeout(pr);
}
function DELAYS()
{
	pr=setTimeout("OUT()", 1000);
}
function OnFocus(always, object, mode)
{
	if (mode==1)
	{
		if (object.value==always) object.value="";
	}
	else
	{
		if (object.value=="")
		{
			object.value=always;
			 if (always==" Поиск") document.SearchForm.is_keyword.value=0; // только для поиска присваиваем переменную
		}
		else if (always==" Поиск") document.SearchForm.is_keyword.value=1; // только для поиска присваиваем переменную
	}
}

function Search()
{
	document.SearchForm.submit();
}

function Subscribe(mode)
{
//	mode=2;
	re=/^[\w\.\-]+\@[\w\.\-]+/;
	email=document.subscr.email.value;
	if(!re.test(email))
	{
		alert("Неправильный почтовый адрес!");
		return;
	}
	document.subscr.mode.value=mode;
	document.subscr.submit();
}
///////////////////////// Opros
flag_opros=false;
function Checks()
{flag_opros=true;}
function Send(mode)
{
	if (flag_opros || mode==2)
	{
		document.Opinion.senti.value="1";
		document.Opinion.submit();
		W=window.open("/misc/opros.php?lang=1&mode="+mode, "o_ph", "width=600, height=400, left=100, top=100, status=no, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no");
	}
	else alert("Не выбран ни один из вариантов ответа");
}
///////////////////////////////////
function GO(mode)
{
	document.formlogin.mode.value=mode;
	if (mode=="reg")  document.formlogin.action="/registration/";
	if (mode=="send") document.formlogin.action="/registration/?mode="+mode;
	if (mode=="exit") document.formlogin.action="/registration/?reg=11";
	if (mode=="sendpass") document.SendPasswd.submit();
	else document.formlogin.submit();
}
function save()
{
	flag=true;
	re = /^\s*$/;
	re1 = /^[\d]+$/;
	re2 = /^\d+$/;
	re3= /([^<)\s]+@\S+\.[^>(\s]+)/;
	re4 = /^[\d \-\+\(\)]+$/;
	with (document.registration)
	{
		if (re.test(secondname.value))
		{
			button.disabled=false;
			alert("Введите фамилию!");
			secondname.focus();
			return;
		}
		if (re.test(name.value))
		{
			button.disabled=false;
			alert("Введите имя!");
			name.focus();
			return;
		}
		if (re.test(otch.value))
		{
			button.disabled=false;
			alert("Введите отчество");
			otch.focus();
			return;
		}
		if (!re4.test(phone.value)) 
		{
			button.disabled=false;
			alert("Заполните поле \"Телефон\". Принимаются символы от 0 до 9, () и -.");
			phone.focus();
			return;
		}
		if (!re3.test(email.value))
		{ 
			button.disabled=false;
			alert("Введите email");
			email.focus();
			return;
		}
		if (re.test(login.value)) 
		{
			button.disabled=false;
			alert("Введите логин!");
			login.focus();
			return;
		}
		if ((login.value.length<4)) 
		{
			button.disabled=false;
			alert("Логин должен быть более 4");
			login.focus();
			return;
		}
		if (document.registration.pass)
		{
			if (re.test(pass.value)) 
			{
				button.disabled=false;
				alert("Введите пароль!");
				pass.focus();
				return;
			}
			if ((pass.value.length<6)||(pass.value.length>15)) 
			{
				button.disabled=false;
				alert("Пароль должен быть более 6 и менее 15 символов!");
				pass.focus();
				return;
			}
			if (pass.value!=re_passwd.value)
			{
				button.disabled=false;
				alert("Несовпадение паролей");
				re_passwd.focus();
				return;
			}
		}
		submit();
	}
}
function OK(mode)
{
	flag=true;
	re = /^\s*$/;

	if (re.test(document.Data3.name.value))
	{
		alert("Введите имя");
		flag=false;
		return;
	}
	if (re.test(document.Data3.phone.value))
	{
		alert("Введите контактный телефон");
		flag = false;
		return;
	}
	if (mode==2 && document.getElementById("hotel"))
	{
		hotel=document.getElementById("hotel").options[document.getElementById("hotel").selectedIndex].value;
		if (hotel==0)
		{
			alert("Выберите базу отдыха");
			flag=false;
			return;
		}
	}
	if (flag) 
	{
		document.Data3.sent.value="1";
		document.Data3.submit();
	}
}
/////////////// Контакты ////////////////
function createRequestObject() 
{
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer") ro = new ActiveXObject("Microsoft.XMLHTTP");
    else ro = new XMLHttpRequest();
    return ro;
}

var http = createRequestObject();
function goAjax(url)
{
//	alert(url);
    http.open("get", url);
   	http.onreadystatechange = handleResponse;
    http.send(null);
}

function sndReq(idm) 
{
	lang=document.Lang.lang.value;
	url='/misc/contacts.php?reg='+idm+"&lang="+lang;
	goAjax(url);
}

function handleResponse()
{
    if(http.readyState == 4)
	{
        var response = http.responseText;
        var update = new Array();
        if(response.indexOf('|' != -1)) 
		{
            update = response.split('|');
//			alert(update[0]+"---"+update[1])
			if (update[0] && update[1] && document.getElementById(update[0])) document.getElementById(update[0]).innerHTML = update[1];
			else
			{
				document.getElementById("dealer_out").style.display="inline";
				document.getElementById("cross").style.display="inline";
	            document.getElementById("dealer").innerHTML = update[0];
	            document.getElementById("tit").innerHTML = update[1];
			}
        } 
    }
}

function gotoRegion(region)
{
	switch(region)
	{
		case 'cherkasi': sndReq(25); break;	
		case 'chernigov': sndReq(26); break;	
		case 'chernovci': sndReq(23); break;	
		case 'dnepropetrovsk': sndReq(4); break;	
		case 'doneck': sndReq(5); break;	
		case 'harkov': sndReq(20); break;	
		case 'herson': sndReq(21); break;	
		case 'hmelnicki': sndReq(22); break;	
		case 'ivanofrankovsk': sndReq(9);	break;	
		case 'jitomir': sndReq(6); break;	
		case 'kirovograd': sndReq(10); break;	
		case 'kyiv': sndReq(1); break;	
		case 'luck': sndReq(3); break;	
		case 'lugansk': sndReq(12); break;	
		case 'lvov': sndReq(13); break;	
		case 'nikolaev': sndReq(14); break;	
		case 'odessa': sndReq(15); break;	
		case 'poltava': sndReq(16); break;	
		case 'rovno': sndReq(17); break;	
		case 'simferopol': sndReq(11); break;	
		case 'summi': sndReq(18); break;	
		case 'ternopol': sndReq(19); break;	
		case 'ujgorod': sndReq(7); break;	
		case 'vinnica': sndReq(2); break;	
		case 'zaporoje': sndReq(8); break;	
		default: sndReq(1); 
	}
}

function SendResume()
{
	re = /^\s*$/;
	with (document.Resume)
	{
		if (re.test(fio.value))
		{
			alert("Введите фамилию!");
			fio.focus();
			return;
		}
		if (re.test(email.value))
		{
			alert("Введите Ваш email!");
			email.focus();
			return;
		}
		if (re.test(opportunity.value))
		{
			alert("Введите предпочитаемую должность!");
			opportunity.focus();
			return;
		}
		submit();	
	}
}

function AllPhotos(id, mode, lang, event)
{
	document.getElementById("allphotos2").innerHTML="";
	url="/misc/photos.php?g_id="+id+"&mode="+mode+"&lang="+lang;
	goAjax(url);

	if (!event) event=window.event;
	coorY=event.clientY;
	var pW = getPageSize();
//	document.documentElement.scrollLeft = 10000;
	var x = document.body.clientWidth;
//	document.documentElement.scrollLeft = 0;
	var y = document.body.scrollTop;
	document.getElementById("overlay").style.width = x+"px";
	document.getElementById("overlay").style.height = pW[1]+"px";
	document.getElementById("overlay").style.display = "inline";

	WidthPhotos=x-500;
	TopPhotos=coorY+y-300;
//	HeightPhotos=pW[1]-500;
	document.getElementById("allphotos").style.top = TopPhotos+"px";
	document.getElementById("allphotos").style.left = "250px";
	document.getElementById("allphotos").style.width = WidthPhotos+"px";
//	document.getElementById("allphotos").style.height = HeightPhotos+"px";
	document.getElementById("allphotos").style.display = "inline";
}

function getPageSize()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	{
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight)// all except Explorer
	{
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight) pageHeight = windowHeight;
	else pageHeight = yScroll;

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth) pageWidth = windowWidth;
	else pageWidth = xScroll;

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function Resize(event)
{
	if (document.getElementById("overlay").style.display=="inline")
	{
		var pW = getPageSize();
		document.documentElement.scrollLeft = 10000; // Определяем размер скролла
		var x = document.documentElement.scrollLeft+document.body.clientWidth;;
		document.documentElement.scrollLeft = 0; // И возвращаем скроллер обратно в ноль

		document.getElementById("overlay").style.width = x+"px";
		document.getElementById("overlay").style.height = pW[1]+"px";
	}
}
///////////////////////////////////////////////////////////////////////////
function hides(num)
{
	Hidden("apart2", "none");	
	if (num==2)
	{
		document.getElementById("overlay").style.display='none';
		document.getElementById("allphotos").style.display='none';		
	}
	else
	{
		document.getElementById("dealer_out").style.display='none';
		document.getElementById("cross").style.display='none';
	}
}
function SENT()
{
	flag=1;
	if (document.Avia.aviafrom.value=="")
	{
		alert('Не заполнено поле "Откуда"');
		document.Avia.aviafrom.focus();
		flag=0;
		return;
	}
	if (document.Avia.aviato.value=='')
	{
		alert('Не заполнено поле "Куда"');
		document.Avia.aviato.focus();
		flag=0;
		return;
	}
	if (document.Avia.numberadults.value=="")
	{
		alert('Не заполнено поле "Количество взрослых"');
		document.Avia.numberadults.focus();
		flag=0;
		return;
	}
	if (document.Avia.numberchild.value=="")
	{
		alert('Не заполнено поле "Количество детей"');
		document.Avia.numberchild.focus();
		flag=0;
		return;
	}
	if (document.Avia.name.value=="")
	{
		alert('Не заполнено поле "Фамилия, Имя"');
		document.Avia.name.focus();
		flag=0;
		return;
	}
	if (document.Avia.phone.value=="")
	{
		alert('Не заполнено поле "Контактный телефон"');
		document.Avia.phone.focus();
		flag=0;
		return;
	}
	if (document.Avia.email.value=="")
	{
		alert('Не заполнено поле "Электронный адрес"');
		document.Avia.email.focus();
		flag=0;
		return;
	}
	if (flag==1)
	{
		document.Avia.sent.value=1;
		document.Avia.submit();
	}
}
function SENT_FEEDBACK()
{
	flag=1;
	re3 = /([^<)\s]+@\S+\.[^>(\s]+)/;
	if (!re3.test(document.Order.email.value))
	{
		alert('Введите адрес электронной почты');
		document.Order.email.focus();
		flag=0;
		return;
	}
	if (document.Order.info.value=='')
	{
		alert('Не заполнено поле "Текст сообщения"');
		document.Order.info.focus();
		flag=0;
		return;
	}
	if (flag==1)
	{
		document.Order.sent.value=1;
		document.Order.submit();
	}
}
function SENT_QUESTION()
{
	flag=1;
	if (document.Opinions.name.value=="")
	{
		alert('Не заполнено поле "Имя"');
		document.Opinions.name.focus();
		flag=0;
		return;
	}
	if (document.Opinions.mess.value=='')
	{
		alert('Поле "Вопрос" пустое');
		document.Opinions.mess.focus();
		flag=0;
		return;
	}
	if (flag==1)
	{
		document.Opinions.sent.value=1;
		document.Opinions.submit();
	}
}
function ShowImg(img, id, event, mode, id2)
{
	if (mode=="") mode="a";
	goAjax("/misc/apartaments.php?id="+id+"&mode="+mode);
	if (mode=="a_c") folder="apartaments_c";
	else folder="apartaments";
	if (mode=="a_c") id=id2;
	document.getElementById("apart").innerHTML='<img src="/img/'+folder+'/'+id+'/big/'+img+'"/>';
	if (!event) event=window.event;
	if (document.body.scrollTop>0) scrolls=document.body.scrollTop;
	else if (document.documentElement.scrollTop>0) scrolls=document.documentElement.scrollTop;
	else scrolls=0;
	coorX=event.clientX-100;
	coorY=event.clientY+scrolls-200;
	document.getElementById("apart2").style.left=coorX+"px";
	document.getElementById("apart2").style.top=coorY+"px";
	Hidden("apart2", "inline");
}
function Hidden(id, style)
{
	if (document.getElementById(id))
	{
		if (style == "table-row")
		{
				if (ie4) document.getElementById(id).style.display="inline";
				else document.getElementById(id).style.display=style;
		}
		else
		document.getElementById(id).style.display=style;
	}
}
function hideDhtmlPop(num)
{
	Hidden("otkr", "none");
}