var xmlhttp;

 
function getmodel(str)
{	
	//document.getElementById("dmodel").style.display="none"
	xmlhttp=getObject();
	if(xmlhttp==null)
	{
	alert('object not created')
	}
	
 	var url="includes/ajax/getmodel.php?str="+str;
	//alert(url);
  xmlhttp.onreadystatechange=stateChanged;
  xmlhttp.open('get',url,true)
  xmlhttp.send(null)
 }

function showPrice()
{	
	var postcode=document.getElementById("postcode1").value;
	var airport=document.getElementById("postcode2").value;
	
	xmlhttp=getObject();
	if(xmlhttp==null)
	{
	alert('object not created')
	}
	
 	var url="includes/ajax/getmodel.php?postcode="+postcode+"&airport="+airport;
	//alert(url);
  xmlhttp.onreadystatechange=stateChanged1;
  xmlhttp.open('get',url,true)
  xmlhttp.send(null)
 }

function stateChanged1() 
{
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
 {// alert(xmlhttp.responseText);
 document.getElementById("Rate").innerHTML = xmlhttp.responseText
 } 
}


function getType()
{	

//<o>/if both combobox and text box are valued then text box is give preference 
if(document.getElementById("dropoffpoint1").value==""){

 stzip = document.getElementById("pickuppoint").value; 
 endzip =document.getElementById("dropoffpoint").value;

//alert(stzip+endzip);
if(stzip=="" || endzip==""){return true;}

//var stzip =stzip.split(",") 
//var endzip =endzip.split(",")
 stzip =stzip.split(",") 
 endzip =endzip.split(",")

           // alert(stzip[0]);//postcode
            //alert(stzip[1]);//geocode value
	  //alert(stzip[2]);//postcode type
//alert(stzip[2]+endzip[2]);

if(stzip[2]==endzip[2] || (stzip[2]=='o' && endzip[2]=='i')){ alert("one of pickup point or drop off point shold be airport and another shold be postal code.\nPlease check the addresses");
                      }else {alert("ok");}
 

}

else {   //else 1
//<c>


	var postcode1=document.getElementById("pickuppoint").value;
    var type1 =postcode1.split(",") 


	var postcode2=document.getElementById("dropoffpoint1").value;
	//alert("ok5"+type1[2]+postcode2);
//validation only outer station

	xmlhttp=getObject();
	if(xmlhttp==null)
	{
	alert('object not created')
	}
	
 	var url="includes/ajax/getType.php?type="+type1[2]+"&postcode2="+postcode2;
	//alert(url);
  xmlhttp.onreadystatechange=stateChanged2;
  xmlhttp.open('get',url,true)
  xmlhttp.send(null)
 }

function stateChanged2() 
{
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
 {// alert(xmlhttp.responseText);
 //document.getElementById("Rate").innerHTML = xmlhttp.responseText
 } 

}//else 1


}


function stateChanged() 
{ 
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
 { 
 document.getElementById("models").innerHTML = xmlhttp.responseText
 } 
}

function stateChanged9() 
{ 
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
 { 
document.getElementById("quotecalc").style.display="inline"
 document.getElementById("quotecalc").innerHTML = xmlhttp.responseText
 } 
}



function getObject(handler)
{
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;
}


//<o1>
//getting the geocode from database for textbox postcode

//function getGeocode(postcode){
//alert("ok2"+postcode);
//function getGeocode(postcode){


function getGeocode()
	{

		alert("getting");
var stzip = document.getElementById("pickuppoint").value;
var endzip =document.getElementById("dropoffpoint").value;



//alert(stzip+endzip);

var stzip =stzip.split(","); 
var endzip =endzip.split(",");

var postcode = stzip[3];

alert(postcode);

//alert("ok21"+postcode);
if(strpostcode.length==0) return false;
//if(postcode.lenth==1) return;

xmlhttp=getObject();
	if(xmlhttp==null)
	{
	alert('object not created')
	}
	//var postcode=postcode;
 	var url="includes/ajax/getGeocode.php?postcode="+postcode;
//alert(url);
 xmlhttp.onreadystatechange=stateChanged3;
  xmlhttp.open('get',url,true)
  xmlhttp.send(null)
  

}

function stateChanged3() 
{
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
 {	//alert("ok20"+xmlhttp.responseText);

	alert(xmlhttp.responseText);
// document.getElementById("Geodiv").innerHTML = xmlhttp.responseText
//document.getElementById("Geo").value= xmlhttp.responseText;

  } 
}
//<c1>

