function determineyear(month,day){
        thisDate=new Date();
        thisYear=thisDate.getFullYear();
        thisMonth=thisDate.getMonth();
        thisDay=thisDate.getDate();
        if(month<thisMonth){year=thisYear+1;}
                else {if(month==thisMonth){
                                if(day>=thisDay){year=thisYear;}
                                        else{year=thisYear+1;}
                                }else{year=thisYear;}}
        return year;
        }

//leap year calculation////////////////////////////////////////////////////////////////
function isLeapYear(year){
        if((year%4==0 && year%100!=0)||year%400==0)return true; else return false;
        }
       
//max day of the month/////////////////////////////////////////////////////////////////
function maxDay(month,year){   
        if(isLeapYear(year)){          
                maxDayMonth=new Array(31,29,31,30,31,30,31,31,30,31,30,31);
        }else{
                maxDayMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
        }      
        return maxDayMonth[month];
        }

//calculate dates/nights based on user change/////////////////////////////////////////
function checkDates(el){
        var nights;
        var inDate,inDay,inMonth,inYear;
        var outDate,outDay,outMonth,outYear;
        form=el.form; //document.th_start;//reference
        ms=86400000; //ms in 24 hours
       
        // build the associative array for the month drop downs
        var month_array = new Array();
        for(i=0;i < form.hotelReservation_inMonth.options.length;i++){
                month_array[form.hotelReservation_inMonth.options[i].value] = i;                       
        }
       
        // build the associative array to take zero based months and create the actual month
        var realmonthindex_array = new Array(01,02,03,04,05,06,07,08,09,10,11,12);     
        inDay=form.hotelReservation_inDay.selectedIndex+1;
        inMonthYear = form.hotelReservation_inMonth.options[form.hotelReservation_inMonth.selectedIndex].value;
        splitInStr = inMonthYear.split("_");
        inMonth = splitInStr[0]-1;
        inYear = splitInStr[1];
       
        outDay=form.hotelReservation_outDay.selectedIndex+1;
        outMonthYear = form.hotelReservation_outMonth.options[form.hotelReservation_outMonth.selectedIndex].value;
        splitOutStr = outMonthYear.split("_");
        outMonth = splitOutStr[0]-1;
        outYear = splitOutStr[1];      
               
        //check maximum day, set inDay, outDay
        if(inDay>maxDay(inMonth,inYear)){ inDay=maxDay(inMonth,inYear);}
        if(outDay>maxDay(outMonth,outYear)){ outDay=maxDay(outMonth,outYear);}         
       
        //create date objects
        inDate=new Date(inYear,inMonth,inDay);
        outDate=new Date(outYear,outMonth,outDay);
       
        //modify boxes depending on what box changed           
        if(el.name=='nights'){
                nights=form.nights.selectedIndex+1;
                outDate.setTime(inDate.getTime()+nights*ms);
        }else if(el.name=='hotelReservation_inDay' || el.name=='hotelReservation_inMonth'){            
                nights=form.nights.selectedIndex+1;
                outDate.setTime(inDate.getTime()+nights*ms);                   
        }else if(el.name=='hotelReservation_outDay' || el.name=='hotelReservation_outMonth'){
                nights=(outDate-inDate)/ms;
        }              
       
        // build the new month values  
        inMonthNew = realmonthindex_array[inDate.getMonth()] + "_" + inDate.getFullYear();
        if( inMonthNew.length == 6 ) inMonthNew = "0" + inMonthNew;
        outMonthNew = realmonthindex_array[outDate.getMonth()] + "_" + outDate.getFullYear();
        if( outMonthNew.length == 6 ) outMonthNew = "0" + outMonthNew; 
               
        form.hotelReservation_inMonth.selectedIndex=month_array[inMonthNew];   
        form.hotelReservation_inDay.selectedIndex=inDate.getDate()-1;
        form.hotelReservation_outMonth.selectedIndex=month_array[outMonthNew]; 
        form.hotelReservation_outDay.selectedIndex=outDate.getDate()-1;
        form.nights.selectedIndex=nights-1;
        }
