function Date_changer(){

	var today = new Date();
	var date_yearfrom = today.getFullYear();
	//alert(date_yearfrom);
	var date_monthfrom = today.getMonth();
	var date_dayfrom = today.getDate();
	date_monthfrom = date_monthfrom + 1;
	var date_yearend;
	var date_monthend;
	var date_dayend;
	
	var daysinmonth = get_days_in_month(date_monthfrom, date_yearfrom);

	if((date_monthfrom == 12) && (date_dayfrom == 31)){
		date_yearend = date_yearfrom + 1;
		date_monthend = 1;
		date_dayend = 1;
	}
	else{
		date_yearend = date_yearfrom;

		if((date_dayfrom + 1) > daysinmonth){
			date_monthend = date_monthfrom + 1;
			date_dayend = 1;
		}
		else{
			date_monthend = date_monthfrom;
			date_dayend = date_dayfrom + 1;
		}

	}
	
	
	document.formReserv.monthfrom.value= date_monthfrom;
	document.formReserv.monthend.value = date_monthend;
	
	document.formReserv.dayfrom.value = date_dayfrom;
	document.formReserv.dayend.value = date_dayend;
}

function Date_changer2(){

	var today = new Date();
	var date_yearfrom = today.getFullYear();
	//alert(date_yearfrom);
	var date_monthfrom = today.getMonth();
	var date_dayfrom = today.getDate();
	date_monthfrom = date_monthfrom + 1;
	var date_yearend;
	var date_monthend;
	var date_dayend;
	
	var daysinmonth = get_days_in_month(date_monthfrom, date_yearfrom);

	if((date_monthfrom == 12) && (date_dayfrom == 31)){
		date_yearend = date_yearfrom + 1;
		date_monthend = 1;
		date_dayend = 1;
	}
	else{
		date_yearend = date_yearfrom;

		if((date_dayfrom + 1) > daysinmonth){
			date_monthend = date_monthfrom + 1;
			date_dayend = 1;
		}
		else{
			date_monthend = date_monthfrom;
			date_dayend = date_dayfrom + 1;
		}

	}
	
	
	document.formReserv2.monthfrom.value= date_monthfrom;
	document.formReserv2.monthend.value = date_monthend;
	
	document.formReserv2.dayfrom.value = date_dayfrom;
	document.formReserv2.dayend.value = date_dayend;
}

function get_days_in_month(date_monthfrom, date_yearfrom) {
	
	var days = 0;

	switch(date_monthfrom){
		case  1:
			days = 31;
			break;
		case 2 :
			if(date_yearfrom%4 == 0){
				days = 29;
			}
			else{
				days = 28;
			}
			break;
		case 3 :
			days = 31;
			break;
		case 4 :
			days = 30;
			break;
		case 5 :
			days = 31;
			break;
		case 6 :
			days = 30;
			break;
		case 7 :
			days = 31;
			break;
		case 8 :
			days = 31;
			break;
		case 9 :
			days = 30;
			break;
		case 10 :
			days = 31;
			break;
		case 11 :
			days = 30;
			break;
		case 12 :
			days = 31;
			break;
	}
	
	return days;
}			


function chk_validity_date(dayfrom, monthfrom, yearfrom, dayend, monthend, yearend, option){
	
	var today = new Date();
	if(yearfrom == ""){
		yearfrom = today.getFullYear();
	}
	if(yearend == ""){
		yearend = today.getFullYear();
	}
	daysinmonth_from = get_days_in_month(parseInt(monthfrom), parseInt(yearfrom));
	daysinmonth_end = get_days_in_month(parseInt(monthend), parseInt(yearend));
	
	
	if(dayfrom > daysinmonth_from){
		if(option == 1){
			formReserv.dayfrom.value = daysinmonth_from;
		}
		if(option == 2){
			formReserv.arrival_day.value = daysinmonth_from;
		}
		if(option == 3){
			formReserv.dayfrom.value = daysinmonth_from;
		}
	}
	if(dayend > daysinmonth_end){
		if(option == 1){
			formReserv.dayend.value = daysinmonth_end;
		}
		if(option == 2){
			formReserv.departure_day.value = daysinmonth_end;
		}
		if(option == 3){
			formReserv.dayend.value = daysinmonth_end;
		}
	}
	

}
