//.........................................................chkvalidate.js.....................................................................//

function setDates() {
  now = new Date();
  dep = new Date();
  ret = new Date(); 
  dep.setTime(now.getTime()+60000*60*24*3);
  ret.setTime(now.getTime()+60000*60*24*6);
  var m1 = dep.getMonth()+1;      
  var d1   = dep.getDate();  
  var m2 = ret.getMonth()+1;   
  var d2   = ret.getDate();
  var y1 = dep.getYear();
  var y2 = ret.getYear();
  m1 = m1 < 10 ? '0' + m1 : m1;
  m2 = m2 < 10 ? '0' + m2 : m2;
  d1 = d1 < 10 ? '0' + d1 : d1;
  d2 = d2 < 10 ? '0' + d2 : d2;
  y1 = y1 < 1000 ? y1 + 1900 : y1;
  y2 = y2 < 1000 ? y2 + 1900 : y2;  
  document.SearchFare.depart_date.value=m1+'/'+d1+'/'+y1;
  document.SearchFare.return_date.value=m2+'/'+d2+'/'+y2; 
  document.SearchFare.trip_type[0].checked = true;
}

function saveCurrentData() 
{   
	var agent_flag = 0;
	var ac2u_flag = 0;
	for(i=0; i<document.SearchFare.elements.length; i++)
	{
		if (document.SearchFare.elements[i].name == 'agent_id'){
			agent_flag = 1;
		}
		if (document.SearchFare.elements[i].name == 'ac2u'){
			ac2u_flag = 1;
		}
		//document.write("The field name is: " + document.SearchFare.elements[i].name + " and it’s value is: " + document.SearchFare.elements[i].value + ".<br />");
	}
    var trip = document.SearchFare.trip_type[0].checked?1:0;
	if (document.SearchFare.trip_type[2].checked){
		trip = 2;
	}		
	var data = '';
	data = document.SearchFare.gateway_dep.value;
	data += ":" + document.SearchFare.gateway_ret.value;    	
	data += ":" + trip;
	data += ":" + document.SearchFare.depart_date.value;
	data += ":" + document.SearchFare.return_date.value;
	data += ":" + document.SearchFare.adult.value;
	data += ":" + document.SearchFare.child.value;
	data += ":" + document.SearchFare.infant.value;	
    data += ":" + document.SearchFare.cls.value;
	data += ":" + document.SearchFare.gateway_departure.value; 
	data += ":" + document.SearchFare.gateway_return.value; 
	data += ":" + document.SearchFare.dest_dep.value; 
	data += ":" + document.SearchFare.dest_ret.value; 
	data += ":" + document.SearchFare.dest_departure.value; 
	data += ":" + document.SearchFare.dest_return.value; 		
	data += ":" + document.SearchFare.client_ref.value;
    data += ":" + document.SearchFare.currency.value;
	if (ac2u_flag)
	{
		data += ":" + document.SearchFare.ac2u.value;
	}
	if (agent_flag)
	{
		//alert(document.SearchFare.agent_id.value);
		data += ":" + document.SearchFare.agent_id.value;
	}
	document.cookie= "fn_query=" + escape(data) + ";path=/";
	//alert(data);
}


function set_date_from_cookie() 
{	
	var datacookie = document.cookie;
	var prefix = "fn_query=";
	var begin = datacookie.indexOf(prefix);	
	if (begin >= 0 )
	{        
	    var data = unescape(datacookie.substring(begin+prefix.length));        
        var fn_cookies= data.split(";");
		var arrdata= fn_cookies[0].split(":");        
		document.SearchFare.gateway_dep.value =arrdata[0];
		document.SearchFare.gateway_ret.value =arrdata[1];
		document.SearchFare.gateway_departure.value =arrdata[9];
		document.SearchFare.gateway_return.value =arrdata[10];
        document.SearchFare.trip_type[0].checked = true;               
		document.SearchFare.depart_date.value =arrdata[3];
	if(arrdata[4] == null || arrdata[4] == '') {
		arrdata[4] = add_days(arrdata[3],3);
	}
        document.SearchFare.return_date.value =arrdata[4];
		document.SearchFare.adult.value =arrdata[5];
        document.SearchFare.child.value =arrdata[6];
		document.SearchFare.infant.value =arrdata[7];
        document.SearchFare.cls.value =arrdata[8];	
	
	}
	
}


