var xmlHttp
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;
}

//=====================================================================================================
//===================calculates the price in the booking form===========================================
var url_price = "include/get_price.php?pickup="; 
function calculate_price() 
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	var pickup = document.getElementById("pickup").value; 

	var dropoff = document.getElementById("dropoff").value;

	var pickup_time = document.getElementById("pickup_time").value; 

	var dropoff_time = document.getElementById("dropoff_time").value;

	var car_id = document.getElementById("car_id").value;

	var location_from = document.getElementById("location_from").value;

	var location_to = document.getElementById("location_to").value;

	var one_day_rental_mes = document.getElementById("one_day_rental_mes").value;

	pickup_time_arr = pickup_time.split(':');
	dropoff_time_arr = dropoff_time.split(':');

	pickup_time_arr[0] = parseFloat(pickup_time_arr[0]);
	dropoff_time_arr[0] = parseFloat(dropoff_time_arr[0]);
	
	valoare = pickup_time_arr[0] - dropoff_time_arr[0];


	if(dropoff_time_arr[0] - pickup_time_arr[0] >= 1)
	{
		alert(one_day_rental_mes);
	}

	//alert("lala:"+url_price + pickup + "&dropoff=" + dropoff + "&pickup_time=" + pickup_time + "&dropoff_time=" + dropoff_time + "&car_id=" + car_id + "&location_from=" + location_from);

	xmlHttp.open("GET", url_price + pickup + "&dropoff=" + dropoff + "&pickup_time=" + pickup_time + "&dropoff_time=" + dropoff_time + "&car_id=" + car_id + "&location_from=" + location_from + "&location_to=" + location_to, true); 
	xmlHttp.onreadystatechange = handleHttpResponse_price; 
	xmlHttp.send(null);
}

function handleHttpResponse_price() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 

		if(document.onlinequote.sess_language_id.value == 1)
		{
			document.onlinequote.current_currency.value = 'euro';
			document.onlinequote.currency.value = 'euro';
		}
		xmlDoc=xmlHttp.responseXML;
		document.onlinequote.nrdays.value = xmlDoc.getElementsByTagName("nr_days")[0].childNodes[0].nodeValue;
		document.onlinequote.car_name.value = xmlDoc.getElementsByTagName("car_name")[0].childNodes[0].nodeValue;
		document.onlinequote.total_price.value = xmlDoc.getElementsByTagName("total_price")[0].childNodes[0].nodeValue;

		document.onlinequote.totalprice_euro.value = document.onlinequote.total_price.value;

		var final_price = document.getElementById("final_price").value;

		if(xmlDoc.getElementsByTagName("not_hire_car_hour")[0].childNodes[0].nodeValue == 1 && xmlDoc.getElementsByTagName("location_from")[0].childNodes[0].nodeValue > 0) 
		{
			alert(document.onlinequote.pick_mes.value)
		}
		else
		{
			var final_price = document.getElementById("final_price").value;

			if((final_price == 'yes') && (document.onlinequote.email_valid.value == 'yes'))
			{
				document.onlinequote.submit();
			}
		}
		
		//document.getElementById("calculated_price").value = "yes";
		//alert("pick = "+xmlDoc.getElementsByTagName("total_price")[0].childNodes[0].nodeValue);
		//alert("drop = "+xmlDoc.getElementsByTagName("drop")[0].childNodes[0].nodeValue);
		//alert("days = "+xmlDoc.getElementsByTagName("not_hire_car")[0].childNodes[0].nodeValue);
		//alert("test = "+xmlDoc.getElementsByTagName("extra_tax")[0].childNodes[0].nodeValue);
		//alert("test = "+xmlDoc.getElementsByTagName("nr_days")[0].childNodes[0].nodeValue);
		//document.getElementById("price").innerHTML=
		//xmlDoc.getElementsByTagName("price")[0].childNodes[0].nodeValue;

	} 
	
} 

