// Copyright (c) 2009 Firestorm Online Ltd 
// Author: Baz Firestorm
// For details, visit our web site web site: http://www.firestorm-online.com/
var $ = function(id){return document.getElementById(id);};

var request = false;
   try {
     request = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }  
     }
   }

   if (!request)
     {alert("Error initializing XMLHttpRequest!");}
     
function calcQuote(){

if ($('LocationID_1').options[$('LocationID_1').selectedIndex].value == '0')
			{alert('Please select your pick up point'); $('LocationID_1').focus(); return false;}
		else
			{
				if ($('LocationID_2').options[$('LocationID_2').selectedIndex].value == '0')
					{alert('Please select your drop off point'); $('LocationID_2').focus(); return false;}
					
					else
						{
						if ($('vehicle').options[$('vehicle').selectedIndex].value == '0')
						   {alert('Please select your preferred vehicle'); $('vehicle').focus(); return false;}
								
								else
									{
									
										if($('paymethod').options[$('paymethod').selectedIndex].value == '0')
											 {alert('Please select your preferred payment method'); $('paymethod').focus(); return false;}
											 	
											 	else
											 	
											 		{
											 		//alert('ok');
													$('qqwrapper').style.display = 'none';
													//$('j_cost_row').style.display = '';
													$('loadingQuote').style.display = '';
													setTimeout('getQuoteInfo()',4500);
											 		}
										
									}
						}
			}							
}
     
function getQuoteInfo() {
     var pickupLoc = $('LocationID_1').options[$('LocationID_1').selectedIndex].value;
     var dropoffLoc = $('LocationID_2').options[$('LocationID_2').selectedIndex].value;
     var pt = $('paymethod').options[$('paymethod').selectedIndex].value;
     var bbs = $('babyseat').options[$('babyseat').selectedIndex].value;
     var bos = $('boosterseat').options[$('boosterseat').selectedIndex].value;
     var veh_t = $('vehicle').options[$('vehicle').selectedIndex].value;
     if (pickupLoc != '' & dropoffLoc != '' & veh_t != '')
     {
	     var url = "/scripts/asp/getQuoteInfo.asp?pickup=" + escape(pickupLoc) + '&dropoff=' + escape(dropoffLoc ) + '&vt=' + veh_t + '&pt=' + pt + '&bbs=' + bbs + '&bos=' + bos;
	     //alert(url);
	     request.open("get", url, true);
	     request.onreadystatechange = updatePage;
	     request.send(null);
     }
     else
     {
     alert('Please Select Your Route');
     $('LocationID_1').focus();
     }
   }
function updatePage() {
     if (request.readyState == 4) {
       if (request.status == 200) {
       	 $('loadingQuote').style.display = 'none';
         var response = request.responseText.split("|||");
         //alert(response);
         var checkresponse = response[0];
         	if(checkresponse == "Route Unavailable")
         		{
         			alert('Sorry, We do not offer this route');
         			$('LocationID_1').options.selectedIndex = 0;
         			$('LocationID_2').options.selectedIndex = 0;
         			//$('j_cost_row').style.display = 'none';
         			//$('j_cost_wrapper').style.display = 'none';
         			$('qqwrapper').style.display = '';
         		}
         			else
         				{
         					$('journeyCOST').innerHTML = checkresponse;
         					//$('j_cost_row').style.display = '';
         					$('j_cost_wrapper').style.display = '';
         				}
       } else
       	 {
           alert('status is ' + request.status);
         }
     }
   }
