// JavaScript Document

var dhtmlgoodies_slideSpeed = 20;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
var dhtmlgoodies_slideInProgress = false;
var dhtmlgoodies_expandMultiple = false; // true if you want to be able to have multiple items expanded at the same time.

function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;

	if(!answerDiv.style.display || answerDiv.style.display=='none'){
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId && !dhtmlgoodies_expandMultiple){
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{

			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';

			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}
}

function slideContent(inputId,direction)
{

	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none';
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}
	}
}
window.onload = initShowHideDivs;


function ShowHideChangeDates(divname){ 
document.getElementById(divname).style.display='';
}

function calcDaysnumber(d1,d2){ 
  var date1 = d1
  var date2 = d2
  date1 = date1.split("/");
  date2 = date2.split("/");
  var sDate = new Date(date1[2]+"/"+date1[1]+"/"+date1[0]);
  var eDate = new Date(date2[2]+"/"+date2[1]+"/"+date2[0]);
  var daysApart = Math.abs(Math.round((sDate-eDate)/86400000));
// alert('days='+daysApart);
  return  daysApart;
}

function GetWaitDiv(){
	waitstr = '<BR><div id="WaitNote" style="display:; float:left; background-color:#293237; padding:25px; -moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px; margin-left:300px;"><div style="float:left;padding-top:8px;"><img src="http://ibook247.com/_layouts/images/ajax-loader.gif"></div><div style="float:left; margin-left:20px;font-family:Verdana, Geneva, sans-serif;"><div style="font-size:20px; color:#ffffff;">Please Standby...</div><div style="font-size:10px; color:#ffffff; line-height:18px;">Getting You The Best Rates</div></div><div style="clear:both"></div></div><div style="clear:both;"></div><BR>';
	return waitstr;
}

function GetHPRates(){
	var ran_number = Math.random()*4;
	$("#Booking_ajax_result_div").html(GetWaitDiv()); 
	$.post('../../../get_room_ajax.php?ran='+ran_number,$("#MyForm").serialize(),function(data) {
    $("#Booking_ajax_result_div").html(data);	 
   });	
}

function GetRoomsChangeDates(){ 
	var ran_number = Math.random()*4;
	loading_div = GetWaitDiv();		
	xmlhttpPost('../../../get_room_ajax.php?ran='+ran_number, 'MyForm', 'Booking_ajax_result_div', loading_div); 
	 
	
	 
/*	  arivaldate =  document.getElementById('arrive_date').value;
	  depart_date =  document.getElementById('depart_date').value;
	  occ =  document.getElementById('adults_0').value;
	 
	  days =  calcDaysnumber( arivaldate,depart_date)
	  datein=arivaldate+"|"+depart_date;
	   alert(arivaldate+'loading'+depart_date+'--'+occ+'days='+days)
	 */
	  
	  
	//  DefultSummary();
}

function BookingSummaryRoomsAjax(){
	arivaldate =  document.getElementById('arrive_date').value;
	  depart_date =  document.getElementById('depart_date').value;
	  occ =  document.getElementById('adults_0').value;
	 
	  days =  calcDaysnumber( arivaldate,depart_date)
	  datein=arivaldate+"|"+depart_date;
	 // alert(arivaldate+'loading'+depart_date+'--'+occ+'days='+days)
	  var child_num =document.getElementById('child_0').value;

	 
	  	CreateChildren(0,child_num);
	 
	 
	 
	 if(document.getElementById('new_service_rates').value){
	  
	     serviceRate =  document.getElementById('new_service_rates').value;
	//	 alert(serviceRate);
			 if(serviceRate!=""){
			  serviceRatearray= serviceRate.split('|') ;
			  for(i=0;i<serviceRatearray.length;i++){
				 rateeach =  serviceRatearray[i];
			     servarvalue =  rateeach.split('_');
				 document.getElementById('Servprice_' +servarvalue[0]).value=servarvalue[1];
				 document.getElementById('Ser_Price_ajax_' +servarvalue[0]).innerHTML=servarvalue[1];
				 document.getElementById('Ser_Cur_ajax_' +servarvalue[0]).innerHTML=  document.getElementById('toCurrency').value
				 //alert( document.getElementById('Servprice_' +servarvalue[0]).value);
			  }
			 }
	  }
	 
	 
	 
	  BookingSummaryRooms(datein,occ,days,0,0);
	  
	  
	 
	  

	  
}

function gotototo(){

initShowHideDivs();
	}