//============================================================================================
//====================calculates the price in rentacar_book_personal.php================================
var url_price_extra = "include/get_price_extra.php?nr_days="; 
function calculate_price_extra() 
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	
	/*var baby_seat = document.getElementById("baby_seat").value;
	var booster_seat = document.getElementById("booster_seat").value;
	var child_seat = document.getElementById("child_seat").value;
	var old_total_price = document.getElementById("old_total_price").value;
	var old_extra = document.getElementById("old_extra").value;
	var additional_drivers = document.getElementById("additional_drivers").value;*/

    //=========1. pay exces insurance or not================
	if (document.getElementById("check_excess_insurance0").checked == true)
	{
		var check_excess_insurance = 0;
	}
	else
	{
		var check_excess_insurance = 1;
	}
	var car_excess = document.getElementById("car_excess").value;
	var nr_days = document.getElementById("nr_days").innerHTML;
	var old_total_price = document.getElementById("old_total_price").value;
	var excess_insurance = document.getElementById("excess_insurance").value;


	//=========2. having additional driver or not================
	var second_driver_name = document.getElementById("second_driver_name").value;
	var second_driver_tax = document.getElementById("second_driver_tax").value;

	//========3. pay young driver or not========================
	if (document.getElementById("check_young_driver").checked == true)
	{
		var check_young_driver = 1;
	}
	else
	{
		var check_young_driver = 0;
	}
	var young_driver_tax = document.getElementById("young_driver_tax").value;


	//=========4. having baby seat/child seat or not================
	var baby_seat = document.getElementById("baby_seat").value;
	var child_seat = document.getElementById("child_seat").value;

	var baby_seat_tax = document.getElementById("baby_seat_tax").value;
	var child_seat_tax = document.getElementById("child_seat_tax").value;

	//=========5. having roof rack or not================
	var add_roof_rack = "";
	var car_roofrack = document.getElementById("car_roofrack").value;
	if(car_roofrack != 0)
	{
		//===the roofrack can be fitted to this car============
		if (document.getElementById("check_roof_rack").checked == true)
		{
			var check_roof_rack = 1;
		}
		else
		{
			var check_roof_rack = 0;
		}
		var roof_rack_tax = document.getElementById("roof_rack_tax").value;
		var add_roof_rack = "&check_roof_rack=" + check_roof_rack + "&roof_rack_tax=" + roof_rack_tax;
	}

	//=========5. paying passenger insurance or not================
	if (document.getElementById("check_passenger_insurance").checked == true)
	{
		var check_passenger_insurance = 1;
	}
	else
	{
		var check_passenger_insurance = 0;
	}
	var passenger_insurance_tax = document.getElementById("passenger_insurance_tax").value;


	//alert("lala:"+url_price + pickup + "&dropoff=" + dropoff + "&pickup_time=" + pickup_time + "&dropoff_time=" + dropoff_time + "&car_id=" + car_id);
	//xmlHttp.open("GET", url_price_extra + baby_seat + "&booster_seat=" + booster_seat + "&child_seat=" + child_seat + "&nr_days=" + nr_days + "&old_total_price=" + old_total_price 
	//	+ "&old_extra=" + old_extra + "&additional_drivers=" + additional_drivers, true); 

	/*alert("lalalal = "+url_price_extra + nr_days + "&car_excess=" + car_excess + "&excess_insurance=" + excess_insurance + "&old_total_price=" + old_total_price 
		+ "&check_excess_insurance=" + check_excess_insurance 
		+ "&second_driver_name=" + second_driver_name + "&second_driver_tax=" + second_driver_tax 
		+ "&check_young_driver=" + check_young_driver + "&young_driver_tax=" + young_driver_tax 
		+ "&baby_seat=" + baby_seat + "&baby_seat_tax=" + baby_seat_tax 
		+ "&child_seat=" + child_seat + "&child_seat_tax=" + child_seat_tax);*/

	xmlHttp.open("GET", url_price_extra + nr_days + "&car_excess=" + car_excess + "&excess_insurance=" + excess_insurance + "&old_total_price=" + old_total_price 
		+ "&check_excess_insurance=" + check_excess_insurance 
		+ "&second_driver_name=" + second_driver_name + "&second_driver_tax=" + second_driver_tax 
		+ "&check_young_driver=" + check_young_driver + "&young_driver_tax=" + young_driver_tax 
		+ "&baby_seat=" + baby_seat + "&baby_seat_tax=" + baby_seat_tax 
		+ "&child_seat=" + child_seat + "&child_seat_tax=" + child_seat_tax 
		+ add_roof_rack 
		+ "&check_passenger_insurance=" + check_passenger_insurance + "&passenger_insurance_tax=" + passenger_insurance_tax , true); 

	xmlHttp.onreadystatechange = handleHttpResponse_price_extra; 
	xmlHttp.send(null);
}