function getCurrentDate() {
  now = new Date();  
  var m1 = now.getMonth()+1;      
  var d1 = now.getDate();    
  var y1 = now.getYear(); 
  m1 = m1 < 10 ? '0' + m1 : m1;  
  d1 = d1 < 10 ? '0' + d1 : d1;  
  y1 = y1 < 1000 ? y1 + 1900 : y1; 
  
  var date = m1+'/'+d1+'/'+y1; 
  return(date); 
}

function compareDate(date1,date2,type) {
 // var calRE = getFormat();

    var dStr1 = date1.substring(6,10) + "" + date1.substring(0,2) + "" + date1.substring(3,5);
    var dStr2 = date2.substring(6,10) + "" + date2.substring(0,2) + "" + date2.substring(3,5);
        
  if (dStr1 == dStr2)
  {   
    return 0;
  }
  else if (dStr1 < dStr2 && type == 1)
  {   
    return 1;
  }
  else if (dStr1 > dStr2 && type == 2)
  {   
    return 1;
  }
  else {
    return -1;
  }
}

function chkNumofDays(date){
     //Get 1 day in milliseconds
    var one_day=1000*60*60*24;
    var today=new Date();
    var sel_date=new Date(date.substring(6,10),date.substring(0,2)-1,date.substring(3,5));
    
    //Calculate difference btw the two dates, and convert to days
    var diff = Math.ceil((sel_date.getTime()-today.getTime())/(one_day));
    //alert(diff);
    return diff;
}

function setReturnDate(){       
    var date = document.SearchFare.depart_date.value;  
    var dep =new Date(date.substring(6,10),date.substring(0,2)-1,date.substring(3,5));
    dep.setTime(dep.getTime()+60000*60*24*7);
    var m1 = dep.getMonth()+1;      
    var d1 = dep.getDate();    
    var y1 = dep.getYear();
 
    m1 = m1 < 10 ? '0' + m1 : m1; 
    d1 = d1 < 10 ? '0' + d1 : d1; 
    y1 = y1 < 1000 ? y1 + 1900 : y1;
  
    document.SearchFare.return_date.value=m1+'/'+d1+'/'+y1;    
}

function checksyntax(date)
{
    var now = new Date();
    var y = now.getYear(); 
    y = y < 1000 ? y + 1900 : y;    
    if (date.substring(2,3) != '/')
    {
        date = '0' + date
    }
    if (date.substring(5,6) != '/')
    {
        date = date.substring(0,3) + '0' + date.substring(3,10)
    }
    
    if (date.length != 10)
    {
        date = date.substring(0,6) + y;
    }

    if (date.substring(2,3) != '/' && date.substring(5,6) != '/')
    {
        return 1;
    }    
    else
    {
    return date;
    }
}

function is_valid_airport(id) {

   var city = document.getElementById(id).value;   
   if ( city.length < 3 )  {
      alert('Please make sure you have selected the right ' + id + ' airport');
      return false;
   }

   var code = city.toUpperCase();

   if ( code.length < 3 )  {
      alert('Please make sure you have selected the right ' + id + ' airport');
      return false;
   }

   if ( city.length >= 3 ) {
      var code = city.replace(/.*\((...)\)/, "$1").toUpperCase();
   }
   
   if ( code.length == 3 ) {   	
   	if (id == "gateway_departure"){
      		document.SearchFare.gateway_dep.value = code;
	}
	if (id == "gateway_return"){
      		document.SearchFare.gateway_ret.value = code;
	}
	if (id == "dest_departure"){
      		document.SearchFare.dest_dep.value = code;
	}
	if (id == "dest_return"){
      		document.SearchFare.dest_ret.value = code;
	}
      return true;
   }

   alert('Please make sure you have selected the right airport');
   return false;
}


