
function actionTable(showid,hiddenid){
	var showobj = document.getElementById(showid);
	var hiddenobj = document.getElementById(hiddenid);
	
	showobj.className='h10_sel';
	hiddenobj.className='h10';
	
	var showTableobj = document.getElementById(showid+"Table");
	var hiddenTableobj = document.getElementById(hiddenid+"Table");
	
	showTableobj.style.display = 'block';
	hiddenTableobj.style.display = 'none';
}
function showRoomAvailability(roomID){
	
	var tobjs = document.getElementsByTagName("table");
	
  for(var i = 0; tobjs!=null && i < tobjs.length; i++){
     if(tobjs[i].className=="h12"){
        	tobjs[i].style.display = 'none';
     }
  }	
	
	
	var roomAY =	document.getElementById("roomAYTable_"+roomID);
	roomAY.style.display = 'block';
	
}

function hiddenRoooAv(){
		var tobjs = document.getElementsByTagName("table");
	
  for(var i = 0; tobjs!=null && i < tobjs.length; i++){
     if(tobjs[i].className=="h12"){
        	tobjs[i].style.display = 'none';
     }
  }
    	
}

function getPre(str){
	var s_index = str.indexOf("_");
	if(s_index<0)return "";
	return str.substr(0,s_index);
}
function getPos(str){
	var s_index = str.indexOf("_");
	if(s_index<0)return "";
	return str.substr(s_index+1,str.length-1);
}

function vliAndSubmit(){
	  var arrClientNames = new Array();
	  var iobjs = document.getElementsByTagName("input");
	  for(var i = 0 ; i < iobjs.length ; i++){
	  	 
	  	 var arrOCN = iobjs[i].id.split("_");
	  	 if(arrOCN.length==3 && arrOCN[0]=="clientName"){
	  	    
	  	    if(!(arrOCN[1] in arrClientNames)){arrClientNames[arrOCN[1]]="";}
	  	   
	  	    if(arrOCN[2]=="0") arrClientNames[arrOCN[1]] = trim(iobjs[i].value) + " " +trim(arrClientNames[arrOCN[1]]);//frist
	  	    if(arrOCN[2]=="1") arrClientNames[arrOCN[1]] = trim(arrClientNames[arrOCN[1]]) + " " + trim(iobjs[i].value);//last
	  	    
	  	 }
	  }
	  
	  for(var i = 0 ; i < arrClientNames.length ;i++){
	  	  
	  	  var fl_names = arrClientNames[i].split(" ");
	  	  if(fl_names[0]=="" && fl_names[1]==""){arrClientNames.remove(arrClientNames[i]);}
	  	  else if(fl_names[0]=="" && fl_names[1]!=""){
	  	  	  alert("please input frist name.");
	  	  	  document.getElementById("clientName_"+i+"_0").focus();
	  	  	  return ;
	  	  }
	  	  else if(fl_names[0]!="" && fl_names[1]==""){
	  	  	  
	  		    alert("please input last name.");
	  	  	  document.getElementById("clientName_"+i+"_1").focus();
	  	  	  return ;
	  		}
	  	  
	  }
	  document.orderNextForm.clientNames.value = arrClientNames.join(",");
	  document.orderNextForm.ContactName.value = document.orderNextForm.ContactNameFrist.value+" "+document.orderNextForm.ContactNameLast.value;

	  if (document.orderNextForm.ContactMobilePhone.value.length < 7 && document.orderNextForm.ContactTel.value.length < 7 )
	  {
	  	alert("please provide at least one contact phone number");
	  	document.orderNextForm.ContactMobilePhone.focus();
	  	return;
	  }	
	  document.orderNextForm.submit();
}
function changeRoomsAndGuests(){
	 var _countPerson = 1;
	 
	 var roomsInt = parseInt(document.orderNextForm.Quantity.value);
	 var guestsInt = parseInt(document.orderNextForm.Persons.value);
	 countPerson = guestsInt * roomsInt;
	 
	 //alert(countPerson);
	 var rpDIV = document.getElementById("roomperson");
	 var divs = rpDIV.getElementsByTagName("div");
	 var tpp_divLength = divs.length;
	 if(divs.length>countPerson){
	    //remove
	    
	    while(tpp_divLength>countPerson){
	       var removeDIV = document.getElementById("pdiv"+(tpp_divLength-1));
	       rpDIV.removeChild(removeDIV);
	       tpp_divLength--;
	    }
	 }
	 if(divs.length<countPerson){
	 	  //add
	 	  
	 	  while(tpp_divLength<countPerson){
	 	  	  
	 	  	  var newDiv = document.createElement("div");
	 	  	  newDiv.style.height = "30px";
	 	  	  newDiv.id="pdiv"+tpp_divLength;
	 	  	  newDiv.innerHTML='<img src="/home/images/hotel/r1.gif" style="vertical-align:-3px;"> Name <input style="vertical-align:-3px;" id="clientName_'+tpp_divLength+'_0" type="text"> - <input style="vertical-align:-3px;" id="clientName_'+tpp_divLength+'_1" type="text">';
	 	  	  rpDIV.appendChild(newDiv);
	 	  	  tpp_divLength++;
	 	  }
	 }
	 //alert(rpDIV.innerHTML);
}

