//****************************************************************************************************
//****************************************************************************************************
//***
//***	Dao G. Yang
//***	Express Booking PHP AJAX Functions
//***	10/24/2007 
//***
//****************************************************************************************************
//****************************************************************************************************
//----------------------------------------------------------------------------------------------------
	var xmlHttp;
//----------------------------------------------------------------------------------------------------
//====================================================================================================
	function getEBPrice(car_class,doFunc,url){ 
		//----------------------------------------------------------------------------------------------------
			xmlHttp=GetXmlHttpObject()
		//----------------------------------------------------------------------------------------------------
			if (xmlHttp==null){
				alert ("Browser does not support HTTP Request");
				return;
			}
		//----------------------------------------------------------------------------------------------------
			xmlHttp.onreadystatechange=function(){
				if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
					doFunc(xmlHttp, car_class);
			}
		//----------------------------------------------------------------------------------------------------
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		//----------------------------------------------------------------------------------------------------
	}
//====================================================================================================
	function stateChanged(obj,car_class){ 
		//----------------------------------------------------------------------------------------------------
			str = obj.responseText;
			var myResult = str.split("|");
		//----------------------------------------------------------------------------------------------------
			for (i=0;i<myResult.length;i++){
				var myPrice = myResult[i].split("$");
				document.getElementById("xtra2_span_info_"+myPrice[0]).innerHTML = "<br>Price: "+myPrice[1];
				if (myPrice[0] == car_class){
					document.getElementById("msg_below_"+myPrice[0]).innerHTML = myPrice[2];
					document.getElementById("eb_summary").innerHTML = myPrice[2];
				}
			}
		//----------------------------------------------------------------------------------------------------
		//	Below is for message manipulation after AJAX call response.
		//----------------------------------------------------------------------------------------------------
			holder = trim(break_trim(document.getElementById('xtra2_span_info_'+car_class).innerHTML));
			holder = price_trim(holder);
			document.getElementById("total").innerHTML = "Total: "+holder;
			e_holder = euro_trim(holder);
			document.getElementById("e_total").innerHTML = e_holder;	
			document.getElementById("eb_total").style.display = "inline";	
		//----------------------------------------------------------------------------------------------------
			ploc_val = document.getElementById("pick_loc").value;
			document.getElementById("pick_loc_name").innerHTML = what_location(ploc_val);
		//----------------------------------------------------------------------------------------------------
			dloc_val = document.getElementById("drop_loc").value;
			document.getElementById("drop_loc_name").innerHTML = what_location(dloc_val);
		//----------------------------------------------------------------------------------------------------
			writePdate(); writeDdate();
		//----------------------------------------------------------------------------------------------------
			document.getElementById("eb_messages").innerHTML = document.getElementById("freesale_yes").value;
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("freesale_yes").value){
				document.getElementById('eb_messages').style.display = "inline";
			}else{
				document.getElementById('eb_messages').style.display = "none";
			}
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("message_text").value){
				document.getElementById("eb_summary").innerHTML = document.getElementById("message_text").value;
				document.getElementById("eb_total").style.display = "none";	
				document.getElementById('total').innerHTML = "Total: Sold Out";
				current_car = document.getElementById('car_class').value;
				document.getElementById('xtra2_span_info_'+current_car).innerHTML = "<br/>Price: Sold Out";
				document.getElementById('eb_messages').style.display = "none";
			}
		//----------------------------------------------------------------------------------------------------
	}