function ValidateDate() {	
    is_valid_airport('gateway_departure');
    is_valid_airport('gateway_return');	
    if (document.SearchFare.trip_type[2].checked){
    	is_valid_airport('dest_departure');
    	is_valid_airport('dest_return');
    }
    if (!(document.SearchFare.trip_type[0].checked || document.SearchFare.trip_type[1].checked ||
    document.SearchFare.trip_type[2].checked))
    {
        alert('Please select the Trip type');
        return false;
    }
    if (document.SearchFare.depart_date.value.length > 0) {
        var date = document.SearchFare.depart_date.value;
        if (date.substring(0,2) > 12){
            alert('The Depart Date Format is Incorrect.  Please enter the date in this format MM/DD/YYYY')
            return false;
        }
    }
    else {
	    alert('You must select a departing date');
	    return false;
    }

    if (document.SearchFare.depart_date.value == 'mm/dd/yyyy')
    {
        alert('Please Select Departure Date');
        document.SearchFare.depart_date.focus();
        return false;
    }
    else if (checksyntax(document.SearchFare.depart_date.value) == 1)
    {
        alert('The Depart Date Format is Incorrect')
        return false;
    }
    else
    {
        document.SearchFare.depart_date.value = checksyntax(document.SearchFare.depart_date.value)
    }        

    if (compareDate(document.SearchFare.depart_date.value, getCurrentDate(),1) == 1)
    {
        alert('Your depart date is earlier than today. Please select another date.')
        return false;
    }
           
    if (document.SearchFare.trip_type[0].checked || document.SearchFare.trip_type[2].checked){        
        if (document.SearchFare.return_date.value.length > 0 ) {
            var date = document.SearchFare.return_date.value;
            if (date.substring(0,2) > 12){
                alert('The Return Date Format is Incorrect.  Please enter the date in this format MM/DD/YYYY')
                return false;
            }
        }
        else {        
            alert('You must select a returning date');
            return false;        
        }
        
        if (document.SearchFare.return_date.value == 'mm/dd/yyyy')
	    {
    	    alert('Please Select Return Date');
            document.SearchFare.return_date.focus();
    	    return false;
    	}
        else if (checksyntax(document.SearchFare.return_date.value) == 1)
        {
            alert('The Return Date Format is Incorrect')
            return false;
        }
        else
        {        
            document.SearchFare.return_date.value = checksyntax(document.SearchFare.return_date.value);        
        }
    
        if (compareDate(document.SearchFare.return_date.value, getCurrentDate(),1) == 1)
        {
            alert('Your return date is earlier than today. Please select another date.')
            return false;
        }
        
        if (compareDate(document.SearchFare.depart_date.value,document.SearchFare.return_date.value,2) == 1)
        {
            alert('Your return date is earlier than departure date. Please select another date.')
            return false;
        } 
      }
   
    if (document.SearchFare.trip_type[1].checked)
    {
    	 if (document.SearchFare.return_date.value == 'mm/dd/yyyy')
	    	{
				document.getElementById( 'return_date' ).value="";
			}
	}
            
    if (document.SearchFare.gateway_departure.value == '')
    {
		var depart_alert = "Please enter the departure city or select a city from the drop down list.  ";
		depart_alert += "If you have entered a city and you see this message please make sure ";
		depart_alert += "you have entered the city only and no province, state or country.";
        alert(depart_alert);
        return false;
    }

    if (document.SearchFare.gateway_return.value == '')
    {
		var return_alert = "Please enter the destination city or select a city from the drop down list.  ";
		return_alert += "If you have entered a city and you see this message please make sure ";
		return_alert += "you have entered the city only and no province, state or country.";
        alert(return_alert);
        return false;
    } 
	if (document.SearchFare.trip_type[2].checked){
		 if (document.SearchFare.dest_departure.value == '')
		{
			var depart_alert = "Please enter the destination departure city or select a city from the drop down list.  ";
			depart_alert += "If you have entered a city and you see this message please make sure ";
			depart_alert += "you have entered the city only and no province, state or country.";
			alert(depart_alert);
			return false;
		}
	
		if (document.SearchFare.dest_return.value == '')
		{
			var return_alert = "Please enter the destination return city  or select a city from the drop down list.  ";
			return_alert += "If you have entered a city and you see this message please make sure ";
			return_alert += "you have entered the city only and no province, state or country.";
			alert(return_alert);
			return false;
		} 
	}
     if (document.SearchFare.infant.value)
    {
        if (document.SearchFare.infant.value > document.SearchFare.adult.value)
        {
            alert('Number of Infants must be less than equal to number of Adults');
            return false;
        }
    }  
    saveCurrentData(); 
	omnitureOnClickCode();
    return true;
}

