 
CMonths = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];

// Non-Leap year Month days..
CDOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
ClDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
function etravelinsure_calendar() {
        var pNow = new Date();
	p_item = "FORM2.F2SDATE";
	p_month = new String(pNow.getMonth());
	p_year = new String(pNow.getFullYear().toString());
	p_format = "DD-MM-YYYY";
	CBuild(p_item, p_month, p_year, p_format);
}

function CBuild(p_item, p_month, p_year, p_format) {
        var gMonthName = CMonths[p_month];
	var gMonth = new Number(p_month);
	var CDx = "";
	CDx = Cshow(gMonthName, gMonth, p_year, p_format, p_item);
        gloria_out(CDx, "Calendar at Etravelinsure");
}
function Cshow (gMonthName, gMonth, gYear, gFormat, gReturnItem)
{
	var vCode = "";
	var CCx = "<span class='redboy' >";
	CCx += gMonthName + " " + gYear;
	CCx += "</span><BR>";
	var prevMMYYYY = Calendar_calc_month_year(gMonth, gYear, -1);
	var prevMM = prevMMYYYY[0];
	var prevYYYY = prevMMYYYY[1];
	var nextMMYYYY = Calendar_calc_month_year(gMonth, gYear, 1);
	var nextMM = nextMMYYYY[0];
	var nextYYYY = nextMMYYYY[1];
	CCx += ("<TABLE WIDTH='100%' BORDER=0 CELLSPACING=0 CELLPADDING=0 class=tbgoverlib ><TR><TD ALIGN=center>");
	CCx += ("<A HREF=\"javascript:void();\" " +
		"onClick=\"CBuild(" + 
		"'" + gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + gFormat + "'" +
		");" +
		"\"><U>Back<\/u><\/A></TD><TD ALIGN=center>");
	CCx += " </TD><TD ALIGN=center>";
	CCx += ("<A HREF=\"javascript:void();\" " +
		"onMouseOver=\"window.status=' '; return true;\" " +
		"onMouseOut=\"window.status=''; return true;\" " +
		"onClick=\"CBuild(" + 
		"'" + gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + gFormat + "'" +
		");" +
		"\"><U>Forward<\/U><\/A></TD></TR></TABLE><BR>");
        vCode += ("<div align=center><TABLE BORDER=1 class=tbroverlib >");
	
	var vHeader_Code = Ccal_header();
	var vData_Code = Ccal_data(gMonth, gYear, gReturnItem);
	vCode += (vHeader_Code + vData_Code);
	vCode += "</TABLE></div>";

	CCx += vCode;
        return CCx;
}
function Calendar_get_daysofmonth(monthNo, p_year) {

	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return CDOMonth[monthNo];
	
		return ClDOMonth[monthNo];
	} else
		return CDOMonth[monthNo];
}

