var flagus = 0;
function onlBody(){
var Height = $("CityList").clientHeight
$("IFrameCityList").style.height = Height

//$('HeightC').style.height = $('cHeight').clientHeight
$('helpess1').style.height = $('helpes1').clientHeight
$('helpess1').style.width = $('helpes1').clientWidth
$('helpess2').style.height = $('helpes2').clientHeight
$('helpess2').style.width = $('helpes2').clientWidth

}
function onclickbody(){
var oppens = $("CityList").style
var frame = $("IFrameCityList").style
if(flagus == 1){
oppens.visibility = 'hidden'
frame.visibility = 'hidden'
flagus = 0;
if(selectCountry == 0)$('SelectCity').value = "";
}}

function flaaag(){flagus = 1;}
function opennli(){flagus = 0;}

function HiddenCityList(){
$("CityList").style.visibility = 'hidden';
$("IFrameCityList").style.visibility = 'hidden';
$('SelectCity').value = "";
}

var selectCountry = null;
function clicked(ids){
selectCountry = 1;
var alls = ids.innerText?ids.innerText:ids.textContent;
$('SelectCity').value = alls
var oppens = $("CityList").style
var frame = $("IFrameCityList").style
oppens.visibility = 'hidden'
frame.visibility = 'hidden'
$("quickSearch").disabled = false;
}

function openwindow(){
var oppens = $("CityList").style
var frame = $("IFrameCityList").style
if(oppens.visibility == "visible"){oppens.visibility = 'hidden';frame.visibility = 'hidden'}
else{selectCountry = 0;GetLetterCity();}
}

function openhelp(helpes){
var heelp = $(helpes).style
if(heelp.visibility == "visible") heelp.visibility = 'hidden'	
else heelp.visibility = 'visible'	
}

function resizeframe(helpess){
var heelpn = $(helpess).style
if(heelpn.visibility == "visible") heelpn.visibility = 'hidden'
else heelpn.visibility = 'visible'
}

function loadAllCountry(el){
document.forms[0].action = "Country-world.html";
document.forms[0].submit();
return true;
}
var elements = "";
function createElement(newF,key,val){
	var newH = $(key);
	if(!newH){
		/*@cc_on @if (@_jscript)  
		var newH = document.createElement("<input id='"+key+"' name='"+key+"'>");  
		@else */  
		newH = document.createElement("input"); 
		newH.name = key; /* @end @*/ 
		newH.type = 'hidden'; 
		newF.appendChild(newH);
	}
	newH.value = val; 
// alert("createElement: " + newH.name + "  " + val);	
//elements += newH.name + "  " + val + "\n";
}

function CheckCountryCity(){
var cn = getCnCode();
var ct = $v("SelectCity");

if(cn==""){alert($("msgChoiceCountry").value);return false;}
if(ct==""){alert($("msgChoiceCity").value);return false;}
return true;
}


function toPostQuickSearch(newF){
SaveCookie();
if(!CheckCountryCity())	return false;	
if(!CheckADDate())	return false;	

elements = "";

createElement(newF,"ControlForm:book_HotelClass0","True");
createElement(newF,"ControlForm:book_HotelClass1","True");
createElement(newF,"ControlForm:book_HotelClass2","True");
createElement(newF,"ControlForm:book_HotelClass3","True");
createElement(newF,"ControlForm:book_HotelClass4","True");
createElement(newF,"ControlForm:book_HotelClass5","True");

var cn = getCnCode();
createElement(newF,"ControlForm:_CountryCode",cn);// el.options[el.selectedIndex].value);
var ct = $v("SelectCity");
createElement(newF,"ControlForm:_City",ct);// $("SelectCity").value);
createElement(newF,"ControlForm:_ArrivalDate",$("_ArrivalDate").value);
createElement(newF,"ControlForm:_DepartureDate",$("_DepartureDate").value);
//alert("CN: "+ cn + "\nCT: " + ct + "\nAD: " + $("_ArrivalDate").value + "\nDD: " + $("_DepartureDate").value);
//el = $("CountOfPerson");
createElement(newF,"ControlForm:_RoomType",$v("CountOfPerson"));// el.options[el.selectedIndex].value);
//el = $("CountOfRoom");
createElement(newF,"ControlForm:_AmountOfRooms",$v("CountOfRoom"));// el.options[el.selectedIndex].value);
createElement(newF,"ControlForm:_CurrencyCode","");
createElement(newF,"ControlForm:_Language",$("Lang").value);
newF.action = "/hotels/search.aspx";

// showValues(newF);
//alert("toPostQuickSearch:\n" + elements);

var ws = $("__VIEWSTATE");
if(ws == null){var _ws = document.getElementsByName("__VIEWSTATE");ws = _ws[0]}
if(ws){ws.name = "_VIEW_STATE";ws.id = "_VIEW_STATE"}
newF.submit();
if(ws){ws.name = "__VIEWSTATE";ws.id = "__VIEWSTATE"}
return true;
}

function showValues(newF){}