function omnitureOnClickCode() {
	
	var s=s_gi('flightnetworkprod'); 					//use the proper report suite

	//all variables that will be set - including the events variable
	s.linkTrackVars='events,prop1,prop2,prop3,prop4,prop5,prop6,prop7,prop8,prop9,prop10,prop11,prop12,prop15,prop16,eVar1,eVar2,eVar3,eVar4,eVar5,eVar6,eVar7,eVar8,eVar9,eVar10,eVar11,eVar12,eVar20,prop22,prop25,prop26,prop27,prop50,eVar22,eVar25,eVar26,eVar27,eVar50';
	
	//the events that will be tracked in s.events				 		
	s.linkTrackEvents='event1';
	
		//now set all variables as normal
	s.events='event1';   //Set the search event						
	s.prop1=s.eVar1=document.SearchFare.gateway_dep.value;   //Origin City
	s.prop2=s.eVar2=document.SearchFare.gateway_ret.value;   //Destination City
	s.prop3=s.eVar3=document.SearchFare.gateway_dep.value + ' - ' +document.SearchFare.gateway_ret.value; //Origin-Destination City Pair
	s.prop4=s.eVar4=document.SearchFare.depart_date.value;  //Departure Date
	//alert("Prop 1: " + document.SearchFare.gateway_dep.value + 'Prop2: ' +  document.SearchFare.gateway_ret.value + ' '+document.SearchFare.depart_date.value + ' ' + document.SearchFare.return_date.value);
	//alert("Prop 1: " + s.prop1 + 'Prop2: ' + s.prop2 + 'Prop3: '+ s.prop3 + 'Prop4: ' + s.prop4);
	var tripduration = chkNumofDays(document.SearchFare.return_date.value) - chkNumofDays(document.SearchFare.depart_date.value);
       
	//s.prop6=s.eVar6=tripduration;   //Trip Duration
	s.prop7=s.eVar7=chkNumofDays(document.SearchFare.depart_date.value); //Days to Departure

        s.prop8 = s.eVar8 = 0;
        s.prop9 = s.eVar9 = 0;
        s.prop10 = s.eVar10 = 0;
        s.prop11 = s.eVar11 = 0;
	s.prop8=s.eVar8=document.SearchFare.adult.value;   //# of Adults
	s.prop9=s.eVar9=document.SearchFare.child.value;  //#of Children
	s.prop10=s.eVar10=document.SearchFare.infant.value; //# of Infants
	s.prop11=s.eVar11= s.prop8*1 + s.prop9*1;  //# of passengers - sum prop8 and prop9
	var triptype = 'Round Trip';						// default - round trip
	if(document.SearchFare.trip_type[1].checked) triptype = 'Oneway';	// one way
	if(document.SearchFare.trip_type[2].checked) triptype = 'MultiCity';	// open jaw
	//alert("TripType is " + triptype);
	s.prop12 = s.eVar12 = triptype; //Flight Type
	if(triptype == 'Oneway') {
		s.prop5=s.eVar5='0'; //Return Date
		s.prop6=s.eVar6='0';   //Trip Duration
	}
	else {
		s.prop5=s.eVar5=document.SearchFare.return_date.value; //Return Date
		s.prop6=s.eVar6=tripduration;   //Trip Duration
	}
	s.prop16 = s.pageName;	
        //alert("values " + chkNumofDays(document.SearchFare.depart_date.value) + ' ' +  document.SearchFare.adult.value + ' '+document.SearchFare.child.value + ' ' + document.SearchFare.cls.value);
        //alert("Prop7: " + s.prop7 + 'Prop8: ' + s.prop8 + 'prop9: '+ s.prop9 + 'prop10: ' + s.prop10 + 'prop11: ' + s.prop11 + 'prop12: ' + s.prop12);
	
	//Send the image request
	s.tl('www.flightnetwork.com', 'o', 'Flight Search');		//send the image request - see the manual for the parameter options

        	
	//Best proctice is to clear all variables once the s.tl call has been sent
	s.events='';					
	s.prop1=s.eVar1='';			
	s.prop2=s.eVar2='';			
	s.prop3=s.eVar3='';		
	s.prop4=s.eVar4='';	
	s.prop5=s.eVar5='';	
	s.prop6=s.eVar6='';			
	s.prop7=s.eVar7='';			
	s.prop8=s.eVar8='';			
	s.prop9=s.eVar9='';			
	s.prop10=s.eVar10='';			
	s.prop11=s.eVar11='';			
	s.prop12=s.eVar12='';
	
}

