﻿//this value allows you to specify where the .swf file for the searching animation is stored
var searchSWF = new String('images/new_searching.swf');

//this value allows you to specify where the smaller .swf file for the vertical gui searching animation is stored
var searchSWFSmall = new String('images/new_searching_small.swf');

//show the infant drop down on the search gui.  0 for Off and 1 for On
var showInfants = 1;

//show the time selection drop downs on the search gui.  0 for Off and 1 for On
var showTimeSelection = 1;

//determines if the dates are displayed as Month/Day/Year or Day/Month/Year
//if false then US Format Month/Day/Year if true the Day/Month/Year
var isEuro = false; 

//allow same day search.  When set to true this will bypass the same day validation check when the search button is clicked.
var asday = false;

//agencyId is the assigned aid value
var agencyId = 14;

/////////////////////////////////////////////////////////////////////////
//externalAccess indicates this is from a site external to the engine ///
/////////////////////////////////////////////////////////////////////////
////////   NOTE THIS SHOULD NOT BE MODIFIED UNLESS INSTRUCTED    ////////
/////////////////////////////////////////////////////////////////////////
var externalAccess = true;                                       ////////
/////////////////////////////////////////////////////////////////////////










var iIndex = 1;
var g_tripType;
var g_airportCityIndex = -1;
var g_airportCityControls = new Array('addCity1','addCity2');

var sentientGui = new GuiManager();

