﻿// JScript File
var TheYear=new Date().getFullYear(); //定义年的变量的初始值
var TheMonth=new Date().getMonth(); //定义月的变量的初始值


Function.prototype.bind = function(object) 
{
  var m_method = this;
  return function() 
  {
    return m_method.apply(object, arguments);
  }
}

function atoi(a){var i=parseInt(a);return isNaN(i)?0:i;}

var g_calMonthList = null;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 当前 日 期 表，及 选择％％％％％％％％％％％％
function calMonth(m,y,pObj,pxLeft,dtSelected)
{
	this.m_month = m;
	this.m_year = y;
	this.m_pxLeft = pxLeft;
	this.m_domElement = null;

	this.getMonth = function(){return this.m_month;}
	this.getYear = function(){return this.m_year;}
	this.getPxLeft = function(){return this.m_pxLeft;}
	this.getDomElement = function(){return this.m_domElement;}
    
	this.createDomElement = function(m,y,dtSelected)
	{
		var mty=DOW(1,m,y); 
		var c=GetMonthCount(m,y);
		
		// Draw current month?
		var fCur=(y==new Date().getFullYear()&&m==new Date().getMonth());
		
		// Draw selected month?
		var fSel=(dtSelected&&y==dtSelected.getFullYear()&&m==dtSelected.getMonth());
		
		var datesE=document.createElement('div');
		datesE.className="dates";

		var szDays="";
		var dayE=null;
		for(i=0;i<mty;i++) 
		{
			dayE=document.createElement('div');
			dayE.className="invalid";
			datesE.appendChild(dayE);
		}
		for(i=1;i<c+1;i++)
		{
			var d=new Date(y,m,i);
			if((!g_dtMin||d>=g_dtMin)&&(!g_dtMax||d<=g_dtMax)) // Valid date
			{
				var szClass="pointer";
				if(fSel && i==dtSelected.getDate())szClass+=" picked";
				if(fCur && i==new Date().getDate())szClass+=" today";
				
				dayE=document.createElement('div');
				dayE.className=szClass;
				dayE.y = y; dayE.m = m; dayE.i = i;
				dayE.onclick=DtClk;
				dayE.onmousemove=DtHvr;
				dayE.onmouseout=DtExt;
				
				dayE.appendChild(document.createTextNode(i));
				datesE.appendChild(dayE);
			}
			else                                      
			{
				dayE=document.createElement('div');
				dayE.className="invalid";
				dayE.appendChild(document.createTextNode(i));
				datesE.appendChild(dayE);
			}
		}

		var titleE=document.createElement('div');
		titleE.className="title";
		titleE.appendChild(document.createTextNode(FmtTitle(m,y)));
		
		var monthTopE=document.createElement('div');
		monthTopE.className="weekdays_top";

		var weekdaysE=document.createElement('div');
		weekdaysE.className="weekdays";

		for(i=0;i<7;i++)                                       
		{
			var weekdayE=document.createElement('div');
			weekdayE.className="weekday";
			weekdayE.appendChild(document.createTextNode(rW[(i+GetDowStart())%7]));
			weekdaysE.appendChild(weekdayE);
		}

		var monthBodyE=document.createElement('div');
		monthBodyE.className="body";
		monthBodyE.appendChild(weekdaysE);
		monthBodyE.appendChild(datesE);
		
		var monthBotE=document.createElement('div');
		monthBotE.className="bottom";

		var monthE=document.createElement('div');
		monthE.className="month";

		monthE.appendChild(titleE);
		monthE.appendChild(monthTopE);
		monthE.appendChild(monthBodyE);
		monthE.appendChild(monthBotE);

		return monthE;
	}
    
    var verticalDiv = document.createElement('div');

    var tFill=document.createElement('div');    // title fill
    tFill.className="titleFill";
    tFill.style.height=22+"px";//22
    verticalDiv.appendChild(tFill);
    
    var cFill=document.createElement('div');     // calendar fill
    cFill.className="calendarFill";
    cFill.style.height=140+"px";//140
    verticalDiv.appendChild(cFill);

    verticalDiv.style.left=pxLeft - 1+"px";
    verticalDiv.style.position='absolute';
    pObj.appendChild(verticalDiv);

    this.m_domElement = this.createDomElement(this.m_month, this.m_year, dtSelected);
    
    // Position and insert	
	this.m_domElement.style.left = pxLeft+"px";
    pObj.appendChild(this.m_domElement);    //calendar fill 
    
	return this;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 当前 月，日，表，及 选择      end  ％％％％％％％％％％％％	
var g_cMonthSpacing=1;
var g_cMonthWidth=168;  //外宽148
//**************************************************************************月 日表××××××××××××××××××××****************************************
function calMonthList(cM,m,y)
{
	this.m_pxLeft=0;
	this.m_pxLeftShift=g_cMonthWidth+g_cMonthSpacing;
	this.m_cMonths=cM; // ------------------------ visible months
	this.m_rgcalMonths=new Array();
    this.m_bPrev=false;
	this.m_bNext=false;
    this.m_bReady=true;
    this.m_lowIndex=0;
    
	this.getFirstMonth = function(){return (this.m_rgcalMonths&&this.m_rgcalMonths.length>0)?this.m_rgcalMonths[0]:null;}
	this.getLastMonth = function(){return (this.m_rgcalMonths&&this.m_rgcalMonths.length>0)?this.m_rgcalMonths[this.m_rgcalMonths.length-1]:null;}
	
	this.init = function(m,y)
	{
		// Reset what we currently have
		this.m_pxLeft = 0;
		while( getObj("monthlist").childNodes.length ) getObj("monthlist").removeChild(getObj("monthlist").childNodes[0]);
		getObj("monthlist").style.left = this.m_pxLeft+"px";
		getObj("monthlist").style.top = "0px"; // set this so it can be accessed via script

        this.m_bPrev=false;this.m_bNext=false;	
        
		for(var i=0;i<this.m_cMonths;i++)
		{
			this.m_rgcalMonths[i] = new calMonth(m,y,getObj("monthlist"),(i*this.m_pxLeftShift),g_dtPick);
			
			// increment month
			y=y+(m==11?1:0);
			m=(m+1)%12;
		}
    }
	
	this.navPrev = function()
	{   
	    if(this.m_bReady)    this.m_bReady = false;
        else                 return null;	        
	    
		var cM=this.getFirstMonth().getMonth();
		var cY=this.getFirstMonth().getYear();
		var pY=cY-(cM==0?1:0);
		var pM=(cM+11)%12;

		
		var cPxLeft = this.getFirstMonth().getPxLeft();
		var prevMonth = new calMonth(pM,pY,getObj("monthlist"),cPxLeft-this.m_pxLeftShift,g_dtPick);
		
		// ------update and seclect--------------------------
		for(var i=this.m_cMonths-1;i>0;i--) this.m_rgcalMonths[i]=this.m_rgcalMonths[i-1];
		this.m_rgcalMonths[i] = prevMonth;
				
		// Scroll the new month into view
		this.m_pxLeft += this.m_pxLeftShift;
		scrollAction(getObj("monthlist"), null, new position(this.m_pxLeft,null), null);
		this.m_bPrev = true;
    }

	this.navNext = function()
	{    
        if(this.m_bReady)    this.m_bReady = false;
        else                 return null;
	
		var cM=this.getLastMonth().getMonth();
		var cY=this.getLastMonth().getYear();
		var nY=cY+(cM==11?1:0);
		var nM=(cM+1)%12;

		
		var cPxLeft = this.getLastMonth().getPxLeft();
		var nextMonth = new calMonth(nM,nY,getObj("monthlist"),cPxLeft+this.m_pxLeftShift,g_dtPick);
		
		
		for(var i=0;i<this.m_cMonths-1;i++) this.m_rgcalMonths[i]=this.m_rgcalMonths[i+1];
		this.m_rgcalMonths[i] = nextMonth;
		
		// Scroll the new month into view
		this.m_pxLeft -= this.m_pxLeftShift;
		scrollAction(getObj("monthlist"), null, new position(this.m_pxLeft,null), null);
		this.m_bNext = true;
	}
    this.cleanList = function()
    {
        if(this.m_bPrev)
        {
            // remove month & fill
            if(this.m_lowIndex == 0)
            {
                getObj("monthlist").removeChild(getObj("monthlist").childNodes[2]);     
                getObj("monthlist").removeChild(getObj("monthlist").childNodes[2]);
            }
            else
            {   
                getObj("monthlist").removeChild(getObj("monthlist").firstChild);
                getObj("monthlist").removeChild(getObj("monthlist").firstChild);
            }
            this.m_lowIndex = 1;
            this.m_bPrev = false;
        }
        else if(this.m_bNext)
        {
            // remove month & fill
            if(this.m_lowIndex == 0)
            {
                getObj("monthlist").removeChild(getObj("monthlist").firstChild);
                getObj("monthlist").removeChild(getObj("monthlist").firstChild);
            }
            else
            {
                getObj("monthlist").removeChild(getObj("monthlist").childNodes[2]);
                getObj("monthlist").removeChild(getObj("monthlist").childNodes[2]);
            }
            this.m_lowIndex = 0;
            this.m_bNext = false;
        }        
        this.m_bReady = true;
    }
    
	this.init(m,y);
	return this;
}

function handlePrev()
{
	g_calMonthList.navPrev();
	UpdPrev();
	UpdNext();
}

function handleNext()
{
	g_calMonthList.navNext();
	UpdNext();
	UpdPrev();
}

function position(x,y)
{
	this.m_x=x;
	this.m_y=y;

	this.getX=function(){return this.m_x;}
	this.getY=function(){return this.m_y;}

	return this;
}
function scrollAction(domElement,startPos,endPos,duration,iterCount)
{   
	this.m_domElement = domElement;
	this.m_startPos = startPos;
	this.m_endPos = endPos;
	this.m_duration = duration;
	this.m_iterCount = iterCount;
	
	var eL=atoi(this.m_domElement.style.left);
	var eT=atoi(this.m_domElement.style.top);

	// Default startPos to current position
	if(null==this.m_startPos || (null==this.m_startPos.getX() && null==this.m_startPos.getY()))
		this.m_startPos = new position(eL,eT);
	else
	{
		if(null==this.m_startPos.getX()) this.m_startPos = new position(eL,this.m_startPos.getY());
		if(null==this.m_startPos.getY()) this.m_startPos = new position(this.m_startPos.getX(),eT);
	}

	// Default endPos to current position
	if(null==this.m_endPos) 
		this.m_endPos = new position(eL,eT);
	else
	{	
		if(null==this.m_endPos.getX()) this.m_endPos = new position(eL,this.m_endPos.getY());
		if(null==this.m_endPos.getY()) this.m_endPos = new position(this.m_endPos.getX(),eT);
	}
	
	if(null==this.m_duration) this.m_duration = 200;	// Default is 1/5 sec
	if(null==this.m_iterCount) this.m_iterCount = 10;	// Move element 10 times
	
	// Calc pixels/iteration
	this.m_incX = (this.m_endPos.getX()-this.m_startPos.getX())/this.m_iterCount;
	this.m_incY = (this.m_endPos.getY()-this.m_startPos.getY())/this.m_iterCount;
	
	this.nextIter = function()
	{
		this.m_iter++;
		this.m_domElement.style.left = (this.m_startPos.getX()+Math.floor(this.m_iter*this.m_incX))+"px";//
		this.m_domElement.style.top = (this.m_startPos.getY()+Math.floor(this.m_iter*this.m_incY))+"px";
		if(this.m_iter<this.m_iterCount) setTimeout("this.nextIter();",this.m_duration/this.m_iterCount);
		else                             setTimeout("g_calMonthList.cleanList();",this.m_duration/this.m_iterCount);
	}		
	this.m_iter = 0;
	this.nextIter();	
	return this;
}

var cf=null;
var g_fCL=false;
var g_eInp=0;
var g_dtMin,g_dtMax;
var g_dtPick;
var tempyear;
function getObj(objID) 
{
	if(document.getElementById){return document.getElementById(objID);}
	else if(document.all){return document.all[objID];}
	else if(document.layers){return document.layers[objID];}
}
function EvtObj(e){if(!e)e=window.event;return e;} 
function stopBubble(e){e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation();}
function EvtTgt(e)
{
	var el;
	if(e.target)el=e.target;
	else if(e.srcElement)el=e.srcElement;
	if(el.nodeType==3)el=el.parentNode; // defeat Safari bug
	return el;
}

function GetCF(){if (!cf)cf=DE('CalFrame');return cf;}
function DoLoad()
{
	g_fCL=true;
}

function DoCala(eD,eDP,dmin,dmax,cM)//---------------------------(6)-----------------
{	  
	var dt=GetInputDate(eD.value);
	if(null==dt&&null!=eDP){dt=GetInputDate(eDP.value);}
	
	g_dtPick=dt;
	if(dmin&&""==dmin)dmin=null;
	if(dmax&&""==dmax)dmax=null;
	if(null==dt)
	{
		// Check for valid min date and use that, else use current
		dt=new Date();
		if(dmin&&dt<new Date(dmin))dt=new Date(dmin);
	}

	SetMinMax(dmin?new Date(dmin):null,dmax?new Date(dmax):null);
	
	if(null==cM)cM=2; // Default to 2 month display	
   
	UpdCal(cM,dt.getMonth(),dt.getFullYear());

    g_eInp=eD;

    // prevent Mozilla from flickering
	setTimeout("ShowCal()",1);
}

function ShowCal()
{
	if ("none"==GetCF().style.display) {GetCF().style.display="block";}// FF drawing bug
	GetCF().style.visibility="visible";
}

function UpdCal(cM,m1,y1)   // Size the frame 框架大小外观---(7)------主要程序入口-------
{
	var m =m1;
	var y=parseInt(y1);
	var pxSpacing = g_cMonthSpacing*(cM-1);
	getObj("OutBdr").style.width=((g_cMonthWidth*cM)+20+pxSpacing)+"px";
	getObj("InBdr").style.width=((g_cMonthWidth*cM)+pxSpacing)+"px";
	getObj("monthcontainer").style.width=((g_cMonthWidth*cM)+pxSpacing)+"px";
	getObj("NavNext").style.left = ((g_cMonthWidth*cM)+pxSpacing-19)+"px";
	GetCF().style.width=((g_cMonthWidth*cM)+2+pxSpacing)+"px";//底宽
	GetCF().style.height=186+"px";//186底高
 if(TheYear == parseInt(y)) 
	{    
	  g_calMonthList = null;
	  g_calMonthList = new calMonthList(cM,m,y);
    }
	else 
	{   
		  g_calMonthList = null;
	      g_calMonthList = new calMonthList(cM,m,y);
		  document.getElementById("selyear").value = y ;
	}

	UpdNext();
	UpdPrev();
}

function UpdNext()
{
	var currMonth=g_calMonthList.getLastMonth();
	var nm=currMonth.getMonth();
	var ny=currMonth.getYear();
  var currYear = document.getElementById("selyear").value

	var hd=(!g_dtMax||!(ny>g_dtMax.getFullYear()||(ny==g_dtMax.getFullYear()&&parseInt(nm)>=g_dtMax.getMonth())));
	getObj('NImg').style.visibility=hd?"visible":"hidden";

	if(currYear != ny) 
	{
	   document.getElementById("selyear").value =ny
	}
}

function UpdPrev()
{
	var currMonth=g_calMonthList.getFirstMonth();
	var pm=currMonth.getMonth();
	var py=currMonth.getYear();
	
	var hd=(!g_dtMin||!(py<g_dtMin.getFullYear()||(py==g_dtMin.getFullYear()&&parseInt(pm)<=g_dtMin.getMonth())));
	getObj('PImg').style.visibility=hd?"visible":"hidden";
}
function DtHvr(e){EvtTgt(EvtObj(e)).style.backgroundColor="#FFDD99";}//鼠标指向时黄色 
function DtExt(e){EvtTgt(EvtObj(e)).style.backgroundColor="";}//鼠标离开时无色
function DtClk(e)                                             //鼠标单击时 
{
    var element = EvtTgt(EvtObj(e))
    CalDateSet(g_eInp,element.i,element.m+1,element.y);  //时期格式设置
    if(g_eInp.onblur){g_eInp.onblur();}                  //鼠标单击样式－外
    GetCF().style.visibility="hidden";
    SetCalShown(false);
    CalendarCallback();
}
function CloseCal(){                                     //点击close
    if(getObj('CalDiv'))
    {
        CalSetFocus(g_eInp);
        getObj('CalDiv').style.visibility="hidden";
        GetCF().style.visibility="hidden";
        SetCalShown(false);    
    }
    else
    {
        CalSetFocus(g_eInp);
        GetCF().style.visibility="hidden";
        SetCalShown(false);
    }
}
function SetMinMax(n,x){g_dtMin=n;g_dtMax=x;}
function FmtTitle(m,y){return rN[m]+"\u00a0\u00a0"+y.toString()}  
// LOC Comment: Month name.
var rN=new Array(12);rN[0]="1月";rN[1]="2月";rN[2]="3月";rN[3]="4月";rN[4]="5月";rN[5]="6月";rN[6]="7月";rN[7]="8月";rN[8]="9月";rN[9]="10月";rN[10]="11月";rN[11]="12月";
// LOC Comment: Weekday abbrv.
var rW=new Array(7);rW[0]="日";rW[1]="一";rW[2]="二";rW[3]="三";rW[4]="四";rW[5]="五";rW[6]="六";
function DOW(d,m,y){var dt=new Date(y,m,d);return(dt.getDay()+(7-GetDowStart()))%7;}

//******-------------------------------------------------------------------------------------------*******
var pwid = '';
var cwid = '';
var FDate = 'mm/dd/yy';
var TDate = 'mm/dd/yy';
var MDate = '';
var CalS = '';
var CalE = '';
function UpdDt(e,str1,str2) //-----------------add ---- ID----
{    
    switch(e.id)
    {
         case str1:
            var f = DE(str1);
            var t = DE(str2);
            break;
        case "pfd":
            var f = DE('pfd');
            var t = DE('ptd');
            break;
        default:
            var f = null;
            var t = null;
            break;
    }

    if(null!=f&&null!=t&&null!=GetInputDate(f.value)&&(null==GetInputDate(t.value)||GetInputDate(f.value)>GetInputDate(t.value))){t.value=f.value;}    
}
function DE(el){return parent.document.getElementById(el);}
function SC(el,str1,str2)//------------------------------------------------程序入口-------(1)---------add----ID-
{
	if (DE('CalFrame') == null){return;}
	var id = el.id;
	var len = el.id.length
	var len2 = str2.length
	var n = el.id.substr(len); //len=3
	if (id.substr(0,len) == str1) //len指定为3
	{
		el.select();
		if(n == ''){ShowCalendar(el,el,null,CalS,CalE);}
		else if(n == '2'){ShowCalendar(el,el,DE(str1),CalS,CalE);}
		else{ShowCalendar(el,el,DE(str1 + (n - 1)),CalS,CalE);}
	}
	if(str2 == "") 
	{
	    
	}
	else
	{
	   if (id.substr(0,len2) == str2){el.select();ShowCalendar(el,el,DE(str1),CalS,CalE);}
	}
	if (id.substr(0,3) == 'pfd'){el.select();ShowCalendar(el,el,DE(str1),CalS,CalE);}
	if (id.substr(0,3) == 'ptd'){el.select();ShowCalendar(el,el,DE('pfd'),CalS,CalE);}
}
   
//function HCal(event)//杨红旗修改
//{
//	var c = DE('CalFrame');
//	var autodiv = DE('autoBox');
//	var autoiframe = DE('autoTable');
//	if (c!=null){
//	    CancelCal();
//	    if(autodiv != null && autoiframe != null){
//	        var event1 = window.event || event;
//	         
//            var ele = event1.srcElement || event1.target;
//             alert("5");
//            if(ele.id == "autoBox" ){    //|| ele.type=="text"   
//             alert("6");
//                DivSetVisible(true);
//            }else{
//                 alert("7");
//                DivSetVisible(false);
//            }
//	    }  
//    }
//}
//控制日历焦点
//parent.document.onclick = HCal;
function SetFocus(obj)
{
	if(obj)
	{
		if (DE('bIE6') && DE('bIE6').value=='1') 
		{			
			var _focustimer = setInterval(function(){
				DE(obj.id).focus();;
				clearInterval(_focustimer);
			},		
			25);
		}
		else
		{
			DE(obj.id).focus();
		}				
	}		
}
function GetSavedValues()
{   
	GetSavedValuesG();	
    var v;
    v = DE('aFDate').value;if (v != '') {aFDate = v.split('|');}aFDate[0] = FDate;
    switch(cwid)
    {
        case '4':case '5':case '6':
	        v = DE('PFDate').value;if (v != '') {PFDate = v;}
	        v = DE('PTDate').value;if (v != '') {PTDate = v;}
	       
            break;
   
        default:break;
    }    
}

function Rem(el,str1,str2)         //---------------------------------add-------------ID---
{     
  var len =el.id.length
		switch (el.id.substr(0,len))
	{
		case str1:FDate = el.value;FDate.value = FDate;break;
		case str2:TDate = el.value;TDate.value = TDate;break;
		case 'mon':MDate = el.value;MDate.value = MDate;break;
		
	}
    var n = el.id.substr(len);
    if(n == ''){n = 1;}	
	switch(cwid)
	{
        case '1':
	        switch (el.id.substr(0,len))
	        {		        
		        case str1:aFDate[n - 1] = el.value;DE('aFDate').value = aFDate.join('|');FDate = aFDate[0];DE('FDate').value = FDate;break;
		        case 'ftt':aFTime[n - 1] = el.value;DE('aFTime').value = aFTime.join('|');FTime = aFTime[0];DE('FTime').value = FTime;break;        		
		  		        default:break;
	        }        
            break;
        case '4':case '5':
	        switch (el.id.substr(0,3))
	        {
		        case 'pfd':PFDate = el.value;DE('PFDate').value = PFDate;break;
		        case 'ptd':PTDate = el.value;DE('PTDate').value = PTDate;break;
		            
		        default:break;
	        }                 
	        break;      
        default:break;
	}
}//**************-------------------------------------------------******************
function GetDowStart() {return 0;}
function GetDateFmt() {return "yymmdd";}
function GetDateSep() {return "-";}
function ShowCalendar(eP,eD,eDP,dmin,dmax) 
{
	SCal(eP,eD,eDP,dmin,dmax);
}
function ShowCalSimp(fm,eD,eDP,dmin,dmax){
 if(!dmin)dmin='3/1/2005';
 if(!dmax)dmax='1/25/2006';
 if(fm){SetNextFocus(objNext(fm,eD));SetPrevFocus(objPrev(fm,eD));}
 SCal(eD,eD,eDP,dmin,dmax);
}

function getObj(objID)
	{
	if (document.getElementById) {return document.getElementById(objID);}
	else if (document.all) {return document.all[objID];}
	else if (document.layers) {return document.layers[objID];}
	}
function DoNothing() {return false;}
var cF=null;var cW=null;var g_tid=0;var g_cP,g_eD,g_eDP,g_dmin,g_dmax;
var nextFocus;var g_fNoCal=false;

function getEventObj(e){if(!e)e=window.event;return e;}

function stopBubble(e){e=getEventObj(e);e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation();}

function CB(){stopBubble(event);}

function SCal(cP,eD,eDP,dmin,dmax){        //--------------------------------(3)--------------------
 clearTimeout(g_tid);
 if(g_fNoCal){g_fNoCal=false;return;}
	if(g_calShown && eD==g_eD)return;
	g_calShown = true;
	g_calCB = null;
 g_cP=cP;
 g_eD=eD;
 g_eDP=eDP;
 g_dmin=dmin;
 g_dmax=dmax;
 WaitCal();}
function CancelCal(){clearTimeout(g_tid);if(!cF)cF=DE('CalFrame');cF.style.visibility="hidden";SetCalShown(false);g_calShown=false;}
function WaitCal()//-------------------------------------------(4)-----------------
{ 
 if(!cW)cW=parent.frames['CalFrame'];

 if(null==cW||null==g_fCL||false==g_fCL){//cW.g_fCL 
	g_tid=setTimeout("WaitCal()", 200);
	}
 else{
 if(!cF)cF=DE('CalFrame');
	cF.style.visibility="hidden";
	SetCalShown(false);
	
	setTimeout("DoCal()",1);
	}
}
function DoCal()//-----------------------------------(5)----------------------
{
PosCal(g_cP);
if(!cW)cW=parent.frames['CalFrame'];
DoCala(g_eD,g_eDP,g_dmin,g_dmax);
}

function getScrollTop()
{
	if(parent.document.documentElement.scrollTop) return parent.document.documentElement.scrollTop;
	if(parent.document.body.scrollTop) return parent.document.body.scrollTop;
	if(window.parent.pageYOffset) return window.parent.pageYOffset;
	return 0;
}

function getWinHeight()
{
	if(window.parent.innerHeight) return window.parent.innerHeight;
	if(parent.document.documentElement.clientHeight) return parent.document.documentElement.clientHeight;
	if(parent.document.body.clientHeight) return parent.document.body.clientHeight;
	return 0;
}

function PosCal(cP)
{
	var dB=parent.document.body;var eL=0;var eT=0;
 if(!cF)cF=DE('CalFrame');
	for(var p=cP;p&&p.tagName!='BODY';p=p.offsetParent){eL+=p.offsetLeft;eT+=p.offsetTop;}
	var eH=cP.offsetHeight;var dH=parseInt(cF.style.height);var sT=getScrollTop();
	if(eT-dH>=sT&&eT+eH+dH>getWinHeight()+sT)eT-=dH;else eT+=eH;
	cF.style.left=eL+'px';cF.style.top=eT+'px';
}

function SetNextFocus(e){nextFocus=e;if(nextFocus)nextFocus.onfocus=CancelCal;}
function SetPrevFocus(e){if(e)e.onfocus=CancelCal;}

function FGoNextFocus(){if(nextFocus){nextFocus.focus();return true;}return false;}

function CalSetFocus(e){if(e){g_fNoCal=true;e.focus();setTimeout("EndCalFocus()", 200);}}
function EndCalFocus(){g_fNoCal=false;}

function CalDateSet(eInp,d,m,y,giveFocus)//时期格式设置
{
	var ds=GetDateSep();
	var fmt=GetDateFmt();

	if(fmt=="mmddyy")eInp.value=m+ds+d+ds+y;
	else if(fmt=="ddmmyy")eInp.value=d+ds+m+ds+y;
	else eInp.value=y+ds+m+ds+d;
	if(!giveFocus)
	CalSetFocus(eInp);
}

var g_calShown = false;
function SetCalShown(fcshown){g_calShown=fcshown;}

var g_calCB;
function CalendarCallback(){if(g_calCB)g_calCB();}
function SetCalendarCallback(cb){g_calCB=cb;}
function GetInputDate(t)
{
	if(!t.length) return null;
	t=t.replace(/\s+/g,"");
	if(t.match(/[^-|\d|\.|\/]/)) return null;
	var rgt=t.split(/-|\.|\//);
	for(var i=0;i<rgt.length;i++) rgt[i]=parseInt(rgt[i],10);
	if(!rgt[1]) return null;
	var m,d,y;
	var fmt=GetDateFmt();
	if(fmt=="yymmdd")
	{
	if(!rgt[2]) return null;
	m=rgt[1];d=rgt[2];y=rgt[0];
	}
	else
	{
	if(fmt=="mmddyy"){m=rgt[0];d=rgt[1];}
	else{m=rgt[1];d=rgt[0];}//fmt=="ddmmyy"
	if(rgt[2])y=rgt[2];
	else y=DefYr(m-1,d);
	}
	m-=1;if(y<100)y+=2000;
	if(y<1601||y>4500||m<0||m>11||d<1||d>GetMonthCount(m,y))return null;
	return new Date(y,m,d);
}

var rM=new Array(12);rM[0]=rM[2]=rM[4]=rM[6]=rM[7]=rM[9]=rM[11]=31;rM[3]=rM[5]=rM[8]=rM[10]=30;rM[1]=28; //----每月的固定天数----1.3.5.7.8.10.12.(31) 
function GetMonthCount(m,y) //-----------------------获取指定年月的天数-----------
{var c=rM[m];if((1==m)&&IsLY(y))c++;return c;}
function IsLY(y)//---------------------------------判断是否为运年---------
{if(0==y%4&&((y%100!=0)||(y%400==0)))return true;else return false;}
function DefYr(m,d)
{var dt=new Date();var yC=(dt.getYear()<1000)?1900+dt.getYear():dt.getYear();if(m<dt.getMonth()||(m==dt.getMonth()&&d<dt.getDate()))yC++;return yC;}

