// WWW: http://www.mattkruse.com/

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=o.offsetLeft; y=o.offsetTop;
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;	
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
		    x=coordinates.x-document.documentElement.scrollLeft+window.screenLeft;
			y=coordinates.y-document.documentElement.scrollTop+window.screenTop;
			//x=coordinates.x-document.documentElement.scrollTop+window.screenLeft;
			//y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.documentElement.scrollLeft+window.screenLeft;
		y=coordinates.y-document.documentElement.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-5-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.documentElement.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.documentElement.scrollTop;
	}
	
// --------------------------------------------------------------------------------

// WWW: http://www.softricks.com/
 
var weekend = [0,6];
var gNow = new Date();
var ggWinCal;
// Default Date Format
var gDefaultDateFormat = 'MM/DD/YYYY';
var pageType ;

isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

// Code added for capturing the Cursor position
var popX=0;popY=0;
function setCursorPosition(AnchorName,popWidth,popHeight) {
	var coord = getAnchorWindowPosition(AnchorName);
	
	// Variables that define browser specific offsets
	var xOffset = 0, yOffset = 0, xxOffset = 0, yyOffset = 0;
	
	if(isNav)	 {	
		xOffset = 90;
		yOffset =  26;
		xxOffset = 4;
		yyOffset = 3;
	}
	else if(isIE) {
		xOffset = 81;
		yOffset =  24;
		xxOffset = 9;
		yyOffset = 4;
	}
	
	// Apply the offsets
	popX = coord.x - xOffset;
	popY = coord.y + yOffset;
	
	winX = (640 - popWidth)/2;
	inY = (480 - popHeight)/2;
	if (screen) {
        winX = screen.availWidth;
			winY = screen.availHeight;	
			
			// Replace the coordinates when the control is at the extreme right or bottom
			if(popX+popWidth >= winX) {
					popX = popX - popWidth + (xOffset + xxOffset);
				}
			if(popY+popHeight >= winY) {
					popY =  popY - popHeight - (yOffset*2 + yyOffset);
				}
    }
}

// --------------------------------------------------------------------------------


Calendar.Months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];


// Code modified to capture the date value ( p_day has been included)
function Calendar(p_item, p_WinCal, p_day, p_month, p_year, p_format) {
	if ((p_month == null) && (p_year == null))	return;

	if (p_WinCal == null)
		this.gWinCal = ggWinCal;
	else
		this.gWinCal = p_WinCal;
	
	if (p_month == null) {
		this.gMonthName = null;
		this.gMonth = null;
		this.gYearly = true;
	} else {
		this.gMonthName = Calendar.get_month(p_month);
		this.gMonth = new Number(p_month);
		this.gYearly = false;
	}

	// Code added to capture the date value
	this.gDay = p_day;
	this.gYear = p_year;
	this.gFormat = p_format;
	
	// Customize your Calendar here.....
	this.gTextColor = "#000000";
	this.gMainTableBgColor = "#adc8ff";
	this.gHeaderBgColor = "#426ec2"; // The Year Display
	this.gHeaderFontColor = "#FFFFFF";
	this.gHeaderFontFace = "Verdana, Arial, Helvetica, sans-serif";
	this.gHeaderFontSize = "2";
	this.gLinkColor="#000000";
	
	// Display of Weekdays ( S M T W T F S )
	this.gDayFontFace = "Verdana, Arial, Helvetica, sans-serif";
	this.gDayFontSize = "2";
	
	// Display of Dates ( 1 - 31 )
	this.gDateFontFace = "Verdana, Arial, Helvetica, sans-serif";
 	this.gDateFontSize = "1";
	this.gDateBgColor = "#FFFFFF";
	this.gWeekendBgColor = "#efeef4";
	// Deep Test	
	var selectedControl = arguments[0];
	selectedControl = selectedControl.replace('aspnetForm.','')
	var selectedDate = document.getElementById(selectedControl).value;
	if (selectedDate != ""){
	    var selecteddateArray = selectedDate.split( (selectedDate.indexOf("/") != -1) ? "/" : "-");
	    var	selectedday = new Number(selecteddateArray[1]);
	    var	selectedmonth = new Number(selecteddateArray[0])-1;
	    var selectedyear = new Number(selecteddateArray[2]);
	    if(Number(selectedday) == p_day && Number(selectedmonth) == p_month && Number(selectedyear) == p_year)
	        this.gSelectedDateFontColor = "#FF0000";
	    else
	        this.gSelectedDateFontColor = "#000000";
	}
	else{
	    var currentDate = new Date();
	    currentDate.getDate();
	    var currentMonth = currentDate.getMonth();
	    var currentYear = currentDate.getFullYear();
	    if(Number(currentMonth) == p_month && Number(currentYear) == p_year)
	        this.gSelectedDateFontColor = "#FF0000";
	    else
	        this.gSelectedDateFontColor = "#000000";
	} 	    
	// End Deep Test
	
	// Images used in the Calendar
	this.gImgYearDcr = "../Images/cal-images/year_dcr.gif";
	this.gImgYearInc = "../Images/cal-images/year_inc.gif";
	this.gImgMonDcr = "../Images/cal-images/month_dcr.gif";
	this.gImgMonInc = "../Images/cal-images/month_inc.gif";
	
	
	this.gReturnItem = p_item;
	
	
}