//....................................................................frmdisplay.js.....................................................................//

function DisplayOJ() { 
    var city1 = document.getElementById('CITY1');  
    city1.style.display = 'inline';
    var city2 = document.getElementById('CITY2');  
    city2.style.display = 'inline';
    document.SearchFare.return_date.disabled = false; 

    // This removes all listeners associated to the element with specified id.
    YAHOO.util.Event.purgeElement( document.getElementById( "return_date_calendar_ico" ) );
    YAHOO.util.Event.purgeElement( document.getElementById( "return_date" ) );

    YAHOO.util.Event.addListener("return_date_calendar_ico", "click", launchCalendar);
    YAHOO.util.Event.addListener("return_date", "focus", launchCalendar);
}

function DisplayReturn()
{
    var city1 = document.getElementById('CITY1');  
    city1.style.display = 'none';
    var city2 = document.getElementById('CITY2');  
    city2.style.display = 'none';
    document.SearchFare.return_date.disabled = false; 

    // This removes all listeners associated to the element with specified id.
    YAHOO.util.Event.purgeElement( document.getElementById( "return_date_calendar_ico" ) );
    YAHOO.util.Event.purgeElement( document.getElementById( "return_date" ) );

    YAHOO.util.Event.addListener("return_date_calendar_ico", "click", launchCalendar);
    YAHOO.util.Event.addListener("return_date", "focus", launchCalendar);
}

function DisplayOneway()
{
    var city1 = document.getElementById('CITY1');  
    city1.style.display = 'none';
    var city2 = document.getElementById('CITY2');  
    city2.style.display = 'none';
    document.SearchFare.return_date.disabled = true;

    // This removes all listeners associated to the element with specified id.
    YAHOO.util.Event.purgeElement( document.getElementById( "return_date_calendar_ico" ) );
    YAHOO.util.Event.purgeElement( document.getElementById( "return_date" ) );
}

//.........................................................Date.js.....................................................................//

// $Id: date.js 4 2008-08-18 15:52:41Z damian $

//  Update date script. 

//  Calcate and update the new return date if the entered departure date is previous than the current return date

function update_return_date(depart_date) {
   var return_date = document.getElementById( 'return_date' );
   if (isDate(depart_date)) {
	  	  return_date.value="";
		  return_date.value = add_days(depart_date, 3);
   }
}  


// return date added the passed date to the number of days passed
function add_days(date, days){

   var n_days = new Number(days);
   var dt = new Date(date);
   	
   dt.setDate(dt.getDate() + n_days);
   var month=(dt.getMonth()+1)<= 9 ?"0"+(dt.getMonth()+1):(dt.getMonth()+1);
   var date = dt.getDate()<=9?"0"+dt.getDate():dt.getDate();
   var date_str = month + '/' + date + '/' + dt.getFullYear();

   return date_str;
}

function get_today(){

   var today = new Date();
   var month=(today.getMonth()+1)<= 9 ?"0"+(today.getMonth()+1):(today.getMonth()+1);
   var date = today.getDate()<=9?"0"+today.getDate():today.getDate();
   var date_str = month + '/' + date + '/' + today.getFullYear();
   return date_str;
}

function get_days_after(date){

   if ( date ) {
      var today = new Date(date);
   } else {
      var today = new Date();
   }

   today.setDate(today.getDate()-1);
   var month=(today.getMonth()+1)<= 9 ?"0"+(today.getMonth()+1):(today.getMonth()+1);
   var date = today.getDate()<=9?"0"+today.getDate():today.getDate();
   var date_str = month + '/' + date + '/' + today.getFullYear();
   return date_str;
}

function get_next_year(){

   var today = new Date();

   today.setDate(today.getDate()+330);
   var month=(today.getMonth()+1)<= 9 ?"0"+(today.getMonth()+1):(today.getMonth()+1);
   var date = today.getDate()<=9?"0"+today.getDate():today.getDate();
   var date_str = month + '/' + date + '/' + today.getFullYear();
   return date_str;
}

