﻿
	var __popcal4js_language = 'en';	
	var __popcal4js_enablePast = 0;
	var __popcal4js_fixedX = -1;
	var __popcal4js_fixedY = -1;
	var __popcal4js_startAt = 1;
	var __popcal4js_showWeekNumber = 0;	
	var __popcal4js_showToday = 1;
	var __popcal4js_imgDir = 'images/';	

	var __popcal4js_gotoString = {
		en : 'Current Date',
		cn : '当前日期'
	};
	var __popcal4js_todayString = {
		en : 'Today: ',
		cn : '今天：'
	};
	var __popcal4js_weekString = {
		en : 'W',
		cn : '周'
	};
	var __popcal4js_timeString = {
		en : 'Time: ',
		cn : '时间：'
	};
	var __popcal4js_scrollLeftMessage = {
		en : 'Last Month',
		cn : '上月'
	};
	var __popcal4js_scrollRightMessage = {
		en : 'Next Month',
		cn : '下月'
	};
	var __popcal4js_selectMonthMessage = {
		en : 'Select Month.',
		cn : '选择月份.'
	};
	var __popcal4js_selectYearMessage = {
		en : 'Select Year.',
		cn : '选择年份.'
	};
	var __popcal4js_selectDateMessage = {
		en : 'Go',
		cn : 'Go'
	};
	var	__popcal4js_monthName = {
		en : new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'),
		cn : new Array('1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月')
	};
	var	__popcal4js_monthName2 = {
		en : new Array('1','2','3','4','5','6','7','8','9','10','11','12'),
		cn : new Array('1','2','3','4','5','6','7','8','9','10','11','12')
	};
  var __popcal4js_dayNameTmp = {
	  en : new Array('Sun','Mon','Tue','Wed','Thu','Fir','Sat'),
		cn : new Array('日','一','二','三','四','五','六')
	};
	var __popcal4js_dayNameAllTmp = {
		en : new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Firday','Saturday'),
		cn : new Array('星期日','星期一','星期二','星期三','星期四','星期五','星期六')
	};
  var __popcal4js_dayName = {
	  en : new Array('','','','','','',''),
		cn : new Array('','','','','','','')
	};
	var __popcal4js_dayNameAll = {
		en : new Array('','','','','','',''),
		cn : new Array('','','','','','','')
	};
	var __popcal4js_dayNameIndex = 0;
	while(__popcal4js_dayNameIndex<7)
	{
		var __popcal4js_dayNameIndexTmp = __popcal4js_dayNameIndex+__popcal4js_startAt;
		if(__popcal4js_dayNameIndexTmp>6)
		{
			__popcal4js_dayNameIndexTmp = __popcal4js_dayNameIndexTmp-7;
		}
		__popcal4js_dayName['en'][__popcal4js_dayNameIndex] = __popcal4js_dayNameTmp['en'][__popcal4js_dayNameIndexTmp];
		__popcal4js_dayName['cn'][__popcal4js_dayNameIndex] = __popcal4js_dayNameTmp['cn'][__popcal4js_dayNameIndexTmp];
		__popcal4js_dayNameAll['en'][__popcal4js_dayNameIndex] = __popcal4js_dayNameAllTmp['en'][__popcal4js_dayNameIndexTmp];
		__popcal4js_dayNameAll['cn'][__popcal4js_dayNameIndex] = __popcal4js_dayNameAllTmp['cn'][__popcal4js_dayNameIndexTmp];
		__popcal4js_dayNameIndex++;
	}

	var __popcal4js_crossobj, __popcal4js_crossMonthObj, __popcal4js_crossYearObj;
	var __popcal4js_monthSelected, __popcal4js_yearSelected, __popcal4js_dateSelected;
	var __popcal4js_omonthSelected, __popcal4js_oyearSelected, __popcal4js_odateSelected;
	var __popcal4js_monthConstructed, __popcal4js_yearConstructed;
	var __popcal4js_intervalID1, __popcal4js_intervalID2, __popcal4js_timeoutID1, __popcal4js_timeoutID2;
	var __popcal4js_ctlToPlaceValue, __popcal4js_ctlNow, __popcal4js_dateFormat, __popcal4js_nStartingYear, __popcal4js_selDayAction, __popcal4js_isPast;
	var __popcal4js_visYear  = 0;
	var __popcal4js_visMonth = 0;
	var __popcal4js_bPageLoaded = false;
	var __popcal4js_ie  = document.all;
	var __popcal4js_dom = document.getElementById;
	var __popcal4js_ns4 = document.layers;
	var __popcal4js_today    = new Date();
	var __popcal4js_dateNow  = __popcal4js_today.getDate();
	var __popcal4js_monthNow = __popcal4js_today.getMonth();
	var __popcal4js_yearNow  = __popcal4js_today.getYear();
	var __popcal4js_timeNow  = 	__popcal4js_today.getHours() + ":" + __popcal4js_today.getMinutes() +":" + __popcal4js_today.getSeconds();
	var __popcal4js_imgsrc   = new Array('popcal4js_drop1.gif','popcal4js_drop2.gif','popcal4js_left1.gif','popcal4js_left2.gif','popcal4js_right1.gif','popcal4js_right2.gif');
	var __popcal4js_img      = new Array();
	var __popcal4js_bShow    = false;

	function hideElement_popcal4js( elmID, overDiv ) {
		if(__popcal4js_ie) {
			for(i = 0; i < document.all.tags( elmID ).length; i++) {
				obj = document.all.tags( elmID )[i];
				if(!obj || !obj.offsetParent) continue;

				// Find the element's offsetTop and offsetLeft relative to the BODY tag.
				objLeft   = obj.offsetLeft;
				objTop    = obj.offsetTop;
				objParent = obj.offsetParent;

				while(objParent.tagName.toUpperCase() != 'BODY' && objParent.tagName.toUpperCase() != 'HTML') {
					objLeft  += objParent.offsetLeft;
					objTop   += objParent.offsetTop;
					objParent = objParent.offsetParent;
				}

				objHeight = obj.offsetHeight;
				objWidth  = obj.offsetWidth;

				if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
				else if((overDiv.offsetTop + overDiv.offsetHeight) <= objTop);
				/* CHANGE by Charlie Roche for nested TDs*/
				else if(overDiv.offsetTop >= (objTop + objHeight + obj.height));
				/* END CHANGE */
				else if(overDiv.offsetLeft >= (objLeft + objWidth));
				else {
					obj.style.visibility = 'hidden';
				}
			}
		}
	}

	function showElement_popcal4js(elmID) {
		if(__popcal4js_ie) {
			for(i = 0; i < document.all.tags( elmID ).length; i++) {
				obj = document.all.tags(elmID)[i];
				if(!obj || !obj.offsetParent) continue;
				obj.style.visibility = '';
			}
		}
	}

	function HolidayRec_popcal4js (d, m, y, desc) {
		this.d = d;
		this.m = m;
		this.y = y;
		this.desc = desc;
	}

	var __popcal4js_HolidaysCounter = 0;
	var __popcal4js_Holidays = new Array();

	function addHoliday_popcal4js (d, m, y, desc) {
		__popcal4js_Holidays[__popcal4js_HolidaysCounter++] = new HolidayRec_popcal4js (d, m, y, desc);
	}

  function startCalendar_popcal4js(imgDir)
  {
  	document.write("<style>");
  	document.write(".popcal4js_onDate{line-height:15px;height:12px;verdana;font-size:12px;}");
  	document.write(".popcal4js_onDate:link,.popcal4js_onDate:visited,.popcal4js_onDate:active{line-height:15px;height:12px;verdana;font-size:12px;}");
		document.write(".popcal4js_onDate:hover{background:#00ff00;line-height:15px;height:12px;verdana;font-size:12px;");
  	document.write("</style>");
  	
  	if(imgDir != null) __popcal4js_imgDir = imgDir;
  	
		if (__popcal4js_dom) {
			for	(i=0;i<__popcal4js_imgsrc.length;i++) {
				__popcal4js_img[i] = new Image;
				__popcal4js_img[i].src = __popcal4js_imgDir + __popcal4js_imgsrc[i];
			}
			// iframe
			document.write ('<div id="__popcal4js_calendar_iframe" style="z-index:+998;position:absolute;visibility:hidden;"></div>');
			
			document.write ('<div onclick="__popcal4js_bShow=true" id="__popcal4js_calendar" style="z-index:+999;position:absolute;visibility:hidden;left:100px; top:100px;"><table width="'+((__popcal4js_showWeekNumber==1)?250:220)+'" style="font-family:ms shell dlg;font-size:12px;border: 1px solid #A0A0A0;" bgcolor="#ffffff"><tr style="background:#000066;"><td style="background:#000066;line-height:15px;height:12px;font-family:verdana;font-size:12px;"><table width="'+((__popcal4js_showWeekNumber==1)?248:218)+'"><tr><td style="padding:2px;font-family:ms shell dlg;font-size:12px;line-height:15px;height:12px;font-family:verdana;font-size:12px;background:#000066;"><font color="#ffffff' + '' /*C9D3E9*/ +'"><b><span id="__popcal4js_caption"></span></b></font></td><td align="right" style="background:#000066;line-height:15px;height:12px;font-family:verdana;font-size:12px;"><a href="javascript:hideCalendar_popcal4js()"><img src="'+__popcal4js_imgDir+'popcal4js_close.gif" width="15" height="13" border="0" /></a></td></tr></table></td></tr><tr><td style="padding:5px;line-height:15px;height:12px;font-family:verdana;font-size:12px;" bgcolor="#ffffff"><span id="__popcal4js_content"></span></td></tr>');
				if (__popcal4js_showToday == 1) {
				document.write ('<tr bgcolor="#f0f0f0"><td style="background:#f0f0f0;padding:5px;line-height:15px;height:12px;font-family:verdana;font-size:12px;" align="center"><span id="__popcal4js_lblToday"></span></td></tr>');
			}
			document.write ('</table></div><div id="__popcal4js_selectMonth" style="z-index:+999;position:absolute;visibility:hidden;"></div><div id="__popcal4js_selectYear" style="z-index:+999;position:absolute;visibility:hidden;"></div>');
		} 	
  }

	var	__popcal4js_styleAnchor = 'text-decoration:none;color:black;line-height:15px;height:12px;verdana;font-size:12px;';
	var	__popcal4js_styleLightBorder = 'border:1px solid #a0a0a0;';

	function swapImage_popcal4js(srcImg, destImg) {
		if (__popcal4js_ie) document.getElementById(srcImg).setAttribute('src',__popcal4js_imgDir + destImg);
	}

	function init_popcal4js() {
		if (!__popcal4js_ns4)
		{
			if (!__popcal4js_ie) __popcal4js_yearNow += 1900;

			__popcal4js_crossobj=(__popcal4js_dom)?document.getElementById('__popcal4js_calendar').style : __popcal4js_ie? document.all.__popcal4js_calendar : document.__popcal4js_calendar;
			hideCalendar_popcal4js();

			__popcal4js_crossMonthObj = (__popcal4js_dom) ? document.getElementById('__popcal4js_selectMonth').style : __popcal4js_ie ? document.all.__popcal4js_selectMonth : document.__popcal4js_selectMonth;

			__popcal4js_crossYearObj = (__popcal4js_dom) ? document.getElementById('__popcal4js_selectYear').style : __popcal4js_ie ? document.all.__popcal4js_selectYear : document.__popcal4js_selectYear;

			__popcal4js_monthConstructed = false;
			__popcal4js_yearConstructed = false;

			sHTML1 = '<span id="__popcal4js_spanLeft" style="border:1px solid #36f;cursor:pointer"  onclick="decMonth_popcal4js()"  onmousedown="clearTimeout(__popcal4js_timeoutID1);__popcal4js_timeoutID1=setTimeout(\'StartDecMonth_popcal4js()\',500)" onmouseup="clearTimeout(__popcal4js_timeoutID1);clearInterval(__popcal4js_intervalID1)">&nbsp<img id="__popcal4js_changeLeft" src="'+__popcal4js_imgDir+'popcal4js_left1.gif" width="10" height="11" border="0">&nbsp</span>&nbsp;';
			sHTML1 += '<span id="__popcal4js_spanRight" style="border:1px solid #36f;cursor:pointer"  onclick="incMonth_popcal4js()" onmousedown="clearTimeout(__popcal4js_timeoutID1);__popcal4js_timeoutID1=setTimeout(\'StartIncMonth_popcal4js()\',500)" onmouseup="clearTimeout(__popcal4js_timeoutID1);clearInterval(__popcal4js_intervalID1)">&nbsp<img id="__popcal4js_changeRight" src="'+__popcal4js_imgDir+'popcal4js_right1.gif" width="10" height="11" border="0">&nbsp</span>&nbsp;';
			sHTML1 += '<span id="__popcal4js_spanMonth" style="border:1px solid #36f;cursor:pointer"  onclick="popUpMonth_popcal4js()"></span>&nbsp;';
			sHTML1 += '<span id="__popcal4js_spanYear" style="border:1px solid #36f;cursor:pointer"  onclick="popUpYear_popcal4js()"></span>&nbsp;';

			document.getElementById('__popcal4js_caption').innerHTML = sHTML1;

			__popcal4js_bPageLoaded=true;
		}
	}

	function hideCalendar_popcal4js() {
		__popcal4js_crossobj.visibility = 'hidden';
		if (__popcal4js_crossMonthObj != null) __popcal4js_crossMonthObj.visibility = 'hidden';
		if (__popcal4js_crossYearObj  != null) __popcal4js_crossYearObj.visibility = 'hidden';
		showElement_popcal4js('SELECT');
		showElement_popcal4js('APPLET');
		
		// iframe
		document.getElementById("__popcal4js_calendar_iframe").innerHTML = '';
		document.getElementById("__popcal4js_calendar_iframe").style.visibility = 'hidden';
	}

	function padZero_popcal4js(num) {
		return (num	< 10) ? '0' + num : num;
	}

	function constructDate_popcal4js(d,m,y, t) {
		sTmp = __popcal4js_dateFormat;
		sTmp = sTmp.replace ('dd','<e>');
		sTmp = sTmp.replace ('d','<d>');
		sTmp = sTmp.replace ('<e>',padZero_popcal4js(d));
		sTmp = sTmp.replace ('<d>',d);
		sTmp = sTmp.replace ('mmmm','<p>');
		sTmp = sTmp.replace ('mmm','<o>');
		sTmp = sTmp.replace ('mm','<n>');
		sTmp = sTmp.replace ('m','<m>');
		sTmp = sTmp.replace ('<m>',m+1);
		sTmp = sTmp.replace ('<n>',padZero_popcal4js(m+1));
		sTmp = sTmp.replace ('<o>',__popcal4js_monthName[__popcal4js_language][m]);
		sTmp = sTmp.replace ('<p>',__popcal4js_monthName2[__popcal4js_language][m]);
		sTmp = sTmp.replace ('yyyy',y);
		sTmp = sTmp.replace ('yy',padZero_popcal4js(y%100));
		sTmp = sTmp.replace ('tt',t);
		return sTmp;
		
	}

	function closeCalendar_popcal4js() {
		var tt = "";
		if (__popcal4js_dateFormat.indexOf("tt") >= 0) {
		  tt = document.getElementById('__popcal4js_txtNowTime').value;	
		}
		
		hideCalendar_popcal4js();

		__popcal4js_ctlToPlaceValue.value = constructDate_popcal4js(__popcal4js_dateSelected,__popcal4js_monthSelected,__popcal4js_yearSelected, tt );
	}

	/*** Month Pulldown	***/
	function StartDecMonth_popcal4js() {
		__popcal4js_intervalID1 = setInterval("decMonth_popcal4js()",80);
	}

	function StartIncMonth_popcal4js() {
		__popcal4js_intervalID1 = setInterval("incMonth_popcal4js()",80);
	}

	function incMonth_popcal4js () {
		__popcal4js_monthSelected++;
		if (__popcal4js_monthSelected > 11) {
			__popcal4js_monthSelected = 0;
			__popcal4js_yearSelected++;
		}
		constructCalendar_popcal4js();
	}

	function decMonth_popcal4js () {
		__popcal4js_monthSelected--;
		if (__popcal4js_monthSelected < 0) {
			__popcal4js_monthSelected = 11;
			__popcal4js_yearSelected--;
		}
		constructCalendar_popcal4js();
	}

	function constructMonth_popcal4js() {
		popDownYear_popcal4js()
		if (!__popcal4js_monthConstructed) {
			sHTML = "";
			for (i=0; i<12; i++) {
				sName = __popcal4js_monthName[__popcal4js_language][i];
				if (i == __popcal4js_monthSelected){
					sName = '<b>' + sName + '</b>';
				}
				sHTML += '<tr><td id="__popcal4js_m' + i + '"  style="background:#f0f0f0;cursor:pointer;line-height:15px;height:12px;font-family:verdana;font-size:12px;" onclick="__popcal4js_monthConstructed=false;__popcal4js_monthSelected=' + i + ';constructCalendar_popcal4js();popDownMonth_popcal4js();event.cancelBubble=true"><font color="#000066">&nbsp;' + sName + '&nbsp;</font></td></tr>';
			}

			document.getElementById('__popcal4js_selectMonth').innerHTML = '<table width="70" style="font-family:ms shell dlg;font-size:12px;border:1px solid #a0a0a0;background:#f0f0f0;" bgcolor="#f0f0f0" cellspacing="0" >' + sHTML + '</table>';

			__popcal4js_monthConstructed = true;
		}
	}

	function popUpMonth_popcal4js() {
		if (__popcal4js_visMonth == 1) {
			popDownMonth_popcal4js();
			__popcal4js_visMonth--;
		} else {
			constructMonth_popcal4js();
			__popcal4js_crossMonthObj.visibility = (__popcal4js_dom||__popcal4js_ie) ? 'visible' : 'show';
			__popcal4js_crossMonthObj.left = parseInt(__popcal4js_crossobj.left) + 50 + "px";
			__popcal4js_crossMonthObj.top =	parseInt(__popcal4js_crossobj.top) + 26 + "px";
			var browser = new Browser_popcal4js();
			if(browser.isIE && browser.version<7)//在ie6及以下版本隐藏select和增加ifreame
			{
				hideElement_popcal4js('SELECT', document.getElementById('__popcal4js_selectMonth'));
			}
			hideElement_popcal4js('APPLET', document.getElementById('__popcal4js_selectMonth'));
			__popcal4js_visMonth++;
		}
	}

	function popDownMonth_popcal4js() {
		__popcal4js_crossMonthObj.visibility = 'hidden';
		__popcal4js_visMonth = 0;
	}

	/*** Year Pulldown ***/
	function incYear_popcal4js() {
		for	(i=0; i<7; i++) {
			newYear	= (i + __popcal4js_nStartingYear) + 1;
			if (newYear == __popcal4js_yearSelected)
				txtYear = '<font style="color:#006;font-weight:bold;">&nbsp;' + newYear + '&nbsp;</font>';
			else
				txtYear = '<font style="color:#006;">&nbsp;' + newYear + '&nbsp;</font>';
			document.getElementById('__popcal4js_y'+i).innerHTML = txtYear;
		}
		__popcal4js_nStartingYear++;
		__popcal4js_bShow=true;
	}

	function decYear_popcal4js() {

		for	(i=0; i<7; i++) {
			newYear = (i + __popcal4js_nStartingYear) - 1;
			if (newYear == __popcal4js_yearSelected)
				txtYear = '<font style="color:#006;font-weight:bold">&nbsp;' + newYear + '&nbsp;</font>';
			else
				txtYear = '<font style="color:#006;">&nbsp;' + newYear + '&nbsp;</font>';
			document.getElementById('__popcal4js_y'+i).innerHTML = txtYear;
		}

		__popcal4js_nStartingYear--;
		__popcal4js_bShow=true;
	}

	function selectYear_popcal4js(nYear) {
		__popcal4js_yearSelected = parseInt(nYear + __popcal4js_nStartingYear);
		__popcal4js_yearConstructed = false;
		constructCalendar_popcal4js();
		popDownYear_popcal4js();
	}

	function constructYear_popcal4js() {
		popDownMonth_popcal4js();
		sHTML = '';
		if (!__popcal4js_yearConstructed) {
			sHTML = '<tr><td align="center" style="background:#f0f0f0;cursor:pointer;line-height:15px;height:12px;font-family:verdana;font-size:12px;" onmousedown="clearInterval(__popcal4js_intervalID1);__popcal4js_intervalID1=setInterval(\'decYear_popcal4js()\',30);" onmouseup="clearInterval(__popcal4js_intervalID1)"><font color="#000066">-</font></td></tr>';

			j = 0;
			__popcal4js_nStartingYear =	__popcal4js_yearSelected - 3;
			for ( i = (__popcal4js_yearSelected-3); i <= (__popcal4js_yearSelected+3); i++ ) {
				sName = i;
				if (i == __popcal4js_yearSelected) sName = '<b>' + sName + '</b>';
				sHTML += '<tr><td height="25" id="__popcal4js_y' + j + '"  style="background:#f0f0f0;cursor:pointer;line-height:15px;height:12px;font-family:verdana;font-size:12px;" onclick="selectYear_popcal4js('+j+');event.cancelBubble=true"><font color="#000066">&nbsp;' + sName + '&nbsp;</font></td></tr>';
				j++;
			}

			sHTML += '<tr><td height="25" align="center" style="background:#f0f0f0;cursor:pointer;line-height:15px;height:12px;font-family:verdana;font-size:12px;" onmousedown="clearInterval(__popcal4js_intervalID2);__popcal4js_intervalID2=setInterval(\'incYear_popcal4js()\',30);" onmouseup="clearInterval(__popcal4js_intervalID2)"><font color="#000066">+</font></td></tr>';

			document.getElementById('__popcal4js_selectYear').innerHTML = '<table width="44" cellspacing="0" bgcolor="#f0f0f0" style="font-family:ms shell dlg;font-size:12px;border:1px solid #a0a0a0;" >' + sHTML + '</table>';

			__popcal4js_yearConstructed = true;
		}
	}

	function popDownYear_popcal4js() {
		clearInterval(__popcal4js_intervalID1);
		clearTimeout(__popcal4js_timeoutID1);
		clearInterval(__popcal4js_intervalID2);
		clearTimeout(__popcal4js_timeoutID2);
		__popcal4js_crossYearObj.visibility= 'hidden';
		__popcal4js_visYear = 0;
	}

	function popUpYear_popcal4js() {
		var leftOffset
		if (__popcal4js_visYear==1) {
			popDownYear_popcal4js();
			__popcal4js_visYear--;
		} else {
			constructYear_popcal4js();
			__popcal4js_crossYearObj.visibility	= (__popcal4js_dom||__popcal4js_ie) ? 'visible' : 'show';
			leftOffset = parseInt(__popcal4js_crossobj.left) + document.getElementById('__popcal4js_spanYear').offsetLeft;
			if (__popcal4js_ie) leftOffset += 6;
			__popcal4js_crossYearObj.left = leftOffset + "px";
			__popcal4js_crossYearObj.top = parseInt(__popcal4js_crossobj.top) + 26 + "px";
			__popcal4js_visYear++;
		}
	}

	/*** calendar ***/
	function WeekNbr_popcal4js(n) {
		// Algorithm used:
		// From Klaus Tondering's Calendar document (The Authority/Guru)
		// http://www.tondering.dk/claus/calendar.html
		// a = (14-month) / 12
		// y = year + 4800 - a
		// m = month + 12a - 3
		// J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045
		// d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461
		// L = d4 / 1460
		// d1 = ((d4 - L) mod 365) + L
		// WeekNumber = d1 / 7 + 1

		year = n.getFullYear();
		month = n.getMonth() + 1;
		if (__popcal4js_startAt == 0) {
			day = n.getDate() + 1;
		} else {
			day = n.getDate();
		}

		a = Math.floor((14-month) / 12);
		y = year + 4800 - a;
		m = month + 12 * a - 3;
		b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
		J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
		d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
		L = Math.floor(d4 / 1460);
		d1 = ((d4 - L) % 365) + L;
		week = Math.floor(d1/7) + 1;

		return week;
	}

	function constructCalendar_popcal4js () {
		var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31);
		var dateMessage;
		var startDate = new Date (__popcal4js_yearSelected,__popcal4js_monthSelected,1);
		var endDate;

		if (__popcal4js_monthSelected==1) {
			endDate = new Date (__popcal4js_yearSelected,__popcal4js_monthSelected+1,1);
			endDate = new Date (endDate - (24*60*60*1000));
			numDaysInMonth = endDate.getDate();
		} else {
			numDaysInMonth = aNumDays[__popcal4js_monthSelected];
		}

		datePointer = 0;
		dayPointer = startDate.getDay() - __popcal4js_startAt;
		
		if (dayPointer<0) dayPointer = 6;

		sHTML = '<table border="0" cellSpacing="0" cellPadding="1" width="100%" style="font-family:verdana;font-size:12px;"><tr>';

		if (__popcal4js_showWeekNumber == 1) {
			sHTML += '<td width="27" style="line-height:15px;height:12px;font-family:verdana;font-size:12px;"><b>' + __popcal4js_weekString[__popcal4js_language] + '</b></td><td width="1" rowspan="7" bgcolor="#d0d0d0" style="padding:0px;line-height:15px;height:12px;font-family:verdana;font-size:12px;"><img src="'+__popcal4js_imgDir+'divider.gif" width="1"></td>';
		}

		for (i = 0; i<7; i++) {
			sHTML += '<td width="27" align="right" style="line-height:15px;height:12px;font-family:verdana;font-size:12px;"><b><font color="#000066">' + __popcal4js_dayName[__popcal4js_language][i] + '</font></b></td>';
		}

		sHTML += '</tr><tr>';
		
		if (__popcal4js_showWeekNumber == 1) {
			sHTML += '<td align="right" style="line-height:15px;height:12px;font-family:verdana;font-size:12px;">' + WeekNbr_popcal4js(startDate) + '&nbsp;</td>';
		}

		for	( var i=1; i<=dayPointer;i++ ) {
			sHTML += '<td style="line-height:15px;height:12px;font-family:verdana;font-size:12px;">&nbsp;</td>';
		}
	
		for	( datePointer=1; datePointer <= numDaysInMonth; datePointer++ ) {
			dayPointer++;
			sHTML += '<td align="right" style="line-height:15px;height:12px;font-family:verdana;font-size:12px;">';
			
			var sStyle=__popcal4js_styleAnchor;
			var sClass = 'popcal4js_onDate';
			if ((datePointer == __popcal4js_odateSelected) && (__popcal4js_monthSelected == __popcal4js_omonthSelected) && (__popcal4js_yearSelected == __popcal4js_oyearSelected))
			{ 
				sStyle+=__popcal4js_styleLightBorder;
				sClass = 'popcal4js_onDate';
			}

			sHint = '';
			for (k = 0;k < __popcal4js_HolidaysCounter; k++) {
				if ((parseInt(__popcal4js_Holidays[k].d) == datePointer)&&(parseInt(__popcal4js_Holidays[k].m) == (__popcal4js_monthSelected+1))) {
					if ((parseInt(__popcal4js_Holidays[k].y)==0)||((parseInt(__popcal4js_Holidays[k].y)==__popcal4js_yearSelected)&&(parseInt(__popcal4js_Holidays[k].y)!=0))) {
						sStyle+= 'background-color:#fdd;';
						sHint += sHint=="" ? __popcal4js_Holidays[k].desc : "\n"+__popcal4js_Holidays[k].desc;
					}
				}
			}

			sHint = sHint.replace('/\"/g', '&quot;');

			dateMessage = 'onmousemove="window.status=\''+__popcal4js_selectDateMessage[__popcal4js_language].replace('[date]',constructDate_popcal4js(datePointer,__popcal4js_monthSelected,__popcal4js_yearSelected, __popcal4js_timeNow))+'\'" onmouseout="window.status=\'\'" ';
			
			if (__popcal4js_enablePast == 0 && ((__popcal4js_yearSelected < __popcal4js_yearNow) || (__popcal4js_monthSelected < __popcal4js_monthNow) && (__popcal4js_yearSelected == __popcal4js_yearNow) || (datePointer < __popcal4js_dateNow) && (__popcal4js_monthSelected == __popcal4js_monthNow) && (__popcal4js_yearSelected == __popcal4js_yearNow))) {
				//__popcal4js_selDayAction = '';
				__popcal4js_selDayAction = 'href="javascript:__popcal4js_dateSelected=' + datePointer + ';closeCalendar_popcal4js();"';
				__popcal4js_isPast = 1;
			} else {
				__popcal4js_selDayAction = 'href="javascript:__popcal4js_dateSelected=' + datePointer + ';closeCalendar_popcal4js();"';
				__popcal4js_isPast = 0;
			}

			if ((datePointer == __popcal4js_dateNow) && (__popcal4js_monthSelected == __popcal4js_monthNow) && (__popcal4js_yearSelected == __popcal4js_yearNow)) {	///// today
				sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+";color:#ff0000;font-weight:bold;' class='"+sClass+"' "+__popcal4js_selDayAction+">&nbsp;" + datePointer + "&nbsp;</a>";
			} else if (dayPointer % 7 == (__popcal4js_startAt * -1)+1) {									///// SI ES DOMINGO
				if (__popcal4js_isPast==1)
					sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' class='"+sClass+"' "+__popcal4js_selDayAction+">&nbsp;<font color=#909090 style='font-family:verdana;font-size:12px;'>" + datePointer + "</font>&nbsp;</a>";
				else
					sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' class='"+sClass+"' "+__popcal4js_selDayAction+">&nbsp;<font color=#ff3535>" + datePointer + "</font>&nbsp;</a>";
			} else if ((dayPointer % 7 == (__popcal4js_startAt * -1)+7 && __popcal4js_startAt==1) || (dayPointer % 7 == __popcal4js_startAt && __popcal4js_startAt==0)) {	///// SI ES SABADO
				if (__popcal4js_isPast==1)
					sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' class='"+sClass+"' "+__popcal4js_selDayAction+">&nbsp;<font color=#909090 style='font-family:verdana;font-size:12px;'>" + datePointer + "</font>&nbsp;</a>";
				else
					sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' class='"+sClass+"' "+__popcal4js_selDayAction+">&nbsp;<font color=#ff3535 style='font-family:verdana;font-size:12px;'>" + datePointer + "</font>&nbsp;</a>";
			} else {																			///// CUALQUIER OTRO DIA
				if (__popcal4js_isPast==1)
					sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' class='"+sClass+"' "+__popcal4js_selDayAction+">&nbsp;<font color=#909090 style='font-family:verdana;font-size:12px;'>" + datePointer + "</font>&nbsp;</a>";
				else
					sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' class='"+sClass+"' "+__popcal4js_selDayAction+">&nbsp;<font color=#000066 style='font-family:verdana;font-size:12px;'>" + datePointer + "</font>&nbsp;</a>";
			}
			
			sHTML += '';
			if ((dayPointer+__popcal4js_startAt) % 7 == __popcal4js_startAt) {
				sHTML += '</tr><tr>';
				if ((__popcal4js_showWeekNumber == 1) && (datePointer < numDaysInMonth)) {
					sHTML += '<td align="right" style="line-height:15px;height:12px;font-family:verdana;font-size:12px;">' + (WeekNbr_popcal4js(new Date(__popcal4js_yearSelected,__popcal4js_monthSelected,datePointer+1))) + '&nbsp;</td>';
				}
			}
		}

		document.getElementById('__popcal4js_content').innerHTML   = sHTML;
		document.getElementById('__popcal4js_spanMonth').innerHTML = '&nbsp;<font style="color:#ffffff;">' +	__popcal4js_monthName[__popcal4js_language][__popcal4js_monthSelected] + '</font>&nbsp;<img id="__popcal4js_changeMonth" src="'+__popcal4js_imgDir+'popcal4js_drop1.gif" width="12" height="10" border="0">'
		document.getElementById('__popcal4js_spanYear').innerHTML  = '&nbsp;<font style="color:#ffffff;">' + __popcal4js_yearSelected	+ '</font>&nbsp;<img id="__popcal4js_changeYear" src="'+__popcal4js_imgDir+'popcal4js_drop1.gif" width="12" height="10" border="0">';
	}

	function showCalendar_popcal4js(ctl, ctl2, format, lang, past, fx, fy, startAt, showWeekNumber, showToday) {
		if (lang != null && lang != '') __popcal4js_language = lang;
		if (past != null) __popcal4js_enablePast = past;
		if (fx != null) __popcal4js_fixedX = fx;
		if (fy != null) __popcal4js_fixedY = fy;

		if(startAt != null) __popcal4js_startAt = startAt;
		if(showWeekNumber != null) __popcal4js_showWeekNumber = showWeekNumber;
		if(showToday != null) __popcal4js_showToday = showToday;

		if (__popcal4js_showToday == 1) {
			if(__popcal4js_language == 'en')
			  document.getElementById('__popcal4js_lblToday').innerHTML = '<font color="#000066">' + __popcal4js_todayString[__popcal4js_language] + '<a onmousemove="window.status=\''+__popcal4js_gotoString[__popcal4js_language]+'\'" onmouseout="window.status=\'\'" title="'+__popcal4js_gotoString[__popcal4js_language]+'" style="'+__popcal4js_styleAnchor+'" href="javascript:__popcal4js_monthSelected=__popcal4js_monthNow;__popcal4js_yearSelected=__popcal4js_yearNow;constructCalendar_popcal4js();">'+__popcal4js_dayNameAll[__popcal4js_language][(__popcal4js_today.getDay()-__popcal4js_startAt==-1)?6:(__popcal4js_today.getDay()-__popcal4js_startAt)]+' '+__popcal4js_monthName[__popcal4js_language][__popcal4js_monthNow].substring(0,3)+'. '+__popcal4js_dateNow+' '+__popcal4js_yearNow+'</a></font>';
			if(__popcal4js_language == 'cn')
			  document.getElementById('__popcal4js_lblToday').innerHTML = '<font color="#000066">' + __popcal4js_todayString[__popcal4js_language] + '<a onmousemove="window.status=\''+__popcal4js_gotoString[__popcal4js_language]+'\'" onmouseout="window.status=\'\'" title="'+__popcal4js_gotoString[__popcal4js_language]+'" style="'+__popcal4js_styleAnchor+'" href="javascript:__popcal4js_monthSelected=__popcal4js_monthNow;__popcal4js_yearSelected=__popcal4js_yearNow;constructCalendar_popcal4js();">'+__popcal4js_dayNameAll[__popcal4js_language][(__popcal4js_today.getDay()-__popcal4js_startAt==-1)?6:(__popcal4js_today.getDay()-__popcal4js_startAt)]+' '+__popcal4js_yearNow+'年'+ __popcal4js_monthName[__popcal4js_language][__popcal4js_monthNow].substring(0,3)+__popcal4js_dateNow+'日</a></font>';
		}
		
		if (format.indexOf("tt") >= 0) {
			 document.getElementById('__popcal4js_lblToday').innerHTML +=	'<br>' + __popcal4js_timeString[__popcal4js_language] + '<input type="text" id="__popcal4js_txtNowTime" name="__popcal4js_txtNowTime" value="' + __popcal4js_timeNow + '" style="width:65px;border:0px;">';
		}
		
		popUpCalendar_popcal4js(ctl, ctl2, format);
	}

	function popUpCalendar_popcal4js(ctl, ctl2, format) {
		var leftpos = 0;
		var toppos  = 0;

		if (__popcal4js_bPageLoaded) {
			if (__popcal4js_crossobj.visibility == 'hidden') {
				__popcal4js_ctlToPlaceValue = ctl2;
				__popcal4js_dateFormat = format;
				
				var format_date = __popcal4js_dateFormat.split(' ')[0]; // get date, no time
				formatChar = ' ';
				aFormat = format_date.split(formatChar);
				if (aFormat.length < 3) {
					formatChar = '/';
					aFormat = format_date.split(formatChar);
					if (aFormat.length < 3) {
						formatChar = '.';
						aFormat = format_date.split(formatChar);
						if (aFormat.length < 3) {
							formatChar = '-';
							aFormat = format_date.split(formatChar);
							if (aFormat.length < 3) {
								formatChar = '';					// invalid date format

							}
						}
					}
				}
				
				tokensChanged = 0;
				if (formatChar != "") {
					var aDataTmp = ctl2.value.split(' ')[0]; // get date, no time
					aData =	aDataTmp.split(formatChar);			// use user's date

					for (i=0; i<3; i++) {
						if ((aFormat[i] == "d") || (aFormat[i] == "dd")) {
							__popcal4js_dateSelected = parseInt(aData[i], 10);
							tokensChanged++;
						} else if ((aFormat[i] == "m") || (aFormat[i] == "mm")) {
							__popcal4js_monthSelected = parseInt(aData[i], 10) - 1;
							tokensChanged++;
						} else if (aFormat[i] == "yyyy") {
							__popcal4js_yearSelected = parseInt(aData[i], 10);
							tokensChanged++;
						} else if (aFormat[i] == "mmm") {
							for (j=0; j<12; j++) {
								if (aData[i] == __popcal4js_monthName[__popcal4js_language][j]) {
									__popcal4js_monthSelected=j;
									tokensChanged++;
								}
							}
						} else if (aFormat[i] == "mmmm") {
							for (j=0; j<12; j++) {
								if (aData[i] == __popcal4js_monthName2[__popcal4js_language][j]) {
									__popcal4js_monthSelected = j;
									tokensChanged++;
								}
							}
						}
					}
				}

				if ((tokensChanged != 3) || isNaN(__popcal4js_dateSelected) || isNaN(__popcal4js_monthSelected) || isNaN(__popcal4js_yearSelected)) {
					__popcal4js_dateSelected  = __popcal4js_dateNow;
					__popcal4js_monthSelected = __popcal4js_monthNow;
					__popcal4js_yearSelected  = __popcal4js_yearNow;
				}

				__popcal4js_odateSelected  = __popcal4js_dateSelected;
				__popcal4js_omonthSelected = __popcal4js_monthSelected;
				__popcal4js_oyearSelected  = __popcal4js_yearSelected;


				//得到parent并累加
				aTag = ctl;
				do {
					aTag     = aTag.parentNode;
					leftpos += aTag.offsetLeft;
					toppos  += aTag.offsetTop;
				} while (aTag.tagName != 'BODY' && aTag.tagName != 'HTML');
				//初始化数据
				var crossobj_left = __popcal4js_fixedX;
				var crossobj_top = __popcal4js_fixedY;
				//fx,fy=-1时
				if(__popcal4js_fixedX == -1) crossobj_left =  ctl.offsetLeft + leftpos;
				if(__popcal4js_fixedY == -1) crossobj_top = ctl.offsetTop + toppos + ctl.offsetHeight + 2;
				//fx,fy=-2时,支持div带有样式overflow-y:auto;
				if(__popcal4js_fixedX == -2) crossobj_left = __popcal4js_rePos(ctl).x;
				if(__popcal4js_fixedY == -2) crossobj_top = __popcal4js_rePos(ctl).y + ctl.offsetHeight + 2;
				//如果再显示屏幕之外，进行调整
				var tmp_cal_x = document.body.clientWidth - document.getElementById("__popcal4js_calendar").scrollWidth;
				var tmp_cal_y = document.body.clientHeight - document.getElementById("__popcal4js_calendar").scrollHeight;
				if(crossobj_left > tmp_cal_x) crossobj_left = tmp_cal_x;
				if(crossobj_top > tmp_cal_y) crossobj_top = tmp_cal_y;
				//赋值, 在top和left数值后面加px,已保证在XHTML 1.0下FireFox中正常显示
				__popcal4js_crossobj.left = crossobj_left + "px";
				__popcal4js_crossobj.top = crossobj_top + "px";
				
				
				constructCalendar_popcal4js (1, __popcal4js_monthSelected, __popcal4js_yearSelected);
				__popcal4js_crossobj.visibility = (__popcal4js_dom||__popcal4js_ie) ? "visible" : "show";

				var browser = new Browser_popcal4js(); 
				hideElement_popcal4js('APPLET', document.getElementById('__popcal4js_calendar'));			
				if(browser.isIE && browser.version<7)//在ie6及以下版本隐藏select和增加ifreame
				{
					hideElement_popcal4js('SELECT', document.getElementById('__popcal4js_calendar'));
					// iframe
		  		document.getElementById("__popcal4js_calendar_iframe").innerHTML = "<iframe scr='' name='__popcal4js__iframe' width='"+((__popcal4js_showWeekNumber==1)?248:218)+"' height='180' border=0 NORESIZE=NORESIZE SCROLLING=no MARGINWIDTH=0 MARGINHEIGHT=0 FRAMESPACING=0 FRAMEBORDER=0></iframe>";
	  			document.getElementById("__popcal4js_calendar_iframe").style.visibility = "";
	  			document.getElementById("__popcal4js_calendar_iframe").style.left = __popcal4js_crossobj.left;
	  			document.getElementById("__popcal4js_calendar_iframe").style.top = __popcal4js_crossobj.top;
	  			
				}
				
				document.getElementById('__popcal4js_calendar').style.zIndex="10000";
			    document.getElementById('__popcal4js_selectMonth').style.zIndex="10000";
			    document.getElementById('__popcal4js_selectYear').style.zIndex="10000";
				__popcal4js_bShow = true;				
			} else {
				hideCalendar_popcal4js();
				if (__popcal4js_ctlNow!=ctl) popUpCalendar_popcal4js(ctl, ctl2, format);
			}
			__popcal4js_ctlNow = ctl;						
		}
	}

	document.onkeypress = function hidecal1 (ev) {
		var ev = window.event || ev;
		var k = ev.keyCode || ev.which;
		if (k == 27) hideCalendar_popcal4js();
	}
	document.onclick = function hidecal2 () {
		if (!__popcal4js_bShow) hideCalendar_popcal4js();
		__popcal4js_bShow = false;
	}
	/*
	if(__popcal4js_ie) {
		init_popcal4js();
	} else {
		window.onload = init_popcal4js;
	}
	*/
	if (document.all){
 window.attachEvent('onload',init_popcal4js)
}
else{
 window.addEventListener('load',init_popcal4js,false);
}