Calendar.get_month = Calendar_get_month;
Calendar.get_daysofmonth = Calendar_get_daysofmonth;
Calendar.calc_month_year = Calendar_calc_month_year;
Calendar.print = Calendar_print;

function Calendar_get_month(monthNo) {
	return Calendar.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 Calendar.DOMonth[monthNo];
	
		return Calendar.lDOMonth[monthNo];
	} else
		return Calendar.DOMonth[monthNo];
}



function Calendar_print() {
	ggWinCal.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,10) - 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month,10) - 1;
			ret_arr[1] = parseInt(p_Year,10);
		}
	} 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,10) + 1;
		}
		else {
			ret_arr[0] = parseInt(p_Month,10) + 1;
			ret_arr[1] = parseInt(p_Year,10);
		}
	}
	
	return ret_arr;
}

// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();

Calendar.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;
	
	return vCode;
}

Calendar.prototype.show = function() {
	var vCode = "";
	
	this.gWinCal.document.open();

	// Setup the page...
	this.wwrite("<HTML>");
	this.wwrite("<HEAD><TITLE>Calendar</TITLE>");
	this.wwrite("</HEAD>");
	this.wwrite("<script language=\"javascript\" >window.focus();</script>");

	this.wwrite("<BODY LEFTMARGIN='0' TOPMARGIN='0' MARGINWIDTH='0' MARGINHEIGHT='0'" + 
		"LINK=\"" + this.gLinkColor + "\" " + 
		"VLINK=\"" + this.gLinkColor + "\" " +
		"ALINK=\"" + this.gLinkColor + "\" " +
		"TEXT=\"" + this.gTextColor + "\">");

	// Show navigation buttons
	var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
	var prevMM = prevMMYYYY[0];
	var prevYYYY = prevMMYYYY[1];

	var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
	var nextMM = nextMMYYYY[0];
	var nextYYYY = nextMMYYYY[1];
	
	this.wwrite("<TABLE WIDTH='100%' BORDER='0' CELLSPACING='1' CELLPADDING='0' BGCOLOR='"+ this.gMainTableBgColor +"'><TR><TD>");
	
	// Code modofied to capture the date value (gDay being included)
	this.wwrite("<TABLE WIDTH='100%' BORDER=0 CELLSPACING=1 CELLPADDING=1 ALIGN='CENTER'><TR><TD WIDTH='10%' ALIGN='CENTER' BGCOLOR='"+ this.gHeaderBgColor +"'>");
	this.wwrite("<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gDay + "','" + this.gMonth + "', '" + (parseInt(this.gYear,10)-1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><IMG SRC='"+ this.gImgYearDcr +"' WIDTH='5' HEIGHT='8' BORDER='0'><\/A></TD><TD WIDTH='10%' ALIGN='CENTER' BGCOLOR='"+ this.gHeaderBgColor +"'>");
	this.wwrite("<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gDay + "','" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><IMG SRC='"+ this.gImgMonDcr +"' WIDTH='4' HEIGHT='8' BORDER='0'><\/A></TD><TD  WIDTH='60%' ALIGN='CENTER' BGCOLOR='"+ this.gHeaderBgColor +"'><FONT FACE='"+ this.gHeaderFontFace +"' SIZE='"+ this.gHeaderFontSize +"' COLOR='"+ this.gHeaderFontColor +"'>");
	this.wwriteA(this.gMonthName + " " + this.gYear);
	this.wwrite("</FONT></TD><TD WIDTH='10%' ALIGN=center BGCOLOR='"+ this.gHeaderBgColor +"'>");
	this.wwrite("<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gDay + "','" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\"><IMG SRC='"+ this.gImgMonInc +"' WIDTH='4' HEIGHT='8' BORDER='0'><\/A></TD><TD WIDTH='10%' ALIGN='CENTER' BGCOLOR='"+ this.gHeaderBgColor +"'>");
	this.wwrite("<A HREF=\"" +
		"javascript:window.opener.Build(" + 
		"'" + this.gReturnItem + "', '" + this.gDay + "','" + this.gMonth + "', '" + (parseInt(this.gYear,10)+1) + "', '" + this.gFormat + "'" +
		");" +
		"\"><IMG SRC='"+ this.gImgYearInc +"' WIDTH='5' HEIGHT='8' BORDER='0'><\/A></TD></TR></TABLE>");

	// Get the complete calendar code for the month..
	vCode = this.getMonthlyCalendarCode();
	this.wwrite(vCode);

	this.wwrite("</TABLE></BODY></HTML>");
	this.gWinCal.document.close();
}