function GuiManager()
{  
  var _formRef;
  var _guiRef;
  
  ///////////////////////
  // public properties //
  ///////////////////////  
  this.formRef = function(){return _formRef};
  this.guiRef = function(){return _guiRef};    
  this.searchingAnimation = '<!--[if !IE]> -->' +
                            '<object type="application/x-shockwave-flash" data="' + searchSWF + '" width="275" height="100">' +
                            '<!-- <![endif]-->' +
                            '<!--[if IE]>' +
                            '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="275" height="100">' +
                            '<param name="movie" value="' + searchSWF + '" />' +
                            '<!-->' +
                            '<!---->' +
                            '<param name="loop" value="true" />' +
                            '<param name="menu" value="false" />' +
                            '<p>Searching For Low Airfares!!!</p>' +
                            '</object>' +
                            '<!-- <![endif]-->';
                            
  this.searchingAnimationSmall = '<!--[if !IE]> -->' +
                            '<object type="application/x-shockwave-flash" data="' + searchSWFSmall + '" width="156" height="85">' +
                            '<!-- <![endif]-->' +
                            '<!--[if IE]>' +
                            '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="156" height="85">' +
                            '<param name="movie" value="' + searchSWFSmall + '" />' +
                            '<!-->' +
                            '<!---->' +
                            '<param name="loop" value="true" />' +
                            '<param name="menu" value="false" />' +
                            '<p>Searching For Low Airfares!!!</p>' +
                            '</object>' +
                            '<!-- <![endif]-->';                            
                                                           
    
  ///////////////////////
  //  public methods   //
  ///////////////////////    
  this.doPost = function()
  {
    if (validate())
    {          
      sentientGui.showSearching();
      _formRef.submit();
    };   
  };
  
  this.doPostVert = function()
  {
    if (validate())
    {          
      sentientGui.showSearchingVert();
      _formRef.submit();
    };   
  };  
  
  this.showSearching = function()
  {                 
    var o = document.getElementById('searchingDiv');
    if(o && _guiRef){              
      o.style.display='block';             
      _guiRef.style.display = 'none';      
    };
  };
  
  this.showSearchingVert = function()
  {                 
    var o = document.getElementById('searchingDiv');
    if(o && _guiRef){              
      o.style.display='block';                       
    };
  };  
        
  this.initializeGui = function(_guiId,_formId)
  {
    _formRef = document.getElementById(_formId);      
    _guiRef = document.getElementById(_guiId);
    
    var o;            
    if (_formRef.namedItem){                    
      o = _formRef.namedItem('aid');    
    }
    else
    {
      o = _formRef.elements[0];
      if (o.id != 'aid')
      {
        o = _formRef.elements[1];
        if (o.id !='aid')
        {
          alert('Error finding aid value.  Please make sure it is the first or second value in the form!');  
        };
      };
    };
    
    if(o){        
      o.value = agencyId;          
    };
                
    o = document.getElementById('ext');
    if(o){
      o.value = externalAccess;    
    };

    if(showInfants==1){      
      o = document.getElementById('infText');
      if(o){ 
        o.style.display='inline';     
        o = document.getElementById('numOfInf');
        if(o){
          o.style.display='inline';          
        };        
      };      
    }; 
    
    if(showTimeSelection==1){
      o = document.getElementById('ddlDepartOnTime1');
      if(o){
        o.style.visibility='visible';        
      };
      
      o = document.getElementById('ddlReturnOnTime');
      if(o){
        o.style.visibility='visible';        
      };      
      
      o = document.getElementById('ddlDepartOnTime2');
      if(o){
        o.style.visibility='visible';      
      };

      o = document.getElementById('ddlDepartOnTime3');
      if(o){
        o.style.visibility='visible';        
      };
    
      o = document.getElementById('ddlDepartOnTime4');
      if(o){
        o.style.visibility='visible';      
      };   
    /*}
    else{
      _setWidth('tbSelector','339px');  
      _setWidth('botTable','339px');  
      _setWidth('tbSel1','310px');  
      _setWidth('tbSel2','310px');  
      _setWidth('tbSel3','310px');  
      _setWidth('tbSel4','310px');        
      _setWidth('txtDepart1','140px');                             
      _setWidth('txtDest1','140px');   
      _setWidth('txtDepart2','140px');   
      _setWidth('txtDest2','140px');   
      _setWidth('txtDepart3','140px');   
      _setWidth('txtDest3','140px');   
      _setWidth('txtDepart4','140px');   
      _setWidth('txtDest4','140px'); */  
    };   
    
    HideWait();   
    getDepDes();     
    SetDepartDest();            
    if (isEuro == true){
      if (scwDateDisplayFormat) scwDateDisplayFormat = 'D-M-YYYY';      
      if (scwDateOutputFormat) scwDateOutputFormat  = 'D/M/YYYY';      
      if (scwDateInputSequence) scwDateInputSequence = 'DMY'; 
    };
    SetDefaultDates(isEuro);        
    getDates(isEuro);
    changeTripDisplay('');    
    _guiRef.style.display = 'block';   
  };
  
  ///////////////////////
  //  private methods  //
  ///////////////////////  
  function _setWidth(_controlId,_width)
  {  
    var o = document.getElementById(_controlId)
    if(o){
      o.style.width = _width;     
    };    
  };   
};



function toggleExtraCities(action,addAnchorId,removeAnchorId,seperatorId)
{
  var iMaxAddLegs = g_airportCityControls.length - 1;
  var oAdd = document.getElementById(addAnchorId);
  var oRemove = document.getElementById(removeAnchorId);
  var oSep = document.getElementById(seperatorId);
  var o = null;
  
  if (action == 'a')
  {
    g_airportCityIndex++;      
    o = document.getElementById(g_airportCityControls[g_airportCityIndex]);
    if (o)
    {
      o.style.display='inline';      
    }; 
  }
  else
  {        
    o = document.getElementById(g_airportCityControls[g_airportCityIndex]);
    if (o)
    {
      o.style.display='none';      
    }; 
    g_airportCityIndex--;
  };
  
  if (g_airportCityIndex > -1 && g_airportCityIndex < iMaxAddLegs)
  {
    oAdd.style.display='inline';  
    oRemove.style.display='inline';  
    oSep.style.display='inline';  
  }
  else if (g_airportCityIndex == -1)
  {
    oAdd.style.display='inline';  
    oRemove.style.display='none';
    oSep.style.display='none';          
  }
  else
  {
    oAdd.style.display='none';  
    oRemove.style.display='inline';  
    oSep.style.display='none';  
  };  
  
  document.getElementById('numOfAddCities').value = g_airportCityIndex
};

