function y2k(number){return (number < 1000) ? number + 1900 : number;}

function isLeapYear(yr)
{
  if (((yr % 4 == 0) && (yr % 100 != 0)) || (yr % 400 == 0)) { return true; }
  else { return false; } 
}


//start new script code
    function initDate()
 {
   var now = new Date();
   var mth = now.getMonth();
   var dd = now.getDate();
   var yy = now.getFullYear();
   if (mth <10)
    {
      mth == 0 + mth;
     }
   if (dd <10)
    {
      dd == 0 + dd;
    }
     if ((mth==11) && (dd>=29)) {
       document.resrvForm.doa_mm.selectedIndex = mth;
       document.resrvForm.doa_dd.selectedIndex = dd - 1;
       document.resrvForm.dod_yy.value= yy;
       document.resrvForm.dod_dd.selectedIndex = dd - dd;
       document.resrvForm.dod_mm.selectedIndex = mth-mth;
       document.resrvForm.dod_yy.value= yy+1;
       
       document.mainForm.inday.selectedIndex = dd - 1;
       document.mainForm.outday.selectedIndex = dd - dd;
       document.mainForm.inmonth.selectedIndex = mth;
       document.mainForm.inyear.value= yy;
       document.mainForm.outmonth.selectedIndex = mth-mth;
       document.mainForm.outyear.value= yy+1;

     }
     else if ((dd>=29 ) || ((dd>=27 ) && (mth==1)))
     {
        document.resrvForm.doa_mm.selectedIndex = mth+1;
        document.resrvForm.doa_dd.selectedIndex = dd-dd;
        document.resrvForm.doa_yy.value= yy;
        document.resrvForm.dod_dd.selectedIndex = (dd-dd)+1;
        document.resrvForm.dod_mm.selectedIndex = mth + 1;
        document.resrvForm.dod_yy.value= yy;


        document.mainForm.inday.selectedIndex = dd-dd;
        document.mainForm.outday.selectedIndex = (dd-dd)+1;
        document.mainForm.outmonth.selectedIndex = mth + 1;
        document.mainForm.inyear.value= yy;
        document.mainForm.inmonth.selectedIndex = mth+1;
        document.mainForm.outyear.value= yy;
    }
   else
    {
   	document.resrvForm.doa_mm.selectedIndex=mth;
   	document.resrvForm.doa_dd.selectedIndex=dd+1;
   	document.resrvForm.dod_mm.selectedIndex=mth;
   	document.resrvForm.dod_dd.selectedIndex=dd+3;
    document.resrvForm.dod_yy.value= yy;
	
    document.mainForm.inday.selectedIndex=dd+1;
    document.mainForm.outday.selectedIndex=dd+3; 
  	document.mainForm.inmonth.selectedIndex=mth;
   	document.mainForm.outmonth.selectedIndex=mth;
    document.mainForm.inyear.value= yy;
    document.mainForm.outyear.value= yy;
   	
	 /*
	
	 */
	}

}


