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;

function showCalendar(sImg,bOpenBound,sFld1,sFld2,sCallback)
{
	var fld1,fld2;
	var cf=document.getElementById("CalFrame");
	var wcf=window.frames.CalFrame;
	var oImg=document.getElementById(sImg);
	if(!oImg){alert("控制对象不存在！");return;}
	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;
	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:eT-cf.height;
	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();
}
function hideCalendar()
{
	var cf=document.getElementById("CalFrame");
	cf.style.display="none";
}
function openwindowguide(){window.open('/html/home/homepage/quicksearch.htm','','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,height=340,width=400');}
function show(strtype){document.getElementById(strtype).style.display="block";document.getElementById("Image_"+strtype).style.display="block";document.dispCtrl.chooseType.value=strtype;if(strtype=="vacation")toggleBlock()}
function hide(strtype){document.getElementById(strtype).style.display="none";document.getElementById("Image_"+strtype).style.display="none";}
function setCheckInDate(d)
{
	document.getElementById("hdate1").value=d;
	if(document.getElementById("hdate2").value.length==0)
	{
		showCalendar('dimg2',false,'hdate2','hdate1');
	}
}
function DateEqual(date1,date2)
{	var year1, month1, day1;
	var iaDate1 = new Array(3);
	var year2, month2, day2;
	var iaDate2 = new Array(3);

	iaDate1 = date1.toString().split("-")
	year1 = parseFloat(iaDate1[0])
	month1 = parseFloat(iaDate1[1]) - 1
	day1=parseFloat(iaDate1[2])
	
	iaDate2 = date2.toString().split("-")
	year2 = parseFloat(iaDate2[0])
	month2 = parseFloat(iaDate2[1]) - 1
	day2=parseFloat(iaDate2[2])
	
	if(year1==year2&&month1==month2&&day1==day2)
	    return true;
	else 
	    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||iaDate[1].length==0||iaDate[2].length==0) 
	    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));
}
function tripchecktime(fH)
{
if (fH.starttime.value.length==0)
{
    alert("请输入起租日期!");
    fH.starttime.focus();
	return false;
}
if(!isDateString(fH.starttime.value))
{
    alert("起租日期应以YYYY-MM-DD的格式输入!");
    fH.starttime.focus();
	return false;
}
var starttime=stringToDate(fH.starttime.value,true);
var deptime=stringToDate(fH.deptime.value,true);
var predate=stringToDate(fH.predate.value,true);
var postdate=stringToDate(fH.postdate.value,true);
if (starttime<predate)
{
    alert("起租日期不能早于"+fH.predate.value+"!");
    fH.starttime.focus();
	return false;
}
if (fH.deptime.value.length==0)
{
    alert("请输入退租日期!");
    fH.deptime.focus();
	return false;
}	
if(!isDateString(fH.deptime.value))
{
    alert("退租日期应以YYYY-MM-DD的格式输入!");
    fH.deptime.focus();
	return false;
}
if (deptime<=starttime)
{
    alert("退租日期不能早于或等于起租日期"+fH.starttime.value+"!");
    fH.deptime.focus();
	return false;
}
/*if (deptime>postdate)
{
    alert("本系统不支持晚于"+fH.postdate.value+"的房间查询!");
    fH.deptime.focus();
	return false;
}*/
return true;
}
function DayDiff(date1,date2)
{
    var timediff =date2.getTime()-date1.getTime();
    var daydiff =(timediff/3600000/24);
    return daydiff;
}
function DateToString(day)//到日期为止
 {
	var y= day.getYear()+1900;
    var m= (day.getMonth()+1);
	var mstr="";
	var dstr="";
	var ystr="";
	ystr=""+y;
    if (m<10)
         mstr="0"+m;
    else
		mstr=""+m;
    var d= day.getDate();
    if (d<10)
        dstr="0"+d;
    else
		dstr=""+d;
	return ystr+"-"+mstr+"-"+dstr;
}