// ****************************************************************************
// createDateField: allows you to transform an <input> tag into a special date 
//                  field that can be used by the 'popCalendar' function. 
//                  Typically, you call this in your init function. (usually
//                  called in the 'onload' event of the <body> tag).
// NOTES:
//       1) pDateFormat: string representing the date format used by
//          the date field; this format is used to format dates and to interpret
//          the user's manual input. You can build any format you want, with 
//          the following code conventions:
//                   MM - will be replaced by the month's number ("01" to "12")
//                   DD - will be replaced by the date ("01" to "31")
//                   YY - will be replaced by the year ("2005", ...)
//          DEFAULT: "MM/DD/YY"
// ****************************************************************************
// EXAMPLE:
//   var vDateField = createDateField("myDateInputField", "MM/DD/YY");
//   ' Set the date field's initial date:
//   vDateField.setDate("01/01/05"); // use the same format as specified on creation!

function createDateField(pFieldID, pDateFormat) {
	var vDateField = findDOM(pFieldID, 0);
	if(vDateField != null) {
		vDateField.dateFormat = (pDateFormat == null) ? "MM/DD/YY" : pDateFormat;
		
		vDateField.dateToString = function(pDate) {
			if(pDate == null) return "";
			
			var vValue = (pDate.getMonth() + 1);
			var vDateString = this.dateFormat.replace(/MM/g, (vValue < 10) ? ("0" + vValue) : vValue);
			vValue = pDate.getDate();
			vDateString =vDateString.replace(/DD/g, (vValue < 10) ? ("0" + vValue) : vValue);
			vValue = pDate.getFullYear();
			vDateString = vDateString.replace(/Y{2,4}/g, vValue);
			
			return vDateString;
		};
		vDateField.stringToDate = function(pDateString) {
			var vYear, vMonth, vDay;
			var vFormat = this.dateFormat.replace(/\//g, "\\/");
			
			var vRE = new RegExp("^" + vFormat.replace(/MM/, "\\d{1,2}").replace(/DD/, "\\d{1,2}").replace(/Y{2,4}/, "(\\d{2,4})") + "$", "");
			var vREMatch = pDateString.match(vRE);
			if(vREMatch != null) {
				vYear = (1 * vREMatch[1]);
				if(vYear < 70) vYear += 2000;
				else if(vYear < 100) vYear +=1900;
			}
			
			var vRE = new RegExp("^" + vFormat.replace(/Y{2,4}/, "\\d{2,4}").replace(/DD/, "\\d{1,2}").replace(/MM/, "(\\d{1,2})") + "$", "");
			vREMatch = pDateString.match(vRE);
			if(vREMatch != null) vMonth = vREMatch[1];
			
			var vRE = new RegExp("^" + vFormat.replace(/Y{2,4}/, "\\d{2,4}").replace(/MM/, "\\d{1,2}").replace(/DD/, "(\\d{1,2})") + "$", "");
			vREMatch = pDateString.match(vRE);
			if(vREMatch != null) vDay = vREMatch[1];
			
			if((vYear == null) || (vMonth == null) || (vDay == null)) return null;
			return new Date(vYear, (vMonth - 1), vDay, 0, 0, 0, 0);
		};
		
		vDateField.date = null;
		
		vDateField.getDate = function() { return this.date };
		vDateField.setDate = function(pDate) {
			if(typeof(pDate) == "string") pDate = this.stringToDate(pDate);
			if((this.date == null) || (this.date.getTime() != pDate.getTime())) {
				this.date = new Date(pDate.getTime());
				this.value = this.dateToString(this.date);
			}
		};
		vDateField.onblur = function(pEvent) {
			var vDate = this.stringToDate(this.value);
			if(vDate == null) {
				alert("Invalid date!");
				this.value = this.dateToString(this.date);
				this.focus();
				this.select();
				return false;
			}
			this.setDate(vDate);
			return true;
		};
	}
	return vDateField;
}

// ****************************************************************************
// createDailyCalendar: allows you to transform an <div> tag into a daily 
//                      calendar object, to be used by 'popCalendar'. Typically,
//                      you call this in your init function. (usually called in 
//                      the 'onload' event of the <body> tag).
// NOTES:
//       1) pStartOfWeek is the day on which the calendar display shoudl start;
//          (0 is Sunday, 6 is Saturday)
//       DEFAULT: 0
//       2) pNumberOfYears: is the number of years you want to show in the "Year"
//          pop-up menu.
//       DEFAULT: 7
// ****************************************************************************
// EXAMPLE:
//   createDailyCalendar("myCalendarDiv");

function createDailyCalendar(pCalendarID, pStartOfWeek, pNumberOfYears) {
	var vCalendarDiv = findDOM(pCalendarID, 0);
	if(vCalendarDiv != null) new Calendar(vCalendarDiv, pStartOfWeek, pNumberOfYears);
	return vCalendarDiv;
}

// ****************************************************************************
// popCalendar: allows you to show a calendar and temporarily link it to a 
//              date field; the date field should have been created by the 
//              'createDateField' function.
// ****************************************************************************
// EXAMPLE:
//   <img src="art/calendar.jpg" onclick="popCalendar(event, 'myCalendarDiv', 'myDateInputField');" />

function popCalendar(pEvent, pCalendarID, pFieldID) {
	var vCalendarDiv = findDOM(pCalendarID, 0);
	if(vCalendarDiv != null) {
		if(vCalendarDiv.calendar_type != null) vCalendarDiv.calendar.pop(pEvent.CustomerX, pEvent.CustomerY, pFieldID);
	}
}






// ****************************************************************************
// PRIVATE API: you should not have to use or modify the code below this point.
// ****************************************************************************
var kDHTMLCalendar_Daily = 1;
var kDHTMLCalendar_Weekly = 2;
var kDHTMLCalendar_MenuPopUp_Delay = 3; // in seconds

function dhtml_calendar_hide_menu(pCalendarDivID) {
	var vCalendarDiv = findDOM(pCalendarDivID, 0);
	if((vCalendarDiv != null) && (vCalendarDiv.calendar != null) && (vCalendarDiv.calendar.menu != null)) {
		vCalendarDiv.calendar.menu.hide();
	}
}
function insureCalendarVisible(pDivID) {
	var vDiv = findDOM(pDivID, 0);
	var vDivStyle = getStyleDOM(vDiv);
	if(vDivStyle != null) {
		var vY = parseInt(vDivStyle.top);
		var vHeight = parseInt(vDiv.offsetHeight);
		if(isIE) {
			if((vY + vHeight) > document.body.CustomerHeight) vY = (document.body.CustomerHeight - vHeight);
		} else {
			if((vY + vHeight) > document.body.CustomerHeight) vY = (document.body.CustomerHeight - vHeight - 6);
		}
		if(vY < 0) vY = 0;
		vDivStyle.top = vY + "px" ;
	}
}

function Calendar(pDiv, pStartOfWeek, pNumberOfYears) {
	this.div = pDiv;
	this.startOfWeek = (pStartOfWeek == null) ? 0 : pStartOfWeek;
	this.data = new Array(); // [year][month][week][day]
	this.selectedDate = null;
	this.currentDate = null;
	this.dateField = null;
	this.nbYears = (pNumberOfYears == null) ? 7 : pNumberOfYears;
	if(this.div != null) this.init();
}
new Calendar();

Calendar.prototype.calendarDivSetWidth = function(pDivStyle) { pDivStyle.width = "210px"; }
Calendar.prototype.init = function() {
	var vCalendarDiv = this.div;
	if(vCalendarDiv != null) {
		
		emptyNode(vCalendarDiv);
		
		this.menu = document.createElement("ul");
		vCalendarDiv.appendChild(this.menu);
		this.menu.className = "dhtml_calendar_menu";
		this.menu.onmouseover = new Function("pEvent", "if(this.delay) clearTimeout(this.delay);");
		this.menu.onmouseout = new Function("pEvent", "this.delayHide();");
		this.menu.delayHide = function() {
			if(this.delay) clearTimeout(this.delay);
			var vMenuStyle = getStyleDOM(this);
			if(vMenuStyle.display != "none") {
				this.delay = setTimeout("dhtml_calendar_hide_menu(\"" + vCalendarDiv.id + "\");", (kDHTMLCalendar_MenuPopUp_Delay * 1000));
			}
		};
		this.menu.hide = function() {
			if(this.delay) clearTimeout(this.delay);
			var vMenuStyle = getStyleDOM(this);
			if(vMenuStyle != null) vMenuStyle.display = "none";
		};
		var vMenuStyle = getStyleDOM(this.menu);
		vMenuStyle.position = "absolute";
		vMenuStyle.top = "0px";
		vMenuStyle.left = "0px";
		vMenuStyle.display  = "none";
		vMenuStyle.zIndex = 10000001;
		
		vCalendarDiv.monthLabel = null;
		vCalendarDiv.yearLabel = null;
		
		var vCalendarStyle = getStyleDOM(vCalendarDiv);
		vCalendarStyle.display = "none";
		vCalendarDiv.calendar_type = kDHTMLCalendar_Daily;
		vCalendarDiv.className = "dhtml_calendar";
		vCalendarStyle.position = "absolute";
		vCalendarStyle.left = "0px";
		vCalendarStyle.top = "0px";
		this.calendarDivSetWidth(vCalendarStyle);
		vCalendarStyle.zIndex = 10000000;
		
		vCalendarDiv.calendar =  this;
		
		var vTitleBar = document.createElement("div");
		vCalendarDiv.appendChild(vTitleBar);
		vTitleBar.className = "dhtml_calendar_titlebar";
		var vTitleBarStyle = getStyleDOM(vTitleBar);
		vTitleBarStyle.position = "relative";
		vTitleBarStyle.padding = "3px 2px";
		if(isIE) vTitleBarStyle.height = "18px";
		
		// Add buttons and controls
		var vButton = document.createElement("a");
		vTitleBar.appendChild(vButton);
		vButton.className = "dhtml_calendar_prev_month";
		vButton.calendar = vCalendarDiv.calendar;
		vButton.onclick = new Function("pEvent", "this.calendar.previous_month();");
		var vButtonStyle = getStyleDOM(vButton);
		vButtonStyle.position = "absolute";
		vButtonStyle.width = "13px";
		if(isIE) vButtonStyle.top = "2px";
		else vButtonStyle.top = "3px";
		if(isIE) vButtonStyle.left = "2px";
		else vButtonStyle.left = "3px";
		if(isIE) vButtonStyle.height = "16px";
		else vButtonStyle.height = "14px";
		
		vButton = document.createElement("a");
		vTitleBar.appendChild(vButton);
		vButton.className = "dhtml_calendar_next_month";
		vButton.calendar = vCalendarDiv.calendar;
		vButton.onclick = new Function("pEvent", "this.calendar.next_month();");
		vButtonStyle = getStyleDOM(vButton);
		vButtonStyle.position = "absolute";
		if(isIE) vButtonStyle.top = "2px";
		else vButtonStyle.top = "3px";
		if(isIE) vButtonStyle.left = "19px";
		else vButtonStyle.left = "21px";
		vButtonStyle.width = "13px";
		if(isIE) vButtonStyle.height = "16px";
		else vButtonStyle.height = "14px";
		
		vCalendarDiv.monthLabel = document.createElement("a");
		vTitleBar.appendChild(vCalendarDiv.monthLabel);
		vCalendarDiv.monthLabel.className = "dhtml_calendar_month_label";
		vCalendarDiv.monthLabel.calendar = vCalendarDiv.calendar;
		vCalendarDiv.monthLabel.onclick = new Function("pEvent", "this.calendar.popMonthMenu((pEvent != null) ? pEvent : event, this); return false;");
		vCalendarDiv.monthLabel.appendChild(document.createTextNode("(Month)"));
		vButtonStyle = getStyleDOM(vCalendarDiv.monthLabel);
		vButtonStyle.position = "absolute";
		if(isIE) vButtonStyle.top = "2px";
		else vButtonStyle.top = "3px";
		if(isIE) vButtonStyle.left = "36px";
		else vButtonStyle.left = "39px";
		vButtonStyle.width = "80px";
		if(isIE) vButtonStyle.height = "16px";
		else vButtonStyle.height = "14px";
		vButtonStyle.padding = "0px 2px";
		
		vCalendarDiv.yearLabel = document.createElement("a");
		vTitleBar.appendChild(vCalendarDiv.yearLabel);
		vCalendarDiv.yearLabel.className = "dhtml_calendar_year_label";
		vCalendarDiv.yearLabel.calendar = vCalendarDiv.calendar;
		vCalendarDiv.yearLabel.onclick = new Function("pEvent", "this.calendar.popYearMenu((pEvent != null) ? pEvent : event, this); return false;");
		vCalendarDiv.yearLabel.appendChild(document.createTextNode("(Year)"));
		vButtonStyle = getStyleDOM(vCalendarDiv.yearLabel);
		vButtonStyle.position = "absolute";
		if(isIE) vButtonStyle.top = "2px";
		else vButtonStyle.top = "3px";
		if(isIE) vButtonStyle.left = "118px";
		else vButtonStyle.left = "127px";
		vButtonStyle.width = "50px";
		if(isIE) vButtonStyle.height = "16px";
		else vButtonStyle.height = "14px";
		vButtonStyle.padding = "0px 2px";
		
		vButton = document.createElement("a");
		vTitleBar.appendChild(vButton);
		vButton.className = "dhtml_calendar_close";
		vButton.calendar = vCalendarDiv.calendar;
		vButton.onclick = new Function("pEvent", "this.calendar.close();");
		vButtonStyle = getStyleDOM(vButton);
		vButtonStyle.position = "absolute";
		if(isIE) vButtonStyle.right = "2px";
		else vButtonStyle.right = "3px";
		if(isIE) vButtonStyle.top = "3px";
		else vButtonStyle.top = "4px";
		vButtonStyle.width = "16px";
		if(isIE) vButtonStyle.height = "16px";
		else vButtonStyle.height = "14px";
		
		var vClear = document.createElement("br");
		vTitleBar.appendChild(vClear);
		vClear.clear = "all";
		
	}
}
Calendar.prototype.insureMonth = function (pYear, pMonthIndex) {
	if(this.data[pYear] == null) this.data[pYear] = new Array();
	
	if(this.data[pYear][pMonthIndex] == null) {
		
		this.data[pYear][pMonthIndex] = new Array();
		var vDate = new Date(pYear, pMonthIndex, 1, 0, 0, 0, 0);
		var vWeekNb = 0;
		this.data[pYear][pMonthIndex][vWeekNb] = new Array();
		var vEndOfWeek = 6;
		if(this.startOfWeek > 0) vEndOfWeek = (this.startOfWeek - 1);
		while(vDate.getMonth() == pMonthIndex) {
			
			var vDayOfMonth = vDate.getDate();
			var vIndex = (vDate.getDay() - this.startOfWeek);
			if(vIndex < 0) vIndex += 7;
			
			this.data[pYear][pMonthIndex][vWeekNb][vIndex] = vDate;
			
			var vNewDate = new Date(pYear, pMonthIndex, ++vDayOfMonth, 0, 0, 0, 0);
			if((vNewDate != null) && (vDate.getDay() == vEndOfWeek)) {
				this.data[pYear][pMonthIndex][++vWeekNb] = new Array();
			}
			
			vDate = vNewDate;
		}
	}
	return true;
}
Calendar.prototype.click_date = function(pDate) {
	this.menu.hide();
	this.select_date(pDate);
	this.close();
}
Calendar.prototype.select_date = function(pDate) {
	var vDateCell;
	if(this.selectedDate != null) {
		// unselect the old date
		vDateCell = findDOM(this.div.id + "_" + this.selectedDate.getTime(), 0);
		if(vDateCell != null) vDateCell.className = (vDateCell.date.getMonth() == vDateCell.calendar.currentDate.getMonth()) ? "" : "inactive_date";
	}
	this.selectedDate = (pDate == null) ? null : new Date(pDate.getTime());
	if(this.selectedDate != null) {
		// select the new date
		vDateCell = findDOM(this.div.id + "_" + this.selectedDate.getTime(), 0);
		if(vDateCell != null) {
			//this.dateField.setDate(this.selectedDate);
			try
			{
				this.dateField.value = formatDate(this.selectedDate,'MM/dd/yyyy');
			}
			catch(e){}
			
			try
			{
				this.dateField.innerHTML = formatDate(this.selectedDate,'MM/dd/yyyy');
			}
			catch(e){}
			
			try
			{
				selDay(formatDate(this.selectedDate,'MM/dd/yyyy'),false);
			}
			catch(e){}
			vDateCell.className = (vDateCell.date.getMonth() == vDateCell.calendar.currentDate.getMonth()) ? "selected_day" : "selected_inactive_day";
		}
	}
}
Calendar.prototype.paint_month = function(pTable, pYear, pMonth) {
	var vRow = document.createElement("tr");
	pTable.appendChild(vRow);
	var vCell;
	for(var vLoop = 0; vLoop < this.data[pYear][pMonth][1].length; vLoop++) {
		vCell = document.createElement("th");
		vCell.appendChild(document.createTextNode(kWeekDaysAbbrev[this.data[pYear][pMonth][1][vLoop].getDay()]));
		vRow.appendChild(vCell);
	}
	
	for(var vWeek = 0; vWeek < this.data[pYear][pMonth].length; vWeek++) {
		vRow = document.createElement("tr");
		pTable.appendChild(vRow);
		for(var vDay = 0; vDay < 7; vDay++) {
			vCell = document.createElement("td");
			vRow.appendChild(vCell);
			vCell.date = this.data[pYear][pMonth][vWeek][vDay];
			if(vCell.date == null) {
				vCell.className = "inactive_date";
				if(vWeek == 0) {
					var vYear = pYear;
					var vMonth = (pMonth -1);
					if(vMonth < 0) {
						vMonth = 11;
						vYear -= 1;
					}
					this.insureMonth(vYear, vMonth);
					vCell.date = this.data[vYear][vMonth][(this.data[vYear][vMonth].length - 1)][vDay];
				} else {
					var vYear = pYear;
					var vMonth = (pMonth + 1);
					if(vMonth > 11) {
						vMonth = 0;
						vYear += 1;
					}
					this.insureMonth(vYear, vMonth);
					vCell.date = this.data[vYear][vMonth][0][vDay];
				}
			}
			vCell.id = (this.div.id + "_" + vCell.date.getTime());
			vCell.calendar = this;
			var vCellStyle = getStyleDOM(vCell);
			vCellStyle.width = "30px";
			if(vCell.date.getMonth() != this.currentDate.getMonth()) {
				vCell.appendChild(document.createTextNode(vCell.date.getDate()));
			} else {
				var vLink = document.createElement("a");
				vCell.appendChild(vLink);
				vLink.href = "#";
				vLink.title = "Select " + vCell.date.toDateString();
				vLink.onclick = new Function("pEvent", "this.parentNode.calendar.click_date(this.parentNode.date); return false;");
				vLink.appendChild(document.createTextNode(vCell.date.getDate()));
			}
		}
	}
}
Calendar.prototype.show_date = function(pDate) {
	var vDivStyle = getStyleDOM(this.div);
	if(this.div.childNodes.length > 2) this.div.removeChild(this.div.lastChild);
	
	this.currentDate = new Date(pDate.getTime());
	this.currentDate.setDate(1);
	var vYear = this.currentDate.getFullYear();
	var vMonth = this.currentDate.getMonth();
	if(this.insureMonth(vYear, vMonth)) {
		
		var vTableDiv = document.createElement("table");
		this.div.appendChild(vTableDiv);
		
		var vTable = document.createElement("tbody");
		vTableDiv.appendChild(vTable);
		
		this.paint_month(vTable, vYear, vMonth);
		
		// Adjust title bar controls:
		if(this.div.monthLabel != null) this.div.monthLabel.firstChild.nodeValue = kMonths[vMonth];
		if(this.div.yearLabel != null) this.div.yearLabel.firstChild.nodeValue = ("" + vYear);
		
	}
	if((this.dateField != null) && (this.dateField.date != null)) {
		this.select_date(this.dateField.date);
	}
	
}
Calendar.prototype.popMenu = function(pEvent, pLabelDiv) {
	var vDivStyle = getStyleDOM(pLabelDiv);
	var vMenuStyle = getStyleDOM(this.menu);
	if(isIE) {
		vMenuStyle.top = (parseInt(vDivStyle.top) + parseInt(vDivStyle.height) + 2) + "px";
		vMenuStyle.left = (parseInt(vDivStyle.left) - 37) + "px";
	} else {
		vMenuStyle.top = ((parseInt(vDivStyle.top) + parseInt(vDivStyle.height)) -8) + "px";
		vMenuStyle.left = (parseInt(vDivStyle.left) + 2) + "px";
	}
	vMenuStyle.display = "block";
	this.menu.delayHide();
}
Calendar.prototype.pop = function(pX, pY, pFieldID) {
	var vDivStyle = getStyleDOM(this.div);
	
	var vShimStyle = null;
	if(isIE && (this.shim == null)) {
		// iFrame Shim for IE and <select> bug...
		this.shim = document.createElement("iframe");
		this.shim.src = "blank.htm";
		this.shim.frameBorder = "0";
		this.shim.scrolling= "no";
		this.div.parentNode.appendChild(this.shim);
		vShimStyle = getStyleDOM(this.shim);
		vShimStyle.position = "absolute";
		vShimStyle.top = "0px";
		vShimStyle.left = "0px";
		vShimStyle.width = "0px";
		vShimStyle.height = "0px";
		vShimStyle.zIndex = (vDivStyle.zIndex - 1);
		vShimStyle.display = "none";
	}
	vShimStyle = getStyleDOM(this.shim);
	
	this.dateField = findDOM(pFieldID, 0);

	var vDate = null;
	if((this.dateField != null) && (this.dateField.getDate)) vDate = this.dateField.getDate();
	if(vDate == null) vDate = new Date();
	
	this.show_date(vDate);
	
	// Make sure the calendar is totally visible on the page's width
	var vWidth = parseInt(vDivStyle.width);
	if(isIE) {
		if((pX + vWidth) > document.body.CustomerWidth) pX = (document.body.CustomerWidth - vWidth);
	} else {
		if((pX + vWidth) > document.body.CustomerWidth) pX = (document.body.CustomerWidth - vWidth - 6);
	}
	if(pX < 0) pX = 0;
	vDivStyle.left = pX + "px";
	vDivStyle.top = pY + "px" ;
	
	vDivStyle.display = "block";
	
	if(vShimStyle != null) {
			vShimStyle.top = vDivStyle.top;
			vShimStyle.left = vDivStyle.left;
			vShimStyle.width = this.div.offsetWidth;
			vShimStyle.height = this.div.offsetHeight;
			vShimStyle.display = "block";
	}
	
	setTimeout("insureCalendarVisible(\""+this.div.id+"\");", 1); // NOTE: we make sure the calendar is totally visible on the page's height;
	// since the height is auto calulated, we need to wait until the calendar is actually displayed
}
Calendar.prototype.close = function() {
	this.menu.hide();
	var vDivStyle = getStyleDOM(this.div);
	if(vDivStyle != null) vDivStyle.display = "none";
	var vShimStyle = getStyleDOM(this.shim);
	if(vShimStyle != null) vShimStyle.display = "none";
}
Calendar.prototype.goto_year_month = function(pYear, pMonthIndex) {
	this.show_date(new Date(pYear, pMonthIndex, 1, 0, 0, 0, 0));
	setTimeout("insureCalendarVisible(\""+this.div.id+"\");", 1);
}
Calendar.prototype.goto_month = function(pMonthIndex) {
	this.menu.hide();
	this.goto_year_month(this.currentDate.getFullYear(), pMonthIndex);
}
Calendar.prototype.goto_year = function(pYear) {
	this.menu.hide();
	this.goto_year_month(pYear, this.currentDate.getMonth());
}
Calendar.prototype.previous_month = function() {
	this.menu.hide();
	var vYear = this.currentDate.getFullYear();
	var vMonth = this.currentDate.getMonth() - 1;
	if(vMonth < 0) {
		vMonth = 11;
		vYear--;
	}
	this.goto_year_month(vYear, vMonth);
}
Calendar.prototype.next_month = function() {
	this.menu.hide();
	var vYear = this.currentDate.getFullYear();
	var vMonth = this.currentDate.getMonth() + 1;
	if(vMonth > 11) {
		vMonth = 0;
		vYear++;
	}
	this.goto_year_month(vYear, vMonth);
}
Calendar.prototype.popMonthMenu = function(pEvent, pLabelDiv) {
	if(this.menu != null) {
		emptyNode(this.menu);
		
		for(var vLoop = 0; vLoop < kMonths.length; vLoop++) {
			
			var vListItem = document.createElement("li");
			this.menu.appendChild(vListItem);
			
			var vLink = document.createElement("a");
			vListItem.appendChild(vLink);
			vLink.calendar = this;
			vLink.href = "#";
			vLink.onclick = new Function("pEvent", "this.calendar.goto_month(" + vLoop + "); return false;");
			vLink.appendChild(document.createTextNode(kMonths[vLoop]));
			
		}
		
		this.popMenu(pEvent, pLabelDiv);
		
	}
}
Calendar.prototype.popYearMenu = function(pEvent, pLabelDiv) {
	if(this.menu != null) {
		emptyNode(this.menu)
		
		var vToday = new Date();
		var vStartYear = (vToday.getFullYear() - Math.round((this.nbYears - 1)/2));
		for(var vYear = vStartYear; vYear < (vStartYear + this.nbYears); vYear++) {
			
			var vListItem = document.createElement("li");
			this.menu.appendChild(vListItem);
			
			var vLink = document.createElement("a");
			vListItem.appendChild(vLink);
			vLink.calendar = this;
			vLink.href = "#";
			vLink.onclick = new Function("pEvent", "this.calendar.goto_year(" + vYear + "); return false;");
			vLink.appendChild(document.createTextNode(vYear));
			
		}
		
		this.popMenu(pEvent, pLabelDiv);
		
	}
}


var kWeekDaysAbbrev = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var kMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];