function vliSearchHotel(){
   if(document.getElementById("city0").checked==true && trim(document.showHotelListForm.cityname.value)==""){alert("please input or select city.");document.showHotelListForm.cityname.focus();return;}
   if(trim(document.showHotelListForm.checkin.value)==""){alert("please input check-in date.");return;}
   if(trim(document.showHotelListForm.checkout.value)==""){alert("please input check-out date.");return;}
   if ( !validDatesInput() ) {
		return;
	}
   document.showHotelListForm.submit();
}

function validDatesInput()
{
	var d_date_s = document.showHotelListForm.checkin.value;
	var reg=new RegExp("[^0-9/]","")
		if(d_date_s.search(reg)>=0){
		alert(" Did you input an invalid date?" );
		return false;
	}
		var ss=d_date_s.split("/");
		if(ss.length!=3){
		alert(" Did you input an invalid date?" );
		return false;
	}
	if(isNaN(ss[0])||isNaN(ss[1])||isNaN(ss[2]))
	{
			alert(" Did you input an invalid date?" );
			return false;
	}
	
	var r_date_s = document.showHotelListForm.checkout.value;
	
	
	if(r_date_s.search(reg)>=0){
		alert(" Did you input an invalid date?" );
		return false;
	}
		var ss=r_date_s.split("/");
		if(ss.length!=3){
		alert(" Did you input an invalid date?" );
		return false;
	}
	if(isNaN(ss[0])||isNaN(ss[1])||isNaN(ss[2]))
	{
			alert(" Did you input an invalid date?" );
			return false;
	}
	
	var d_date = new Date(d_date_s);
	var r_date = new Date(r_date_s);

	var curdate = new Date();

	if ( (d_date.getTime() <= curdate.getTime())  || (r_date.getTime() <= d_date.getTime()) )
	{
		alert(" Did you input an invalid date?" );
		return false;
	}
	else {
		return true;
	}
}
function keys_handledown(){
   var ctable = document.getElementById("citylist").getElementsByTagName("table")[0].getElementsByTagName("tbody")[0];
	 if(ctable!=null){
	 	   
	 	   if(select_tr==null){
			    select_city_tr(ctable.firstChild);
			 }
			 else{
			 	  if(typeof(select_tr.nextSibling)!="undefined" && select_tr.nextSibling != null){
			 	  	select_city_tr(select_tr.nextSibling);
			 	  }
			 }
	 }
}
function keys_handleup(){
	 var ctable = document.getElementById("citylist").getElementsByTagName("table")[0].getElementsByTagName("tbody")[0];
	 if(ctable!=null){
	 	   
	 	   if(select_tr==null){
			    select_city_tr(ctable.lastChild);
			 }
			 else{
			 	  if(typeof(select_tr.previousSibling)!="undefined" && select_tr.previousSibling != null){
			 	  	select_city_tr(select_tr.previousSibling);
			 	  }
			    
			 }
	 }
	 
}

function select_city_tr(trobj){
	 
   trobj.style.backgroundColor='#E0F2FF';
   document.showHotelListForm.cityname.value = trobj.firstChild.innerText;
   if(select_tr!=null){
      select_tr.style.backgroundColor='#FFFFFF';
   }
   select_tr = trobj;
}
function cityclick(){
   showHotelListForm.cityname.value="";
   document.getElementById("cityMsg").innerHTML="";
}
function loadcity(ev){
	 document.getElementById("city0").checked=true;
   document.getElementById("citylist").style.display="block";
   //select_tr = null;
   var dontloadcityflag = true;//default load city
   
   switch(keepKeyNum(ev)){
			case 38: //up
				  dontloadcityflag = false;
				  keys_handleup();
			    return;break;
			case 40: //down
				  dontloadcityflag = false;
				  keys_handledown();
			    return;break;
			case 39: //right
			    dontloadcityflag = false;
				  return;break;
			case 37: //left
			    dontloadcityflag = false;
				  return;break;
			
			case 13: //enter
			    dontloadcityflag = false;
			    hiddenCity();
			    return;break;
			case 18: //alt
			    dontloadcityflag = false;
				  hiddenCity();
			    return;break;
			case 27: //Esc
			    dontloadcityflag = false;
				  hiddenCity();
			    return;break;
	 }
	 if(dontloadcityflag){
	 	       select_tr = null;
	         if(trim(document.showHotelListForm.cityname.value)==""){document.getElementById("citylist").innerHTML=htmlstr_citylist;}
				   else{
				        var http_request = createHttpRequest();
								http_request.onreadystatechange = function(){
						      if(http_request.readyState == 4) {
							       if(http_request.status == 200) {
												var rootXML = http_request.responseXML.getElementsByTagName("Citys")[0];
												var _count = parseInt(rootXML.getAttribute("count"));
												if(_count>0){
													  document.getElementById("citylist").innerHTML=rootXML.getElementsByTagName("CityHtml")[0].firstChild.nodeValue;
													  //document.getElementById("test").innerText = rootXML.getElementsByTagName("CityHtml")[0].firstChild.nodeValue;
												}
												else {return;}
							       }
						      }
					      }
					      var _url = "/home/lookupcity" ; 
				        http_request.open("POST",_url,true);
				        http_request.send('<City nameseo="'+document.showHotelListForm.cityname.value+'"/>');
				   }
	 }
   
}

