
var disablePropertyCalendarArray	=new Array(false,false,false,false,false);


//Const for arrival date name and departure date name
var CONST_ARRIVAL_DATE_ARRAY		=new Array('arriveday','arriveday1','arriveday2','arriveday3','arriveday4');
var CONST_DEPARTURE_DATE_ARRAY		=new Array('departday','departday1','departday2','departday3','departday4');

//template storage for current arrival date and departure date
var CurrentArrivalDateArray			=new Array(new Date(),new Date(),new Date(),new Date(),new Date());
var CurrentDepartureDateArray		=new Array(new Date(),new Date(),new Date(),new Date(),new Date());


//arrive day and depart date object
var ArrivalDateObjArray			=new Array(5);
var DepartureDateObjArray		=new Array(5);

var when_my_date_change;

/**
 *  Get date name index by a specified date name
 *  The specified date name might be a arrival date name, or a departure date name in the array
 */
function getDateNameIndex(dateName){
	if (dateName==null || dateName=="")
		return -1;
	
	for (var i=0; i<CONST_ARRIVAL_DATE_ARRAY.length; i++){
		var arriveDateName	=CONST_ARRIVAL_DATE_ARRAY[i];
		var departDateName	=CONST_DEPARTURE_DATE_ARRAY[i];
		if (arriveDateName==dateName || departDateName==dateName)
			return i;
	}	
	
	return -1;
}


/**
 *  Get arrival date name by a specified date name
 *  The specified date name might be a arrival date name, or a departure date name in the array
 */
function getArrivalDateName(dateName){
	var nameIndex	=getDateNameIndex(dateName);
	if (nameIndex<0)
		return "";
	
	return CONST_ARRIVAL_DATE_ARRAY[nameIndex];
}

/**
 *  Get current arrival date by a specified date name
 *  The specified date name might be a arrival date name, or a departure date name in the array
 */
function getCurrentArrivalDate(dateName){
	
	var nameIndex	=getDateNameIndex(dateName);
	if (nameIndex<0)
		return new Date();
	
	return CurrentArrivalDateArray[nameIndex];
}
function setCurrentArrivalDate(dateName,date){
	var nameIndex	=getDateNameIndex(dateName);
	if (nameIndex<0)
		return;
	
	CurrentArrivalDateArray[nameIndex]	=date;
}



/**
 *  Get departure date name by a specified date name
 *  The specified date name might be a arrival date name, or a departure date name in the array
 */
function getDepartureDateName(dateName){

	var nameIndex	=getDateNameIndex(dateName);
	if (nameIndex<0)
		return "";
	
	return CONST_DEPARTURE_DATE_ARRAY[nameIndex];
}


/**
 *  Get current departure date by a specified date name
 *  The specified date name might be a departure date name, or a departure date name in the array
 */
function getCurrentDepartureDate(dateName){
	var nameIndex	=getDateNameIndex(dateName);
	if (nameIndex<0)
		return new Date();
	
	return CurrentDepartureDateArray[nameIndex];
}
function setCurrentDepartureDate(dateName,date){
	var nameIndex	=getDateNameIndex(dateName);
	if (nameIndex<0)
		return;
	
	CurrentDepartureDateArray[nameIndex]	=date;
}


function setDateObjValue(dateName, val){
	if (!dateName){
		return;
	}
	
	var dateObj = document.getElementById(dateName);
	var dateObj2 = document.getElementById(dateName+"_currDate");
	
	if (dateObj!=null){
		dateObj.value = val;
	}
	if (dateObj2!=null){
		dateObj2.value = val;
	}
}

//clear dates from 'Any' to blank
function clearAny(){
	
	for (var i=0; i<CONST_ARRIVAL_DATE_ARRAY.length; i++){
		var dateName = CONST_ARRIVAL_DATE_ARRAY[i];
		var dateObj  =document.getElementById(dateName);
		if (dateObj!=null && dateObj.value=="Any"){
			setDateObjValue(dateName, "");
		}
	}

	for (var i=0; i<CONST_DEPARTURE_DATE_ARRAY.length; i++){
		var dateName = CONST_DEPARTURE_DATE_ARRAY[i];
		var dateObj  =document.getElementById(dateName);
		if (dateObj!=null && dateObj.value=="Any"){
			setDateObjValue(dateName, "");
		}
	}
	
}

//reset dates from blank to any
function resetAny(){
	
	return;
	
	for (var i=0; i<CONST_ARRIVAL_DATE_ARRAY.length; i++){
		var dateName = CONST_ARRIVAL_DATE_ARRAY[i];
		var dateObj  =document.getElementById(dateName);
		if (dateObj!=null && dateObj.value==""){
			setDateObjValue(dateName, "Any");
		}
	}

	for (var i=0; i<CONST_DEPARTURE_DATE_ARRAY.length; i++){
		var dateName = CONST_DEPARTURE_DATE_ARRAY[i];
		var dateObj  =document.getElementById(dateName);
		if (dateObj!=null && dateObj.value==""){
			setDateObjValue(dateName, "Any");
		}
	}
	
}



/**
 *  Get current arrival/departure date object by a specified date name
 *  The specified date name might be a departure date name, or a departure date name in the array
 */
function getArrivalDateObj(dateName){
	var nameIndex	=getDateNameIndex(dateName);
	if (nameIndex<0)
		return null;
	
	var obj	=ArrivalDateObjArray[nameIndex];
	
	if (obj==null){

		obj	=document.getElementById(getArrivalDateName(dateName)+"_currDate");		
		ArrivalDateObjArray[nameIndex]	=obj;
	}
	return obj;
}

function getDepartureDateObj(dateName){
	var nameIndex	=getDateNameIndex(dateName);
	if (nameIndex<0)
		return null;
	
	var obj	=DepartureDateObjArray[nameIndex];
	if (obj==null){
		obj	=document.getElementById(getDepartureDateName(dateName)+"_currDate");		
		DepartureDateObjArray[nameIndex]	=obj;
	}
	return obj;
}


function isDisablePropertyCalendarArray(dateName){


	var nameIndex	=getDateNameIndex(dateName);
	if (nameIndex<0)
		return false;

	
	return disablePropertyCalendarArray[nameIndex];
}






var isCalendarClick			=false;
var calendarSize			=10;

// Customizable variables
var DefaultDateFormat = 'MM/DD/YYYY'; // If no date format is supplied, this will be used instead
var HideWait = 200; // Number of seconds before the calendar will disappear
var Y2kPivotPoint = 76; // 2-digit years before this point will be created in the 21st century
var UnselectedMonthText = ''; // Text to display in the 1st month list item when the date isn't required
var FontSize = 13; // In pixels
var FontFamily = 'Tahoma';
var CellWidth = 25;
var CellHeight = 22;
var ImageURL = 'zohut/js/calendar/calendar.jpg';
var NextURL = 'zohut/js/calendar/next.gif';
var PrevURL = 'zohut/js/calendar/prev.gif';
var CalBGColor = 'white';
var TopRowBGColor = 'buttonface';
//var DayBGColor = '#E27F9C';
var DayBGColor = '#f5f5f5';
var DayBGColor_disabled = '#aaaaaa';

var default_font_size=";font-size: 13px;";