function GetRoomTypeArray(){
	
    strid='';
	var indexn =document.getElementById('indexn').value;
	
	if(indexn==1){ 
		var objCheckBoxes= document.getElementById('roomselect[]').value;
		
		var mySplitResult = objCheckBoxes.split("_");
				 if(mySplitResult[1]>0){ 
				  strid= strid + objCheckBoxes;
				}
		
		}else{
				//alert(indexn)
			FormName	='MyForm';
			FieldName   = 'roomselect[]';
			
			 c=0;
				if(!document.forms[FormName]){
					return;}
				var objCheckBoxes = document.forms[FormName].elements[FieldName];
				if(!objCheckBoxes){ 
					return;}
				var countCheckBoxes = objCheckBoxes.length;
				if(!countCheckBoxes){ 
				}else{ 
					for(var i = 0; i < countCheckBoxes; i++) {
						myString = objCheckBoxes[i].value;
						var mySplitResult = myString.split("_");
						 if(mySplitResult[1]>0){
						   if(c==0)strid= strid + objCheckBoxes[i].value;
						   else strid= strid +'|'+ objCheckBoxes[i].value;
						c++;
						}
						// if(objCheckBoxes[i].checked==true){count =count+1;}
					}
				 }
		 
		 
		}
		return strid; 

}


function GetAllRoomTypeArray(){
	
    strid='';
	var indexn =document.getElementById('indexn').value;
	
	if(indexn==1){ 
		var objCheckBoxes= document.getElementById('roomselect[]').value;
		
		var mySplitResult = objCheckBoxes.split("_");
				 
				  strid= strid + objCheckBoxes;
				
		
		}else{
				//alert(indexn)
			FormName	='MyForm';
			FieldName   = 'roomselect[]';
			
			 c=0;
				if(!document.forms[FormName]){
					return;}
				var objCheckBoxes = document.forms[FormName].elements[FieldName];
				if(!objCheckBoxes){ 
					return;}
				var countCheckBoxes = objCheckBoxes.length;
				if(!countCheckBoxes){ 
				}else{ 
					for(var i = 0; i < countCheckBoxes; i++) {
						myString = objCheckBoxes[i].value;
						var mySplitResult = myString.split("_");
						
						   if(c==0)strid= strid + objCheckBoxes[i].value;
						   else strid= strid +'|'+ objCheckBoxes[i].value;
						c++;
						
						// if(objCheckBoxes[i].checked==true){count =count+1;}
					}
				 }
		 
		 
		}
		return strid; 

}
	
	
	
function SubmitFormStep2(roomid,occ){
	
roomid=GetRoomTypeArray();

if(roomid==""){
	alert("ERROR! Please Select Room");
	document.getElementById('selectRoomBalloon').style.display='';
    return false;	
}else{
document.getElementById('selectRoomBalloon').style.display='none';
}

//var no_of_rooms= document.MyForm.no_of_rooms.value;
//roomid='';
	
	/*sl=1;
	for(r=0;r<no_of_rooms;r++){
		rid= 'room_'+ r;
		count=0;
		
		if(document.forms['MyForm'][rid].length){
			count=redio_checkbox_checked("MyForm",rid);
			
			if(count < 1){alert("ERROR! Please Select Room"+sl);
				return false;
			 }else{
				rdvalues = redio_checkbox_checked_value("MyForm",rid);
			 }
			
		}else{
			if(document.forms['MyForm'][rid].checked==true){ 
			count=1;
			 }
			if(count < 1){alert("ERROR! Please Select Room"+sl);
				return false;
			 }else{
			rdvalues= 	document.forms['MyForm'][rid].value;
			
			}
		}
		
		
		 
		 
		 
		sl++;
		if(r>0)das='|';else das='';
		roomid = roomid +das+ rdvalues;
		
	//		
		
		
		
	}*/
	
/*		extrvluaes='';
	alert('roomids'+roomid)

		
		extraarray= roomid.split("|");
		
		for(e=0;e<extraarray.length;e++){
		extrabedid='extrabed_'+e+'_'+extraarray[e];
		
		//	alert(document.getElementById(extrabedid).value);
		extrvluaes=extrvluaes + '&' + extrabedid +'='+document.getElementById(extrabedid).value;
	
		}

	alert(extrvluaes);*/
	var currenturl=document.location.href;
	
	//protocol = window.location.protocol; 
	hostname = window.location.host ;
	pathname = window.location.pathname ;
	
	hotel_id= document.MyForm.hotel_id.value;
	aff_id= document.MyForm.aff_id.value;
	
	
	
	popupBookingSecureServer('https://booking.roomseller.com/bookhotelonline/' + hotel_id+'/' + aff_id + '/?roomid='+roomid + '&occ=' + occ+'#booking_step2', 920, 800, 'yes', '');
	
	
	//alert(hotel_id);
	
//alert('http://'+hostname + pathname + '?roomid='+roomid + '&occ=' + occ)
//https://booking.roomseller.com/bookhotelonline/4177/1712/?roomid=33582_1_2&occ=2#booking_step2
//if(hotel_id==4177){
   document.MyForm.action='https://booking.roomseller.com/bookhotelonline/' + hotel_id+'/' + aff_id + '/?roomid='+roomid + '&occ=' + occ+'#booking_step2';
//}else{

  //document.MyForm.action='http://'+hostname + pathname + '?roomid='+roomid + '&occ=' + occ+'#booking_step2';
//}
document.MyForm.submit();
}

