
	var gotoString = "Go To Current Month"
	var todayString = "Today is"
	
	var scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically."
	var scrollRightMessage = "Click to scroll to next month. 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 oCalStyle //calendar style
	var oMonthStyle //month style
	var oYearStyle //year style 
	var ctlToPlaceValue //Control to put user selection into
	var monthSelected //Month (as integer) that was passed in
	var yearSelected //Year (as integer) that was passed in
	var dateSelected //day part of date (as integer) that was passed in
	var omonthSelected 
	var oyearSelected
	var odateSelected
	var crossYearObj,  monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlNow, nStartingYear
	
	var	bPageLoaded=false
	var	ie = document.all;
	var	dom = document.getElementById;

	var today =	new	Date()
	var dateNow	 = today.getDate()
	var monthNow = today.getMonth()
	var yearNow	 = today.getFullYear()
	
	var imgsrc = new Array("drop1.gif","drop2.gif","left1.gif","left2.gif","right1.gif","right2.gif")
	var img	= new Array()
	
	var firstAvailableDate;
	var lastAvailableDate;

	var bShow = false;
	
	//Will be called first.  popUpCal checks if it has been called if it hasn't it calls it.
	function init()	
	{
		oCalStyle = document.getElementById("calendarpop").style;
		
		hideCalendar() //hide existing calendar going to rebuild

		oMonthStyle = document.getElementById("selectMonth").style;

		oYearStyle = document.getElementById("selectYear").style;

		monthConstructed=false;
		yearConstructed=false;

		if (showToday == 1)
		{
		
			document.getElementById("lblToday").innerHTML =	todayString + " <a class='CalendarToday' onmousemove='window.status=\""+gotoString+"\"' onmouseout='window.status=\"\"' title='"+gotoString+"' href='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();'>"+dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+", " + dateNow + " " + monthAbbr[monthNow]	+ "	" +	yearNow	+ "</a>"
		}

		sHTML1= "<a id='spanLeft' name='spanLeft' class='CalendarTitleControlNormal' onmouseover='swapImage(\"changeLeft\",\"left2.gif\");this.className=\"CalendarTitleControlActive\";window.status=\""+scrollLeftMessage+"\"' href='javascript:decMonth();' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"left1.gif\");this.className=\"CalendarTitleControlNormal\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'><IMG id='changeLeft' SRC='"+imgDir+"left1.gif' width=10 height=11 BORDER=0></a>&nbsp;"
		sHTML1+="<a id='spanRight' name='spanRight' class='CalendarTitleControlNormal' onmouseover='swapImage(\"changeRight\",\"right2.gif\");this.className=\"CalendarTitleControlActive\";window.status=\""+scrollRightMessage+"\"' onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"right1.gif\");this.className=\"CalendarTitleControlNormal\";window.status=\"\"' href='javascript:incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'><IMG id='changeRight' SRC='"+imgDir+"right1.gif'	width=10 height=11 BORDER=0></a>&nbsp;"
		sHTML1+="<span id='spanMonth'  name='spanMonth' class='CalendarTitleControlNormal' onmouseover='swapImage(\"changeMonth\",\"drop2.gif\");this.className=\"CalendarTitleControlActive\";window.status=\""+selectMonthMessage+"\"' onmouseout='swapImage(\"changeMonth\",\"drop1.gif\");this.className=\"CalendarTitleControlNormal\";window.status=\"\"' onclick='popUpMonth()'></span>&nbsp;"
		sHTML1+="<span id='spanYear' name='spanYear' class='CalendarTitleControlNormal' onmouseover='swapImage(\"changeYear\",\"drop2.gif\");this.className=\"CalendarTitleControlActive\";window.status=\""+selectYearMessage+"\"'	onmouseout='swapImage(\"changeYear\",\"drop1.gif\");this.className=\"CalendarTitleControlNormal\";window.status=\"\"'	onclick='popUpYear()'></span>&nbsp;"
		
		document.getElementById("caption").innerHTML  =	sHTML1

		bPageLoaded=true
	}
	
	//Hides calendar
	function hideCalendar()	
	{
		if(oCalStyle)
			oCalStyle.visibility="hidden"
			
		if (oMonthStyle != null){oMonthStyle.visibility="hidden"}
		if (oYearStyle !=	null){oYearStyle.visibility="hidden"}

		showElement( 'SELECT' );
	}
	
	
	//Main entry point...this is the call from page
	function popUpCalendar(ctl, ctl2, format) 
	{
		var leftpos = 0
		var toppos = 0
		
		//Check if init has been called	
		if (bPageLoaded)
		{
			if ( oCalStyle.visibility ==	"hidden" ) 
			{
				ctlToPlaceValue = ctl2
			
				tokensChanged =	0
				//gave us a valid date format....use the date the gave us
				
				// use user's date
				aData =	ctl2.value.split(localDateSeparator)
				aFormat = localDateFormat.split(localDateSeparator);
				for	(i = 0; i < 3; i++)
				{
					if ((aFormat[i] == "d") || (aFormat[i] == "dd"))
					{
						dateSelected = parseInt(aData[i], 10)
						tokensChanged ++
					}
					else if	((aFormat[i] == "m") || (aFormat[i] == "mm" ))
					{
						monthSelected =	parseInt(aData[i], 10) - 1
						tokensChanged ++
					}
					else if	(aFormat[i]=="yyyy" || aFormat[i]=="yy" || aFormat[i]=="y")
					{
						yearSelected = parseInt(aData[i], 10)
						tokensChanged ++
					}
					else if	(aFormat[i] == "mmm")
					{
						for	(j=0; j<12;	j++)
						{
							if (aData[i] == monthName[j])
							{
								monthSelected=j
								tokensChanged ++
							}
						}
					}
				}
				
				//Make sure that we got a valid date. if not, set to today
				if ((tokensChanged != 3) || isNaN(dateSelected) || isNaN(monthSelected) || isNaN(yearSelected))
				{
					dateSelected = dateNow
					monthSelected =	monthNow
					yearSelected = yearNow
				}

				odateSelected = dateSelected
				omonthSelected = monthSelected
				oyearSelected = yearSelected
				
				//Set position of Cal
				aTag = ctl
				do {
					aTag = aTag.offsetParent;
					leftpos	+= aTag.offsetLeft;
					toppos += aTag.offsetTop;
				} while(aTag.tagName!="BODY");
				
				
				oCalStyle.left =	fixedX == -1 ? ctl.offsetLeft	+ leftpos :	fixedX
				oCalStyle.top = fixedY==-1 ?	ctl.offsetTop +	toppos + ctl.offsetHeight +	2 :	fixedY
				constructCalendar (1, monthSelected, yearSelected);
				oCalStyle.visibility=(dom||ie)? "visible" : "show"
				
				hideElement( 'SELECT', document.getElementById("calendarpop") );
				bShow = true;
				
				if(document.getElementById("spanLeft"))
				{
					document.getElementById("spanLeft").focus();
				}
		
			}
		}
		else
		{
			init()
			popUpCalendar(ctl,	ctl2, format)
		}
	}
	


    /* 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 + 20) <= objTop );
          else if( overDiv.offsetTop >= ( objTop + objHeight + obj.height ));
          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 swapImage(srcImg, destImg){
		if (ie)	{ document.getElementById(srcImg).setAttribute("src", imgDir + destImg) }
	}

	function padZero(num) {
		return (num	< 10) ? '0' + num : num ;
	}

	/*** Month Pulldown	***/

	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.className=\"CalendarDropDownItemActive\"' onmouseout='this.className=\"CalendarDropDownItemNormal\"' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
			}

			document.getElementById("selectMonth").innerHTML = "<table width=70	class='CalendarDropdownNormal' cellspacing=0 onmouseover='clearTimeout(timeoutID1)'	onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>" +	sHTML +	"</table>"

			monthConstructed=true
		}
	}

	function popUpMonth() {
		constructMonth()
		oMonthStyle.visibility = (dom||ie)? "visible"	: "show"
		oMonthStyle.left = parseInt(oCalStyle.left) + 50
		oMonthStyle.top =	parseInt(oCalStyle.top) + 26

		hideElement( 'SELECT', document.getElementById("selectMonth") );
		hideElement( 'APPLET', document.getElementById("selectMonth") );			
	}

	function popDownMonth()	{
		oMonthStyle.visibility= "hidden"
	}

	/*** Year Pulldown ***/

	function incYear() {
		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() {
		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) {

			sHTML =	"<tr><td align='center'	onmouseover='this.className=\"CalendarDropDownItemActive\"' onmouseout='clearInterval(intervalID1);this.className=\"CalendarDropDownItemNormal\"' onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"
			j =	0
			nStartingYear =	yearSelected-3
			for	(i=(yearSelected-3); i<=(yearSelected+3); i++) {
				sName =	i;
				if (i==yearSelected){
					sName =	"<B>" +	sName +	"</B>"
				}

				sHTML += "<tr><td id='y" + j + "' onmouseover='this.className=\"CalendarDropDownItemActive\"' onmouseout='this.className=\"CalendarDropDownItemNormal\"' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
				j ++;
			}

			sHTML += "<tr><td align='center' onmouseover='this.className=\"CalendarDropDownItemActive\"' onmouseout='clearInterval(intervalID2);this.className=\"CalendarDropDownItemNormal\"' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'	onmouseup='clearInterval(intervalID2)'>+</td></tr>"

			document.getElementById("selectYear").innerHTML	= "<table width=44 class='CalendarDropdownNormal' 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)
		oYearStyle.visibility= "hidden"
	}

	function popUpYear() {
		var	leftOffset

		constructYear()
		oYearStyle.visibility	= (dom||ie)? "visible" : "show"
		leftOffset = parseInt(oCalStyle.left) + document.getElementById("spanYear").offsetLeft
		if (ie)
		{
			leftOffset += 6
		}
		oYearStyle.left =	leftOffset
		oYearStyle.top = parseInt(oCalStyle.top) +	26
	}

	/*** 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 class='CalendarBody' ><tr>"

		

		for	(i=0; i<7; i++)	{
			sHTML += "<td width='27' align='right'><B>"+ dayName[i]+"</B></td>"
		}
		sHTML +="</tr><tr>"
		

		for	( var i=1; i<=dayPointer;i++ )
		{
			sHTML += "<td>&nbsp;</td>"
		}
	
		for	( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
		{
			dayPointer++;
			sHTML += "<td align=right>"

			var sStyle="CalendarNormalDay"; //regular day

			if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)) //today
			{ sStyle = "CalendarCurrentDay"; } 
			else if	(dayPointer % 7 == (startAt * -1) +1) //end-of-the-week day
			{ sStyle = "CalendarEndWeekday"; }

			//selected day
			if ((datePointer == odateSelected) &&	(monthSelected==omonthSelected)	&& (yearSelected==oyearSelected))
			{ sStyle += " CalendarSelectedDay"; }

			sHint = ""
			var regexp= /\"/g
			sHint=sHint.replace(regexp,"&quot;")

			dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",makeLocalDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "

			sHTML += "<a class='"+sStyle+"' "+dateMessage+" title=\"" + sHint + "\" href='javascript:dateSelected="+datePointer+";closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>"

			sHTML += ""
			if ((dayPointer+startAt) % 7 == startAt) { 
				sHTML += "</tr><tr>" 
			}
		}

		document.getElementById("content").innerHTML   = sHTML
		document.getElementById("spanMonth").innerHTML = "&nbsp;" +	monthName[monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
		document.getElementById("spanYear").innerHTML =	"&nbsp;" + yearSelected	+ "&nbsp;<IMG id='changeYear' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
	}
	
	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='calendarpop'	 class='CalendarDiv'><table width='220' class='CalendarContainer'><tr><td><table width='218)'  class='CalendarHeaderTable' ><tr><td class='CalendarTitle'><B><span id='caption'></span></B></td><td align=right><a href='javascript:hideCalendar()'><IMG SRC='"+imgDir+"close.gif' WIDTH='15' HEIGHT='13' BORDER='0' tooltip='Close the Calendar'></a></td></tr></table></td></tr><tr><td class='CalendarBody'><span id='content'></span></td></tr>")
			
		if (showToday==1)
		{
			document.write ("<tr class='CalendarToday'><td><span id='lblToday'></span></td></tr>")
		}
			
		document.write ("</table></div><div id='selectMonth' class='CalendarDiv'></div><div id='selectYear' class='CalendarDiv'></div>");
	}

	
	document.onclick = function hidecal2 () 
	{ 		
		if (!bShow)
		{
			hideCalendar()
		}
		bShow = false
	}

	if(ie)
	{
		init()
	}
	else
	{
		window.onload=init
	}
	
	function makeLocalDate(d, m, y)
	{
		sTmp = localDateFormat;
		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)
		sTmp = sTmp.replace	("<n>",padZero(m))
		sTmp = sTmp.replace	("<o>",monthName[m])
		sTmp = sTmp.replace	("yyyy",y)
		sTmp = sTmp.replace ("yy", padZero(y%100))
		return sTmp;
	}
	
	function selectText(box)
	{
		
		if(box)
		{
			checkDateFired = false;
			try
			{
				box.select();
			}
			catch(cantSelect)
			{
			}
			if(typeof(clearResults) != 'undefined')
				clearResults();
		}
		
		
	}
	
	
	function isLeapYear(year)
	{
		return (year % 4 == 0 && ( year % 100 != 0 || year % 400 ==0 ));
	}
	
	var daysofmonth   = new Array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var daysofmonthLY = new Array( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	
	
	var keyDownFired = false;
	function checkKeyDownDate(event, box)
	{
		var key = getKey(event);
		
		if(key == 100)
		{
			keyDownFired = true;
			monthSelected = monthNow + 1;
			dateSelected = dateNow;
			yearSelected = yearNow;

			populateBoxWithDate(box, monthSelected, dateSelected, yearSelected);
			return false;
		}
		
		var dateIs = getXFromValue(box.value, "d");
		var monthIs = getXFromValue(box.value, "m");
		var yearIs = getXFromValue(box.value, "y");
		
		if(dateIs == -1 || monthIs == -1 ||yearIs == -1) //don't have a good date.
			return true;
		
	
		keyDownFired = false;
		switch(key)
		{
			case 61: //+				
			case 43:
				dateIs = dateIs + 1;
				if(isLeapYear(yearIs))
				{
					if(dateIs > daysofmonthLY[monthIs - 1])
					{
						dateIs = 1;
					
						if(monthIs == 12)
						{
							monthIs = 1;
							yearIs = yearIs + 1;
						}
					}
				}
				else
				{
					if(dateIs > daysofmonth[monthIs - 1])
					{
						dateIs = 1;
					
						if(monthIs == 12)
						{
							monthIs = 1;
							yearIs = yearIs + 1;
						}
						else
						{
							monthIs = monthIs + 1;
						}
					}
				}
	
				keyDownFired = true;
				break;
				
			case 45: // -
				dateIs = dateIs - 1;
				if(dateIs < 1)
				{
					if(isLeapYear(yearIs))
					{
						if(monthIs == 1)
						{
							monthIs = 12;
							yearIs = yearIs - 1; 
						}
						else
							monthIs = monthIs - 1;
						
						dateIs = daysofmonthLY[monthIs - 1];
					}
					else
					{
						if(monthIs == 1)
						{
							monthIs = 12;
							yearIs = yearIs - 1; 
						}
						else
							monthIs = monthIs - 1;
						
						dateIs = daysofmonth[monthIs - 1];
					}
				}
				
				keyDownFired = true;
				break;
		}
		
		if(keyDownFired)
		{
			monthSelected = monthIs;
			dateSelected = dateIs;
			yearSelected = yearIs;
			populateBoxWithDate(box, monthIs, dateIs, yearIs);
			return false;
		}
		else
		{
			return true;
		}
	}
	
	
	function dateBoxKeyPressed(event, box)
	{
		
		var key = getKey(event);
			
		checkKeyDownDate(event, box);
		if(!keyDownFired) //The did NOT push +, -, or d
		{
			if(key < 32 || (key >= 33 && key < 46) || (key >= 112 && key <= 123) )
				return true;
		}
		else
			return false;
		
	}
	
	
		
	function getXFromValue(boxValue, x)
	{
		try
		{
			var formatArray = new Array();
			formatArray = localDateFormat.split(localDateSeparator);	
			var dateParts = new Array();
			dateParts = boxValue.split(localDateSeparator);
			
			if(dateParts.length == 3)
			{
				try
				{
					dateParts[2] = dateParts[2].substr(0, (dateParts[2].length - dateParts[2].indexOf(" ") + 1));
				}
				catch(badThird)
				{
				}
			}
			var dateIndex = -1;
			for(i = 0; i < dateParts.length; i++)
			{
				if(formatArray[i].indexOf(x) >= 0)
				{
					return Number(dateParts[i]);
				}
			}
			
			return dateIndex;
		}
		catch(badDate)
		{
			
		}
	}
	
	var checkDateFired = false;
	function checkDate(box, validateEmpty)
	{
		if(!validateEmpty && box.value == '')
			return;
			
		if(!checkDateFired)
		{
			var dateIs = checkNum(getXFromValue(box.value, "d"));
			var monthIs = checkNum(getXFromValue(box.value, "m"));
			var yearIs = checkNum(getXFromValue(box.value, "y"));
			
			if(!monthIs || monthIs == -1)
				monthIs = monthNow + 1;
			
			if(yearIs == -1)
				yearIs = yearNow;
			else
			{
				if(yearIs < 38)
					yearIs += 2000;
				else 
				{
					if(yearIs < 1900)
						yearIs += 1900;
				}
			}
			
			if(monthIs > 12)
				monthIs = -1;
			
			
			if(isLeapYear(yearIs) && monthIs != -1)
			{
				if(dateIs > daysofmonthLY[monthIs -1])
					dateIs = -1;
			}
			else
			{
				if(dateIs > daysofmonth[monthIs -1])
					dateIs = -1;
			}
			
			if(yearIs > 9999)
			{
				yearIs = -1;
			}
			
			if(dateIs == -1 || monthIs == -1 || yearIs == -1) //don't have a good date.
			{
				alert("Invalid Date");
				populateBoxWithDate(box, monthNow + 1, dateNow, yearNow)
				selectText(box)
			}
			else
			{
				populateBoxWithDate(box, monthIs, dateIs, yearIs)
			}
			checkDateFired = true;
		}
	}

	function checkNum(x)
	{
		if(!x)
			return -1;
		if(isNaN(x))
			return -1;
		
		return Number(x);
	}


	
	function populateBoxWithDate(box, monthIs, dateIs, yearIs)
	{
		var sSelectedDateForDayName = new Date(monthIs + '/' + dateIs  + '/' + yearIs);
		
		if(firstAvailableDate > sSelectedDateForDayName)
		{
			alert("Date violates your first available event date");
			monthIs = firstAvailableDate.getMonth() + 1;
			dateIs = firstAvailableDate.getDate();
			yearIs = firstAvailableDate.getFullYear();
		}
		
		if(lastAvailableDate < sSelectedDateForDayName)
		{
			alert("Date violates your last available event date");
			monthIs = lastAvailableDate.getMonth() + 1;
			dateIs = lastAvailableDate.getDate();
			yearIs = lastAvailableDate.getFullYear();
		}
			
		sSelectedDateForDayName = new Date(monthIs + '/' + dateIs  + '/' + yearIs); 
			
		box.value =	 makeLocalDate(dateIs,monthIs,yearIs) + ' ' + dayName[(sSelectedDateForDayName.getDay()-startAt==-1)?6:(sSelectedDateForDayName.getDay()-startAt)]
		
		if(document.getElementById('hdlastAttendeeBookDate'))
			document.getElementById('hdlastAttendeeBookDate').value =  makeLocalDate(dateIs, monthIs, yearIs);
			
		if(typeof(attemptClear) != 'undefined')
			attemptClear();
		return;
	}
	