var calendarTable		="";


// Global variables
var ZCounter = 100;
var Today = new Date();

var WeekDays = new Array('S','M','T','W','T','F','S');
var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var MonthNames = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

var CalendarBuilt	=false;

// Write out the stylesheet definition for the calendar
with (document) {
   writeln('<style>');
   writeln('td.calendarDateInput {letter-spacing:normal;line-height:normal;font-family:' + FontFamily + ',Sans-Serif;font-size:' + FontSize + 'px;}');
   writeln('select.calendarDateInput {letter-spacing:.06em;font-family:Verdana,Sans-Serif;font-size:11px;}');
   writeln('input.calendarDateInput {letter-spacing:.06em;font-family:Verdana,Sans-Serif;font-size:11px;}');
   writeln('</style>');
}

function setCalendarSize(size){
	calendarSize	=size;
}	


// Only allows certain keys to be used in the date field
function YearDigitsOnly(e) {
   var KeyCode = (e.keyCode) ? e.keyCode : e.which;
   return ((KeyCode == 8) // backspace
        || (KeyCode == 9) // tab
        || (KeyCode == 37) // left arrow
        || (KeyCode == 39) // right arrow
        || (KeyCode == 46) // delete
        || ((KeyCode > 47) && (KeyCode < 58)) // 0 - 9
   );
}

// Gets the absolute pixel position of the supplied element
function GetTagPixels(StartTag, Direction) {
   var PixelAmt = (Direction == 'LEFT') ? StartTag.offsetLeft : StartTag.offsetTop;
   while ((StartTag.tagName != 'BODY') && (StartTag.tagName != 'HTML')) {
      StartTag = StartTag.offsetParent;
      PixelAmt += (Direction == 'LEFT') ? StartTag.offsetLeft : StartTag.offsetTop;
   }
   return PixelAmt;
}

// Is the specified select-list behind the calendar?
function BehindCal(SelectList, CalLeftX, CalRightX, CalTopY, CalBottomY, ListTopY) {
   var ListLeftX = GetTagPixels(SelectList, 'LEFT');
   var ListRightX = ListLeftX + SelectList.offsetWidth;
   var ListBottomY = ListTopY + SelectList.offsetHeight;
   return (((ListTopY < CalBottomY) && (ListBottomY > CalTopY)) && ((ListLeftX < CalRightX) && (ListRightX > CalLeftX)));
}

// For IE, hides any select-lists that are behind the calendar
function FixSelectLists(Over) {
	
   if (navigator.appName == 'Microsoft Internet Explorer') {
      var CalDiv = this.getCalendar();
      var CalLeftX = CalDiv.offsetLeft;
      var CalRightX = CalLeftX + CalDiv.offsetWidth;
      var CalTopY = CalDiv.offsetTop;
      var CalBottomY = CalTopY + (CellHeight * 9);
      var FoundCalInput = false;
      formLoop :
      for (var j=this.formNumber;j<document.forms.length;j++) {
         for (var i=0;i<document.forms[j].elements.length;i++) {
         	try{
            	if (typeof document.forms[j].elements[i].type == 'string') {
               		if ((document.forms[j].elements[i].type == 'hidden') && (document.forms[j].elements[i].name == this.hiddenFieldName)) {
                  		FoundCalInput = true;
                  		i += 3; // 3 elements between the 1st hidden field and the last year input field
               		}
               		if (FoundCalInput) {
                  		if (document.forms[j].elements[i].type.substr(0,6) == 'select') {
                     		ListTopY = GetTagPixels(document.forms[j].elements[i], 'TOP');
                     		if (ListTopY < CalBottomY) {
                        		if (BehindCal(document.forms[j].elements[i], CalLeftX, CalRightX, CalTopY, CalBottomY, ListTopY)) {
                           		document.forms[j].elements[i].style.visibility = (Over) ? 'hidden' : 'visible';
                        		}
                     		}
                     		else break formLoop;
                  		}
               		}
            	}
        	}catch(e){
            		//jxbjxb
        	}
         }
      }
   }
}


//if current date is a reserved date by customer
function isReservedDate(year,month,day,formName){
try{	

	//var xx=isDisablePropertyCalendarArray(formName);

	//propertyCalendar is an array of integer, something like this:
	//var propertyCalendar =new Array(0,0,1,1,1,1,1);
	if (propertyCalendar==null || isDisablePropertyCalendarArray(formName))
		return false;


	var newDate	=new Date();
	newDate.setDate(1);     //initialize to 1
	newDate.setYear(year);
	newDate.setMonth(month);
	newDate.setDate(day);
	
	return isReservedDate2(newDate,formName);
}catch(e){
	return false;
}	
}


//if current date is a reserved date by customer
function isReservedDate2(newDate,formName){

try{	
	//propertyCalendar is an array of integer, something like this:
	//var propertyCalendar =new Array(0,0,1,1,1,1,1);	
	if (propertyCalendar==null || isDisablePropertyCalendarArray(formName)){
		return false;
	}

	
		
	//property start date is a start date for the property calendar, the first day of the calendar
	var startDate	=getDate_ee(propertyStartDate,"MM/DD/YYYY");
	var dateDiffer	=parseInt((newDate.getTime()-startDate.getTime())/24/3600/1000);

	
	if (dateDiffer<0)
		return false;
	if (dateDiffer>propertyCalendar.length-1)
		return false;
	
	return propertyCalendar[dateDiffer]==0;
}catch(e){
	return false;
}		
}




//date before today is forbidden date, jxb
function isForbiddenDate(year, month, day, formName){
	
	var newDate	=new Date();
	newDate.setDate(1);     //initialize to 1
	newDate.setYear(year);
	newDate.setMonth(month);
	newDate.setDate(day);
	
	return isForbiddenDate2(newDate,formName);
}

//date before today is forbidden date, jxb
function isForbiddenDate2(newDate,formName){
	
	var startDate	=Today;
	
	return (newDate.getTime()<startDate.getTime());
}



//if current date is blocked
function isBlockedDate(year, month, day, formName){

	year	=getRealYear_ee(year);

	
	var newDate	=new Date();
	newDate.setDate(1);     //initialize to 1
	newDate.setYear(year);
	newDate.setMonth(month);
	newDate.setDate(day);
	
	return isBlockedDate2(newDate,formName);
}


//if current date is blocked
function isBlockedDate2(newDate,formName){
	

	var arriveDateObj	=getArrivalDateObj(formName);
	var departDateObj	=getDepartureDateObj(formName);

	//if is departure date, it will always > arrival date + 1
	if (formName==getDepartureDateName(formName)){
		var arrivalDate	=getCurrentArrivalDate(formName);
		if (newDate.getTime() < (arrivalDate.getTime() + ONEDAY * 2)){
			return true;
		}
	}
	


	if (arriveDateObj!=null && departDateObj!=null){

		
		var arriveDate	=arriveDateObj.value;
		var departDate	=departDateObj.value;
		
		//test if current date is blocked
		if (formName==getDepartureDateName(formName)){
			if (isBlockedDepartureDate(arriveDate,newDate)){
				return true;
			}
		}
		if (formName==getArrivalDateName(formName)){
		
			if (isBlockedArrivalDate(newDate,departDate))
				return true;

		}
	}
	
	return false;	
}



