	var	fixedX = -1 // x position (-1 if to appear below control)
	var	fixedY = -1 // y position (-1 if to appear below control)
	var startAt = 0 // 0 - sunday ; 1 - monday
	var imgDir = "icons/calendar/"	// directory for images ... e.g. var imgDir="/img/"
	var calage = 0
	
	var gotoString = "Go To Current Month"
	var todayString = "Today is"
	var weekString = "Wk"
	var scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically."
	var scrollLeftYearMessage = "Click to scroll to previous year. Hold mouse button to scroll automatically."
	var scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically."
	var scrollRightYearMessage = "Click to scroll to next year. Hold mouse button to scroll automatically."
	var selectMonthMessage = "Click to select a month."
	var selectYearMessage = "Click to select a year."
	var selectDateMessage = "Select [date] as date." // do not replace [date], it will be replaced by date.

	var	crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue1,ctlToPlaceValue2,ctlToPlaceValue3, ctlNow, dateFormat, nStartingYear, enddate

	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	imgsrc = new Array("drop1.gif","drop2.gif","left1.gif","left2.gif","right1.gif","right2.gif")
	var	img	= new Array()
	

	var bShow = false;

    /* hides <select> and <applet> objects (for IE only) */
    function hideElement( elmID, overDiv )
    {
      if( 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" )
          {
            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";
          }
        }
      }
    }
     
    /*
    * unhides <select> and <applet> objects (for IE only)
    */
    function showElement( elmID )
    {
      if( 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 (d, m, y, desc)
	{
		this.d = d
		this.m = m
		this.y = y
		this.desc = desc
	}

	var HolidaysCounter = 0
	var Holidays = new Array()

	function addHoliday (d, m, y, desc)
	{
		Holidays[HolidaysCounter++] = new HolidayRec ( d, m, y, desc )
	}


	if (dom)
	{
		for	(i=0;i<imgsrc.length;i++)
		{
			img[i] = new Image
			img[i].src= imgDir + imgsrc[i]
		}
		
		document.write ("<div onclick='bShow=true' id='calendar' class='div-style'><table width=200 cellSpacing=1 cellPadding=0 bgcolor='#ffffff'><tr bgcolor='#a0b1c5'><td><table cellspacing=1 width='100%'><tr><td class='title-style'><B><span id='caption'></span></B></td></tr></table></td></tr><tr><td ><span id='content'></span></td></tr>")
		document.write ("<tr bgcolor='#a0b1c5'><td class='title-style'>&nbsp;</td></tr></table></div><div id='selectMonth' class='div-style'></div><div id='selectYear' class='div-style'></div>");
		
		
	}

	var	monthName =	new	Array("January","February","March","April","May","June","July","August","September","October","November","December")
	var	monthName2 = new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC")

	if (startAt==0)
	{
		dayName = new Array	("S","M","T","W","T","F","S")
	}
	else
	{
		dayName = new Array	("M","T","W","T","F","S","S")
	}

	function swapImage(srcImg, destImg){
		if (ie)	{ document.getElementById(srcImg).setAttribute("src",imgDir + destImg) }
	}

	function init()	{
		var temp_date = new Date();
		nStartingYear = temp_date.getYear();
		if (!ns4)
		{
			if (!ie) { yearNow += 1900	}

			crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar
			hideCalendar()

			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;

			sHTML1= "<TABLE cellSpacing=0 cellPadding=0 width='100%' border=0><TR>";
			sHTML1+="<TD width='10%' class=CalendarTitle align=left style='cursor: hand'><span id='spanYearLeft'  title=\""+scrollLeftYearMessage+"\" onclick='javascript:decYear()' onmouseout='clearInterval(intervalID1);' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecYear()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> &lt;&lt; </span></td>";
			sHTML1+="<TD width='5%' class=CalendarTitle align=left style='cursor: hand'><span id='spanLeft'  title=\""+scrollLeftMessage+"\" onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> &lt; </span></td>"
			sHTML1+="<TD width='61%' class=CalendarTitle align=center><span id='spanMonth'>&nbsp;" + monthName[monthSelected] + "&nbsp;</span>&nbsp;"
			sHTML1+="<span id='spanYear'>" + yearSelected + "&nbsp;</span></td>"
			sHTML1+="<TD width='7%' class=CalendarTitle align=left style='cursor: hand'><span id='spanRight' title=\""+scrollRightMessage+"\" onmouseout='clearInterval(intervalID1);' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> &gt; </span></td>"
			sHTML1+="<TD width='10%' class=CalendarTitle align=left style='cursor: hand'><span id='spanYearRight' title=\""+scrollRightYearMessage+"\" onmouseout='clearInterval(intervalID1);' onclick='incYear()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncYear()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'> &gt;&gt; </span></td>"
			sHTML1+="<td width='7%' align=right class=CalendarTitle style='cursor: hand'><span id='closeCal' title='Close the Calendar' onclick='hideCalendar()'>x</span></td>"
			sHTML1+="</TR></TABLE>"
			
			document.getElementById("caption").innerHTML  =	sHTML1
			bPageLoaded=true
		}
	}

	function hideCalendar()	{
		crossobj.visibility="hidden"
		if (crossMonthObj != null){crossMonthObj.visibility="hidden"}
		if (crossYearObj !=	null){crossYearObj.visibility="hidden"}

		showElement( 'SELECT' );
		showElement( 'APPLET' );
	}

	function padZero(num) {
		return (num	< 10)? '0' + num : num ;
	}

	function constructDate(d,m,y)
	{
		sTmp = "mm-dd-yyyy";
		sTmp = sTmp.replace	("dd","<e>")
		sTmp = sTmp.replace	("d","<d>")
		sTmp = sTmp.replace	("<e>",padZero(d))
		sTmp = sTmp.replace	("<d>",d)
		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(m+1))
		sTmp = sTmp.replace	("<o>",monthName2[m])
		sTmp = sTmp.replace	("yyyy",y)
		return sTmp.replace ("yy",padZero(y%100))
	}

	function closeCalendar() {
		var	sTmp

		hideCalendar();
		ctlToPlaceValue1.value = padZero(monthSelected + 1)+"-"+padZero(dateSelected)+"-"+yearSelected;
		if(calage == 1)
			findAge();
		/*ctlToPlaceValue2.value = padZero(dateSelected);
		ctlToPlaceValue3.value = yearSelected;*/
	}

	/*** Month Pulldown	***/

	function StartDecMonth()
	{
		intervalID1=setInterval("decMonth()",80)
	}

	function StartIncMonth()
	{
		intervalID1=setInterval("incMonth()",80)
	}

	function StartDecYear()
	{
		intervalID1=setInterval("decYear()",80)
	}

	function StartIncYear()
	{
		intervalID1=setInterval("incYear()",80)
	}

	function incMonth () {
		monthSelected++
		if (monthSelected>11) {
			monthSelected=0
			yearSelected++
		}
		constructCalendar()
	}

	function decMonth () {
		monthSelected--
		if (monthSelected<0) {
			monthSelected=11
			yearSelected--
		}
		constructCalendar()
	}
	
	function incYear () {
		yearSelected++
		constructCalendar()
	}

	function decYear () {
		yearSelected--
		constructCalendar()
	}

	/*** calendar ***/
	function takeYear(theDate)
	{
		x = theDate.getYear();
		var y = x % 100;
		y += (y < 38) ? 2000 : 1900;
		return y;
	}

	function constructCalendar () {
		var dateMessage
		var	startDate =	new	Date (yearSelected,monthSelected,1)
		var	endDate	= new Date (yearSelected,monthSelected+1,1);
		endDate	= new Date (endDate	- (24*60*60*1000));
		numDaysInMonth = endDate.getDate()

		datePointer	= 0
		dayPointer = startDate.getDay() - startAt
		
		if (dayPointer<0)
		{
			dayPointer = 6
		}

		sHTML =	"<table	border=0 width='100%'><tr>"

		for	(i=0; i<7; i++)	{
			sHTML += "<td width='14%' class=WeekdayTitle align='right' ><B>"+ dayName[i]+"</B></td>"
		}
		sHTML +="</tr><tr>"
		
		for	( var i=1; i<=dayPointer;i++ )
		{
			sHTML += "<td class=BlankDay >&nbsp;</td>"
		}
	
		for	( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
		{
			dayPointer++;
			if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)) //today
				sHTML += "<td align=center bgColor=#c7c7c7 >"
			else
				sHTML += "<td align=center bgColor=#eaf4ff >"

			var sStyle="NormalDay"; //regular day

			if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)) //today
			{ sStyle = "NormalDay"; } 
			else if	(dayPointer % 7 == (startAt * -1) +1) //end-of-the-week day
			{ sStyle = "NormalDay"; } 

			//selected day
			if ((datePointer==odateSelected) &&	(monthSelected==omonthSelected)	&& (yearSelected==oyearSelected))
			{ sStyle = "NormalDay"; } //selected-day-style

			sHint = ""
			for (k=0;k<HolidaysCounter;k++)
			{
				if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1)))
				{
					if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))
					{
						sStyle = "NormalDay"; //holiday-style
						sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
					}
				}
			}

			var regexp= /\"/g
			sHint=sHint.replace(regexp,"&quot;")
			temp_dt_mes = selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected));
			dateMessage = "onmousemove='window.status=\""+ temp_dt_mes +"\"' onmouseout='window.status=\"\"' "

			sHTML += "<a class='"+sStyle+"' "+dateMessage+" title=\"" + temp_dt_mes + "\" href='javascript:dateSelected="+datePointer+";closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>"

			sHTML += "</td>"
			if ((dayPointer+startAt) % 7 == startAt) { 
				sHTML += "</tr><tr>" 
			}
		}
		for	( var i=dayPointer+startAt; i%7!=0;i++ )
		{
			sHTML += "<td class=BlankDay >&nbsp;</td>"
		}
		document.getElementById("content").innerHTML   = sHTML
		document.getElementById("spanMonth").innerHTML = "&nbsp;" +	monthName[monthSelected] + "&nbsp;"
		document.getElementById("spanYear").innerHTML =	"" + yearSelected	+ "&nbsp;"
	}

	function popUpCalendar(ctl,	ctl1,ctl2,ctl3,end_time) {
		var	leftpos=0
		var	toppos=0
		enddate =  end_time;
		if (bPageLoaded)
		{
			if ( crossobj.visibility ==	"hidden" ) {
				ctlToPlaceValue1 = ctl1
				ctlToPlaceValue2 = ctl2
				ctlToPlaceValue3 = ctl3
				dateSelected = dateNow
				monthSelected =	monthNow
				yearSelected = yearNow

				odateSelected=dateSelected
				omonthSelected=monthSelected
				oyearSelected=yearSelected

				aTag = ctl
				do {
					aTag = aTag.offsetParent;
					leftpos	+= aTag.offsetLeft;
					toppos += aTag.offsetTop;

				} while(aTag.tagName!="BODY");

				crossobj.left =	fixedX==-1 ? ctl.offsetLeft	+ leftpos :	fixedX
				crossobj.top = fixedY==-1 ?	ctl.offsetTop +	toppos + ctl.offsetHeight +	2 :	fixedY
				constructCalendar (1, monthSelected, yearSelected);
				crossobj.visibility=(dom||ie)? "visible" : "show"
				
				hideElement( 'SELECT', document.getElementById("calendar") );
				hideElement( 'APPLET', document.getElementById("calendar") );			

				bShow = true;
			}
		}
		else
		{
			init()
			popUpCalendar(ctl,	ctl1,ctl2,ctl3)
		}
	}
	document.onkeypress = function hidecal1 () { 
		if (event.keyCode==27) 
		{
			hideCalendar()
		}
	}
	document.onclick = function hidecal2 () { 		
		if (!bShow)
		{
			hideCalendar()
		}
		bShow = false
	}

	if(ie)
	{
		init()
	}
	else
	{
		window.onload=init
	}