function changeDates(formArg)
{
	
  var today = new Date();
  var yy  = today.getFullYear();
  
  var inMonth=parseInt(document.mainForm.inmonth.options[document.mainForm.inmonth.selectedIndex].value,10)-1;
  var inYear=today.getFullYear();
  var baseMonth=today.getMonth();
  var baseDay=today.getDate();
  var inDay=parseInt(document.mainForm.inday.options[document.mainForm.inday.selectedIndex].value,10);
  
  document.mainForm.inday.options[inDay-1].selected=true;
  
  var currOutMonth = parseInt(document.mainForm.outmonth.options[document.mainForm.outmonth.selectedIndex].value,10)-1;
  var currOutDay = parseInt(document.mainForm.outday.options[document.mainForm.outday.selectedIndex].value,10);
  var currOutYear = yy;
  
    outMonth=inMonth;
    outDay = inDay;
    outYear=inYear;
    
    document.mainForm.outmonth.options[outMonth].selected=true;
    document.mainForm.outday.options[outDay].selected=true;
    document.mainForm.inyear.value= yy;
    document.mainForm.outyear.value= yy;
}
   
   
   
   // Checks if browser is Netscape 2.0x since the options array properties don't work with Netscape 2.0x
   
   
   
    function isBrowserSupp() {
        // Get the version of the browser
        version =  parseFloat( navigator.appVersion );

        if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
            return false;
        } else {
            return true;
        }

        return true;
    }

    function isLeapYear( yrStr ) {
        var leapYear = false;
        var year = parseInt( yrStr, 10 );
        // every fourth year is a leap year
        if ( year % 4 == 0 ) {
            leapYear = true;
            // unless it's a multiple of 100
            if( year % 100 == 0 ) {
                leapYear = false;
                // unless it's a multiple of 400
                if( year % 400 == 0 ) {
                    leapYear=true;
                }
            }
        }
        return leapYear;
    }

    function getDaysInMonth( mthIdx, YrStr ) {
        // all the rest have 31
        var maxDays = 31
        // expect Feb. (of course)
        if( mthIdx == 1 ) {
            if( isLeapYear( YrStr ) ) {
                maxDays=29;
            } else {
                maxDays=28;
            }
        }

        // thirty days hath...
        if( mthIdx == 3 || mthIdx == 5 || mthIdx == 8 || mthIdx == 10 ) {
            maxDays=30;
        }
        return maxDays;
    }

    //the function which does some magic to the date fields
    // return non-zero if it is the last day of the month
    function adjustDate( mthIdx, Dt ) {
        var value = 0;

        var today = new Date()
        var theYear = parseInt( today.getYear(), 10 )

        if( mthIdx < today.getMonth() ) {
            theYear = ( parseInt( today.getYear(), 10 ) + 1 )
        }
        if( theYear < 100 ) {
            theYear = "19" + theYear
        } else {
            if( ( theYear - 100 ) < 10 ) {
                theYear = "0" + ( theYear - 100 )
            } else {
                theYear = ( theYear - 100 ) + ""
            }
            theYear = "20" + theYear
        }


        var numDays = getDaysInMonth( mthIdx, theYear );

        if( mthIdx == 1 ) {
            if( Dt.options.selectedIndex + 1 < numDays ) {
                return 0;
            } else {
                Dt.options.selectedIndex=numDays - 1;
                //check for leap year
                if( numDays == 29 ) {
                    return 99;
                } else {
                    return 1;
                }
            }
        }

        if( Dt.options.selectedIndex + 1 < numDays ) {
            value = 0;
        } else {
            if ( Dt.options.selectedIndex + 1 > numDays ) {
                Dt.options.selectedIndex--;
                value = 3;
            } else {
                //index is 31 or 30
                value = 2;
            }
        }
        return value;
    }

    //changes departure month when arrival month is changed
    function amadChange( inM, inD, outM, outD ) {
        if ( !isBrowserSupp() ) {
            return;
        }

        var res = adjustDate( inM.options.selectedIndex, inD );
        if( res != 0 ) {
               outD.options.selectedIndex = 0;
               if ( outM.options.selectedIndex == 11 ) {
                    outM.options.selectedIndex = 0
               } else {
                    outM.options.selectedIndex=inM.options.selectedIndex + 1;
                    outD.options.selectedIndex = 1;
               }
        } else {
            outM.options.selectedIndex = inM.options.selectedIndex;
            if (outD.options.selectedIndex <= inD.options.selectedIndex) {
                outD.options.selectedIndex = inD.options.selectedIndex + 2;
            }
        }
        return;
    }


    function dmddChange( outM, outD ) {
        if ( !isBrowserSupp() ) {
            return;
        }

        adjustDate( outM.options.selectedIndex, outD );
        return;
    }

function loadDates(arrivalMonthSelect,  arrivalDaySelect, departureMonthSelect, departureDaySelect)
{
	var calendar = new Date();
	var calendar2 = new Date();
	var cal
	var cal2
	var date;
	var month;
	var year;
	var date2;
	var month2;
	var year2;

	//Here is the variable to change for to advance the arrival Date
	 var advanceArrival = 14;
	//Here is the variable to change for to advance the departure Date
	 var advanceDeparture = 16;


	//Set the arrival Days
	calendar.setDate(calendar.getDate()+ advanceArrival);
	date = calendar.getDate();
	month = calendar.getMonth();

	//Set the Departure Days
	calendar2.setDate(calendar2.getDate()+advanceDeparture);
	date2 = calendar2.getDate();
	month2 = calendar2.getMonth();

	arrivalMonthSelect.value=month;
	arrivalDaySelect.value=date;
	departureMonthSelect.value=month2;
	departureDaySelect.value=date2;
}

    function OpenWindow(file, name, width, height) {
        OpenWindow(file, name, width, height, false);
    }

    function OpenWindow(file, name, width, height, showLeftTopScrollbar) {
        var attr = "";
        if(showLeftTopScrollbar) {
            attr += "top=50,left=50,scrollbars=1,";
        }
        attr += "width=" + width + ",height=" + height + ",resizeable=1";
        window.open(file, name, attr);
    }

   