var date=new Date();
function frmSubmit(frm,compID,flag)
{
	var strStartTime = trim(frm.RoomSearch210H_startdate.value);
	var strEndTime = trim(frm.RoomSearch210H_enddate.value);
			
		tempStr = strStartTime;
		var i = tempStr.indexOf("-");					
		if(i > -1)
			var strYear = tempStr.substring(0, i);
			var nYear = parseInt(strYear) + 1;	
		tempStr = tempStr.substring(i+1, tempStr.length);
		i = tempStr.indexOf("-");					
		if(i > -1)
			var strMonth = tempStr.substring(0, i);				
		strDay = tempStr.substring(i+1, tempStr.length);					
		tempStr = tempStr.substring(i+1, tempStr.length);																									
		var strOverTime = nYear + "-" + strMonth + "-" + strDay;		
			

	//验证入住日期
  if(trim(frm.RoomSearch210H_startdate.value) == "")
  {
		alert("Please input the arrival date!");
		frm.RoomSearch210H_startdate.focus();
		return false;
  }	
	if((trim(frm.RoomSearch210H_startdate.value) != "") && !isDate(trim(frm.RoomSearch210H_startdate.value)))
	{
		alert("Please input the valid arrival date!");
		frm.RoomSearch210H_startdate.focus();
		return false;
	}  
	//验证离开日期		
  if(trim(frm.RoomSearch210H_enddate.value) == ""){
		alert("Please input the departure date.");
		frm.RoomSearch210H_enddate.focus();
		return false;
  }	
	if((trim(frm.RoomSearch210H_enddate.value) != "") && !isDate(trim(frm.RoomSearch210H_enddate.value))){
		alert("please input the valid departure date!");
		frm.RoomSearch210H_enddate.focus();
		return false;
	}   
	
		//闰年处理
		if(!isLeapYear(strStartTime)){
			alert("The check-in date is incorrect.");
			frm.RoomSearch210H_startdate.focus();
			return false;
		}else if(!isLeapYear(strEndTime)){
			alert("The departure date is not correct");
			frm.RoomSearch210H_enddate.focus();
			return false;
		}
    
  //验证有效期
  if(frm.RoomSearch210H_startdate.value > frm.RoomSearch210H_enddate.value)
	{
 		alert("Departure date should be greater than arrival date at least!");
 		frm.RoomSearch210H_enddate.focus();
 		return false; 
	}  
	if(compareDate(strOverTime,strEndTime))
	{
 		//alert("The difference between the departure date and the check-in date can only be within one year");
 		alert("The difference between the departure date and the check-in date can only be within one year");
 		frm.RoomSearch210H_enddate.focus();
 		return false; 	
	}
	if(flag=="Y")
	{
		if(!confirm("If you click “confirm”, the system will search for the guest room again, and clear out your present booking plan!"))
		return false;
	}
           frm.action="RoomMultiplePageDisplay.html?"+compID+"_action=Search&time="+ date.getTime();
           frm.submit();
}

function isLeapYear(date){
	var yyyy =  parseInt(date.substring(0,4));
	var mm =  parseInt(date.substring(5,7));
	var dd =  parseInt(date.substring(8,10));
	if(mm==2){
     if((yyyy%4)==0 && (yyyy%100)!=0 || (yyyy%400)==0){
        if(dd>29){
          return false;
        }
     } else {
        if(dd>28){
          return false;
        }
     }
  }
	return true;
}