Calendar.prototype.wwrite = function(wtext) {
	this.gWinCal.document.writeln(wtext);
}

Calendar.prototype.wwriteA = function(wtext) {
	this.gWinCal.document.write(wtext);
}

Calendar.prototype.cal_header = function() {
	var vCode = "";
	
	vCode = vCode + "<TABLE ALIGN='CENTER' WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='2'>";
	vCode = vCode + "<TR ALIGN='CENTER'>";
	vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%'><FONT FACE='"+ this.gDayFontFace +"' SIZE='"+ this.gDayFontSize +"'>S</FONT></TD>";
	vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%'><FONT FACE='"+ this.gDayFontFace +"' SIZE='"+ this.gDayFontSize +"'>M</FONT></TD>";
	vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%'><FONT FACE='"+ this.gDayFontFace +"' SIZE='"+ this.gDayFontSize +"'>T</FONT></TD>";
	vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%'><FONT FACE='"+ this.gDayFontFace +"' SIZE='"+ this.gDayFontSize +"'>W</FONT></TD>";
	vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%'><FONT FACE='"+ this.gDayFontFace +"' SIZE='"+ this.gDayFontSize +"'>T</FONT></TD>";
	vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%'><FONT FACE='"+ this.gDayFontFace +"' SIZE='"+ this.gDayFontSize +"'>F</FONT></TD>";
	vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%'><FONT FACE='"+ this.gDayFontFace +"' SIZE='"+ this.gDayFontSize +"'>S</FONT></TD>";
	vCode = vCode + "</TR>";
	vCode = vCode + "</TABLE>";
	
	return vCode;
}