function get_wh(){
var frameHeight=640;
if (self.innerHeight)frameHeight = self.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight)	frameHeight = document.documentElement.clientHeight;
else if (document.body)	frameHeight = document.body.clientHeight;
return frameHeight}

function getBodyScrollTop(){
return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop)}

function getBodyScrollLeft(){
return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft)}

function onchangeCountry(){ 
SaveCookie();
// lcCountry.Set_selsug();
//var id = lcCountry.selsug.split(',');
var cn = getCountryName();
cn = cn.trim().toLowerCase();
//alert("onchangeCountry(): " + cn);
///// var sc = $('SelectQuickCountry');
var l = "/"+ cn + "+cities";
//// var l = "ListCity.aspx?country="+sc.options[sc.selectedIndex].value + "&allcity=1";
/////// var l = "/catalog/ru/ListCity.aspx?country="+cn;
// var l = "listcity.aspx?country="+cn;
var a = $("aCityList");
if(a.click){a.href = l;a.click();}
else{
var newF = document.createElement("form"); 
newF.action = l;
newF.method = 'GET'; 
// createElement(newF,"country",cn);
document.getElementsByTagName('body')[0].appendChild(newF); 
newF.submit(); 
}}		 

function LoadSearchForm(){onSetPeriod()}
//addLoadEvent(LoadSearchForm);

function GetParamForCookies(){
    var params = 
        'RoomType=' + $v("CountOfRoom") + '&'+ 'AmountOfRooms='+ $v("CountOfPerson") + '&'+
  		'ArrivalDate=' + $v("_ArrivalDate")+'&'+ 'DepartureDate=' + $v("_DepartureDate") + '&'+
  		'VisitorID=' + $v("VisitorID");
//alert("GetParamForCookies(): " + params);  		
  	return	params;
}

function GetParamForCookiesEx(){
    var params = 'Country='+ getCountryCode() + ";" + $v("cbInputText") +
                 '&City=' + $v("SelectCity") + 
                 '&Cities=' + getCountryName()+ ";" + $v("cbInputTextCities");
  	return	params;  		
}

function SaveCookie(){
    deleteCookie("search_cookie");
    setCookie("search_cookie",GetParamForCookies());
    setCookie("index_cookie",GetParamForCookiesEx());
//alert("SaveCookie()\n"+document.cookie);    
}
function unloadPage(){SaveCookie();return true}
	    
function s(n,v){
var el = $(n);
v = String(v).toUpperCase();
if(el){
 v = v.trim().toLowerCase()
 for(j=0;j<el.options.length;j++)
 if(String(el.options[j].value).trim().toLowerCase() == v){el.selectedIndex=j;break}
}}

//function Set_Progress(f){
//        if(f){
//            var d = $("yrProgress");
//            if(d.style.display!="") d.style.display="";
//            Timer_Progress = window.setTimeout('PutStripe()',TimeReit);
//        }
//        else if(Timer_Progress != null) 
//            window.clearTimeout(Timer_Progress);
//	}

var timer_loadPage;
function onloadPage(){
    Timer_Progress = window.setTimeout('loadPage()',100);
}

function loadPage(){
if(isCook=="yes"){
    var cookie = getCookie("search_cookie");
//    alert("cookie:\n" + cookie);
    if(cookie){
        var ps = cookie.split("&");
        for(ii=0;ii<ps.length;ii++){
            var p = ps[ii].split("=");
            if(p.length>1){
                var f = String(p[0]).toLowerCase()
                if(f == "roomtype") RoomType = p[1];
                else if(f == "amountofrooms") AmountOfRooms = p[1];
                else if(f == "arrivaldate") ArrivalDate = p[1];
                else if(f == "departuredate") DepartureDate = p[1];
                else if(f == "visitorid") $v("VisitorID",p[1]);
	        }
        }
    }
    var cookie = getCookie("index_cookie");
//    alert("index_cookie:\n" + cookie);
    if(cookie){
//window.status = cookie;
        var ps = cookie.split("&");
        for(ii=0;ii<ps.length;ii++){
            var p = ps[ii].split("=");
            if(p.length>1){
                var f = String(p[0]).toLowerCase()
                //if(f == "countrycode"){ setCountryCode(p[1])}
                //else if(f == "countryname"){ $v("cbInputText",p[1]);}
                //else 
		if(f == "city"){ $v("SelectCity", p[1])} 
                else if(f == "country"){ setCountry(p[1])} // $v("cbInputTextCities",p[1]);}
                else if(f == "countrynm"){ setCountryNm(p[1])}
                else if(f == "cities") { setCities(p[1])}
	        }
        }
    }
}
onSetPeriod();
return true;
}

function setOnUnloadPage(){               
    for(var i=0; i<document.links.length; i++){
        link = document.links[i];
        if(!link.onclick) link.onclick = "unloadPage();return true"}
}

function str_replace ( search, replace, subject ) {
var result = ""; var prev_i = 0;
for (i = subject.indexOf(search); i > -1; i = subject.indexOf(search, i)) {
result += subject.substring(prev_i, i);
result += replace;
i += search.length;
prev_i = i;
}
return result + subject.substring(prev_i, subject.length);
}
