﻿/*双月日历控件*/
document.write('<iframe id=\"CalFrame\" name=\"CalFrame\" frameborder=\"0\" style=\"display:none;position:absolute;z-index:1000\" onload=\"loadCalendarHtm();\"></iframe>');
document.onclick=hideCalendar;
function loadCalendarHtm(){}

function setCheckInDate(d){
	document.getElementById("checkin").value=d;
	if(document.getElementById("checkout").value.length==0){
		showCalendar('dimg2',false,'checkout','checkin');
	}
}

function setCheckIn1Date(d){
	document.getElementById("checkin1").value=d;
	if(document.getElementById("checkout1").value.length==0){
		showCalendar('dimg22',false,'checkout1','checkin1');
	}
}

function setCheckIn2Date(d){
	document.getElementById("checkin2").value=d;
	if(document.getElementById("checkout2").value.length==0){
		showCalendar('dimg32',false,'checkout2','checkin2');
	}
}

function showCalendar(sImg,bOpenBound,sFld1,sFld2,sCallback,isdetails){
	var obj1=document.getElementById(sFld1);
	if(obj1){
		if(obj1.value.length>0)
			sFld2=sFld1;
	}
	showCalendar_v(sImg,bOpenBound,sFld1,null,null,null,null,null,null,null,null,null,sFld2,sCallback,null,null,null,isdetails);
}