function isSameDate(date1, date2){
	if (date1==null || date2==null)
		return false;
	
	var year1	=date1.getYear();
	var month1	=date1.getMonth();
	var day1	=date1.getDate();


	var year2	=date2.getYear();
	var month2	=date2.getMonth();
	var day2	=date2.getDate();

	
	return (year1==year2) && (month1==month2) && (day1==day2);
}

function addDay(date, days){
		var d	=date.getTime() + 86400000 * days;
		return new Date(d);
}

function dateDiffer(startDate, endDate){
		var startD	=startDate.getTime();
		var endD	=endDate.getTime();
		var d	=(endD-startD)/86400000;
		return d;
}
	
	

function isPickedDate(year, month, day, formName){


	var newDate	=new Date();
	newDate.setDate(1);     //initialize to 1
	newDate.setYear(year);
	newDate.setMonth(month);
	newDate.setDate(day);
	
	//store arrival date
	if (formName==getArrivalDateName(formName)){

		return isSameDate(newDate,getCurrentArrivalDate(formName)); //(newDate.getTime()==CurrentArrivalDate.getTime());

	}else if (formName==getDepartureDateName(formName)){

		return isSameDate(newDate,getCurrentDepartureDate(formName)); //(newDate.getTime()==CurrentDepartureDate.getTime());

	}

	return false;
}	


//hide a calendar
function closeAllCalendars(){
try{
	if (!isCalendarClick){
		for (var i=0; i<CONST_ARRIVAL_DATE_ARRAY.length; i++){
			closeCalendar(CONST_ARRIVAL_DATE_ARRAY[i]);
			closeCalendar(CONST_DEPARTURE_DATE_ARRAY[i]);
		}
	}
	isCalendarClick	=false;
}catch(e){
}
}


function closeCalendar(formName){
	try{
		if (formName==null || formName=="")
			return;
		
		var obj	=formName+'_Object';
		eval(obj+ '.hide();');

	}catch(e){
	}
}

//if current formName is ArrivalCalendar, then close DepartureCalendar, and vice versa
function closeNotCalendar(formName){
	if (formName==null || formName=="")
		return;
	
	if (formName==getArrivalDateName(formName))
		closeCalendar(getDepartureDateName(formName));

	else if (formName==getDepartureDateName(formName))
		closeCalendar(getArrivalDateName(formName));
}



// Displays a message in the status bar when hovering over the calendar days
function DayCellHover(Cell, Over, Color, HoveredDay) {
	

	//jxb
	if (isForbiddenDate(this.yearValue,this.monthIndex,HoveredDay,this.hiddenFieldName)||
	    isBlockedDate(this.yearValue,this.monthIndex,HoveredDay,this.hiddenFieldName)){

   			Cell.style.backgroundColor = Color;
   			Cell.style.border = '1px solid white';
    
    	}else if (isReservedDate(this.yearValue,this.monthIndex,HoveredDay,this.hiddenFieldName)){

   			Cell.style.backgroundColor = Color;
   			Cell.style.border = '1px solid white';
    			
   	}else{
            
   			Cell.style.backgroundColor = (Over) ? DayBGColor : Color;
   			Cell.style.border = (Over)? '1px solid darkred':'1px solid white';
   	}

   if (Over) {
      if (!isForbiddenDate(Today,this.hiddenFieldName) && (this.yearValue == Today.getFullYear()) && (this.monthIndex == Today.getMonth()) && (HoveredDay == Today.getDate()) &&
          !isReservedDate(Today,this.hiddenFieldName) && (this.yearValue == Today.getFullYear()) && (this.monthIndex == Today.getMonth()) && (HoveredDay == Today.getDate()) &&
          !isBlockedDate(Today,this.hiddenFieldName) && (this.yearValue == Today.getFullYear()) && (this.monthIndex == Today.getMonth()) && (HoveredDay == Today.getDate())
          ) 
      	self.status = 'Click to select today';
      else {
         var Suffix = HoveredDay.toString();
         switch (Suffix.substr(Suffix.length - 1, 1)) {
            case '1' : Suffix += (HoveredDay == 11) ? 'th' : 'st'; break;
            case '2' : Suffix += (HoveredDay == 12) ? 'th' : 'nd'; break;
            case '3' : Suffix += (HoveredDay == 13) ? 'th' : 'rd'; break;
            default : Suffix += 'th'; break;
         }
         
         if (isForbiddenDate(this.yearValue,this.monthIndex,HoveredDay,this.hiddenFieldName))
         	self.status = 'Forbiden Date: ' + this.monthName + ' ' + Suffix;
         else if (isBlockedDate(this.yearValue,this.monthIndex,HoveredDay,this.hiddenFieldName))
         	self.status = 'Blocked Date: ' + this.monthName + ' ' + Suffix;
         else if (isReservedDate(this.yearValue,this.monthIndex,HoveredDay,this.hiddenFieldName))
         	self.status = 'Reserved Date: ' + this.monthName + ' ' + Suffix;
         else
         	self.status = 'Click to select ' + this.monthName + ' ' + Suffix;
      }
   }
   else self.status = '';
   return true;
}




function formatDate(date){
	if (isNaN(date))
		date	=new Date();
	
	var Year = takeYear(date);
	var Month = leadingZero(date.getMonth()+1);
	var Day = leadingZero(date.getDate());
	
	return ""+Month+"/"+Day+"/"+Year;
}


function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

function leadingZero(nr)
{
	if (nr < 10) nr = "0" + nr;
	return nr;
}


// Sets the form elements after a day has been picked from the calendar
function userChangeDate(date) {
	

   if (date==null || date=="" || date.toLowerCase()=="any"){
	   document.getElementById(this.hiddenFieldName).value	="Any";
	   document.getElementById(this.hiddenFieldName + '_currDate').value	="Any";
	   resetAny();
	   return;
   }
   	

   var newDate=parseDate_ee(date);
   		
	
   var year	=takeYear(newDate);
   var mon	=newDate.getMonth();
   var day	=newDate.getDate();


   this.setPicked(year,mon,day);


   var currentD	= formatDate(newDate);

	
   this.triggerDate(year,mon,day,currentD);
   
}	



// Sets the form elements after a day has been picked from the calendar
function PickDisplayDay(ClickedDay) {

   this.show();

   var year	=Number(this.displayed.yearValue);
   var mon	=Number(this.displayed.monthIndex);
   var day	=Number(ClickedDay);


   this.setPicked(year,mon,day);


   //current system date
   var currentD	=document.getElementById(this.hiddenFieldName).value; //this can not run in FireFox
   //var currentD	= eval(this.hiddenFieldName+".value");

	
   this.triggerDate(year,mon,day,currentD);
}


  	

