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() 
{ 
	//alert("ok");
	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 one_day_rental_mess = document.getElementById("one_day_rental_mess").value;

	var company_id = document.getElementById("cid").value;

	var car_airport = document.getElementById("car_airport").value;

	var grace_hours = document.getElementById("grace_hours").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] > grace_hours || ((dropoff_time_arr[0] - pickup_time_arr[0] == grace_hours) && (pickup_time_arr[1] == "00") && (dropoff_time_arr[1] == "30")))
	{
		alert(one_day_rental_mess);
	}

	//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 + "&company_id=" + company_id + "&car_airport=" + car_airport, 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;
		
		var mylist = xmlDoc.getElementsByTagName("cars_groups_not_available")[0].childNodes[0].nodeValue;
		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.total_price_gc.value = xmlDoc.getElementsByTagName("total_price_gc")[0].childNodes[0].nodeValue;
		document.onlinequote.total_price_gc2.value = xmlDoc.getElementsByTagName("total_price_gc2")[0].childNodes[0].nodeValue;

		var pickup_location_name = xmlDoc.getElementsByTagName("pickup_location_name")[0].childNodes[0].nodeValue;

		document.onlinequote.totalprice_euro.value = document.onlinequote.total_price.value;

		if(xmlDoc.getElementsByTagName("not_hire_car")[0].childNodes[0].nodeValue == 1) 
		{
			//alert(document.onlinequote.car_not_available.value);
			var car_not_available = document.onlinequote.car_not_available.value;
			var car_not_available_2 = document.onlinequote.car_not_available_2.value;
			var car_not_available_3 = document.onlinequote.car_not_available_3.value;
			var car_not_available_4 = document.onlinequote.car_not_available_4.value;

			//====adauagat de Irina pe 2 feb 2010 pt stop sale system
			if(mylist == 0)
			{
				document.getElementById("show_message").innerHTML = "<img src='images/no_booking.jpg'>"+car_not_available;
			}
			else
			{
				//=adaugam lista de grupuri care nu sunt disponibile pt perioada respectiva
				document.getElementById("show_message").innerHTML = "<img src='images/no_booking.jpg'>"+car_not_available_2+mylist+car_not_available_3+pickup_location_name+car_not_available_4;	
			}
			
			document.getElementById("show_message").style.display = "block";
		}
		else
		{
			document.getElementById("show_message").innerHTML = "";
			document.getElementById("show_message").style.display = "none";
			var final_price = document.getElementById("final_price").value;

			if(final_price == 'yes')
			{
				document.onlinequote.submit();
			}
		}
		//document.getElementById("calculated_price").value = "yes";
		//alert("pick = "+xmlDoc.getElementsByTagName("pick")[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(""+xmlDoc.getElementsByTagName("nr_days2")[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?baby_seat="; 
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;
	var nr_days = document.getElementById("nr_days").innerHTML;
	

	
    //document.book_clubs.calculate_total_price.value = "Please wait...";


	//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); 
	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_extras").innerHTML = parseFloat(xmlDoc.getElementsByTagName("old_extra")[0].childNodes[0].nodeValue) + parseFloat(xmlDoc.getElementsByTagName("extra_drivers")[0].childNodes[0].nodeValue);
		document.getElementById("span_extras_pound").innerHTML = Math.round(((parseFloat(xmlDoc.getElementsByTagName("old_extra")[0].childNodes[0].nodeValue) + parseFloat(xmlDoc.getElementsByTagName("extra_drivers")[0].childNodes[0].nodeValue)) / pound) * 100) / 100;

		document.onlinequote.total_price.value = xmlDoc.getElementsByTagName("total_price")[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;


		document.onlinequote.baby_seat_price.value = xmlDoc.getElementsByTagName("baby_seat_price")[0].childNodes[0].nodeValue;
		document.onlinequote.child_seat_price.value = xmlDoc.getElementsByTagName("child_seat_price")[0].childNodes[0].nodeValue;
		document.onlinequote.booster_cushion_price.value = xmlDoc.getElementsByTagName("booster_cushion_price")[0].childNodes[0].nodeValue;
		document.onlinequote.add_driver_price.value = xmlDoc.getElementsByTagName("extra_drivers")[0].childNodes[0].nodeValue;

		//alert("baby = "+document.onlinequote.baby_seat_price.value+"child= "+document.onlinequote.child_seat_price.value+"booster = "+document.onlinequote.booster_cushion_price.value+"driver = "+document.onlinequote.add_driver_price.value)
	} 
} 

//=======================================================================================
//===============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;
	} 
}

//================================================================================================
//============START function added to show cars depending on the chosen location=====================
//============added by IRINA on 21 april 2009===================================================
function get_cars()
{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url_img = "include/get_cars.php?location_from="; 
	var location_from = document.getElementById("location_from").value; 

	var car_group = document.getElementById("car_group").value;

	curent_select_cars = document.getElementById("car_id");
	curent_select_cars.options[0] = new Option("Loading ...", "0|0");
	curent_select_cars.selectedIndex = 0;
	

	xmlHttp.open("GET", url_img + location_from + "&car_group=" + car_group, true); 
	xmlHttp.onreadystatechange = handleHttpResponse_cars; 
	xmlHttp.send(null);
}

//===================================================================================================================
function handleHttpResponse_cars()
{
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		
		xmlDoc=xmlHttp.responseXML;

		curent_select_cars = document.getElementById("car_id");

		var select_a_car = document.getElementById("select_a_car").value;

		curent_select_cars.options[0] = new Option(select_a_car+" ...", "0|0");
		curent_select_cars.options.length  = 1;

		

		var respNode = xmlDoc.getElementsByTagName("response")[0];
		var cars = respNode.getElementsByTagName("car");


		if(cars.length > 0)
		{
	
				for (var i=0; i<cars.length; i++)
				{
					var car_name = cars[i].getElementsByTagName("car_name")[0].firstChild.nodeValue;
					var car_value = cars[i].getElementsByTagName("car_value")[0].firstChild.nodeValue;

					var objOption=document.createElement("option");

					objOption.innerHTML = car_name;
					objOption.value = car_value;
					
					curent_select_cars.options[i+1] = new Option(car_name, car_value);
					if(isNaN(car_value))
					{
						curent_select_cars.options[i+1].className="blue_bg";
						//curent_select_cars.options[car_value].parentNode.label;
					}

				}
		}
		curent_select_cars.selectedIndex = 0;

	} 

}
//================================================================================================
//============END function added to show cars depending on the chosen location=====================
//============added by IRINA on 21 april 2009===================================================

