var MinDuration = 1;
var keepDate = new Date;
var dynCalendar_minDate = 0;
var glbBookToolNo = 1;
var currentHost = unescape(window.location.host);

function MinNightsWarning(bkToolNo) {
  return 'The minimum nights allowed is ' + MinDurationForDate(PickupDateValue(bkToolNo)) + ' - please adjust your pickup and/or dropoff date(s)!'; 
}
function SummerStartDate() {
  var ssDate = new Date("May 1, 2009");  
  return ssDate;  
}
function SummerEndDate() {
  var ssDate = new Date("October 15, 2009");  
  return ssDate;  
}
function ResetMinDuration() 
{
var sInputDropoff = 'WebDateDropoff';
    if (req.readyState == 4) {
	   if (req.status == 200) {
	      var theResponse = eval('(' + req.responseText + ')'); 
              var sToolNo = '';
              var iDuration = 4;
              if (theResponse.ToolNo != undefined) {
                 sInputDropoff = sInputDropoff + theResponse.ToolNo; 
                 sToolNo = theResponse.ToolNo;
                 iDuration = theResponse.Duration;
              } else iDuration = theResponse;
              MinDuration = iDuration;
	      if (document.getElementById(sInputDropoff).value == "" ||
		  DropoffDateValue(sToolNo) < PickupDateValue(sToolNo)) 
	      {
		 var theDate = new Date;
		 theDate = PickupDateValue(sToolNo);
		 theDate.setMilliseconds(theDate.getMilliseconds() + (iDuration * (24*60*60*1000)));
		 iMonth = theDate.getMonth() + 1;
		 var txMonth = new String(iMonth);
		 document.getElementById(sInputDropoff).value = theDate.getDate() + '/' + txMonth + '/' + theDate.getFullYear();
	      } 
	   }	  
       else 
	     alert("There was a problem determining the minimum duration of the booking.:\n" + req.statusText + ' ' + req.status + ' ' + req.readyState);
	}
}
function MinDurationForDate(onDate) {
  return MinDuration;
}
function PickupDateValue(bkToolNo) {
  var puDate = new Date;
  var txtText = new String();
  txtDate = document.getElementById('WebDatePickup'+bkToolNo).value;
  j1 = txtDate.indexOf('/');
  if (j1 == -1) j1 = txtDate.indexOf('.');
  j2 = txtDate.indexOf('/',j1+1);  
  if (j2 == -1) j2 = txtDate.indexOf('.',j1+1); 
  puDate.setDate(1);	  
  puDate.setMonth(txtDate.substring(j1+1,j2)-1);
  puDate.setYear(txtDate.substr(j2+1,4)); 	
  puDate.setDate(txtDate.substring(0,j1));  
  puDate.setHours(12);
  puDate.setMinutes(0);	
  puDate.setSeconds(0);	  
  return puDate;
}
function DropoffDateValue(bkToolNo) {
  var doDate = new Date;
  var txtText = new String();
  txtDate = document.getElementById('WebDateDropoff'+bkToolNo).value;
  j1 = txtDate.indexOf('/');
  if (j1 == -1) j1 = txtDate.indexOf('.'); 
  j2 = txtDate.indexOf('/',j1+1);  	
  if (j2 == -1) j2 = txtDate.indexOf('.',j1+1); 
  doDate.setDate(1);	  
  doDate.setMonth(txtDate.substring(j1+1,j2)-1);
  doDate.setYear(txtDate.substr(j2+1,4)); 	
  doDate.setDate(txtDate.substring(0,j1));  
  doDate.setHours(12);
  doDate.setMinutes(0);	
  doDate.setSeconds(0);	   
  return doDate;
}
function CompDates(date1, date2) {
	diffMs = date2 - date1;
	diffSc = diffMs / 1000;
	diffMn = diffSc / 60;
	diffHrs = diffMn / 60;
	diffDays = diffHrs / 24;
	return Math.round(diffDays);
}
function TripNights(bkToolNo) {
  return CompDates(PickupDateValue(bkToolNo), DropoffDateValue(bkToolNo));
}
function FormatDate(theDate) {

}
function ValidatePUDate(theDate, bkToolNo) {
    var mDate   = new Date();
		mxDate  = new Date();
        todayDate = new Date();
        todayDate.setHours(0);
        todayDate.setMinutes(0);
        todayDate.setSeconds(0);
		sMn = new String;
    theResult = 0;
	mDate.setDate(1);				
	mDate.setDate(document.getElementById('MinPuDate'+bkToolNo).value.substr(0,2));	
	mDate.setYear(document.getElementById('MinPuDate'+bkToolNo).value.substr(6,4));
	mDate.setMonth(document.getElementById('MinPuDate'+bkToolNo).value.substr(3,2)-1);
	mDate.setDate(document.getElementById('MinPuDate'+bkToolNo).value.substr(0,2));	
	mDate.setHours(0);
	mDate.setMinutes(0);	
	mDate.setSeconds(0);				

    mxDate.setDate(1);
	mxDate.setYear(document.getElementById('MaxPuDate'+bkToolNo).value.substr(6,4));
	mxDate.setMonth(document.getElementById('MaxPuDate'+bkToolNo).value.substr(3,2)-1);
	mxDate.setDate(document.getElementById('MaxPuDate'+bkToolNo).value.substr(0,2));
	mxDate.setHours(0);
	mxDate.setMinutes(0);	
	mxDate.setSeconds(0);	
	<!-- alert(theDate + ' ... ' + todayDate + ' diff ' + CompDates(todayDate, theDate)); -->
    if (CompDates(mDate, theDate) < 0) 
	{
	   window.alert('Pickup Date must be On or after ' + mDate.toLocaleString().substr(0,28));
	   theResult = -1;
	}
    else if (CompDates(todayDate, theDate) < 3) 
	{
	   window.alert('For online reservations, pickup date must be at least 3 days after today!\n\nFor an earlier pickup, please phone CanaDream Reservations;\n\nToll Free:\t\t1-800-461-7368\nDirect:\t\t1-403-291-1000');
	   theResult = -1;
	}	
	else if (CompDates(mxDate, theDate) > 0) 
	{
	   window.alert('Pickup Date must be on or before ' + mxDate.toLocaleString().substr(0,28));
	   theResult = -1;
	}
	return theResult;
}
function ValidateDODate(theDate, bkToolNo) {
    var mDate   = new Date();
		mxDate  = new Date();
    theResult = 0;
	mDate.setDate(1);
	mDate.setYear(document.getElementById('MinDoDate'+bkToolNo).value.substr(6,4));
	mDate.setMonth(document.getElementById('MinDoDate'+bkToolNo).value.substr(3,2)-1);
	mDate.setDate(document.getElementById('MinDoDate'+bkToolNo).value.substr(0,2));	
	mDate.setHours(12);
	mDate.setMinutes(0);	
	mDate.setSeconds(0);		
	
    if (CompDates(mDate, theDate) < -1) 
	{
	   window.alert('Dropoff Date must be on or after ' + mDate.toLocaleString().substr(0,28));
	   theResult = -1;
	}
	if (theResult == 0)
	{
	   mxDate.setDate(1);
	   mxDate.setMonth(document.getElementById('MaxDoDate'+bkToolNo).value.substr(3,2)-1);
	   mxDate.setYear(document.getElementById('MaxDoDate'+bkToolNo).value.substr(6,4));
	   mxDate.setDate(document.getElementById('MaxDoDate'+bkToolNo).value.substr(0,2));	
	   mxDate.setHours(12);
	   mxDate.setMinutes(0);	
	   mxDate.setSeconds(0);				   	   
	   if (CompDates(mxDate, theDate) > 0) 
  	   {			   
	     window.alert('Dropoff Date must be on or before ' + mxDate.toLocaleString().substr(0,28));
	     theResult = -1;
	   }
	}
	return theResult;
}		
function calendarCallbackPU(calCtrl, day, month, year)
{
   var theDate = new Date(year, month-1, day);
   theBkToolNo = calCtrl.editControl.substr(calCtrl.editControl.length-1, 1);
   if (theBkToolNo == 'p') theBkToolNo = '';   
   if (ValidatePUDate(theDate, theBkToolNo) == 0)
   {	
      date = day + '/' + month + '/' + year;
	  <!-- document.forms[0].WebDatePickup.value = date; -->
	  document.getElementById(calCtrl.editControl).value = date;
      theSessId = '0';
	  <!-- alert(calCtrl.editControl + ' and ' + theBkToolNo); -->
      if (document.getElementById('SessionId') != null) theSessId = document.getElementById('SessionId').value;	 
      theAgentId = '245';
	  if (document.getElementById('AgentId') != null) theAgentId = document.getElementById('AgentId').value;	   
	  if (document.getElementById('SessionId') != null) 
	     SendServerMsg('CalcMinDuration?SessionId='+theSessId+'&AgentId='+theAgentId+'&PuDate='+date+'&ToolNo='+theBkToolNo, ResetMinDuration);
      else {		 
	    theSystem = 'C';
	    if (document.getElementById('BookingSystem') != null) theSystem = document.getElementById('BookingSystem').value;
	    if (theSystem == 'A') {
           var newDate = new Date;
           newDate.setMilliseconds(theDate.getMilliseconds() + (7 * (24*60*60*1000)));
           iMonth = newDate.getMonth() + 1;
	       var txMonth = new String(iMonth);
           if (theAgentId == '1000')
              SendServerMsg('http://www.ameridream.travel/webBook/AmWebP.dll/CalcMinDuration?SessionId='+theSessId+'&AgentId='+theAgentId+'&PuDate='+date+'&ToolNo='+theBkToolNo, ResetMinDuration);
            } 
	    else if (theSystem == 'C')
	       SendServerMsg('http://www.canadream.com/webBook/CdWebP.dll/CalcMinDuration?SessionId='+theSessId+'&AgentId='+theAgentId+'&PuDate='+date+'&ToolNo='+theBkToolNo, ResetMinDuration);
		else
	       SendServerMsg('CalcMinDuration?SessionId='+theSessId+'&AgentId='+theAgentId+'&PuDate='+date+'&ToolNo='+theBkToolNo, ResetMinDuration);		   
	  }
    }
}
function calendarCallbackDO(calCtrl, day, month, year)
{
    var j1, j2, iDuration;
    var theDate = new Date(year, month-1, day);

	theBkToolNo = calCtrl.editControl.substr(calCtrl.editControl.length-1, 1);
	if (theBkToolNo == 'f') theBkToolNo = '';
    if (ValidateDODate(theDate, theBkToolNo) == 0)
	{						
	  date = day + '/' + month + '/' + year;
	  <!-- document.forms[0].WebDateDropoff.value = date; -->
	  document.getElementById(calCtrl.editControl).value = date;
 	  theDate.setHours(12);
	  theDate.setMinutes(0);	
	  theDate.setSeconds(0);	 
	  if (CompDates(PickupDateValue(theBkToolNo), theDate) < MinDurationForDate(PickupDateValue(theBkToolNo)))
		 window.alert(MinNightsWarning(theBkToolNo));  
	}
}	
function CheckPuDate(bkToolNo)
{
 var dateText = new String();
 var toolNo = '';

 if (bkToolNo) toolNo = bkToolNo;


 dateText = document.getElementById('WebDatePickup').value;
 var d= new Date(dateText);
 
	 var FromDate =dateText;
     var DateSplit =FromDate.split('/');
     var FromDate   =new Date(DateSplit[2],DateSplit[1]-1,DateSplit[0]);
     FromDate.setDate(FromDate.getDate()+7);
     var TheDate = new Array(3)
     TheDate[1] = new String(FromDate.getDate())
     TheDate[2] = new String(FromDate.getMonth()+1)
     TheDate[3] = new String(FromDate.getFullYear())
     for(var x = 1; x < TheDate.length; x++)
          {
          if (TheDate[x].length == 1)
          TheDate[x] = "0" + TheDate[x]
          }
     


 
  if (dateText.length > 0)
  {
      var j1, j2;
  	  j1 = dateText.indexOf('/');
	  if (j1 == -1) j1 = dateText.indexOf('.');
	  j2 = dateText.indexOf('/',j1+1);  
	  if (j2 == -1) j2 = dateText.indexOf('.',j1+1); 
	  if ((dateText.length < 8) || (j1 == -1) || (j2 == -1)) 
	  {
		 window.alert('Invalid Pickup Date entry - please enter in a valid format!'); 
	  }	 
	  else
	  {


		document.getElementById('WebDateDropoff'+toolNo).value=TheDate[1]+'/'+(TheDate[2])+'/'+ TheDate[3];
	    var theDate = new Date;
	    theDate.setDate(dateText.substring(0,j1));
	    theDate.setMonth(dateText.substring(j1+1,j2)-1);
	    theDate.setYear(dateText.substr(j2+1,4)); 
  	    theDate.setHours(12);
	    theDate.setMinutes(0);	
	    theDate.setSeconds(0);		
		if (ValidatePUDate(theDate, toolNo) == -1)
		   document.getElementById('WebDatePickup'+toolNo).value = ''; 
	  }
   }
}
function CheckDoDate(bkToolNo)
{
 var dateText = new String();
 var toolNo = '';
 if (bkToolNo) toolNo = bkToolNo;
 dateText = document.getElementById('WebDateDropoff'+toolNo).value;
  if (dateText.length > 0)
  {
      var j1, j2, iMinDuration;

  	  j1 = dateText.indexOf('/');
	  if (j1 == -1) j1 = dateText.indexOf('.');
	  j2 = dateText.indexOf('/',j1+1);  
	  if (j2 == -1) j2 = dateText.indexOf('.',j1+1); 	  
	  if ((dateText.length < 8) || (j1 == -1) || (j2 == -1)) 
	     window.alert('Invalid Dropoff Date entry - please enter in a valid format!');
	  else
	  {
	    var theDate = new Date;
	    theDate.setDate(dateText.substring(0,j1));
	    theDate.setMonth(dateText.substring(j1+1,j2)-1);
	    theDate.setYear(dateText.substr(j2+1,4)); 	
  	    theDate.setHours(12);
	    theDate.setMinutes(0);	
	    theDate.setSeconds(0);				
		if (ValidateDODate(theDate, toolNo) == -1)
		   document.getElementById('WebDateDropoff'+toolNo).value = ''
		else {	
		  if (CompDates(PickupDateValue(toolNo), theDate) < MinDurationForDate(PickupDateValue(toolNo)))
		     window.alert(MinNightsWarning(toolNo));
		} 
	  }
   }
}
function FindVehicles(onDatabase, forAgentId, bkToolNo, pkgId)
{
  var toolNo = '';
  if (bkToolNo) toolNo = bkToolNo;
  todayDate = new Date();
  todayDate.setHours(0);
  todayDate.setMinutes(0);
  todayDate.setSeconds(0);
  sMsg = '';
  if (document.getElementById('puLocation'+toolNo).value == '') sMsg = 'Please specify a Pickup Location prior to booking!';
  else if (document.getElementById('puLocation'+toolNo).value == 'Select Location') sMsg = 'Please specify a Pickup Location prior to booking!';
  else if (document.getElementById('doLocation'+toolNo).value == '') sMsg = 'Please specify a Dropoff Location prior to booking!';
  else if (document.getElementById('doLocation'+toolNo).value == '0') sMsg = 'Please specify a Dropoff Location prior to booking!';
  else if (document.getElementById('doLocation'+toolNo).value == 'Select Location') sMsg = 'Please specify a Dropoff Location prior to booking!';
  else if (document.getElementById('WebDatePickup'+toolNo).value == '') sMsg = 'Please specify a Pickup Date prior to booking!';
  else if (document.getElementById('WebDateDropoff'+toolNo).value == '') sMsg = 'Please specify a Dropoff Date prior to booking!';
  if (sMsg != '')
     alert(sMsg)
  else	 
  {
      <!-- alert('PU = ' + PickupDateValue() + ' DO = ' + DropoffDateValue() + ' Nights = ' + TripNights()); -->
	  if (TripNights(toolNo) < MinDurationForDate(PickupDateValue(toolNo)))
	     window.alert(MinNightsWarning(toolNo));
          else if (CompDates(todayDate, PickupDateValue(toolNo)) < 3) 
             window.alert('Invalid Pickup Date specified - must be at least 3 days after today!')
	  else
	  {   
	    theSystem = 'C';
	    if (document.getElementById('BookingSystem') != null) theSystem = document.getElementById('BookingSystem').value;
	    theDealershipId = 1;
	    if (document.getElementById('DealershipId') != null) theDealershipId=document.getElementById('DealershipId').value;	  
	    sParameters = forAgentId + "&PuLocation="+document.getElementById('puLocation'+toolNo).value + 
	                  "&PuDate="+document.getElementById('WebDatePickup'+toolNo).value + 
			          "&DoLocation="+document.getElementById('doLocation'+toolNo).value + 
	                  "&DoDate="+document.getElementById('WebDateDropoff'+toolNo).value +
			  "&DealershipId="+theDealershipId;
            if (pkgId) 
               sParameters = sParameters + '&pkgId='+pkgId;
        var sHostPath = 'http://'+currentHost+'/webBook/CdWebP.dll/BookRV'; 
        if (theSystem == 'A')
           bkRVWin = window.open("http://www.canadream.com/webBook/AmWebP.dll/BookRV?Id="+sParameters, "BookRV", "left=100, top=120, width=600, height=650, resizable=yes, toolbar=no, status=yes, scrollbars=yes, dependent=yes" ); 
        else
	       bkRVWin = window.open(sHostPath+'?Id='+sParameters, "BookRV", "left=100, top=120, width=600, height=650, resizable=yes, toolbar=no, status=yes, scrollbars=yes, dependent=yes" ); 
	    bkRVWin.focus();   
	  }
   }
}
function ChangePickupLocation(toolNo)
{
  if (toolNo == 1)
     document.forms[0].doLocation1.selectedIndex = document.forms[0].puLocation1.selectedIndex;
  else if (toolNo == 2)
     document.forms[0].doLocation2.selectedIndex = document.forms[0].puLocation2.selectedIndex;
  else
    document.forms[0].doLocation.selectedIndex = document.forms[0].puLocation.selectedIndex;  
}
function ListSalesForLocation()
{
  sMsg = '';
  if ((document.getElementById('purchaseLocation').value == '') ||
      (document.getElementById('purchaseLocation').value == 'Select location'))
     sMsg = 'Please specify a Location prior to booking!';
  if (sMsg != '')
     alert(sMsg)
  else	
  {
    salesWin = window.open("http://www.canadream.com/rvSales/CdSalesP.dll/RVListing?Location="+document.getElementById('purchaseLocation').value, "BuyRV", "left=100, top=120, width=800, height=700, resizable=yes, toolbar=no, status=yes, scrollbars=yes, dependent=yes" ); 
    salesWin.focus();   
  }
}

