// JavaScript Document

var xmlHttpSup;
var supUrl = '';
var crWin = null; 
var hwWin = null; 
function openSup(usResident) {
  //alert("t");
  //alert("z");
	if(usResident) {
		if(document.getElementById("pickup").value != "Type an airport, city or town." && document.getElementById("pickup").value.length >= 3) {
			if(document.getElementById('pDate') && (document.getElementById('pDate').value != "Click to choose" && document.getElementById('pDate').value != "dd/mm/yyyy" && document.getElementById('pDate').value != "mm/dd/yyyy")) {
				if(document.getElementById('dDate') && (document.getElementById('dDate').value != "Click to choose" && document.getElementById('dDate').value != "dd/mm/yyyy" && document.getElementById('dDate').value != "mm/dd/yyyy")) {
					if(document.getElementById("country_id").value == "113") {	//	113 = USA		
            //  CR results
            crWin = window.open("about:blank", "Carrentals", "toolbar=yes,menubar=yes,location=yes, scrollbars=yes,resizable=yes, dependent=yes,directories=yes, width=800,height=400,x=50,y=50");			
	         
						xmlHttpSup=GetXmlHttpObject()
						if (xmlHttpSup==null)
						{
							alert ("Browser does not support HTTP Request")
							return
						}
						var url="/includes/crcom_aff_link_builder.php";
            //	Assume US date format (mm/dd/yyyy) as only US vistors get this
						pDate = document.getElementById("pDate").value.split("/");
						dDate = document.getElementById("dDate").value.split("/");
					
						url=url+"?pickupMonthYear="+pDate[0]+pDate[2].substring(2);
						url=url+"&pickupDay="+pDate[1];
						url=url+"&pickupTime="+document.getElementById("pTime").value;
						url=url+"&dropoffMonthYear="+dDate[0]+dDate[2].substring(2);
						url=url+"&dropoffDay="+dDate[1];
						url=url+"&dropoffTime="+document.getElementById("dTime").value;
						url=url+"&l="+document.getElementById('ploc_id').value;
						//alert(url);

						//xmlHttpSup.onreadystatechange=stateChangedSup 
						xmlHttpSup.open("GET",url,false)
						xmlHttpSup.send(null)	
						
						var url = '/redirect.php?r=0&p=0&sitename=carrentals.com&site=carrentalscom&url='+xmlHttpSup.responseText;
						//alert(url);
						crWin.location = url;
						
						//  HW results
            hwWin = window.open("about:blank", "HotWire", "toolbar=yes,menubar=yes,location=yes, scrollbars=yes,resizable=yes, dependent=yes,directories=yes, width=800,height=400,x=50,y=50");			
	         
						xmlHttpSup=GetXmlHttpObject()
						if (xmlHttpSup==null)
						{
							alert ("Browser does not support HTTP Request")
							return
						}
						var url="/includes/hotwire_aff_link_builder.php";
            //	Assume US date format (mm/dd/yyyy) as only US vistors get this
						pDate = document.getElementById("pDate").value.split("/");
						dDate = document.getElementById("dDate").value.split("/");
					
						url=url+"?pickupMonth="+pDate[0];
						url=url+"&pickupDay="+pDate[1];
						url=url+"&pickupTime="+document.getElementById("pTime").value;
						url=url+"&dropoffMonth="+dDate[0];
						url=url+"&dropoffDay="+dDate[1];
						url=url+"&dropoffTime="+document.getElementById("dTime").value;
						url=url+"&pLoc="+document.getElementById('ploc_id').value;
						url=url+"&dLoc="+document.getElementById('dloc_id').value;
						//alert(url);

						//xmlHttpSup.onreadystatechange=stateChangedSup 
						xmlHttpSup.open("GET",url,false)
						xmlHttpSup.send(null)	
						
						var url = '/redirect.php?r=0&p=0&sitename=hotwire.com&site=hotwirecom&url='+xmlHttpSup.responseText;
						//alert(url);
						hwWin.location = url;
						crWin.focus();
					}
				}
			}
		}
	}
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

