var isHotel	=	false;
var isAir = false;
function OpenWindow(file, name, width, height)
{
	OpenWindow(file, name, width, height, false);
}

function OpenWindow(file, name, width, height, showLeftTopScrollbar)
{
	var attr = "";
	if(showLeftTopScrollbar) {
		attr += "top=50,left=50,scrollbars=1,";
	}
	attr += "width=" + width + ",height=" + height + ",resizeable=1";
	window.open(file, name, attr);
}

function openWin(fileName)
{
   thor = window.open(fileName,'thor','top=200,left=220,width=275,height=450,resizable=1,scrollbars=yes');
}

function openWindow(fileName)
{
   thor = window.open(fileName,'thor','top=200,left=220,width=275,height=450,resizable=1,scrollbars=yes');
}

function movepic(img_name,img_src)
{
	document[img_name].src=img_src;
}


function lookupDepart(tripType){
  var x, y;
  var element = document.forms[1].from;
  if (document.layers) {
    x = element.x + window.screenX + window.outerWidth - window.innerWidth;
    y = element.y + window.screenY + window.outerHeight - window.innerHeight;
  }
  else if (document.all) {
    var coords = getPageCoords(element);
    x = coords.x + window.screenLeft + 130;
    y = coords.y + window.screenTop + 60;
  	y = y - 200;
  }
  else if (document.getElementById) {
    var coords = getPageCoords(element);
    x = coords.x + window.screenX + window.outerWidth - window.innerWidth;
    y = coords.y + window.screenY + window.outerHeight - window.innerHeight;
	y = y - 28;
  }
  x = x - 5;
  y = y + 19;
  if(navigator.appName=="Netscape")
	{
		x = x + 140;
		y = y - 120;
	}
  window.open('/htdocs/ng/fromairportcodes.html?trip='+tripType, 'AirportCodes', 'left=' + x
        + ',top=' + y + ',width=250,height=500,scrollbars,resizable');

}

function lookupReturn(tripType){
  var x, y;
  var element = document.forms[1].to;
  if (document.layers) {
    x = element.x + window.screenX + window.outerWidth - window.innerWidth;
    y = element.y + window.screenY + window.outerHeight - window.innerHeight;
  }
  else if (document.all) {
    var coords = getPageCoords(element);
    x = coords.x + window.screenLeft + 5;
    y = coords.y + window.screenTop + 130;
  	y = y - 130;
  }
  else if (document.getElementById) {
    var coords = getPageCoords(element);
    x = coords.x + window.screenX + window.outerWidth - window.innerWidth;
    y = coords.y + window.screenY + window.outerHeight - window.innerHeight;
	y = y - 28;
  }
  x = x - 280;
  y = y - 120;
  if(navigator.appName=="Netscape")
  {
	   x = x - 5;
	   y = y + 19;
  }
  window.open('/htdocs/ng/toairportcodes.html?trip='+tripType, 'AirportCodes', 'left=' + x
        + ',top=' + y + ',width=250,height=500,scrollbars,resizable');
}

function getPageCoords (element) {
  var coords = {x: 0, y: 0};
  while (element) {
    coords.x += element.offsetLeft;
    coords.y += element.offsetTop;
    element = element.offsetParent;
  }
  return coords;
}


function departchanged(airForm)
{
	var today = new Date();
	var mon = airForm.depmon.value;
	var day = airForm.depdat.value;
	var year = today.getFullYear();
	// modified to fix problems with 2008
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}

	//var newdat = new Date();
	//newdat.setMonth(mon-1);
	//newdat.setDate(day);
	//newdat.setYear(year);
	var newdat = new Date(mon+"/"+day+"/"+year);
	var field = getElement("depart_input");
	field.value = newdat.print("%m/%d/%Y");
}

function returnchanged(airForm)
{
	var today = new Date();
	var mon = airForm.retmon.value;
	var day = airForm.retdat.value;
	var year = today.getFullYear();
	// modified to fix problems with 2008
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}

	//var newdat = new Date();
	//newdat.setMonth(mon-1);
	//newdat.setDate(day);
	//newdat.setYear(year);
    var newdat = new Date(mon+"/"+day+"/"+year);
	var field = getElement("return_input");
	field.value = newdat.print("%m/%d/%Y");
}

function pickupchanged(carForm)
{
	var today = new Date();
	var mon = carForm.pickUpMonth.value;
	var day = carForm.pickUpDay.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}

	var newdat = new Date();
	newdat.setMonth(mon);
	newdat.setDate(day);
	newdat.setYear(year);
	var field = getElement("pickup_input");
	field.value = newdat.print("%m/%d/%Y");
}

function dropoffchanged(carForm)
{
	var today = new Date();
	var mon = carForm.dropOffMonth.value;
	var day = carForm.dropOffDay.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}

	var newdat = new Date();
	newdat.setMonth(mon);
	newdat.setDate(day);
	newdat.setYear(year);
	var field = getElement("dropoff_input");
	field.value = newdat.print("%m/%d/%Y");
}

function checkinchanged(hotForm)
{
	var today = new Date();
	var mon = hotForm.checkinMonth.value;
	var day = hotForm.checkinDay.value;
	
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}

