//Global Variables
//Define the different browser types that are supported
var NS4 = (navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)==4);
var NS6 = (navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)==5);
var IE4 = document.all;
//Calendar objects
var calNS4;
var calNS6;
var calIE4;
//Holding Variables
var CALENDAR_HTML = "";
var DISPLAY_DATE = "";
var HLD_DIV = "";
var CURRENT_DATE_FIELD = "";
var CURRENT_DATE_FIELD2 = "";
var BUILT = "no";
//End of Global Variables
//Write out the style sheets
document.write("<style>");
document.write(".txtDay { font-size: 9px; color:#000000; font-family:  Arial, Helvetica, sans-serif; text-decoration: none;}");
document.write(".txtMonth { font-size: 11px; color:#000000; font-family:  Arial, Helvetica, sans-serif; text-decoration: none;}");
document.write(".tblCalendar { border: 1px solid #999999; }");
document.write(".tdMonth { padding: 2px; }");
document.write(".tdDayW { padding: 2px; border: 1px solid #999999; }");
document.write(".tdDay { padding: 2px; border: 1px solid #999999; }");
document.write(".btnPrev { font-size: 14px; color: #000000; font-family: webdings; font-weight:bold; text-decoration: none;}");
document.write(".btnNext { font-size: 14px; color: #000000; font-family: webdings; font-weight:bold; text-decoration: none;}");
document.write("</style>");
//This function is used to display the calendar
function numofmonth(mon){
            if (mon == "Jan")
                return 01;
            else if (mon == "Feb")
                return 02;
            else if (mon =="Mar")
                return 03;
            else if (mon == "Apr")
                return 04;
            else if (mon =="May")
                return 05;
            else if (mon == "Jun")
                return 06;
            else if (mon =="Jul")
                return 07;
            else if (mon == "Aug")
                return 08;
            else if (mon =="Sep")
                return 09;
            else if (mon =="Oct")
                return 10;
            else if (mon == "Nov")
                return 11;
            else if (mon =="Dec")
                return 12;
}            
function getDates(field1,field2){
        var nowdate = new Date(); 
        nowyear = nowdate.getFullYear();
        
        if (document.forms[1].name == "LoginPage") {
            //non-member login, so access 3rd form
            theMonth = numofmonth(document.forms[2][field1].value);
            theDay = document.forms[2][field2].value;
        } else {
            //member login, so access 2nd form
            theMonth = numofmonth(document.forms[1][field1].value);
            theDay = document.forms[1][field2].value;
        }
        
        var theDate = new Date(nowyear, theMonth, theDay);        
        theFullDate = theMonth + '/' + theDay + '/' + theDate.getFullYear();
        
        //theFullDate = theMonth + '/' + theDay + '/' + nowyear;
        return theFullDate;
}
function setDates(selMonth,selDay){
                
                document.AirSearch.depMonth.value = themonths[selMonth];
                document.AirSearch.depDay.value = selDay;
}
function showCalendar(field1,field2,date,xPos,yPos)
{
    if (HLD_DIV != date && BUILT == "yes")
    {
        if (NS4)
            calNS4.visibility = 'hidden';
        else if (IE4)
            calIE4.style.visibility = 'hidden';
        else if (NS6)
            calNS6.style.visibility = 'hidden';
        
        BUILT = "no";
        HLD_DIV = date;
    }
        
    if (BUILT == "yes")
    {
        if (NS4)
            calNS4.visibility = 'visible';
        else if (IE4)
            calIE4.style.visibility = 'visible';
        else if (NS6)
            calNS6.style.visibility = 'visible';
        return;
    }
    
    CURRENT_DATE_FIELD = field1;
    CURRENT_DATE_FIELD2 = field2;
    //Set the Display Date to null
    DISPLAY_DATE = getDates(CURRENT_DATE_FIELD,CURRENT_DATE_FIELD2);
    //Build the Calendar
    buildCalendar(DISPLAY_DATE);
    
    if (!xPos)
        xPos = "";
    if (!yPos)
        yPos = "";
    
    //Display the Calendar on the Web page
    if (NS4)
    {
        calNS4 = new Layer(50,this);
        calNS4.document.write(CALENDAR_HTML);
        calNS4.document.close();
        if (xPos != "" || yPos != "")
        {
            this.calNS4.pageX = xPos;
            this.calNS4.pageY = (yPos - 95);
        }
        else
        {
            this.calNS4.pageX = document.layers[date].pageX;
            this.calNS4.pageY = (document.layers[date].pageY - 95);
        }
        calNS4.visibility = 'visible';
    }
    else if (IE4)
    {
        calIE4 = document.all[date];
        
        calIE4.innerHTML = CALENDAR_HTML;
        
        if (xPos != "" || yPos != "")
        {
            calIE4.style.posLeft = xPos;
            calIE4.style.posTop = yPos;
        }
        calIE4.style.visibility = 'visible';
    }
    else if (NS6)
    {
        calNS6 = document.getElementById(date);
        
        calNS6.innerHTML = CALENDAR_HTML;
        if (xPos != "" || yPos != "")
        {
            calNS6.style.top = yPos;
            calNS6.style.left = xPos;
        }
        calNS6.style.visibility = 'visible';
    }
    
    BUILT = "yes";
}
//This function is used to hide the calendar
function hideCalendar()
{
    if (BUILT == "no")
        return;
    if (NS4){
        calNS4.visibility = 'hidden';
    }
    else if (IE4){
        calIE4.style.visibility = 'hidden';
    }
    else if (NS6){
        calNS6.style.visibility = 'hidden';
    }
}
//This function is used to change the Calendar Date
function chgCalendarDate(dspDate)
{
    buildCalendar(dspDate);
    //Display the Calendar on the Web page
    if (NS4)
    {
        calNS4.document.write(CALENDAR_HTML);
        calNS4.document.close();
    }
    else if (IE4)
        calIE4.innerHTML = CALENDAR_HTML;
    else if (NS6)
        calNS6.innerHTML = CALENDAR_HTML;
}
//This function is used to change the Date field to the selected calendar date
function chgDate(selMonth,selDay)
{
    //setDates(selMonth,selDay);    
    //Hide the Calendar
    
    if (document.forms[1].name == "LoginPage") {
        //non-member login, so access 3rd form
        document.forms[2][CURRENT_DATE_FIELD].value = themonths[selMonth];
        document.forms[2][CURRENT_DATE_FIELD2].value = selDay;
    } else {
        //member login, so access 2nd form
        document.forms[1][CURRENT_DATE_FIELD].value = themonths[selMonth];
        document.forms[1][CURRENT_DATE_FIELD2].value = selDay;    
    }
    
    var nowdate = new Date(); 
    nowyear = nowdate.getFullYear();
    nowMonth = selMonth + 1;
    var theDate = new Date(nowyear, nowMonth, selDay);    
    
    theFullDate = nowMonth + '/' + selDay + '/' + theDate.getFullYear();
    //theFullDate = nowMonth + '/' + selDay + '/' + nowyear;
    buildCalendar(theFullDate);
        if (NS4)
    {
        calNS4.document.write(CALENDAR_HTML);
        calNS4.document.close();
    }
    else if (IE4)
        calIE4.innerHTML = CALENDAR_HTML;
    else if (NS6)
        calNS6.innerHTML = CALENDAR_HTML;
    hideCalendar();
}
//This function is used to Build the Calendar
function buildCalendar(DISPLAY_DATE)
{
    //Define the Month Names and Month Days Array
    monthNames         = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    monthDays         = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        calendarDateObj    = new Date(DISPLAY_DATE);
    calendarDate    = calendarDateObj.getDate();
    calendarDay        = calendarDateObj.getDay();
    calendarMonth    = calendarDateObj.getMonth();
    calendarYear    = calendarDateObj.getYear();
        
    if (LeapYear(calendarYear))
        monthDays[1] = 29;
    
    //Make sure the Year is in the correct century
    calendarYear     = calendarYear % 100;
    calendarYear     = ((calendarYear < 50) ? (2000 + calendarYear) : (1900 + calendarYear));
    //Calculate the Blank entries before the 1st of the month
    blankEntry = calendarDate;
    while (blankEntry > 7) 
        blankEntry-= 7;
    blankEntry = calendarDay - blankEntry + 1;
    
    if (blankEntry < 0) 
        blankEntry+= 7;
    
    //Calculate Next Months Date
    nextMonth = (calendarMonth + 2);        
        
    //for december
    if (nextMonth == 13)
    {
        nextMonth = 1;        
        nextYear = (calendarYear + 1);    
    }
    else {
        if (ArrivalYear != nowyear)
        {
            //flights or hotel
            if (ArrivalYear != 0)
            {
                calendarYear = ArrivalYear;
            } 
            else //cars
            {
                calendarYear = nowyear + 1;
            }
        }
        nextYear = calendarYear;
    }
    
    nextDate = nextMonth + "/1/" + nextYear;
    
    //Calculate Previous Months Date
    prevMonth = calendarMonth;
    
    if (prevMonth == 0)
    {
        prevMonth = 12;
        prevYear = (calendarYear - 1);
    } 
    else
        prevYear = calendarYear;
    //*** Fix - TDS 2-06-2003 ***
    //prevDate = prevMonth + "/" + currentDate + "/" + prevYear;
    prevDate = prevMonth + "/1/" + prevYear;
    //*** End Fix - 2-06-2003 ***
    //Build the Header for the Calendar
    CALENDAR_HTML = "<table class=\"tblCalendar\" cellpadding=0 cellspacing=0>";
    CALENDAR_HTML += "<tr>";
    CALENDAR_HTML += "<td bgcolor=#FFF7C9 align=center class=\"tdMonth\" onMouseOver=mOvr(this,'#FFF7C9') onMouseOut=mOut(this,'#FFF7C9') onClick=chgCalendarDate('" + prevDate + "')><a href=javascript:chgCalendarDate('" + prevDate + "')><font class=\"btnPrev\">3</font></a></td>";
    CALENDAR_HTML += "<td bgcolor=#FFF7C9 align=center class=\"tdMonth\" colspan=5><font class=\"txtMonth\">" + monthNames[calendarMonth] + " " + calendarYear + "</font></td>";
    CALENDAR_HTML += "<td bgcolor=#FFF7C9 align=center class=\"tdMonth\" onMouseOver=mOvr(this,'#FFF7C9') onMouseOut=mOut(this,'#FFF7C9') onClick=chgCalendarDate('" + nextDate + "')><a href=javascript:chgCalendarDate('" + nextDate + "')><font class=\"btnNext\">4</font></a></td>";
    CALENDAR_HTML += "</tr>";
    CALENDAR_HTML += "<tr>";
    CALENDAR_HTML += "<td bgcolor=#FFF7C9 align=center class=\"tdDayW\"><font class=\"txtDay\">SUN</font></td>";
    CALENDAR_HTML += "<td bgcolor=#FFF7C9 align=center class=\"tdDayW\"><font class=\"txtDay\">MON</font></td>";
    CALENDAR_HTML += "<td bgcolor=#FFF7C9 align=center class=\"tdDayW\"><font class=\"txtDay\">TUE</font></td>";
    CALENDAR_HTML += "<td bgcolor=#FFF7C9 align=center class=\"tdDayW\"><font class=\"txtDay\">WED</font></td>";
    CALENDAR_HTML += "<td bgcolor=#FFF7C9 align=center class=\"tdDayW\"><font class=\"txtDay\">THR</font></td>";
    CALENDAR_HTML += "<td bgcolor=#FFF7C9 align=center class=\"tdDayW\"><font class=\"txtDay\">FRI</font></td>";
    CALENDAR_HTML += "<td bgcolor=#FFF7C9 align=center class=\"tdDayW\"><font class=\"txtDay\">SAT</font></td>";
    CALENDAR_HTML += "</tr>";
    CALENDAR_HTML += "<tr>";
    //Build a blank cell for each Blank Entry before the 1st of the Month
    for (s = 0;s < blankEntry;s++) 
        CALENDAR_HTML += "<td bgcolor=#FFFFFF align=center class=\"tdDay\"><font class=\"txtDay\">&nbsp;</font></td>";
    //Start the Day Counter
    dayCount = 1;
    noDaysMonth= monthDays[calendarMonth];
    //Loop through until the total days of calendar month have been reached
    while (dayCount<=noDaysMonth) 
    {
        //Start a new table row each time through the loop except the first time
        if (dayCount > 1)
            CALENDAR_HTML += "<tr>";
        
        //Start at the next cell after the blank entries and entry the cells across the row.
        for (b = blankEntry;b < 7;b++) 
        {
            //If the Day Counter is greater than the Month total then add blank entries
            if (dayCount <= monthDays[calendarMonth])
            {
                tdProperties = "onClick=chgDate(" + calendarMonth + "," + dayCount + ") ";
                tdData = "<a href=javascript:chgDate(" + calendarMonth + "," + dayCount + ")><font class=\"txtDay\">" + dayCount + "</font></a>";
                //If the day counter is equal to the current date then change the color
                if (dayCount == calendarDate)
                    tdProperties = tdProperties + "bgcolor=#FFF7C9";
                else 
                    tdProperties = tdProperties + "onMouseOver=mOvr(this,'" + "#FFF7C9" + "') onMouseOut=mOut(this,'" + "#FFFFFF" + "') bgcolor=" + "#FFFFFF" + "";
            
            } 
            else
            {
                tdProperties = "bgcolor=" + "#FFFFFF";
                tdData = "<font class=\"txtDay\">&nbsp;</font>";
            }
        
            //Build the table cells
            CALENDAR_HTML += "<td align=center class=\"tdDay\" " + tdProperties + ">" + tdData + "</td>";
        
            //Add to the Day counter
            dayCount++;
        }
    
        //End the table row
        CALENDAR_HTML += "</tr>";
        
        //Set the Blank entries to zero
        blankEntry=0;
    }
    //End the table
    CALENDAR_HTML += "<tr>";
    CALENDAR_HTML += "<td bgcolor=" + "#FFF7C9" + " colspan=7 class=\"tdMonth\"><a class=\"txtDay\" href=javascript:hideCalendar();>hide</a>&nbsp;</td>";
    CALENDAR_HTML += "</tr>";
    CALENDAR_HTML += "</table>";
}
//*** Fix - TDS 2-06-2003 ***
//This fuction checks for the Leap Year
function LeapYear(year) 
{
    if ((year/4)   != Math.floor(year/4))   return false;
    if ((year/100) != Math.floor(year/100)) return true;
    if ((year/400) != Math.floor(year/400)) return false;
    return true;
}
//*** End Fix - 2-06-2003 ***
//This function is used to control the mouse over event.
function mOvr(src,clrOver)
{ 
    if (!src.contains(event.fromElement))
    { 
        src.style.cursor = 'hand'; 
        src.bgColor = clrOver;
    } 
}
//This function is used to control the mouse out event.
function mOut(src,clrIn)
{ 
    if (!src.contains(event.toElement))
    { 
        src.style.cursor = 'default'; 
        src.bgColor = clrIn; 
    } 
}