function redio_checkbox_checked(FormName,FieldName){ 
 	count=0;
		if(!document.forms[FormName])
			return;
		var objCheckBoxes = document.forms[FormName].elements[FieldName];
		if(!objCheckBoxes)
			return;
		var countCheckBoxes = objCheckBoxes.length;
		if(!countCheckBoxes){ 
		}else{ 
		for(var i = 0; i < countCheckBoxes; i++) 
			 if(objCheckBoxes[i].checked==true){count =count+1;}
		 }
		return count; 
 
 }
 function redio_checkbox_checked_value(FormName,FieldName){
 	values=0;
		if(!document.forms[FormName])
			return;
		var objCheckBoxes = document.forms[FormName].elements[FieldName];
		if(!objCheckBoxes)
			return;
		var countCheckBoxes = objCheckBoxes.length;
		if(!countCheckBoxes){ 
		}else{ 
		for(var i = 0; i < countCheckBoxes; i++) 
			 if(objCheckBoxes[i].checked==true){values =objCheckBoxes[i].value}
		 }
		return values; 
 
 }
 
 //*******************
 //*******************
 function BookingSummaryRooms(datein,occ,days,service,price){ 
 
 
 	arivaldate =  document.getElementById('arrive_date').value;
	depart_date =  document.getElementById('depart_date').value;
	days =  calcDaysnumber( arivaldate,depart_date)
	datein=arivaldate+"|"+depart_date;

 	
	var child_num =document.getElementById('child_0').value;
	var adult_num =document.getElementById('adults_0').value;
	var	total_occ = Number(child_num) + Number(adult_num);
	
	 edates=datein.split("|");
	 
	 date1 = edates[0];
	 date1=date1.split("/");
	 date2 = edates[1];
	 date2=date2.split("/");
	// var d1 = new Date( date1[2],date1[1]+1, date1[0]); 
	// var d2 = new Date( date2[2],date2[1]+1, date2[0]); 
	 
	 var d1 = new Date( date1[2],date1[1], date1[0]); 
	 var d2 = new Date( date2[2],date2[1], date2[0]);
	 
	  
	 var today = new Date();
	 var the_day = today.getDate();
	var the_month = today.getMonth();
	var the_year = today.getFullYear();
	the_month = the_month + 1;

	 //UpdateTotelBooking(datein,occ,days,0,0);
	 
    
	  service_flag =occ;
	 
	
	 var todaydays = new Date(the_year,the_month,the_day); 

if(service_flag!='service')	{
	 if(d1<todaydays){ 
		 MessagePopupDatesInput();
	 }
	  if(d2.getTime()<=d1.getTime()){    
		MessagePopupDatesInput();
	 }
}
	 //01.var d1 = new Date(2005, 5, 1); 
	 
	
	
	total_sel_occ=0;
	roomid = GetRoomTypeArray();
	
	
    if(roomid==""){ 
	//	MessagePopup();
		DefultSummary();
	}
	
	//**********************
	 if(document.getElementById('pckagei').value){
	  var packagi = document.getElementById('pckagei').value;
	  var season1_days = document.getElementById('season1_days').value;
		  season2day = days - season1_days ;
		  
	//	  alert(days+ '- '+season1_days);
	//	 alert('second seadon'+season2day);
	  }
	//**********************
	
	
	
	
	 roomarray =roomid.split("|");
	  roomstr='';
	  total=0;
	  diccout_free_night=0;
	  free_night_extra=0;
	   roomtotal=0;
	   mesage_min_nights='';
	   room_surcharge =0;
	   
	  
	   
	for(i=0;i< roomarray.length;i++){
		  restur= roomarray[i];
		  roominfo =restur.split("_");
		  room = roominfo[0];
		  room_num = roominfo[1];
	      room_occ = roominfo[2];
		  result_min_nignt_surcharge='';
		  

		  
	//	  alert(room+'_'+room_occ);
		var room_room_number =document.getElementById(room+'_'+room_occ).innerHTML;
		
		var free_nights_row =document.getElementById('feenightsamount_'+room+'_'+room_occ).value;
	//	alert( Number(diccout_free_night)+ ' + ' + Number(free_nights_row))
		diccout_free_night = Number(diccout_free_night) + Number(free_nights_row);
		
		
		
		var free_nights_extra_row =document.getElementById('feenightextra_'+room+'_'+room_occ).value;
	
		free_night_extra = Number(free_night_extra) + Number(free_nights_extra_row);
		
		
		var min_nights =document.getElementById('min_nights_'+room+'_'+room_occ).value;
		
	//	if(room==34701 || room==34699 || room==33054 ){
		result_min_nignt_surcharge='';
		
		SurchargeMinNightsAray = GetMinNightSurchage(room,room_occ); 
		for(key in SurchargeMinNightsAray)
		{
		//alert("key " + key	+ " has value "	+ SurchargeMinNightsAray[key]);
		
			room_surcharge += days * Number(room_num)* SurchargeMinNightsAray[key];
			result_min_nignt_surcharge += ''+key+': '+room_surcharge+' <br />';
			//room_surcharge +=room_surcharge;
			
		}
		
		
	 //   }
		
		
		
		//  alert( room_room_number);
		  room_results =room_room_number.split("|");
		  
		  
		    if(room_results[1]=='-1'){
				 occ_value = room_occ;
			 
			}else{
			 	occ_value = GetOcc(room_occ);
			}
			
		  total_sel_occ= total_sel_occ + Number(occ_value)* Number(room_num) ;
		  
		  
		  if(days<min_nights){
			
			mesage_min_nights +='Please select '+min_nights + ' nights for '+room_results[0]+' <BR>';
			
		  }
		  
		  
		  
		
		  roomstr += room_num +' x '+ room_results[0]+'<br />';
		  
		  
		  
		  roomstr += 'Number of persons:'+occ_value +'';
		  if(room_results[1]=='-1'){
			   total = '-1';
			    roomstr += '<br />';
		  }else{
			 
			  
	  if(season2day==0){	  
			  total =  total +  room_num*room_results[1]*days;
			  roomtotal= roomtotal+room_num*room_results[1]*days;
			  eachroomtotal=room_num*room_results[1]*days;  
			   roomstr += '<br />Room Rate Per Night:'+room_results[1]+' '+ room_results[2]+' <br />';
			   
		 }else{
			 	
			 if(document.getElementById('ses2_'+room+'_'+room_occ)){
			  var season2_rates = document.getElementById('ses2_'+room+'_'+room_occ).value;
			  total =  total +  room_num*room_results[1]*season1_days;
			  roomtotal= roomtotal+room_num*room_results[1]*season1_days;
			  eachroomtotal=room_num*room_results[1]*season1_days;
			  
			  
			 		
			  
			  total =  total +  room_num*season2_rates*season2day;
			  roomtotal= roomtotal+room_num*season2_rates*season2day;
			  eachroomtotal=  eachroomtotal + room_num*season2_rates*season2day;
			  
			  roomstr += '<br />Room Rate Period 1:'+room_results[1]+' '+ room_results[2]+'';
			   roomstr += '<br />Room Rate Period 2:'+season2_rates+' '+ room_results[2]+' <br />';
			  
			 }else{  
			    total =  total +  room_num*room_results[1]*days;
			    roomtotal= roomtotal+room_num*room_results[1]*days;
			    eachroomtotal=room_num*room_results[1]*days;
			 	 roomstr += '<br />Room Rate Per Night:'+room_results[1]+' '+ room_results[2]+' <br />';
			 }
		
		  }
		  
		  
		  
		  
		  roomstr += 'Room Total:'+eachroomtotal.toFixed()+' '+ room_results[2]+' <br /><br />';			  
		  
		 
		  }
		  currency =room_results[2];
	}
	
	
	
	//***************
	//***************
if(service_flag!='service')	{
	if(mesage_min_nights!=''){
	   MessagePopupMinStay(mesage_min_nights);
	}
}
			
	
	 varfun='onclick="SubmitFormStep2(0,\''+occ+'\')"';
//	alert(roomid)
       bookingpag =' <div id="gray_top_bg" style="text-align:left; padding-left:5px;" >BOOKING SUMMARY</div>';
	   bookingpag +='	  <div id="gray_text" style="text-align:left; padding-left:5px;" >Check-in date:'+edates[0]+'<br />Check-out date:'+edates[1]+'<br /></div>';
	     bookingpag +='	  <div id="gray_text" style="text-align:left; padding-left:5px;" >Nights:'+days+'</div>';
	    bookingpag +='	  <div id="gray_text" style="font-size:11px; padding-bottom:15px; text-align:left; padding-left:5px;" ><b>Your Selected Accommodation:</b><br />'+roomstr+'Room Sub Total:'+roomtotal.toFixed()+' '+currency+'<br /></div>';
		
		  
		  
	// Free Nights
	if(diccout_free_night>0){
		 bookingpag +='	  <div id="gray_text" style="font-size:11px; text-align:left; padding-left:5px; padding-bottom:15px;" ><b> Free Nights Discounts</b><br />Total Free Nights Discount:'+diccout_free_night.toFixed()+' '+currency+'<br />Free Nights Extras:'+free_night_extra.toFixed()+' '+currency+'<br /></div>';	  
	}
	//****************
	service_summary='';
	service_total=0;
	service_sub_total=0;
	service_ids = document.getElementById('services').value;
	
	
	
	if(service_ids!=""){ 
		var service_fl=service_ids.indexOf('|');
		if(service_fl==-1){ 
		     
			    service_ids_aray= new Array(1); 
				service_ids_aray[0]=service_ids;
				
				combo_value = document.getElementById('service_'+service_ids_aray[0]).value;
				
				if(document.getElementById('check_'+service_ids_aray[0]).checked == true){
					if(combo_value!=""){
						serviceprice = document.getElementById('Servprice_'+service_ids_aray[0]).value;
						servicename = document.getElementById('Servname_'+service_ids_aray[0]).value;
						service_total =combo_value*serviceprice;
						
						service_summary +=  combo_value+' x '+servicename+'<BR>';
						service_summary += 'Service Total: '+service_total.toFixed()+' '+currency+'<BR>';
						service_sub_total +=service_total;
					 }
				}else{
				service_summary='None';
				}
		   
		}else{
				
			
			 service_ids_aray= service_ids.split("|");
		   for(i=0;i<service_ids_aray.length;i++){ 
				
				combo_value = document.getElementById('service_'+service_ids_aray[i]).value;
				
				if(document.getElementById('check_'+service_ids_aray[i]).checked == true){
					//checkBox = document.getElementById('check_'+service_ids_aray[i]).value;
				
					if(combo_value!=""){
						serviceprice = document.getElementById('Servprice_'+service_ids_aray[i]).value;
						servicename = document.getElementById('Servname_'+service_ids_aray[i]).value;
						service_total =combo_value*serviceprice;
						
						service_summary +=  combo_value+' x '+servicename+'<BR>';
						service_summary += 'Service Total: '+service_total.toFixed()+' '+currency+'<BR>';
						service_sub_total +=service_total;
					 }
				}else{
				
				}
			}

			}
			
			
	
	if(service_total==0){
		service_summary='None';
	}
	 bookingpag +='	  <div id="gray_text" style="font-size:11px; text-align:left; padding-left:5px; padding-bottom:15px;" ><b>Hotel Extra Services:</b><br />'+service_summary+'<br /></div>';
	}
	
	//****************

	
	 
	total = total - diccout_free_night;
		  
	total = total + free_night_extra;  
	
	
	
	
		
       if(total=='-1'){
		    bookingpag +='      <div id="gray_text" ><span style"font-size:25px; text-align:center; color:#4f4f4f;">Special Rate - Submit For Quote</span></div>';
	   }else{
	
	
	//****************
	// room Surcharge
	//****************
	//bookingpag += result_min_nignt_surcharge;
	total = total+ room_surcharge;
		 
	//****************
	// Tax
	//****************
	CustomTaxStr='';
	TaxStr='';
	sc   = GetHotelTax(total);
	tax1 = GetHotelTaxCustom(total);
	
	if(sc !=0){
		total = total + sc;  
		 TaxStr ='Tax: '+sc.toFixed(2)+'&nbsp;'+ currency+'<br />';
	}	
	if(tax1 !=0){
		total = total + tax1;  
		tax_name = document.getElementById('tax_name').value;
		 CustomTaxStr =''+tax_name+':</b> '+tax1.toFixed(2)+'&nbsp;'+ currency+'<br />';
	}	

if(sc!=0 || tax1 !=0 || result_min_nignt_surcharge !=''){	
// Surcharge and Tax 
	 bookingpag +='<div id="gray_text" style="font-size:11px; text-align:left; padding-left:5px; padding-bottom:15px;" ><b>Other Charges</b><br />';
	  bookingpag += result_min_nignt_surcharge; 
	  bookingpag += TaxStr; 
	  bookingpag += CustomTaxStr; 
  bookingpag +='</div>';
}
		   
		 total +=  service_sub_total;
		 
		
		// ADD 4 PERCENT TO ASSIAWORD SPUUPIER
		/*if(document.getElementById('supplier_id').value==4){
			Asiawordtax = Get4PercentAsiaword(total);
			total 	+= 	Asiawordtax;
	   }*/
		 
	    bookingpag +='      <div id="gray_text" style="position:relative; padding-top:60px;">Total:<br /><span class="price">'+total.toFixed()+'&nbsp;'+ currency+'</span><div id="selectRoomBalloon" class="select-room-balloon" style="left:30px; top:-10px;"><div class="popuptext">Rates are inclusive of tax and service charge unless otherwise noted</div></div></div>';
	   }
     
		
		    bookingpag +='<div id="green_booking_bg"><a href="#scrollbar=false" '+varfun+' >BOOK NOW</a></div>';
 
		document.getElementById('light_gray_bg').innerHTML=  bookingpag;
		
	
//	alert("selectd="+total_sel_occ+'=== Totalocc='+total_occ);;
	
	
if(service_flag!='service')	{	
	if(total_occ>0){
		if( total_sel_occ < total_occ){ 
		 	  MessagePopupAdults();
		}
	     
		 if(child_num>0 && service==0){
		    	if( total_sel_occ < total_occ){ 
			       MessagePopupChildren();
				}
		 }
		 
	}
 
}
	
 
 
 }
 
 
 function Get4PercentAsiaword(total){
	asiaword =  total*4/100;
	return asiaword;
}
 
 
 function GetHotelTax(total){
	 tax_percent = document.getElementById('tax').value;
	 if(tax_percent!=0){
			   sc =  total * tax_percent/100;
     }else{
		  sc=0;
	 }
	 
	 return sc; 
		 
 }
 
 
  function GetHotelTaxCustom(total){
	 tax_1_percent = document.getElementById('tax_1').value;
	 custom_tax_flag = document.getElementById('custom_tax_flag').value;
	 if(tax_1_percent!=0){
			if(custom_tax_flag==1){
				sc =  GetHotelTax(total)
				total = total+sc;
				tax1 =  total * tax_1_percent/100;
			}else{
				 tax1 =  total * tax_1_percent/100;
			}
     }else{
		  tax1=0;
	 }
	 
	 return tax1; 
		 
 }
 
 
 
 function DefultSummary(){ 
	 
	         bookingpag ='     <div id="gray_top_bg" style="text-align:left; padding-left:5px;" >BOOKING SUMMARY</div>';
            bookingpag +='     <div id="dark_gray_text" >YOU MUST SELECT A ROOM TO MAKE BOOKING</div>';
           bookingpag  +='    <div id="gray_text"></div>';
           bookingpag  +='    <div id="green_booking_bg"><a href="#scrollbar=false">BOOK NOW</a></div>';
			  
			  document.getElementById('light_gray_bg').innerHTML=  bookingpag;
 }
 
 
 //****************
 //****************