Calendar.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=Calendar.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. 
	*/
	vCode = vCode + "<TABLE WIDTH='100%' BORDER='1' CELLSPACING='1' CELLPADDING='0'>";
	vCode = vCode + "<TR>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%' HEIGHT='21'" + this.write_weekend_string(i) + "><FONT FACE='"+ this.gDateFontFace +"' SIZE='"+ this.gDateFontSize +"'><B>&nbsp;</B></FONT></TD>";
	}


	// Write rest of the 1st week 
	// changeFlag has been included to trigger the onChange event in the concerned screens
	if(pageType == undefined)
	{
	    for (j=vFirstDay; j<7; j++) {
		    vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%' HEIGHT='21'" + this.write_weekend_string(j) + "><FONT FACE='"+ this.gDateFontFace +"' SIZE='"+ this.gDateFontSize +"'><B>" + 
			    "<A HREF='#' " + 
				    "onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
				    this.format_data(vDay) + 
				    "'; if(self.opener.changeFlag) self.opener.changeFlag='true';window.close();\">" +
				    this.format_day(vDay) + 
			    "</A>" + 
			    "</B></FONT></TD>";
		    vDay=vDay + 1;
	    }
	}
	else
	{
	    for (j=vFirstDay; j<7; j++) {
		    vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%' HEIGHT='21'" + this.write_weekend_string(j) + "><FONT FACE='"+ this.gDateFontFace +"' SIZE='"+ this.gDateFontSize +"'><B>" + 
			    "<A HREF='#' " + 
				    "onClick=\"self.opener.document.getElementById('" + this.gReturnItem + "').value='" + 
				    this.format_data(vDay) + 
				    "'; if(self.opener.changeFlag) self.opener.changeFlag='true';window.close();\">" +
				    this.format_day(vDay) + 
			    "</A>" + 
			    "</B></FONT></TD>";
		    vDay=vDay + 1;
	    }
	}
	vCode = vCode + "</TR>";

	// Write the rest of the weeks
	// changeFlag has been included to trigger the onChange event in the concerned screens
	for (k=2; k<7; k++) {
		vCode = vCode + "<TR>";

        if(pageType == undefined)
	    {
		    for (j=0; j<7; j++) {
			    vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%' HEIGHT='21'" + this.write_weekend_string(j) + "><FONT FACE='"+ this.gDateFontFace +"' SIZE='"+ this.gDateFontSize +"'><B>" + 
				    "<A HREF='#' " + 
					    "onClick=\"self.opener.document." + this.gReturnItem + ".value='" + 
					    this.format_data(vDay) + 
					    "'; if(self.opener.changeFlag) self.opener.changeFlag='true';window.close();\">" +
				    this.format_day(vDay) + 
				    "</A>" + 
				    "</B></FONT></TD>";
			    vDay=vDay + 1;

			    if (vDay > vLastDay) {
				    vOnLastDay = 1;
				    break;
			    }
		    }
		}
		else
		{
		    for (j=0; j<7; j++) {
			    vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%' HEIGHT='21'" + this.write_weekend_string(j) + "><FONT FACE='"+ this.gDateFontFace +"' SIZE='"+ this.gDateFontSize +"'><B>" + 
				    "<A HREF='#' " + 
					    "onClick=\"self.opener.document.getElementById('" + this.gReturnItem + "').value='" + 
					    this.format_data(vDay) + 
					    "'; if(self.opener.changeFlag) self.opener.changeFlag='true';window.close();\">" +
				    this.format_day(vDay) + 
				    "</A>" + 
				    "</B></FONT></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)
			vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%' HEIGHT='21'" + this.write_weekend_string(j+m) + 
			"><FONT FACE='"+ this.gDateFontFace +"' SIZE='"+ this.gDateFontSize +"'><B>&nbsp;</B></FONT></TD>";
		else
			vCode = vCode + "<TD ALIGN='CENTER' WIDTH='14%' HEIGHT='21'" + this.write_weekend_string(j+m) + 
			"><FONT FACE='"+ this.gDateFontFace +"' SIZE='"+ this.gDateFontSize +"'><B>&nbsp;</B></FONT></TD>";
	}
	vCode = vCode + "</TABLE>";
	return vCode;
}

Calendar.prototype.format_day = function(vday) {
	// Code modified to capture the date value (the date in the text field is shown highlighted)
	if (vday == this.gDay)
		return ("<FONT COLOR='"+ this.gSelectedDateFontColor +"'>" + vday + "</FONT>");
	else
		return (vday);
}

Calendar.prototype.write_weekend_string = function(vday) {
	var i;

	// Return special formatting for the weekend day.
	for (i=0; i<weekend.length; i++) {
		if (vday == weekend[i])
			return (" BGCOLOR=\"" + this.gWeekendBgColor + "\"");
	}
	
	return (" BGCOLOR=\"" + this.gDateBgColor + "\"");
}

Calendar.prototype.format_data = function(p_day) {
	var vData;
	var vMonth = 1 + this.gMonth;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
	var vFMon = Calendar.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;

		default :
			vData = vMonth + "\/" + vDD + "\/" + vY4;
	}

	return vData;
}

// Code modified to capture the date value (p_day has been included)
function Build(p_item,  p_day,  p_month, p_year, p_format) {
	var p_WinCal = ggWinCal;

	// Code modified to capture the date value (p_day has been included)
	gCal = new Calendar(p_item, p_WinCal, p_day,  p_month, p_year, p_format);

	// Show function
	gCal.show();
}

function show_calendar() {
	/* 
		p_month : 0-11 for Jan-Dec; 12 for All Months.
		p_year	: 4-digit year
		p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
		p_item	: Return Item.
	*/
	p_item = arguments[1];
	pageType = arguments[7];

	// Code added to capture the date value
	if (arguments[2] == "") 	{
		p_day = gNow.getDate();
		p_month = new String(gNow.getMonth());
		p_year = new String(gNow.getFullYear().toString());
	}
	else {
		var dateValue = arguments[2];
		var dateArray = dateValue.split( (dateValue.indexOf("/") != -1) ? "/" : "-");
		p_day = new Number(dateArray[1]);
		p_month = new Number(dateArray[0])-1;
		p_year = new String(dateArray[2]);
		
		if( isNaN(p_day) || p_day < 1 || p_day > 31 || isNaN(p_month) || p_month == -1 || p_month<0 || p_month > 11 || p_year.length != 4 || isNaN(p_year) ) {
			p_day = gNow.getDate();
			p_month = new String(gNow.getMonth());
			p_year = new String(gNow.getFullYear().toString());
		}
		
	}
	

	 
	// ----------------------------------------------------------------------------
	
	if (arguments[3] == null || arguments[3] == "")
		p_format = gDefaultDateFormat;
	else
		p_format = arguments[3];
		

	// Code added to capture the cursor position
	setCursorPosition(arguments[0],arguments[5],arguments[6])
	// Code modified
	vWinCal = window.open("", "Calendar", 
		"width="+arguments[5]+",height="+arguments[6]+",status=no,resizable=no,top="+popY+",left="+popX);

	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, p_day,  p_month, p_year, p_format);
}
	// ------ E N D ----------------------------------------------------------------------
	