function date(){
 var book_date=document.getElementById("book_date").value;
var book_date=book_date.split("-") ;
 var currentTime = new Date();
 var day=currentTime.getDate();
 var month=currentTime.getMonth() ;
 var year=currentTime.getFullYear() ;

//alert(currentTime.getHours() );

// alert("month="+month+1);

 //alert(book_date[0]+ ","+day + ","+ book_date[1]+","+(month+1)+ ","+ book_date[2]+","+year);
if( book_date[2]<year){ alert("date is not valid" ); return false; }
 else {   
	   if(   book_date[1]< month+1 ){ alert("date is not valid" ); return false; }
       else {
		if( book_date[0]<day ){ alert("date is not valid" );return false; }
		else { return true;}//do nothing
	  } 
  } 


}



//for fixed rate
//<o7>




function fixedDistance()
{ 


var stzip = document.getElementById("pickuppoint").value;
var endzip =document.getElementById("dropoffpoint").value;



//alert(stzip+endzip);

var stzip =stzip.split(","); 
var endzip =endzip.split(",");

            //alert(stzip[0]);//postcode
            //alert(stzip[1]);//geocode value
	 // alert(stzip[2]);//postcode type
//alert(stzip[2]+endzip[2]);


//validating postcodes
alert("str " +stzip[3]);
alert("end " +endzip[3]);

//alert("The value is" +document.detailform.vehtype.value);

 


if( (stzip[3]=='a' && endzip[3]=='a') || (stzip[3]=='a' || endzip[3]=='a')) //both zips cannot be airports,city and one has to be airport
	{ 
	  
		  if( (stzip[3]=='o' || endzip[3]=='o'))
		  {
		     alert("outside");
		     return false;
		  }

 
  for (var i=0; i < document.detailform.vehtype.length; i++)
   {
   if (document.detailform.vehtype[i].checked)
      {
         var vehicle_val = document.detailform.vehtype[i].value;    //getting selected vehicle
      }
	    
   }
				
	}
						 else {
	alert("one of pickup point or drop off point shold be airport and another shold be postal code.\nPlease check the addresses");					 
						     return false;
						  }
 

 if(!vehicle_val)
		{
	        alert("Please select a vehicle")
				return false;
	    }




//price implemented
		var BabySeat = document.getElementById("baby_seat").value;
           
   alert(BabySeat);


	   if(vehicle_val=="Saloon" && stzip[3]=='a')
		{
		   price=5+(parseInt(BabySeat))*5;
		} 

		if(vehicle_val=="Saloon" && stzip[3]!='a')
		{
    		price=(parseInt(BabySeat))*5;
		 }

		 if(vehicle_val=="Estate" && stzip[3]=='a')
		 {
		   price=4+5+(parseInt(BabySeat))*5;
		 }

		  if(vehicle_val=="Estate" && stzip[3]!='a')
		 {
		   price=4+(parseInt(BabySeat))*5;
		 }


		 if(vehicle_val=="MPV" && stzip[3]=='a')
		 {
		   price=16+5+(parseInt(BabySeat))*5;
		 }

		  if(vehicle_val=="MPV" && stzip[3]!='a')
		 {
		   price=16+(parseInt(BabySeat))*5;
		 }


		 if(vehicle_val=="MPVPLUS" && stzip[3]=='a')
		 {
		   price=22+5+(parseInt(BabySeat))*5;
		 }

		  if(vehicle_val=="MPVPLUS" && stzip[3]!='a')
		 {
		   price=22+(parseInt(BabySeat))*5;
		 }

		 if(vehicle_val=="8Seater" && stzip[3]=='a')
		 {
		   price=28+5+(parseInt(BabySeat))*5;
		 }

		  if(vehicle_val=="8Seater" && stzip[3]!='a')
		  {
		    price=28+(parseInt(BabySeat))*5;
		  } 

		

alert("includes/ajax/fixedDistance1.php?price="+price);

//window.location="includes/ajax/fixedDistance1.php?price="+price;

   xmlhttp=getObject();
	if(xmlhttp==null)
	{
	alert('object not created')
	}

	var url="includes/ajax/fixedDistance1.php?="+price;
   
  xmlhttp.onreadystatechange=stateChanged10;
  xmlhttp.open('get',url,true)
  xmlhttp.send(null) 
}   


function stateChanged10() 
{ alert(xmlhttp.responseText);
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
 {	
 

  } 
}

	  
   



//extacting info from  vehicle type radio buttons like saloon estate
/*for (var i=0; i < document.detailform.vehtype.length; i++)
   {
   if (document.detailform.vehtype[i].checked)
      {
      var vehicle_val = document.frm1.vehicle[i].value;
      
      }
   }*/

