var fixedX = -1; var fixedY = -1; var showWeekNumber = 1; var showToday = 0;var imgDir = "images/";
var sBgColor = "#ffffff"; var sWeekColor = "black";

var gotoString="Go To Current Month"; var todayString="Today is";
var weekString="Wk"; var selectMonthMessage = "Click to select a month."; var selectYearMessage = "Click to select a year.";
var selectDateMessage = "Select [date] as date."; var styleAnchor="text-decoration:none;color:gray;";
var styleAnchorwhite="text-decoration:none;color:gray;";
var styleLightBorder="border-style:1px solid #282828";
var monthName=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var imgsrc=new Array("icCalDown.gif","icCalDown.gif","left1.gif","left2.gif","right1.gif","right2.gif");

var crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear, crossFrame; //, hidctlToPlaceValue 
var bPageLoaded=false; var ie=document.all; var dom=document.getElementById; var ns4=document.layers;
var today = new Date(); var dateNow=today.getDate(); var monthNow=today.getMonth(); var yearNow=today.getYear();
var img	= new Array(); var bShow = false; var HolidaysCounter = 0; var Holidays = new Array();
var selectedDate; var selectedMonth; var selectedYear;

if (dom) {
	for	(i=0;i<imgsrc.length;i++){img[i] = new Image; img[i].src = imgDir + imgsrc[i];}
	document.write ("<iframe id='calframe' name='calframe' src='javascript:false' width="+((showWeekNumber==1)?252:222)+" height="+((showToday==1)?173:140)+" style='z-index:500;position:absolute;visibility:hidden;' scrolling='no' frameborder='0'></iframe>")
	document.write ("<style type='text/css'>#calendar td {border:2px solid transparent;}</style>");
	document.write ("<div id='calendar' name='calendar' onclick='bShow=true' style='z-index:+999;position:absolute;visibility:hidden;color:" + sWeekColor + ";'>");
	document.write ("<table width="+((showWeekNumber==1)?250:220)+" style='font-family:tahoma;padding:0px;font-size:11px;border:1px solid black;background-color:" + sBgColor + ";'>");
	document.write ("<tr style='background-color:black;'><td><table border='0' width='"+((showWeekNumber==1)?248:218)+"'><tr><td align=right width='50%' valign=middle style='padding:2px;font-family:Arial;font-size:11px;'><font color=White><B><span id='caption1' name='caption1'></span></B></font></td><td align=left width='35%' valign=middle style='padding:2px;font-family:Arial;font-size:11px;'><font color=White><B><span id='caption2' name='caption2'></span></B></font></td><td align=right width='10%'><img src='"+imgDir+"icCalX.gif' border='0' alt='Close' onclick='javascript:hideCalendar()' style='cursor:pointer;'></td></tr></table></td></tr>");
	document.write ("<tr><td><span id='content' name='content'></span></td></tr>")	
	if (showToday==1) {document.write ("<tr style='background-color:" + sBgColor +  ";'><td style='color:White;' align=center><span id='lblToday' name='lblToday'></span></td></tr>")}
	document.write ("</table></div>");
	document.write ("<div id='selectMonth' style='z-index:+999;position:absolute; visibility:hidden; border:1px solid black;'></div>")
	document.write ("<div id='selectYear' style='z-index:+999;position:absolute; visibility:hidden; border:1px solid black;'></div>");
}

document.onmouseOver = function higlight() {}
if(1==1) { init() } else { window.onload=init }