function SubmitBookingpage2(val_flag){
	
	var sflag=1;
	
if(val_flag==1){
	
	
if(document.MyForm3.name.value==""){
		document.getElementById('ERRORMSG').innerHTML= 'Please Enter Guest Name.';
		 document.getElementById("ERRORMSG").style.color = "red";
		 sflag=0;
		 document.MyForm3.name.focus();
		 document.getElementById('name').style.backgroundColor="#f9e5e6";
		
}else if(document.MyForm3.email.value==""){
		document.getElementById('ERRORMSG').innerHTML= 'Please Enter Email.';
		document.getElementById("ERRORMSG").style.color = "red";
		 sflag=0;
		 document.MyForm3.email.focus();
		 document.getElementById('email').style.backgroundColor="#f9e5e6";
		
}else if(!checkemail1()){ 
		
		document.getElementById('ERRORMSG').innerHTML= 'Please Enter Valid Email.';
		document.getElementById("ERRORMSG").style.color = "red";
		 sflag=0;
		  document.MyForm3.email.focus();
		     document.getElementById('email').style.backgroundColor="#f9e5e6";
			 
		
}else if(document.MyForm3.email2.value==""){
		document.getElementById('ERRORMSG').innerHTML= 'Please Enter Confirm Email.';
		document.getElementById("ERRORMSG").style.color = "red";
		 sflag=0;
		 document.MyForm3.email2.focus();
		 document.getElementById('email2').style.backgroundColor="#f9e5e6";


		
}else if(!checkemail2()){
		
		document.getElementById('ERRORMSG').innerHTML= 'Please Enter Valid Confirm Email.';
		document.getElementById("ERRORMSG").style.color = "red";
		 sflag=0;
		  document.MyForm3.email2.focus();
		     document.getElementById('email2').style.backgroundColor="#f9e5e6";

}else if(document.MyForm3.email.value!=document.MyForm3.email2.value){
	
	document.getElementById('ERRORMSG').innerHTML= 'Please ensure both emails are the same';
		document.getElementById("ERRORMSG").style.color = "red";
		 sflag=0;
		  document.MyForm3.email2.focus();
		     document.getElementById('email2').style.backgroundColor="#f9e5e6";
	
		
}else if(document.MyForm3.country.value==""){
		document.getElementById('ERRORMSG').innerHTML= 'Please Select Country.';
		document.getElementById("ERRORMSG").style.color = "red";
		 sflag=0;
		 document.MyForm3.country.focus();
		 document.getElementById('country').style.backgroundColor="#f9e5e6";
		
}else if(document.MyForm3.address.value==""){
		document.getElementById('ERRORMSG').innerHTML= 'Please Select Address.';
		document.getElementById("ERRORMSG").style.color = "red";
		 sflag=0;
		 document.MyForm3.address.focus();
		 document.getElementById('address').style.backgroundColor="#f9e5e6";
		
}else if(document.MyForm3.sCity.value==""){
		document.getElementById('ERRORMSG').innerHTML= 'Please Select City.';
		document.getElementById("ERRORMSG").style.color = "red";
		 sflag=0;
		 document.MyForm3.sCity.focus();
		 document.getElementById('sCity').style.backgroundColor="#f9e5e6";
		
}else if(document.MyForm3.iZip.value==""){
		document.getElementById('ERRORMSG').innerHTML= 'Please Select Zip.';
		document.getElementById("ERRORMSG").style.color = "red";
		 sflag=0;
		 document.MyForm3.iZip.focus();
		 document.getElementById('iZip').style.backgroundColor="#f9e5e6";
		
}

}
	if(sflag==1){ 
			
				 document.getElementById('continue_bttm').style.display='none';
				document.forms['MyForm3'].submit();	
	}

	
}

 function checkemail1(){
	var testresults;
	var str=document.MyForm3.email.value;
	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)){
		return testresults=true;
	}else{ 
		return testresults=false ;
		//alert("Please input a valid email address!") ;
	
	 } 


}
function checkemail2(){
	var testresults;
	var str=document.MyForm3.email2.value;
	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)){
		return testresults=true;
	}else{ 
		return testresults=false ;
		//alert("Please input a valid email address!") ;
	
	 } 


}

