function AjaxCal(date123)
{
  document.frmsearch.CalDate.value=date123;
  document.frmsearch.submit();
}

// JavaScript Document
var weekendv = [0,6];
var weekendColorv = "#e0e0e0";
var fontfacev = "arial";
var fontsize = 2;
var nextMM="";
var nextYYYY="";
var gNowv = new Date();
var ggWinCalv;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

Calendarv.Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];

// Non-Leap year Month days..
Calendarv.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendarv.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function Calendarv(p_WinCal, p_month, p_year, p_format) {
	if ((p_month == null) && (p_year == null))	return;

	if (p_WinCal == null)
		this.gWinCal = ggWinCalv;
	else
		this.gWinCal = p_WinCal;
	
	if (p_month == null) {
		this.gMonthName = null;
		this.gMonth = null;
		this.gYearly = true;
	} else {
		this.gMonthName = Calendarv.get_month(p_month);
		this.gMonth = new Number(p_month);
		this.gYearly = false;
	}
	this.g_datev = "";
	this.gYear = p_year;
	this.gFormat = p_format;
	this.DivInnerHtml = "";
}

Calendarv.get_month = Calendar_get_month;
Calendarv.get_daysofmonth = Calendar_get_daysofmonth;
Calendarv.calc_month_year = Calendar_calc_month_year;
Calendarv.print = Calendar_print;

function Calendar_get_month(monthNo) {
	return Calendarv.Months[monthNo];
}

function Calendar_get_daysofmonth(monthNo, p_year) {
	/* 
	Check for leap year ..
	1.Years evenly divisible by four are normally leap years, except for... 
	2.Years also evenly divisible by 100 are not leap years, except for... 
	3.Years also evenly divisible by 400 are leap years. 
	*/
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return Calendarv.DOMonth[monthNo];
	
		return Calendarv.lDOMonth[monthNo];
	} else
		return Calendarv.DOMonth[monthNo];
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();
	
	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
}

function Calendar_print() {
	ggWinCalv.print();
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	/* 
	Will return an 1-D array with 1st element being the calculated month 
	and second being the calculated year 
	after applying the month increment/decrement as specified by 'incr' parameter.
	'incr' will normally have 1/-1 to navigate thru the months.
	*/
	var ret_arr = new Array();
	
	if (incr == -1) {
		// B A C K W A R D
		if (p_Month == 0) {
			ret_arr[0] = 11;
			ret_arr[1] = parseInt(p_Year) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) - 1;
			ret_arr[1] = parseInt(p_Year);
		}
	} else if (incr == 1) {
		// F O R W A R D
		if (p_Month == 11) {
			ret_arr[0] = 0;
			ret_arr[1] = parseInt(p_Year) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month) + 1;
			ret_arr[1] = parseInt(p_Year);
		}
	}
	
	return ret_arr;
}

// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendarv();

Calendarv.prototype.getMonthlyCalendarCode = function() {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";
	
	// Begin Table Drawing code here..
	
	vHeader_Code = this.cal_header();
	vData_Code = this.cal_data();
	vCode = vCode + vHeader_Code + vData_Code;
	
	//vCode = vCode + "</table></td></tr></table>";
	
	return vCode;
}

