﻿//将日期控件封装成对象，以便统一路径使用图片和静态网页资源 by lich at 2008-04-28
var __jtbCalendar_obj = null;
document.onclick = function()
{
    if ( __jtbCalendar_obj != null ) {
        __jtbCalendar_obj.hideCalendar();
    }
}
function jtbCalendar(path) /*构造函数*/
{
	__jtbCalendar_obj = this;
	this.rootPath =  path + "script";
	this.isFirst = true;

	 document.write("<iframe id=etpassCalFrame name=etpassCalFrame frameborder=0 src='javascript:false' width=0 height=0 style=display:none;position:absolute;z-index:100></iframe>");
	
	this.hideCalendar = function() {
		var cf=document.getElementById("etpassCalFrame");
		if (cf!=null)
			cf.style.display="none";
		var cf1=document.getElementById("divShowDestinationList");
		if (cf1!=null)
			cf1.style.display="none";
		var cf2=document.getElementById("divShowCityListIndex");
		if (cf2!=null)
			cf2.style.display="none";
	}

	this.showCalendar1 = function(sImg,tmpA,fld1,fld2) {
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		cf.src = this.rootPath+"/Calendar1.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst;
		//alert(cf.src);
		
   		while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	
		if(cf.width==0) cf.width = 304 ;
		cf.style.top=((document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH:eT-cf.height)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		
	}
	
	this.showCalendar7 = function(sImg,tmpA,fld1,fld2) {
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		cf.src = this.rootPath+"/Calendar7.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst;
		//alert(cf.src);
		
   		while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	
		if(cf.width==0) cf.width = 304 ;
		cf.style.top=((document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH:eT-cf.height)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		
	}
	
this.showCalendar10 = function(sImg,tmpA,fld1,fld2) {
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = this.rootPath+"/Calendar5.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst;
		//alert(cf.src);
		
   		while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	
		if(cf.width==0) cf.width = 304 ;
		cf.style.top=((document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH:eT-cf.height)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		
	}
this.showCalendar13 = function(sImg,tmpA,fld1,fld2) {
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = this.rootPath+"/Calendar10.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst;
		//alert(cf.src);
		
   		while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	
		if(cf.width==0) cf.width = 304 ;
		cf.style.top=((document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH:eT-cf.height)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		
	}
		
	this.showCalendarClearFirst = function(sImg,tmpA,fld1,fld2) {
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		cf.src = this.rootPath+"/Calendar6.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst;
		//alert(cf.src);
		
   		while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	
		if(cf.width==0) cf.width = 304 ;
		cf.style.top=((document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH:eT-cf.height)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		
	}
	
	this.showCalendarClear = function(sImg,tmpA,fld1,fld2) {
		var cf=document.getElementById("etpassCalFrame");
		//if(cf.style.display=="block" && fld2 == ''){
		//    return;
		//}
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = this.rootPath+"/Calendar4.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst;
		//alert(cf.src);
		
   		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)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(cf.width==0) cf.width = 304 ;
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		//cf.style.display="block";
	}
	
	this.showCalendarClearForIndex = function(sImg,tmpA,fld1,fld2) {
		var cf=document.getElementById("etpassCalFrame");
		//if(cf.style.display=="block" && fld2 == ''){
		//    return;
		//}
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = this.rootPath+"/Calendar8.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst;
		//alert(cf.src);
		
   		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)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(cf.width==0) cf.width = 304 ;
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		//cf.style.display="block";
	}

	this.showCalendar2 = function(sImg,tmpA,fld2,fld1) {
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = this.rootPath+"/Calendar2.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst+"&root="+this.rootPath;
		
		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)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		cf.style.display="block";
	}

	this.showCalendar3 = function(sImg,tmpA,fld2,fld1) {
	
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = cf.src = this.rootPath+"/Calendar3.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst+"&root="+this.rootPath;	
		
		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)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		cf.style.display="block";
	}

	this.showCalendar11 = function(sImg,tmpA,fld2,fld1) {
	
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;
		var four="4";
		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = this.rootPath+"/Calendar11.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst + "&forwardValue=" + four+"&root="+this.rootPath;
		
		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)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		cf.style.display="block";
	}
	
	this.showCalendar14 = function(sImg,tmpA,fld2,fld1) {
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;
		var four="4";
		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = this.rootPath+"/Calendar14.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst + "&forwardValue=" + four+"&root="+this.rootPath;
		
		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)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		cf.style.display="block";
	}

	this.showCalendar12 = function(sImg,tmpA,fld2,fld1) {

		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var four="4";
		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = this.rootPath+"/Calendar12.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst + "&forwardValue=" + four+"&root="+this.rootPath;
		cf.document.getElementById("imgbyprev").src = this.rootPath+"/byprev.gif";
		cf.document.getElementById("imgbynext").src = this.rootPath+"/bynext.gif";
		
		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)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		cf.style.display="block";
	}

	this.showCalendar4 = function(sImg,tmpA,fld2,fld1) {

		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;
		
		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;

		cf.src = this.rootPath+"/Calendar4.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst+"&root="+this.rootPath;	
		
		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)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		cf.style.display="block";
	}

	//lich 用于不显示底部按扭的日期选择 2007-09-14
	this.showCalendar5 = function(sImg,tmpA,fld2,fld1) {
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = this.rootPath+"/Calendar5.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst+"&root="+this.rootPath;	
		
		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)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		cf.style.display="block";
	}

	//给页面用的不是日历控件的函数
	this.getNowDate = function() {
		var nowDate = new Date();
		return parseDateToString(nowDate.getMonth(),nowDate.getDate(),nowDate.getYear());
	}

	this.addDate = function(nowDate, intDay) {
		nowDate.setTime(parseInt(nowDate.getTime()) + 86400000 * intDay);
		return parseDateToString(nowDate.getMonth(), nowDate.getDate(), nowDate.getYear());
	}

	this.parseDateToString = function(gMonth, gDay, gYear) {
		var parseDateToString;
		parseDateToString = fillYear(gYear) + "-" + fillZero(gMonth + 1) + "-" + fillZero(gDay);
		return parseDateToString;
	}

	this.fillZero = function(number) {
		var m_int
		if (number < 10)
			m_int = '0' + number.toString();
		else
			m_int = number.toString();
		return m_int
	}

	this.fillYear = function(year_) {
		var m_year = year_.toString();
		
		if (m_year.length < 4 && m_year.length == 3) {
			return "20" + m_year.substring(m_year.length-2,m_year.length);
		}
		return m_year;
	}
	
	// yjf
	this.showCalendar20 = function(sImg,tmpA,fld1,fld2,first) {
		var cf=document.getElementById("etpassCalFrame");
		var oImg=document.getElementById(sImg);
		var wcf=window.frames.CalFrame;

		var eT=0,eL=0,p=oImg;
		var sT=document.body.scrollTop,sL=document.body.scrollLeft;
		var eH=oImg.height+25,eW=oImg.width;
		
		cf.src = this.rootPath+"/Calendar5.htm?fld1=" + fld1 + "&fld2=" + fld2 + "&this.isFirst=" + this.isFirst + "&first=" + first;
		
   		while(p&&p.tagName!="BODY"){eT+=p.offsetTop;eL+=p.offsetLeft;p=p.offsetParent;}
	
		if(cf.width==0) cf.width = 304 ;
		cf.style.top=((document.body.clientHeight-(eT-sT)-eH>=cf.height)?eT+eH:eT-cf.height)-5;
		cf.style.left=((document.body.clientWidth-(eL-sL)>=cf.width)?eL:eL+eW-cf.width);
		
		if(!oImg){alert("制御対象が存在しません！");return;}
		if(oImg.tagName!="INPUT"||oImg.type!="text"){alert("入力コントロールの種類が間違っています！");return;}
		
	}
}