function triggerDateChange(year,mon,day,currentD){



   var formName	=this.hiddenFieldName;
   
   //show current system date to customer
   document.getElementById(formName + '_currDate').value	=currentD;



    var currentDate			=new Date(year,mon,day);
    if (this.hiddenFieldName==getArrivalDateName(formName))
    {
    	setCurrentArrivalDate(formName,currentDate);
    	
    }
    else if (this.hiddenFieldName==getDepartureDateName(formName))
    {
    	setCurrentDepartureDate(formName, currentDate);
    	
    }


    //store arrival date
    if (this.hiddenFieldName==getArrivalDateName(formName)){
	
			var currArrivalDate	=getCurrentArrivalDate(formName);
			var currDepartureDate	=getCurrentDepartureDate(formName);

			
			var minStay		=getMinStay_arrival_ee(currArrivalDate);
			
			if (dateDiffer(currArrivalDate,currDepartureDate)<minStay){
				
				var currDepartureDate	=addDay(currArrivalDate,minStay);
				setCurrentDepartureDate(formName,currDepartureDate);

				//if current new departure date is not available, will make it ANY
				var departureDateName	=getDepartureDateName(formName);
								
				if (isBlockedDate2(currDepartureDate,departureDateName) ||
				    isReservedDate2(currDepartureDate,departureDateName)){
					document.getElementById(getDepartureDateName(formName)).value	="Any";
					document.getElementById(getDepartureDateName(formName)+"_currDate").value	="Any";
					return;
				}

				year	=takeYear(currDepartureDate);
				mon	=currDepartureDate.getMonth();
				day	=currDepartureDate.getDate();
				
				eval(getDepartureDateName(formName) + '_Object.setPicked(' + year + ',' + mon + ',' + day + ')');
				document.getElementById(getDepartureDateName(formName)+"_currDate").value	=formatDate(currDepartureDate);

			}else{
				//year	=CurrentDepartureDate.getYear();
				//mon   	=CurrentDepartureDate.getMonth();
				//day		=CurrentDepartureDate.getDate();
				//eval(CONST_DEPARTURE_DATE + '_Object.setPicked(' + year + ',' + mon + ',' + day + ')');
			}
	}


}


// Builds the HTML for the calendar days
function BuildCalendarDays() {



			if(this.objName == "departday_Object" || this.objName == "departday2_Object" || this.objName == "departday3_Object" || this.objName == "departday4_Object")
      {
				var formName;
	      if(this.objName == "departday_Object")
	      	formName = getArrivalDateName("arriveday");
	      else if(this.objName == "departday2_Object")
	        formName = getArrivalDateName("arriveday2");
	      else if(this.objName == "departday3_Object")
	        formName = getArrivalDateName("arriveday3");
	      else if(this.objName == "departday4_Object")
	      	formName = getArrivalDateName("arriveday4");
				
				var obj = document.getElementById(formName);
				var tempDate = parseDate_ee(obj.value);
				
				setCurrentArrivalDate(formName, tempDate);
			}
	
			
   var isLc1	=true;

 
   var Rows = 5;
   if (((this.displayed.dayCount == 31) && (this.displayed.firstDay > 4)) || ((this.displayed.dayCount == 30) && (this.displayed.firstDay == 6))) Rows = 6;
   else if ((this.displayed.dayCount == 28) && (this.displayed.firstDay == 0)) Rows = 4;
   var HTML = '<table width="' + (CellWidth * 7) + '" cellspacing="0" cellpadding="1" style="cursor:default" >';
   for (var j=0;j<Rows;j++) {
      HTML += '<tr>';
      for (var i=1;i<=7;i++) {
         Day = (j * 7) + (i - this.displayed.firstDay);
         if ((Day >= 1) && (Day <= this.displayed.dayCount)) {

   	

          
            //jxb
            if (isForbiddenDate(this.displayed.yearValue,this.displayed.monthIndex, Day,this.hiddenFieldName) ||
            	isBlockedDate(this.displayed.yearValue,this.displayed.monthIndex, Day,this.hiddenFieldName)
                ){
                	if(this.objName == "departday_Object" || this.objName == "departday2_Object" || this.objName == "departday3_Object" || this.objName == "departday4_Object")
            			{
            				var formName;
            				if(this.objName == "departday_Object")
            					formName = getArrivalDateName("arriveday");
            				else if(this.objName == "departday2_Object")
            					formName = getArrivalDateName("arriveday2");
            				else if(this.objName == "departday3_Object")
            					formName = getArrivalDateName("arriveday3");
            				else if(this.objName == "departday4_Object")
            					formName = getArrivalDateName("arriveday4");
            					
            				var newDate = getCurrentArrivalDate(formName);

            				var year1	= takeYear(newDate);
   									var mon1 = newDate.getMonth();
   									var day1 = newDate.getDate();
   						
   								if(day1 == Day){	
   										TextStyle = 'color:'+'#000000'+';border:1px solid white;padding:0px;font-weight: bold;'+default_font_size;
            				}
            				else{
            					TextStyle = 'color:'+DayBGColor_disabled+';border:1px solid white;padding:0px;'+default_font_size;
            				}
            		}
            		else
            			TextStyle = 'color:'+DayBGColor_disabled+';border:1px solid white;padding:0px;'+default_font_size;
                	
                	
            //	TextStyle = 'color:'+DayBGColor_disabled+';border:1px solid white;padding:0px;';
            	BackColor	=CalBGColor;
            	HTML += '<td align="center" height='+CellHeight+' class="calendarGray" style="cursor:default;height:' + CellHeight + ';width:' + CellWidth + ';' + TextStyle + ';background-color:' + BackColor + '"  onClick="isCalendarClick=true;" onMouseOver="return ' + this.objName + '.displayed.dayHover(this,true,\'' + BackColor + '\',' + Day + ')" onMouseOut="return ' + this.objName + '.displayed.dayHover(this,false,\'' + BackColor + '\')">' + Day + '</td>';
				
				//var x1=isForbiddenDate(this.displayed.yearValue,this.displayed.monthIndex, Day,this.hiddenFieldName);
				//var x2=isBlockedDate(this.displayed.yearValue,this.displayed.monthIndex, Day,this.hiddenFieldName);
				
        	}else if (isReservedDate(this.displayed.yearValue,this.displayed.monthIndex, Day,this.hiddenFieldName)){
            	TextStyle = 'color:#FF0000;border:1px solid white;padding:0px;text-decoration:line-through;font-weight: normal;'+default_font_size;
            	BackColor	=CalBGColor;
            	HTML += '<td align="center" height='+CellHeight+' style="cursor:default;height:' + CellHeight + ';width:' + CellWidth + ';' + TextStyle + ';background-color:' + BackColor + '"  onClick="isCalendarClick=true;" onMouseOver="return ' + this.objName + '.displayed.dayHover(this,true,\'' + BackColor + '\',' + Day + ')" onMouseOut="return ' + this.objName + '.displayed.dayHover(this,false,\'' + BackColor + '\')">' + Day + '</td>';
				
				
			//is picked date
        	}else if ((this.displayed.yearValue == this.picked.yearValue) && (this.displayed.monthIndex == this.picked.monthIndex) && (Day == this.picked.day)) {
               TextStyle = 'color:black; border:1px solid darkred;padding:0px;'+default_font_size;
               BackColor = DayBGColor;
               HTML += 	'<td align="center" height='+CellHeight+
               			' class="calendarBlack" style="cursor:default;height:' + CellHeight + 
               			';width:' + CellWidth + ';' + 
               			TextStyle + ';background-color:' + 
               			BackColor + '" onClick="isCalendarClick=true; ' + 
               			this.objName + '.pickDay(' + Day 
               			+ ');" onMouseOver="self.status =\'Current selected date\';return true;" onMouseOut="return true;">' + Day + '</td>';
            }
            else if(isLc1){
               //TextStyle = 'color:black;'
               TextStyle = 'border:1px solid white;padding:0px;'+default_font_size;
               BackColor = CalBGColor;
            	//if ((this.displayed.yearValue == Today.getFullYear()) && (this.displayed.monthIndex == Today.getMonth()) && (Day == Today.getDate())) 
            	//	TextStyle = 'color:black; border:1px solid darkred;padding:0px;';
            	HTML += '<td align="center" height='+CellHeight+' class="calendarBlack" style="cursor:default;height:' + CellHeight + ';width:' + CellWidth + ';' + TextStyle + ';background-color:' + BackColor + '" onClick="isCalendarClick=true; ' + this.objName + '.pickDay(' + Day + ');" onMouseOver="return ' + this.objName + '.displayed.dayHover(this,true,\'' + BackColor + '\',' + Day + ')" onMouseOut="return ' + this.objName + '.displayed.dayHover(this,false,\'' + BackColor + '\')">' + Day + '</td>';
            }
         }
         else HTML += '<td class="calendarDateInput" style="height:' + CellHeight + '">&nbsp;</td>';
      }
      HTML += '</tr>';
   }
   
  
  
   
   if (this.CalendarBuilt){
   		//jxb, if last month is forbidden, will disable Preview Btn Arrow:
   		var newDate	=new Date();
   
   		//first day of this month
   		newDate.setDate(1);
   		newDate.setYear(this.displayed.yearValue);
   		newDate.setMonth(this.displayed.monthIndex);
   
   		//last day of preview month
   		newDate.setTime(newDate.getTime()-24*3600);


		//previous column
		var prevKey		=this.hiddenFieldName
		var prevTdName	=prevKey +"_Previous_ID";
		var prevTd		= document.getElementById(prevTdName);
		
   		if (isForbiddenDate2(newDate,this.hiddenFieldName)){
			document.getElementById(prevKey+"_prevBtn").style.display="none";
			
			prevTd.disabled		=true;

		}else{
			document.getElementById(prevKey+"_prevBtn").style.display="";

			prevTd.disabled		=false;
			
		}
  }


   this.CalendarBuilt	=true;
   
   return HTML += '</table>';
}