Calendarv.prototype.show = function() {
	var vCode = "";
	
	this.wwrite('<table width="50%" height="175px" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #666464;">');
	this.wwriteA('<tr bgcolor="#ffffff"> <td>');
      
	// Show navigation buttons
	var prevMMYYYY = Calendarv.calc_month_year(this.gMonth, this.gYear, -1);
	var prevMM = prevMMYYYY[0];
	var prevYYYY = prevMMYYYY[1];

	var nextMMYYYY = Calendarv.calc_month_year(this.gMonth, this.gYear, 1);
	nextMM = nextMMYYYY[0];
	nextYYYY = nextMMYYYY[1];

	this.wwrite('<table width="100%" height="35px" border="0" align="center" cellpadding="1" cellspacing="1"><tr> <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">  <tr><td align="center" valign="middle">');
	
	/* this.wwrite("<A style=\"cursor:pointer;\" onclick=\"" + 
		"javascript:Build(" + 
		"'" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><IMG border='0' SRC='images/arrow-left_new.png' title='Previous Year' align='middle'><\/A></td><td align='center' valign='middle'>"); */
		
		this.wwrite("<table border=0 width=100%><tr><td align=left>");
		
	this.wwrite("<A style=\"cursor:pointer; text-decoration:underline\" onclick=\"" +
		"javascript:Build(" + 
		"'" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><font color=red><</font><\/A></td><td align='center' valign='middle'>");

		//<IMG border='0' SRC='images/left-arrow_n.png' title='Previous Month' align='middle'>
		
this.wwrite("</td><td align=center>");
		
		this.wwriteA("<b><font size='2' face='Tahoma'>" + this.gMonthName + " " + this.gYear + "</font></b>");
		
	
this.wwrite("</td><td align=right>");
	
	this.wwrite("<A style=\"cursor:pointer; text-decoration:underline\"\" onclick=\"" +
		"javascript:Build(" + 
		"'" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><font color=red>></font><\/A></td><td align='center' valign='middle'>");
		
		//<IMG border='0' SRC='images/right-arrow_n.png' title='Next Month' align='middle'>
		
		this.wwrite("</td></tr></table>");
		
	/* this.wwrite("<A style=\"cursor:pointer;\" onclick=\"" +
		"javascript:Build(" + 
		"'" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><IMG border='0' SRC='images/arrow-right_new.png' title='Next Year' align='middle'><\/A></td></tr></table></td></tr></table>"); */
		
	this.wwrite("</td></tr></table></td></tr></table>");
		
	// Get the complete calendar code for the month..
	vCode = this.getMonthlyCalendarCode();
	this.wwrite(vCode);

	this.wwrite("</table></td></tr></table>");
	//this.wwrite("</font></body></html>");
//	alert(this.DivInnerHtml);
	//alert(nextYYYY);
	document.getElementById("CalDivTag").innerHTML=this.DivInnerHtml;
}

Calendarv.prototype.wwrite = function(wtext) {
	this.DivInnerHtml=this.DivInnerHtml+wtext;
}

Calendarv.prototype.wwriteA = function(wtext) {
	this.DivInnerHtml=this.DivInnerHtml+wtext;
}

Calendarv.prototype.cal_header = function() {
	var vCode = "";
	
	vCode = vCode + '<table width="75%" border="1" align="center" cellpadding="8" cellspacing="1" style="border:1px solid #999999; border-collapse:collapse;" height="175px"><tr><td id="WeekHead" style="font-family: Tahoma; font-size:11px; color:#01A6E6; font-weight:bold; text-align:center; height:30px; width:30px">Sun </td><td id="WeekHead" style="font-family: Tahoma; font-size:11px; color:#01A6E6; font-weight:bold; text-align:center; height:30px; width:30px">Mon </td><td id="WeekHead" style="font-family: Tahoma; font-size:11px; color:#01A6E6; font-weight:bold; text-align:center; height:30px; width:30px">Tue</td><td id="WeekHead" style="font-family: Tahoma; font-size:11px; color:#01A6E6; font-weight:bold; text-align:center; height:30px; width:30px">Wed</td><td id="WeekHead" style="font-family: Tahoma; font-size:11px; color:#01A6E6; font-weight:bold; text-align:center; height:30px; width:30px">Thu </td><td id="WeekHead" style="font-family: Tahoma; font-size:11px; color:#01A6E6; font-weight:bold; text-align:center; height:30px; width:30px">Fri </td><td id="WeekHead" style="font-family: Tahoma; font-size:11px; color:#01A6E6; font-weight:bold; text-align:center; height:30px; width:30px">Sat</td></tr>';
	return vCode;
}

Calendarv.prototype.cal_data = function() {
	var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);

	var vFirstDay=vDate.getDay();
	var vDay=1;
	var vLastDay=Calendarv.get_daysofmonth(this.gMonth, this.gYear);
	var vOnLastDay=0;
	var vCode = "";

	/*
	Get day for the 1st of the requested month/year..
	Place as many blank cells before the 1st day of the month as necessary. 
	*/
	
    if(this.gMonth<10)
	   var mnth="0"+nextMM;
	   
	vCode = vCode + "<tr>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<td id='CalDays' style=\"font-family: Tahoma; font-size:11px; color:#666464; text-align:center; height:30px;\"></td>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {
		if(isweekendBg = this.write_weekend_string(j,vDay,mnth))
			vCode = vCode + "<TD onmousemove=\"this.style.backgroundColor='#99CCFF'\" onmouseout=\"this.style.backgroundColor='white'\"  onmouseover=\"this.style.cursor='pointer';\" onClick=\"AjaxCal('"+ this.format_data(vDay) + "')\""+ isweekendBg + " style=\"font-family: Tahoma; font-size:11px; color:#666464; text-align:center; height:30px;\"><A " + 
				"onClick=\"AjaxCal('"+ this.format_data(vDay) + "')\">" + vDay + "</A>" + "</TD>";
		else
			vCode = vCode + "<TD onmousemove=\"this.style.backgroundColor='#99CCFF'\" onmouseout=\"this.style.backgroundColor='white'\"  onmouseover=\"this.style.cursor='pointer';\" onmouseover=\"this.style.cursor='pointer';\" onClick=\"AjaxCal('"+ this.format_data(vDay) + "')\""+ this.format_day(vDay,mnth) + " style=\"font-family: Tahoma; font-size:11px; color:#666464; text-align:center; height:30px;\"><A " + 
				"onClick=\"AjaxCal('"+ this.format_data(vDay) + "')\">" + vDay + "</A>" + "</TD>";
		vDay=vDay + 1;
	}
	vCode = vCode + "</TR>";

	// Write the rest of the weeks
	for (k=2; k<7; k++) {
		vCode = vCode + "<TR>";

		for (j=0; j<7; j++) {
			if(isweekendBg = this.write_weekend_string(j,vDay,mnth))
			vCode = vCode + "<TD onmousemove=\"this.style.backgroundColor='#99CCFF'\" onmouseout=\"this.style.backgroundColor='white'\"  onmouseover=\"this.style.cursor='pointer';\" onmouseover=\"this.style.cursor='pointer';\" onClick=\"AjaxCal('"+ this.format_data(vDay) + "')\"" + isweekendBg + "<A " + "onClick=\"AjaxCal('" + this.format_data(vDay) + "');\" style=\"font-family: Tahoma; font-size:11px; color:#666464; text-align:center; height:30px;\">" + vDay + "</A>" + "</TD>";
			else
			vCode = vCode + "<TD onmousemove=\"this.style.backgroundColor='#99CCFF'\" onmouseout=\"this.style.backgroundColor='white'\"  onmouseover=\"this.style.cursor='pointer';\" onmouseover=\"this.style.cursor='pointer';\" onClick=\"AjaxCal('"+ this.format_data(vDay) + "')\"" + this.format_day(vDay,mnth) + " style=\"font-family: Tahoma; font-size:11px; color:#666464; text-align:center; height:30px;\"><A " + 
					"onClick=\"AjaxCal('" + 
					this.format_data(vDay) + 
					"');\">" + vDay + 
				"</A>" + "</TD>";
			vDay=vDay + 1;

			if (vDay > vLastDay) {
				vOnLastDay = 1;
				break;
			}
		}

		if (j == 6)
			vCode = vCode + "</TR>";
		if (vOnLastDay == 1)
			break;
	}
	
	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
	for (m=1; m<(7-j); m++) {
		if (this.gYearly){
			if(isweekendBg = this.write_weekend_string(j+m,vDay,mnth))
				vCode = vCode + "<TD" + isweekendBg + " style=\"font-family: Tahoma; font-size:11px; color:#666464; text-align:center; height:30px;\"></TD>";
			else
				vCode = vCode + "<TD" + isweekendBg + " style=\"font-family: Tahoma; font-size:11px; color:#666464; text-align:center; height:30px;\"></TD>";
		}
		else{
			if(isweekendBg = this.write_weekend_string(j+m,vDay,mnth))
				vCode = vCode + "<TD" + isweekendBg + " style=\"font-family: Tahoma; font-size:11px; color:#666464; text-align:center; height:30px;\">" + m + "</TD>";
			else
				vCode = vCode + "<TD id='CalDays' style=\"font-family: Tahoma; font-size:11px; color:#666464; text-align:center; height:30px;\">" + m + "</TD>";
		}
	}
	
	return vCode;
}