function StartShowWait(show)
{    
  if (show)
  {
    document.getElementById('gui').style.display = 'none';  
    if (document.getElementById('mydiv')){
    document.getElementById('mydiv').style.display = 'block';        
    }; 
    return true;
  };
  
  return false;
};

function HideWait()
{    
  if (document.getElementById('mydiv')){
      document.getElementById('mydiv').style.display = 'none';      
  };  
};

function saveDates()
{
  var departOn1;
  var departOn2;
  var returnOn;
  var departOn3;
  var departOn4;
  
  departOn1 = document.frmGui.txtDepartOn1.value + '/' + document.getElementById('departOnYear1').innerHTML;    
  createCookie('departOn1',departOn1,0,20); 
    
  if (document.frmGui.txtDepartOn2)
  { 
    departOn2 = document.frmGui.txtDepartOn2.value + '/' + document.getElementById('departOnYear2').innerHTML;      
    createCookie('departOn2',departOn2,0,20); 
  };
  
  returnOn = document.frmGui.txtReturnOn.value + '/' + document.getElementById('returnOnYear').innerHTML;    
  createCookie('returnOn',returnOn,0,20); 
  
  if(document.frmGui.txtDepartOn3)
  {
    departOn3 = document.frmGui.txtDepartOn3.value + '/' + document.getElementById('departOnYear3').innerHTML;      
    createCookie('departOn3',departOn3,0,20);   
  };
  
  if(document.frmGui.txtDepartOn4)
  {
    departOn4 = document.frmGui.txtDepartOn4.value + '/' + document.getElementById('departOnYear4').innerHTML;      
    createCookie('departOn4',departOn4,0,20);   
  };  
        							
};

function getDates(europe)
{
  var cookieValue = readCookie('departOn1');           
  if (cookieValue != null){     
    FormatDate(document.frmGui.txtDepartOn1,document.getElementById('departOnYear1'),document.getElementById('departOnDay1'),cookieValue,0,europe,0);		  				          
    if (europe) cookieValue = swapDM(cookieValue);   
	  m_MasterDate = new Date(cookieValue);
  };
  
  cookieValue = readCookie('departOn2');        
  if (cookieValue != null && document.frmGui.txtDepartOn2){       
    FormatDate(document.frmGui.txtDepartOn2,document.getElementById('departOnYear2'),document.getElementById('departOnDay2'),cookieValue,0,europe,0);
  };
    
  cookieValue = readCookie('returnOn');      
  if (cookieValue != null){   
    FormatDate(document.frmGui.txtReturnOn,document.getElementById('returnOnYear'),document.getElementById('returnOnDay'),cookieValue,0,europe,0);       	  
  };  
  
  cookieValue = readCookie('departOn3');        
  if (cookieValue != null && document.frmGui.txtDepartOn3){       
    FormatDate(document.frmGui.txtDepartOn3,document.getElementById('departOnYear3'),document.getElementById('departOnDay3'),cookieValue,0,europe,0);
  };  
  
  cookieValue = readCookie('departOn4');        
  if (cookieValue != null && document.frmGui.txtDepartOn4){       
    FormatDate(document.frmGui.txtDepartOn4,document.getElementById('departOnYear4'),document.getElementById('departOnDay4'),cookieValue,0,europe,0);
  };  
};

function swapDM(val)
{
  var iDay = val.substring(0,val.indexOf('/'));    
  var iMonth = val.slice(val.indexOf('/') + 1,val.lastIndexOf('/'));
  var iYear = val.substring(val.lastIndexOf('/') + 1);

  return iMonth + '/' + iDay + '/' + iYear;
};