//  date validation script. 
//  Originate from Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
//
//  Declaring valid date character, minimum year and maximum year
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){

    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("The date format should be : mm/dd/yyyy")
        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 enter a valid day")
        return false;
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        alert("Please enter a valid 4 digit year")
        return false;
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
        alert("Please enter a valid date")
        return false;
    }
    return true;
}

//.........................................................calender_handler.js.....................................................................//

// $Id: calendar_handler.js 137 2008-10-23 17:07:47Z damian $

// scripts to handle yahoo calendar

function launchCalendar(e) {
   if ( this.id.match('return') ) {
      input_id = 'return_date';
      cal_title = 'Select Return Date';
      if (document.getElementById( 'return_date' ).value == "")	{
		document.getElementById( 'return_date' ).value = document.getElementById( 'depart_date' ).value;
		}
      if (document.getElementById( 'return_date' ).value == "mm/dd/yyyy")	{
	      if (document.getElementById( 'depart_date' ).value == "mm/dd/yyyy")	{
			alert("Please Select Departure Date First");
			document.getElementById( 'depart_date' ).focus();
		  }
		  else{
		    var dep_date= document.getElementById( 'depart_date' ).value;
			document.getElementById( 'return_date' ).value="";
			document.getElementById( 'return_date' ).value = add_days(dep_date, 3);
		  }
	  }
   } 
   else {
      input_id = 'depart_date';
      cal_title = 'Select Departure Date';
   }

   initCalendar( cal_title );
   document.getElementById('calendar').style.display = '';
}


function handleSelect(type,args,obj) {
   var dates = args[0];
   var date = dates[0];
   var year = date[0], month =date[1]<=9?"0"+date[1]:date[1], day = date[2]<=9?"0"+date[2]:date[2];
   // update input field
   var dateTxtBx = document.getElementById( input_id );

   dateTxtBx.value = month + "/" + day + "/" + year;

   // if input_id is 'departure date', then check return date
   if ( input_id == 'depart_date' ) {
     var r_date = document.getElementById( 'return_date' );
     var trip_type;
     if ( document.getElementById( 'trip_type' ).type == 'radio' ) {
          trip_type = document.SearchFare.trip_type[1].checked?0:1;
	 }
	 else {
		var tripType_ddl_cal = document.SearchFare.trip_type;
		var tripType_ddl_val = tripType_ddl_cal.options[ tripType_ddl_cal.selectedIndex ].value;
		if ( tripType_ddl_val == '0' ) {
			trip_type = 0;
		}
		else {
			trip_type = 1;
		}
	}
    if ( r_date && new Date( dateTxtBx.value ) > new Date(r_date.value) ) { update_return_date( dateTxtBx.value ); }

   }
   this.hide();
}

function initCalendar( cal_title ) {

   // setting mindate and maxdate for calendar
   var depart_date = document.getElementById( 'depart_date' );
   var return_date = document.getElementById( 'return_date' );
   //var return_area = document.getElementById( 'return_area' );

   if ( input_id == 'return_date' && depart_date ) {
      var mindate = depart_date.value;
   } else {
      var mindate = get_today();
   }

   var maxdate = get_next_year();

   var in_date = document.getElementById( input_id );
   if ( in_date ) {
		if(in_date.value=='mm/dd/yyyy') {
		 	 var dates = get_today().split('/');
		 }
		 else {
		 	 var dates = in_date.value.split('/');
		 }
   } else {
      var dates = get_today().split('/');
   }
   var pagedate = dates[0]+'/'+dates[2];

   YAHOO.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","calendar", { title: cal_title, pages: 3,  pagedate: pagedate, mindate: mindate, maxdate: maxdate, close: true });

   YAHOO.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.calendar.cal1, true);

   if ( depart_date ) { YAHOO.calendar.cal1.addRenderer(depart_date.value, YAHOO.calendar.cal1.renderCellStyleHighlight1); }

  // if ( return_date && return_area.style.display != 'none' ) { YAHOO.calendar.cal1.addRenderer(return_date.value, YAHOO.calendar.cal1.renderCellStyleHighlight2); }
	//#7497 START
   /**
	*	Added for RT #7497
	*	To remove Back Navigation Arrow from the default Calender
	* Added by: Thathees Siva
	*/
	YAHOO.calendar.cal1.renderEvent.subscribe(
			function (type, args) { 
			
				var fromDate = args[0];
				var toDate = args[1];
				var currentDate = YAHOO.calendar.cal1.pages[0].cfg.getProperty("pagedate");
				var today = new Date();
			
				if(currentDate< today){
					var calNavLeft = YAHOO.util.Dom.getElementsByClassName("calnavleft", "a", "calendar")[0];
					calNavLeft.style.display = "none";
					YAHOO.util.Event.removeListener(calNavLeft,'click');
				}
			});
	//#7497 END
   YAHOO.calendar.cal1.render();
}

