/* Created by D Shukri, Conchango Plc http://www.conchango.com
(based on the work of Matt Kruse http://www.mattkruse.com)*/

/*************** Script functions in this file **************
Filename: CalendarPopup.js; as of 08/30/2001
  FUNCTION:                                               LINE:
  CalendarPopup()                                          53     // CONSTRUCTOR for the CalendarPopup Object
  CalendarPopup_buildBody()                                404    // Construct calendar table body cells
  CalendarPopup_buildHeaders()                             366    // Construct day heading cells
  CalendarPopup_buildJavascript()                          278    // Construct calendar Javascript section (excluding <script><!-- --></script> tags)
  CalendarPopup_buildMonthList(index)                      337    // Construct selection list of available months
  CalendarPopup_buildStyles()                              326    // Construct calendar CSS style section (excluding <style></style> tags)
  CalendarPopup_buildYearList(index)                       350    // Construct selection list of available years
  CalendarPopup_getBody()                                  399    // Retrieve calendar table body cells
  CalendarPopup_getCalendar()                              474  
  CalendarPopup_getHeaders()                               394    // Retrieve day heading cells
  CalendarPopup_getJavascript()                            374    // Retrieve Javascript section
  CalendarPopup_getMonthList()                             384    // Retrieve selection list of available months
  CalendarPopup_getStyles()                                379    // Retrieve style section
  CalendarPopup_getYearList()                              389    // Retrieve selection list of available years
  CalendarPopup_hideCalendar()                             249    // Hide a calendar object
  CalendarPopup_refreshCalendar(index)                     258    // Refresh the contents of the calendar display
  CalendarPopup_setDateRange(dateString1,dateString2)      215    // Set start date and end date for calendar
  CalendarPopup_setDayHeaders()                            117    // Over-ride the built-in column headers for each day
  CalendarPopup_setExcludeDates(excludeDates)              149    // Set a list of non-selectable dates
  CalendarPopup_setExcludeDays(excludeDays)                205    // Set weekday indices (0-6 = Sun-Sat) to be excluded
  CalendarPopup_setMonthNames()                            109    // Over-ride the built-in month names
  CalendarPopup_setPastExclusion(val)                      187    // Set boolean flag for exclusion of past dates
  CalendarPopup_setPresentExclusion(val)                   178    // Set boolean flag for exclusion of current date
  CalendarPopup_setReturnFunction(name)                    104    // Set the name of the function to call to get the clicked date
  CalendarPopup_setTodayDate(dateString)                   130    // Set today date remotely
  CalendarPopup_setWeekStartDay(day)                       125    // Set the day of the week (0-7) that the calendar display starts on
  CalendarPopup_showCalendar(anchorname)                   269    // Populate the calendar and display it
  CalendarPopup_startTodaysMonth(val)                      196    // Override calendar beginning on first month of dateRange
  CalendarPopup_tmpReturnFunction(y,m,d)                   99     // Temporary default function to be called when a date is clicked, so no error is thrown
  daysInFeb(year)                                          566    // Determine days in February for a given year
  doubleFigure(num)                                        576    // Return double figure number
  generateHTML(index)                                      509    // Generates HTML template for the calendar popup
************ (end Script functions in this file) ***********/