// Determines which century to use (20th or 21st) when dealing with 2-digit years
function GetGoodYear(YearDigits) {
   if (YearDigits.length == 4) return YearDigits;
   else {
      var Millennium = (YearDigits < Y2kPivotPoint) ? 2000 : 1900;
      return Millennium + parseInt(YearDigits,10);
   }
}

// Returns the number of days in a month (handles leap-years)
function GetDayCount(SomeYear, SomeMonth) {
   return ((SomeMonth == 1) && ((SomeYear % 400 == 0) || ((SomeYear % 4 == 0) && (SomeYear % 100 != 0)))) ? 29 : MonthDays[SomeMonth];
}

// Highlights the buttons
function VirtualButton(Cell, ButtonDown) {
   if (ButtonDown) {
      Cell.style.borderLeft = 'buttonshadow 1px solid';
      Cell.style.borderTop = 'buttonshadow 1px solid';
      Cell.style.borderBottom = 'buttonhighlight 1px solid';
      Cell.style.borderRight = 'buttonhighlight 1px solid';
   }
   else {
      Cell.style.borderLeft = 'buttonhighlight 1px solid';
      Cell.style.borderTop = 'buttonhighlight 1px solid';
      Cell.style.borderBottom = 'buttonshadow 1px solid';
      Cell.style.borderRight = 'buttonshadow 1px solid';
   }
}

// Mouse-over for the previous/next month buttons
function NeighborHover(Cell, Over, DateObj) {
   if (Over) {
      VirtualButton(Cell, false);
      self.status = 'Click to view ' + DateObj.fullName;
   }
   else {
      Cell.style.border = 'buttonface 1px solid';
      self.status = '';
   }
   return true;
}

// Adds/removes days from the day list, depending on the month/year
function FixDayList(DayList, NewDays) {
   var DayPick = DayList.selectedIndex + 1;
   if (NewDays != DayList.length) {
      var OldSize = DayList.length;
      for (var k=Math.min(NewDays,OldSize);k<Math.max(NewDays,OldSize);k++) {
         (k >= NewDays) ? DayList.options[NewDays] = null : DayList.options[k] = new Option(k+1, k+1);
      }
      DayPick = Math.min(DayPick, NewDays);
      DayList.options[DayPick-1].selected = true;
   }
   return DayPick;
}

// Resets the year to its previous valid value when something invalid is entered
function FixYearInput(YearField) {
   var YearRE = new RegExp('\\d{' + YearField.defaultValue.length + '}');
   if (!YearRE.test(YearField.value)) YearField.value = YearField.defaultValue;
}

// Displays a message in the status bar when hovering over the calendar icon
function CalIconHover(Over) {
   var Message = (this.isShowing()) ? 'hide' : 'show';
   self.status = (Over) ? 'Click to ' + Message + ' the calendar' : '';
   return true;
}

// Starts the timer over from scratch
function CalTimerReset() {
try{
   eval('clearTimeout(' + this.timerID + ')');
   eval(this.timerID + '=setTimeout(\'' + this.objName + '.show()\',' + (HideWait * 1000) + ')');
}catch(e){
}
}

// The timer for the calendar
function DoTimer(CancelTimer) {
try{
   if (CancelTimer) eval('clearTimeout(' + this.timerID + ')');
   else {
      eval(this.timerID + '=null');
      this.resetTimer();
   }
}catch(e){
}   
}


// hide the calendar
function HideCalendar() {
   if (this.isShowing()) {
      var StopTimer = true;
      this.getCalendar().style.zIndex = --ZCounter;
      this.getCalendar().style.visibility = 'hidden';
      this.fixSelects(false);
   }
}



// Show or hide the calendar
function ShowCalendar() {
  	
   if (this.isShowing()) {
      var StopTimer = true;
      this.getCalendar().style.zIndex = --ZCounter;
      this.getCalendar().style.visibility = 'hidden';
      this.fixSelects(false);
   }
   else {

   	  closeNotCalendar(this.hiddenFieldName);
	  
	  //jxb xxxx: Rebuild the calendar with current month and year
	  var obj	=document.getElementById(this.hiddenFieldName+"_currDate");
	  
	  if (obj){
	  
	  		
			var date	=parseDate_ee(obj.value);
			if (date!=null){
				var year	=date.getYear();
				year 	= year % 100;
				year += (year < 38) ? 2000 : 1900;				
				var mon		=date.getMonth();
			    this.setDisplayed(year,mon);
		    }
	   }	  
	  	
      var StopTimer = false;
      this.fixSelects(true);
      this.getCalendar().style.zIndex = ++ZCounter;
      this.getCalendar().style.visibility = 'visible';
   }
   this.handleTimer(StopTimer);
   self.status = '';
}