//***************
// POP Message
//*************** 

function MessagePopupAdults(){
	//request data for centering
		
   	  document.getElementById('MSGTXT2').innerHTML='Please consider selecting a room with the correct occupancy or adding an extra bed from the hotel services';
		     $('#error_popup2').show('4000').fadeIn(2000);
              //    $('#usercheck').html(data);fadeOut(1500);
          setTimeout("$('#error_popup2').hide(4000); ", 3000); //display message for 3 
		  
		
	     	
				var windowHeight =  getScrollXY()-400;
				
				//centering
				$("#error_popup2").css({
					"position": "absolute",
					"top":  windowHeight,
					"left": 50
				});
		  
		  
	
}
function MessagePopupChildren(){
	//request data for centering
	
	 document.getElementById('MSGTXT').innerHTML='Please note that extra charges might be applicable for children depending on individual hotel policies, number of children and their ages';
	
	      $('#error_popup').show('4000').fadeIn(2000);
              //    $('#usercheck').html(data);fadeOut(1500);
          setTimeout("$('#error_popup').hide(4000); ", 3000); //display message for 3 

		var windowHeight =  getScrollXY()-570;
				//centering
				$("#error_popup").css({
					"position": "absolute",
					"top":  windowHeight,
					"left": 50
				});



	
}
function MessagePopupMinStay(minstay){
	//request data for centering
		
   	        document.getElementById('MSGTXT2').innerHTML=minstay ;
			
		     $('#error_popup2').show('4000').fadeIn(2000);
              //    $('#usercheck').html(data);fadeOut(1500);
          setTimeout("$('#error_popup2').hide(4000); ", 3000); //display message for 3 
		  
		
	     
			//	var windowHeight =  window.pageYOffset+400;
				 windowHeight =  getScrollXY()-400;
			//	alert(windowHeight)
				//centering
				$("#error_popup2").css({
					"position": "absolute",
					"top":  windowHeight,
					"left": 50
				});
		  
		 
	
}

