function getCity(cityName)
{
	if(cityName.length>3)
	{
		var stratPos = cityName.indexOf('-')
		var endPos = cityName.indexOf(',')				      	
		//alert(cityName.substring(stratPos+2,endPos));
		cityName=cityName.substring(stratPos+2,endPos);
	}				      
	
    return cityName;
}




var objDoc;
var autoCompleteCell;
var autoCompleteFrame;
var totField;
var autoCompletePopUp;
var resData;
var isIE;
var tmp = 0;
var browser;
var flag=0;
var detect = navigator.userAgent.toLowerCase();
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr,strComment){
//	alert(dtStr);
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Please enter valid date")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please select a valid "+strComment+" day.")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please select a valid date")
		return false
	}
return true
}
function validateMultiAir(aForm)
{
   var date = new Date();
   var todayDateVal = new Date();
   todayDateVal.setDate(todayDateVal.getDate()-1);
	todayDateVal.setHours(23);
	todayDateVal.setMinutes(59);
	todayDateVal.setSeconds(59);

   if(aForm.trip_type.value == "roundtrip") 
  	{
     if(aForm.rt_from.value==null || strTrim(aForm.rt_from.value) == "" || strTrim(aForm.rt_from.value).length<3)
	   {
	   			alert("Please enter a valid departure airport name/code.");
	   			aForm.rt_from.focus();
	   			return false;
	   }
	   
	   if(aForm.rt_to.value==null || strTrim(aForm.rt_to.value) == "" || strTrim(aForm.rt_to.value).length<3)
	   {
			alert("Please enter a valid going to airport name/code.");
			aForm.rt_to.focus();
			return false;
		}
	
	   if(aForm.hd_rt_from.value == "" || aForm.hd_rt_from.value == null)
	   {
	   		aForm.hd_rt_from.value=aForm.rt_from.value;
	   }
	
	   if(aForm.hd_rt_to.value == "" || aForm.hd_rt_to.value == null)
	   {
	   		aForm.hd_rt_to.value=aForm.rt_to.value;
	   }
	  
	if(aForm.hd_rt_from.value==null || strTrim(aForm.hd_rt_from.value) == "" || strTrim(aForm.hd_rt_from.value).length<3)
	{
			alert("Please enter a valid departure airport name/code.");
			aForm.rt_from.focus();
		return false;
	}
	if(aForm.hd_rt_to.value==null || strTrim(aForm.hd_rt_to.value) == "" || strTrim(aForm.hd_rt_to.value).length<3)
	{
		alert("Please enter a valid going to airport name/code.");
			aForm.rt_to.focus();
		return false;
	}
	if(aForm.hd_rt_from.value!=null && strTrim(aForm.hd_rt_from.value) != "" && aForm.hd_rt_to.value!=null && strTrim(aForm.hd_rt_to.value) != "")
	{
		if(aForm.hd_rt_from.value == aForm.hd_rt_to.value)
		{
			alert("The departure and return cities are same. Please enter a valid city name/code.");
			aForm.rt_from.value="";
			aForm.rt_to.value="";
			aForm.rt_from.focus();
			return false;	
		}
	}
	 
		if(new Date(aForm.rt_Depart.value) > new Date(aForm.rt_Return.value))
		{ 
			alert("The return date is prior to the departure date.\n" +
					  "Please enter a valid return date.");
				
				return false;
	
		}
		
		//alert(new Date(aForm.rt_Depart.value)+"=====TODAYIS "+todayDateVal);
	    if(new Date(aForm.rt_Depart.value) < todayDateVal )
		{ 
			alert("The departure date is prior to today's date.\n" +
					  "Please enter a valid departure date.");		
	        	return false;
	
		}
	
	   if(new Date(aForm.rt_Return.value)  < todayDateVal )
		{ 
			alert("The return date is prior to today's date.\n" +
					  "Please enter a valid return date.");
				return false;
	
		}
	
	
		if(strTrim(aForm.rt_Depart.value) == "" || aForm.rt_Depart.value==null){
				alert("Please enter a valid departure date.");
				return false;
		}
		if(strTrim(aForm.rt_Return.value) == "" || aForm.rt_Return.value==null){
					alert("Please enter a valid return date.");
					return false;
		}
		
		if(!isDate(aForm.rt_Depart.value,"Departing"))
		{
			return false;
		}
		if(!validDate(aForm.rt_Depart.value))
		{
			alert("Please enter a valid departure date.");
			return false;
		}
		if(!isDate(aForm.rt_Return.value,"Returning"))
		{
			return false;
		}
		if(!validDate(aForm.rt_Return.value))
		{
			alert("Please enter a valid return date.");
			return false;
	        }
	   if(!isDatesOK(aForm.rt_Depart.value,aForm.rt_Return.value,"/"))
			{
				alert("The return date is prior to the departure date.\n" +
					  "Please enter a valid return date.");
					 
				return false; 
	        }
	
	    if(!CompareDates(aForm.rt_Depart.value,aForm.rt_Return.value,"/"))
	   	{
	           	alert("Flights are available for up to 330 days in advance.\n" + "The date you entered exceeds this number of days.");
	            return false;
	    }

			return true;
	}
	
	else if(aForm.trip_type.value == "oneway")
	{
		if(aForm.ow_from.value==null || strTrim(aForm.ow_from.value) == "" || strTrim(aForm.ow_from.value).length<3){
			alert("Please enter a valid departure airport name/code.");
			aForm.ow_from.focus();
			
		return false;
		}
		
		if(aForm.ow_to.value==null ||strTrim(aForm.ow_to.value) == "" || strTrim(aForm.ow_to.value).length<3){
			alert("Please enter a valid going to airport name/code.");
			aForm.ow_to.focus();
		return false;
		}
		
		
	
	if(aForm.hd_ow_from.value == "" || aForm.hd_ow_from.value == null)
	   {
	   		aForm.hd_ow_from.value=aForm.ow_from.value;
	   }
	    if(aForm.hd_ow_to.value == "" || aForm.hd_ow_to.value == null)
	   {
	   	aForm.hd_ow_to.value=aForm.ow_to.value;
	   }
		
		
	    if(new Date(aForm.ow_Depart.value) < todayDateVal )
		{ 
			alert("The departure date is prior to today's date.\n" +
					  "Please enter a valid departure date.");	
				return false;
	
		}
	
	  
	
	if(aForm.hd_ow_from.value==null || strTrim(aForm.hd_ow_from.value) == "" || strTrim(aForm.hd_ow_from.value).length<3){
			alert("Please enter a valid departure airport name/code.");
			aForm.ow_from.focus();
		return false;
		}
		else if(aForm.hd_ow_to.value==null ||strTrim(aForm.hd_ow_to.value) == "" || strTrim(aForm.hd_ow_to.value).length<3){
			alert("Please enter a valid going to airport name/code.");
			aForm.ow_to.focus();
		return false;
		}
	    else if(aForm.hd_ow_from.value == aForm.hd_ow_to.value)
		{
			alert("The departure and return cities are same. Please enter a valid city name/code.");
			aForm.ow_from.value="";
			aForm.ow_to.value="";
			aForm.ow_from.focus();
			return false;	
		}
		
		else if(strTrim(aForm.ow_Depart.value) == "" || aForm.ow_Depart.value==null)
		{
				alert("Please enter a valid departure date.");
				return false;
		}
		
		if(!isDate(aForm.ow_Depart.value,"Departing"))
		{
			return false;
		}
		
		if(!validDate(aForm.ow_Depart.value))
		{
			alert("Please enter a valid departure date.");
			return false;
		}
	
	  if(!CompareDates(aForm.ow_Depart.value,aForm.ow_Depart.value,"/"))
	   {
	            	alert("Flights are available for up to 330 days in advance.\n" +
	            	      "The date you entered exceeds this number of days.");
	            return false;
	   }
	
			return true;
	}
	else if(aForm.trip_type.value == "multicity")
	{
	
	if(aForm.mc_l1_from.value == null || strTrim(aForm.mc_l1_from.value) == "" || strTrim(aForm.mc_l1_from.value).length<3){
			alert("Please enter a valid Flight 1 departure airport name/code.");
			aForm.mc_l1_from.focus();
		return false;
		}
		
		if(aForm.mc_l1_to.value==null ||strTrim(aForm.mc_l1_to.value) == "" || strTrim(aForm.mc_l1_to.value).length<3){
			alert("Please enter a valid Flight 1 going to airport name/code.");
			aForm.mc_l1_to.focus();
		return false;
		}
		
	if(aForm.hd_mc_l1_from.value == "" || aForm.hd_mc_l1_from.value == null)
	{
	      		aForm.hd_mc_l1_from.value=aForm.mc_l1_from.value;
	}
		if(aForm.hd_mc_l1_to.value == "" || aForm.hd_mc_l1_to.value == null)
	{
	       	aForm.hd_mc_l1_to.value=aForm.mc_l1_to.value;
	}
		if(aForm.hd_mc_l2_from.value == "" || aForm.hd_mc_l2_from.value == null)
	{
	      		aForm.hd_mc_l2_from.value=aForm.mc_l2_from.value;
	}
		if(aForm.hd_mc_l2_to.value == "" || aForm.hd_mc_l2_to.value == null)
	{
	       	aForm.hd_mc_l2_to.value=aForm.mc_l2_to.value;
	}
		if(aForm.hd_mc_l3_from.value == "" || aForm.hd_mc_l3_from.value == null)
	{
	      		aForm.hd_mc_l3_from.value=aForm.mc_l3_from.value;
	}
		if(aForm.hd_mc_l3_to.value == "" || aForm.hd_mc_l3_to.value == null)
	{
	       		aForm.hd_mc_l3_to.value=aForm.mc_l3_to.value;
	}
		if(aForm.hd_mc_l4_from.value == "" || aForm.hd_mc_l4_from.value == null)
	{
	      		aForm.hd_mc_l4_from.value=aForm.mc_l4_from.value;
	}
		if(aForm.hd_mc_l4_to.value == "" || aForm.hd_mc_l4_to.value == null)
	{
	       		aForm.hd_mc_l4_to.value=aForm.mc_l4_to.value;
	}
		//Flight 1
		if(aForm.hd_mc_l1_from.value==null || strTrim(aForm.hd_mc_l1_from.value) == "" || strTrim(aForm.hd_mc_l1_from.value).length<3){
			alert("Please enter a valid Flight 1 departure airport name/code.");
			aForm.mc_l1_from.value="";
			aForm.mc_l1_from.focus();
		return false;
		}
		if(aForm.hd_mc_l1_to.value==null ||strTrim(aForm.hd_mc_l1_to.value) == "" || strTrim(aForm.hd_mc_l1_to.value).length<3){
			alert("Please enter a valid Flight 1 going to airport name/code.");
			aForm.mc_l1_to.value="";
			aForm.mc_l1_to.focus();
		return false;
		}
		if(aForm.hd_mc_l1_from.value!=null && strTrim(aForm.hd_mc_l1_from.value) != "" && aForm.hd_mc_l1_to.value!=null && strTrim(aForm.hd_mc_l1_to.value) != "")
		{
			
			if(aForm.hd_mc_l1_from.value == aForm.hd_mc_l1_to.value)
		{
			alert("The departure and return cities are same. Please enter a valid city name/code.");
			aForm.mc_l1_from.value="";
			aForm.mc_l1_to.value="";
			aForm.mc_l1_from.focus();
			return false;	
			}
		}
		if(new Date(aForm.mc_l1_Depart.value) < todayDateVal )
		{ 
			alert("The departure date of flight 1 is prior to today's date.\n" +
					  "Please enter a valid departure date.");
				
			aForm.mc_l1_depmon.focus();
	        	return false;
		}
		if(strTrim(aForm.mc_l1_Depart.value) == "" || aForm.mc_l1_Depart.value==null){
				alert("Please enter a valid departure date.");
				aForm.mc_l1_depmon.focus();
				return false;
		}
		
	if(!isDate(aForm.mc_l1_Depart.value,"Flight 1 Departing"))
		{
			return false;
		}
		if(!validDate(aForm.mc_l1_Depart.value))
		{
			alert("Please enter a valid Flight 1 departure date.");
			return false;
		}
		
		if(!CompareDates(aForm.mc_l1_Depart.value,aForm.mc_l1_Depart.value,"/"))
	   	{
	            	alert("Flights are available for up to 330 days in advance.\n" +
	            	      "The date you entered exceeds this number of days for Flight 1.");
	            return false;
	   	}
	   	
	   	//Flight 2
			if(aForm.hd_mc_l2_from.value!=null && strTrim(aForm.hd_mc_l2_from.value) != "")
			{
			
				if((aForm.hd_mc_l1_from.value==null || aForm.hd_mc_l1_from.value=="") || (aForm.hd_mc_l1_to.value==null || aForm.hd_mc_l1_to.value==""))
				{
					alert("Please enter a valid Flight 1 departure & return airport name/code.");
					aForm.mc_l1_from.focus();
					return false;
				}
				else if(strTrim(aForm.hd_mc_l2_from.value).length<3)
				{
					alert("Please enter a valid Flight 2 departure airport name/code.");
					aForm.mc_l2_from.value="";
					aForm.mc_l2_from.focus();
					return false;
				}
			}

			if(aForm.hd_mc_l2_from.value!=null && strTrim(aForm.hd_mc_l2_from.value) != "" && !strTrim(aForm.hd_mc_l2_from.value).length<3)
			{  
				if(aForm.hd_mc_l2_to.value==null || strTrim(aForm.hd_mc_l2_to.value) == "" || strTrim(aForm.hd_mc_l2_to.value).length<3)
				{
					alert("Please enter a valid Flight 2 going to airport name/code.");
					aForm.mc_l2_to.value="";
					aForm.mc_l2_to.focus();
					return false;
				}		
			}
			if(aForm.hd_mc_l2_to.value!=null && strTrim(aForm.hd_mc_l2_to.value) != "" && !strTrim(aForm.hd_mc_l2_to.value).length<3)
			{  
				if(aForm.hd_mc_l2_from.value==null || strTrim(aForm.hd_mc_l2_from.value) == "" || strTrim(aForm.hd_mc_l2_from.value).length<3)
				{
					alert("Please enter a valid Flight 2 departure airport name/code.");
					aForm.mc_l2_from.focus();
					return false;
				}		
			}
			if(aForm.hd_mc_l2_from.value!=null && strTrim(aForm.hd_mc_l2_from.value) != "" && aForm.hd_mc_l2_to.value!=null && strTrim(aForm.hd_mc_l2_to.value) != "")
			{
				if(aForm.hd_mc_l2_from.value == aForm.hd_mc_l2_to.value)
			{
				alert("Depart and Return Cities are same. Please enter valid cities.");
				aForm.mc_l2_from.value="";
				aForm.mc_l2_to.value="";
				aForm.mc_l2_from.focus();
				return false;	
				}
			}
			if(aForm.hd_mc_l2_from.value!=null && strTrim(aForm.hd_mc_l2_from.value) != "")
			{
				if((new Date(aForm.mc_l2_Depart.value) < todayDateVal ) || (new Date(aForm.mc_l2_Depart.value) < new Date(aForm.mc_l1_Depart.value)))
				{ 
					alert("The departure date of flight 2 is either prior to today's date or prior to the departure date of flight 1.\n" +
							  "Please enter a valid departure date.");
					aForm.mc_l2_depmon.focus();
						return false;
			
				}
			}
		
		if(!isDate(aForm.mc_l2_Depart.value,"Flight 2 Departing"))
		{
			return false;
		}
		
		if(!validDate(aForm.mc_l2_Depart.value))
		{
			alert("Please enter a valid Flight 2 departure date.");
			return false;
		}

		if(!CompareDates(aForm.mc_l2_Depart.value,aForm.mc_l2_Depart.value,"/"))
	   	{
	            	alert("Flights are available for up to 330 days in advance.\n" +
	            	      "The date you entered exceeds this number of days for Flight 2.");
	            return false;
	   	}
		//Flight 3
		
			if(aForm.hd_mc_l3_from.value!=null && strTrim(aForm.hd_mc_l3_from.value) != "")
			{
				if((aForm.hd_mc_l2_from.value==null || aForm.hd_mc_l2_from.value=="") || (aForm.hd_mc_l2_to.value==null || aForm.hd_mc_l2_to.value==""))
				{
					alert("Please enter a valid Flight 2 departure & return airport name/code.");
					aForm.mc_l2_from.focus();
					return false;
				}
				else if(strTrim(aForm.hd_mc_l3_from.value).length<3)
					 {
						alert("Please enter a valid Flight 3 departure airport name/code.");
						aForm.mc_l3_from.value="";
						aForm.mc_l3_from.focus();
						return false;
					 }
			}

			if(aForm.hd_mc_l3_from.value!=null && strTrim(aForm.hd_mc_l3_from.value) != "" && !strTrim(aForm.hd_mc_l3_from.value).length<3)
			{  
				if(aForm.hd_mc_l3_to.value==null || strTrim(aForm.hd_mc_l3_to.value) == "" || strTrim(aForm.hd_mc_l3_to.value).length<3)
				{
					alert("Please enter a valid Flight 3 going to airport name/code.");
					aForm.mc_l3_to.value="";
					aForm.mc_l3_to.focus();
					return false;
				}		
			}
			if(aForm.hd_mc_l3_to.value!=null && strTrim(aForm.hd_mc_l3_to.value) != "" && !strTrim(aForm.hd_mc_l3_to.value).length<3)
			{  
				if(aForm.hd_mc_l3_from.value==null || strTrim(aForm.hd_mc_l3_from.value) == "" || strTrim(aForm.hd_mc_l3_from.value).length<3)
				{
					alert("Please enter a valid Flight 3 departure airport name/code.");
					aForm.mc_l3_from.focus();
					return false;
				}		
			}
			if(aForm.hd_mc_l3_from.value!=null && strTrim(aForm.hd_mc_l3_from.value) != "" && aForm.hd_mc_l3_to.value!=null && strTrim(aForm.hd_mc_l3_to.value) != "")
			{
				if(aForm.hd_mc_l3_from.value == aForm.hd_mc_l3_to.value)
			{
				alert("Depart and Return Cities are same. Please enter valid cities.");
				aForm.mc_l3_from.value="";
				aForm.mc_l3_to.value="";
				aForm.mc_l3_from.focus();
			return false;	
				}
			}
			if(aForm.hd_mc_l3_from.value!=null && strTrim(aForm.hd_mc_l3_from.value) != "")
			{
				if((new Date(aForm.mc_l3_Depart.value) < todayDateVal ) || (new Date(aForm.mc_l3_Depart.value) < new Date(aForm.mc_l2_Depart.value)) || (new Date(aForm.mc_l3_Depart.value) < new Date(aForm.mc_l1_Depart.value)))
				{ 
					alert("The departure date of flight 3 is either prior to today's date or prior to the departure date of flight 1 or flight 2.\n" +
							  "Please enter a valid departure date.");
					aForm.mc_l3_depmon.focus();
						return false;
			
				}
			}
		
		if(!isDate(aForm.mc_l3_Depart.value,"Flight 3 Departing"))
		{
			return false;
		}
		if(!validDate(aForm.mc_l3_Depart.value))
		{
			alert("Please enter a valid Flight 3 departure date.");
			return false;
		}

		if(!CompareDates(aForm.mc_l3_Depart.value,aForm.mc_l3_Depart.value,"/"))
	   	{
	            	alert("Flights are available for up to 330 days in advance.\n" +
	            	      "The date you entered exceeds this number of days for Flight 3.");
	            return false;
	   	}
		//Flight 4
		
		if(aForm.hd_mc_l4_from.value!=null && strTrim(aForm.hd_mc_l4_from.value) != "")
		{
			if((aForm.hd_mc_l3_from.value==null || aForm.hd_mc_l3_from.value=="") || (aForm.hd_mc_l3_to.value==null || aForm.hd_mc_l3_to.value==""))
			{
					alert("Please enter a valid Flight 3 departure & return airport name/code.");
					aForm.mc_l3_from.focus();
					return false;
				}
			else if(strTrim(aForm.hd_mc_l4_from.value).length<3)
			{
				alert("Please enter a valid Flight 4 departure airport name/code.");
				aForm.mc_l4_from.value="";
				aForm.mc_l4_from.focus();
				return false;
			}
		}

		if(aForm.hd_mc_l4_from.value!=null && strTrim(aForm.hd_mc_l4_from.value) != "" && !strTrim(aForm.hd_mc_l4_from.value).length<3)
		{ 
			if(aForm.hd_mc_l4_to.value==null || strTrim(aForm.hd_mc_l4_to.value) == "" || strTrim(aForm.hd_mc_l4_to.value).length<3)
			{
				alert("Please enter a valid Flight 4 going to airport name/code.");
				aForm.mc_l4_to.value="";
				aForm.mc_l4_to.focus();
				return false;
			}		
		}
		if(aForm.hd_mc_l4_to.value!=null && strTrim(aForm.hd_mc_l4_to.value) != "" && !strTrim(aForm.hd_mc_l4_to.value).length<3)
		{  
			if(aForm.hd_mc_l4_from.value==null || strTrim(aForm.hd_mc_l4_from.value) == "" || strTrim(aForm.hd_mc_l4_from.value).length<3)
			{
				alert("Please enter a valid Flight 4 departure airport name/code.");
				aForm.mc_l4_from.focus();
				return false;
			}		
		}
		if(aForm.hd_mc_l4_from.value!=null && strTrim(aForm.hd_mc_l4_from.value) != "" && aForm.hd_mc_l4_to.value!=null && strTrim(aForm.hd_mc_l4_to.value) != "")
		{
			if(aForm.hd_mc_l4_from.value == aForm.hd_mc_l4_to.value)
		{
			alert("Depart and Return Cities are same. Please enter valid cities.");
			aForm.mc_l4_from.value="";
			aForm.mc_l4_to.value="";
			aForm.mc_l4_from.focus();
			return false;	
			}
		}
		if(aForm.hd_mc_l4_from.value!=null && strTrim(aForm.hd_mc_l4_from.value) != "")
		{
			if((new Date(aForm.mc_l4_Depart.value) < todayDateVal ) || (new Date(aForm.mc_l4_Depart.value) < new Date(aForm.mc_l3_Depart.value)) || (new Date(aForm.mc_l4_Depart.value) < new Date(aForm.mc_l2_Depart.value)) || (new Date(aForm.mc_l4_Depart.value) < new Date(aForm.mc_l1_Depart.value)))
			{ 
				alert("The departure date of flight 4 is either prior to today's date or prior to the departure date of flight 1 or flight 2 0r flight 3.\n" +
						  "Please enter a valid departure date.");
				aForm.mc_l4_depmon.focus();
				return false;
		
			}
	    }
	    if(!isDate(aForm.mc_l4_Depart.value,"Flight 4 Departing"))
		{
			return false;
		}
		if(!validDate(aForm.mc_l4_Depart.value))
		{
			alert("Please enter a valid Flight 4 departure date.");
			return false;
		}
		
		if(!CompareDates(aForm.mc_l4_Depart.value,aForm.mc_l4_Depart.value,"/"))
	   	{
	            	alert("Flights are available for up to 330 days in advance.\n" +
	            	      "The date you entered exceeds this number of days for Flight 4.");
	            return false;
	   	}
		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 stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
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 changeView(chg_type)
{	
var rtdivs = document.getElementById('roundtrip');
var owdivs = document.getElementById('oneway');
var mcdivs = document.getElementById('multicity');

if(chg_type == 'roundtrip')
{
	clearTable();
	clearPopupFrame();
	rtdivs.style.display='';// show/hide
	mcdivs.style.display='none';// show/hide
	owdivs.style.display='none';// show/hide
	selectRadio(chg_type)
	document.multitype.changetype.value = 'round';
}
else if(chg_type == 'oneway')
{
	clearTable();
	clearPopupFrame();
	rtdivs.style.display='none';// show/hide
	mcdivs.style.display='none';// show/hide
	owdivs.style.display='';// show/hide
	selectRadio(chg_type)
	document.multitype.changetype.value = 'one';

}
else if(chg_type == 'multicity')
{
	clearTable();
	clearPopupFrame();
	rtdivs.style.display='none';// show/hide
	mcdivs.style.display='';// show/hide
	owdivs.style.display='none';// show/hide
	selectRadio(chg_type)
	document.multitype.changetype.value = 'multi';
}
else
{
	return;
}

}

function selectRadio(chg_type)
{
check = document.multitype.changetype.value;
if(chg_type == 'roundtrip')
{
if(check=="one")
{	
	document.multitype.rt_regionalsearch.checked = document.multitype.ow_regionalsearch.checked;	
	document.multitype.rt_nonstop_search.checked = document.multitype.ow_nonstop_search.checked;
	
	document.multitype.rt_from.value=document.multitype.ow_from.value;
	document.multitype.rt_to.value=document.multitype.ow_to.value;
	
	document.multitype.hd_rt_from.value=document.multitype.hd_ow_from.value;
	document.multitype.hd_rt_to.value=document.multitype.hd_ow_to.value;
	
	document.multitype.rt_dmon_sel.value=document.multitype.ow_dmon_sel.value;
	document.multitype.rt_ddat_sel.value=	document.multitype.ow_ddat_sel.value
	
	var today = new Date();
	var mon = document.multitype.ow_dmon_sel.value;
	var day = document.multitype.ow_ddat_sel.value
	
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}
	if(day<10)
	{
	 day="0"+day;
	}
	var field = getElement("rt_depart_input");
	field.value = mon+"/"+day+"/"+year;
	

	if(document.multitype.ow_departSchedule.value == "Any" || document.multitype.ow_departSchedule.value == "Any Time")
	{
		document.multitype.rt_departSchedule.selectedIndex = 0;
	}
	else
	{
		document.multitype.rt_departSchedule.value = document.multitype.ow_departSchedule.value;
	}

	document.multitype.rt_pax_count.value=	document.multitype.ow_pax_count.value	
	document.multitype.rt_air_class.value=	document.multitype.ow_air_class.value

}	
else if(check=="multi")
{
	document.multitype.rt_regionalsearch.checked = document.multitype.mc_regionalsearch.checked;
	
	document.multitype.rt_nonstop_search.checked = document.multitype.mc_nonstop_search.checked;
	
	document.multitype.rt_from.value= document.multitype.mc_l1_from.value
	document.multitype.rt_to.value= document.multitype.mc_l1_to.value
	
	document.multitype.hd_rt_from.value= document.multitype.hd_mc_l1_from.value
	document.multitype.hd_rt_to.value= document.multitype.hd_mc_l1_to.value
	
	document.multitype.rt_dmon_sel.value= document.multitype.mc_l1_dmon_sel.value
	document.multitype.rt_ddat_sel.value=	document.multitype.mc_l1_ddat_sel.value
	
	var today = new Date();
	var mon = document.multitype.mc_l1_dmon_sel.value;
	var day = document.multitype.mc_l1_ddat_sel.value;
	
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}
	if(day<10)
	{
	 day="0"+day;
	}
	var field = getElement("rt_depart_input");
	field.value = mon+"/"+day+"/"+year;
	
	
	if(document.multitype.mc_l1_departSchedule.value == "Any" || document.multitype.mc_l1_departSchedule.value == "Any Time")
	{
		document.multitype.rt_departSchedule.selectedIndex = 0;
	}
	else
	{
		document.multitype.rt_departSchedule.value = document.multitype.mc_l1_departSchedule.value;
	}
		
	document.multitype.rt_pax_count.value=	document.multitype.mc_pax_count.value
	document.multitype.rt_air_class.value=	document.multitype.mc_air_class.value
	
}
	document.multitype.rt_rt_radiobutton.checked = true;
	document.multitype.rt_ow_radiobutton.checked = false;
	document.multitype.rt_mc_radiobutton.checked = false;
	document.multitype.ow_rt_radiobutton.checked = false;
	document.multitype.ow_ow_radiobutton.checked = false;
	document.multitype.ow_mc_radiobutton.checked = false;
	document.multitype.mc_rt_radiobutton.checked = false;
	document.multitype.mc_ow_radiobutton.checked = false;
	document.multitype.mc_mc_radiobutton.checked = false;
	
	document.multitype.trip_type.value="roundtrip";
}
else if(chg_type == 'oneway')
{

if(check=="round")
{
   document.multitype.ow_regionalsearch.checked = document.multitype.rt_regionalsearch.checked;

	document.multitype.ow_nonstop_search.checked = document.multitype.rt_nonstop_search.checked;
	
	document.multitype.ow_from.value = document.multitype.rt_from.value;
	document.multitype.ow_to.value=document.multitype.rt_to.value;
	
	document.multitype.hd_ow_from.value = document.multitype.hd_rt_from.value;
	document.multitype.hd_ow_to.value = document.multitype.hd_rt_to.value;
	
	document.multitype.ow_dmon_sel.value=document.multitype.rt_dmon_sel.value;
	document.multitype.ow_ddat_sel.value=document.multitype.rt_ddat_sel.value;
	
	var today = new Date();
	var mon = document.multitype.rt_dmon_sel.value;
	var day = document.multitype.rt_ddat_sel.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}
	if(day<10)
	{
	 day="0"+day;
	}
	var field = getElement("ow_depart_input");
	field.value = mon+"/"+day+"/"+year;
	
	if(document.multitype.rt_departSchedule.value == "Any" || document.multitype.rt_departSchedule.value == "Any Time")
	{
		document.multitype.ow_departSchedule.selectedIndex = 0;
	}
	else
	{
		document.multitype.ow_departSchedule.value = document.multitype.rt_departSchedule.value;
	}
	
	
	
	document.multitype.ow_pax_count.value	=  document.multitype.rt_pax_count.value;
	document.multitype.ow_air_class.value= document.multitype.rt_air_class.value;
}
else if(check=="multi")
{
	document.multitype.ow_regionalsearch.checked = document.multitype.mc_regionalsearch.checked;
	
	document.multitype.ow_nonstop_search.checked = document.multitype.mc_nonstop_search.checked;
	
	document.multitype.ow_from.value=document.multitype.mc_l1_from.value
	document.multitype.ow_to.value=document.multitype.mc_l1_to.value
	
	document.multitype.hd_ow_from.value=document.multitype.hd_mc_l1_from.value
	document.multitype.hd_ow_to.value=document.multitype.hd_mc_l1_to.value
	
	document.multitype.ow_dmon_sel.value=document.multitype.mc_l1_dmon_sel.value
	document.multitype.ow_ddat_sel.value=document.multitype.mc_l1_ddat_sel.value
	
	var today = new Date();
	var mon = document.multitype.mc_l1_dmon_sel.value
	var day = document.multitype.mc_l1_ddat_sel.value
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}
	if(day<10)
	{
	 day="0"+day;
	}
	var field = getElement("ow_depart_input");
	field.value = mon+"/"+day+"/"+year;
	
	if(document.multitype.mc_l1_departSchedule.value == "Any" || document.multitype.mc_l1_departSchedule.value == "Any Time")
	{
		document.multitype.ow_departSchedule.selectedIndex = 0;
	}
	else
	{
		document.multitype.ow_departSchedule.value = document.multitype.mc_l1_departSchedule.value;
	}

		document.multitype.ow_pax_count.value	=  	document.multitype.mc_pax_count.value
	document.multitype.ow_air_class.value= document.multitype.mc_air_class.value
	
}
	
	document.multitype.rt_rt_radiobutton.checked = false;
	document.multitype.rt_ow_radiobutton.checked = false;
	document.multitype.rt_mc_radiobutton.checked = false;
	document.multitype.ow_rt_radiobutton.checked = false;
	document.multitype.ow_ow_radiobutton.checked = true;
	document.multitype.ow_mc_radiobutton.checked = false;
	document.multitype.mc_rt_radiobutton.checked = false;
	document.multitype.mc_ow_radiobutton.checked = false;
	document.multitype.mc_mc_radiobutton.checked = false;
	document.multitype.trip_type.value="oneway";
}