function saveDepDes()
{
  var dep1;
  var des1;
  var dep2;
  var des2;
  var dep3;
  var des3;
  var dep4;
  var des4;
  
  dep1 = document.frmGui.txtDepart1.value;  
  createCookie('depart1',dep1,0,20); 
  
  des1 = document.frmGui.txtDest1.value;  
  createCookie('dest1',des1,0,20); 
  
  dep2 = document.frmGui.txtDepart2.value;  
  createCookie('depart2',dep2,0,20); 
  
  des2 = document.frmGui.txtDest2.value;  
  createCookie('dest2',des2,0,20);   
  
  dep3 = document.frmGui.txtDepart3.value;  
  createCookie('depart3',dep3,0,20); 
  
  des3 = document.frmGui.txtDest3.value;  
  createCookie('dest3',des3,0,20); 
  
  dep4 = document.frmGui.txtDepart4.value;  
  createCookie('depart4',dep4,0,20); 
  
  des4 = document.frmGui.txtDest4.value;  
  createCookie('dest4',des4,0,20);           							
};

function getDepDes()
{
  var cookieValue = readCookie('depart1');
  if (cookieValue != null){       
	  document.frmGui.txtDepart1.value = cookieValue;	  
  };
  
  cookieValue = readCookie('dest1');    
  if (cookieValue != null){       
	  document.frmGui.txtDest1.value = cookieValue;
  };
  
  cookieValue = readCookie('depart2');    
  if (cookieValue != null){       
	  document.frmGui.txtDepart2.value = cookieValue;
  };   
  
  cookieValue = readCookie('dest2');    
  if (cookieValue != null){       
	  document.frmGui.txtDest2.value = cookieValue;
  };     
    
  cookieValue = readCookie('depart3');    
  if (cookieValue != null){           
	  document.frmGui.txtDepart3.value = cookieValue;
  };   
  
  cookieValue = readCookie('dest3');    
  if (cookieValue != null){       
	  document.frmGui.txtDest3.value = cookieValue;
  };   
  
  cookieValue = readCookie('depart4');    
  if (cookieValue != null){       
	  document.frmGui.txtDepart4.value = cookieValue;
  };   
  
  cookieValue = readCookie('dest4');    
  if (cookieValue != null){       
	  document.frmGui.txtDest4.value = cookieValue;
  };  
       
};
    
