function checkdate(theForm){

	var tf = 'true';
	var message = 'Please check information below \n';
	var tour_month;
	var tour_day;
	var digits_date="/0123456789";
	var temp;
	var add_message1;
	var daysinmonth;
	var today = new Date();
	var today_year = today.getYear();
	var today_month = today.getMonth()+1;
	var today_day = today.getDate();
	var tour_month = theForm.tour_date.value.substring(0,2);
	var	tour_day = theForm.tour_date.value.substring(3,5);

	if(!theForm.yearfrom.value){
		theForm.yearfrom.value = today_year;
	}

	if((theForm.tour_date.value == 'mm/dd') || (theForm.tour_date.value == '')){
		tour_day = today_day;
		tour_month = today_month;
		//message += '---> Please fill in \"tour date\" field\n';
		//tf = 'false';
	}	
	
	if((theForm.tour_date.value != '') && (theForm.tour_date.value != 'mm/dd')){
		
		if(theForm.tour_date.value.length != 5){
			tour_day = today_day;
			tour_month = today_month;
			//theForm.tour_date.value = 'mm/dd';
			//message += '---> tour date must to be \"5\" digits\n';
			//tf = 'false';
		}
		else{
		
			for(i=0; i<theForm.tour_date.value.length; i++){
				temp = theForm.tour_date.value.substring(i,i+1);
				if(digits_date.indexOf(temp)==-1){
					add_message1 = '---> Tour date must to be numberic in \"mm/dd\" format\n';
					tf = 'false';
				}
			}
			
			if(!add_message1){			
			
				if(tour_month > 12){
					tour_month = 12;
				}
				else if(tour_month < 1){
					tour_month  = 1;
				}			
				daysinmonth = Get_days_in_month(parseInt(tour_month), parseInt(theForm.yearfrom.value));
				if(tour_day > daysinmonth){
					tour_day = daysinmonth;					
				}		
			
			}
			
			//-----------------------check validity date----------------------------------------
			if(parseInt(today_year) > parseInt(theForm.yearfrom.value)){
				theForm.yearfrom.value = today_year;
			}
			else if(parseInt(today_year) == parseInt(theForm.yearfrom.value)){
			
				if(parseInt(today_month) > parseInt(tour_month)){
					theForm.yearfrom.value = parseInt(today_year) + 1;
					//tour_month = today_month + '';
					//tour_day = today_day + '';
				}
				else if(parseInt(today_month) == parseInt(tour_month)){
					if(parseInt(today_day) > parseInt(tour_day)){
						tour_day = today_day + '';
					}
				}	
			}
		}
	
	}
	
	tour_day = tour_day + '';
	tour_month = tour_month + '';
	
	if(tour_day.length == 1){
		tour_day = '0' + tour_day;
	}
	if(tour_month.length == 1){
		tour_month = '0' + tour_month;
	}
	
	theForm.tour_date.value = tour_month + '/' + tour_day;
	
	/*if(theForm.tour_date.value.length != 5){
		//theForm.tour_date.value = 'mm/dd';
		tour_day = today_day;
		tour_month = today_month;
		theForm.yearfrom.value = today_year;
	}*/
	
	theForm.trip_date.value = theForm.yearfrom.value + '-' + tour_month + '-' + tour_day;
	//alert('trip date =' + tripdate);
	//alert('departure date =' +  reserv.departure_date.value);
	
	
	if(add_message1){
		message += add_message1;
	}	
	
	if(tf == 'false'){
		alert(message);
		return false;
	}
	if(tf == 'true'){
		return true;
	}	
	
}

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;
}			