/*function update_travel() {
      if(document.frmFlights.travel[1].checked) {
         document.frmFlights.travel.value = document.frmFlights.travel[1].value;
         document.getElementById("return_area").style.display = 'none';
      }
      if(document.frmFlights.travel[0].checked) {
         document.frmFlights.travel.value = document.frmFlights.travel[0].value;
         document.getElementById("return_area").style.display = '';
         if (document.getElementById("return_date").value == '') {
             document.getElementById("return_date").value = document.getElementById("depart_date").value;
         }
      }
}*/



//.........................................................detectbrowser.js.....................................................................//

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

//.........................................................flightnetwork.js.....................................................................//

//alert("Hello " +BrowserDetect.OS);
var currentTime = new Date();
var year = currentTime.getFullYear();
document.write('<meta name="robots" content="index, follow">');
document.write('<meta name="copyright" content="Flight Network Cheap Flights,1998-'+year+'">');
if (BrowserDetect.browser == "Explorer") { // Windows
	 if( BrowserDetect.version =="6") { //IE-6
		 document.write('<link href="/css/style1-ie6.css" rel="stylesheet" type="text/css"/>');
	 }
	 else if( BrowserDetect.version =="7") { //IE-7
		 document.write('<link href="/css/style1-ie7.css" rel="stylesheet" type="text/css"/>');
	 }
	 else if( BrowserDetect.version =="8") { //IE-8
		 document.write('<link href="/css/style1-ie8.css" rel="stylesheet" type="text/css"/>');
	 }
	 else{
		 document.write('<link href="/css/style1-ie6.css" rel="stylesheet" type="text/css"/>');
	 }
 }
 else if (BrowserDetect.browser == "Firefox") { //Linux
	 if( BrowserDetect.OS =="Linux") { // Firebox in Linux
		 document.write('<link href="/css/style1-ff.css" rel="stylesheet" type="text/css"/>');
	 }
	 else { // Firefox in IE
		 document.write('<link href="/css/style1-ffi.css" rel="stylesheet" type="text/css"/>');
	 }
 }
 else if (BrowserDetect.browser == "Safari") { //Safari
	 if( BrowserDetect.OS =="Windows") { // Safari in Windows
		 document.write('<link href="/css/style1-sfi.css" rel="stylesheet" type="text/css"/>');
	 }
	 else if( BrowserDetect.OS =="Mac") { // Safari in Mac
		 document.write('<link href="/css/style1-sf.css" rel="stylesheet" type="text/css"/>');
	 }
	else { // others
		 document.write('<link href="/css/style1-sf.css" rel="stylesheet" type="text/css"/>');
	 }
 }

 else if (BrowserDetect.browser == "Chrome") { //Chrome
	 document.write('<link href="/css/style1-ch.css" rel="stylesheet" type="text/css"/>');
 }
 else { // Generic Default
//alert("Hello " +BrowserDetect.browser);
	
	document.write('<link href="/css/style1.css" rel="stylesheet" type="text/css"/>'); 
	 
 }


//.........................................................b2cv3/ft_account.js.....................................................................//