function validate()
{
  if (document.frmGui.btContinue) return true;

  var pass;
  var errCnt = 0;
  var curDate = new Date(Date.parse(new Date().toDateString()));	
  var dow = curDate.getDay();
  var day = curDate.getDate();
  var month = curDate.getMonth();  
  var year = curDate.getFullYear();
  var dep1;
  var do1,do2,ro,md;
       
  pass = true;
    
  if (document.frmGui)
  {             
    if (scwDateInputSequence == 'DMY'){                 
      do1 = bstSwapDM(document.frmGui.txtDepartOn1.value + '/' + document.getElementById('departOnYear1').innerHTML);
      if (document.frmGui.txtDepartOn2)
      {
        do2 = bstSwapDM(document.frmGui.txtDepartOn2.value + '/' + document.getElementById('departOnYear2').innerHTML);        
      };
      ro = bstSwapDM(document.frmGui.txtReturnOn.value + '/' + document.getElementById('returnOnYear').innerHTML);
      md = bstSwapDM(m_MasterDate.scwFormat(scwDateOutputFormat));
    }
    else
    {
      do1 = document.frmGui.txtDepartOn1.value + '/' + document.getElementById('departOnYear1').innerHTML;
      if (document.frmGui.txtDepartOn2)
      {
        do2 = document.frmGui.txtDepartOn2.value + '/' + document.getElementById('departOnYear2').innerHTML;        
      };
      ro = document.frmGui.txtReturnOn.value + '/' + document.getElementById('returnOnYear').innerHTML;        
      md = m_MasterDate.scwFormat(scwDateOutputFormat);  
    };       

    if (!Date.parse(do1) || ro.indexOf('00/00') != -1)
    {
      alert('You have entered an Invalid Date.  Please correct.');
      return false;
    }                      
                   
    var days = days_Between(new Date(Date.parse(do1)),curDate);    
    var numInf;      

    if (dow == 0){dow = 7};
    
    if (document.frmGui.selNumberOfInfants)
    {
      numInf = parseInt(document.frmGui.selNumberOfInfants.selectedIndex);
    }
    else{
      numInf = 0;
    };
       
    if (document.frmGui.selNumberOfAdults)
    {
      if ((parseInt(document.frmGui.selNumberOfAdults.selectedIndex) + 1) + parseInt(document.frmGui.selNumberOfChildren.selectedIndex) + numInf > 6)
      {            
        alert('The number of passengers combined cannot exceed 6.  Please contact us directly if you need to book more than 9 passengers or try multiple bookings.  Thank you!');
        document.frmGui.selNumberOfAdults.selectedIndex = 0;
        document.frmGui.selNumberOfChildren.selectedIndex = 0;
        
        if (document.frmGui.selNumberOfInfants)
        {
          document.frmGui.selNumberOfInfants.selectedIndex = 0;
        };
        pass = false;
      };       
    };
    
    if (((document.frmGui.txtDepart1.value == document.frmGui.txtDest1.value) && document.frmGui.txtDepart1.value != '') || ((document.frmGui.txtDepart2.value == document.frmGui.txtDest2.value) && document.frmGui.txtDepart2.value != '')){
      pass = false;
      alert('Your departue and destination cannot be the same.  Please correct to continue.');  
    };

    if (do1 == '' || do1 == '//')
    {
      alert('Please enter a Leave On Date.');
      pass = false;
    }
    else
    {      
      days = days_Between(new Date(Date.parse(do1)),new Date()); 
        
      dep1 = new Date((new Date(do1)).toDateString());         
         
      if(days > 330)
      {
        pass = false;
        alert('Due to certain restricitons we cannot sell fares more than 330 days out from todays date.  We apologize for any inconvenience!');
      }   
      else if (Date.parse(dep1) == Date.parse(curDate) && !asday)
      {
        alert('Due to time restrictions we cannot sell same day tickets.');
        pass = false;    
      }     
      else if (Date.parse(dep1) > Date.parse(curDate))
      {        
        if (document.frmGui.radTripType.length > 2)
        {
          if (document.frmGui.radTripType[2].checked)
          {
            if ((new Date(do2)) < dep1) 
            {
              alert('The Departure Date for the next part of your trip cannot be earlier then the previous Departure Date.');
              pass = false;                    
            };         
          };
        };
        
        if (document.frmGui.radTripType[0].checked)
        {
          if (ro != '' && ro != '//')
          {
             if ((new Date(ro)) < dep1)
            {
              alert('Your Return Date cannot be before your Departure Date.');
              pass = false;
            };
          }
          else
          {
            alert('Please enter a Return On Date.');
            pass = false;
          };
        };      

        if (!asday && ((dow == 5 && days <= 3) || (dow == 6 && days <= 2) || (dow == 7 && days <= 1)))
        {
          pass = false;

          var sellDate = new Date();
          sellDate.setFullYear(year,month ,day + ((7 - dow) + 2));
          alert('Due to weekend restricitons we cannot sell fares departing before ' + sellDate.toDateString() + '.  We apologize for any inconvenience!');
        }
        else if (days <= 1 && !asday)
        {
          pass = false;
          alert('Due to certain restricitons we cannot sell fares less then 2 days out from your departure date.  We apologize for any inconvenience!');    
        };      
      }
      else if (Date.parse(dep1) < Date.parse(curDate) )
      {
        if (ro != '' && ro != '//')
        {
          alert('Your Departure Date cannot be before Today\'s Date.');
          pass = false;
        }
        else
        {
          alert('Please enter a Return On Date.');
          pass = false;
        };
      };            
    };
       
    if (ro && (document.frmGui.radTripType[0].checked == true))
    {       
      if (ro != '' && ro != '//')
      {        
        var dtBuf = new Date(Date.parse(ro));
        days = days_Between(dtBuf,new Date(Date.parse(do1))); 
       
        if (days > 330)
        {
          pass = false;
          alert('Due to certain restricitons we cannot sell fares more than 330 days out from your departure date.  We apologize for any inconvenience!');
        };              
      }
      else
      {
        alert('Please enter a Return On Date.');
        pass = false;
      }; 
    }
    else if (document.frmGui.radTripType.length > 2)
    {      
      if (do2 && (document.frmGui.radTripType[2].checked == true))
      {           
        if (do2 != '' && do2 != '//')
        {
          var dtBuf = new Date(Date.parse(do2));
          days = days_Between(dtBuf,new Date(Date.parse(do1))); 

          if (days > 330)
          {
            pass = false;
            alert('Due to certain restricitons we cannot sell fares more than 330 days out from your departure date.  We apologize for any inconvenience!');
          };        
        }
        else
        {
          alert('Please enter a Departure date for the next leg.');
          pass = false;
        }; 
      };
    };
          
    errCnt = errCnt + checkField('txtDepart1','depart1',3);  
    errCnt = errCnt + checkField('txtDest1','dest1',3); 
    
    if (document.frmGui.radTripType.length > 2)
    {
      if (document.frmGui.radTripType[2].checked == true)
      {
        errCnt = errCnt + checkField('txtDepart2','depart2',3);  
        errCnt = errCnt + checkField('txtDest2','dest2',3);  
                   
        if(g_airportCityIndex >=0)
        {
          errCnt = errCnt + checkField('txtDepart3','depart3',3);
          errCnt = errCnt + checkField('txtDest3','dest3',3);
          
          if(g_airportCityIndex == 1)
          {
            errCnt = errCnt + checkField('txtDepart4','depart4',3);
            errCnt = errCnt + checkField('txtDest4','dest4',3);          
          };
        };
      };    
    };
  };
    
  if (errCnt > 0)
  {
    pass = false;
    if (errCnt == 1)
    {
      alert('There is 1 required field with invalid or missing data.  Please correct the item with RED text.'); 
     }
    else if (errCnt > 1)
    {
      alert('There are ' + errCnt + ' required fields with invalid or missing data.  Please correct the items with RED text.'); 
    };
  }
  else
  {
    if(g_tripType == 'openJaw'){
      document.frmGui.txtReturnOn.value = document.frmGui.txtDepartOn2.value;	
    }
    else if(g_tripType == 'roundTrip'){
      document.frmGui.txtDepartOn2.value = document.frmGui.txtReturnOn.value;	
    };
    
    saveDates(); 
    saveDepDes();
    createCookie('addCityIndex',g_airportCityIndex,0,20); 
    
  };
     
  return pass;
};