//	var newdat = new Date();
//	newdat.setMonth(mon);
//	newdat.setDate(day);
//	newdat.setYear(year);
//	var field = getElement("checkin_input");
//	field.value = newdat.print("%m/%d/%Y");
//
	var newdat = new Date(mon+"/"+day+"/"+year);
	//var field = getElement("checkin_input");
	//field.value = newdat.print("%m/%d/%Y");
	hotForm.checkin_input.value = newdat.print("%m/%d/%Y");
}
function air_checkinchanged(hotForm)
{
	var today = new Date();
	var mon = hotForm.air_checkinMonth.value;
	var day = hotForm.air_checkinDay.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}

//	var newdat = new Date();
//	newdat.setMonth(mon);
//	newdat.setDate(day);
//	newdat.setYear(year);
//	var field = getElement("checkin_input");
//	field.value = newdat.print("%m/%d/%Y");
//
	var newdat = new Date(mon+"/"+day+"/"+year);
	var field = getElement("checkin_input");
	field.value = newdat.print("%m/%d/%Y");
}
function checkoutchanged(hotForm)
{
	var today = new Date();
	var mon = hotForm.checkoutMonth.value;
	var day = hotForm.checkoutDay.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}

//	var newdat = new Date();
//	newdat.setMonth(mon);
//	newdat.setDate(day);
//	newdat.setYear(year);
//	var field = getElement("checkout_input");
//	field.value = newdat.print("%m/%d/%Y");
	var newdat = new Date(mon+"/"+day+"/"+year);
	//var field = getElement("checkout_input");
	//field.value = newdat.print("%m/%d/%Y");
    hotForm.checkout_input.value = newdat.print("%m/%d/%Y");
	
}

function air_checkoutchanged(hotForm)
{
	var today = new Date();
	var mon = hotForm.air_checkoutMonth.value;
	var day = hotForm.air_checkoutDay.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}

//	var newdat = new Date();
//	newdat.setMonth(mon);
//	newdat.setDate(day);
//	newdat.setYear(year);
//	var field = getElement("checkout_input");
//	field.value = newdat.print("%m/%d/%Y");
	var newdat = new Date(mon+"/"+day+"/"+year);
	var field = getElement("checkout_input");
	field.value = newdat.print("%m/%d/%Y");
}
function getElement(divID)
{
    if(document.layers){ //netscape 4+
       return document.layers[divID];
    } else if(document.getElementById) { //netscape 6 internetExplorer 5+
        return document.getElementById(divID);
    } else {    //Internet Explorer 4
        return document.document.all[divID];
    }
}


function flipTabs(tabIndex)
{
	var imageName = '/images/searchtop' + tabIndex + '.gif' ;
	movepic('tabimage',imageName);
	if(tabIndex == 0){
	 isAir = true;
	 isHotel=false;
		displayAir();}
	else if(tabIndex == 1){isHotel=false; isAir = false;
		displayCar();}
	else if(tabIndex == 2){isHotel=true;isAir= false;
		displayHotel();}
		putFocus();
//	return false;
}

function toggleDiv(divID, state){
    if(document.layers){ //netscape 4+

       document.layers[divID].visibility = state ? "show" : "hide";
       document.layers[divID].display = state ? "block" : "none";

    } else if(document.getElementById) { //netscape 6 internetExplorer 5+

        document.getElementById(divID).style.visibility = state ? "visible" : "hidden";
        document.getElementById(divID).style.display = state ? "block" : "none";

    } else {    //Internet Explorer 4

        document.all[divID].style.visibility = state ? "visible" : "hidden";
        document.all[divID].style.display = state ? "block" : "none";

    }
}

function statusDiv(divID){
	var status = "hidden";
    if(document.layers){ //netscape 4+
       status = document.layers[divID].visibility=='show'? "visible" : "hidden";
    } else if(document.getElementById) { //netscape 6 internetExplorer 5+
        status = document.getElementById(divID).style.visibility;;
    } else {    //Internet Explorer 4
        status = document.all[divID].style.visibility;
    }
    return status;
}


function displayHotel(){

	toggleDiv('hoteltab', 1);
	toggleDiv('cartab', 0);
	toggleDiv('airtab', 0);

	
}
function displayCar(){
	toggleDiv('hoteltab', 0);
	toggleDiv('cartab', 1);
	toggleDiv('airtab', 0);
}
function displayAir(){
	toggleDiv('hoteltab', 0);
	toggleDiv('cartab', 0);
	toggleDiv('airtab', 1);
}

// Air form related functionality

var aDateArray = new Array();
aDateArray[0]="Jan";
aDateArray[1]="Feb";
aDateArray[2]="Mar";
aDateArray[3]="Apr";
aDateArray[4]="May";
aDateArray[5]="Jun";
aDateArray[6]="Jul";
aDateArray[7]="Aug";
aDateArray[8]="Sep";
aDateArray[9]="Oct";
aDateArray[10]="Nov";
aDateArray[11]="Dec";