Calendarv.prototype.format_day = function(vday,mnth) {
	var vNowDay = gNowv.getDate();
	var vNowMonth = gNowv.getMonth();
	var vNowYear = gNowv.getFullYear();
 
 Array.prototype.inArray = function (value)
{
// Returns true if the passed value is found in the
// array. Returns false if it is not.
//alert(value);
var i;
for (i=0; i < this.length; i++) 


{
	if (this[i] == value) 
	{
	return true;
	}
}
return false;
};

	var arry = new Array();
//	alert(document.getElementById('days').value);
	arry=document.getElementById('days').value.split(',');
	
	vday=nextYYYY+mnth+vday;
	//alert(vday);
	
	if(this.g_datev == "")
		if (arry.inArray(vday))    // vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
			return (" id='CalDaysSel' ");
		else
			return (" id='CalDays' ");
	else
		if (arry.inArray(vday))
			return (" id='CalDaysSel' ");
		else
			return (" id='CalDays' ");
}

Calendarv.prototype.write_weekend_string = function(vday,day,mnth) {
	var i;

	// Return special formatting for the weekend day.
	 Array.prototype.inArray = function (value)
{
// Returns true if the passed value is found in the
// array. Returns false if it is not.
//alert(value);
var i;
for (i=0; i < this.length; i++) 
{ 
	if (this[i] == value) 
	{
	return true;
	}
}
return false;
};
var arry = new Array();
//	alert(document.getElementById('days').value);
	//alert(vday);
	day=nextYYYY+mnth+day;
	arry=document.getElementById('days').value.split(',');
	//alert(day);
	for (i=0; i<weekendv.length; i++) {
		if(arry.inArray(day))
		return (" id='CalDaysSel' ");
		else
		if (vday == weekendv[i])
			return (" id='CalDaysWE' ");
	}
	
	return "";
}