// Global variables shared by the functions
var daysinmonth = new Array(0,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 now = new Date();
var windowref;

// Variables used to hold inline styles
var bgActive = '#555555';
var bgInactive = '#FFFFFF';
var fntActive = '#FFFFFF';
var fntInactive = '#999999';
var fntToday = '#000000';


// Variables used in the generateHTML() function
var launcherURL = document.location;
var pathRoot = launcherURL.protocol + '//' + launcherURL.host;
var pathImage = pathRoot + '/media/unversioned/images/popupCalendar/';
//following added by VP 7/1/03, this is used to define the path of copy.
var pathCopy = pathRoot + '/media/articles/';

// CONSTRUCTOR for the CalendarPopup Object
function CalendarPopup() {
	var newCalendar;
	newCalendar = new PopupWindow();
	newCalendar.setSize(150,175);
	newCalendar.offsetX = -152;
	newCalendar.offsetY = 25;
	newCalendar.autoHide();
	// Calendar-specific properties
	newCalendar.monthNames = monthNames;
	newCalendar.years = new Array();
	newCalendar.dayHeaders = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	newCalendar.returnFunction = "tmpReturnFunction";
	newCalendar.weekStartDay = 0;
	// Method mappings
	newCalendar.setReturnFunction = CalendarPopup_setReturnFunction;
	newCalendar.setMonthNames = CalendarPopup_setMonthNames;
	newCalendar.setDayHeaders = CalendarPopup_setDayHeaders;
	newCalendar.setTodayDate = CalendarPopup_setTodayDate;
	newCalendar.setWeekStartDay = CalendarPopup_setWeekStartDay;
	newCalendar.setExcludeDates = CalendarPopup_setExcludeDates;
	newCalendar.setPastExclusion = CalendarPopup_setPastExclusion;
	newCalendar.setPresentExclusion = CalendarPopup_setPresentExclusion;
	newCalendar.setDateRange = CalendarPopup_setDateRange;
	newCalendar.startTodaysMonth = CalendarPopup_startTodaysMonth;
	newCalendar.setExcludeDays = CalendarPopup_setExcludeDays;
	newCalendar.showCalendar = CalendarPopup_showCalendar;
	newCalendar.hideCalendar = CalendarPopup_hideCalendar;
	newCalendar.getMonthList = CalendarPopup_getMonthList;
	newCalendar.getYearList = CalendarPopup_getYearList;
	newCalendar.getHeaders = CalendarPopup_getHeaders;
	newCalendar.getBody = CalendarPopup_getBody;
	newCalendar.refreshCalendar = CalendarPopup_refreshCalendar;
	newCalendar.getCalendar = CalendarPopup_getCalendar;
	newCalendar.buildJavascript = CalendarPopup_buildJavascript;
	newCalendar.buildMonthList = CalendarPopup_buildMonthList;
	newCalendar.buildYearList = CalendarPopup_buildYearList;
	newCalendar.buildHeaders = CalendarPopup_buildHeaders;
	newCalendar.buildBody = CalendarPopup_buildBody;
	// Return the object
	return newCalendar;
	}

// Temporary default function to be called when a date is clicked, so no error is thrown
function CalendarPopup_tmpReturnFunction(y,m,d){
	alert('Use setReturnFunction() to define which function will get the clicked results!');
	}

// Set the name of the function to call to get the clicked date
function CalendarPopup_setReturnFunction(name){
	this.returnFunction = name;
	}

// Over-ride the built-in month names
function CalendarPopup_setMonthNames(){
	for(var i=0; i<arguments.length; i++){
		monthNames[i] = arguments[i];
		this.monthNames = monthNames
	}
}

// Over-ride the built-in column headers for each day
function CalendarPopup_setDayHeaders(){
	for(var i=0; i<arguments.length; i++){
		this.dayHeaders[i] = arguments[i];
	}
}

// Set the day of the week (0-7) that the calendar display starts on
// This is for countries other than the US whose calendar displays start on Monday(1), for example
function CalendarPopup_setWeekStartDay(day){
	this.weekStartDay = day;
}

// Set today date remotely
function CalendarPopup_setTodayDate(dateString){
	dateString = dateString.substring(0,10);// Trim timestamp
	// If valid-looking date and month not greater than 12
	if(dateString.search(/^2[0-9]{3}-[0-1][0-9]-[0-3][0-9]$/) !=-1 && (parseInt(parseFloat(dateString.substring(5,7))) <= 12)){
		dateStringParts = dateString.split('-');
		year = dateStringParts[0];
		month = dateStringParts[1];
		day = dateStringParts[2];
		daysInFeb(year);
		// If day is within the range of the current month
		if(0 < parseInt(parseFloat(day)) <= daysinmonth[parseInt(parseFloat(month))+1]){
			this.todayDate = new Date(year,month,day);
		}
	}else{
		alert('incorrect dateString supplied to setTodayDate()')
	}
}

// Set a list of non-selectable dates
function CalendarPopup_setExcludeDates(excludeDates){
	excludeDatesArray = excludeDates.split(',');
	errorPos = '';
	// for each element of excludeDatesArray that is expected to contain a date
	for(i = 1;i < excludeDatesArray.length-1;i++){
		// If not valid-looking date add position to reported errors
		if(excludeDatesArray[i].search(/^[0-3][0-9]\/[0-1][0-9]\/2[0-9]{3}$/) == -1){
			errorPos += i + ',';
		}else{
			excludeDateParts = excludeDatesArray[i].split('/');
			day = parseInt(parseFloat(excludeDateParts[0]));
			month = parseInt(parseFloat(excludeDateParts[1]));
			// If month greater than 12 add position to reported errors
			month > 12 ? errorPos += i + ',':errorPos += '';
			year = parseInt(excludeDateParts[2]);
			daysInFeb(year);
			// If day not valid for month add position to reported errors
			!(0 < day <= daysinmonth[month]) ? errorPos += i + ',':errorPos += ''
		}
	}
	// If all dates valid set excludeDates property
	if(errorPos == ''){
		this.excludeDates = excludeDates;
	}else{
		alert('Invalid date at positions ' + errorPos + ' in input string (zero-indexed) of setExcludeDates() method')
	}
}

// Set boolean flag for exclusion of current date
function CalendarPopup_setPresentExclusion(val){
	if(!(val == true || val == false)){
		alert('setPresentExclusion() method accepts only true or false as a parameter')
	}else{
		this.excludePresent = val
	}
}

// Set boolean flag for exclusion of past dates
function CalendarPopup_setPastExclusion(val){
	if(!(val == true || val == false)){
		alert('setPastExclusion() method accepts only true or false as a parameter')
	}else{
		this.excludePast = val
	}
}

// Override calendar beginning on first month of dateRange
function CalendarPopup_startTodaysMonth(val){
	if(!(val == true || val == false)){
		alert('startTodaysMonth() method accepts only true or false as a parameter')
	}else{
		this.startTodayMonth = val
	}
}

// Set weekday indices (0-6 = Sun-Sat) to be excluded
function CalendarPopup_setExcludeDays(excludeDays){
	dayIndexRE = new RegExp(/[^ 0-6]/);
	if(dayIndexRE.exec(excludeDays) != null){
		alert('Invalid day index in input string of setExcludeDays() method')
	}else{
		this.excludeDays = excludeDays;
	}
}

// Set start date and end date for calendar
function CalendarPopup_setDateRange(dateString1,dateString2){
	for(i=0;i < arguments.length;i++){
		arguments[i] = arguments[i].substring(0,10);
		if(arguments[i].search(/^2[0-9]{3}-[0-1][0-9]-[0-3][0-9]$/) !=-1 && (parseInt(parseFloat(arguments[i].substring(5,7))) <= 12)){
			argumentParts = arguments[i].split('-');
			year = argumentParts[0];
			month = argumentParts[1];
			day = argumentParts[2];
			daysInFeb(year);
			if(0 < parseInt(parseFloat(day)) <= daysinmonth[parseInt(parseFloat(month))]){
				i==0 ? rangeStart = year + '' + month + '' + day : rangeEnd = year + '' + month + '' + day;
			}
		}else{
			alert('incorrect dateString supplied to setDateRange()')
		}
	}
	if(parseInt(rangeStart) <= parseInt(rangeEnd)){
		this.rangeStart = rangeStart;
		this.rangeEnd = rangeEnd;
		startYear = parseInt(rangeStart.substring(0,4));
		endYear = parseInt(rangeEnd.substring(0,4));
		arrayIndex = 0;
		for(i = startYear;i < endYear+1;i++){
			this.startYear = startYear;
			this.endYear = endYear;
			this.years[arrayIndex] = i;
			arrayIndex++
		}
	}else{
		alert('rangeStart date must be earlier than rangeEnd date')
	}
}

// Hide a calendar object
function CalendarPopup_hideCalendar(){
	if (arguments.length > 0){
		window.popupWindowObjects[arguments[0]].hidePopup()
	}else{
		this.hidePopup()
	}
}

// Refresh the contents of the calendar display
function CalendarPopup_refreshCalendar(index) {
	var calObject = window.popupWindowObjects[index];
	if(arguments.length>1){
		calObject.populate(calObject.getCalendar(arguments[1],calObject.years[arguments[2]]));
	}else{
		calObject.populate(calObject.getCalendar())
	}
	calObject.refresh()
}

// Populate the calendar and display it
function CalendarPopup_showCalendar(anchorname){
	this.buildJavascript();
	this.buildHeaders();
	this.populate(this.getCalendar());
	this.showPopup(anchorname);
}

// Construct calendar Javascript section (excluding <script><!-- --></script> tags)
function CalendarPopup_buildJavascript(){
	this.Javascript = '\n\t\tvar imgNames = new Array();\/\/store of img names';
	this.Javascript += '\n\t\tvar newImg = new Array();\/\/store of replacement img objects';
	this.Javascript += '\n\t\tvar origSrc = new Array();\/\/store of original img paths';
	this.Javascript += '\n\t\tvar loaded = false;\/\/\'loaded\' state flag\n';
	
	// Start writing preload() function
	this.Javascript += '\n\t\tfunction preload(ref){\n\t\t\t!ref ? ';
	this.Javascript += 'ref = null:ref = ref;\n\t\t\tfor(i = 0;i <';
	this.Javascript += ' document.images.length;i++){\n\t\t\t\timg =';
	this.Javascript += ' document.images[i]; \/\/Assigns current image to variable img';
	this.Javascript += '\n\t\t\t\tif(img.src.substring(img.src.lastIndexOf(\'.\')-4,';
	this.Javascript += 'img.src.lastIndexOf(\'.\')) == \'_off\'){\n\t\t\t\t\t';
	this.Javascript += 'imgNames[i] = img.name;\n\t\t\t\t\t origSrc[i] = img.src; ';
	this.Javascript += '//Stores image location in origSrc array\n\t\t\t\t\t';
	this.Javascript += 'newImg[i] = new Image(); \/\/Creates new image in newImg array';
	this.Javascript += '\n\t\t\t\t\t newImg[i].src = img.src.substring(0,img.src.';
	this.Javascript += 'lastIndexOf(\'.\')-3) + \'on\' + img.src.';
	this.Javascript += 'substring(img.src.lastIndexOf(\'.\')); \/\/Constructs the path';
	this.Javascript += ' for the newImg image preserving img src extension\n\t\t\t\t';
	this.Javascript += ' }\n\t\t\t }\n\t\t loaded = true;\n\t\t }\n';
	
	// Start writing hilight() function
	this.Javascript += '\n\t\tfunction hilight(ref){\n\t\t\t num = refToNum(ref);';
	this.Javascript += '\n\t\t\t if(loaded){\n\t\t\t\t img = document.images[ref];';
	this.Javascript += '\n\t\t\t\t img.src = newImg[num].src \/\/Set link\'s image ';
	this.Javascript += 'to new source\n\t\t\t }\n\t\t }\n';
	
	// Start writing lolight() function
	this.Javascript += '\n\t\tfunction lolight(ref){\n\t\t\t num = refToNum(ref);';
	this.Javascript += '\n\t\t\t if(loaded){\n\t\t\t\t img = document.images[ref];';
	this.Javascript += '\n\t\t\t\t img.src = origSrc[num] \/\/Set link\'s image ';
	this.Javascript += 'to original source\n\t\t\t }\n\t\t }\n';
	
	// Start writing refToNum() function
	this.Javascript += '\n\t\tfunction refToNum(ref){\n\t\t\t if(isNaN(ref)){';
	this.Javascript += '//If \'ref\' is not numeric\n\t\t\t\t for(i=0;i<imgNames.';
	this.Javascript += 'length;i++){\/\/For each name in imgNames array\n\t\t\t\t\t';
	this.Javascript += ' if(ref == imgNames[i]){\n\t\t\t\t\t\t num = i;\n\t\t\t\t\t\t';
	this.Javascript += ' break\n\t\t\t\t\t }\n\t\t\t\t }\n\t\t\t }else{\n\t\t\t\t num';
	this.Javascript += ' = parseInt(ref, 10)\n\t\t\t }\n\t\t\t return num\n\t\t }\n';
	
	// Addition of getJavascript() method to calendar object
	//(not added with other mappings due to NS4.x issue)
	this.getJavascript = CalendarPopup_getJavascript
}

// Construct selection list of available months
function CalendarPopup_buildMonthList(index){
	!index ? index = this.display_month-1: index=index;
	this.monthList = '<select name="availMonths" onchange="javascript:window.opener.CalendarPopup';
	this.monthList += '_refreshCalendar(0,this.selectedIndex,document.forms[0].elements[1].selectedIndex);">\n\t\t';
	for(i=0;i < monthNames.length;i++){
		this.monthList += '\t<option';
		i == index ? this.monthList += ' selected':this.monthList +='';
		this.monthList += '>' + monthNames[i] + '</option>\n\t'
	}
	this.monthList += '</select>'
}

// Construct selection list of available years
function CalendarPopup_buildYearList(index){
	this.yearList = '<select name="availYears" onchange="javascript:window.opener.CalendarPopup';
	this.yearList += '_refreshCalendar(0,document.forms[0].elements[0].selectedIndex,this.selectedIndex);">\n\t\t';
	if(this.years.length > 0){
		for(i=0;i < this.years.length;i++){
			this.yearList += '\t<option';
			i == index ? this.yearList += ' selected' : this.yearList += '';
			this.yearList += '>' + this.years[i] + '</option>\n\t'
		}
	}else{
		this.yearList += '\t<option>' + this.display_year + '</option>\n\t'
	}
	this.yearList += '</select>'
}

// Construct day heading cells
function CalendarPopup_buildHeaders(){
	this.headers = '';
	for(i=0;i<7;i++){
		this.headers += '\t<td align="center" width="38"><font face="Arial" size="3"><strong>'+this.dayHeaders[(this.weekStartDay+i)%7]+'</strong></font></td>\n';
	}
}

// Retrieve Javascript section
function CalendarPopup_getJavascript(){
	return this.Javascript
}

// Retrieve selection list of available months
function CalendarPopup_getMonthList(){
	return this.monthList
}

// Retrieve selection list of available years
function CalendarPopup_getYearList(){
	return this.yearList
}

// Retrieve day heading cells
function CalendarPopup_getHeaders(){
	return this.headers
}

// Retrieve calendar table body cells
function CalendarPopup_getBody(){
	return this.body
}

// Construct calendar table body cells
function CalendarPopup_buildBody(){
	windowref = 'window.opener.';
	var dayofmonth = 1;
	this.body = '';
	colWidth = 36;
	monthStartDate = new Date(this.display_month+ '/' + dayofmonth + '/' +this.display_year)
	monthStartDay = monthStartDate.getDay();
	// Possible that month will span 6 weeks (rows)
	for (row=1; row<=6; row++){
		// Seven days in a week
		for (col=1; col<=7; col++){
			// Determine number of columns that the leading cell should span
			colspan = (7-(this.weekStartDay-monthStartDay))%7;
			if(row==1 && col==1 && (colspan!=0)){
				// Add leading cell to calendar body string
				this.body += '<td colspan="' + colspan +'" height="28" width="';
				this.body += colspan*(colWidth+1) + '"></td>\n\t\t';
				col += colspan-1;// Set the column to continue from
				dayofmonth = 1// Reset to first day of the month
			}else{
				// If more cells than days in the display_month
				if(dayofmonth > daysinmonth[this.display_month]){
					colspan = 8-col;
					this.body += '<td colspan="' + colspan +'" height="28" width="' + colspan*(colWidth+1) + '"></td>\n\t\t';
					col += colspan
				}else{
					/* Begin construction of regular expression pattern with which to
					search list of excluded dates*/
					pattern = doubleFigure(dayofmonth) + '\\/';
					pattern += doubleFigure(this.display_month) + '\\/';
					pattern += this.display_year;
					patternRE = new RegExp(pattern);// Create regexp from pattern
					// Create date for current cell
					currentDate = new Date(this.display_year,this.display_month-1,dayofmonth);
					// Create simple date string
					simpleDate = this.display_year + '';
					simpleDate += doubleFigure(this.display_month);
					simpleDate += doubleFigure(dayofmonth);
					this.excludeDates ? dayExcluded = (patternRE.exec(this.excludeDates) != null) : dayExcluded = false;
					this.excludeDays && this.excludeDays.search(currentDate.getDay()) != -1 ? excludedWeekDay = true : excludedWeekDay = false;
					dateInPast = (this.excludePast && (simpleDate < this.today));
					outsideDateRange = (this.rangeStart && this.rangeEnd && (simpleDate < this.rangeStart || simpleDate > this.rangeEnd));
					// If date is equal to this.todayDate
					if ((this.display_month == this.todayDate.getMonth()) && (dayofmonth==this.todayDate.getDate()) && (this.display_year==this.todayDate.getFullYear())) {
						if(dayExcluded || excludedWeekDay || dateInPast || outsideDateRange){
							td_style = 'today_inactive'
						}else{
							td_style = 'today_active'
						}
						// Exclude this day if excludePresent is true
						this.excludePresent ? this.excludeDates += ',' + dayofmonth + '/' + this.display_month + '/' + this.display_year:this.excludeDates += '';
					}else if(dayExcluded || excludedWeekDay || dateInPast || outsideDateRange){
						td_style = 'inactive'
					}else{
						td_style = 'active'
					}
					switch(td_style){
						case 'active':
							this.body += '\t\t<td align="center" bgcolor="' + bgActive + '" height="28" width="' + colWidth +'"><a';
							this.body += ' href="javascript:';
							this.body += windowref+this.returnFunction+'('+this.display_year+',';
							this.body += this.display_month+','+dayofmonth+');'+windowref;
							this.body += 'CalendarPopup_hideCalendar(\''+this.index+'\');" ><font face="Arial" size="3" color="' + fntActive + '">'+dayofmonth+'</font></a>';
							break;
						case 'inactive':
							this.body += '\t\t<td align="center" bgcolor="' + bgInactive + '" height="28" width="' + colWidth +'"><font face="Arial" size="3" color="' + fntInactive + '">' + dayofmonth + '</font>'
							break;
						case 'today_active':
							this.body += '\t\t<td align="center" bgcolor="' + bgActive + '" height="28" width="' + colWidth +'"><a';
							this.body += ' href="javascript:';
							this.body += windowref+this.returnFunction+'('+this.display_year+',';
							this.body += this.display_month+','+dayofmonth+');'+windowref;
							this.body += 'CalendarPopup_hideCalendar(\''+this.index+'\');" ><font face="Arial" size="3" color="' + fntToday + '">'+dayofmonth+'</font></a>';
							break;
						case 'today_inactive':
							this.body += '\t\t<td align="center" bgcolor="' + bgInactive + '" height="28" width="' + colWidth +'"><font face="Arial" size="3" color="' + fntToday + '">' + dayofmonth + '</font>'
							break;
					}
					this.body += '</TD>\n\t';
					dayofmonth++
				}
			}
		}
		row == 6 ? this.body += '' : this.body += '</tr>\n\t<tr>\n\t\t'
	}
}

function CalendarPopup_getCalendar(){
	!this.todayDate ? this.todayDate = now : this.todayDate = this.todayDate;
	
	if(arguments.length > 0){
		this.display_month = arguments[0]+1
	}else if(this.rangeStart && !this.startTodayMonth){
		startMonth = this.rangeStart.substring(4,6);
		this.display_month = parseInt(parseFloat(startMonth));	
	}else{
		this.display_month = this.todayDate.getMonth();
	}

	if(arguments.length > 1){
		this.display_year = arguments[1]
  } else if (this.rangeStart && !this.startTodayMonth){
		startYear = this.rangeStart.substring(0,4);
		this.display_year = parseInt(startYear)
	}else{
		this.display_year = this.todayDate.getFullYear();
	}
	
	this.today = this.todayDate.getFullYear();
	this.today += doubleFigure(this.todayDate.getMonth()+1);
	this.today += this.todayDate.getDate();
	daysInFeb(this.year);
	var current_fulldate = new Date(this.display_year,this.display_month-1,1);
	this.weekday= current_fulldate.getDay();
	this.buildMonthList(this.display_month-1);
	this.buildYearList(this.display_year-this.startYear);
	this.buildBody();
	this.content = generateHTML();
	return this.content
}

// Generates HTML template for the calendar popup
function generateHTML(index){
	!index ? index = 0 : index = index;
	var calObject = window.popupWindowObjects[index];
	HTML = '<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">\n\n<html>\n<head>\n\t';
	HTML += '<title>Calendar</title>\n\t';
	if(!document.layers){
		HTML += '<script language="javascript" type="text/javascript">';
		HTML += '\n\t<!--\n\t' + calObject.getJavascript() + '\n\t//-->\n\t</script>\n'
	}
	HTML += '</head>\n';
	HTML += '<body marginwidth="0" marginheight="0" topmargin="0" rightmargin="0" leftmargin="0" onload="javascript:preload();">\n';

	// Start writing controls table
	HTML += '<form action="about:blank">\n<table width="278" border="0" cellspacing="0" cellpadding="0">\n';
	HTML += '\t<tr>\n\t\t<td bgcolor="#CCCCCC" colspan="5" width="278">';
	HTML += '<img align="left" src="' + pathImage + 'calendar_title.gif" width="133" height="20"';
	HTML += ' alt="Calendar" border="0" vspace="7" hspace="4"></td>\n\t</tr>\n\t<tr>';
	HTML += '<td rowspan="3" width="6" bgcolor="#CCCCCC">&nbsp;</td>\n\t\t';
	HTML += '<td bgcolor="#CCCCCC" class="text" colspan="4" height="10" valign="top">';
	HTML += '<font face="Arial" size="3">Please select the date by clicking it.</font></tr>\n\t<tr>\n\t\t';
	HTML += '<td height="4" bgcolor="#CCCCCC" colspan="4"><img src="' + pathImage + 'trans.gif" ';
	HTML += 'height="1" width="272" border="0" alt=""></td>\n\t</tr>\n\t<tr>\n\t\t';
	HTML += '<td bgcolor="#CCCCCC" height="12" valign="bottom">' + calObject.getMonthList() + '</td>\n\t\t';
	HTML += '<td bgcolor="#CCCCCC" width="9">&nbsp;</td>\n\t\t';
	HTML += '<td bgcolor="#CCCCCC">' + calObject.getYearList() + '</td>\n\t\t';
	HTML += '<td align="right" bgcolor="#CCCCCC" valign="bottom"><a href="javascript:';
	HTML += 'window.opener.CalendarPopup_hideCalendar(0);" onmouseover="hilight(\'closeButt\')" ';
	HTML += 'onmouseout="lolight(\'closeButt\')"><img name="closeButt" src="' + pathImage + 'close_off.gif" ';
	HTML += 'hspace="6" vspace="0" border="0" alt="Close"></a></td>\n\t</tr>\n\t<tr>';
	HTML += '<td bgcolor="#CCCCCC" colspan="5" width="278"><img src="' + pathImage;
	HTML += 'trans.gif" width="1" height="7" hspace="0" vspace="0" border="0" alt=""></td>\n\t';
	HTML += '</tr>\n</table>\n\n';

	// Start writing calendar table
	HTML += '<table width="278" border="0" cellpadding="0" cellspacing="0">\n\t<tr>\n\t\t';
	HTML += '<td bgcolor="#555555" colspan="8" width="276"><img src="' + pathImage;
	HTML +='trans.gif" border="0" alt="" height="1" width="276"></td>\n\t</tr>\n\t';
	HTML += '<tr bgcolor="#A8A6A6">\n\t\t<td class="headers" width="6"><img src="' + pathImage;
	HTML += 'trans.gif" width="6" height="20" border="0" alt=""></td>\n\t\t';
	HTML += calObject.getHeaders() + '\n\t</tr>\n\t<tr>\n\t\t';
	HTML += '<td bgcolor="#555555" colspan="8" width="276"><img src="' + pathImage;
	HTML += 'trans.gif" border="0" alt="" height="1" width="276"></td>\n\t</tr>\n\t<tr>\n\t\t';
	HTML += '<td bgcolor="#555555" rowspan="4" width="11"><img src="' + pathImage;
	HTML += 'trans.gif" width="11" height="205" border="0" alt=""></td>';
	HTML += '<td colspan="7">\n\t\t\t<table border="1" bordercolor="#C0C0C0" cellpadding="0"';
	HTML += ' cellspacing="0">\n\t\t\t\t<tr>\n\t\t\t\t\t' + calObject.getBody();
	HTML += '</tr>\n\t\t\t</table>\n\t\t</td>\n\t</tr>\n\t<tr><td colspan="7" height="3">';
	HTML += '</td>\n\t</tr>\n\t<tr>\n\t\t<td height="19"><img src="' + pathImage;
	HTML += 'available.gif" border="0" alt="Swatch of color #004659" hspace="7"></td>\n';
	HTML += '\t\t<td class="text" colspan="6"><font face="Arial" size="3">Dates available to select</font></td>\n\t</tr>\n\t<tr>\n';
	HTML += '\t\t<td height="19"><img src="' + pathImage + 'unavailable.gif"';
	HTML += ' border="0" alt="Swatch of color #FFFFFF" hspace="7"></td>\n\t\t<td class="text" colspan="6">';
	HTML += '<font face="Arial" size="3">Dates not available</font></td>\n\t</tr>\n\t<tr>\n\t\t';
	HTML += '<td colspan="7" height="3"></td>\n\t</tr>';
	HTML += '</table>\n\n</form>\n</body>\n</html>';
	return HTML
}

// Determine days in February for a given year
function daysInFeb(year) {
	if (year == null) {
		var curdate = new Date();
		year = curdate.getYear();	}
	if (((year%4 == 0)&&(year%100 != 0)) || (year%400 == 0)){ // leap year
		febDays = 29;
	} else {
		febDays = 28;
	}
	daysinmonth[2] = febDays;
}

// Return double figure number
function doubleFigure(num){
	// Prepend '0' if num < 10
	num < 10 ? numString = '0' + num : numString = num;
	return numString
}