var swDateArray = new Array();
swDateArray[0]="None";
swDateArray[1]="January";
swDateArray[2]="February";
swDateArray[3]="March";
swDateArray[4]="April";
swDateArray[5]="May";
swDateArray[6]="June";
swDateArray[7]="July";
swDateArray[8]="August";
swDateArray[9]="September";
swDateArray[10]="October";
swDateArray[11]="November";
swDateArray[12]="December";


var date = new Date();
var todayDateVal = new Date();
todayDateVal.setDate(todayDateVal.getDate()-1);
todayDateVal.setHours(23);
todayDateVal.setMinutes(59);
todayDateVal.setSeconds(59);
function validateAir(aForm)
{
   

	   if(aForm.hd_from.value == "" || aForm.hd_from.value == null)
	   {
	   	aForm.hd_from.value=aForm.from.value;
	   }
	
	   
	   if(aForm.hd_to.value == "" || aForm.hd_to.value == null)
	   {
	   		aForm.hd_to.value=aForm.to.value;
	   }
    aForm.IsItCompleteIte.value = "COMPLETE";
    aForm.Depart.value = aForm.depmon.value + '/' +
    					 aForm.depdat.value + '/' +
    					 aForm.depyear.value;

    aForm.Return.value = aForm.retmon.value + '/' +
    					 aForm.retdat.value + '/' +
    					 aForm.retyear.value;

	departchanged(aForm); //for Dec'05 to jan 06 search failures
	returnchanged(aForm);	
	if(new Date(aForm.Depart.value) > new Date(aForm.Return.value))
	{ 
		alert("The return date is prior to the today's date.\n" +
				  "Please enter a valid return date.");
			//aForm.Return.focus();
			return false;

	}
    if(new Date(aForm.Depart.value) < todayDateVal )
	{ 
		alert("The departure date is prior to today's date.\n" +
				  "Please enter a valid departure date.");		
            //aForm.Depart.focus();
			return false;

	}

   if(new Date(aForm.Return.value)  < todayDateVal )
	{ 
		alert("The return date is prior to the today's date.\n" +
				  "Please enter a valid return date.");
			//aForm.Return.focus();
			return false;

	}

    if(strTrim(aForm.from.value) == "" || aForm.from.value==null){
		alert("Please enter a valid departure airport name/code.");
		//aForm.from.focus();
		return false;
	}
	else if(strTrim(aForm.to.value) == "" || aForm.to.value==null){
		alert("Please enter a valid going to airport name/code.");
		//aForm.to.focus();
		return false;
	}
	else if(strTrim(aForm.from.value) == strTrim(aForm.to.value))
	{
	alert("The departure and return cities are same. Please enter a valid city name/code.");
		aForm.from.value="";
			aForm.to.value="";
			aForm.from.focus();
		return false;	
	}

	else if(strTrim(aForm.Depart.value) == "" || aForm.Depart.value==null){
			alert("Please enter a valid departure date.");
			//aForm.Depart.focus();
			return false;
	}
	else if(strTrim(aForm.Return.value) == "" || aForm.Return.value==null){
				alert("Please enter a valid return date.");
				//aForm.Return.focus();
				aForm.from.focus();
				return false;
	}

	if(!validDate(aForm.Depart.value))
	{
		alert("Please enter a valid departure date.");
		//aForm.DepartLegMonth.focus();
		//aForm.Depart.focus();
		aForm.from.focus();
		return false;
	}
	else if(!validDate(aForm.Return.value))
	{
		alert("Please enter a valid return date.");
		//aForm.ReturnLegMonth.focus();
		//aForm.Return.focus();
		return false;
        }
        else if(!isDatesOK(aForm.Depart.value,aForm.Return.value,"/"))
		{
			alert("The return date is prior to the departure date.\n" +
				  "Please enter a valid return date.");
			//aForm.Return.focus();
			aForm.to.focus();
			return false; 
        }

        else if(!CompareDates(aForm.Depart.value,aForm.Return.value,"/"))
        {
            	alert("Flights are available for up to 330 days in advance.\n" +
            	      "The date you entered exceeds this number of days.");
            	//aForm.DepartLegMonth.focus();
            	//aForm.Depart.focus();
            	aForm.from.focus();
		return false;
    }
	
    else
    {
    	aForm.from.value =spaceTrim(aForm.from.value);
    	aForm.to.value =spaceTrim(aForm.to.value);

    	aForm.dateDifferenceValue.value = datesDifference(aForm.Depart.value, "/");
    	aForm.from.value = aForm.from.value.toUpperCase();
        aForm.to.value = aForm.to.value.toUpperCase();
		aForm.SendRequestTo.value = "SITE_1";
		aForm.departCity.value = aForm.from.value;
		aForm.arriveCity.value = aForm.to.value;
		aForm.fromMonth.value = getOrbFromMonthFormat(aForm.Depart.value);
		aForm.fromDate.value = aForm.Depart.value.substring(3,5);
		aForm.toMonth.value = getOrbToMonthFormat(aForm);
		aForm.toDate.value = aForm.Return.value.substring(3,5);
		aForm.exSessFromDate.value = getExSessDate(aForm.Depart.value);
		aForm.exSessToDate.value= getExSessDate(aForm.Return.value);
		aForm.num_fromDate.value = parseInt(aForm.Depart.value.substring(3,5),10);
		aForm.num_toDate.value = parseInt(aForm.Return.value.substring(3,5),10);
		aForm.num_fromMonth.value = parseInt(aForm.Depart.value.substring(0,2),10);
		aForm.num_toMonth.value = parseInt(aForm.Return.value.substring(0,2),10);
		aForm.fstr_fromMonth.value = getFullMonthName(parseInt(aForm.Depart.value.substring(0,2),10));
		aForm.fstr_toMonth.value = getFullMonthName(parseInt(aForm.Return.value.substring(0,2),10));

		//Please do not change the variable names.
		agentID="23979";
		subAgentID="268";
		agentEmail="jafri@excambria.com";

		aForm.AgentID.value = agentID;
		aForm.SubAgentID.value = subAgentID;
		aForm.AgentEmail.value = agentEmail;
		aForm.dep_from.value = aForm.from.value;
		aForm.dep_to.value = aForm.to.value;
		aForm.ret_from.value = aForm.to.value;
		aForm.ret_to.value = aForm.from.value;
		aForm.dep_month.value = aForm.Depart.value.substring(0,2);
		aForm.dep_day.value = aForm.Depart.value.substring(3,5);
		aForm.dep_year.value = aForm.Depart.value.substring(6);
		aForm.ret_month.value = aForm.Return.value.substring(0,2);
		aForm.ret_day.value = aForm.Return.value.substring(3,5);
		aForm.ret_year.value = aForm.Return.value.substring(6);
		if(aForm.air_class.options[aForm.air_class.selectedIndex].value=="economy")
		{
			aForm.simpleclass.value="Economy";
		}
		else
		{
			aForm.simpleclass.value="BusFirst";
		}
		if(aForm.regionalsearch.checked)
		{
			aForm.regionalsearch.value="true";
		}
		else
		{
			aForm.regionalsearch.value="false";
		}
		
		aForm.adultno.value=aForm.pax_count.options[aForm.pax_count.selectedIndex].value;
		return true;
    }
}