function HolidayRec (d, m, y, desc){this.d = d; this.m = m; this.y = y; this.desc = desc;}
function addHoliday (d, m, y, desc) { Holidays[HolidaysCounter++] = new HolidayRec ( d, m, y, desc ) }
function swapImage(srcImg, destImg) { if (ie) {document.getElementById(srcImg).setAttribute("src",imgDir + destImg) } }
function init()	{
	if (!ns4) {
	    if (!ie) { yearNow += 1900 }
			crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendarhideCalendar();
			crossFrame=document.getElementById("calframe").style;
			crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth	: document.selectMonth;
			crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear;

		    monthConstructed=false; yearConstructed=false;
		    if (showToday==1) {document.getElementById("lblToday").innerHTML = todayString + " <a onmousemove='window.status=\""+gotoString+"\"'onmouseout='window.status=\"\"' title='"+gotoString+"' style='"+styleAnchorwhite+"' href='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();'>"+dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+", " + dateNow + " " + monthName[monthNow].substring(0,3) + "	" +	yearNow	+ "</a>";		    }

        if(typeof(calMPD) != 'undefined') {
            sHTML1 ="<span id='spanMonth' name='spanMonth' style='border:none;' window.status=\""+selectMonthMessage+"\"' window.status=\"\"'></span>&nbsp;";
            sHTML2 ="<span id='spanYear' name='spanYear' style='border:none;' window.status=\""+selectYearMessage+"\"' window.status=\"\"'></span>&nbsp;";
        } else {
            sHTML1 ="<span id='spanMonth' name='spanMonth' style='border:none;cursor:hand;' onmouseover='swapImage(\"changeMonth\",\"icCalDown.gif\"); window.status=\""+selectMonthMessage+"\"' onmouseout='swapImage(\"changeMonth\",\"icCalDown.gif\");window.status=\"\"' onclick='popUpMonth()'></span>&nbsp;";
            sHTML2 ="<span id='spanYear' name='spanYear' style='border:none;cursor:hand;' onmouseover='swapImage(\"changeYear\",\"icCalDown.gif\"); window.status=\""+selectYearMessage+"\"' onmouseout='swapImage(\"changeYear\",\"icCalDown.gif\");window.status=\"\"' onclick='popUpYear()'></span>&nbsp;";
        }
        document.getElementById("caption1").innerHTML  = sHTML1; document.getElementById("caption2").innerHTML  = sHTML2;
	}
}

