﻿// JScript File
function searchsubmit(){
					var formname=document.form1;
					if (formname.starttime.value.length==0){
						alert("请输入入住时间!");
						formname.starttime.focus();
						return false
					}	
					if(!isDate(formname.starttime.value)){
						alert("起始日期不符合格式规范或无效的日期!");
						formname.starttime.focus();
						return false
					}
					if (stringToDate(formname.starttime.value,true)<stringToDate(formname.perdate.value,true)){
						alert("起始日期不能早于"+formname.perdate.value+"!");
						formname.starttime.focus();
						return false
					}
//					if (stringToDate(formname.starttime.value,true)>=stringToDate(formname.postdate.value,true)){
//						//modified by pegasus 2003-07-17 begin
//						//alert("入住时间不能晚于或等于"+document.ListItemForSale.postdate.value+"!");
//						alert("本系统不支持晚于或等于"+formname.postdate.value+"的网上预订，如需预订请致电800-820-6666!");
//						//modified by pegasus 2003-07-17 end
//						formname.starttime.focus();
//						return false
//					}
					if (formname.deptime.value.length==0){
						alert("请输入截止日期!");
						formname.deptime.focus();
						return false
					}	
					if(!isDate(formname.deptime.value)){
						alert("截止日期不符合格式规范或无效的日期!");
						formname.deptime.focus();
						return false
					}
					if (stringToDate(formname.deptime.value,true)<=stringToDate(formname.starttime.value,true)){
						alert("截止日期不能早于或等于入住时间"+formname.starttime.value+"!");
						formname.deptime.focus();
						return false
					}
//					if (stringToDate(formname.deptime.value,true)>stringToDate(document.ListItemForSale.postdate.value,true)){
//						//modified by pegasus 2003-07-17 begin
//						//alert("离店时间不能晚于"+document.ListItemForSale.postdate.value+"!");
//						alert("本系统不支持晚于或等于"+document.ListItemForSale.postdate.value+"的网上预订，如需预订请致电800-820-6666!");
//						//modified by pegasus 2003-07-17 end
//						formname.deptime.focus();
//						return false
//					}
//					if ((stringToDate(formname.deptime.value,true)-stringToDate(formname.starttime.value,true))>2419200000)
//					{
//						alert("入住时间段不能超过28天！");
//						formname.deptime.focus();
//						return false
//					}
					
				} 

function isDateString(sDate)
{	var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
	var iaDate = new Array(3)
	var year, month, day

	if (arguments.length != 1) return false
	iaDate = sDate.toString().split("-")
	if (iaDate.length != 3) return false
	if (iaDate[1].length > 2 || iaDate[2].length > 2) return false
	if (isNaN(iaDate[0])||isNaN(iaDate[1])||isNaN(iaDate[2])) return false

	year = parseFloat(iaDate[0])
	month = parseFloat(iaDate[1])
	day=parseFloat(iaDate[2])

	if (year < 1900 || year > 2100) return false
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
	if (month < 1 || month > 12) return false
	if (day < 1 || day > iaMonthDays[month - 1]) return false
	return true
}

function stringToDate(sDate, bIgnore)
{	var bValidDate, year, month, day
	var iaDate = new Array(3)
	
	if (bIgnore) bValidDate = true
	else bValidDate = isDateString(sDate)
	
	if (bValidDate)
	{  iaDate = sDate.toString().split("-")
		year = parseFloat(iaDate[0])
		month = parseFloat(iaDate[1]) - 1
		day=parseFloat(iaDate[2])
		return (new Date(year,month,day))
	}
	else return (new Date(1900,1,1))
}

document.write('<iframe id=CalFrame name=CalFrame frameborder=0 src=../Calendar/calendar.htm style=display:none;position:absolute;z-index:100></iframe>');
//document.onclick=hideCalendar;//当页面有点击时，控制日期选择窗口的隐藏。

var sCtl1,sCtl2;