function hiddenCity(){
 	 document.getElementById("citylist").style.display="none";
 	 
 	 if(trim(showHotelListForm.cityname.value)!=""){
 	 	   var http_request = createHttpRequest();
			 http_request.onreadystatechange = function(){
		   if(http_request.readyState == 4) {
		       if(http_request.status == 200) {
							var rootXML = http_request.responseXML.getElementsByTagName("Citys")[0];
							var _count = parseInt(rootXML.getAttribute("count"));
							if(_count>0){
								  document.getElementById("cityMsg").innerHTML="<img src='images/standard_msg_ok.gif'>";
							}
							else {
								  document.getElementById("cityMsg").innerHTML="<img src='images/ico06.gif'> <span style='color:red;'>The city name error.</span>";
							}
		       }
		      }
		   }
		   var _url = "/home/lookupcity" ; 
		   http_request.open("POST",_url,true);
		   http_request.send('<City nameseo="'+document.showHotelListForm.cityname.value+'"/>');
 	 }
 	 
}

function get800City(city_name){
   showHotelListForm.cityname.value=city_name;
}
function hotel_reservation_process(){
	  //submitOrderForm.submit();
	  document.getElementById("divprocess").style.display="block";
	  
    var processBar = new ProcessBar();
		processBar.width=256;
		processBar.backImg = "images/process0.gif";
		processBar.foreImg = "images/process1.gif";
		processBar.top = 0;
		processBar.left = 0;
		processBar.init();
		
		window.location.href="#bodyBottom"; //cursor move to bottom		
		processBar.changeMode();
		
	
	  //submitOrder by ajax
	  var request_root_head_xml = "<SubmitOrder>";
	  var request_root_end_xml = "</SubmitOrder>";
	  var request_root_body_xml = "";
	  request_root_body_xml += "<UserID>"+SOF.UserID+"</UserID>";
	  request_root_body_xml += "<UserID_800Trips>"+SOF.UserID_800Trips+"</UserID_800Trips>";
	  request_root_body_xml += "<HotelID>"+SOF.HotelID+"</HotelID>";
	  request_root_body_xml += "<RoomID>"+SOF.RoomID+"</RoomID>";
	  request_root_body_xml += "<Arrival><![CDATA["+SOF.Arrival+"]]></Arrival>";
	  request_root_body_xml += "<Departure><![CDATA["+SOF.Departure+"]]></Departure>";
	  request_root_body_xml += "<Quantity>"+SOF.Quantity+"</Quantity>";
	  request_root_body_xml += "<Persons>"+SOF.Persons+"</Persons>";
	  request_root_body_xml += "<ClientName><![CDATA["+SOF.ClientName+"]]></ClientName>";
	  request_root_body_xml += "<ClientComeFrom>"+SOF.ClientComeFrom+"</ClientComeFrom>";
	  request_root_body_xml += "<BalanceType>"+SOF.BalanceType+"</BalanceType>";
	  request_root_body_xml += "<EarlyArrivalTime><![CDATA["+SOF.EarlyArrivalTime+"]]></EarlyArrivalTime>";
	  request_root_body_xml += "<LateArrivalTime><![CDATA["+SOF.LateArrivalTime+"]]></LateArrivalTime>";
	  request_root_body_xml += "<ContactName><![CDATA["+SOF.ContactName+"]]></ContactName>";
	  request_root_body_xml += "<ContactMobile><![CDATA["+SOF.ContactMobile+"]]></ContactMobile>";
	  request_root_body_xml += "<ContactTel><![CDATA["+SOF.ContactTel+"]]></ContactTel>";
	  request_root_body_xml += "<ContactFax><![CDATA["+SOF.ContactFax+"]]></ContactFax>";
	  request_root_body_xml += "<ContactEmail><![CDATA["+SOF.ContactEmail+"]]></ContactEmail>";
	  request_root_body_xml += "<ContactAddr><![CDATA["+SOF.ContactAddr+"]]></ContactAddr>";
	  request_root_body_xml += "<ConfirmType>"+SOF.ConfirmType+"</ConfirmType>";
	  request_root_body_xml += "<Price><![CDATA["+SOF.Price+"]]></Price>";
	  request_root_body_xml += "<Remarks><![CDATA["+SOF.Remarks+"]]></Remarks>";
	  
	  request_root_body_xml += "<CreditCardType><![CDATA["+SOF.CreditCardType+"]]></CreditCardType>";
	  request_root_body_xml += "<CreditCardNumber><![CDATA["+SOF.CreditCardNumber+"]]></CreditCardNumber>";
	  request_root_body_xml += "<EffectYear><![CDATA["+SOF.EffectYear+"]]></EffectYear>";
	  request_root_body_xml += "<EffectMonth><![CDATA["+SOF.EffectMonth+"]]></EffectMonth>";
	  request_root_body_xml += "<CardHolder><![CDATA["+SOF.CardHolder+"]]></CardHolder>";
	  request_root_body_xml += "<CVV><![CDATA["+SOF.CVV+"]]></CVV>";
	  request_root_body_xml += "<BillingAddress><![CDATA["+SOF.BillingAddress+"]]></BillingAddress>";
	  request_root_body_xml += "<BillingCity><![CDATA["+SOF.BillingCity+"]]></BillingCity>";
	  request_root_body_xml += "<BillingState><![CDATA["+SOF.BillingState+"]]></BillingState>";
	  request_root_body_xml += "<BillingZipCode><![CDATA["+SOF.BillingZipCode+"]]></BillingZipCode>";
	  request_root_body_xml += "<CCAssociatedPhone><![CDATA["+SOF.CCAssociatedPhone+"]]></CCAssociatedPhone>";

	  
		var http_request = createHttpRequest();
		http_request.onreadystatechange = function(){
      if(http_request.readyState == 4) {
	       if(http_request.status == 200) {
						 var rootXML = http_request.responseXML.getElementsByTagName("SubmitResult")[0];
						 //alert(rootXML.getAttribute("flag"));
						 //alert(rootXML.getAttribute("reservation_id"));
						 //alert(rootXML.firstChild.nodeValue);
						 if(rootXML.getAttribute("flag")=="1"){
						 	   //submit success
						 	   var span_msg = document.getElementById("spanMsg");
						 	   span_msg.innerText= rootXML.firstChild.nodeValue +" In processing... ";
						 	   //span_msg.style.color="green";
						 	   //update status
						 	   window.setTimeout("hotel_reservation_getStatus('"+rootXML.getAttribute("reservation_id")+"')",1*1000*16);
						 }
						 else{
						     //submit fail
						     var target_url = "/home/BookRoom.do*hotelID^"+SOF.HotelID+"@roomID^"+SOF.RoomID;
						     //================rule=====don`t remove this Explain=================== 
						     //target_url = replaceAll("=","^");
						     //target_url = replaceAll("?","*");
						     //target_url = replaceAll("&","@");
						     // for action_msg page will do
						     //============================================
						     
						     
						     window.location.href="/home/action_msg.do?flag=0&msg="+rootXML.firstChild.nodeValue+"&target_url="+target_url;	
						 }
	       }
      }
    }
    var _url = "/home/submitOrder_Ajax.do" ; 
    http_request.open("POST",_url,true);
    http_request.send(request_root_head_xml+request_root_body_xml+request_root_end_xml);
}
function hotel_reservation_cancel(reservation_id){
   window.location.href="cancelReservation.do?reservation_id="+reservation_id;
}
function hotel_reservation_getStatus(reservation_id){
    var http_request = createHttpRequest();
		http_request.onreadystatechange = function(){
      if(http_request.readyState == 4) {
	       if(http_request.status == 200) {
						 var rootXML = http_request.responseXML.getElementsByTagName("GetStatus")[0];
						 //alert(rootXML.getAttribute("flag"));
						 //alert(rootXML.firstChild.nodeValue);
						 //window.location.href="/home/hotelReservationResult.do?reservation_id="+reservation_id+"&flag="+rootXML.getAttribute("flag");
						 document.getstatusForm.flag.value=rootXML.getAttribute("flag");
						 document.getstatusForm.reservation_id.value=reservation_id;
						 document.getstatusForm.msg.value=rootXML.firstChild.nodeValue;
						 
						 document.getstatusForm.submit();
	       }
      }
    }
    var _url = "/home/getStatus_Ajax.do" ; 
    http_request.open("POST",_url,true);
    http_request.send('<GetStatus reservation_id="'+reservation_id+'" />');
}