
function fToggleColor(myElement)
{
	var toggleColor = "#c0c0c0";
	//alert(myElement.bgColor)
	if(myElement.bgColor == "#c0c0c0")
	{
		myElement.bgColor = "#ffffff";
	}
	else
	{
		myElement.bgColor = "#c0c0c0";
	}
	
}

function fSetSelectedDay(myElement)
{
	if (myElement.id == "calCell")
	{
    	if (!isNaN(parseInt(myElement.children["calDateText"].innerText)))
		{
        	myElement.bgColor = "#c0c0c0";
			objPrevElement.bgColor = "";
			document.all.calSelectedDate.value = parseInt(myElement.children["calDateText"].innerText);
			objPrevElement = myElement;
			if(document.all.calSelectedDate.value<10)
			{
				document.location.href = goToPage + frmCalendarSample.tbSelYear.value + frmCalendarSample.tbSelMonth.value + "0" + document.all.calSelectedDate.value;
 			}
 			else
 			{
 				document.location.href = goToPage + frmCalendarSample.tbSelYear.value + frmCalendarSample.tbSelMonth.value + document.all.calSelectedDate.value;
			}
		}
    }
}

function fGetDaysInMonth(iMonth, iYear)
{
	var dPrevDate = new Date(iYear, iMonth, 0);
	return dPrevDate.getDate();
}

function fBuildCal(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();
	var iDaysInMonth = fGetDaysInMonth(iMonth, iYear);
	var iVarDate = 1;
	var i, d, w;
	
	aMonth[0][0] = "S";
	aMonth[0][1] = "M";
	aMonth[0][2] = "T";
	aMonth[0][3] = "W";
	aMonth[0][4] = "T";
	aMonth[0][5] = "F";
	aMonth[0][6] = "S";
	
	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++;
     		}
   		}
	}
	return aMonth;
}

function fDrawCal(iYear, iMonth, iCellWidth, iCellHeight, sDateTextSize, sDateTextWeight, iDayStyle) {
var myMonth;
myMonth = fBuildCal(iYear, iMonth, iDayStyle);
document.write("<table cellpadding='0' cellspacing='0' border='1' bordercolor='#D0CECE'")
document.write("<tr><td colspan='7' bgcolor='#3D4F72'>");
document.write("<table width='100%' cellpadding='0' cellspacing='6' border='0' bordercolor='#D0CECE'")
document.write("<tr><td bgcolor='#3D4F72'>");
document.write("<span class='white-11px'>&nbsp;</span>");
document.write("</td><td align='left' bgcolor='#3D4F72'>");
document.write("<select name='tbSelMonth' onchange='fUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value)'>");
document.write("<option value='01'>January</option>");
document.write("<option value='02'>February</option>");
document.write("<option value='03'>March</option>");
document.write("<option value='04'>April</option>");
document.write("<option value='05'>May</option>");
document.write("<option value='06'>June</option>");
document.write("<option value='07'>July</option>");
document.write("<option value='08'>August</option>");
document.write("<option value='09'>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>&nbsp;");
document.write("<select name='tbSelYear' onchange='fUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value)'>");
document.write("<option value='2004'>2004</option>");
document.write("<option value='2005'>2005</option>");
document.write("<option value='2006'>2006</option>");
document.write("<option value='2007'>2007</option>");
document.write("</select></td></tr></td></tr></table></td>");
document.write("<tr><td align='center' style='FONT-WEIGHT:BOLD;COLOR:#3D4F72;FONT-FAMILY:Arial;FONT-SIZE:11px;'>" + myMonth[0][0] + "</td>");
document.write("<td align='center' style='FONT-WEIGHT:BOLD;COLOR:#3D4F72;FONT-FAMILY:Arial;FONT-SIZE:11px;'>" + myMonth[0][1] + "</td>");
document.write("<td align='center' style='FONT-WEIGHT:BOLD;COLOR:#3D4F72;FONT-FAMILY:Arial;FONT-SIZE:11px;'>" + myMonth[0][2] + "</td>");
document.write("<td align='center' style='FONT-WEIGHT:BOLD;COLOR:#3D4F72;FONT-FAMILY:Arial;FONT-SIZE:11px;'>" + myMonth[0][3] + "</td>");
document.write("<td align='center' style='FONT-WEIGHT:BOLD;COLOR:#3D4F72;FONT-FAMILY:Arial;FONT-SIZE:11px;'>" + myMonth[0][4] + "</td>");
document.write("<td align='center' style='FONT-WEIGHT:BOLD;COLOR:#3D4F72;FONT-FAMILY:Arial;FONT-SIZE:11px;'>" + myMonth[0][5] + "</td>");
document.write("<td align='center' style='FONT-WEIGHT:BOLD;COLOR:#3D4F72;FONT-FAMILY:Arial;FONT-SIZE:11px;'>" + myMonth[0][6] + "</td>");
document.write("</tr>");
for (w = 1; w < 7; w++) {
document.write("<tr>")
for (d = 0; d < 7; d++) {
if(myMonth[w][d]== dCurDayOfMonth)
{
document.write("<td align='center' bgcolor='#c0c0c0' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "' id=calCell style='CURSOR:Hand'>");
}
else{
document.write("<td align='center' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "' id=calCell style='CURSOR:Hand' onMouseOver='fToggleColor(this)' onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)>");
}
if (!isNaN(myMonth[w][d])) {
document.write("<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;COLOR:#3D4F72;FONT-FAMILY:Arial;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "' onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)>" + myMonth[w][d] + "</font>");
} else {
document.write("<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;COLOR:#3D4F72;FONT-FAMILY:Arial;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "' onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)>&nbsp;&nbsp;</font>");
}
document.write("</td>")
}
document.write("</tr>");
}
document.write("</table>")
}
function fUpdateCal(iYear, iMonth) {
myMonth = fBuildCal(iYear, iMonth);
objPrevElement.bgColor = "";
document.all.calSelectedDate.value = "";
for (w = 1; w < 7; w++) {
for (d = 0; d < 7; d++) {
if (!isNaN(myMonth[w][d])) {
calDateText[((7*w)+d)-7].innerText = myMonth[w][d];
} else {
calDateText[((7*w)+d)-7].innerText = " ";
         }
      }
   }
}
// End -->