// Hides the input elements when the "blank" month is selected
function SetElementStatus(Hide) {
   this.getDayList().style.visibility = (Hide) ? 'hidden' : 'visible';
   this.getYearField().style.visibility = (Hide) ? 'hidden' : 'visible';
   this.getCalendarLink().style.visibility = (Hide) ? 'hidden' : 'visible';
}

// Sets the date, based on the month selected
function CheckMonthChange(MonthList) {
   var DayList = this.getDayList();
   if (MonthList.options[MonthList.selectedIndex].value == '') {
      DayList.selectedIndex = 0;
      this.hideElements(true);
      this.setHidden('');
   }
   else {
      this.hideElements(false);
      if (this.isShowing()) {
         this.resetTimer(); // Gives the user more time to view the calendar with the newly-selected month
         this.getCalendar().style.zIndex = ++ZCounter; // Make sure this calendar is on top of any other calendars
      }
      var DayPick = FixDayList(DayList, GetDayCount(this.picked.yearValue, MonthList.options[MonthList.selectedIndex].value));
      this.setPicked(this.picked.yearValue, MonthList.options[MonthList.selectedIndex].value, DayPick);
   }
}

// Sets the date, based on the day selected
function CheckDayChange(DayList) {
   if (this.isShowing()) this.show();
   this.setPicked(this.picked.yearValue, this.picked.monthIndex, DayList.selectedIndex+1);
}

// Changes the date when a valid year has been entered
function CheckYearInput(YearField) {
   if ((YearField.value.length == YearField.defaultValue.length) && (YearField.defaultValue != YearField.value)) {
      if (this.isShowing()) {
         this.resetTimer(); // Gives the user more time to view the calendar with the newly-entered year
         this.getCalendar().style.zIndex = ++ZCounter; // Make sure this calendar is on top of any other calendars
      }
      var NewYear = GetGoodYear(YearField.value);
      var MonthList = this.getMonthList();
      var NewDay = FixDayList(this.getDayList(), GetDayCount(NewYear, this.picked.monthIndex));
      this.setPicked(NewYear, this.picked.monthIndex, NewDay);
      YearField.defaultValue = YearField.value;
   }
}

// Holds characteristics about a date
function dateObject() {
   if (Function.call) { // Used when 'call' method of the Function object is supported
      var ParentObject = this;
      var ArgumentStart = 0;
   }
   else { // Used with 'call' method of the Function object is NOT supported
      var ParentObject = arguments[0];
      var ArgumentStart = 1;
   }
   ParentObject.date = (arguments.length == (ArgumentStart+1)) ? new Date(arguments[ArgumentStart+0]) : new Date(arguments[ArgumentStart+0], arguments[ArgumentStart+1], arguments[ArgumentStart+2]);
   ParentObject.yearValue = ParentObject.date.getFullYear();
   ParentObject.monthIndex = ParentObject.date.getMonth();
   ParentObject.monthName = MonthNames[ParentObject.monthIndex];
   ParentObject.fullName = ParentObject.monthName + ' ' + ParentObject.yearValue;
   ParentObject.day = ParentObject.date.getDate();
   ParentObject.dayCount = GetDayCount(ParentObject.yearValue, ParentObject.monthIndex);
   var FirstDate = new Date(ParentObject.yearValue, ParentObject.monthIndex, 1);
   ParentObject.firstDay = FirstDate.getDay();
}

// Keeps track of the date that goes into the hidden field
function storedMonthObject(DateFormat, DateYear, DateMonth, DateDay) {
	
	
   (Function.call) ? dateObject.call(this, DateYear, DateMonth, DateDay) : dateObject(this, DateYear, DateMonth, DateDay);
   this.yearPad = this.yearValue.toString();
   this.monthPad = (this.monthIndex < 9) ? '0' + String(this.monthIndex + 1) : this.monthIndex + 1;
   this.dayPad = (this.day < 10) ? '0' + this.day.toString() : this.day;
   this.monthShort = this.monthName.substr(0,3).toUpperCase();
   // Formats the year with 2 digits instead of 4
   if (DateFormat.indexOf('YYYY') == -1) this.yearPad = this.yearPad.substr(2);
   // Define the date-part delimiter
   if (DateFormat.indexOf('/') >= 0) var Delimiter = '/';
   else if (DateFormat.indexOf('-') >= 0) var Delimiter = '-';
   else var Delimiter = '';

   // Determine the order of the months and days
   if (/DD?.?((MON)|(MM?M?))/.test(DateFormat)) {
      this.formatted = this.dayPad + Delimiter;
      this.formatted += (RegExp.$1.length == 3) ? this.monthShort : this.monthPad;
   }
   else if (/((MON)|(MM?M?))?.?DD?/.test(DateFormat)) {
      this.formatted = (RegExp.$1.length == 3) ? this.monthShort : this.monthPad;
      this.formatted += Delimiter + this.dayPad;
   }

   // Either prepend or append the year to the formatted date
   this.formatted = (DateFormat.substr(0,2) == 'YY') ? this.yearPad + Delimiter + this.formatted : this.formatted + Delimiter + this.yearPad;

}

// Object for the current displayed month
function displayMonthObject(ParentObject, DateYear, DateMonth, DateDay, formName) {
	

   (Function.call) ? dateObject.call(this, DateYear, DateMonth, DateDay) : dateObject(this, DateYear, DateMonth, DateDay);
   this.displayID = ParentObject.hiddenFieldName + '_Current_ID';
   this.getDisplay = new Function('return document.getElementById(this.displayID)');
   this.dayHover = DayCellHover;
   this.goCurrent = new Function(ParentObject.objName + '.getCalendar().style.zIndex=++ZCounter;' + ParentObject.objName + '.setDisplayed(Today.getFullYear(),Today.getMonth());');
   
   if (ParentObject.formNumber >= 0) this.getDisplay().innerHTML = this.fullName;
   

   this.hiddenFieldName	=formName;
   
}

// Object for the previous/next buttons
function neighborMonthObject(ParentObject, IDText, DateMS) {
   (Function.call) ? dateObject.call(this, DateMS) : dateObject(this, DateMS);
   this.buttonID = ParentObject.hiddenFieldName + '_' + IDText + '_ID';
   this.hover = new Function('C','O','NeighborHover(C,O,this)');
   this.getButton = new Function('return document.getElementById(this.buttonID)');
   this.go = new Function(ParentObject.objName + '.getCalendar().style.zIndex=++ZCounter;' + ParentObject.objName + '.setDisplayed(this.yearValue,this.monthIndex);');
   //if (ParentObject.formNumber >= 0) this.getButton().title = this.monthName;
}

// Sets the currently-displayed month object
function SetDisplayedMonth(DispYear, DispMonth) {


   this.displayed = new displayMonthObject(this, DispYear, DispMonth, 1, this.hiddenFieldName);


   // Creates the previous and next month objects
   this.previous = new neighborMonthObject(this, 'Previous', this.displayed.date.getTime() - 86400000);


   this.next = new neighborMonthObject(this, 'Next', this.displayed.date.getTime() + (86400000 * (this.displayed.dayCount + 1)));


   // Creates the HTML for the calendar
   //jiang closed text below at 2006.11.10, not sure if this good. XXXX
   if (this.formNumber >= 0) this.getDayTable().innerHTML = this.buildCalendar();


}

