function initDate() {
	var dob = new DATE_date_object();
	dob.arr_month.options[dob.start_month-1].selected = true;
	dob.arr_day.options[dob.start_day-1].selected = true;
	DATE_set_days(dob.arr_year, dob.arr_month, dob.arr_day); 
	var myDate = new Date();
	myDate.setDate(myDate.getDate()+1);
	end_month = myDate.getMonth() + 1;
	end_day = myDate.getDate();
	end_year = myDate.getFullYear();
	dob.dep_month.options[end_month-1].selected = true;
	dob.dep_day.options[end_day-1].selected = true;
	DATE_set_days(dob.dep_year, dob.dep_month, dob.dep_day);
	
}

function DATE_date_object(){
	var myDate = new Date();
	this.arr_year = document.ReservationForm.arrival_year;
	this.arr_month = document.ReservationForm.arrival_month;
	this.arr_day = document.ReservationForm.arrival_day;
	this.dep_year = document.ReservationForm.departure_year;
	this.dep_month = document.ReservationForm.departure_month;
	this.dep_day = document.ReservationForm.departure_day;
	this.start_month = myDate.getMonth() + 1;
	this.start_day = myDate.getDate();
	this.start_year = myDate.getFullYear();
}

function DATE_set_date(){
	var dob = new DATE_date_object()
	//Main Rule: dep > arr >= start
	
	//Assert dimmed day is not selected
	if(dob.arr_day.options[dob.arr_day.selectedIndex].value == ""){
	dob.arr_day.options[DATE_get_number_of_days_in_month(dob.arr_year.options[dob.arr_year.selectedIndex].value, 

dob.arr_month.options[dob.arr_month.selectedIndex].value) - 1].selected = true;
	}
	if(dob.dep_day.options[dob.dep_day.selectedIndex].value == ""){
	dob.dep_day.options[DATE_get_number_of_days_in_month(dob.dep_year.options[dob.dep_year.selectedIndex].value, 

dob.arr_month.options[dob.arr_month.selectedIndex].value) - 1].selected = true;
	}
	
	//Assert arr_month == start_month, if arr_year == start_year and arr_month > start_month 
	if(dob.arr_year.options[dob.arr_year.selectedIndex].value == dob.start_year && 
		dob.arr_month.selectedIndex < dob.start_month - 1){
	    //SR 05-12-2001
		//dob.arr_month.options[dob.start_month - 1].selected = true;
		dob.arr_year.options[dob.arr_year.selectedIndex + 1].selected = true;
	}
	
	//Assert arr_day == start_day, if if arr_year == start_year and arr_month == start_month and arr_day < start_day	

	
	if(dob.arr_year.options[dob.arr_year.selectedIndex].value == dob.start_year && 
		dob.arr_month.options[dob.arr_month.selectedIndex].value  == dob.start_month &&
		//dob.arr_day.selectedIndex < dob.start_day - 1){
		dob.arr_day.options[dob.arr_day.selectedIndex].value < dob.start_day ){
		
		dob.arr_day.options[dob.start_day - 1].selected = true;
	}
	
	//Assert dep_year == arr_year, if dep_year < arr_year 
	if(dob.dep_year.selectedIndex < dob.arr_year.selectedIndex){
		dob.dep_year.options[dob.arr_year.selectedIndex].selected = true;
		//SR 05-12-2001
		//SR Assert dep_month also == arr_month , like the year, if dep_year < arr_year
		dob.dep_month.options[dob.arr_month.selectedIndex].selected = true;
	} 

	//Assert dep_month == arr_month, if dep_year == arr_year and dep_month < arr_month
	if(dob.dep_year.selectedIndex == dob.arr_year.selectedIndex &&
		dob.dep_month.selectedIndex < dob.arr_month.selectedIndex ) {
		dob.dep_month.options[dob.arr_month.selectedIndex].selected = true;
	} 
	//Assert dep_day == arr_day + 1, if dep_year == arr_year and dep_month == arr_month and dep_day <= arr_day
	if(dob.dep_year.selectedIndex == dob.arr_year.selectedIndex &&
		dob.dep_month.selectedIndex == dob.arr_month.selectedIndex &&
		dob.dep_day.selectedIndex <= dob.arr_day.selectedIndex){
		//Set dep_day == arr_day, if arr_day + 1 < DATE_get_number_of_days_in_month(y, m)
		
		if(dob.arr_day.options[dob.arr_day.selectedIndex].value < 

DATE_get_number_of_days_in_month(dob.arr_year.options[dob.arr_year.selectedIndex].value, 

dob.arr_month.options[dob.arr_month.selectedIndex].value)){
			dob.dep_day.options[dob.arr_day.selectedIndex + 1].selected = true;
		}
		//Set dep_month == arr_month + 1 and dep_day == 0, if arr_month < 11
		else if(dob.arr_month.options[dob.arr_month.selectedIndex].value < 12){
			dob.dep_month.options[dob.arr_month.selectedIndex + 1].selected = true;
			dob.dep_day.options[0].selected = true;
		} 
		//Set dep_year == arr_year + 1 and dep_month = 0, arr_month >= 11
		else if(dob.arr_month.options[dob.arr_month.selectedIndex].value >= 12){
			//Set dep == max date if max date is reached
			if(dob.arr_year.selectedIndex == dob.arr_year.length - 1){
				dob.dep_year.options[dob.arr_year.length - 1].selected = true;
				dob.dep_month.options[11].selected = true;
				dob.dep_day.options[30].selected = true;
			}
			//Set dep_yeat == arr_year + 1 and dep_month == 0 and dep_day == 0
			else{
				dob.dep_year.options[dob.arr_year.selectedIndex + 1].selected = true;
				dob.dep_month.options[0].selected = true;
				dob.dep_day.options[0].selected = true;
			}
		}
	}
	
	DATE_set_days(dob.arr_year, dob.arr_month, dob.arr_day); 
	DATE_set_days(dob.dep_year, dob.dep_month, dob.dep_day); 
	
 }





