function ajaxFunction()
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        try
        {
          xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch(e)
        {
          alert("Your browser does not support AJAX!");
          return false;
        }
      }
    }
  }
  return xmlHttp;
}

function cdwCheck()
{
	
	if (document.getElementById("Country")[document.getElementById("Country").selectedIndex].value != 'IE')
	{
		document.getElementById("cdwHolder").style.visibility="hidden";
	}
	else
		document.getElementById("cdwHolder").style.visibility="visible";
}

function countriesDropDown(DefaultCountry,DefaultLocation)
{	
	countries = ajaxFunction();
    
	countries.onreadystatechange=function()
    	{
    		
		if (countries.readyState==4 || countries.readyState=="complete")
      		{
			var x1 =document.getElementById("Country");
      	
			//remove the current elements in dropdowns;
			for (i=x1.length;i>=0;i--)
			{
				x1.remove(i);
			}
            
			//prep the returned data and add it as new options to the dropdowns
			var options = countries.responseText.split("~");
			for (values in options)
			{
				optionVal=options[values].split("@");
				var y1=document.createElement('option');
				
			
				//cookie read Location
				var x = readCookie('quote');

				if (x)
				{
					x = unescape(x);
					var quoteArray = x.split('#');

					if (quoteArray[15]==optionVal[0])
					{
						y1.selected=true;
					}
					//set selected if matches current
				}
				else
				{
					if(optionVal[0]==DefaultCountry)
					{
						y1.selected=true;
					}
				}

				if (optionVal[0]=='N')
				{
					y1.disabled=true;
				}
				else
				{
					y1.value=optionVal[0];
				}

				y1.text=optionVal[1];

				try
				{
					x1.add(y1,null); 
				}
				catch (e)
				{
					x1.add(y1);
				}
			}
		
			locationsDropDown(DefaultLocation);
		}
	}
	var url="/ajax/countries_dropdown.php?sid="+Math.random();
	countries.open("GET",url,true);
	countries.send(null);    
}

function locationsDropDown(DefaultLocation)
{
	
  locationsDD = ajaxFunction();
  locationsDD.onreadystatechange=function()
  {
    if (locationsDD.readyState==4 || locationsDD.readyState=="complete")
    {
      //dump out the data to the dropdowns
      var x1 =document.getElementById("PickUpLocationID");
      var x2 =document.getElementById("ReturnLocationID");
       
      //remove the current elements in dropdowns;
      for (i=x1.length;i>=0;i--)
      {
        x1.remove(i);
        x2.remove(i);
      }
            
      //prep the returned data and add it as new options to the dropdowns
      var options = locationsDD.responseText.split("~");
      for (values in options)
      {
        optionVal=options[values].split("@");
        var y1=document.createElement('option');
        var y2=document.createElement('option');
        
        //cookie read Location
        var x = readCookie('quote');

	if (x)
	{
		x = unescape(x);
		var quoteArray = x.split('#');
		if (quoteArray[11]==optionVal[0])
		{
			y1.selected=true;
		}
		if (quoteArray[12]==optionVal[0])
		{
			y2.selected=true;
		}
        //set selected if matches current
    	}
    	else
    	{
		if (DefaultLocation==optionVal[0])
		{			
			y1.selected=true;
			y2.selected=true;   
		}
    	
    	}
    	
        y1.value=optionVal[0];
        y2.value=optionVal[0];
        y1.text=optionVal[1];
        y2.text=optionVal[1];
        
        try
        {
          x1.add(y1,null);
          x2.add(y2,null); 
        }
        catch (e)
        {
          x1.add(y1);
          x2.add(y2);
        }
      }
   
	cdwCheck();
	
      
    }
  }
  //alert(document.GetQuote.Country.options[document.GetQuote.Country.selectedIndex].value);
  var url="/ajax/locations_dropdown.php";
  url=url+"?Country="+document.GetQuote.Country.options[document.GetQuote.Country.selectedIndex].value;
  url=url+"&sid="+Math.random();
  locationsDD.open("GET",url,true);
  locationsDD.send(null);
}