function StartReservation(linkOptions, bkToolNo)
{
  var toolNo = '';
  if (bkToolNo) toolNo = bkToolNo;
  sMsg = ''; 
  sAgentId = '245';
  if (document.getElementById('AgentId') != null) {
     if (document.forms[0].AgentId.value > 0)
        sAgentId = document.forms[0].AgentId.value;  
  }
  if (document.getElementById('puLocation'+toolNo).value == '')  sMsg = 'Please specify a Pickup Location prior to booking!';
  else if (document.getElementById('puLocation'+toolNo).value == 'Select Location') sMsg = 'Please specify a Pickup Location prior to booking!';
  else if (document.getElementById('doLocation'+toolNo).value == '') sMsg = 'Please specify a Dropoff Location prior to booking!';
  else if (document.getElementById('doLocation'+toolNo).value == 'Select Location') sMsg = 'Please specify a Dropoff Location prior to booking!';
  else if (document.getElementById('WebDatePickup'+toolNo).value == '') sMsg = 'Please specify a Pickup Date prior to booking!';
  else if (document.getElementById('WebDateDropoff'+toolNo).value == '') sMsg = 'Please specify a Dropoff Date prior to booking!';
  if (sMsg != '')
     alert(sMsg)
  else	 
  {
      <!-- alert('PU = ' + PickupDateValue() + ' DO = ' + DropoffDateValue() + ' Nights = ' + TripNights()); -->
	  if (TripNights(toolNo) < MinDurationForDate(PickupDateValue(toolNo)))
	     window.alert(MinNightsWarning(toolNo));
	  else
	  {
        sParameters = "&PuLocation="+document.getElementById('puLocation'+toolNo).value + 
                      "&PuDate="+document.getElementById('WebDatePickup'+toolNo).value + 
		      "&DoLocation="+document.getElementById('doLocation'+toolNo).value + 
                      "&DoDate="+document.getElementById('WebDateDropoff'+toolNo).value;
	if (document.getElementById('Product'+toolNo) != undefined)
	   sParameters = sParameters + "&Product="+document.getElementById('Product'+toolNo).value;
        var sHostPath = 'http://www.canadream.com/webBook/CdWebP.dll/StartRes'; 
        if (linkOptions != null) 
    	   bkRVWin = window.open("http://www.canadream.com/webBook/CdWebP.dll/StartRes?Id=" + sAgentId + sParameters + linkOptions, "BookRV", "left=100, top=120, width=800, height=650, resizable=yes, toolbar=no, status=yes, scrollbars=yes, dependent=yes" ); 
        else  
	       bkRVWin = window.open(sHostPath+'?Id=' + sAgentId + sParameters, "BookRV", "left=100, top=120, width=800, height=650, resizable=yes, toolbar=no, status=yes, scrollbars=yes, dependent=yes" ); 
        bkRVWin.focus();   
	  }
   }
}