//====================================================================================================
	function GetXmlHttpObject(){
		//----------------------------------------------------------------------------------------------------
			var xmlHttp=null;
		//----------------------------------------------------------------------------------------------------
			try{
				//----------------------------------------------------------------------------------------------------
				//	Firefox, Opera 8.0+, Safari
				//----------------------------------------------------------------------------------------------------
					xmlHttp=new XMLHttpRequest();
				//----------------------------------------------------------------------------------------------------
			}catch(e){
				//----------------------------------------------------------------------------------------------------
				//	Internet Explorer
				//----------------------------------------------------------------------------------------------------
					try{
						xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
					}catch(e){
						xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
				//----------------------------------------------------------------------------------------------------
			}
		//----------------------------------------------------------------------------------------------------
			return xmlHttp;
		//----------------------------------------------------------------------------------------------------
	}
//====================================================================================================
	function CoalesceDates(){
		//----------------------------------------------------------------------------------------------------
		//	Pickup Date separated
		//----------------------------------------------------------------------------------------------------
			pmonth = document.f.pick_time_mon.value;
			pday = document.f.pick_time_day.value;
			pyear = document.f.pick_time_year.value;
		//----------------------------------------------------------------------------------------------------
		//	0 Padding
		//----------------------------------------------------------------------------------------------------
			if(pmonth.length == 1){ pmonth = "0"+pmonth; }
			if(pday.length == 1){ pday = "0"+pday; }
		//----------------------------------------------------------------------------------------------------
		//	Pickup Date 
		//----------------------------------------------------------------------------------------------------
			pud = pyear+pmonth+pday;
		//----------------------------------------------------------------------------------------------------
		//	Pickup Time
		//----------------------------------------------------------------------------------------------------
			phour = document.f.pick_time_hour.value;
			pmin = document.f.pick_time_min.value;
		//----------------------------------------------------------------------------------------------------
		//	Dropoff Date separated
		//----------------------------------------------------------------------------------------------------
			dmonth = document.f.drop_time_mon.value;
			dday = document.f.drop_time_day.value;
			dyear = document.f.drop_time_year.value;
		//----------------------------------------------------------------------------------------------------
		//	0 Padding
		//----------------------------------------------------------------------------------------------------
			if(dmonth.length == 1){ dmonth = "0"+dmonth; }
			if(dday.length == 1){ dday = "0"+dday; }
		//----------------------------------------------------------------------------------------------------
		//	Dropoff Date
		//----------------------------------------------------------------------------------------------------
			dod = dyear+dmonth+dday;
		//----------------------------------------------------------------------------------------------------
		//	Dropoff Time
		//----------------------------------------------------------------------------------------------------
			dhour = document.f.drop_time_hour.value;
			dmin = document.f.drop_time_min.value;
		//----------------------------------------------------------------------------------------------------
		//	Pickup and Dropoff Location
		//----------------------------------------------------------------------------------------------------
			ploc = document.f.pick_loc.value;
			dloc = document.f.drop_loc.value;
		//----------------------------------------------------------------------------------------------------
		//	Booking Extras ---------------------------------------------------------------------------------
		//----------------------------------------------------------------------------------------------------
		//	1=True 0=False ---------------------------------------------------------------------------------
		//----------------------------------------------------------------------------------------------------
		//	Car Seat
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("extras[1]") && document.getElementById("extras[1]").value){ carseat = document.getElementById("extras[1]").value; }else{ carseat = 0; }
		//----------------------------------------------------------------------------------------------------
		//	Booster Seat
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("extras[3]") && document.getElementById("extras[3]").value){ booster = document.getElementById("extras[3]").value; }else{ booster = 0; }
		//----------------------------------------------------------------------------------------------------
		//	Baby Seat
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("extras[5]") && document.getElementById("extras[5]").value){ babyseat = document.getElementById("extras[5]").value; }else{ babyseat = 0; }
		//----------------------------------------------------------------------------------------------------
		//	Mobile Phone
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("extras[7]") && document.getElementById("extras[7]").value){ mobile_phone = 1; }else{ mobile_phone = 0; }
		//----------------------------------------------------------------------------------------------------
		//	Airtime
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("airtime_id") && document.getElementById("airtime_id").value == 8){ airtime = 1; }else{ airtime = 0; }
		//----------------------------------------------------------------------------------------------------
		//	Mobil Broadband
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("extras[13]") && document.getElementById("extras[13]").value){ mobile_broadband = 1; }else{ mobile_broadband = 0; }
		//----------------------------------------------------------------------------------------------------
		//	Additional Drivers
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("additional_drivers") && document.getElementById("additional_drivers").value){ additional_drivers = document.getElementById("additional_drivers").value; }else{ additional_drivers = 0; }
		//----------------------------------------------------------------------------------------------------
		//	Snow Tires
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("extras[11]") && document.getElementById("extras[11]").checked){ st = 1; }else{ st = 0; }
		//----------------------------------------------------------------------------------------------------
		//	Neverlost GPS
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById("extras[12]") && document.getElementById("extras[12]").checked){ gps = 1; }else{ gps = 0; }
		//----------------------------------------------------------------------------------------------------
		//	Service Level
		//----------------------------------------------------------------------------------------------------
			if (document.getElementById('SS1') && document.getElementById('SS2')){
				SS1_val = document.getElementById('SS1').checked;
				SS2_val = document.getElementById('SS2').checked;
				
				if (!SS1_val && !SS2_val){
					service_level = 2;
				}else if(SS1_val && !SS2_val){
					service_level = 1;
				}else if(!SS1_val && SS2_val){
					service_level = 2;
				}else if(SS1_val && SS2_val){
					service_level = 1;
				}else{
					//----------------------------------------------------------------------------------------------------
					//	Default Service Level
					//----------------------------------------------------------------------------------------------------
						service_level = 2;
					//----------------------------------------------------------------------------------------------------
				}
			}else{
				//----------------------------------------------------------------------------------------------------
				//	Default Service Level
				//----------------------------------------------------------------------------------------------------
					service_level = 2;
				//----------------------------------------------------------------------------------------------------
			}
		//----------------------------------------------------------------------------------------------------
			if (document.f.car_class.value){
				car_class = document.f.car_class.value;
				document.getElementById("xtra2_span_info_"+car_class).innerHTML = "<br/><IMG src='https://www.danskautorent.com/images/busy.gif'>";
			}else{
				car_class=24;
				document.getElementById("xtra2_span_info_"+car_class).innerHTML = "<br/><IMG src='https://www.danskautorent.com/images/busy.gif'>";
				document.f.car_class.value = car_class;
			}
		//----------------------------------------------------------------------------------------------------
			var url = "getCalc.php";
			url = url + "?id=" 					+ car_class;
			url = url + "&start=" 				+ pud;
			url = url + "&end=" 				+ dod;
			url = url + "&ploc=" 				+ ploc;
			url = url + "&dloc=" 				+ dloc;
			url = url + "&pmonth=" 				+ pmonth;
			url = url + "&pday=" 				+ pday;
			url = url + "&pyear="				+ pyear;
			url = url + "&dmonth=" 				+ dmonth;
			url = url + "&dday=" 				+ dday;
			url = url + "&dyear=" 				+ dyear;
			url = url + "&phour=" 				+ phour;
			url = url + "&pmin=" 				+ pmin;
			url = url + "&dhour=" 				+ dhour;
			url = url + "&dmin=" 				+ dmin;
			url = url + "&st=" 					+ st;
			url = url + "&gps=" 				+ gps;
			url = url + "&carseat=" 			+ carseat;
			url = url + "&booster=" 			+ booster;
			url = url + "&babyseat=" 			+ babyseat;
			url = url + "&mobile_phone=" 		+ mobile_phone;
			url = url + "&airtime=" 			+ airtime;
			url = url + "&mobile_broadband=" 	+ mobile_broadband;
			url = url + "&additional_drivers=" 	+ additional_drivers;
			url = url + "&service_level=" 		+ service_level;
		//----------------------------------------------------------------------------------------------------
			//document.write(url);
			getEBPrice(car_class,stateChanged,url);
		//----------------------------------------------------------------------------------------------------
	}
//====================================================================================================
//====================================================================================================
//====================================================================================================