/*var Passangers =document.getElementById("Passangers").value;
var Handcarry = document.getElementById("Handcarry").value;
var CheckingLaugage =document.getElementById("CheckingLaugage").value;
var BabySeat = document.getElementById("BabySeat").value;
var InfantSeat =document.getElementById("InfantSeat").value;
var BoosterSeat = document.getElementById("BoosterSeat").value;*/
//alert( InfantSeat+BoosterSeat);
/* //values are not correct
for (var i=0; i < document.frm1.midway.length; i++)
   {
   if (document.frm1.midway[i].checked)
      {
      var midway_val = document.frm1.midway[i].value;
      }
   }
*/
//var midway =document.getElementById("midway").value;
//alert( midway_val);
       

/*for (var i=0; i < document.frm1.oneway.length; i++)
   {
   if (document.frm1.oneway[i].checked)
      {
      var oneway_val = document.frm1.oneway[i].value;
      }
   }
alert( oneway_val);

/*
var year =document.getElementById("year").value;
var month =document.getElementById("month").value;
var day = document.getElementById("day").value;
*/
/*var year =book_date[2];
var month =book_date[1];
var day = book_date[0];



var hour =document.getElementById("hour").value;
var min =document.getElementById("min").value;



//alert(year+month+day+hour+min);


//alert(stzip+","+endzip+","+vehicle);
//alert(vehicle+","+Passangers+","+Handcarry+","+CheckingLaugage);

var  miles=-1.00;
//alert(miles);
//arrange postcode and airprt in order
var arrange=1;
if(stzip[2]!='i')  //no in order
{
 arrange=-1;

}

//alert(stzip[0]+endzip[0]);

var endzip1="AB10";

//alert("before ajax");

xmlhttp=getObject();
	if(xmlhttp==null)
	{
	alert('object not created')
	}
	var mil=Math.round(miles);
 	var url="includes/ajax/fixedDistance.php?dist="+mil+"&stzip="+stzip[0]+"&endzip="+endzip[0]+"&vehicle_type="+vehicle_val+"&Passangers="+Passangers+"&Handcarry="+Handcarry+"&Handcarry="+Handcarry+"&CheckingLaugage="+CheckingLaugage+"&BabySeat="+BabySeat+"&InfantSeat="+InfantSeat+"&BoosterSeat="+BoosterSeat+"&oneway_val="+oneway_val+"&year="+year+"&month="+month+"&day="+day+"&hour="+hour+"&min="+min+"&arrange="+arrange+"&endzip1="+endzip1+"&pickuptype="+stzip[2];
//alert(url);
  xmlhttp.onreadystatechange=stateChanged10;
  xmlhttp.open('get',url,true)
  xmlhttp.send(null)

}   //fixedDistance

function stateChanged10() 
{
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
 {	//alert("ok20"+xmlhttp.responseText);
	 document.getElementById("main1").style.display='none'
 document.getElementById("FixedRate").innerHTML = xmlhttp.responseText
//document.getElementById("Geo").value= xmlhttp.responseText;

  } 
}

//<c7>


//for variable rate
//<o8>

//for variable rate
//<o8>
*/