function MessagePopupDatesInput(){
	
		
	//request data for centering
		
   	        document.getElementById('MSGTXT2').innerHTML='Please enter valid check-in and check-out dates';
			
		     $('#error_popup2').show('4000').fadeIn(2000);
              //    $('#usercheck').html(data);fadeOut(1500);
          setTimeout("$('#error_popup2').hide(4000); ", 3000); //display message for 3 
		  
		
	     
				 windowHeight =  getScrollXY()-400;
				//centering
				$("#error_popup2").css({
					"position": "absolute",
					"top":  windowHeight,
					"left": 50
				});
		  
		  
	
}



 function hidepopmsg(){
	 document.getElementById('error_popup').style.display='none';
 }
 
 
 function UpdateServiceBooking(datein,service,days,price){ 
 d1 = document.getElementById('arrive_date').value;
 d2 = document.getElementById('depart_date').value;
 	
	days =document.getElementById('days').value;
  
   service_flag='service';
   BookingSummaryRooms(datein,service_flag,days,service,price);
 }
 
 
 // function create children
 function CreateChildren(val,child_num){ 
 if(child_num>0){
	result ='<div id="extra_service" style="width:833px; margin:0px 8px 10px 8px;">  <div id="extra_service_heading">Children Ages</div>';
     result +='<div id="extra_service_contents" style="position:relative;">';
	 result +='<table width="100%" border="0" cellspacing="0" cellpadding="0">';
					 chp=1;
					 oppt='';
					
					for(chi=0; chi < child_num; chi++){
						
					oppt='';
					name = 'childage_0['+chp+']';
					
					     for(c=1;c<13;c++){
							oppt += '<option value="' + c + '">' + c + '</option>';
						 }
						
						result  +='<tr style="border-top:none;">';
          				result  +=' <td>Child Age '+chp+'</td>';
						result  += '<td><select name="'+name+'" style="width:150px;">' + oppt + '</select</td>';
					    result  +=' </tr>';
					chp++;
					}
	 
        
	   result  +=' </table>  </div></div>';
	   
	 	document.getElementById('Children_div').innerHTML= result;
 }else{
	 document.getElementById('Children_div').innerHTML= '';
 }
	// alert(result);
 }
 
 
 