else if(chg_type == 'multicity')
{
	if(check=="round")
	{
		
		document.multitype.mc_regionalsearch.checked = document.multitype.rt_regionalsearch.checked;
		
		document.multitype.mc_nonstop_search.checked = document.multitype.rt_nonstop_search.checked;
			
			document.multitype.mc_l1_from.value=document.multitype.rt_from.value
			document.multitype.mc_l1_to.value=document.multitype.rt_to.value
			
			document.multitype.hd_mc_l1_from.value=document.multitype.hd_rt_from.value
			document.multitype.hd_mc_l1_to.value=document.multitype.hd_rt_to.value
			
			document.multitype.mc_l1_dmon_sel.value=document.multitype.rt_dmon_sel.value
			document.multitype.mc_l1_ddat_sel.value=document.multitype.rt_ddat_sel.value
			
			var today = new Date();
			var mon = document.multitype.rt_dmon_sel.value
			var day = document.multitype.rt_ddat_sel.value
			
			var year = today.getFullYear();
			if(today.getMonth() > mon-1)
			{
				year = year + 1;
			}
			if(day<10)
			{
			 day="0"+day;
			}
			var field = getElement("mc_l1_depart_input");
			field.value = mon+"/"+day+"/"+year;
			
					
		if(document.multitype.rt_departSchedule.value == "Any" || document.multitype.rt_departSchedule.value == "Any Time")
		{
			document.multitype.mc_l1_departSchedule.selectedIndex = 0;
		}
		else
		{
		 document.multitype.mc_l1_departSchedule.value = document.multitype.rt_departSchedule.value 
		}
	
			document.multitype.mc_pax_count.value	=  document.multitype.rt_pax_count.value
			document.multitype.mc_air_class.value= document.multitype.rt_air_class.value
	}
	else if(check=="one")
	{
			document.multitype.mc_regionalsearch.checked = document.multitype.ow_regionalsearch.checked;
			
			document.multitype.mc_nonstop_search.checked = document.multitype.ow_nonstop_search.checked;
		
			document.multitype.mc_l1_from.value=document.multitype.ow_from.value
			document.multitype.mc_l1_to.value=	document.multitype.ow_to.value
			
			document.multitype.hd_mc_l1_from.value=document.multitype.hd_ow_from.value
			document.multitype.hd_mc_l1_to.value=document.multitype.hd_ow_to.value
			
			document.multitype.mc_l1_dmon_sel.value = document.multitype.ow_dmon_sel.value
			document.multitype.mc_l1_ddat_sel.value = document.multitype.ow_ddat_sel.value
			
			var today = new Date();
			var mon = document.multitype.ow_dmon_sel.value
			var day = document.multitype.ow_ddat_sel.value
			
			var year = today.getFullYear();
			if(today.getMonth() > mon-1)
			{
				year = year + 1;
			}
			if(day<10)
			{
			 day="0"+day;
			}
			var field = getElement("mc_l1_depart_input");
			field.value = mon+"/"+day+"/"+year;
			
		if(document.multitype.ow_departSchedule.value == "Any" || document.multitype.ow_departSchedule.value == "Any Time")
		{
			document.multitype.mc_l1_departSchedule.selectedIndex = 0;
		}
		else
		{
			document.multitype.mc_l1_departSchedule.value=document.multitype.ow_departSchedule.value
		}
		
			document.multitype.mc_pax_count.value	=  document.multitype.ow_pax_count.value	
			document.multitype.mc_air_class.value= document.multitype.ow_air_class.value
		}
	
	document.multitype.rt_rt_radiobutton.checked = false;
	document.multitype.rt_ow_radiobutton.checked = false;
	document.multitype.rt_mc_radiobutton.checked = false;
	document.multitype.ow_rt_radiobutton.checked = false;
	document.multitype.ow_ow_radiobutton.checked = false;
	document.multitype.ow_mc_radiobutton.checked = false;
	document.multitype.mc_rt_radiobutton.checked = false;
	document.multitype.mc_ow_radiobutton.checked = false;
	document.multitype.mc_mc_radiobutton.checked = true;
	document.multitype.trip_type.value="multicity";
}
else
{
	return;
}

}
	
	
function owDepartchanged(airForm)
{
	var today = new Date();
	var mon = airForm.ow_depmon.value;
	var day = airForm.ow_depdat.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}
	if(day<10)
	{
	 day="0"+day;
	}
	var field = getElement("ow_depart_input");
	field.value = mon+"/"+day+"/"+year;
	
}