function hideCalendar()	{crossobj.visibility="hidden";crossFrame.visibility="hidden";if (crossMonthObj !=null) {crossMonthObj.visibility="hidden"};if (crossYearObj !=null) {crossYearObj.visibility="hidden"};}
function padZero(num) { return (num	< 10)? '0' + num : num ; }
function constructDate(d,m,y) {sTmp = dateFormat; sTmp = sTmp.replace ("dd","<e>"); sTmp = sTmp.replace ("d","<d>"); sTmp = sTmp.replace ("<e>",padZero(d)); sTmp = sTmp.replace ("<d>",d); sTmp = sTmp.replace ("MMMM","<o>"); sTmp = sTmp.replace ("mmmm","<o>"); sTmp = sTmp.replace ("MMM","<g>"); sTmp = sTmp.replace ("mmm","<g>"); sTmp = sTmp.replace ("mm","<n>"); sTmp = sTmp.replace ("m","<m>"); sTmp = sTmp.replace ("<m>",m+1); sTmp = sTmp.replace ("<n>",padZero(m+1)); sTmp = sTmp.replace ("<o>",monthName[m]); sTmp = sTmp.replace ("<g>",monthName[m].substr(0,3)); sTmp = sTmp.replace ("yyyy", y); sTmp = sTmp.replace ("YYYY", y); return sTmp.replace ("yy", y.toString().substr(2,2));}
function closeCalendar() {var sTmp; hideCalendar(); var obj = document.getElementById(ctlToPlaceValue); switch (obj.nodeName) {case "INPUT": obj.value = constructDate(dateSelected,monthSelected,yearSelected); break; case "TD": case "SPAN": obj.innerText = constructDate(dateSelected,monthSelected,yearSelected); break; default: obj.innerText = constructDate(dateSelected,monthSelected,yearSelected); break;}}
function StartDecMonth() { intervalID1=setInterval("decMonth()",80); }
function StartIncMonth() { intervalID1=setInterval("incMonth()",80); }
function incMonth() {monthSelected++; if (monthSelected>11) {monthSelected=0;yearSelected++;}constructCalendar()}
function decMonth() {monthSelected--; if (monthSelected<0) {monthSelected=11;yearSelected--;}constructCalendar()}
function constructMonth() {popDownYear(); if (!monthConstructed) {sHTML=""; for	(i=0; i<12;	i++) {sName=monthName[i]; if (i==monthSelected) { sName =	"<B>" +	sName +	"</B>"; } sHTML += "<tr><td id='m" + i + "' onmouseover='this.style.backgroundColor=\"black\"; this.style.color=\"white\"' onmouseout='this.style.backgroundColor=\"white\"; this.style.color=\"black\"' style='cursor:hand' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();window.event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>";} document.getElementById("selectMonth").innerHTML = "<table width=40 style='font-family:arial;font-size:11px;border-width:1;border-style:solid;border-color:" + sBgColor + ";background-color:white;' cellspacing=0 onmouseover='clearTimeout(timeoutID1);' onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);window.event.cancelBubble=true;'>"+sHTML+"</table>"; monthConstructed=true;}}
function popUpMonth() {constructMonth(); crossMonthObj.visibility = (dom||ie)? "visible":"show"; if (showWeekNumber == 0) {crossMonthObj.left = (parseInt(crossobj.left) + 45) + "px";} else {crossMonthObj.left = (parseInt(crossobj.left) + 55) + "px";} crossMonthObj.top =	(parseInt(crossobj.top) + 26) + "px";}
function popDownMonth()	{ crossMonthObj.visibility= "hidden";}
function incYear() {if (nStartingYear+7 != endYear){for	(i=0; i<7; i++) {newYear=(i+nStartingYear)+1; if (newYear==yearSelected) { txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;"; } else { txtYear = "&nbsp;" + newYear + "&nbsp;"; } document.getElementById("y"+i).innerHTML = txtYear;} nStartingYear ++;} bShow=true;}
function decYear() {if (nStartingYear != startYear){for	(i=0; i<7; i++) {newYear=(i+nStartingYear)-1; if (newYear==yearSelected) { txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" } else { txtYear = "&nbsp;" + newYear + "&nbsp;"; } document.getElementById("y"+i).innerHTML = txtYear;} nStartingYear --;} bShow=true;}
function selectYear(nYear) {yearSelected=parseInt(nYear+nStartingYear);yearConstructed=false;constructCalendar();popDownYear();}
function constructYear() {popDownMonth(); sHTML =	"";
	if (!yearConstructed) {if ((endYear - startYear) > 6) { sHTML = "<tr><td align='center' style='border-bottom:1px solid black;cursor:hand;' onmouseover='this.style.backgroundColor=\"black\"' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"; } j = 0;
    if ((endYear - startYear) < 6) {
	    nStartingYear =	startYear; n = (endYear-startYear);
	    for	(i=(startYear); i<=(startYear+n); i++) { sName=i; if (i==yearSelected) { sName = "<B>" + sName + "</B>" } sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"black\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:hand' onclick='selectYear("+j+");window.event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"; j ++;}
	} else {
	    if ((endYear - yearSelected) > 6) { nStartingYear =	yearSelected; } else { nStartingYear = endYear - 7; }
	    for	(i=(nStartingYear); i<=(nStartingYear+6); i++) {sName =	i; if (i==yearSelected) { sName = "<B>" + sName + "</B>"; } sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"black\";' onmouseout='this.style.backgroundColor=\"\"' style='cursor:hand' onclick='selectYear("+j+");window.event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"; j ++;}
	}
    if ((endYear - startYear)> 6) {sHTML += "<tr><td align='center' style='border-top:1px solid black;cursor:hand;' onmouseover='this.style.backgroundColor=\"black\"' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)' onmouseup='clearInterval(intervalID2)'>+</td></tr>";} document.getElementById("selectYear").innerHTML ="<table width=44 style='font-family:arial; font-size:11px; border:1px solid " + sBgColor + ";' bgcolor='white' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>" + sHTML + "</table>"; yearConstructed	= true;}
}

function popDownYear() {clearInterval(intervalID1); clearTimeout(timeoutID1); clearInterval(intervalID2); clearTimeout(timeoutID2); crossYearObj.visibility= "hidden";}
function popUpYear() {var leftOffset; constructYear();crossYearObj.visibility	= (dom||ie)? "visible" : "show";var element = document.getElementById("spanYear"); while (element.parentNode.tagName != "TR") { element = element.parentNode; } leftOffset = parseInt(crossobj.left) + element.offsetLeft; if (ie) { leftOffset += 2; } crossYearObj.left =	leftOffset + "px"; crossYearObj.top = (parseInt(crossobj.top) + 26) + "px";}
function WeekNbr(n) {year = n.getFullYear();month = n.getMonth() + 1; if (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 () {
	var aNumDays = Array(31,0,31,30,31,30,31,31,30,31,30,31); 
	var dateMessage; 
	var startDate = new Date(yearSelected,monthSelected,1);
	var endDate;

	if (monthSelected==1) {endDate	= new Date (yearSelected,monthSelected+1,1); endDate = new Date (endDate - (24*60*60*1000)); numDaysInMonth = endDate.getDate();} else {numDaysInMonth = aNumDays[monthSelected];} datehand = 0; dayhand = startDate.getDay() - startAt; if (dayhand < 0) { dayhand = 6; }
	sHTML =	"<table	border=0 style='font-family:verdana;font-size:10px;border-width:1px solid;'><tr>";
	if(typeof(calMPD) == 'undefined') {if (showWeekNumber==1) { sHTML += "<td width=27><b>" + weekString + "</b></td><td rowspan='7' style='width:1px; backgroundColor:#535353; border-right:1px solid #535353; padding:0px;'><img src='"+imgDir+"divider.gif' style='width:1px;'></td>"; }}

	for	(i=0; i<7; i++)	{ sHTML += "<td width='27' align='center'><B>"+ dayName[i]+"</B></td>" } sHTML += "</tr><tr>"; if(typeof(calMPD) == 'undefined') { if (showWeekNumber==1) { sHTML += "<td align=center>" + WeekNbr(startDate) + "&nbsp;</td>"; }}
	for	(var i=1; i<=dayhand;i++ ) { sHTML += "<td>&nbsp;</td>"; }
	for	(datehand=1; datehand<=numDaysInMonth;datehand++ ) {
		dayhand++;
		var isInRange = isDateInRange(new Date(yearSelected,monthSelected,datehand))
		if ((datehand==odateSelected)&&(monthSelected==omonthSelected)&&(yearSelected==oyearSelected)){sHTML += "<td align='center' style='border=1px solid #938976;'";} else {sHTML += "<td align='center' style='border=2px solid transparent;' ";}
		if (isInRange){ sHTML += "onmouseover='this.style.border=\"2px solid gray\"'"; }	    	
		if ((datehand==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)) { sHTML += "style='background-color:black;'" }
		if ((datehand==odateSelected)&&(monthSelected==omonthSelected)&&(yearSelected==oyearSelected)){sHTML += ""} else {sHTML += "onmouseout='this.style.border=\"2px solid transparent\"'";}
		sHTML += ">"
        sStyle=styleAnchor;
		if ((datehand==odateSelected) && (monthSelected==omonthSelected) && (yearSelected==oyearSelected)){ sStyle += styleLightBorder; }sHint = "";
		for (k=0;k<HolidaysCounter;k++) {if ((parseInt(Holidays[k].d)==datehand)&&(parseInt(Holidays[k].m)==(monthSelected+1))) {if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0))) {v += "background-color:#938976;";sHint += sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc;}}}
		var regexp= /\"/g;
		sHint=sHint.replace(regexp,"&quot;");

		sHTML += "<span "+dateMessage+" title=\"" + sHint + "\" ";
		if (isInRange) { sHTML += "style='cursor:hand; "+sStyle+";' onclick='javascript:dateSelected="+datehand+"; closeCalendar();'"; } else{ sHTML += "style='color:gray;'"; } sHTML += ">";
		
		if ((datehand==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)) {sHTML += "<font color=white>&nbsp;<b>" + datehand + "</b></font>"} else if ((datehand==odateSelected)&&(monthSelected==omonthSelected)&&(yearSelected==oyearSelected)) {sHTML += "<font color=black>&nbsp;<b>" + datehand + "</b></font>"} else {if (isInRange){ sHTML += "&nbsp;" + datehand; } else{ sHTML += "&nbsp;<span color=red>" + datehand + "</span>"; }}

		sHTML += "&nbsp;</span>";
		if ((dayhand+startAt) % 7 == startAt) {sHTML += "</tr><tr>"; if ((showWeekNumber==1)&&(datehand < numDaysInMonth)) {if (typeof(calMPD) == 'undefined') { sHTML += "<td align=center>" + (WeekNbr(new Date(yearSelected,monthSelected,datehand+1))) + "&nbsp;</td>"; }}}
	}

	document.getElementById("content").innerHTML = sHTML;	
	if(typeof(calMPD) != 'undefined') {
        document.getElementById("spanMonth").innerHTML = "&nbsp;" + monthName[monthSelected] + "&nbsp;"; document.getElementById("spanYear").innerHTML ="&nbsp;" + yearSelected	+ "&nbsp;";
    } else {
	    document.getElementById("spanMonth").innerHTML = "&nbsp;" + monthName[monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDir+"icCalDown.gif' BORDER=0>"; document.getElementById("spanYear").innerHTML ="&nbsp;" + yearSelected	+ "&nbsp;<IMG id='changeYear' SRC='"+imgDir+"icCalDown.gif' BORDER=0>";
	}
}

function isDateInRange(date) {if (restrictSel == true){ if (date<resStart || date>resEnd) { return false; }} return true;}

function popUpCalendar(ctl,	ctl2, format) {
	var leftpos=0; var toppos=0;
	if (crossobj.visibility =="hidden" ) {
		ctlToPlaceValue	= ctl2; formatChar = ""; dateFormat=format;
		if (dateFormat.indexOf("/") != -1) { formatChar = "/"; } else if (dateFormat.indexOf(".") != -1) { formatChar = "." } else if (dateFormat.indexOf("-") != -1) { formatChar = "-" }
		tokensChanged =	0
		if (formatChar != "") { aFormat	= dateFormat.split(formatChar);
		    if (aFormat.length == 3) {
		        aData =	document.getElementById(ctl2).value.split(formatChar);
		        for	(i=0;i<3;i++) {
				    if ((aFormat[i].toLowerCase()=="d") || (aFormat[i].toLowerCase()=="dd")) {dateSelected = parseInt(aData[i], 10); tokensChanged ++;}
				    if ((aFormat[i].toLowerCase()=="m") ||(aFormat[i].toLowerCase()=="mm")) {monthSelected = parseInt(aData[i], 10) - 1; tokensChanged ++;}
				    if (aFormat[i].toLowerCase()=="yyyy" || aFormat[i].toLowerCase()=="yy") {yearSelected = parseInt(aData[i], 10); tokensChanged ++;}
				    if (aFormat[i].toLowerCase()=="mmmm") {for	(j=0; j<12;	j++) {if (aData[i]==monthName[j]) {monthSelected=j; tokensChanged ++}}}
				    if (aFormat[i].toLowerCase()=="mmm") {for (j=0; j<12; j++) {if (aData[i]==monthName[j].substr(0,3)) {monthSelected=j; tokensChanged ++;}}}
				}
			}
		}
		if ((tokensChanged!=3) || isNaN(dateSelected) || isNaN(monthSelected) || isNaN(yearSelected)) {if (restrictSel == true){dateSelected = resStart.getDate(); monthSelected = resStart.getMonth(); yearSelected = resStart.getYear();} else {dateSelected = dateNow; monthSelected =	monthNow; yearSelected = yearNow;}} else {odateSelected = dateSelected; omonthSelected = monthSelected; oyearSelected = yearSelected;}
		aTag = ctl;
		do {aTag = aTag.offsetParent; leftpos += aTag.offsetLeft; toppos += aTag.offsetTop;} while(aTag.offsetParent != null);
		crossobj.left =	(fixedX==-1 ? ctl.offsetLeft + leftpos : fixedX) + "px"; crossobj.top = (fixedY==-1 ? ctl.offsetTop + toppos + ctl.offsetHeight +2 : fixedY) + "px";		
		crossFrame.left = (fixedX==-1 ? ctl.offsetLeft + leftpos : fixedX) + "px"; crossFrame.top = (fixedY==-1 ? ctl.offsetTop + toppos + ctl.offsetHeight + 2 : fixedY) + "px";		
		constructCalendar (1, monthSelected, yearSelected);
		crossobj.visibility=(dom||ie)? "visible" : "show"; crossFrame.visibility=(dom||ie)? "visible" : "show";
		bShow = true;

	} else {
		hideCalendar();
		if (ctlNow!=ctl) {popUpCalendar(ctl, ctl2, format)}
	}
	ctlNow = ctl
}