

var jsBase = "http://www.teztour.com";
var addition="?a="+(new Date()).getTime();
var CountrySelectId=0;
var RegionSelectId=0;
var HotelSelectId=0;
var HotelPansionSelectId=0;

function xloadJs(uri) {
// alert(uri);
  if ((uri!=null) &&(uri.length>4) ) {
	var el2=document.getElementById("jsElement");
	if (el2!=null) {
		var el1 = el2.parentNode;
		var el3 = document.createElement("script");
		el3.src=jsBase+uri+addition;
		el3.id = "jsElement";
		if (el2!=null) {
			el1.removeChild(el2);
		}
		el1.appendChild(el3);
	}
  }
}
function replaceReferenceSelect(cn) {
//	alert("cn="+cn);
	var doNextStep = false;

  if ((cn!=null) && (cn.length>1)){
	eval(cn+"SelectId=0;");
	var clist = null;
	eval("clist = "+cn+"List;");
	var el = document.getElementById(cn+"Select");
	if (el!=null) {
		while (el.firstChild)
		 {
		    el.removeChild(el.firstChild);
		 };

		
//		alert("cn="+cn+" def.="+clist["defaultId"]);
//		alert("null? "+(clist["defaultId"]==null));
//		alert("isNaN? "+(isNaN(clist["defaultId"])));
		if ((clist["defaultId"]==null) || (clist["defaultId"].length==0) || (isNaN(clist["defaultId"]))) {
			var el2 = document.createElement("option");
			var el3 = document.createTextNode("-- all --");
			el2.value="";
			el2.appendChild(el3);
			el.appendChild(el2);
		}

		var s='';
		for (var name in clist) {
			var index = name.indexOf("_");
			if (index>0) {
				var id = name.substring(index+1, name.length );
				var el2 = document.createElement("option");
				var el3 = document.createTextNode(clist[name]);
				el2.value=id;
//				s=s+" id="+id;
				el2.appendChild(el3);
				el.appendChild(el2);
				if (id==clist["defaultId"]) {
					el2.selected=true; 
					doNextStep = true;
					eval(cn+"SelectId=id;");
				}
			}
		}
	}
	if (cn=="Region") { doNextStep=true; }
	if (doNextStep) { 
		xupdateSelect(cn+"Select", clist["nextClassName"]+"Select", clist["nextClassPrefix"], ""); 
	}
  }
}
function xupdateSelect(cns, cnext, cnextpref, defval) {
//	alert("cns="+cns+" defval="+defval);

//	alert("id="+id);
	if (cnext=="CountrySelect") {
		xloadJs("/ssi/include/ajax/site_lv/countries.js");
	} else {
		var el = document.getElementById(cns);
		var id = el[el.selectedIndex].value;
//		alert("id="+id);
		if (id!="") {
			xloadJs("/ssi/include/ajax/site_lv/"+cnextpref+"/"+id+".js");
		} else {
			if (cns=="RegionSelect") {
				var cns2="CountrySelect";
				el = document.getElementById(cns2);
				id = el[el.selectedIndex].value;
//				alert("id="+id);
				xloadJs("/ssi/include/ajax/site_lv/"+cnextpref+"/"+id+".js");
			}
		}
	}
}
var xId = null;
xId = setTimeout("xloadCountry()", 200);
function xloadCountry() {
	clearTimeout(xId);
	var el = document.getElementById("HotelSelect");
//	alert(el);
	if (el==null) {
		xId = setTimeout("xloadCountry()", 200);
	} else {
		var f = document.getElementById('tourSearchForm');
//		alert(f);
		if (f!=null) {
			updateStayType(f);
		}
		xloadJs("/ssi/include/ajax/site_lv/cities.js");
	}
}
function updateStayType(f) {
	var adu =f.adultCount.value;
	var chi =f.childCount.value;
	if (adu==null) {adu=2;}
	if (chi==null) {chi=2;}
	
	var ans= 14356;
	if ((adu==2) && (chi==0)) { ans=2; }
	if ((adu==1) && (chi==0)) { ans=1; }
	if ((adu==3) && (chi==0)) { ans=3; }
	if ((adu==1) && (chi==1)) { ans=14317; }
	if ((adu==1) && (chi==2)) { ans=14357; }
	if ((adu==2) && (chi==2)) { ans=14356; }
	if ((adu==3) && (chi==1)) { ans=21347; }
	if ((adu==3) && (chi==2)) { ans=26274; }
/*
<option value="2"
selected
>DBL</option>
<option value="1"
>SGL</option>
<option value="3"
>DBL+EXB</option>
<option value="14317"
>SGL+CHD</option>
<option value="14357"
>SGL+2CHD</option>
<option value="14258"
>DBL+CHD</option>
<option value="14356"
>DBL+2CHD</option>
<option value="21347"
>DBL+EXB+ CHD</option>
<option value="26274"
>TRPL+2CHD</option>
*/
	f.hotelStayTypeId.value=ans;
//	alert(f.childAge2.style.visibility);
//	alert(document.getElementById("childAge1Div").style.visibility);
	document.getElementById("childAge2").style.visibility = (chi<2) ? "hidden" : "visible" ;
	document.getElementById("childAge1").style.visibility = (chi<1) ? "hidden" : "visible" ;
	document.getElementById("childAge1Div").style.visibility = (chi<1) ? "hidden" : "visible" ;
}

