document.write("<iframe id=CalFrame name=CalFrame frameborder=0 src=\"/css/calendar.htm\" style=display:none;position:absolute;z-index:100></iframe>");

var sel_id = "";
function dateOnFocus(sImg,bOpenBound,sFld1,sFld2,sCallback){
	showCalendar(sImg,bOpenBound,sFld1,sFld2,sCallback, 2);
}
function showCalendar(sImg,bOpenBound,sFld1,sFld2,sCallback){
	showCalendar(sImg,bOpenBound,sFld1,sFld2,sCallback, 1);
}

function showCalendar(sImg,bOpenBound,sFld1,sFld2,sCallback, type){
	
	window.document.body.onbeforeunload = null;
	document.onclick=hideCalendar;
	var fld1,fld2;
	var cf=document.getElementById("CalFrame");
	var wcf=window.frames.CalFrame;
	var oImg=document.getElementById(sImg);
	sel_id = oImg.id;
	if(!oImg){alert("控制对象不存在！");return;}
	if(!sFld1){alert("输入控件未指定！");return;}
	fld1=document.getElementById(sFld1);
	if(!fld1){alert("输入控件不存在！");return;}
	if(fld1.tagName!="INPUT"){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";
	if (type == 2)
		cf.style.top=(document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH+21:eT-cf.height;
		
	//alert(eH);
	window.frames.CalFrame.openbound=bOpenBound;
	window.frames.CalFrame.fld1=fld1;
	window.frames.CalFrame.fld2=fld2;
	window.frames.CalFrame.callback=sCallback;
	window.frames.CalFrame.initCalendar();
}        
function hideCalendar()
{	
	try {
		if (sel_id != "") {
			if (event.srcElement != null)
				if (event.srcElement.id == sel_id) return;
		}
		sel_id = "";
		hideCalendar_base();
	}catch(err) {
		hideCalendar_base();
	}
}    
function hideCalendar_base()
{
	var cf=document.getElementById("CalFrame");
	cf.style.display="none";

}
