﻿function DateDiff(startDate, endDate){
   var aDate, oDate1, oDate2, iDays ;
   aDate = startDate.split('-');
   oDate1 = new Date(aDate[1]+'-'+aDate[2]+'-'+aDate[0]) ;
   aDate = endDate.split('-');
   oDate2 = new Date(aDate[1]+'-'+ aDate[2] +'-'+aDate[0]);
   iDays = parseInt(Math.abs(oDate1 -oDate2)/1000/60/60/24); //把相差的毫秒数转换为天数
   return iDays ;
}

function stringFormat()
{
    if (arguments.length < 2){
        return "";
    }
    var strFormat = arguments[0].toString();
    for( var i = 1; i < arguments.length; i++)
    {
        strFormat = strFormat.replace("%S",arguments[i]);
    }
    return strFormat;
}

//查询
function queryResult()
{
    

    var country=window.document.getElementById('countryCity').contentWindow.document.getElementById('Country').selectedIndex;
    var city=window.document.getElementById('countryCity').contentWindow.document.getElementById('City').value;

    if(city=="-1")
    {
        for(i=0;i<document.form1.city.length;i++)
        {
           if(document.form1.city[i].checked==true)
           {
               city=document.form1.city[i].value;
           }
        }
    }
    if(city=="-1")
    {
       alert("请选择城市");
       return false;        
    }
    
    var selectTime=document.getElementById('starttime').value;
    var outTime=document.getElementById('deptime').value;
    var days=DateDiff(selectTime,outTime);
    var selectSingleBed=document.getElementById('selectSingleBed').options[document.getElementById('selectSingleBed').selectedIndex].value;
    var selectTwoBed=document.getElementById('selectTwoBed').options[document.getElementById('selectTwoBed').selectedIndex].value;
    var selectDoubleBed=document.getElementById('selectDoubleBed').options[document.getElementById('selectDoubleBed').selectedIndex].value;
    var starLevel=document.getElementById('starLevel').options[document.getElementById('starLevel').selectedIndex].value;
    var hotelName=document.getElementById('hotelname').value;
    if(hotelName=="请输入至少3个字母")
    {
    	
    	hotelName="";
    	}
    if(selectTime == null || selectTime == "")
	{
		alert("请选择入住日期");
		return false;
	}
	
	var sDate = new Date(selectTime.replace(/\-/g, "\/"));
    var eDate = new Date(outTime.replace(/\-/g, "\/"));
    if(sDate >= eDate)
    {
     alert("入住日期不能大于离店日期");
     return false;
    }



   
    if(selectSingleBed=='0' && selectTwoBed=='0' && selectDoubleBed=='0')
    {
        alert("请选择房间"); 
        return false;
    }
    
   
    if((parseInt(selectSingleBed)+parseInt(selectTwoBed*2)+parseInt(selectDoubleBed*3))>10)
    {
        alert("预订10人以上请选择团体预订！"); 
        return false;
    }
    
    var pNum = selectSingleBed +","+ selectTwoBed + "," + selectDoubleBed;
    var queryString = "country="+country+"&city="+city+"&inT="+selectTime+"&days="+days+"&pnum="+pNum+"&star="+starLevel+"&hName="+hotelName+"&outT="+outTime;
    var message = "您确认要进行本次查询吗?" ;
    //if ( confirm(message) )
    //{
  	    //转向查询结果页面
	//    window.location='Search/SearchResult.aspx?'+queryString;	
   // }   


   window.open('/Search/loading.aspx?'+queryString);
}

//重新载入国家城市
function ResetCountryCity()
{
    document.getElementById('countryCity').src='/inc/countryCity.htm';
}

function erase()
{
	if(document.getElementById('hotelname').value=="请输入至少3个字母")
	{
	
	document.getElementById('hotelname').value="";
		
	}
}

function recovery()
{
	if(document.getElementById('hotelname').value=="")
	{
	
	document.getElementById('hotelname').value="请输入至少3个字母";
		
	}
}