function strTrim(sParseString){
	var sResultString = "";
	var nCount=0;
	for(nCount=0;nCount<sParseString.length;nCount++){
		if(sParseString.charAt(nCount) != "" && sParseString.charAt(nCount) != " "){
			sResultString = sResultString + sParseString.charAt(nCount);
		}
	}
	return sResultString;
}

function validDate(inputDate) {
	 
	   
	   var returnValue=true;
     
          if (inputDate == "") return returnValue = false;

          if (inputDate.length != 10)
			{  
		
				returnValue = false;
			}

		 
          if (returnValue){
          var inputMonth = inputDate.substring(0, 2);       // month
          var firstDelimeter = inputDate.substring(2, 3);    // '/'
          var inputDay = inputDate.substring(3, 5);         // day
          var secondDelimeter = inputDate.substring(5, 6);  // '/'
          var inputYear = inputDate.substring(6, 10);       // year
		
		 
         
          inputMonth = parseInt(inputMonth, 10);
          inputDay = parseInt(inputDay, 10);
          inputYear = parseInt(inputYear, 10);
          
		 
		  if (isNaN(inputMonth))
              returnValue = false;

          if (isNaN(inputDay))
              returnValue = false;

          if (isNaN(inputYear))
              returnValue = false;
          

          if (firstDelimeter != '/')
               returnValue = false;

          if (secondDelimeter != '/')
               returnValue = false;

          if (inputMonth < 1 || inputMonth > 12) returnValue = false;

          if (inputDay < 1 || inputDay > 31) returnValue = false;

          if (inputYear < 999) returnValue = false;

          if (inputMonth == 4 || inputMonth == 6 ||
              inputMonth == 9 || inputMonth == 11){
             if (inputDay ==31) returnValue = false;
          }

          if (inputMonth == 2){
             if (isNaN(inputYear)) {
                returnValue = false;
             }

             if (inputDay > 29)
                 returnValue=false;

             if (inputDay == 29){
                   if (!(inputYear%400 == 0 || (inputYear%4 ==0 && inputYear%100 != 0)))
                      returnValue = false;
             }
          }
	}

	

   	return returnValue;
}

function isDatesOK(strFirstDate,strSecondDate,strDelimiter)
{
	var curDate,firstDate,secondDate,dd,mm,yy;
	var difference;
	curDate = new Date();
	firstDate = strFirstDate.split(strDelimiter);
	mm = firstDate[0];
	dd = firstDate[1];
	yy = firstDate[2];
	firstDate = new Date(yy,mm-1,dd);
	secondDate = strSecondDate.split(strDelimiter);
	mm = secondDate[0];
	dd = secondDate[1];
	yy = secondDate[2];
	secondDate = new Date(yy,mm-1,dd);
	if (firstDate > secondDate){return false;}
	else{return true;}
}