// 判断浏览器版本信息
function Browser_popcal4js() { 

var ua, s, i; 

this.isIE = false; // Internet Explorer 
this.isNS = false; // Netscape 
this.version = null; 

ua = navigator.userAgent; 

s = "MSIE"; 
if ((i = ua.indexOf(s)) >= 0) { 
this.isIE = true; 
this.version = parseFloat(ua.substr(i + s.length)); 
return; 
} 

s = "Netscape6/"; 
if ((i = ua.indexOf(s)) >= 0) { 
this.isNS = true; 
this.version = parseFloat(ua.substr(i + s.length)); 
return; 
} 

// Treat any other "Gecko" browser as NS 6.1. 

s = "Gecko"; 
if ((i = ua.indexOf(s)) >= 0) { 
this.isNS = true; 
this.version = 6.1; 
return; 
} 
} 



/*
2009-07-10 Mars add
get object position x and y value.
*/
var __popcal4js_rePos = function () {
    return document.documentElement.getBoundingClientRect && function (o) {
        var pos = o.getBoundingClientRect(), root = o.ownerDocument || o.document;
        return { x : pos.left + root.documentElement.scrollLeft, y : pos.top + root.documentElement.scrollTop };
    } || function (o) {
        var x = 0, y = 0;
        do { x += o.offsetLeft, y += o.offsetTop; } while (o = o.offsetParent);
        return { 'x' : x, 'y' : y };
    };
}();