function changeTripDisplay(tripType)
{ 
  if (document.frmGui.radTripType)
  {    
    if (tripType != ''){
      g_tripType = tripType;    
      if (tripType == 'roundTrip'){     
        document.getElementById('multiCityAddRemove').style.display = 'none';    
        document.getElementById('returnOnDate').style.display = 'block';      
        document.getElementById('returnOnText').style.display = 'block';          
                
        //document.frmGui.txtReturnOn.value = document.frmGui.txtDepartOn2.value;	
        
        if(document.getElementById('returnOnDay'))
        {
          document.getElementById('returnOnDay').innerHTML = document.getElementById('departOnDay2').innerHTML;	
        };
        
        document.getElementById('multiCity').style.display = 'none';
        document.getElementById('addCity1').style.display = 'none';
        document.getElementById('addCity2').style.display = 'none';
        document.frmGui.radTripType[0].checked = true;
      }
      else if (tripType == 'oneWay'){
        document.getElementById('multiCityAddRemove').style.display = 'none';    
        document.getElementById('returnOnDate').style.display = 'none'; 
        document.getElementById('returnOnText').style.display = 'none';   
        document.getElementById('addCity1').style.display = 'none';
        document.getElementById('addCity2').style.display = 'none';            
               
        document.getElementById('multiCity').style.display = 'none';       
        document.frmGui.radTripType[1].checked = true;
      }
      else if (tripType == 'openJaw'){          
        document.getElementById('returnOnDate').style.display = 'none'; 
        document.getElementById('returnOnText').style.display = 'none';          
        
        /*
        document.frmGui.txtDepartOn2.value = document.frmGui.txtReturnOn.value;		  
        if(document.getElementById('returnOnDay'))
        {
          document.getElementById('departOnDay2').innerHTML = document.getElementById('returnOnDay').innerHTML;  
        };
        */
        
        document.getElementById('multiCity').style.display = 'block';
        document.getElementById('multiCityAddRemove').style.display = 'block';  
        
        cookieValue = readCookie('addCityIndex');      
        if(cookieValue != null){        
          g_airportCityIndex=parseInt(cookieValue);
          document.getElementById('numOfAddCities').value = g_airportCityIndex;          
        };
        var i=0;
        var o;
        g_airportCityIndex = parseInt(cookieValue);                        
        if((g_airportCityIndex > g_airportCityControls.length) || (g_airportCityIndex < -1)) g_airpotCityIndex = -1;
                
        var i=0;
        for (i=0;i<=g_airportCityIndex;i++)
        {
          document.getElementById(g_airportCityControls[i]).style.display = 'block';
        };
                
        if (g_airportCityIndex > -1 && g_airportCityIndex < (g_airportCityControls.length - 1))
        {
          document.getElementById('aAirportCity').style.display='inline';  
          document.getElementById('rAirportCity').style.display='inline';  
          document.getElementById('airCitySep').style.display='inline';  
        }
        else if (g_airportCityIndex == -1)
        {
          document.getElementById('aAirportCity').style.display='inline';  
          document.getElementById('rAirportCity').style.display='none';
          document.getElementById('airCitySep').style.display='none';          
        }
        else
        {
          document.getElementById('aAirportCity').style.display='none';  
          document.getElementById('rAirportCity').style.display='inline';  
          document.getElementById('airCitySep').style.display='none';  
        };  
                       
        document.frmGui.radTripType[2].checked = true;
      };
      
      createCookie('tripType',tripType,0,20);              
      createCookie('addCityIndex',g_airportCityIndex,0,20);        
    }
    else
    {       
      var cookieValue = readCookie('tripType');
      
      if (cookieValue == null){                            
        changeTripDisplay('roundTrip');      
      }
      else 
      {    
        changeTripDisplay(cookieValue);     
      };
      
      cookieValue = readCookie('addCityIndex');
      //alert('GetCookie: ' + cookieValue);      
      if(cookieValue != null & cookieValue != -1){
        var i=0;
        var o;
        g_airportCityIndex = parseInt(cookieValue);        
        for (i=0;i<parseInt(cookieValue);i++)
        {
          o=document.getElementById(g_airportCityControls[i]);
          if(o)o.style.display='inline';
        };            
      };      
    };
  };
};