function CompareDates(strFirstDate,strSecondDate,strDelimiter)
{
	var curDate,firstDate,secondDate,dd,mm,yy;
	var difference;
	curDate = new Date();
	firstDate = strFirstDate.split(strDelimiter);
	mm = firstDate[0];
	dd = firstDate[1];
	yy = firstDate[2];
	firstDate = new Date(yy,mm-1,dd);
	secondDate = strSecondDate.split(strDelimiter);
	mm = secondDate[0];
	dd = secondDate[1];
	yy = secondDate[2];
	secondDate = new Date(yy,mm-1,dd);
	difference = firstDate.getTime() - curDate.getTime();
	difference = Math.floor(difference / (1000 * 60 * 60 * 24));
	if(parseInt(difference,10)>=330){return false;}
	difference = secondDate.getTime() - curDate.getTime();
	difference = Math.floor(difference / (1000 * 60 * 60 * 24));
	if(parseInt(difference,10)>=330){return false;}
	else{return true;}
}

function spaceTrim(s)
{
	// Remove leading spaces and carriage returns
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	{
		s = s.substring(1,s.length);
	}

	// Remove trailing spaces and carriage returns
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	{
		s = s.substring(0,s.length-1);
	}
	return s;
}

function datesDifference(strFirstDate,strDelimiter)
{
	var curDate,firstDate,dd,mm,yy;
	var difference;
	curDate = new Date();
	firstDate = strFirstDate.split(strDelimiter);
	mm = firstDate[0];
	dd = firstDate[1];
	yy = firstDate[2];
	firstDate = new Date(yy,mm-1,dd);
	difference = firstDate.getTime() - curDate.getTime();
	difference = Math.floor(difference / (1000 * 60 * 60 * 24))+1;
	return difference;
}

function getOrbFromMonthFormat(aDate)
{
    var year = parseInt(aDate.substring(6),10);
    var d = new Date();
    var curYear = parseInt(d.getFullYear(),10);
    var ei = parseInt(aDate.substring(0,2),10);
    var mm = aDateArray[(ei-1)];
    if(year>curYear)
        return mm + " " + year;
    return mm;

}

function getOrbToMonthFormat(aForm)
{
    var fromYear = parseInt(aForm.Depart.value.substring(6),10);
    var toYear = parseInt(aForm.Return.value.substring(6),10);
    var ei = parseInt(aForm.Return.value.substring(0,2),10);
    var mm = aDateArray[(ei-1)];
    if(toYear>fromYear)
        return mm + " " + toYear;
    return getOrbFromMonth(aForm.Return.value);
}

function getOrbFromMonth(aDate)
{
    var year = parseInt(aDate.substring(6),10);
    var d = new Date();
    var curYear = parseInt(d.getFullYear(),10);
    var ei = parseInt(aDate.substring(0,2),10);    
    var mm = aDateArray[(ei-1)];    
    if(year>curYear)
        return mm + " " + year;
    return mm;
    
}

function getExSessDate(aVal)
{
    var dd = parseInt(aVal.substring(3,5),10);
    var ei = parseInt(aVal.substring(0,2),10);
    var mm = aDateArray[(ei-1)];
    return mm + " " + dd;
}

function getFullMonthName(aNum)
{
	return swDateArray[aNum];
}

function putFocus()
{
	var d = new Date();
	var curDate = parseInt(d.getDate(),10);
	d.setDate(curDate + 14);
	
	var d2 = new Date();
	var curDate2 = parseInt(d2.getDate(),10);
	d2.setDate(curDate2 + 21);
// AIR form
if(isAir==false)
{
	
	curDate = parseInt(d.getDate(),10);
	var curMonth = parseInt(d.getMonth(),10)+1;
	var fy=parseInt(d.getFullYear(),10);
	var ry=parseInt(d.getFullYear(),10);

	
	curDate2 = parseInt(d2.getDate(),10);
	var curMonth2 = parseInt(d2.getMonth(),10)+1;
	var fy2=parseInt(d2.getFullYear(),10);
	var ry2=parseInt(d2.getFullYear(),10);

	var curDateStr = curDate;
	if(curDate < 10){
		curDateStr = "0"+curDateStr;
	}
	var currMonStr = curMonth;
	if(curMonth < 10){
		currMonStr = "0"+currMonStr;
	}

	var depHdn = getElement("depart_input");
	depHdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	var depMon = getElement("dmon_sel");
	var depDat = getElement("ddat_sel");
	depDat.selectedIndex = d.getDate()-1;
	depMon.selectedIndex = d.getMonth();

	var currMonStr2 = curMonth2;
	if(curMonth2 < 10){
		currMonStr2 = "0"+currMonStr2;
	}
	var curDateStr2 = curDate2;
	if(curDate2 < 10){
		curDateStr2 = "0"+curDateStr2;
	}
	var retHdn = getElement("return_input");
	retHdn.value = currMonStr2+"/"+curDateStr2+"/"+fy2;
	var retMon = getElement("rmon_sel");
	var retDat = getElement("rdat_sel");
	retDat.selectedIndex = d2.getDate()-1;
	retMon.selectedIndex = d2.getMonth();
	document.MultiSite.Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.MultiSite.Return.value = currMonStr2+"/"+curDateStr2+"/"+fy2;
 }

// CAR form
    var pudate = d;
    var puMon = getElement("pumon_sel");
    var puDat = getElement("pudat_sel");
    puDat.selectedIndex = pudate.getDate()-1;
    puMon.selectedIndex = pudate.getMonth();

    var dodate = d2;
    var doMon = getElement("domon_sel");
    var doDat = getElement("dodat_sel");
    doDat.selectedIndex = dodate.getDate()-1;
    doMon.selectedIndex = dodate.getMonth();
    
    var field1 = getElement("pickup_input");
    field1.value = pudate.print("%m/%d/%Y");
    var field2 = getElement("dropoff_input");
    field2.value = dodate.print("%m/%d/%Y");
    
// HOTEL form
	if(isHotel==false){
    var cidate = d;
    var ciMon = getElement("cimon_sel");
    var ciDat = getElement("cidat_sel");
    
    if(ciDat != null)
    	ciDat.options[(cidate.getDate()-1)].selected = true;
  //  	ciDat.selectedIndex = cidate.getDate()-1;
    if(ciMon != null)
  	ciMon.options[cidate.getMonth()].selected = true;
   // 	ciMon.selectedIndex = cidate.getDate()-1;


	var d3 = new Date();
	var curDate3 = parseInt(d3.getDate(),10);
	d3.setDate(curDate3 + 16);
	curDate3 = parseInt(d3.getDate(),10);
	var curMonth3 = parseInt(d3.getMonth(),10)+1;
	var fy3=parseInt(d3.getFullYear(),10);
	var ry3=parseInt(d3.getFullYear(),10);
	
	
    var codate = d3;
    var coMon = getElement("comon_sel");
    var coDat = getElement("codat_sel");
    if(coDat != null)
        coDat.options[(codate.getDate()-1)].selected = true;
    if(coMon != null)
    	coMon.options[codate.getMonth()].selected = true;
    	
    var field3 = getElement("checkin_input");
    field3.value = cidate.print("%m/%d/%Y");
    var field4 = getElement("checkout_input");
    field4.value = codate.print("%m/%d/%Y");
    }
    
}

