var chainID = 10316;
var locale = "en-US";
//&locale=zh-CN

var hotelID=new Array(); // regular array 
hotelID["Shanghai - Eaton Luxe"]=27667
hotelID["Hong Kong - Eaton"]=27425
hotelID["Koh Samui - Langham Place"]=27422
hotelID["Hong Kong - Langham Place"]=27421
hotelID["Los Angeles – The Langham"]=27405
hotelID["Auckland - The Langham"]=27424    
hotelID["Boston - The Langham"]=27423                             
hotelID["Hong Kong - The Langham"]=27404                                        
hotelID["London - The Langham"]=27406                          
hotelID["Melbourne - The Langham"]=27408                                   
hotelID["Shanghai-The Langham Yangtze"]=27407
hotelID["Shanghai-The Langham Xintiandi"]=28382
hotelID["Beijing Capital Airport - Langham Place"]=27897
hotelID["Shanghai - 88 Xintiandi"]=53395
hotelID["New Delhi - Eaton Smart"]=51842

var _ihoteler = new Array();            //hoteID,cityID,brandID,isNew
_ihoteler["Shanghai - Eaton Luxe"]    = new Array(27667,5811,2283,1);
_ihoteler["Hong Kong - Eaton"]  = new Array(4940,5831,2283,1);
_ihoteler["Koh Samui - Langham Place"]= new Array(73007,6531,2284,1);
_ihoteler["Hong Kong - Langham Place"]= new Array(4930,5831,2284,1);
_ihoteler["Los Angeles – The Langham"]   = new Array(71098,4498,2285,1);
_ihoteler["Auckland - The Langham"]   = new Array(4442,4513,2285,1);
_ihoteler["Boston - The Langham"]     = new Array(5873,4497,2285,1);                          
_ihoteler["Hong Kong - The Langham"]  = new Array(5129,5831,2285,1);                                    
_ihoteler["London - The Langham"]     = new Array(4396,4495,2285,1);                    
_ihoteler["Melbourne - The Langham"]  = new Array(4430,4512,2285,1);                               
_ihoteler["Shanghai-The Langham Yangtze"]   = new Array(72457,5811,2285,1);
_ihoteler["Shanghai-The Langham Xintiandi"]   = new Array(28382,5811,2285,1);
_ihoteler["Beijing Capital Airport - Langham Place"]   = new Array(27897,5811,2284,1);
_ihoteler["Shanghai - 88 Xintiandi"]   = new Array(53395,5811,2285,1);
_ihoteler["New Delhi - Eaton Smart"]   = new Array(51842,5811,2285,1);


	function y2k(number) { return (number < 1000) ? number + 1900 : number; }

	function daysElapsed(date1,date2) {
    	var difference = Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0) - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
	    return difference/1000/60/60/24;
	}