function Calendar_calc_month_year(p_Month, p_Year, incr) {
	var ret_arr = new Array();
	if (incr == -1) {
		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) {
		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 Ccal_header() {
	var vCode = "";
	vCode = vCode + "<tr>";
	vCode = vCode + "<td class=\"calhd\" ><span class=\"calhc\" >S</span></td>";
	vCode = vCode + "<td class=\"calhd\" ><span class=\"calhc\" >M</span></td>";
	vCode = vCode + "<td class=\"calhd\" ><span class=\"calhc\" >T</span></td>";
	vCode = vCode + "<td class=\"calhd\" ><span class=\"calhc\" >W</span></td>";
	vCode = vCode + "<td class=\"calhd\" ><span class=\"calhc\" >T</span></td>";
	vCode = vCode + "<td class=\"calhd\" ><span class=\"calhc\" >F</span></td>";
	vCode = vCode + "<td class=\"calhd\" ><span class=\"calhc\" >S</span></td>";
	vCode = vCode + "</tr>";
	return vCode;
}

Ccal_data = function(gMonth, gYear, gReturnItem) {
	var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(gMonth);
	vDate.setFullYear(gYear);

	var vFirstDay=vDate.getDay();
	var vDay=1;
	var vLastDay=Calendar_get_daysofmonth(gMonth, gYear);
	var vOnLastDay=0;
	var vCode = "";
	vCode = vCode + "<tr>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<td class=\"caldd\" ><span class=\"caldn\" > </span></TD>";
	}


	for (j=vFirstDay; j<7; j++) {
		vCode = vCode + "<td class=\"caldd\" >" + 
			"<A HREF='javascript:void();' " + 
				"onMouseOver=\"window.status=' " + Cformat_data(vDay, gMonth, gYear) + "'; return true;\" " +
				"onMouseOut=\"window.status=' '; return true;\" " +
				"onClick=\"document." + gReturnItem + ".value='" + 
				 Cformat_data(vDay, gMonth, gYear) + 
				"';\" " + 
				Cformat_day(vDay, gMonth, gYear) + 
			"</span></A>" + 
			"</TD>";
		vDay=vDay + 1;
	}
	vCode = vCode + "</tr>";	
	for (k=2; k<7; k++) {
		vCode = vCode + "<tr>";

		for (j=0; j<7; j++) {
			vCode = vCode + "<td class=\"caldd\" >" + 
				"<A HREF='javascript:void();' " +
					"onMouseOver=\"window.status=' " + Cformat_data(vDay, gMonth, gYear) + "'; return true;\" " +
					"onMouseOut=\"window.status=' '; return true;\" " +
					"onClick=\"document." + gReturnItem + ".value='" + 
					Cformat_data(vDay, gMonth, gYear) + 
					"'\">" + 
				Cformat_day(vDay, gMonth, gYear) + 
				"</span></A>" + 
				"</TD>";
			vDay=vDay + 1;

			if (vDay > vLastDay) {
				vOnLastDay = 1;
				break;
			}
		}

		if (j == 6)
			vCode = vCode + "</tr>";
		if (vOnLastDay == 1)
			break;
	}
	
	for (m=1; m<(7-j); m++) {
	vCode = vCode + "<td class=\"caldd\" ><span class=\"caldg\" >" + m + "</span></td>";
	}
	
	return vCode;
}

function Cformat_day (vday, gMonth, gYear) {
        var vNow = new Date();
	var vNowDay = vNow.getDate();
	var vNowMonth = vNow.getMonth();
	var vNowYear = vNow.getFullYear();

	if (vday == vNowDay && gMonth == vNowMonth && gYear == vNowYear)
		return ("<span class=\"redboy\">" + vday );
	else
		return ("<span class=\"caldn\">" + vday );
}



function Cformat_data(p_day, gMonth, gYear)
{
	var vData;
	var vMonth = 1 + gMonth;
	vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
	var vY4 = new String(gYear);
	var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;
	vData = vDD + "-" + vMonth + "-" + vY4;
	return vData;
}

function gloria_out(text, title)
{
titleclass="t84";
toptable="topclass";
caltable="calclass";
var closing="<TD ALIGN=RIGHT><a href=" + '"javascript:setSidebar(' + "'0')" + '"><img src="images6/x.gif" border="0" ></a><td>';
var output="<TABLE WIDTH=200 BORDER=0 CELLPADDING=1 CELLSPACING=0 class=" + '"' + toptable + '"' + "><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><span class=" + '"' + titleclass + '"' + ">" + title +"</span></TD>" + closing + "</TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=0 class=" + '"' + caltable + '"' + "><TR><TD  ALIGN=center VALIGN=TOP>" +text +"</TD></TR></TABLE></TD></TR></TABLE>";
output +="\n";
//document.justgloria.innerHTML=txt;
if (isIE) { document.all["sidebar"].innerHTML=output; }
var over = findDOM("sidebar", 0);
if(nav){
      range=self.document.createRange();
      range.setStartBefore(over);
      domfrag=range.createContextualFragment(output);
      while(over.hasChildNodes()){
                  over.removeChild(over.lastChild);
                  }
      over.appendChild(domfrag);
      }

}