function StartNewBooking(sAgentId, linkOptions, bkToolNo)
{
  var toolNo = '';
  if (bkToolNo) toolNo = bkToolNo;
  sMsg = ''; 
  if (document.getElementById('AgentId') != null) {
     if (document.forms[0].AgentId.value > 0)
        sAgentId = document.forms[0].AgentId.value;  
  }
  if (document.getElementById('puLocation'+toolNo).value == '')  sMsg = 'Please specify a Pickup Location prior to booking!';
  else if (document.getElementById('puLocation'+toolNo).value == 'Select Location') sMsg = 'Please specify a Pickup Location prior to booking!';
  else if (document.getElementById('doLocation'+toolNo).value == '') sMsg = 'Please specify a Dropoff Location prior to booking!';
  else if (document.getElementById('doLocation'+toolNo).value == 'Select Location') sMsg = 'Please specify a Dropoff Location prior to booking!';
  else if (document.getElementById('WebDatePickup'+toolNo).value == '') sMsg = 'Please specify a Pickup Date prior to booking!';
  else if (document.getElementById('WebDateDropoff'+toolNo).value == '') sMsg = 'Please specify a Dropoff Date prior to booking!';
  if (sMsg != '')
     alert(sMsg)
  else	 
  {
       <!-- alert('PU = ' + PickupDateValue(toolNo) + ' DO = ' + DropoffDateValue(toolNo) + ' Nights = ' + TripNights(toolNo) + ' MinDuration='+MinDurationForDate(PickupDateValue(toolNo))); -->
	  if (TripNights(toolNo) < MinDurationForDate(PickupDateValue(toolNo)))
	     window.alert(MinNightsWarning(toolNo));
	  else
	  {
        sParameters = "&PickupLocId="+document.getElementById('puLocation'+toolNo).value + 
                      "&DatePickup="+document.getElementById('WebDatePickup'+toolNo).value + 
		              "&DropoffLocId="+document.getElementById('doLocation'+toolNo).value + 
                      "&DateDropoff="+document.getElementById('WebDateDropoff'+toolNo).value;
        if (linkOptions != null) 
    	   bkRVWin = window.open("http://www.canadream.com/CoraV3/CoraWeb.dll/NewBooking?AgentId=" + sAgentId + sParameters + linkOptions, "BookRV", "left=100, top=120, width=920, height=750, resizable=yes, toolbar=no, status=yes, scrollbars=yes, dependent=yes" ); 
        else  
	   bkRVWin = window.open("http://www.canadream.com/CoraV3/CoraWeb.dll/NewBooking?AgentId=" + sAgentId + sParameters, "BookRV", "left=100, top=120, width=920, height=750, resizable=yes, toolbar=no, status=yes, scrollbars=yes, dependent=yes" ); 
        bkRVWin.focus();   
	  }
   }
}