function QueryString(name) 
{
	var AllVars = window.location.search.substring(1);
	var Vars = AllVars.split("&");
	for (i = 0; i < Vars.length; i++)
	{
		var Var = Vars[i].split("=");
		if (Var[0] == name) return Var[1];
	}
	return "";
}

    function getOldLink(DateIn,DateOut,Rooms,Adults,Hotel,Childs){
		
				hotelId = _ihoteler[Hotel][0];
				city = _ihoteler[Hotel][1];
				brands = _ihoteler[Hotel][2];					
				myDin  = DateIn.split("/");
				myDout = DateOut.split("/");
	
				night = daysElapsed(new Date(myDout[2],Number(myDout[0],10)-1,myDout[1]),new Date(myDin[2],Number(myDin[0],10)-1,myDin[1]));

	
//				if(hotelId == 72457){
//			        var link = "https://reservations.ihotelier.com/iStay.cfm?Children=0&HotelID=72457&DateIn="+DateIn+"&DateOut="+DateOut+"&Rooms="+Rooms+"&Adults="+Adults+"&Length="+night+"&LanguageID=11";
//				}else{
					var link=	"http://reservations.ihotelier.com/areasearch/default.cfm?PortalSymbol=lgm&ViewQty=0&SortBy=3&CurrentPage=1&sType=1&sInput=HotelID&ChangeLevel=6&GeoID_6=ALL&ChangeLevel=6&GeoID_5=ALL&ChangeLevel=6&GeoID_4="+city+"&btnLevel=0&languageid=1&HotelID="+hotelId+"&DateIn="+DateIn+"&DateOut="+DateOut+"&Rooms="+Rooms+"&Adults="+Adults+"&Children="+Childs+"&Channel=C_Room&RateType=&PromoCode=&ConID_1628="+brands;		
		
//				}	
				return link;
	}
	
	function getNewLink(DateIn,DateOut,Rooms,Adults,Hotel,ip,Childs){
		
				if( hotelID[Hotel] == 27406 || hotelID[Hotel] == 27407 || hotelID[Hotel] == 27408 || hotelID[Hotel] == 27421 || hotelID[Hotel] == 27422 || hotelID[Hotel] == 27424 ||hotelID[Hotel] == 28382  ||hotelID[Hotel] == 27897) {
		            // From mm/dd/yyyy to dd/mm/yyyy
					//_DateIn  = DateIn.split("/");
					//_DateOut = DateOut.split("/");
					
					//DateIn = _DateIn[1]+"/"+_DateIn[0]+"/"+_DateIn[2];
					//DateOut = _DateOut[1]+"/"+_DateOut[0]+"/"+_DateOut[2];
				}
		
				if(DateOut == "" && DateIn == ""){
	  		  		var link = "https://gc.synxis.com/rez.aspx?Hotel="+hotelID[Hotel]+"&Chain="+chainID+"&adult="+Adults+"&Rooms="+Rooms+"&Child="+Childs;
				}else if(DateIn == ''){
  				  var link = "https://gc.synxis.com/rez.aspx?Hotel="+hotelID[Hotel]+"&Chain="+chainID+"&adult="+Adults+"&Rooms="+Rooms+"&Child="+Childs;		
				}else if(DateOut == ''){
  				  var link = "https://gc.synxis.com/rez.aspx?Hotel="+hotelID[Hotel]+"&Chain="+chainID+"&arrive="+DateIn+"&adult="+Adults+"&Rooms="+Rooms+"&Child="+Childs;			
				}else{
					if(ip == 1){
  						  var link = "https://gc.synxis.com/rez.aspx?Hotel="+hotelID[Hotel]+"&Chain="+chainID+"&arrive="+DateIn+"&depart="+DateOut+"&adult="+Adults+"&Rooms="+Rooms+"&Child="+Childs;			
					}else{
		  				  var link = "https://gc.synxis.com/rez.aspx?Hotel="+hotelID[Hotel]+"&Chain="+chainID+"&arrive="+DateIn+"&depart="+DateOut+"&adult="+Adults+"&Rooms="+Rooms+"&start=1&Child="+Childs;	
					}
				}
				return link;
	}


	

	function calculate(ip) //more search option or not
		{

		var DateIn = document.getElementById("DateIn").value;
		var DateOut = document.getElementById("DateOut").value;
		var Adults = document.getElementById("Adults").value;
		var Rooms = document.getElementById("Rooms").value;
		var Hotel = document.getElementById("hotel").value;
		var Childs = document.getElementById("Childs").value;
        
		if(Hotel == ''){

			parent.layout(DateIn,DateOut,Adults,Rooms,0,ip,Childs);

		}else{
			
			if(_ihoteler[Hotel][3] == 0){
				
			  link = getOldLink(DateIn,DateOut,Rooms,Adults,Hotel,Childs);
				
			}else{
			  
			  link = getNewLink(DateIn,DateOut,Rooms,Adults,Hotel,ip,Childs);
				
			} // end ihoteler == 0
		
		   // window.open(link,"_blank");
			if(ip == 1){
					parent.window.open(link,"_self");
				}else{
					//window.open(link,"_blank");	
					parent.window.open(link,"_self");
			}			
		
		}

    }	
		
		
		
	function calculate_overlay()
		{
		var DateIn = QueryString("DateIn");
		var DateOut = QueryString("DateOut");
		var Adults = QueryString("Adults");
        var Childs = QueryString("Childs");        
		var Rooms = QueryString("Rooms");
		var isMoreSearchOption = QueryString("isMoreSearchOption");
		var isModify = QueryString("isModify");
		var Childs = QueryString("Childs");
		
		var Hotel = document.getElementById("hotel").value;

		if(isModify == 0 && isModify != ''){
			//alert(isModify)			
			if(Hotel == ''){
		  		//var link = "https://gc.synxis.com/rez.aspx?Chain=10316&template=eaton&shell=eaton";
			}else{

				if(_ihoteler[Hotel][3] == 0){
				
				  link = getOldLink(DateIn,DateOut,Rooms,Adults,Hotel,Childs);
				
				}else{
			  
				  link = getNewLink(DateIn,DateOut,Rooms,Adults,Hotel,isMoreSearchOption,Childs);
				
				} // end ihoteler == 0
				
				window.open(link,"_blank");	
				
			    
			}			
			
		}else{
			
			
		
	  			if(Hotel == ""){
					
			    }else{
					if(_ihoteler[Hotel][3] == 0){
				        link = "https://reservations.ihotelier.com/areasearch/cancel.cfm?Languageid=1&portalsymbol=lgm"
					}else{
  					   link = "https://gc.synxis.com/rez.aspx?Hotel="+hotelID[Hotel]+"&Chain="+chainID+"&start=16";
					}
		 	        window.open(link,"_blank");
			    }				
		
	



		}


    }			                                                                                                                                          