function variableDistance(){



//<o1>
//calender
 var book_date=document.getElementById("book_date").value;

var book_date=book_date.split("-") ;
//alert(book_date[0] + "-"+book_date[1] + "-"+book_date[2] );


//validating date

 var currentTime = new Date();
 var day=currentTime.getDate();
 var month=currentTime.getMonth() ;
 var year=currentTime.getFullYear() ;

if( book_date[2]<year){ alert("date is not valid" ); return false; }
 if( book_date[2]==year &&  book_date[1]< month+1 ){ alert("date is not valid" ); return false; }
 if( book_date[2]==year &&  book_date[1]== month+1 && book_date[0]<day ){ alert("date is not valid" ); return false; }

//<c1>





var directions;
var geocoder = null;
geocoder = new GClientGeocoder();


var stzip = document.getElementById("pickuppoint").value;
//var endzip =document.getElementById("dropoffpoint").value;

var stzip =stzip.split(",") 
//var endzip =endzip.split(",")
            //alert(stzip[0]);//postcode
            //alert(stzip[1]);//geocode value
	  //alert(stzip[2]);//postcode type
//alert(stzip[2]+endzip[2]);
/*
if(stzip[2]==endzip[2]){ alert("one of pickup point or drop off point shold be airport and another shold be postal code");

}
*/

//extacting info from radio button
for (var i=0; i < document.frm1.vehicle.length; i++)
   {
   if (document.frm1.vehicle[i].checked)
      {
      var vehicle_val = document.frm1.vehicle[i].value;
      }
   }

var Passangers =document.getElementById("Passangers").value;
var Handcarry = document.getElementById("Handcarry").value;
var CheckingLaugage =document.getElementById("CheckingLaugage").value;
var BabySeat = document.getElementById("BabySeat").value;
var InfantSeat =document.getElementById("InfantSeat").value;
var BoosterSeat = document.getElementById("BoosterSeat").value;
//alert( InfantSeat+BoosterSeat);



/* //values are not correct
for (var i=0; i < document.frm1.midway.length; i++)
   {
   if (document.frm1.midway[i].checked)
      {
      var midway_val = document.frm1.midway[i].value;
      }
   }
*/
//var midway =document.getElementById("midway").value;
//alert( midway_val);
for (var i=0; i < document.frm1.oneway.length; i++)
   {
   if (document.frm1.oneway[i].checked)
      {
      var oneway_val = document.frm1.oneway[i].value;
      }
   }
//alert( oneway_val);


var year =document.getElementById("year").value;
var month =document.getElementById("month").value;
var day = document.getElementById("day").value;
var hour =document.getElementById("hour").value;
var min =document.getElementById("min").value;
//var endzip1 =document.getElementById("dropoffpoint1").value;

//alert(endzip1);


//alert(stzip+","+endzip+","+vehicle);
//alert(vehicle+","+Passangers+","+Handcarry+","+CheckingLaugage);


//<0>


var map = new GMap(document.getElementById("map"));

  directions = new GDirections(map);

 var geocode=document.getElementById("Geo").value;
alert("ok8_2"+geocode);
directions.load(geocode+" to "+stzip[0]);


//directions.load("LUTON" +" to "+" 57.13	-2.11 ");
alert("ok500");
GEvent.addListener(directions, "load", function() {
alert("ok501");
//arrange postcode and airprt in order
var arrange=1;

//alert("outstation calculation");

var distance = directions.getDistance().meters;
var kilometers = distance/1000;
var miles = kilometers *  0.621371192;
var feet = distance *  3.280839;
alert(miles);

document.getElementById("distanceM").innerHTML = "Miles: &nbsp; &nbsp; " + Math.round(miles);
document.getElementById("quotehome").style.display="none";
document.getElementById("quotecalc").style.display="inline";

xmlhttp=getObject();
	if(xmlhttp==null)
	{
	alert('object not created')
	}
	var mil=Math.round(miles);
 	//var url="includes/ajax/variableDistance.php?dist="+mil+"&stzip="+stzip[0]+"&endzip="+endzip[0]+"&vehicle_type="+vehicle_val+"&Passangers="+Passangers+"&Handcarry="+Handcarry+"&Handcarry="+Handcarry+"&CheckingLaugage="+CheckingLaugage+"&BabySeat="+BabySeat+"&InfantSeat="+InfantSeat+"&BoosterSeat="+BoosterSeat+"&oneway_val="+oneway_val+"&year="+year+"&month="+month+"&day="+day+"&hour="+hour+"&min="+min+"&arrange="+arrange+"&endzip1="+endzip1;
    var url="includes/ajax/variableDistance.php?dist="+mil+"&stzip="+stzip[0]+"&endzip=AB"+"&vehicle_type="+vehicle_val+"&Passangers="+Passangers+"&Handcarry="+Handcarry+"&Handcarry="+Handcarry+"&CheckingLaugage="+CheckingLaugage+"&BabySeat="+BabySeat+"&InfantSeat="+InfantSeat+"&BoosterSeat="+BoosterSeat+"&oneway_val="+oneway_val+"&year="+year+"&month="+month+"&day="+day+"&hour="+hour+"&min="+min+"&arrange="+arrange+"&endzip1=";

//alert(url);
  xmlhttp.onreadystatechange=stateChanged11;
  xmlhttp.open('get',url,true)
  xmlhttp.send(null)

});


}   //fixedDistance

function stateChanged11() 
{
if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
 {	alert("ok40"+xmlhttp.responseText);
	
 document.getElementById("VariableRate").innerHTML = xmlhttp.responseText
//document.getElementById("Geo").value= xmlhttp.responseText;
// document.getElementById("main1").style="display: none"

  } 
}

//<c8>

//<o9>
//diverting to correct distance formula
 function distance(){
	 // alert( "ok200");
 /*
 var divert =document.getElementById("dropoffpoint1").value;
 alert( "ok201"+divert);
if(divert==null){alert( "fixed");}
else {alert( "variable");}
 variableDistance(); 
*/
fixedDistance(); 
 }
//<c9>
  