function handleHttpResponse_price_extra() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		xmlDoc=xmlHttp.responseXML;
		var pound = document.getElementById("pound").value;
		document.getElementById("span_total_price").innerHTML = xmlDoc.getElementsByTagName("total_price")[0].childNodes[0].nodeValue;
		document.getElementById("span_total_price_pound").innerHTML = Math.round((xmlDoc.getElementsByTagName("total_price")[0].childNodes[0].nodeValue / pound) * 100) / 100;

		document.getElementById("span_excess").innerHTML = parseFloat(xmlDoc.getElementsByTagName("show_car_excess_insurance")[0].childNodes[0].nodeValue);
		document.getElementById("span_excess_pound").innerHTML = Math.round((parseFloat(xmlDoc.getElementsByTagName("show_car_excess_insurance")[0].childNodes[0].nodeValue) / pound) * 100) / 100;

		if(xmlDoc.getElementsByTagName("second_driver_tax")[0].childNodes[0].nodeValue != 0)
		{
			document.getElementById("div_second_driver_tax").style.display = "block";
		}
		else
		{
			document.getElementById("div_second_driver_tax").style.display = "none";
		}
		
		document.getElementById("id_second_driver_tax").innerHTML = parseFloat(xmlDoc.getElementsByTagName("second_driver_tax")[0].childNodes[0].nodeValue);
		document.getElementById("id_second_driver_tax_pound").innerHTML = Math.round((parseFloat(xmlDoc.getElementsByTagName("second_driver_tax")[0].childNodes[0].nodeValue) / pound) * 100) / 100;


		if(xmlDoc.getElementsByTagName("young_driver_tax")[0].childNodes[0].nodeValue != 0)
		{
			document.getElementById("div_young_driver_tax").style.display = "block";
		}
		else
		{
			document.getElementById("div_young_driver_tax").style.display = "none";
		}
		
		document.getElementById("id_young_driver_tax").innerHTML = parseFloat(xmlDoc.getElementsByTagName("young_driver_tax")[0].childNodes[0].nodeValue);
		document.getElementById("id_young_driver_tax_pound").innerHTML = Math.round((parseFloat(xmlDoc.getElementsByTagName("young_driver_tax")[0].childNodes[0].nodeValue) / pound) * 100) / 100;


		if(xmlDoc.getElementsByTagName("baby_seat_tax")[0].childNodes[0].nodeValue != 0)
		{
			document.getElementById("div_baby_seat_tax").style.display = "block";
		}
		else
		{
			document.getElementById("div_baby_seat_tax").style.display = "none";
		}
		
		document.getElementById("id_baby_seat_tax").innerHTML = parseFloat(xmlDoc.getElementsByTagName("baby_seat_tax")[0].childNodes[0].nodeValue);
		document.getElementById("id_baby_seat_tax_pound").innerHTML = Math.round((parseFloat(xmlDoc.getElementsByTagName("baby_seat_tax")[0].childNodes[0].nodeValue) / pound) * 100) / 100;

		if(xmlDoc.getElementsByTagName("child_seat_tax")[0].childNodes[0].nodeValue != 0)
		{
			document.getElementById("div_child_seat_tax").style.display = "block";
		}
		else
		{
			document.getElementById("div_child_seat_tax").style.display = "none";
		}
		
		document.getElementById("id_child_seat_tax").innerHTML = parseFloat(xmlDoc.getElementsByTagName("child_seat_tax")[0].childNodes[0].nodeValue);
		document.getElementById("id_child_seat_tax_pound").innerHTML = Math.round((parseFloat(xmlDoc.getElementsByTagName("child_seat_tax")[0].childNodes[0].nodeValue) / pound) * 100) / 100;

		if(xmlDoc.getElementsByTagName("roof_rack_tax")[0].childNodes[0].nodeValue != 0)
		{
			document.getElementById("div_roof_rack_tax").style.display = "block";
		}
		else
		{
			document.getElementById("div_roof_rack_tax").style.display = "none";
		}
		
		document.getElementById("id_roof_rack_tax").innerHTML = parseFloat(xmlDoc.getElementsByTagName("roof_rack_tax")[0].childNodes[0].nodeValue);
		document.getElementById("id_roof_rack_tax_pound").innerHTML = Math.round((parseFloat(xmlDoc.getElementsByTagName("roof_rack_tax")[0].childNodes[0].nodeValue) / pound) * 100) / 100;

		if(xmlDoc.getElementsByTagName("passenger_insurance_tax")[0].childNodes[0].nodeValue != 0)
		{
			document.getElementById("div_passenger_insurance_tax").style.display = "block";
		}
		else
		{
			document.getElementById("div_passenger_insurance_tax").style.display = "none";
		}
		
		document.getElementById("id_passenger_insurance_tax").innerHTML = parseFloat(xmlDoc.getElementsByTagName("passenger_insurance_tax")[0].childNodes[0].nodeValue);
		document.getElementById("id_passenger_insurance_tax_pound").innerHTML = Math.round((parseFloat(xmlDoc.getElementsByTagName("passenger_insurance_tax")[0].childNodes[0].nodeValue) / pound) * 100) / 100;


		document.onlinequote.excess_insurance.value = xmlDoc.getElementsByTagName("show_car_excess_insurance")[0].childNodes[0].nodeValue;

		document.onlinequote.total_price.value = xmlDoc.getElementsByTagName("total_price")[0].childNodes[0].nodeValue;
		document.onlinequote.old_total_price.value = xmlDoc.getElementsByTagName("total_price")[0].childNodes[0].nodeValue;

		document.onlinequote.second_driver_tax.value = xmlDoc.getElementsByTagName("second_driver_tax")[0].childNodes[0].nodeValue;
		document.onlinequote.young_driver_tax.value = xmlDoc.getElementsByTagName("young_driver_tax")[0].childNodes[0].nodeValue;

		document.onlinequote.baby_seat_tax.value = xmlDoc.getElementsByTagName("baby_seat_tax")[0].childNodes[0].nodeValue;
		document.onlinequote.child_seat_tax.value = xmlDoc.getElementsByTagName("child_seat_tax")[0].childNodes[0].nodeValue;

		document.onlinequote.roof_rack_tax.value = xmlDoc.getElementsByTagName("roof_rack_tax")[0].childNodes[0].nodeValue;
		document.onlinequote.passenger_insurance_tax.value = xmlDoc.getElementsByTagName("passenger_insurance_tax")[0].childNodes[0].nodeValue;


		//document.onlinequote.extras.value = document.getElementById("span_extras").innerHTML;
		//document.onlinequote.old_extra.value = xmlDoc.getElementsByTagName("old_extra")[0].childNodes[0].nodeValue;
		//alert(xmlDoc.getElementsByTagName("cuc")[0].childNodes[0].nodeValue);
	} 
} 

//=======================================================================================
//===============changes the car image in the booking form================================
var url = "include/get_image.php?car_id="; 

function getimage() 
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	var my_car_id = document.getElementById("car_id").value; 

	xmlHttp.open("GET", url + my_car_id, true); 
	xmlHttp.onreadystatechange = handleHttpResponse; 
	xmlHttp.send(null);
}

function handleHttpResponse() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		xmlDoc=xmlHttp.responseXML;
		document.getElementById("image_car").src = xmlDoc.getElementsByTagName("image")[0].childNodes[0].nodeValue;
	} 
}
