// JavaScript Document
//读取页面元素
function getObject(objectId) {
     if(document.getElementById && document.getElementById(objectId)){// W3C DOM
       return document.getElementById(objectId);
     } 
     else if (document.all && document.all(objectId)){// MSIE 4 DOM
       return document.all(objectId);
     } 
     else if (document.layers && document.layers[objectId]){// NN 4 DOM.. note: this won't find nested layers
       return document.layers[objectId];
     } 
     else{
       return false;
     }
}  
// 创建XMLHttpRequest对象
function CreateXMLHttpRequest()
{
   // Initialize Mozilla XMLHttpRequest object
   var xmlHttp;
   if (window.XMLHttpRequest)
   {
       xmlHttp = new XMLHttpRequest();
   } 
   // Initialize for IE/Windows ActiveX version
   else if (window.ActiveXObject)
   {
       try
       {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
         } 
       catch (e)
       {
                try
                {
                     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }  
                catch(e)
                {
                     newsstring = "对不起，您的浏览器不支持XMLHttpRequest对象！";}
          }   
   }
   return xmlHttp;
}


function subForm(fStr){
	getObject(fStr).submit();
	}
	//下单
function SubOrder(){
	if (getObject("cust_name").value=="" || getObject("cust_tel").value==""){
		alert("名称或电话不能为空！");
		}
	else{
		subForm("suborder");
		}
	}
function OrderRoom(ridInt){
	ShowDivById('orderwindow');
	getObject('orderwindow').style.width = getWidth();
	getObject('orderwindow').style.height = getWidth();
	UrlToDiv('Order.asp?rid='+ridInt,'orderwindow');
	initialize();
	}
function SubAsk(){
	ShowDivById('orderwindow');
	getObject('orderwindow').style.width = getWidth();
	getObject('orderwindow').style.height = getWidth();
	UrlToDiv('Ask.asp','orderwindow');	
	initialize();
	}
	
function SubComment(){
	ShowDivById('orderwindow');
	getObject('orderwindow').style.width = getWidth();
	getObject('orderwindow').style.height = getWidth();
	UrlToDiv('Comment.asp','orderwindow');	
	initialize();
	}
function SubCommentDo(){
	if (getObject("username").value=="" || getObject("Content").value==""){
		alert("名称、内容不能为空！");
		}
	else{
		subForm("SaveComment");
		}
	}
function SubAskDo(){
	if (getObject("A_USER").value=="" || getObject("A_CONTENT").value==""){
		alert("名称、内容不能为空！");
		}
	else{
		subForm("SubAsk");
		}
	}
	
	//加载页面到一个DIV中
function UrlToDiv(rUrl,tDiv){
	
	var infoObj=CreateXMLHttpRequest();
	infoObj.open("GET", rUrl, true);
	infoObj.onreadystatechange = function(){
		if (infoObj.readyState == 4 && infoObj.status == 200) 	{
			getObject(tDiv).innerHTML  = infoObj.responseText;
		}
	}
	
	
	infoObj.setRequestHeader("If-Modified-Since","0");
    infoObj.send(null); 	
	
	}

function ShowDivById(idStr){
   getObject(idStr).style.display= "block";
}

function HiddenDivById(idStr){
    getObject(idStr).style.display = "none";
}

//-- 获取窗口宽度 --
function getWidth()
{
    var strWidth,clientWidth,bodyWidth;
    clientWidth = document.documentElement.clientWidth;
    bodyWidth = document.body.clientWidth;
    if(bodyWidth > clientWidth){
        strWidth = bodyWidth;
    } else {
        strWidth = clientWidth;
    }
    return strWidth;
}

//-- 获取窗口高度 --
function getHeight()
{
    var strHeight,clientHeight,bodyHeight;
    clientHeight = document.documentElement.clientHeight;
    bodyHeight = document.body.clientHeight;
    if(bodyHeight > clientHeight){
        strHeight = bodyHeight;
    } else {
        strHeight = clientHeight;
    }
    return strHeight+200;
}


var currentpos,timer; 
function initialize() 
{ 

} 
function sc(){
clearInterval(timer);	
}
function scrollwindow() 
{ 
currentpos=document.body.scrollTop; 
window.scroll(0,++currentpos); 
if (currentpos != document.body.scrollTop) 
sc();
} 



function SelectDayPrice(){
	var now= new Date();
	var hid=getObject("hid").value;
	var bdate=getObject("Startdate").value;
	var edate=getObject("Enddate").value;
	now=now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
	alert
	if(daysBetween(bdate,now)<<0 || daysBetween(bdate,edate)<<0){
		
		alert("入住时间不能小于当前时间\n并且离店时间不能小于入住时间");
		}
		else	
	UrlToDiv("http://hotels.cthnet.com/Getroom.aspx?hid="+hid+"&Bdate="+bdate+"&Edate="+edate,"Roomlist");
	}


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 cha;      
}      


function ShortDivContent(DivId,CLength){
	//var Content=Math.ceil(parseInt(getObject(DivId).offsetHeight));
	var ContentLenght=Content.length;
	var realContent=Content.substring(0,CLength)
	getObject(DivId).innerHTML=realContent;
	}
	
function GetFlashAd(sInt){
	switch (sInt){
		case 1 :
			UrlToDiv("flash.asp?s=1","FlashAd11");
		case 2 :
			UrlToDiv("flash.asp?s=2","FlashAd11");
		default :
			UrlToDiv("flash.asp?s=1","FlashAd11");
		}
	
	}