function UpdateTotelBooking(datein,occ,days,service,price){ 
 		

 
 	arivaldate =  document.getElementById('arrive_date').value;
	depart_date =  document.getElementById('depart_date').value;
	days =  calcDaysnumber( arivaldate,depart_date)
	datein=arivaldate+"|"+depart_date;

 	
	var child_num =document.getElementById('child_0').value;
	var adult_num =document.getElementById('adults_0').value;
	var	total_occ = Number(child_num) + Number(adult_num);
	
	 edates=datein.split("|");
	 
	 date1 = edates[0];
	 date1=date1.split("/");
	 date2 = edates[1];
	 date2=date2.split("/");
	 var d1 = new Date( date1[2],date1[1], date1[0]); 
	 var d2 = new Date( date2[2],date2[1], date2[0]); 
	 
	  
	 var today = new Date();
	 var the_day = today.getDate();
	var the_month = today.getMonth();
	var the_year = today.getFullYear();
	the_month = the_month + 1;

	// alert(the_year+'--'+the_month+'--'+the_day)
	 
     var todaydays = new Date(the_year,the_month,the_day); 
	
 
	
	//**********************
	 if(document.getElementById('pckagei').value){
	  var packagi = document.getElementById('pckagei').value;
	  var season1_days = document.getElementById('season1_days').value;
		  season2day = days - season1_days ;
		  
	//	  alert(days+ '- '+season1_days);
	//	 alert('second seadon'+season2day);
	  }
	//**********************
 		
		//************************
	
	roomidall =  GetAllRoomTypeArray();
	 roomarrayall =roomidall.split("|");
//	alert(roomidall) 
	 for(i=0;i< roomarrayall.length;i++){  
		 
		  restur2= roomarrayall[i];
		  roominfo2 =restur2.split("_");
		  room2 = roominfo2[0];
		  room_num2 = roominfo2[1];
	      room_occ2 = roominfo2[2];
		  var room_room_number2 =document.getElementById(room2+'_'+room_occ2).innerHTML;
		   room_results2 =room_room_number2.split("|");
		    if(season2day==0){	 //alert("seadon==0");
			  eachroomtotal2=room_results2[1]*days;
			     
		 }else{
			 	
			 if(document.getElementById('ses2_'+room2+'_'+room_occ2)){  //alert("sesaon2");
			  var season2_rates2 = document.getElementById('ses2_'+room2+'_'+room_occ2).value;
			  eachroomtotal2=room_results2[1]*season1_days;
			  eachroomtotal2 =  eachroomtotal2 + season2_rates2*season2day;
			 }else{  
			    
			    //alert(room_results2[1]+'*'+days);
				
			    eachroomtotal2=room_results2[1]*days;
			 
			 }
		
		  }
		  
		 
		   roomstr2 = eachroomtotal2.toFixed(2);		
		  
          if( document.getElementById('currency_rate_total_'+room2+'_'+room_occ2)){		
		  document.getElementById('currency_rate_total_'+room2+'_'+room_occ2).innerHTML=roomstr2;
		  }
	
	 }
	//*********************/
		
 
	 
	 }