Calendarv.prototype.format_data = function(p_day) {
	var vData;
	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	var vMon = Calendarv.get_month(this.gMonth).substr(0,3).toUpperCase();
	var vFMon = Calendarv.get_month(this.gMonth).toUpperCase();
	var vY4 = new String(this.gYear);
	var vY2 = new String(this.gYear.substr(2,2));
	var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

	switch (this.gFormat) {
		case "MM\/DD\/YYYY" :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
			break;
		case "MM\/DD\/YY" :
			vData = vMonth + "\/" + vDD + "\/" + vY2;
			break;
		case "MM-DD-YYYY" :
			vData = vMonth + "-" + vDD + "-" + vY4;
			break;
		case "MM-DD-YY" :
			vData = vMonth + "-" + vDD + "-" + vY2;
			break;

		case "DD\/MON\/YYYY" :
			vData = vDD + "\/" + vMon + "\/" + vY4;
			break;
		case "DD\/MON\/YY" :
			vData = vDD + "\/" + vMon + "\/" + vY2;
			break;
		case "DD-MON-YYYY" :
			vData = vDD + "-" + vMon + "-" + vY4;
			break;
		case "DD-MON-YY" :
			vData = vDD + "-" + vMon + "-" + vY2;
			break;

		case "DD\/MONTH\/YYYY" :
			vData = vDD + "\/" + vFMon + "\/" + vY4;
			break;
		case "DD\/MONTH\/YY" :
			vData = vDD + "\/" + vFMon + "\/" + vY2;
			break;
		case "DD-MONTH-YYYY" :
			vData = vDD + "-" + vFMon + "-" + vY4;
			break;
		case "DD-MONTH-YY" :
			vData = vDD + "-" + vFMon + "-" + vY2;
			break;

		case "DD\/MM\/YYYY" :
			vData = vDD + "\/" + vMonth + "\/" + vY4;
			break;
		case "DD\/MM\/YY" :
			vData = vDD + "\/" + vMonth + "\/" + vY2;
			break;
		case "DD-MM-YYYY" :
			vData = vDD + "-" + vMonth + "-" + vY4;
			break;
		case "DD-MM-YY" :
			vData = vDD + "-" + vMonth + "-" + vY2;
			break;
		case "YYYY-MM-DD" :
			vData = vY4 + "-" + vMonth + "-" + vDD;
			break;
		default :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
	}

	return vData;
}

function Build( p_month, p_year, p_format) {
	var p_WinCal = ggWinCalv;
	gCal = new Calendarv( p_WinCal, p_month, p_year, p_format);

	// Customize your Calendar here..
	gCal.g_datev=ObjDate.p_Dayv;
	gCal.show();
}
ObjDate=Object();
function show_calendar() { 

	if (arguments[2] == null)
		p_month = new String(gNowv.getMonth());
	else
		p_month = arguments[2];
	
	if (arguments[3] == "" || arguments[3] == null)
		p_year = new String(gNowv.getFullYear().toString());
	else
		p_year = arguments[3];
	
	if (arguments[4] == "" || arguments[4] == null)
		ObjDate.p_Dayv = new String(gNowv.getDate().toString());
	else
		ObjDate.p_Dayv = arguments[4];
	
	if (arguments[1] == null)
		p_format = "MM-DD-YYYY";
	else
		p_format = arguments[1];

	ggWinCalv = document.getElementById("CalDivTag");

	Build(p_month, p_year, p_format);
}
// JavaScript Document