function mcL1Departchanged(airForm)
{
   
	var today = new Date();
	var mon = airForm.mc_l1_depmon.value;
	var day = airForm.mc_l1_depdat.value;
	
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}
	if(day<10)
	{
	 day="0"+day;
	}
	var field = getElement("mc_l1_depart_input");
	field.value = mon+"/"+day+"/"+year;

	
}

function mcL2Departchanged(airForm)
{
	var today = new Date();
	var mon = airForm.mc_l2_depmon.value;
	var day = airForm.mc_l2_depdat.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}
	if(day<10)
	{
	 day="0"+day;
	}
	var field = getElement("mc_l2_depart_input");
	field.value = mon+"/"+day+"/"+year;
}

function mcL3Departchanged(airForm)
{
	var today = new Date();
	var mon = airForm.mc_l3_depmon.value;
	var day = airForm.mc_l3_depdat.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}
	if(day<10)
	{
	 day="0"+day;
	}

	var field = getElement("mc_l3_depart_input");
	field.value = mon+"/"+day+"/"+year;
	
	
}

function mcL4Departchanged(airForm)
{
	var today = new Date();
	var mon = airForm.mc_l4_depmon.value;
	var day = airForm.mc_l4_depdat.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}

	if(day<10)
	{
	 day="0"+day;
	}
    var field = getElement("mc_l4_depart_input");
	field.value = mon+"/"+day+"/"+year;
		
	
}
function rtReturnchanged(airForm)
{
	var today = new Date();
	var mon = airForm.rt_retmon.value;
	var day = airForm.rt_retdat.value;
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}

	
	if(day<10)
	{
	 day="0"+day;
	}
    var field = getElement("rt_return_input");
	field.value = mon+"/"+day+"/"+year;
	 
}