function showCalendar_v(sImg,bOpenBound,sFld1,sNextP,sNextD,sStartD,sEndD,sVD,sOE,sVDE,sOT,s3F,sFld2,sCallback,sNextVDE,iPosLeft,iPosTop,isdetails){
	var fld1,fld2;
	var cf=document.getElementById("CalFrame");
	if (cf!=null && cf!="undefine" && cf.src==""){
	    loadCalendarHtm = function() {
	         showCalendar_v(sImg,bOpenBound,sFld1,sNextP,sNextD,sStartD,sEndD,sVD,sOE,sVDE,sOT,s3F,sFld2,sCallback,sNextVDE,iPosLeft,iPosTop,isdetails);
	    }
	    cf.src = "/hotel/inc/js/dmcalendar/dm_calendar.htm";
	    return;
	}

	var wcf=window.frames.CalFrame;
	var oImg=document.getElementById(sImg);
	if(!oImg){alert("Sorry,The System Error1");return;}
	if(!sFld1){alert("Sorry,The System Error2");return;}
	fld1=document.getElementById(sFld1);
	if(!fld1){alert("Sorry,The System Error3");return;}
	if(fld1.tagName!="INPUT"||fld1.type!="text"){alert("Sorry,The System Error4");return;}
	if(sFld2)
	{
		fld2=document.getElementById(sFld2);
		if(!fld2){alert("Sorry,The System Error5");return;}
		if(fld2.tagName!="INPUT"||(fld2.type!="text"&&fld2.type!="hidden")){alert("Sorry,The System Error6");return;}
	}
	if(!wcf.bCalLoaded){alert("Sorry,The System Error7");return;}
	wcf.n_position=sNextP;
	wcf.n_textdate=sNextD;
	wcf.startdate=sStartD;
	wcf.enddate=sEndD;
	wcf.vailidday=sVD;
	wcf.oddeven=sOE;
	wcf.vailiddate=sVDE;
	wcf.nextvailiddate = sNextVDE;
	wcf.objecttype=sOT;
	wcf.thirdfocus=s3F;
	if(cf.style.display=="block"){cf.style.display="none";return;}
	if (!(iPosLeft && iPosTop)){
	    var pos = getPositionNew(oImg);
	    iPosLeft = pos.OffsetLeft;
	    iPosTop = pos.OffsetTop +(oImg.clientHeight == null ? 0 : oImg.clientHeight);
	    
	    var wh =getClientNew();
	    if((iPosLeft+290)>wh.clientWidth){
	    	iPosLeft = pos.OffsetLeft+(oImg.clientWidth == null ? 21 : oImg.clientWidth)-290;
	    	iPosTop = pos.OffsetTop +(oImg.clientHeight == null ? 0 : oImg.clientHeight);
	    }
	}
	if(isdetails){
	    var pos = getPositionNew(oImg);
		iPosLeft = pos.OffsetLeft+(oImg.clientWidth == null ? 21 : oImg.clientWidth)-290;
	    iPosTop = pos.OffsetTop +(oImg.clientHeight == null ? 0 : oImg.clientHeight);
	}
	cf.style.left = iPosLeft + "px";
	cf.style.top  = (iPosTop + 4) + "px";
	
	cf.height = 200;
	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 getAbsolutePos(obj){
    var pos = { x: 0, y: 0 };
    var offset_x = obj.clientLeft;
    var offset_y = obj.clientTop;

    function innerFunction(){
        while(obj && (obj.style.position != "relative")){
           pos.x += obj.offsetLeft;
           pos.y += obj.offsetTop;
           pos.x += obj.clientLeft;
           pos.y += obj.clientTop;
           if(obj.scrollLeft)
             pos.x += obj.clientLeft;
           if(obj.scrollTop)pos.y += obj.scrollTop;
           obj=obj.offsetParent;
        }
    }

    innerFunction();
    pos.x -= offset_x;
    pos.y -= offset_y;

    return pos;
}
function getScroll(){
	var sTop = 0, sLeft = 0, sWidth = 0, sHeight = 0;
	sTop = (document.body.scrollTop > document.documentElement.scrollTop)? document.body.scrollTop:document.documentElement.scrollTop;
	if( isNaN(sTop) || sTop <0 ){ sTop = 0 ;}
	sLeft = (document.body.scrollLeft > document.documentElement.scrollLeft )? document.body.scrollLeft:document.documentElement.scrollLeft;
	if( isNaN(sLeft) || sLeft <0 ){ sLeft = 0 ;}
	return { sTop:sTop, sLeft: sLeft, sWidth: sWidth, sHeight: sHeight };
}
function getClient(){
	var h1 = document.body.clientHeight;
	var h2 = document.documentElement.clientHeight;
	var isXhtml = (h2<=h1&&h2!=0)?true:false;
	this.clientHeight = isXhtml?document.documentElement.clientHeight:document.body.clientHeight;
	this.clientWidth  = isXhtml?document.documentElement.clientWidth:document.body.clientWidth;
	return {clientHeight:this.clientHeight,clientWidth:this.clientWidth};
}
function getPositionNew(sObj){
    var sObjOffsetTop = 0;
    var sObjOffsetLeft = 0;
    var tempObj = sObj;
    while (tempObj && tempObj.tagName.toUpperCase() != "BODY"){
        sObjOffsetTop += tempObj.offsetTop;
        sObjOffsetLeft += tempObj.offsetLeft;
        tempObj = tempObj.offsetParent;
    }
    tempObj = null;
    return { OffsetTop: sObjOffsetTop, OffsetLeft: sObjOffsetLeft };
}
function getClientNew(){
    var isXhtml = true;
    if (document.documentElement == null || document.documentElement.clientHeight <= 0) {
        if (document.body.clientHeight > 0) {
            isXhtml = false;
        }
    }
    this.clientHeight = isXhtml ? document.documentElement.clientHeight : document.body.clientHeight;
    this.clientWidth = isXhtml ? document.documentElement.clientWidth : document.body.clientWidth;
    return { clientHeight: this.clientHeight, clientWidth: this.clientWidth };
}
function getScrollNew() {
    var scrollTop = 0, scrollLeft = 0;
    scrollTop = (document.body.scrollTop > document.documentElement.scrollTop) ? document.body.scrollTop : document.documentElement.scrollTop;
    if (isNaN(scrollTop) || scrollTop < 0) { scrollTop = 0; }
    scrollLeft = (document.body.scrollLeft > document.documentElement.scrollLeft) ? document.body.scrollLeft : document.documentElement.scrollLeft;
    if (isNaN(scrollLeft) || scrollLeft < 0) { scrollLeft = 0; }
    return { scrollTop: scrollTop, scrollLeft: scrollLeft };
}