function date1(){
if($("check_out_date").value!='' && $("check_in_date").value!=''){
var date=dateStartEnd('d',$("check_in_date").value,$("check_out_date").value);
if(date<0){
alert('choose right check out date.please')	;
$("check_out_date").value='';
$("check_out_date").focus();
}else{
$("room1date").value=date;
}
}
}

function date2(){

if($("room").value==2 || $("room").value==3 || $("room").value==4){	
if($("check_out_date2").value!='' && $("check_in_date2").value!=''){
var date=dateStartEnd('d',$("check_in_date2").value,$("check_out_date2").value);
if(date<0){
alert('choose right check out date.please')	;
$("check_out_date2").value='';
$("check_out_date2").focus();
}else{
$("room2date").value=date;
}
}
}
}

function date3(){
if($("room").value==3 || $("room").value==4){	
if($("check_out_date4").value!='' && $("check_in_date4").value!=''){
var date=dateStartEnd('d',$("check_in_date4").value,$("check_out_date4").value);
if(date<0){
alert('choose right check out date.please')	;
$("check_out_date4").value='';
$("check_out_date4").focus();
}else{
$("room3date").value=date;
}
}
}
}

function date4(){
if($("room").value==4){	
if($("check_out_date6").value!='' && $("check_in_date6").value!=''){
var date=dateStartEnd('d',$("check_in_date6").value,$("check_out_date6").value);
if(date<0){
alert('choose right check out date.please')	;
$("check_out_date6").value='';
$("check_out_date6").focus();
}else{
$("room4date").value=date;
}
}
}
}
date1.periodical(1000);
date2.periodical(1000);
date3.periodical(1000);
date4.periodical(1000);


function daysBetween(DateOne,DateTwo)
   {  
      var OneMonth = DateOne.substring(5,DateOne.lastIndexOf ('-'));
      var OneDay = DateOne.substring(DateOne.length,DateOne.lastIndexOf ('-')+1);
      var OneYear = DateOne.substring(0,DateOne.indexOf ('-'));
      var TwoMonth = DateTwo.substring(5,DateTwo.lastIndexOf ('-'));
      var TwoDay = DateTwo.substring(DateTwo.length,DateTwo.lastIndexOf ('-')+1);
      var TwoYear = DateTwo.substring(0,DateTwo.indexOf ('-'));   
      var cha=((Date.parse(OneMonth+'/'+OneDay+'/'+OneYear)- Date.parse(TwoMonth+'/'+TwoDay+'/'+TwoYear))/86400000);  
     return Math.abs(cha);
}


    //+---------------------------------------------------
   //| 比较日期差 dtEnd 格式为日期型或者 有效日期格式字符串
   //+------------------- --------------------------------
function datediff (strInterval, dtStart) {  
  
    var dtEnd = new Date();
    if (typeof dtStart == 'string' )//如果是字符串转换为日期型
     {  
          dtStart = StringToDate(dtStart);
     }
      switch (strInterval) {  
         case 's' :return parseInt((dtEnd - dtStart) / 1000);
         case 'n' :return parseInt((dtEnd - dtStart) / 60000);
         case 'h' :return parseInt((dtEnd - dtStart) / 3600000);
         case 'd' :return parseInt((dtEnd - dtStart) / 86400000);
         case 'w' :return parseInt((dtEnd - dtStart) / (86400000 * 7));
         case 'm' :return (dtEnd.getMonth()+1)+((dtEnd.getFullYear()-dtStart.getFullYear())*12) - (dtStart.getMonth()+1);
         case 'y' :return dtEnd.getFullYear() - dtStart.getFullYear();
         case 'd-h' :return parseFloat((dtEnd - dtStart) / 86400000).toFixed(2);
      }
}
      //+---------------------------------------------------
   //| 比较日期差 dtStart dtEnd 格式为日期型或者 有效日期格式字符串
   //+------------------- --------------------------------
function dateStartEnd (strInterval, dtStart,dtEnd) {   
    if (typeof dtStart == 'string' )//如果是字符串转换为日期型
     {  
          dtStart = StringToDate(dtStart);
     }
     if (typeof dtEnd == 'string' )//如果是字符串转换为日期型
     {  
          dtEnd = StringToDate(dtEnd);
     }
      switch (strInterval) {  
         case 's' :return parseInt((dtEnd - dtStart) / 1000);
         case 'n' :return parseInt((dtEnd - dtStart) / 60000);
         case 'h' :return parseInt((dtEnd - dtStart) / 3600000);
         case 'd' :return parseInt((dtEnd - dtStart) / 86400000);
         case 'w' :return parseInt((dtEnd - dtStart) / (86400000 * 7));
         case 'm' :return (dtEnd.getMonth()+1)+((dtEnd.getFullYear()-dtStart.getFullYear())*12) - (dtStart.getMonth()+1);
         case 'y' :return dtEnd.getFullYear() - dtStart.getFullYear();
         case 'd-h' :return parseFloat((dtEnd - dtStart) / 86400000).toFixed(2);
      }
}
   //+---------------------------------------------------
//| 字符串转成日期类型  
//| 格式 YYYY-MM-dd-HH-mm-ss
//+---------------------------------------------------
function StringToDate(DateStr)
{  
     var converted = Date.parse(DateStr);
     var myDate = new Date(converted);
     if (isNaN(myDate))
     {  
          var arys= DateStr.split('-');
          myDate = new Date(arys[0],--arys[1],arys[2],arys[3],arys[4],arys[5]);
      }
     return myDate;
      }
	  
	  