function rtDepartchanged(airForm)
{
	var today = new Date();
	var mon = airForm.rt_depmon.value;
	var day = airForm.rt_depdat.value;
	
	var year = today.getFullYear();
	if(today.getMonth() > mon-1)
	{
		year = year + 1;
	}
	if(day<10)
	{
	 day="0"+day;
	}
	var field = getElement("rt_depart_input");
	field.value = mon+"/"+day+"/"+year;
	  
}


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 putFocus(tripType, noOfLegs)
{  
//	alert("putFocus");
	
	if(tripType==1)
	{
	//	alert("oneway");
	
		// AIR form
	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);
	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 depRtHdn = getElement("rt_depart_input");
	var depMcL1Hdn = getElement("mc_l1_depart_input");
	var depMcL2Hdn = getElement("mc_l2_depart_input");
	var depMcL3Hdn = getElement("mc_l3_depart_input");
	var depMcL4Hdn = getElement("mc_l4_depart_input");
	
	depRtHdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL1Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL2Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL3Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL4Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	
	var depRtMon = getElement("rt_dmon_sel");
	var depMcL1Mon = getElement("mc_l1_dmon_sel");
	var depMcL2Mon = getElement("mc_l2_dmon_sel");
	var depMcL3Mon = getElement("mc_l3_dmon_sel");
	var depMcL4Mon = getElement("mc_l4_dmon_sel");
	
	var depRtDat = getElement("rt_ddat_sel");
	var depMcL1Dat = getElement("mc_l1_ddat_sel");
	var depMcL2Dat = getElement("mc_l2_ddat_sel");
	var depMcL3Dat = getElement("mc_l3_ddat_sel");
	var depMcL4Dat = getElement("mc_l4_ddat_sel");
	
	depRtDat.selectedIndex = d.getDate()-1;
	depMcL1Dat.selectedIndex = d.getDate()-1;
	depMcL2Dat.selectedIndex = d.getDate()-1;
	depMcL3Dat.selectedIndex = d.getDate()-1;
	depMcL4Dat.selectedIndex = d.getDate()-1;
	
	depRtMon.selectedIndex = d.getMonth();
	depMcL1Mon.selectedIndex = d.getMonth();
	depMcL2Mon.selectedIndex = d.getMonth();
	depMcL3Mon.selectedIndex = d.getMonth();
	depMcL4Mon.selectedIndex = d.getMonth();
	

	var currMonStr2 = curMonth2;
	if(curMonth2 < 10){
		currMonStr2 = "0"+currMonStr2;
	}
	var curDateStr2 = curDate2;
	if(curDate2 < 10){
		curDateStr2 = "0"+curDateStr2;
	}
	var retRtHdn = getElement("rt_return_input");
	retRtHdn.value = currMonStr2+"/"+curDateStr2+"/"+fy2;
	var retRtMon = getElement("rt_rmon_sel");
	var retRtDat = getElement("rt_rdat_sel");
	retRtDat.selectedIndex = d2.getDate()-1;
	retRtMon.selectedIndex = d2.getMonth();

	document.multitype.rt_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l1_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l2_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l3_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l4_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.rt_Return.value = currMonStr2+"/"+curDateStr2+"/"+fy2;
	}
	if(tripType==2)
	{
	// AIR form
	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);
	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 depOwHdn = getElement("ow_depart_input");
	var depMcL1Hdn = getElement("mc_l1_depart_input");
	var depMcL2Hdn = getElement("mc_l2_depart_input");
	var depMcL3Hdn = getElement("mc_l3_depart_input");
	var depMcL4Hdn = getElement("mc_l4_depart_input");
	
	depOwHdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL1Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL2Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL3Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL4Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	
	var depOwMon = getElement("ow_dmon_sel");
	var depMcL1Mon = getElement("mc_l1_dmon_sel");
	var depMcL2Mon = getElement("mc_l2_dmon_sel");
	var depMcL3Mon = getElement("mc_l3_dmon_sel");
	var depMcL4Mon = getElement("mc_l4_dmon_sel");
	
	var depOwDat = getElement("ow_ddat_sel");
	var depMcL1Dat = getElement("mc_l1_ddat_sel");
	var depMcL2Dat = getElement("mc_l2_ddat_sel");
	var depMcL3Dat = getElement("mc_l3_ddat_sel");
	var depMcL4Dat = getElement("mc_l4_ddat_sel");
	
	depOwDat.selectedIndex = d.getDate()-1;
	depMcL1Dat.selectedIndex = d.getDate()-1;
	depMcL2Dat.selectedIndex = d.getDate()-1;
	depMcL3Dat.selectedIndex = d.getDate()-1;
	depMcL4Dat.selectedIndex = d.getDate()-1;
	
	depOwMon.selectedIndex = d.getMonth();
	depMcL1Mon.selectedIndex = d.getMonth();
	depMcL2Mon.selectedIndex = d.getMonth();
	depMcL3Mon.selectedIndex = d.getMonth();
	depMcL4Mon.selectedIndex = d.getMonth();
	

	var currMonStr2 = curMonth2;
	if(curMonth2 < 10){
		currMonStr2 = "0"+currMonStr2;
	}
	var curDateStr2 = curDate2;
	if(curDate2 < 10){
		curDateStr2 = "0"+curDateStr2;
	}

	document.multitype.ow_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l1_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l2_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l3_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l4_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	}
	if(tripType==3)
	{
	// AIR form
	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);
	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 depRtHdn = getElement("rt_depart_input");
	var depOwHdn = getElement("ow_depart_input");
	
	depRtHdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depOwHdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	
	var depRtMon = getElement("rt_dmon_sel");
	var depOwMon = getElement("ow_dmon_sel");
	
	var depRtDat = getElement("rt_ddat_sel");
	var depOwDat = getElement("ow_ddat_sel");
	
	depRtDat.selectedIndex = d.getDate()-1;
	depOwDat.selectedIndex = d.getDate()-1;
	
	depRtMon.selectedIndex = d.getMonth();
	depOwMon.selectedIndex = d.getMonth();


	var currMonStr2 = curMonth2;
	if(curMonth2 < 10){
		currMonStr2 = "0"+currMonStr2;
	}
	var curDateStr2 = curDate2;
	if(curDate2 < 10){
		curDateStr2 = "0"+curDateStr2;
	}
	var retRtHdn = getElement("rt_return_input");
	retRtHdn.value = currMonStr2+"/"+curDateStr2+"/"+fy2;
	var retRtMon = getElement("rt_rmon_sel");
	var retRtDat = getElement("rt_rdat_sel");
	retRtDat.selectedIndex = d2.getDate()-1;
	retRtMon.selectedIndex = d2.getMonth();

	document.multitype.rt_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.ow_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.rt_Return.value = currMonStr2+"/"+curDateStr2+"/"+fy2;

	//For Multi City
	if(noOfLegs==1)
	{
		var depMcL2Hdn = getElement("mc_l2_depart_input");
		var depMcL3Hdn = getElement("mc_l3_depart_input");
		var depMcL4Hdn = getElement("mc_l4_depart_input");

		depMcL2Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
		depMcL3Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
		depMcL4Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;

		var depMcL2Mon = getElement("mc_l2_dmon_sel");
		var depMcL3Mon = getElement("mc_l3_dmon_sel");
		var depMcL4Mon = getElement("mc_l4_dmon_sel");

		var depMcL2Dat = getElement("mc_l2_ddat_sel");
		var depMcL3Dat = getElement("mc_l3_ddat_sel");
		var depMcL4Dat = getElement("mc_l4_ddat_sel");

		depMcL2Dat.selectedIndex = d.getDate()-1;
		depMcL3Dat.selectedIndex = d.getDate()-1;
		depMcL4Dat.selectedIndex = d.getDate()-1;

		depMcL2Mon.selectedIndex = d.getMonth();
		depMcL3Mon.selectedIndex = d.getMonth();
		depMcL4Mon.selectedIndex = d.getMonth();

		var currMonStr2 = curMonth2;
		if(curMonth2 < 10){
			currMonStr2 = "0"+currMonStr2;
		}
		var curDateStr2 = curDate2;
		if(curDate2 < 10){
			curDateStr2 = "0"+curDateStr2;
		}
	
		document.multitype.mc_l2_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
		document.multitype.mc_l3_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
		document.multitype.mc_l4_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	}
	if(noOfLegs==2)
	{
		var depMcL3Hdn = getElement("mc_l3_depart_input");
		var depMcL4Hdn = getElement("mc_l4_depart_input");

		depMcL3Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
		depMcL4Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;

		var depMcL3Mon = getElement("mc_l3_dmon_sel");
		var depMcL4Mon = getElement("mc_l4_dmon_sel");

		var depMcL3Dat = getElement("mc_l3_ddat_sel");
		var depMcL4Dat = getElement("mc_l4_ddat_sel");

		depMcL3Dat.selectedIndex = d.getDate()-1;
		depMcL4Dat.selectedIndex = d.getDate()-1;

		depMcL3Mon.selectedIndex = d.getMonth();
		depMcL4Mon.selectedIndex = d.getMonth();

		var currMonStr2 = curMonth2;
		if(curMonth2 < 10){
			currMonStr2 = "0"+currMonStr2;
		}
		var curDateStr2 = curDate2;
		if(curDate2 < 10){
			curDateStr2 = "0"+curDateStr2;
		}
	
		document.multitype.mc_l3_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
		document.multitype.mc_l4_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	}
	if(noOfLegs==3)
	{
		var depMcL4Hdn = getElement("mc_l4_depart_input");

		depMcL4Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;

		var depMcL4Mon = getElement("mc_l4_dmon_sel");

		var depMcL4Dat = getElement("mc_l4_ddat_sel");

		depMcL4Dat.selectedIndex = d.getDate()-1;

		depMcL4Mon.selectedIndex = d.getMonth();

		var currMonStr2 = curMonth2;
		if(curMonth2 < 10){
			currMonStr2 = "0"+currMonStr2;
		}
		var curDateStr2 = curDate2;
		if(curDate2 < 10){
			curDateStr2 = "0"+curDateStr2;
		}
	
		document.multitype.mc_l4_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	}

	}
	if(tripType=="all")
	{
	// AIR form
	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);
	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 depRtHdn = getElement("rt_depart_input");
	var depOwHdn = getElement("ow_depart_input");
	var depMcL1Hdn = getElement("mc_l1_depart_input");
	var depMcL2Hdn = getElement("mc_l2_depart_input");
	var depMcL3Hdn = getElement("mc_l3_depart_input");
	var depMcL4Hdn = getElement("mc_l4_depart_input");
	
	depRtHdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depOwHdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL1Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL2Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL3Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	depMcL4Hdn.value = currMonStr+"/"+curDateStr+"/"+fy;
	
	var depRtMon = getElement("rt_dmon_sel");
	var depOwMon = getElement("ow_dmon_sel");
	var depMcL1Mon = getElement("mc_l1_dmon_sel");
	var depMcL2Mon = getElement("mc_l2_dmon_sel");
	var depMcL3Mon = getElement("mc_l3_dmon_sel");
	var depMcL4Mon = getElement("mc_l4_dmon_sel");
	
	var depRtDat = getElement("rt_ddat_sel");
	var depOwDat = getElement("ow_ddat_sel");
	var depMcL1Dat = getElement("mc_l1_ddat_sel");
	var depMcL2Dat = getElement("mc_l2_ddat_sel");
	var depMcL3Dat = getElement("mc_l3_ddat_sel");
	var depMcL4Dat = getElement("mc_l4_ddat_sel");
	
	depRtDat.selectedIndex = d.getDate()-1;
	depOwDat.selectedIndex = d.getDate()-1;
	depMcL1Dat.selectedIndex = d.getDate()-1;
	depMcL2Dat.selectedIndex = d.getDate()-1;
	depMcL3Dat.selectedIndex = d.getDate()-1;
	depMcL4Dat.selectedIndex = d.getDate()-1;
	
	depRtMon.selectedIndex = d.getMonth();
	depOwMon.selectedIndex = d.getMonth();
	depMcL1Mon.selectedIndex = d.getMonth();
	depMcL2Mon.selectedIndex = d.getMonth();
	depMcL3Mon.selectedIndex = d.getMonth();
	depMcL4Mon.selectedIndex = d.getMonth();
	

	var currMonStr2 = curMonth2;
	if(curMonth2 < 10){
		currMonStr2 = "0"+currMonStr2;
	}
	var curDateStr2 = curDate2;
	if(curDate2 < 10){
		curDateStr2 = "0"+curDateStr2;
	}
	var retRtHdn = getElement("rt_return_input");
	retRtHdn.value = currMonStr2+"/"+curDateStr2+"/"+fy2;
	var retRtMon = getElement("rt_rmon_sel");
	var retRtDat = getElement("rt_rdat_sel");
	retRtDat.selectedIndex = d2.getDate()-1;
	retRtMon.selectedIndex = d2.getMonth();

	document.multitype.rt_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.ow_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l1_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l2_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l3_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
	document.multitype.mc_l4_Depart.value = currMonStr+"/"+curDateStr+"/"+fy;
			document.multitype.rt_Return.value = currMonStr2+"/"+curDateStr2+"/"+fy2;
}
}