function showCalendar(sFld1,bOpenBound,sFld,sFld2,sCallback)
{
    
	sCtl1=sFld1;
	sCtl2=sFld;

	var fld1,fld2;
	var cf=document.getElementById("CalFrame");
	cf.style.visibility="visible";
	var wcf=window.frames.CalFrame;
	var oImg=document.getElementById(sFld1);
	if(!oImg){alert("控制对象不存在！");return;}
	//oImg.focus(); //使文本框得到焦点
    //oImg.select();
	if(!sFld1){alert("输入控件未指定！");return;}
	fld1=document.getElementById(sFld1);
	if(!fld1){alert("输入控件不存在！");return;}
	if(fld1.tagName!="INPUT"||fld1.type!="text"){alert("输入控件类型错误！");return;}
	if(sFld2)
	{
		fld2=document.getElementById(sFld2);
		if(!fld2){alert("参考控件不存在！");return;}
		if(fld2.tagName!="INPUT"||fld2.type!="text"){alert("参考控件类型错误！");return;}
	}
	if(!wcf.bCalLoaded){alert("日历未成功装载！请刷新页面！");return;}
	if(cf.style.display=="block"){cf.style.display="none";return;}
	
	var eT=0,eL=0,p=oImg;
	var sT=document.body.scrollTop,sL=document.body.scrollLeft;
	var eH=oImg.height,eW=oImg.width,extraH=20;
	while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	cf.style.top=(document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH+extraH:eT-cf.height+extraH;
	cf.style.left=(document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width;
	cf.style.display="block";
	
	wcf.openbound=bOpenBound;//当前所选日期以前的日期是否可选的标志
	wcf.fld1=fld1;
	wcf.fld2=fld2;
	wcf.callback=sCallback;
	wcf.initCalendar();
	click_datechange();
}
function click_datechange()
{
    var hidd=document.getElementById("selectrmtyp");
    if (hidd!=null)
    {
        temphtlcd=hidd.value.split(',');
        if (temphtlcd.length>=0)
        {   
            hidd.value="";
            for (var j=0;j<temphtlcd.length;j++)
            {
                var temphtlrm=temphtlcd[j].split('^');
                var temptext2=document.getElementById(temphtlrm[0]+"^"+temphtlrm[1]);
                if (temptext2!=null)
                {
                    temptext2.checked=false;
                }
            }
        }
    }
}
function hideCalendar()
{
	var cf=document.getElementById("CalFrame");
	cf.style.display="none";
}

function show(strtype){document.getElementById(strtype).style.display="block";document.getElementById("images_"+strtype).style.display="block";document.dispCtrl.chooseType.value=strtype;if(strtype=="vacation")toggleBlock()}
function hide(strtype){document.getElementById(strtype).style.display="none";document.getElementById("images_"+strtype).style.display="none";}

function setCheckInDate(d)
{
    var ctl1,ctl2;
    if(sCtl1)
	{
	    ctl1=document.getElementById(sCtl1);
		if(!ctl1){alert("参考控件sCtl1不存在！");return;}
		if(ctl1.tagName!="INPUT"||ctl1.type!="text"){alert("参考控件sCtl1类型错误！");return;}
	}
	if(sCtl2)
	{
	    ctl2=document.getElementById(sCtl2);
		if(!ctl2){alert("参考控件sCtl2不存在！");return;}
		if(ctl2.tagName!="INPUT"||ctl2.type!="text"){alert("参考控件sCtl2类型错误！");return;}
	}
//	document.getElementById("ctl00_CRSRight_JBFXcontent1_EditBgDt").value=d;
//	showCalendar('ctl00_CRSRight_JBFXcontent1_EditEdDt',false,'ctl00_CRSRight_JBFXcontent1_EditEdDt','ctl00_CRSRight_JBFXcontent1_EditBgDt');

    document.getElementById(sCtl1).value=d;
	
	//设置止期
	var arys= new Array();
    arys=d.split('-');
//    var currdt=arys[0]+"-"+arys[1]+"-"+(Number(arys[2])+1);
    var currdt=arys[0]+"-"+arys[1]+"-"+arys[2];
	document.getElementById(sCtl2).value=currdt;
	
	showCalendar(sCtl2,true,null,sCtl1);
    
}