// GENERIC, CROSS-BROWSER LIBRARIES
var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayer = 0;
var isIE = (navigator.appName.indexOf('Internet Explorer') != -1);

if(document.getElementById) {
	isID = 1;
	isDHTML = 1;
} 

if(document.all) {
	isAll = 1;
	isDHTML = 1;
} else {
	browserVersion = parseInt(navigator.appVersion);
	
	if((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
		isLayer = 1;
		isDHTML = 1;
	}
}

function findDOM(objectID, withStyle) {
	var objectRef;
	if(isID) { objectRef = document.getElementById(objectID); }
	
	if(!objectRef)
	{
		if(isAll) { 
			objectRef = eval('document.all.'+objectID); 
		} else {
			if(isLayer) { objectRef = document.layers[objectID]; }
		}
	}
	
	if(withStyle == 1) { return getStyleDOM(objectRef); }
	else { return objectRef; } 
}
function getStyleDOM(objectRef) {
	if(!objectRef) { return; }
	if(!objectRef.style) { return objectRef; }
	if(isID) { return (objectRef.style); }
	else {
		if(isAll) {
			return (objectRef.style);
		}
	}
	return objectRef;
}
function findLeft(objectRef) {
	var domStyle = getStyleDOM(objectRef);
	var result = null;
				
	if (objectRef.offsetParent) {
		while (objectRef.offsetParent) {
			result += objectRef.offsetLeft;
			objectRef = objectRef.offsetParent;
		}
	} else if(objectRef.x)
		result = objectRef.x;
	else if(domStyle.left)
		result = domStyle.left;
	else if(domStyle.pixelLeft)
		result = domStyle.pixelLeft;
		
	return result;
}
function findTop(objectRef) {
	var domStyle = getStyleDOM(objectRef);
	var result = 0;
	
	if (objectRef.offsetParent) {
		while (objectRef.offsetParent) {
			result += objectRef.offsetTop;
			objectRef = objectRef.offsetParent;
		}
	} else if(objectRef.y)
		result = objectRef.y;
	else if(domStyle.top)
		result = domStyle.top;
	else if(domStyle.pixelTop)
		result = domStyle.pixelTop;
	
	return result;
}
function findWidth(objectRef) {
	var result = 0;
	
	if(objectRef.offsetWidth)
		result = objectRef.offsetWidth;
	else if(dom.clip.width)
		result = objectRef.clip.width;
	
	return result;
}
function findHeight(objectRef) {
	var result = 0;
	
	if(objectRef.offsetHeight)
		result = objectRef.offsetHeight;
	else if(dom.clip.height)
		result = objectRef.clip.height;
	
	return result;
}
function findLivePageWidth() {
	if(window.innerWidth != null) { return window.innerWidth; }
	else {
		if(document.body.CustomerWidth != null) { return document.body.CustomerWidth; }
	}
	return 0;
}
function emptyNode(pNode) {
	if(pNode == null) return;
	
	for(var vChild = (pNode.childNodes.length - 1); vChild >= 0; vChild--) {
		if((pNode.childNodes[vChild].nodeType) == 1 || (pNode.childNodes[vChild].nodeType == 3))
			pNode.removeChild(pNode.childNodes[vChild]);
	}
}