var defDOW = new Array('SUN','MON','TUE','WED','THU','FRI','SAT');

function FormatDate(dayMonthInput,yearDiv,dowDiv,disDate,dateOffSet,europe)
{   
  var dtBuf = new Date();
      
  var iMonth = disDate.substring(0,disDate.indexOf('/'));    
  var iDay = disDate.slice(disDate.indexOf('/') + 1,disDate.lastIndexOf('/'));
  var iYear = disDate.substring(disDate.lastIndexOf('/') + 1);
      
  if (europe)
  {
    dtBuf = new Date(Date.parse(iDay + '/' + iMonth + '/' + iYear));
  }
  else
  {
    dtBuf = new Date(Date.parse(iMonth + '/' + iDay + '/' + iYear));
  };
  
  var iMaxYear = new Date().getFullYear() + 1;
    
  dtBuf.setDate(dtBuf.getDate() + parseInt(dateOffSet));  
  
  iYear = dtBuf.getFullYear();
  if (iYear > iMaxYear) iYear = iMaxYear;
  
  var buf = new String();  
  if (europe)
  {    
    buf = addLeadingZero(dtBuf.getDate()) + '/' + addLeadingZero((dtBuf.getMonth() + 1));        
  }
  else
  {
    buf = addLeadingZero((dtBuf.getMonth() + 1)) + '/' + addLeadingZero(dtBuf.getDate());
  };
  
  //alert(buf);
  dayMonthInput.value = buf;  
  yearDiv.innerHTML = iYear;    
  dowDiv.innerHTML = defDOW[dtBuf.getDay()];
  
  return buf;
};