function putCarAndHotelFocus()
{
	var d = new Date();
	var curDate = parseInt(d.getDate(),10);
	d.setDate(curDate + 14);
	curDate = parseInt(d.getDate(),10);
	var curMonth = parseInt(d.getMonth(),10)+1;
	var fy=parseInt(d.getFullYear(),10);
	var ry=parseInt(d.getFullYear(),10);

	var d2 = new Date();
	var curDate2 = parseInt(d2.getDate(),10);
	//d2.setDate(curDate2 + 21);
	d2.setDate(curDate2 + 16);
	curDate2 = parseInt(d2.getDate(),10);
	var curMonth2 = parseInt(d2.getMonth(),10)+1;
// CAR form
    var pudate = d;
    var puMon = getElement("pumon_sel");
    var puDat = getElement("pudat_sel");
    puDat.selectedIndex = pudate.getDate()-1;
    puMon.selectedIndex = pudate.getMonth();

    var dodate = d2;
    var doMon = getElement("domon_sel");
    var doDat = getElement("dodat_sel");
    doDat.selectedIndex = dodate.getDate()-1;
    doMon.selectedIndex = dodate.getMonth();
    
    var field1 = getElement("pickup_input");
    field1.value = pudate.print("%m/%d/%Y");
    var field2 = getElement("dropoff_input");
    field2.value = dodate.print("%m/%d/%Y");
    
// HOTEL form
    var cidate = d;
    var ciMon = getElement("cimon_sel");
    var ciDat = getElementById("cidat_sel");
   

    if(ciDat != null)
    	ciDat.options[(cidate.getDate()-1)].selected = true;
    if(ciMon != null)
    	ciMon.options[cidate.getMonth()].selected = true;

    var codate = d2;
    var coMon = getElement("comon_sel");
    var coDat = getElement("codat_sel");
    if(coDat != null)
        coDat.options[(codate.getDate()-1)].selected = true;
    if(coMon != null)
    	coMon.options[codate.getMonth()].selected = true;
    	
    var field3 = getElement("checkin_input");
    field3.value = cidate.print("%m/%d/%Y");
    var field4 = getElement("checkout_input");
    field4.value = codate.print("%m/%d/%Y");
}


