	/**
     * Sets the correct number of days in the pulldown menu when a month is selected
     */	
    function selectMonth(dayField,monthField){        
    	
        var selectedMonth = monthField.options[monthField.selectedIndex].value;
        var selectedDay = dayField.options[dayField.selectedIndex].value;
        var selectedYear;
        var today = new Date();
        var thisYear=today.getYear();
        if(thisYear<2000)thisYear+=1900;
        var febDate=new Date(thisYear,(selectedMonth-1),selectedDay);
        
        if (febDate<today){            
            selectedYear = thisYear+1;
        }
        else{            
            selectedYear = thisYear;
        }
        var days = getNumDays(selectedMonth,selectedYear);
        
        dayField.length=days;        
        
        for(var i=1;i<=days;i++){
            dayField.options[i-1] = null;
            dayField.options[i-1] = new Option(i,i);            
        }
        
        if (selectedDay <= dayField.options.length){
        	dayField.selectedIndex=selectedDay-1;
        }
        
    }           
    
    function getNumDays(M,Y){
        if(M==2){
                var febDate=new Date(Date.UTC(Y,1,29)); 
                return (febDate.getMonth()==1)?29:28; 
        } 
        else return (M==9||M==4||M==6||M==11)?30:31;
    }
 

	

	/**
	 * Updates form objects: lmnCheckOutDay, lmnCheckOutDayDisplay, lmnCheckOutMonthDisplay and formReference.
	 */	 
	function updateCheckOut(value) {		
				
		var months_array = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		// save number of nights
		no_nights = parseInt(value);
		
		// check that iis a valid number
		if(isNaN(no_nights)||no_nights<=0) {
            //alert("Please enter a valid number of nights"); 
            }
		else {
			// construct the check in date
			// for this we need to decide if the month selected is before current month, if so
			// user is booking for next year
			
			d = new Date();
			y = d.getFullYear();
			m1 = d.getMonth();			
			m2 = formReference.lmnCheckInMonth.value-1; // month is not 0 based in calendar!!
			months_array_index = formReference.lmnCheckInMonth.value -1;
			if(m2<m1) { y = y+1; }
			
			// now create the proper check in date
			real_checkin_s = formReference.lmnCheckInDay.value+" "+months_array[months_array_index]+" "+y;
			real_checkin_d = new Date(real_checkin_s);
	
			
			dayOfCheckInMonth = real_checkin_d.getDate();
			dayOfCheckOutMonth = dayOfCheckInMonth + no_nights;
			
			real_checkout_d = real_checkin_d;
			real_checkout_d.setDate(dayOfCheckOutMonth);
			
			// get day and month for check out
			check_out_day = real_checkout_d.getDate();
			check_out_month = months_array[real_checkout_d.getMonth()];
			// show user
			formReference.lmnCheckOutDay.value=check_out_day;
			formReference.lmnCheckOutDayDisplay.value=check_out_day;
			//localised_months obtained from lsLocalisedVariables.jsp
			formReference.lmnCheckOutMonthDisplay.value=localised_months[real_checkout_d.getMonth()];
            formReference.lmnCheckOutMonth.value=(real_checkout_d.getMonth()+1);
            
		}
	}
	