function flipMonthDay(dateStr) {
    var day = dateStr.substring(0, dateStr.indexOf("/"));
    dateStr = dateStr.substring(dateStr.indexOf("/") + 1);
    var month = dateStr.substring(0, dateStr.indexOf("/"));
    dateStr = dateStr.substring(dateStr.indexOf("/") + 1);
    var year = dateStr;

    var result = month + "/" + day + "/" + year;
    return result;
}

function SendServerMsg(url, callbackFnc) 
{
    // branch for native XMLHttpRequest object
    if (window.ActiveXObject) {
	var ua = navigator.userAgent.toLowerCase();
        if (ua.indexOf('msie 5') == -1)
           req = new ActiveXObject("Msxml2.XMLHTTP");
        else
           req = new ActiveXObject("Microsoft.XMLHTTP");	
        if (req) {
            req.onreadystatechange = callbackFnc; //processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
    else if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = callbackFnc; //processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } 
}
function PostServerMsg(url, params) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.open("POST", url, false);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
	    var ua = navigator.userAgent.toLowerCase();
        if (ua.indexOf('msie 5') == -1)
           req = new ActiveXObject("Msxml2.XMLHTTP");
        else
           req = new ActiveXObject("Microsoft.XMLHTTP");	
        if (req) {
            req.open("POST", url, false);
        }
    }
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    req.send(params);

    strResult=req.responseText;
}
function BookingToolCallback()
{
  if (req.readyState == 4) {
	 if (req.status == 200) {
	    var theToolNo = req.responseText.substring(0, 1); 
            var theHTML   = req.responseText.substring(1, req.responseText.length-1);
	    sDivTag = 'bookingtool';
	    if (theToolNo == '2')
	       sDivTag = 'booknowbottom';
	    if (is_ie) {
                   var container = document.getElementById(sDivTag);  		   
		   var newdiv = document.createElement("div");
		   newdiv.innerHTML = theHTML;
		   container.appendChild(newdiv); }
		else   
 	       document.getElementById(sDivTag).innerHTML = theHTML;
	 }
  }	
}
function BookingToolCallback2()
{
  if (req2.readyState == 4) {
	 if (req2.status == 200) {
	    var theToolNo = req2.responseText.substring(0, 1); 
            var theHTML   = req2.responseText.substring(1, req2.responseText.length-1);
	    sDivTag = 'bookingtool';
	    if (theToolNo == '2')
	       sDivTag = 'booknowbottom';
	    if (is_ie) {
                   var container = document.getElementById(sDivTag);  		   
		   var newdiv = document.createElement("div");
		   newdiv.innerHTML = theHTML;
		   container.appendChild(newdiv); }
 	    else   
 	       document.getElementById(sDivTag).innerHTML = theHTML;
	 }
  }	
}
function GenBookingToolContent(forDealershipId, forAgentId, forPkgId, withOrientation, bkToolNumber)
{
  var d = new Date();
  var theTime = d.getTime();
   sParams = 'AgentId='+forAgentId+'&Orientation='+withOrientation+'&ToolNumber='+bkToolNumber+'&TS='+theTime;
   if (forPkgId > 0)
      sParams = sParams + '&PkgId=' + forPkgId;
   var sHostPath = 'http://'+currentHost+'/webBook/CdWebP.dll/BookingTool?'; 
   if (bkToolNumber == 2)
      SendServerMsg2(sHostPath+sParams, BookingToolCallback2); 
   else
      SendServerMsg(sHostPath+sParams, BookingToolCallback);
}