function setIntialdateHotel()
{
 var d = new Date();
	var curDate = parseInt(d.getDate(),10);
	d.setDate(curDate + 14);
	curDate = parseInt(d.getDate(),10);
	var curMonth = parseInt(d.getMonth(),10)+1;
	var fy=parseInt(d.getFullYear(),10);
	var ry=parseInt(d.getFullYear(),10);
	var d2 = new Date();
	var curDate2 = parseInt(d2.getDate(),10);
	//d2.setDate(curDate2 + 21);
	d2.setDate(curDate2 + 16);
	curDate2 = parseInt(d2.getDate(),10);
	var curMonth2 = parseInt(d2.getMonth(),10)+1;
	
	// HOTEL form
    var cidate = d;
    var ciMon = getElement("cimon_sel");
    var ciDat = getElement("cidat_sel");
   

    if(ciDat != null)
    	ciDat.options[(cidate.getDate()-1)].selected = true;
    if(ciMon != null)
    	ciMon.options[cidate.getMonth()].selected = true;

    var codate = d2;
    var coMon = getElement("comon_sel");
    var coDat = getElement("codat_sel");
    if(coDat != null)
        coDat.options[(codate.getDate()-1)].selected = true;
    if(coMon != null)
    	coMon.options[codate.getMonth()].selected = true;
    	
    var field3 = getElement("checkin_input");
    field3.value = cidate.print("%m/%d/%Y");
    var field4 = getElement("checkout_input");
    field4.value = codate.print("%m/%d/%Y");
}
function setHotelYear()
{

	


	var d1 = new Date();
	document.hotForm.checkinyear.value=d1.getFullYear();
	document.hotForm.checkoutyear.value=d1.getFullYear();
	
	
	
	
	
	
}
function validateHotel(aForm)
{
		setHotelYear();
	   if(aForm.citycode.value == "" || aForm.citycode.value == null)
	  {
	      aForm.citycode.value=aForm.city.value;
	  }
  
	aForm.check_in.value = aForm.checkinMonth.value + '/' +	 aForm.checkinDay.value + '/' + aForm.checkinyear.value;
	aForm.check_out.value = aForm.checkoutMonth.value + '/' + aForm.checkoutDay.value + '/' + aForm.checkoutyear.value; 
	checkinchanged(aForm); //for Dec'05 to jan 06 search failures
	checkoutchanged(aForm);	
	
	if(new Date(aForm.check_in.value) > new Date(aForm.check_out.value))
	{ 
		alert("Check out date is prior to Check in date.\n" +
				  "Please enter a valid Check out date.");
			
			return false;

	}
    if(new Date(aForm.check_in.value) < todayDateVal )
	{ 
		alert("Check in date is prior to the today's date.\n" +
				  "Please enter a valid Check In date.");		
           
			return false;

	}

   if(new Date(aForm.check_out.value)  < todayDateVal )
	{ 
		alert("Check out date is prior to the today's date.\n" +
				  "Please enter a valid Check out date.");
			
			return false;

	}

  if(strTrim(aForm.citycode.value) == "" || aForm.citycode.value==null)
   {
		alert("Please enter a valid city name/code.");
		aForm.city.focus();
		return false;
	}
	


	else if(strTrim(aForm.check_in.value) == "" || aForm.check_in.value==null)
		{
		   			
			aForm.check_in.focus();
			return false;
	}
	else if(strTrim(aForm.check_out.value) == "" || aForm.check_out.value==null){
				alert("Please enter a valid checkout date.");
				aForm.check_out.focus();
				return false;
	}


	if(!validDate(aForm.check_in.value))
	{
		alert("Please Enter valid Check in date"); 
		//aForm.DepartLegMonth.focus();
		aForm.check_in.focus();
		return false;
	}
	else if(!validDate(aForm.check_out.value))
	{
		alert("Please enter a valid Check Out date.");
		aForm.check_out.focus();
		return false;
        }
        else if(!isDatesOK(aForm.check_in.value,aForm.check_out.value,"/"))
		{
			alert("Check out  date is prior to Check In date.\n" +
				  "Please enter a valid check Out date.");
			aForm.check_out.focus();
			return false; 
        }

        else if(!CompareDates(aForm.check_in.value,aForm.check_out.value,"/"))
        {
            	alert("Hotels are available for up to 330 days in advance.\n" +
            	      "The date you entered exceeds this number of days.");
            	//aForm.DepartLegMonth.focus();
        	aForm.check_in.focus();
		return false;
    }

	
	
   return true;
}


function ad_validateHotel(aForm)
{
		
		
	
	    if(aForm.citycode.value == "" || aForm.cityName.value == null)
	   {
	       aForm.citycode.value=aForm.cityName.value;
	   }

	aForm.check_in.value = aForm.checkinMonth.value + '/' +	 aForm.checkinDay.value + '/' + aForm.checkinyear.value;
	aForm.check_out.value = aForm.checkoutMonth.value + '/' + aForm.checkoutDay.value + '/' + aForm.checkoutyear.value; 
	checkinchanged(aForm); //for Dec'05 to jan 06 search failures
	checkoutchanged(aForm);	
	if(new Date(aForm.check_in.value) > new Date(aForm.check_out.value))
	{ 
		alert("Check Out date is prior to Check in date.\n" +
				  "Please enter a valid Check out date.");
			//aForm.Return.focus();
			return false;

	}
    if(new Date(aForm.check_in.value) < todayDateVal )
	{ 
		alert("Check in date is prior to the today's date.\n" +
				  "Please enter a valid Check In date.");		
            //aForm.Depart.focus();
			return false;

	}

   if(new Date(aForm.check_out.value)  < todayDateVal )
	{ 
		alert("Check out date is prior to the today's date.\n" +
				  "Please enter a valid Check out date.");
			//aForm.Return.focus();
			return false;

	}

/*    if(strTrim(aForm.citycode.value) == "" || aForm.citycode.value==null)
   {
		alert("Please enter a valid City  Name/Code.");
		aForm.city.focus();
		return false;
	}*/
	


	else if(strTrim(aForm.check_in.value) == "" || aForm.check_in.value==null)
		{
			alert("Please enter a valid check In date.");
			aForm.check_in.focus();
			return false;
	}
	else if(strTrim(aForm.check_out.value) == "" || aForm.check_out.value==null){
				alert("Please enter a valid  checkout date.");
				aForm.check_out.focus();
				return false;
	}

	if(!validDate(aForm.check_in.value))
	{
		alert("Please enter a valid Check In date.");
		//aForm.DepartLegMonth.focus();
		aForm.check_in.focus();
		return false;
	}
	else if(!validDate(aForm.check_out.value))
	{
		alert("Please enter a valid Check Out date.");
		//aForm.ReturnLegMonth.focus();
		aForm.check_out.focus();
		return false;
        }
        else if(!isDatesOK(aForm.check_in.value,aForm.check_out.value,"/"))
		{
			alert("Check out  date is prior to Check In date.\n" +
				  "Please enter a valid check Out date.");
			aForm.check_out.focus();
			return false; 
        }

        else if(!CompareDates(aForm.check_in.value,aForm.check_out.value,"/"))
        {
            	alert("Hotels are available for up to 330 days in advance.\n" +
            	      "The date you entered exceeds this number of days.");
            	//aForm.DepartLegMonth.focus();
            	aForm.check_in.focus();
		return false;
    }
	
   return true;
}