function DATE_get_number_of_days_in_month(y, m){
	if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12){
		return 31;
	}
	else if (m == 4 || m == 6 || m == 9 || m == 11){
		return 30;
	}
	else if (m == 2){
		if (y % 4 == 0 || y % 100 == 0){
			return 29;
		}
		else{
			return 28;
		}
	}
}



function DATE_set_days(s_year, s_month, s_day){
	var dimdate = DATE_get_number_of_days_in_month(s_year.options[s_year.selectedIndex].value, 

s_month.options[s_month.selectedIndex].value)
	if(s_day.options[s_day.selectedIndex].value > dimdate || s_day.options[s_day.selectedIndex].value == "" ){
		s_day.options[dimdate - 1].selected = true;		
	}
	for(d = 27; d < s_day.options.length; d++){
		if(d >= dimdate){
			s_day.options[d].value = "";
			s_day.options[d].text = "";
		}
		else{
			s_day.options[d].value = d + 1;
			s_day.options[d].text = d + 1;
		}
	}
}

function setDate() {
	document.ReservationForm.Arrival.value = 

document.ReservationForm.arrival_day[document.ReservationForm.arrival_day.selectedIndex].value + "/" + 

document.ReservationForm.arrival_month[document.ReservationForm.arrival_month.selectedIndex].value + "/" + 

document.ReservationForm.arrival_year[document.ReservationForm.arrival_year.selectedIndex].value;
	document.ReservationForm.Departure.value = 

document.ReservationForm.departure_day[document.ReservationForm.departure_day.selectedIndex].value + "/" + 

document.ReservationForm.departure_month[document.ReservationForm.departure_month.selectedIndex].value + "/" + 

document.ReservationForm.departure_year[document.ReservationForm.departure_year.selectedIndex].value;
}