function GetOcc(occ){
	var ocary= new Array(20) 
	ocary[1]= 1 ;
	ocary[2]= 2 ;
	ocary[3] = 3 ;
	ocary[4] =4 ;
	ocary[6] = 8 ;
	ocary[11] = 5; 
	ocary[12] = 6 ;
	ocary[16] = 7 ;
	ocary[19] = 10 ;
	ocary[20] =12 ;
	ocary[21] =14 ;
	ocary[28] = 11 ;
	ocary[31] =15 ;
	ocary[32] = 25 ;
	ocary[33] = 13 ;
	ocary[35] = 20 ;
	ocary[36] = 16 ;
	ocary[40] =9 ;
	ocary[43] = 18; 
	ocary[44] = 30 ;
	
	curren_oc = ocary[occ];
	return curren_oc;
	
}	 
	 
function getScrollXY() {  
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  
  return scrOfY;
}


//***********

//   GET MIN NIGHTS SURCHAGE

//************
function GetMinNightSurchage(room,room_occ){
	
	var SurchargeArray = new Array();

	// *** min stay surchage
		 if(document.getElementById('min_nights_surcharge_'+room+'_'+room_occ).value){
			 if(document.getElementById('min_nights_surcharge_'+room+'_'+room_occ).value !=0){ 
					 var min_nights_surcharge_str = document.getElementById('min_nights_surcharge_'+room+'_'+room_occ).value;
		  	 
				//	alert(min_nights_surcharge_str);
					var is_multiple_sur=min_nights_surcharge_str.indexOf('~');
					
					if (is_multiple_sur==-1){ 
					 // alert(min_nights_surcharge_str +'single');
					 
						 min_nights_surcharge_value_ary = min_nights_surcharge_str.split('|');
						  SurchargeArray[min_nights_surcharge_value_ary[0]]=min_nights_surcharge_value_ary[1];
						// alert(min_nights_surcharge_value_ary[0]);
						// alert(min_nights_surcharge_value_ary[1]);
					 
					 }else{
					//   alert(min_nights_surcharge_str +'multiple');
					  	 min_nights_surcharge_ary = min_nights_surcharge_str.split('~');
					//	 alert(min_nights_surcharge_ary[0]);
						 for(i=0;i<min_nights_surcharge_ary.length;i++){
							     
								 surcharge_aryval = min_nights_surcharge_ary[i];
						 	     min_nights_surcharge_value_ary = surcharge_aryval.split('|');
								 SurchargeArray[min_nights_surcharge_value_ary[0]]=min_nights_surcharge_value_ary[1];
								// alert(min_nights_surcharge_value_ary[0]);
								// alert(min_nights_surcharge_value_ary[1]);
		 
						 }
		   
					}


				
 
			 }
		 }
		 
	return SurchargeArray;	 
}
//****************
// function POP Secure server
//****************	 
function popupBookingSecureServer(adresa, w, h, scr,title){ 
var l=(screen.availWidth-w)/2 , t=(screen.availHeight-h)/2;
//alert(title)
win=window.open(adresa,'PopupSevure',"width="+w+",height="+h+",left="+l+",top="+t+",statusbar=yes,toolbar=no,scrollbars="+scr+",navbar=no");
win.focus();
}