function get_xhttp_object(){
	var http_request = false;
    if (window.XMLHttpRequest)
	{ //all but IE
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
		{
            http_request.overrideMimeType('text/xml');
        }
    }
	else if (window.ActiveXObject)
	{ //IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
	if (!http_request)
	{
        alert("http_request could not be established.");
        return false;
    }
	return http_request;
}
//.........................................................us_canada_pagecookie.js.....................................................................//

function setCookie()
        {
            var value="us";
            var expiredays = 1825;
            var exdate=new Date();
            exdate.setDate(exdate.getDate()+expiredays);
            document.cookie="hasVisited=" +escape(value)+((expiredays==null) ? "" : ";path=/;expires="+exdate.toGMTString());
        }

function getCookie(c_name)
{
	
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function checkCookie()
{
	searchstr=getCookie('hasVisited');
	if(searchstr == 'us') {
		var fullurl = location.href;
		var qln = fullurl.indexOf('?');
		 if(qln != -1) {
			var qstring = fullurl.substr(qln+1);
			//alert("Hello "+qstring);
			window.location='us/?'+qstring;
		}
		else {
			window.location=location.href+'us/';
		}
	}
		//window.location=location.href+'us/index.shtml';
}

function deleteCookie()
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime(cookie_date.getTime() - 1);
  document.cookie = "hasVisited=;path=/;expires=" + cookie_date.toGMTString();
}

//........................................................ homepage.js ................................................................................//
// yahoo calendar
var input_id = 'depart_date';
var cal_title = 'Select Departure Date';
YAHOO.namespace("calendar");

YAHOO.util.Event.addListener("depart_date_calendar_ico", "click", launchCalendar);
YAHOO.util.Event.addListener("depart_date", "focus", launchCalendar);
YAHOO.util.Event.addListener("return_date_calendar_ico", "click", launchCalendar);
YAHOO.util.Event.addListener("return_date", "focus", launchCalendar);

function LoadAutocompleter() {

	new Ajax.Autocompleter('gateway_departure', 'd_hint1', '/cgi-bin/b2c-v3/get_airport.cgi', {minChars: 3, frequency: 0.1});
    	new Ajax.Autocompleter('gateway_return', 'r_hint1', '/cgi-bin/b2c-v3/get_airport.cgi', {minChars: 3, frequency: 0.1});
    	new Ajax.Autocompleter('dest_departure', 'd_hint2', '/cgi-bin/b2c-v3/get_airport.cgi', {minChars: 3, frequency: 0.1});
    	new Ajax.Autocompleter('dest_return', 'r_hint2', '/cgi-bin/b2c-v3/get_airport.cgi', {minChars: 3, frequency: 0.1});
	
}
function set_dest() {
	searchstr=getCookie('hasVisited');
    var url = location.href;
    var idx = url.indexOf('d=');    	
    if(idx != -1 && searchstr != 'us') {
    	city = url.substr(idx+2);
    	http_request = get_xhttp_object();
		var url = '/cgi-bin/b2c-v3/auto_populate.cgi?city_name='+ city;
		http_request.open('GET',url,false);
		http_request.send(null);
		if ( http_request.status == 200 ) {
			var response = http_request.responseText;
			document.getElementById('gateway_return').value = response; 
		}
    	
    }
}
function check()
{
     if(navigator.cookieEnabled)
     {
       	document.getElementById("wrapper").style.display = "block";
       	document.getElementById("vpartner").style.display = "block";
       	document.getElementById("cr").style.display = "block";
     }
     else
     {
       	window.location.href='/b2c-v3/fn_warning.html';
     }	
}
function reset_menu(mid){
	document.getElementById(mid).style.backgroundImage = 'url(/img/bg-menu-hover.gif)';
}

var curr_lb_div; 
var is_modal = false; 
function ShowLightBox(lb_div, isModal) { 
    document.getElementById(lb_div).style.display='block'; 
    document.getElementById('fade').style.display='block'; 
    curr_lb_div = lb_div;
    if (isModal) 
    is_modal = true; 
    else is_modal = false;
    setTimeout("HideLightBox()",3000);
} 
function HideLightBox() { 
    if (document.getElementById(curr_lb_div)) 
    { 
        document.getElementById(curr_lb_div).style.display='none'; 
        document.getElementById('fade').style.display='none'; 
        curr_lb_div = ''; 
    } 
} 
var http_request = false;
function makePOSTRequest(url, parameters) {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
        }
    } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            	try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            	} catch (e) {}
         	}
      }
    if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
    }
      
//       http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
function get(obj) {
   var poststr = document.getElementById("txtemail").value  ;
   var testresults;
   var filter=/^.+@.+\..{2,3}$/ ;

      if (filter.test(poststr)) {

            testresults=true;
	    ShowLightBox('single1');
            makePOSTRequest('/cgi-bin/b2c-v3/SuccessByEmail/cgi/successClient.cgi', poststr);

       }
	  else{
            ShowLightBox('single2');
	    lightbox_msg.title = "ERROR : Invalid email address; Please check the email address. ";
            testresults=false;
       }
     return (testresults);
   }
