
var ctrlhotel = new function (){
	this.opcode = "";
	this.optype = "";

	this.setOpCode = function (code)	{	this.opcode = code;	};
	this.setOpType = function (type)		{	this.optype = type;		};
	this.dropCountry = function (){
		ctrlhotel.setOpCode($("cboContinent").value);
		ctrlhotel.setOpType("country");
		ctrlhotel.drowdorp();
	};

	this.dropCity = function (){
		ctrlhotel.setOpCode($("cboCountry").value);
		ctrlhotel.setOpType("city");
		ctrlhotel.drowdorp();
	};

	this.dropHotel = function (){
		ctrlhotel.setOpCode($("cboCity").value);
		ctrlhotel.setOpType("hotel");
		ctrlhotel.drowdorp();
	};

	this.drowdorp  = function (){	
		var optype = this.optype;
		var Path = "opcode="+this.opcode+"&optype="+this.optype;

		var myurl = "/hotelcontent/hotels/hotel_controller.php?act=dropdown", http = new getXMLHTTPRequest();
		http.onreadystatechange = function() {if (http.readyState != 4) { return; }
			var mytext = http.responseXML;
			switch(optype) {
				case "continent" :		
					$("cboContinent").length = 1;		
					$("cboCountry").length = 1;		
					$("cboCity").length = 1;	
					$("cboHotel").length = 1;		
				break;
				case "country" :			
					$("cboCountry").length = 1;		
					$("cboCity").length = 1;	
					$("cboHotel").length = 1;		
				break;
				case "city" :					
					$("cboCity").length = 1;				
					$("cboHotel").length = 1;		
				break;		
				case "hotel" :					
					$("cboHotel").length = 1;				
				break;	
			}

			var obj = mytext.getElementsByTagName("Code");

			for(i=0; i<obj.length; i+=1){				
				var data = obj[i];
				var Code = data.firstChild.nodeValue;
			//	prompt("",Code);
				var LongName = mytext.getElementsByTagName("LongName")[i].firstChild.nodeValue;
				var objOption = new Option(LongName, Code);
				switch(optype) {
					case "continent" :		$("cboContinent").options[i] = objOption;		break;
					case "country" :			$("cboCountry").options[i] = objOption;			break;
					case "city" :					$("cboCity").options[i] = objOption;				break;			
					case "hotel" :				$("cboHotel").options[i] = objOption;				break;			
				}
			}
		};

		http.open("POST", myurl, true); http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http.send(Path+"&"+new Date().getTime());

	};

	this.searchHotel  = function (){
		//Get value==========
		cboContinent=$("cboContinent").value;
		cboCountry=$("cboCountry").value;
		cboCity=$("cboCity").value;
		cboHotel=$("cboHotel").value;

		//Check error=========
		if(cboContinent=="" || cboContinent=="NONE"){	alert("Please Select Continent");		return false;		}else
		if(cboCountry=="" || cboCountry=="NONE"){
			Continent=$("cboContinent").options[$("cboContinent").selectedIndex].text;
			Continent=Continent.replace(/ /,"_");
			Continent=Continent.replace(/&/,"_");
			window.document.form1.action = "/"+Continent+".html";
			window.document.form1.submit();
			return true;
		}else
		if(cboCity=="" || cboCity=="NONE"){			
			Continent=$("cboContinent").options[$("cboContinent").selectedIndex].text;
			Continent=Continent.replace(/ /,"_");
			Continent=Continent.replace(/&/,"_");
			Country=$("cboCountry").options[$("cboCountry").selectedIndex].text;
			Country=Country.replace(/ /,"_");
			Country=Country.replace(/&/,"_");
			window.document.form1.action = "/"+Continent+"/"+Country+".html";
			window.document.form1.submit();
			return true;
		}else
		if(cboHotel=="" || cboHotel=="NONE"){
			Continent=$("cboContinent").options[$("cboContinent").selectedIndex].text;
			Continent=Continent.replace(/ /,"_");
			Continent=Continent.replace(/&/,"_");
			Country=$("cboCountry").options[$("cboCountry").selectedIndex].text;
			Country=Country.replace(/ /,"_");
			Country=Country.replace(/&/,"_");
			City=$("cboCity").options[$("cboCity").selectedIndex].text;
			City=City.replace(/ /,"_");
			City=City.replace(/&/,"_");
			window.document.form1.action = "/"+Continent+"/"+Country+"/"+City+".html";
			window.document.form1.submit();
			return true;
		} else  {
			Country=$("cboCountry").options[$("cboCountry").selectedIndex].text;
			Country=Country.replace(/ /,"_");
			Country=Country.replace(/&/,"_");
			City=$("cboCity").options[$("cboCity").selectedIndex].text;
			City=City.replace(/ /,"_");
			City=City.replace(/&/,"_");
			Hotel=$("cboHotel").options[$("cboHotel").selectedIndex].text;
			Hotel=Hotel.replace(/ /,"_");
			Hotel=Hotel.replace(/&/,"_");
			window.document.form1.action = "/"+Country+"/"+City+"/hotel-"+Hotel+".html";
			window.document.form1.submit();
			return true;
		}
	};

}
