// Variable for storing previous date cell information
var objPrevElement = new Object();
// Variable to be used as a constant, some people want the calendar week to start with a Monday, some on a Sunday, comment/uncomment required start of week day
var StartDayOfWeek = "Monday";
//var StartDayOfWeek = "Sunday";

function setStartupDate()
{
	var dCurDate = new Date();
	setDate(dCurDate.getFullYear(), dCurDate.getMonth()+1, dCurDate.getDate());
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Function called when a cell in table is selected, performs the required display changes, also fires an event (this event does not have to be used, here - just incase)
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function setSelectedDateCell(selectedElement){
	
	if (selectedElement.id == "calendarCell") 
	{
	    if(document.all)
	    {
		    if (!isNaN(parseInt(selectedElement.children["calendarCellText"].innerText)))
		    {
			    if(selectedElement.children["calendarCellText"].color == '#ffffff'){
				    if(selectedElement.children["calendarCellText"].innerText < 15) {
					    if(document.all("calendarSelectMonth").options.selectedIndex == 11) {
						    document.all("calendarSelectYear").options.selectedIndex = document.all("calendarSelectYear").options.selectedIndex + 1;
						    document.all("calendarSelectMonth").options.selectedIndex = 0;
					    } else {
						    document.all("calendarSelectMonth").options.selectedIndex = document.all("calendarSelectMonth").options.selectedIndex + 1;
					    }
				    } else {
					    if(document.all("calendarSelectMonth").options.selectedIndex == 0) {
						    document.all("calendarSelectYear").options.selectedIndex = document.all("calendarSelectYear").options.selectedIndex - 1;
						    document.all("calendarSelectMonth").options.selectedIndex = 11;
					    } else {
						    document.all("calendarSelectMonth").options.selectedIndex = document.all("calendarSelectMonth").options.selectedIndex - 1;
					    }
				    }
				    refreshCalendar(document.all("calendarSelectYear").value, document.all("calendarSelectMonth").value, selectedElement.children["calendarCellText"].innerText);
			    } else if(selectedElement.children["calendarCellText"].color == '#000000') {
    			
				    selectedElement.style.backgroundColor = "#2b7e2a";
				    selectedElement.style.borderTop = "black 1px solid";
				    selectedElement.style.borderLeft = "black 1px solid";
				    selectedElement.style.borderBottom = "lightgrey 1px solid";
				    selectedElement.style.borderRight = "lightgrey 1px solid";
				    selectedElement.children["calendarCellText"].color = 'yellow';

				    try{
				    objPrevElement.style.backgroundColor = "#c6dabe";
				    objPrevElement.style.borderTop = "white 1px solid";
				    objPrevElement.style.borderLeft = "white 1px solid";
				    objPrevElement.style.borderBottom = "darkgray 1px solid";
				    objPrevElement.style.borderRight = "darkgray 1px solid";
				    objPrevElement.children["calendarCellText"].color = '#000000';
				    } catch(dontcare) {}
    			
				    document.all("calendarSelectDate").value = parseInt(selectedElement.children["calendarCellText"].innerText);
				    objPrevElement = selectedElement;
				    try {
					    calendarDate_changed(); //Call event - let user do something else after day changed
				    } catch(nothing_important){}
			    }
		    }
		}
		else
		{
		    // ok lets make a fix for this script
		    try
		    {
		        //check that we have a number to deal with
		        var intDay = parseInt(selectedElement.firstChild.textContent);
		        if(!isNaN(intDay))
		        {
		            //do a check against the color, WHY???
		            if(selectedElement.firstChild.color = '#ffffff')
		            {

		                if(selectedElement.childNodes[0].innerText < 15) {
					        if(document.getElementById("calendarSelectMonth").options.selectedIndex == 11) {
						        document.getElementById("calendarSelectYear").options.selectedIndex = document.getElementById("calendarSelectYear").options.selectedIndex + 1;
						        document.getElementById("calendarSelectMonth").options.selectedIndex = 0;
					        } else {
						        document.getElementById("calendarSelectMonth").options.selectedIndex = document.getElementById("calendarSelectMonth").options.selectedIndex + 1;
					        }
				        } else {
					        if(document.getElementById("calendarSelectMonth").options.selectedIndex == 0) {
						        document.getElementById("calendarSelectYear").options.selectedIndex = document.getElementById("calendarSelectYear").options.selectedIndex - 1;
						        document.getElementById("calendarSelectMonth").options.selectedIndex = 11;
					        } else {
						        document.getElementById("calendarSelectMonth").options.selectedIndex = document.getElementById("calendarSelectMonth").options.selectedIndex - 1;
					        }
				        }
				        refreshCalendar(document.getElementById("calendarSelectYear").value, document.getElementById("calendarSelectMonth").value, selectedElement.childNodes[0].innerText);

		            }
		            else if(selectedElement.firstChild.color = '#000000')
		            {
		            
		                selectedElement.style.backgroundColor = "#2b7e2a";
				        selectedElement.style.borderTop = "black 1px solid";
				        selectedElement.style.borderLeft = "black 1px solid";
				        selectedElement.style.borderBottom = "lightgrey 1px solid";
				        selectedElement.style.borderRight = "lightgrey 1px solid";
				        selectedElement.firstChild.color = 'yellow';

				        try{
				            objPrevElement.style.backgroundColor = "#c6dabe";
				            objPrevElement.style.borderTop = "white 1px solid";
				            objPrevElement.style.borderLeft = "white 1px solid";
				            objPrevElement.style.borderBottom = "darkgray 1px solid";
				            objPrevElement.style.borderRight = "darkgray 1px solid";
				            selectedElement.firstChild.color = '#000000';
				        } catch(dontcare) {}
        			
				        document.getElementById("calendarSelectDate").value = parseInt(selectedElement.childNodes[0].innerText);
				        objPrevElement = selectedElement;
				        try {
					        calendarDate_changed(); //Call event - let user do something else after day changed
				        } catch(nothing_important){}
		            
		            }
		        }
		    }
		    catch(ex)
		    {
		        // handle the exception
		    }
		}
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to return the number of days for a given month in a given year (required to check for leap year)
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function numberOfDaysInMonth(iMonth, iYear) {
	var dPrevDate = new Date(iYear, iMonth, 0);
	return dPrevDate.getDate();
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to create the cell information for the calendar control, returns an array of information to build the calendar
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function GenerateCalendar(iYear, iMonth, iDayStyle) {
	var aMonth = new Array();
	aMonth[0] = new Array(7);
	aMonth[1] = new Array(7);
	aMonth[2] = new Array(7);
	aMonth[3] = new Array(7);
	aMonth[4] = new Array(7);
	aMonth[5] = new Array(7);
	aMonth[6] = new Array(7);

	var dCalDate = new Date(iYear, iMonth-1, 1);
	var iDayOfFirst = dCalDate.getDay();

	if(StartDayOfWeek=="Monday"){
		if(iDayOfFirst>0){
			iDayOfFirst--;
		} else {
			iDayOfFirst = 6;
		}
	}

	var endDays = 1;

	var iDaysInMonth = numberOfDaysInMonth(iMonth, iYear);
	var iVarDate = 1;
	var i, d, w;

	if(StartDayOfWeek=="Monday"){
		if (iDayStyle == 2) {
			aMonth[0][6] = "Sunday"; aMonth[0][0] = "Monday"; aMonth[0][1] = "Tuesday"; aMonth[0][2] = "Wednesday"; aMonth[0][3] = "Thursday"; aMonth[0][4] = "Friday"; aMonth[0][5] = "Saturday";
		} else if (iDayStyle == 1) {
			aMonth[0][6] = "Sun"; aMonth[0][0] = "Mon"; aMonth[0][1] = "Tue"; aMonth[0][2] = "Wed"; aMonth[0][3] = "Thu"; aMonth[0][4] = "Fri"; aMonth[0][5] = "Sat";
		} else {
			aMonth[0][6] = "Su"; aMonth[0][0] = "Mo"; aMonth[0][1] = "Tu"; aMonth[0][2] = "We"; aMonth[0][3] = "Th"; aMonth[0][4] = "Fr"; aMonth[0][5] = "Sa";
		}
	} else {
		if (iDayStyle == 2) {
			aMonth[0][0] = "Sunday"; aMonth[0][1] = "Monday"; aMonth[0][2] = "Tuesday"; aMonth[0][3] = "Wednesday"; aMonth[0][4] = "Thursday"; aMonth[0][5] = "Friday"; aMonth[0][6] = "Saturday";
		} else if (iDayStyle == 1) {
			aMonth[0][0] = "Sun"; aMonth[0][1] = "Mon"; aMonth[0][2] = "Tue"; aMonth[0][3] = "Wed"; aMonth[0][4] = "Thu"; aMonth[0][5] = "Fri"; aMonth[0][6] = "Sat";
		} else {
			aMonth[0][0] = "Su"; aMonth[0][1] = "Mo"; aMonth[0][2] = "Tu"; aMonth[0][3] = "We"; aMonth[0][4] = "Th"; aMonth[0][5] = "Fr"; aMonth[0][6] = "Sa";
		}
	}

	if(iDayOfFirst!=0)
	{
		var tmpDaysInPrevMonth = numberOfDaysInMonth(iMonth-1, iYear);
		var aa=tmpDaysInPrevMonth-iDayOfFirst+1;
		for (var bb=0; bb<iDayOfFirst; bb++)
		aMonth[1][bb] =100 + (aa+bb);
	}

	for (d = iDayOfFirst; d < 7; d++) {
		aMonth[1][d] = iVarDate;
		iVarDate++;
	}

	for (w = 2; w < 7; w++) {
		for (d = 0; d < 7; d++) {
			if (iVarDate <= iDaysInMonth) {
				aMonth[w][d] = iVarDate;
				iVarDate++;
			}else {
				aMonth[w][d] = 100 + endDays;
				endDays++;
			}
		}
	}
	return aMonth;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to create the HTML code for the day part of the calendar in a table format
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function createHTMLCalendar(iYear, iMonth, iCellWidth, iCellHeight, sDateTextSize, sDateTextWeight, iDayStyle) {
	var myMonth;
	myMonth = GenerateCalendar(iYear, iMonth, iDayStyle);
	if(document.all)
	{
	    document.write("<table border='0' cellspacing='1' cellpadding='1' bgcolor='black'>")
	    document.write("<tr>");
	    document.write("<td class='Header' bgcolor='silver' align='center' style='border-left: white 1px solid;border-top: white 1px solid;border-right: darkgray 1px solid;border-bottom: darkgray 1px solid;'>" + myMonth[0][0] + "</td>");
	    document.write("<td class='Header' bgcolor='silver' align='center' style='border-left: white 1px solid;border-top: white 1px solid;border-right: darkgray 1px solid;border-bottom: darkgray 1px solid;'>" + myMonth[0][1] + "</td>");
	    document.write("<td class='Header' bgcolor='silver' align='center' style='border-left: white 1px solid;border-top: white 1px solid;border-right: darkgray 1px solid;border-bottom: darkgray 1px solid;'>" + myMonth[0][2] + "</td>");
	    document.write("<td class='Header' bgcolor='silver' align='center' style='border-left: white 1px solid;border-top: white 1px solid;border-right: darkgray 1px solid;border-bottom: darkgray 1px solid;'>" + myMonth[0][3] + "</td>");
	    document.write("<td class='Header' bgcolor='silver' align='center' style='border-left: white 1px solid;border-top: white 1px solid;border-right: darkgray 1px solid;border-bottom: darkgray 1px solid;'>" + myMonth[0][4] + "</td>");
	    document.write("<td class='Header' bgcolor='silver' align='center' style='border-left: white 1px solid;border-top: white 1px solid;border-right: darkgray 1px solid;border-bottom: darkgray 1px solid;'>" + myMonth[0][5] + "</td>");
	    document.write("<td class='Header' bgcolor='silver' align='center' style='border-left: white 1px solid;border-top: white 1px solid;border-right: darkgray 1px solid;border-bottom: darkgray 1px solid;'>" + myMonth[0][6] + "</td>");
	    document.write("</tr>");
	
	    for (w = 1; w < 7; w++) {
		    document.write("<tr>")
		    for (d = 0; d < 7; d++) {
			    document.write("<td class='Cells'  align='center' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "' id=calendarCell style='border-left: white 1px solid;border-top: white 1px solid;border-right: darkgray 1px solid;border-bottom: darkgray 1px solid; CURSOR:Hand;background:#c6dabe' onclick=setSelectedDateCell(this)>");
				    if (!isNaN(myMonth[w][d])) {
					    if(myMonth[w][d]>100) {
						    document.write("<font color='#ffffff' id=calendarCellText name'calendarCellText' style='CURSOR:Hand;' onclick=setSelectedDateCell(this)>" + (myMonth[w][d]-100) + "</font>");
					    } else {
					    document.write("<font color='#000000' id=calendarCellText style='CURSOR:Hand;' onclick=setSelectedDateCell(this)>" + myMonth[w][d] + "</font>");
					    }
				    } else {
				    document.write("<font id=calendarCellText style='CURSOR:Hand;' onclick=setSelectedDateCell(this)>&nbsp;</font>");
				    }
			    document.write("</td>")
		    }
		    document.write("</tr>");
	    }
	}
	else
	{
	    document.write("<table border='0' cellspacing='1' cellpadding='1'")
	    document.write("<tr><td colpan='3'>Day:");
	    document.write("<select name='CalenderDay' id='CalenderDay'>");
	    for(i = 1; i <= 31; i++)
	    {
	        document.write("<option value='" + i + "'>" + i + "</option>");
	    }
	    document.write("</select>");
	    document.write("</td></tr>");
	}
	document.write("</table>")
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to redraw the contents of the calendar cells - this is used to create a new month and/or year
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function refreshCalendar(iYear, iMonth, iDay) {
    //var calendarCellText = calendarCellText;
    if(!document.all)
    {
        calendarCellText = document.getElementsByName("calendarCellText");
    }
	myMonth = GenerateCalendar(iYear, iMonth);
	var daySet = false;
	for (w = 1; w < 7; w++) {
	for (d = 0; d < 7; d++) {
	if (!isNaN(myMonth[w][d])) {
		if (myMonth[w][d]>100) {
			calendarCellText[((7*w)+d)-7].innerText = myMonth[w][d]-100;
			calendarCellText[((7*w)+d)-7].color = '#ffffff';
			calendarCellText[((7*w)+d)-7].parentElement.style.backgroundColor = "#88946B";
			calendarCellText[((7*w)+d)-7].parentElement.style.borderTop = "white 1px solid";
			calendarCellText[((7*w)+d)-7].parentElement.style.borderLeft = "white 1px solid";
			calendarCellText[((7*w)+d)-7].parentElement.style.borderBottom = "darkgray 1px solid";
			calendarCellText[((7*w)+d)-7].parentElement.style.borderRight = "darkgray 1px solid";
		} else {
			calendarCellText[((7*w)+d)-7].innerText = myMonth[w][d];
			if(iDay == myMonth[w][d]) {
				daySet = true;
				document.all("calendarSelectDate").value = iDay;
				calendarCellText[((7*w)+d)-7].color = 'yellow';
				calendarCellText[((7*w)+d)-7].parentElement.style.backgroundColor = "#2b7e2a";
				calendarCellText[((7*w)+d)-7].parentElement.style.borderTop = "black 1px solid";
				calendarCellText[((7*w)+d)-7].parentElement.style.borderLeft = "black 1px solid";
				calendarCellText[((7*w)+d)-7].parentElement.style.borderBottom = "lightgrey 1px solid";
				calendarCellText[((7*w)+d)-7].parentElement.style.borderRight = "lightgrey 1px solid";
				objPrevElement = calendarCellText[((7*w)+d)-7].parentElement;
			} else {
				calendarCellText[((7*w)+d)-7].color = '#000000';
				calendarCellText[((7*w)+d)-7].parentElement.style.backgroundColor = "#c6dabe";
				calendarCellText[((7*w)+d)-7].parentElement.style.borderTop = "white 1px solid";
				calendarCellText[((7*w)+d)-7].parentElement.style.borderLeft = "white 1px solid";
				calendarCellText[((7*w)+d)-7].parentElement.style.borderBottom = "darkgray 1px solid";
				calendarCellText[((7*w)+d)-7].parentElement.style.borderRight = "darkgray 1px solid";
			}
		}
	} else {
		calendarCellText[((7*w)+d)-7].innerText = " ";
		calendarCellText[((7*w)+d)-7].color = '#ffffff';
		calendarCellText[((7*w)+d)-7].parentElement.style.backgroundColor = "#88946B";
		calendarCellText[((7*w)+d)-7].parentElement.style.borderTop = "white 1px solid";
		calendarCellText[((7*w)+d)-7].parentElement.style.borderLeft = "white 1px solid";
		calendarCellText[((7*w)+d)-7].parentElement.style.borderBottom = "darkgray 1px solid";
		calendarCellText[((7*w)+d)-7].parentElement.style.borderRight = "darkgray 1px solid";
	         }
	      }
	   }
	 
	 if(!daySet) objPrevElement = null;
	   
	  if(!iDay){
		try {
		if(objPrevElement.children['calendarCellText'].color =='#ffffff') {
				objPrevElement.style.backgroundColor = "#88946B";
				objPrevElement.style.borderTop = "white 1px solid";
				objPrevElement.style.borderLeft = "white 1px solid";
				objPrevElement.style.borderBottom = "darkgray 1px solid";
				objPrevElement.style.borderRight = "darkgray 1px solid";
				document.all("calendarSelectDate").value = "";
			} else {
				objPrevElement.children['calendarCellText'].color = 'yellow';
				objPrevElement.style.backgroundColor = "#2b7e2a";
				objPrevElement.style.borderTop = "black 1px solid";
				objPrevElement.style.borderLeft = "black 1px solid";
				objPrevElement.style.borderBottom = "lightgrey 1px solid";
				objPrevElement.style.borderRight = "lightgrey 1px solid";
				//document.all.calendarSelectDate.value = "";
			}
			} catch(dontcare) {}
		}
		try {
			calendarDate_changed();
		} catch(Nothing_Here) {}
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to return the name of the current day selected on the calendar
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function getDayOfWeekName() {
	var iDayOfFirst = new Date(getSelectedYear(), getSelectedMonth()-1, getSelectedDate()).getDay();
	switch(iDayOfFirst)
	{
		case 1:
			return 'Monday';
			break;
		case 2:
			return 'Tuesday';
			break;
		case 3:
			return 'Wednesday';
			break;
		case 4:
			return 'Thursday';
			break;
		case 5:
			return 'Friday';
			break;
		case 6:
			return 'Saturday';
			break;
		case 0:
			return 'Sunday';
			break;
	}		
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to retiurn the current selected day number of the week, starts at 0
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function getDayOfWeek() {
	var iDayOfFirst = new Date(getSelectedYear(), getSelectedMonth()-1, getSelectedDate()).getDay();

	if(StartDayOfWeek=="Monday"){
		if(iDayOfFirst>0){
			iDayOfFirst--;
		} else {
			iDayOfFirst = 6;
		}
	}
	return iDayOfFirst;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to draw the calendar form and control to the HTML page.  used to make the display of the calendar control as easy as possible
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function createCalendarControl() {
	var dCurDate = new Date();
//	document.write('<form name="frmCalendar" method="post" action="">');
	document.write('<input type="hidden" id="calendarSelectDate" name="calendarSelectDate" value="">');
	document.write('<table border="0"  cellspacing="0" cellpadding="1" background="black">');
	document.write('<tr>');

	document.write('<td align="Center"  class="tback">');
	document.write('<select class="combo" id="calendarSelectMonth" name="calendarSelectMonth" onchange="refreshCalendar(document.all(\'calendarSelectYear\').value, document.all(\'calendarSelectMonth\').value, document.all(\'calendarSelectDate\').value)">');
	document.write('<option value="1">January</option>');
	document.write('<option value="2">February</option>');
	document.write('<option value="3">March</option>');
	document.write('<option value="4">April</option>');
	document.write('<option value="5">May</option>');
	document.write('<option value="6">June</option>');
	document.write('<option value="7">July</option>');
	document.write('<option value="8">August</option>');
	document.write('<option value="9">September</option>');
	document.write('<option value="10">October</option>');
	document.write('<option value="11">November</option>');
	document.write('<option value="12">December</option>');
	document.write('</select>');
	createYears();
	document.write('</td>');
	document.write('</tr>');
	document.write('<tr>');
	document.write('<td>');
	createHTMLCalendar(dCurDate.getFullYear(), dCurDate.getMonth()+1, 20, 18, "12px", "bold", 0);
	document.write('</td>');
	document.write('</tr>');
	document.write('</table>');
//	document.write('</form>');
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function used to set the current year of the calendar
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function setYear(iYear) {
	for (i = 0; i < document.all("calendarSelectYear").length; i++) {
		if (document.all("calendarSelectYear").options[i].value == iYear)
			document.all("calendarSelectYear").options[i].selected = true;
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function used to set the current month of the calendar
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function setMonth(iMonth) {
		if (document.all("calendarSelectMonth").options.length >= (iMonth-1)) {
			document.all("calendarSelectMonth").options[iMonth-1].selected = true;
		}
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function used to set the current day of the calendar
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function setDay(iDay) {
	refreshCalendar(document.all("calendarSelectYear").value, document.all("calendarSelectMonth").value, iDay);
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to set the current date to be displayed on the calendar
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function setDate(iYear, iMonth, iDate) {
	setYear(iYear);
	setMonth(iMonth);
	setDay(iDate);
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to create the selection box with the required dates in it
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function createYears() { //Writes the years in a combo box on the form
//refreshCalendar(document.all(\'calendarSelectYear\').value, document.all(\'calendarSelectMonth\').value, document.all(\'calendarSelectDate\').value)
	document.write('<select class="combo" id="calendarSelectYear" name="calendarSelectYear" onchange="refreshCalendar(document.all(\'calendarSelectYear\').value, document.all(\'calendarSelectMonth\').value, document.all(\'calendarSelectDate\').value)">');
	for(var i=2007; i<=2015; i++) document.write("<option value='" + i + "'>" + i + "</option>");
	document.write("</select>");
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to return the current selected year from the calendar control
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function getSelectedYear() {
	var tmpDate = new Date(document.getElementById("calendarSelectYear").options[document.getElementById("calendarSelectYear").selectedIndex].value, document.getElementById("calendarSelectMonth").options.selectedIndex, document.getElementById("calendarSelectDate").value);
	return tmpDate.getFullYear();
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to return the current selected month from the calendar control
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function getSelectedMonth() {
	var tmpDate = new Date(document.getElementById("calendarSelectYear").options[document.getElementById("calendarSelectYear").selectedIndex].value, document.getElementById("calendarSelectMonth").options.selectedIndex, document.getElementById("calendarSelectDate").value)
	return tmpDate.getMonth()+1;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to return the current selected month name from the calendar control
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function getMonthName() {
    if(document.all)
    {
	    return document.getElementById("calendarSelectMonth").options[getSelectedMonth()-1].innerText;
	}
	else
	{
	    return document.getElementById("calendarSelectMonth").options[getSelectedMonth()].text;
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to return the current selected day of the month from the calendar control
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function getSelectedDate() {
    var tmpDate;
    if(document.all)
    {
	    tmpDate = new Date(document.getElementById("calendarSelectYear").options[document.getElementById("calendarSelectYear").selectedIndex].value, document.getElementById("calendarSelectMonth").options.selectedIndex, document.getElementById("calendarSelectDate").value)
	}
	else
	{
	    tmpDate = new Date(document.getElementById("calendarSelectYear").options[document.getElementById("calendarSelectYear").selectedIndex].value, document.getElementById("calendarSelectMonth").options.selectedIndex + 1, document.getElementById("CalenderDay").options[document.getElementById("CalenderDay").options.selectedIndex].value)
	}
	return tmpDate.getDate();
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to return the current date on the calendar
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function getSelection() {
	var tmpDate = new Date(getSelectedYear(), getSelectedMonth()-1, getSelectedDate());
	return tmpDate;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to return the date of the day at the start of the week for the current date
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function getWeekBeginDate(){
	var d = getSelection(); //Get the current selected date
	var e = new Date(); //Start Of Week Date - Store

	if(StartDayOfWeek=="Monday") {
		if(d.getDay()==0){
			e = new Date(d.getYear(), d.getMonth(), d.getDate()-6);
		} else {
			e = new Date(d.getYear(), d.getMonth(), d.getDate()-d.getDay()+1);
		}
	} else {
		e = new Date(d.getYear(), d.getMonth(), d.getDate()-d.getDay());
	}
	return (1 + e.getMonth()) + "/" + e.getDate() + "/" + (e.getFullYear());
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Function to return the date of the day at the end of the week for the current date
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function getWeekEndDate(){
	var d = getSelection(); //Get the current selected date
	var e = new Date(); //Start Of Week Date - Store
	
	if(StartDayOfWeek=="Monday") {
		if(d.getDay()==0){
			e = new Date(d.getYear(), d.getMonth(), d.getDate());
		} else {
			e = new Date(d.getYear(), d.getMonth(), d.getDate()-d.getDay()+7);
		}
	} else {
		e = new Date(d.getYear(), d.getMonth(), d.getDate()+(6-d.getDay()));
	}
	return (1 + e.getMonth()) + "/" + e.getDate() + "/" + (e.getYear());
}