// Sets the current selected date
function SetPickedMonth(PickedYear, PickedMonth, PickedDay) {


   this.picked = new storedMonthObject(this.format, PickedYear, PickedMonth, PickedDay);
   
   
   this.setHidden(this.picked.formatted);


   this.setDisplayed(PickedYear, PickedMonth);


}

// The calendar object
function calendarObject(DateName, DateFormat, DefaultDate) {

   if (DateName==getDepartureDateName(DateName)){

		var currDate	=formatDate(new Date());
		   	
   	   if (DefaultDate==null || DefaultDate=="" || DefaultDate==currDate){

    		var departDay	=addDay(new Date(),2);
    		DefaultDate	=formatDate(departDay);

       	   			
   	   }
   }	




   /* Properties */
   this.hiddenFieldName = DateName;
   this.monthListID = DateName + '_Month_ID';
   this.dayListID = DateName + '_Day_ID';
   this.yearFieldID = DateName + '_Year_ID';
   this.monthDisplayID = DateName + '_Current_ID';
   this.calendarID = DateName + '_ID';
   this.dayTableID = DateName + '_DayTable_ID';
   this.calendarLinkID = this.calendarID + '_Link';
   this.timerID = this.calendarID + '_Timer';
   this.objName = DateName + '_Object';
   this.format = DateFormat;
   this.formNumber = -1;
   this.picked = null;
   this.displayed = null;
   this.previous = null;
   this.next = null;
   this.CalendarBuilt	=false; 


   /* Methods */
   this.setPicked = SetPickedMonth;
   this.setDisplayed = SetDisplayedMonth;
   this.checkYear = CheckYearInput;
   this.fixYear = FixYearInput;
   this.changeMonth = CheckMonthChange;
   this.changeDay = CheckDayChange;
   this.resetTimer = CalTimerReset;
   this.hideElements = SetElementStatus;
   this.show = ShowCalendar;
   this.hide = HideCalendar;
   this.handleTimer = DoTimer;
   this.iconHover = CalIconHover;
   this.buildCalendar = BuildCalendarDays;
   this.pickDay = PickDisplayDay;
   this.userChange	=userChangeDate;
   this.triggerDate	=triggerDateChange;
   this.fixSelects = FixSelectLists;
   this.setHidden = new Function('D','if (this.formNumber >= 0) this.getHiddenField().value=D');
   // Returns a reference to these elements
   this.getHiddenField = new Function('return document.forms[this.formNumber].elements[this.hiddenFieldName]');
   this.getMonthList = new Function('return document.getElementById(this.monthListID)');
   this.getDayList = new Function('return document.getElementById(this.dayListID)');
   this.getYearField = new Function('return document.getElementById(this.yearFieldID)');
   this.getCalendar = new Function('return document.getElementById(this.calendarID)');
   this.getDayTable = new Function('return document.getElementById(this.dayTableID)');
   this.getCalendarLink = new Function('return document.getElementById(this.calendarLinkID)');
   this.getMonthDisplay = new Function('return document.getElementById(this.monthDisplayID)');
   this.isShowing = new Function('return !(this.getCalendar().style.visibility != \'visible\')');

   /* Constructor */
   // Functions used only by the constructor
   function getMonthIndex(MonthAbbr) { // Returns the index (0-11) of the supplied month abbreviation
      for (var MonPos=0;MonPos<MonthNames.length;MonPos++) {
         if (MonthNames[MonPos].substr(0,3).toUpperCase() == MonthAbbr.toUpperCase()) break;
      }
      return MonPos;
   }
   function SetGoodDate(CalObj, Notify) { // Notifies the user about their bad default date, and sets the current system date
      CalObj.setPicked(Today.getFullYear(), Today.getMonth(), Today.getDate());
      if (Notify) alert('WARNING: The supplied date is not in valid \'' + DateFormat + '\' format: ' + DefaultDate + '.\nTherefore, the current system date will be used instead: ' + CalObj.picked.formatted);
   }
   // Main part of the constructor
   if (DefaultDate != '') {
      if ((this.format == 'YYYYMMDD') && (/^(\d{4})(\d{2})(\d{2})$/.test(DefaultDate))) this.setPicked(RegExp.$1, parseInt(RegExp.$2,10)-1, RegExp.$3);
      else {
         // Get the year
         if ((this.format.substr(0,2) == 'YY') && (/^(\d{2,4})(-|\/)/.test(DefaultDate))) { // Year is at the beginning
            var YearPart = GetGoodYear(RegExp.$1);
            // Determine the order of the months and days
            if (/(-|\/)(\w{1,3})(-|\/)(\w{1,3})$/.test(DefaultDate)) {
               var MidPart = RegExp.$2;
               var EndPart = RegExp.$4;
               if (/D$/.test(this.format)) { // Ends with days
                  var DayPart = EndPart;
                  var MonthPart = MidPart;
               }
               else {
                  var DayPart = MidPart;
                  var MonthPart = EndPart;
               }
               MonthPart = (/\d{1,2}/i.test(MonthPart)) ? parseInt(MonthPart,10)-1 : getMonthIndex(MonthPart);
               this.setPicked(YearPart, MonthPart, DayPart);
            }
            else SetGoodDate(this, true);
         }
         else if (/(-|\/)(\d{2,4})$/.test(DefaultDate)) { // Year is at the end
            var YearPart = GetGoodYear(RegExp.$2);
            // Determine the order of the months and days
            if (/^(\w{1,3})(-|\/)(\w{1,3})(-|\/)/.test(DefaultDate)) {
               if (this.format.substr(0,1) == 'D') { // Starts with days
                  var DayPart = RegExp.$1;
                  var MonthPart = RegExp.$3;
               }
               else { // Starts with months
                  var MonthPart = RegExp.$1;
                  var DayPart = RegExp.$3;
               }
               MonthPart = (/\d{1,2}/i.test(MonthPart)) ? parseInt(MonthPart,10)-1 : getMonthIndex(MonthPart);
               this.setPicked(YearPart, MonthPart, DayPart);
            }
            else SetGoodDate(this, true);
         }
         else SetGoodDate(this, true);
      }
   }
}


function getEvent(evnt)
{
    return (typeof(evnt)!='undefined' && evnt) ? evnt : ((typeof(event)!='undefined' && event) ? event : null);
}


function getEventKeypress(evnt)
{
    evnt = getEvent(evnt);

    return (evnt.which) ? evnt.which : evnt.keyCode;

}