function SetDefaultDates(europe,excludeYear)
{					
  var sDate;
  var dtBuf = new Date(Date.parse(new Date().toDateString()));					  
  m_MasterDate = new Date(Date.parse(new Date().toDateString()));
  
  if (europe)
  {
    sDate = dtBuf.getDate() + '/' + (dtBuf.getMonth() + 1) + '/' + dtBuf.getFullYear();
  }
  else
  {
    sDate = (dtBuf.getMonth() + 1) + '/' + dtBuf.getDate() + '/' + dtBuf.getFullYear();
  };  
  
  FormatDate(document.frmGui.txtDepartOn1,document.getElementById('departOnYear1'),document.getElementById('departOnDay1'),sDate,7,europe);		  				    
  FormatDate(document.frmGui.txtReturnOn,document.getElementById('returnOnYear'),document.getElementById('returnOnDay'),sDate,10,europe);		  				  
  
  if (document.frmGui.txtDepartOn2)
  {
    document.frmGui.txtDepartOn2.value = document.frmGui.txtReturnOn.value;		  
    document.getElementById('departOnYear2').innerHTML = document.getElementById('returnOnYear').innerHTML;
    document.getElementById('departOnDay2').innerHTML = document.getElementById('returnOnDay').innerHTML;
    
    if(document.frmGui.txtDepartOn3)
    {
      FormatDate(document.frmGui.txtDepartOn3,document.getElementById('departOnYear3'),document.getElementById('departOnDay3'),sDate,13,europe);		  				  
      if(document.frmGui.txtDepartOn4)
      {
        FormatDate(document.frmGui.txtDepartOn4,document.getElementById('departOnYear4'),document.getElementById('departOnDay4'),sDate,16,europe);		  				        
      };
    };
  };
  
  /*
  scwDisabledDates[0] = [new Date(dtBuf.getFullYear(),0,1),new Date(dtBuf.getFullYear(),dtBuf.getMonth(),dtBuf.getDate())];
  
  dtBuf.setDate(dtBuf.getDate() + parseInt(329)); 
    
  scwDisabledDates[1] = [new Date(dtBuf.getFullYear(),dtBuf.getMonth(),dtBuf.getDate()),new Date(dtBuf.getFullYear(),11,31)];
  */
};

function days_Between(date1,date2)
{
  var one_day=1000*60*60*24;
  var days = (Math.abs(date1.getTime()-date2.getTime()));

  return Math.round(days/one_day);
};

function subtract_Days(date1,days)
{
  var one_day=1000*60*60*24;
  var curDateMS = date1.getTime();
  var diffMS = (one_day * days);  
  var returnDate = new Date();
  
  returnDate.setTime(curDateMS - diffMS);
  
  return returnDate;
};

function SetDepartDest()
{
  if (Request.QueryString("departure").Count > 0){
    document.frmGui.txtDepart1.value = Request.QueryString("departure");           
  };
  
  if (Request.QueryString("destination").Count > 0){
    document.frmGui.txtDest1.value = Request.QueryString("destination");           
  };
};