function air_validateHotel(aForm)
{
		
	 		
   if(aForm.citycode.value == "" || aForm.cityName.value == null)
	   {
	       aForm.citycode.value=aForm.air_cityName.value;
	   }
//	aForm.check_in.value = aForm.air_checkinMonth.value + '/' +	 aForm.air_checkinDay.value + '/' + aForm.checkinyear.value;
//	aForm.check_out.value = aForm.air_checkoutMonth.value + '/' + aForm.air_checkoutDay.value + '/' + aForm.checkoutyear.value; 
	
	
	air_checkinchanged(aForm); //for Dec'05 to jan 06 search failures
	air_checkoutchanged(aForm);	
	
	if(new Date(aForm.check_in.value) > new Date(aForm.check_out.value))
	{ 
		alert("Check Out date is prior to Check In date.\n" +
				  "Please enter a valid Check out date.");
			//aForm.Return.focus();
			return false;

	}
    if(new Date(aForm.check_in.value) < todayDateVal )
	{ 
		alert("Check in date is prior to the today's date.\n" +
				  "Please enter a valid Check In date.");		
            //aForm.Depart.focus();
			return false;

	}

   if(new Date(aForm.check_out.value)  < todayDateVal )
	{ 
		alert("Check out date is prior to the today's date.\n" +
				  "Please enter a valid Check out date.");
			//aForm.Return.focus();
			return false;

	}

    if(strTrim(aForm.citycode.value) == "" || aForm.citycode.value==null)
   {
		alert("Please enter a valid city name/code.");
		aForm.city.focus();
		return false;
	}
	


	else if(strTrim(aForm.check_in.value) == "" || aForm.check_in.value==null)
		{
			
			aForm.check_in.focus();
			return false;
	}
	else if(strTrim(aForm.check_out.value) == "" || aForm.check_out.value==null){
				alert("Please enter a valid Check Out date.");
				aForm.check_out.focus();
				return false;
	}


	if(!validDate(aForm.check_in.value))
	{

		//aForm.DepartLegMonth.focus();
		aForm.check_in.focus();
		return false;
	}
	else if(!validDate(aForm.check_out.value))
	{
		alert("Please enter a valid Check Out date.");
		//aForm.ReturnLegMonth.focus();
		aForm.check_out.focus();
		return false;
        }
        else if(!isDatesOK(aForm.check_in.value,aForm.check_out.value,"/"))
		{
			alert("Check out  date is prior to Check In date.\n" +
				  "Please enter a valid check Out date.");
			aForm.check_out.focus();
			return false; 
        }

        else if(!CompareDates(aForm.check_in.value,aForm.check_out.value,"/"))
        {
            	alert("Hotels are available for up to 330 days in advance.\n" +
            	      "The date you entered exceeds this number of days.");
            	//aForm.DepartLegMonth.focus();
            	aForm.check_in.focus();
		return false;
    }
	
	return true;
   
}


function lookupBookHotel(tType,formname){
  var x, y;
  var tripType = tType;
  var element = formname.air_cityName;
  if (document.layers) {
    x = element.x + window.screenX + window.outerWidth - window.innerWidth;
    y = element.y + window.screenY + window.outerHeight - window.innerHeight;
  }
  else if (document.all) {
    var coords = getPageCoords(element);
    x = coords.x + window.screenLeft + 130;
    y = coords.y + window.screenTop + 60;
  	y = y - 200;
  }
  else if (document.getElementById) {
    var coords = getPageCoords(element);
    x = coords.x + window.screenX + window.outerWidth - window.innerWidth;
    y = coords.y + window.screenY + window.outerHeight - window.innerHeight;
	y = y - 28;
  }
  x = x - 5;
  y = y + 19;
  if(navigator.appName=="Netscape")
	{
		x = x + 140;
		y = y - 120;
	}
  window.open('/htdocs/ng/fromairportcodes.html?trip='+tripType, 'AirportCodes', 'left=' + x
        + ',top=' + y + ',width=250,height=500,scrollbars,resizable');

}