// Main function that creates the form elements
function DateInput(DateName, Required, DateFormat, DefaultDate) {

	
   var tahoeDefaultDate	=DefaultDate;
   if (!DefaultDate || DefaultDate==null || DefaultDate=="" ||  DefaultDate.toLowerCase()=="null" || DefaultDate.toLowerCase()=="any"){

        var CurrentDate1 = new storedMonthObject("MM/DD/YYYY", Today.getFullYear(), Today.getMonth(), Today.getDate());
        DefaultDate = CurrentDate1.formatted;
	   	tahoeDefaultDate	="Any";
   }

   	
   if (arguments.length == 0) document.writeln('<span style="color:red;font-size:' + FontSize + 'px;font-family:' + FontFamily + ';">ERROR: Missing required parameter in call to \'DateInput\': [name of hidden date field].</span>');
   else {
      // Handle DateFormat
      if (arguments.length < 3) { // The format wasn't passed in, so use default
         DateFormat = DefaultDateFormat;
         if (arguments.length < 2) Required = false;
      }
      else if (/^(Y{2,4}(-|\/)?)?((MON)|(MM?M?)|(DD?))(-|\/)?((MON)|(MM?M?)|(DD?))((-|\/)Y{2,4})?$/i.test(DateFormat)) DateFormat = DateFormat.toUpperCase();
      else { // Passed-in DateFormat was invalid, use default format instead
         var AlertMessage = 'WARNING: The supplied date format for the \'' + DateName + '\' field is not valid: ' + DateFormat + '\nTherefore, the default date format will be used instead: ' + DefaultDateFormat;
         DateFormat = DefaultDateFormat;
         if (arguments.length == 4) { // DefaultDate was passed in with an invalid date format
            var CurrentDate = new storedMonthObject(DateFormat, Today.getFullYear(), Today.getMonth(), Today.getDate());
            AlertMessage += '\n\nThe supplied date (' + DefaultDate + ') cannot be interpreted with the invalid format.\nTherefore, the current system date will be used instead: ' + CurrentDate.formatted;
            DefaultDate = CurrentDate.formatted;
         }
         alert(AlertMessage);
      }
      // Define the current date if it wasn't set already
      if (!CurrentDate) var CurrentDate = new storedMonthObject(DateFormat, Today.getFullYear(), Today.getMonth(), Today.getDate());
      // Handle DefaultDate
      if (arguments.length < 4) { // The date wasn't passed in
         DefaultDate = (Required) ? CurrentDate.formatted : ''; // If required, use today's date
      }
      // Creates the calendar object!
      eval(DateName + '_Object=new calendarObject(\'' + DateName + '\',\'' + DateFormat + '\',\'' + DefaultDate + '\')');
      // Determine initial viewable state of day, year, and calendar icon
      if ((Required) || (arguments.length == 4)) {
         var InitialStatus = '';
         var InitialDate = eval(DateName + '_Object.picked.formatted');
      }
      else {
         var InitialStatus = ' style="visibility:hidden"';
         var InitialDate = '';
         eval(DateName + '_Object.setPicked(' + Today.getFullYear() + ',' + Today.getMonth() + ',' + Today.getDate() + ')');
      }
      // Create the form elements
      with (document) {
         //writeln('<input type="hidden" name="' + DateName + '" value="' + InitialDate + '">');
         writeln('<input type="hidden" name="' + DateName + '" id="'+DateName+'" value="' + tahoeDefaultDate + '">');

         // Find this form number
         for (var f=0;f<forms.length;f++) {
            for (var e=0;e<forms[f].elements.length;e++) {
               if (typeof forms[f].elements[e].type == 'string') {
                  if ((forms[f].elements[e].type == 'hidden') && (forms[f].elements[e].name == DateName)) {
                     eval(DateName + '_Object.formNumber='+f);
                     break;
                  }
               }
            }
         }



         writeln('<table cellpadding="0" cellspacing="2" onclick="isCalendarClick=true"><tr>' + String.fromCharCode(13) + '<td valign="middle">');

         writeln('<input type="text"  class="calendarInput" onclick="clearAny()"  name="' + DateName + '_currDate"  id="' + DateName + '_currDate"  value="' + tahoeDefaultDate + '" size=15 onblur="'+DateName + '_Object.userChange(this.value)" onkeydown="if (getEventKeypress(event) == 9 || getEventKeypress(event) == 13){this.onblur();}">');
         writeln('</td>');
                  
         write('<td valign="middle">' + String.fromCharCode(13) + '<a' + InitialStatus + ' id="' + DateName + '_ID_Link" href="javascript:' + DateName + '_Object.show()" onMouseOver="return ' + DateName + '_Object.iconHover(true)" onMouseOut="return ' + DateName + '_Object.iconHover(false)"><img src="' + ImageURL + '" align="baseline" title="Calendar" border="0"></a>&nbsp;');
         writeln('<span id="' + DateName + '_ID" style="position:absolute;visibility:hidden;width:' + (CellWidth * 7) + 'px;background-color:' + CalBGColor + ';border:1px solid dimgray;" onMouseOver="' + DateName + '_Object.handleTimer(true)" onMouseOut="' + DateName + '_Object.handleTimer(false)">');
         writeln('<table width="' + (CellWidth * 7) + '" cellspacing="0" cellpadding="1">' + String.fromCharCode(13) + '<tr style="background-color:' + TopRowBGColor + ';">');
         writeln('<td disabled id="' + DateName + '_Previous_ID" style="cursor:default" align="center" class="calendarDateInput" style="height:' + CellHeight + '" onClick="' + DateName + '_Object.previous.go()" onMouseDown="VirtualButton(this,true)" onMouseUp="VirtualButton(this,false)" onMouseOver="return ' + DateName + '_Object.previous.hover(this,true)" onMouseOut="return ' + DateName + '_Object.previous.hover(this,false)" title="' + eval(DateName + '_Object.previous.monthName') + '"><img id="'+DateName+'_prevBtn" name="'+DateName+'_prevBtn" style="display:none" border=0 src="' + PrevURL + '"></td>');
         writeln('<td id="' + DateName + '_Current_ID" style="cursor:pointer" align="center" class="calendarDateInput" style="height:' + CellHeight + '" colspan="5" onClick="' + DateName + '_Object.displayed.goCurrent()" onMouseOver="self.status=\'Click to view ' + CurrentDate.fullName + '\';return true;" onMouseOut="self.status=\'\';return true;" title="Show Current Month">' + eval(DateName + '_Object.displayed.fullName') + '</td>');
         writeln('<td id="' + DateName + '_Next_ID" style="cursor:default" align="center" class="calendarDateInput" style="height:' + CellHeight + '" onClick="' + DateName + '_Object.next.go()" onMouseDown="VirtualButton(this,true)" onMouseUp="VirtualButton(this,false)" onMouseOver="return ' + DateName + '_Object.next.hover(this,true)" onMouseOut="return ' + DateName + '_Object.next.hover(this,false)" title="' + eval(DateName + '_Object.next.monthName') + '"><img src="' + NextURL + '"></td></tr>' + String.fromCharCode(13) + '<tr>');
         for (var w=0;w<7;w++) writeln('<td width="' + CellWidth + '" align="center" class="calendarDateInput" style="height:' + CellHeight + ';width:' + CellWidth + ';font-weight:bold;border-top:1px solid dimgray;border-bottom:1px solid dimgray;">' + WeekDays[w] + '</td>');
         writeln('</tr>' + String.fromCharCode(13) + '</table>' + String.fromCharCode(13) + '<span id="' + DateName + '_DayTable_ID">' + eval(DateName + '_Object.buildCalendar()') + '</span>' + String.fromCharCode(13) + '</span>' + String.fromCharCode(13) + '</td>' + String.fromCharCode(13) + '</tr>' + String.fromCharCode(13) + '</table>');
         
      }
   }   
}