function setRegionalCheckBoxValue(idVal)
{
	if(document.getElementById(idVal).checked)
	{
		document.getElementById("regionalsearch").value="true";
	}else if(!document.getElementById(idVal).checked)
		{
		
		document.getElementById("regionalsearch").value="false";
		}
		
}


function setNonStopCheckBoxValue(idVal)
{
	
	if(document.getElementById(idVal).checked)
	{
		document.getElementById("nonstopsearch").value="true";
		
	}else if(!document.getElementById(idVal).checked)
	{
		
		document.getElementById("nonstopsearch").value="false";
	}
		
}

function AJAXInteraction(url,field) 
{
    this.url = url;
    this.field = field;
    var req = init();
    req.onreadystatechange = processRequest;
        
    function init() {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        isIE = true;
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    
    function processRequest () {
      if (req.readyState == 4) {
        if (req.status == 200) {
          postProcess(req.responseXML,field);
        }
      }
    }

    this.send = function() {
        req.open("GET", url, true);
        req.send(null);
    }
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function initAutoComplete(objDocPassed) 
{

	objDoc = objDocPassed.document;
	var rtToTable = objDoc.getElementById("table_popup");
	rtToTable.setAttribute("bordercolor", "white");
	autoCompleteFrame = objDoc.getElementById("iframe1");
	autoCompleteFrame.style.top = 200+"px";
   	autoCompleteFrame.style.left = 200+"px";
   	autoCompleteFrame.style.width = 0;
   	autoCompleteFrame.style.height = 0;
   	autoCompleteFrame.style.visibility="hidden";
   	
}
	

function doCompletion(field) 
{
	flag=0; 
	if(field.value == null)
	{
		//alert("Inside");
	}
	else
	{
	 if((field.value) || (field.value.length==0))
	 {
		if(field.value.length==0)
		{
			tmp = 0;
			clearPopupFrame();
		}
		if(field.value.length <3 && tmp==1 && field.value.length>0)
	     	{
			clearTable();
			postProcess(resData,field);
	    	}
	    	else if (field.value.length<3) 
	    	{
		clearTable();
		document.multitype.elements['hd_'+field.name].value="";
	    	}
	     	else if(field.value.length >=3)
	     	{
				var url = "/dyna/autocomplete?action=complete&id=" + escape(field.value);
				var ajax = new AJAXInteraction(url,field);
				ajax.send();
	    	}
	    	else
	    	{
	    		if(resData!=null)
				{
					var airports = resData.getElementsByTagName("as")[0];
					if(airports.childNodes[0].nodeValue=="Enter city name or choose from the airport code link")
					{
						var url = "/dyna/autocomplete?action=complete&id=" + escape(field.value);
						var ajax = new AJAXInteraction(url,field);
						ajax.send();
			}
			else
			{
				//filtering the unnecessary data
				filterRes(resData,field);
				return;
	    	}
	    	}
		}
	}
	}
}



function postProcess(responseXML,field) 
{
	resData	=	responseXML;
	tmp = 1;
	totField = field;
	var rtToYPos;
	if(isIE)
	{
		rtToYPos = findPosY(field)+field.offsetHeight*2 + 1;
	}
	else if (checkIt('safari'))
	{
		rtToYPos = findPosY(field)+field.offsetHeight*2 + 1;
	}
	else
	{
		rtToYPos = findPosY(field)+field.offsetHeight + 1;
	}
    var rtToXPos = findPosX(field);
	autoCompletePopUp = document.getElementById("menu_popup");
	autoCompleteFrame = document.getElementById("iframe1");
	if(autoCompletePopUp)
	{
	autoCompletePopUp.style.display='block';
	autoCompletePopUp.style.top = rtToYPos + "px";
   	autoCompletePopUp.style.left = rtToXPos + "px";
   	}
   
   	autoCompleteCell = document.getElementById("cell_popup");
    
    clearTable();
	var airports = responseXML.getElementsByTagName("as")[0];
	if(airports.childNodes[0].nodeValue=="Enter city name or choose from the airport code link")
	{
		appendMsg(airports.childNodes[0].nodeValue);
	}
	else
	{
    if (airports.childNodes.length > 0) {
    } else {
        clearTable();
    }
    
    for (loop = 0; loop < airports.childNodes.length; loop++) {
	    var airportInfo = airports.childNodes[loop];
        var displayName = airportInfo.getElementsByTagName("dn")[0];
        var code = airportInfo.getElementsByTagName("c")[0];
        appendAirports(displayName.childNodes[0].nodeValue,code.childNodes[0].nodeValue,field);
        
    }
	}
		if(autoCompletePopUp)
		{
    	autoCompleteFrame.style.top = autoCompletePopUp.style.top;
   		autoCompleteFrame.style.left = autoCompletePopUp.style.left;
        autoCompleteFrame.style.width = autoCompletePopUp.offsetWidth;
   		autoCompleteFrame.style.height = autoCompletePopUp.offsetHeight;
		autoCompleteFrame.style.visibility="visible";
		autoCompleteFrame.style.display='block';
}
}

function cleartmp()
{
	tmp=0;
    //clearPopupFrame();	
}
function clearTable() {
    if (autoCompleteCell) {
      autoCompleteCell.style.visible = false;
      for (loop = autoCompleteCell.childNodes.length -1; loop >= 0 ; loop--) {
        autoCompleteCell.removeChild(autoCompleteCell.childNodes[loop]);
      }
    }
    if(autoCompleteFrame)
    {
    autoCompleteFrame.style.top = 0+"px";
   	autoCompleteFrame.style.left = 0+"px";
   	autoCompleteFrame.style.width = 0;
   	autoCompleteFrame.style.height = 0;
   	autoCompleteFrame.style.visibility="hidden";
   	}
}

function appendAirports(displayName,code) {
    var firstNameCell;
    var lastNameCell;
    var row;
    var nameCell;
	flag = 1;
  /*  if (isIE) {
        row = autoCompleteTable.insertRow(autoCompleteTable.rows.length);
        nameCell = row.insertCell(0);
    } else { */
		var divTag = document.createElement("div");
		divTag.className = "on5";
		if (autoCompleteCell) {	
        autoCompleteCell.appendChild(divTag);
		}
  //  }
    divTag.className = "on5";
    var linkElement = document.createElement("a");
    linkElement.className = "popupItem";
    linkElement.setAttribute("href", "javascript:updateAir('"+code+"','"+displayName+"')");
    linkElement.appendChild(document.createTextNode(displayName));
    divTag.appendChild(linkElement);
}

function appendMsg(msg) {
    var firstNameCell;
    var lastNameCell;
    var row;
    var nameCell;
	flag = 1;
  /*  if (isIE) {
        row = autoCompleteTable.insertRow(autoCompleteTable.rows.length);
        nameCell = row.insertCell(0);
    } else { */
		var divTag = document.createElement("div");
		divTag.className = "on5";
		if (autoCompleteCell) {	
        autoCompleteCell.appendChild(divTag);
		}
  //  }
    divTag.className = "on5";
    //var linkElement = document.createElement("a");
    //linkElement.className = "popupItem";
    //linkElement.setAttribute("href", "javascript:updateAir('"+msg+"')");
    divTag.appendChild(document.createTextNode(msg));
    //divTag.appendChild(linkElement);
}


function updateAir(code,displayname)
{
	
	totField.value=displayname;
	totField.focus();
	document.multitype.elements['hd_'+totField.name].value=code;
	clearTable();
	clearPopupFrame();
}

function clearPopupFrame()
{
	var setTo='none';
	if(autoCompletePopUp)
	{
	autoCompletePopUp.style.top = 0 + "px";
   	autoCompletePopUp.style.left = 0 + "px";
	autoCompletePopUp.style.width = 0;
   	autoCompletePopUp.style.height = 0;
	autoCompletePopUp.style.display=setTo;
	}
	if(autoCompleteFrame)
	{
	autoCompleteFrame.style.display=setTo;
	autoCompleteFrame.style.top = 0+"px";
   	autoCompleteFrame.style.left = 0+"px";
   	autoCompleteFrame.style.width = 0;
   	autoCompleteFrame.style.height = 0;
	}
}


function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
function filterRes(resXML,field)
{
  flag=0;
  var msg_ctr = 0;
  if(resXML!=null)
  {
	var ctr = 0;
	var airports = resXML.getElementsByTagName("as")[0];
	var rtToYPos;

			if(isIE)
			{
				rtToYPos = findPosY(field)+field.offsetHeight*2 + 1;
			}
			else if (checkIt('safari'))
			{
				rtToYPos = findPosY(field)+field.offsetHeight*2 + 1;
			}
			else
			{
				rtToYPos = findPosY(field)+field.offsetHeight + 1;
			}
			var rtToXPos = findPosX(field);
			autoCompletePopUp = document.getElementById("menu_popup");
			autoCompleteFrame = document.getElementById("iframe1");
			if(autoCompletePopUp)
			{	
			autoCompletePopUp.style.top = rtToYPos + "px";
   			autoCompletePopUp.style.left = rtToXPos + "px";
			}
   			autoCompleteCell = document.getElementById("cell_popup");
	clearTable();
    
		for (loop = 0; loop < airports.childNodes.length; loop++) 
		{
	    var airportInfo = airports.childNodes[loop];
        var displayName = airportInfo.getElementsByTagName("dn")[0];
		var code = airportInfo.getElementsByTagName("c")[0];
		var airport_name	=	displayName.childNodes[0].nodeValue;
		ctr=0;
			if(field.value.length>4)
		{

		}
			var re = new RegExp(field.value.toLowerCase());
	/*	for(var i=0; i<field.length; i++)
		{
			if(airport_name.toLowerCase().charAt(i)==field.toLowerCase().charAt(i))
			{
				ctr++;
			}
		} */
		if (airport_name.toLowerCase().match(re)) {
			ctr=1;
		}
		if(ctr == 1)
		{
			 appendAirports(airport_name,code.childNodes[0].nodeValue,field);
			 msg_ctr = 1;
		}
    }
	    if(msg_ctr!=1)
		{
			 appendMsg("Enter city name or choose from the airport code link");
		}
			if(autoCompletePopUp)
			{
    		autoCompleteFrame.style.top = autoCompletePopUp.style.top;
   			autoCompleteFrame.style.left = autoCompletePopUp.style.left;
			autoCompleteFrame.style.width = autoCompletePopUp.offsetWidth;
			autoCompleteFrame.style.height = autoCompletePopUp.offsetHeight;
			autoCompleteFrame.style.visibility="visible";
}
}
}
function flipTabs(tabIndex)
{
	var imageName = '/images/modify' + tabIndex + '.gif' ;
	movepic('tabimage',imageName);
	if(tabIndex == 0){
	 isboth = true;
	 isnew=false;
		}
	else if(tabIndex == 1){isnew=false; isboth = false;
		}
	else if(tabIndex == 2){isnew=true;isboth= false;
		}
		//putFocus();
}

function movepic(img_name,img_src)
{
	document[img_name].src=img_src;
}

function lookupDepart(tripType){
  var x, y;
 
  if(tripType=="round")
	{
		var element = document.forms[0].rt_from;
	}
  if(tripType=="one")
	{
		var element = document.forms[0].ow_from;
	}
  if((tripType=="multi1") || (tripType=="multi2") || (tripType=="multi3") || (tripType=="multi4"))
	{
		var element = document.forms[0].mc_l1_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 + 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 + 160;
  y = y - 240;
  if(navigator.appName=="Netscape")
	{
		x = x - 20;
		y = y + 20;
	}
  var newWin = 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;
  if(tripType=="round")
	{
		var element = document.forms[0].rt_from;
	}
  if(tripType=="one")
	{
		var element = document.forms[0].ow_from;
	}
  if((tripType=="multi1") || (tripType=="multi2") || (tripType=="multi3") || (tripType=="multi4"))
	{
		var element = document.forms[0].mc_l1_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 + 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 - 100;
  y = y - 240;
  if(navigator.appName=="Netscape")
	{
		x = x + 20;
		y = y + 20;
	}
  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 defaultvalues(isnearby,isNonStop)
{

if(isnearby=="true")
{

	document.multitype.rt_regionalsearch.checked = "true";
	document.multitype.ow_regionalsearch.checked = "true";
	document.multitype.mc_regionalsearch.checked = "true";
}

if(isNonStop=="true")
{
	document.multitype.ow_nonstop_search.checked = "true";
	document.multitype.rt_nonstop_search.checked = "true";
	document.multitype.mc_nonstop_search.checked = "true";

}
}

