/**
 * @author A-1692
 */
/**
 * Revision History ---------------- Date Version Author Activity 23-Mar-2005
 * 1.0 Mithun P R Modification done 17-May-2005 1.1 Mithun P R Modification done
 * for Virgin Blue 24-May-2005 1.2 Mithun P R Previous dates should be disabled
 * 29-Jun-2006 1.3 John Varghese Made the component XHTML compliant Added px to
 * dimensions in style 29-Jun-2006 1.4 Jomon George Solved the rendering issue
 * in Opera by not producing the iframe 10-09-2006 1.5 Mithun P R Modified to
 * correct error while selecting last item in combo 14-09-2006 1.6 Mithun P R
 * Modified to set focus to calendar
 * 
 * 
 */

/* PLAYGROUND */
var todayDate = new Date();
todayDateString=todayDate.getDate()+'-'+todayDate.getMonth()+'-'+todayDate.getFullYear();
          
var CalendarMonths = new Object();
		CalendarMonths[0]='GENNAIO';
		CalendarMonths[1]='FEBBRAIO';
		CalendarMonths[2]='MARZO';
		CalendarMonths[3]='APRILE';
		CalendarMonths[4]='MAG';
		CalendarMonths[5]='GIUGNO';
		CalendarMonths[6]='LUGLIO';
		CalendarMonths[7]='AGOSTO';
		CalendarMonths[8]='SETTEMBRE';
		CalendarMonths[9]='OTTOBRE';
		CalendarMonths[10]='NOVEMBRE';
		CalendarMonths[11]='DICEMBRE';

var monthsVal = new Object();
		monthsVal[0]='Gen';
		monthsVal[1]='Feb';
		monthsVal[2]='Mar';
		monthsVal[3]='Apr';
		monthsVal[4]='Mag';
		monthsVal[5]='Giu';
		monthsVal[6]='Lug';
		monthsVal[7]='Ago';
		monthsVal[8]='Set';
		monthsVal[9]='Ott';
		monthsVal[10]='Nov';
		monthsVal[11]='Dic';
	
var titleVar= 'Calendar' ;	       	
	var yearVar='Anno';
	var monVar='Lun';
	var tueVar='Mar';
	var wedVar='Mer';
	var thuVar='Gio';
	var friVar='Ven';
	var satVar='Sab';
	var sunVar='Dom';
	var prevVar='Prec';
	var closeVar='Chiudi';
	var nextVar='Prossimo';
	var startday='Lun';
	var datevalue = '';
	
/*if(datevalue.length >0 && datevalue.trim != "" && datevalue != "DD/MM/YYYY" && isaValidDate('')){
	document.getElementById('trvDate_1').value=toClientDate('');
} */    

/* */

var vWinCal;
var weekend = [0,6];
var weekendColor = "#FFFFFF";
var fontface = "Verdana";
var fontsize = 1;

var calendar_bgcolor = '#789AC8';
var calendar_head_font = '#ffffff';

var gNow = new Date();
var ggWinCal;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

var engMonths=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

/*Calendar.Months = ["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE",
                   "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"];*/

//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];

function Calendar(p_item, p_WinCal, 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;
	}

	this.gYear = p_year;
	this.gFormat  = p_format;
	this.gBGColor = "#789AC8";
	this.gFGColor = "black";
	this.gTextColor = "#CCCC99";
	this.gHeaderColor = "#ffffff";
	this.gReturnItem = p_item;
	this.gSunColour="#E5056F";
}

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 CalendarMonths[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_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() {
	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) - 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 Calendar();

Calendar.prototype.getMonthlyCalendarCode = function(p_state) {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";

	// Begin Table Drawing code here..
	vCode = vCode + "<TABLE id='table1' CELLSPACING=0 HEIGHT='105px;' CELLPADDING=0 BORDER=0 BORDERCOLOR='#DDDDDD' BGCOLOR=\"" + this.gBGColor + "\">";

	vHeader_Code = this.cal_header();

	if(p_state=="false")
	{
		vData_Code = this.cal_data();
	}
	else
	{
		vData_Code = this.cal_date_comp();
	}


	vCode = vCode + vHeader_Code + vData_Code;

	vCode = vCode + "</TABLE>";

	return vCode;
}

Calendar.prototype.color_day_comp = function(vday) {
	var vNowDay = gNow.getDate();
	var vNowMonth = gNow.getMonth();
	var vNowYear = gNow.getFullYear();

	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
	{
		return (" BGCOLOR='#E8F0F4' ");        
	}
	else {
		return ("");
	}
}
function getFirstDay(vDate){	
	if(startday == monVar){	
		var vFirstDay=vDate.getDay();
		if(vFirstDay <=6 && vFirstDay > 0){
			vFirstDay = vFirstDay -1;
		} else {
			vFirstDay = 6;
		}
		return vFirstDay;
	} 
	else if(startday == sunVar){	
		return vDate.getDay();
	}
}
Calendar.prototype.cal_date_comp = function() {    
  var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(this.gMonth);
	vDate.setFullYear(this.gYear);
	var vFirstDay = getFirstDay(vDate);
	
	//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 + "<TR>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<TD  class='dateCol' WIDTH='14%' HEIGHT=15 ALIGN=CENTER" + this.write_weekend_string(i) + "><FONT  SIZE='1' FACE='" + fontface + "'>&nbsp;</FONT></TD>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {    
		vCode = vCode + "<TD class=\"dateCol\"  onmouseover='{hover(this)}'"+	 
		" onmouseout='mouseout(this)' "+
		"onclick=\"if(correctElement(this)) {return setDateValues('" + 
		this.format_data(vDay) +
		"','"+this.gReturnItem+"')}\"" +"   class='dateCol'  WIDTH='14%'"+this.color_day_comp(vDay)+
		" HEIGHT=15 ALIGN=CENTER "  + this.write_weekend_string(j) + ">";

		var sampDate = vDay+"-"+this.gMonth+"-"+this.gYear;            
		
    var state = chkDates(expectedStartDte,sampDate); // 1 <=2


    if(state=="failure")
		{
			vCode = vCode + "<span style='text-decoration: line-through; color: grey;'>"+this.format_day(vDay)+"</span>"; 
		}
		else
		{
      if(j==6)
       	vCode = vCode + this.format_sunday(vDay);
			else 
				vCode = vCode + this.format_day(vDay)  ;
		}            

		vCode = vCode + "</TD>";           
		vDay=vDay + 1;
	}
	vCode = vCode + "</TR>";

	var kval = 2;
	if((vFirstDay >=5 && vLastDay == 31) ||(vFirstDay >= 6 && vLastDay == 30)){
	} else {
		kval=1;
	}
	var kvalfeb = 1;
	if(vFirstDay == 0 && vLastDay ==  28){
		kvalfeb = 10;
	}

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

		for (j=0; j<7; j++) {
			vCode = vCode + "<TD class='dateCol' onmouseover='hover(this)'" + 
			" onmouseout='mouseout(this)' onclick=\"if(correctElement(this)){ return setDateValues('" +
			this.format_data(vDay) +
			"','"+this.gReturnItem+"')}\""+ " WIDTH='14%'"+this.color_day_comp(vDay)+" HEIGHT=15 ALIGN=CENTER "  +
			this.write_weekend_string(j) + ">";

			var sampDate = vDay+"-"+this.gMonth+"-"+this.gYear;            
			var state = chkDates(expectedStartDte,sampDate); // 1 <=2

			if(state=="failure")
			{
				vCode = vCode + "<span style='text-decoration: line-through; color: grey;'>"+this.format_day(vDay)+"</span>"; 
			}
			else
			{
				if(j==6)
            	vCode = vCode + this.format_sunday(vDay);
				else 
				vCode = vCode + this.format_day(vDay)  ;
				//vCode = vCode +  this.format_day(vDay); 

			}

			vCode = vCode + "</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 class='dateCol' HEIGHT=15 ALIGN=CENTER WIDTH='14%'" + this.write_weekend_string(j+m) +
			"></TD>";
		else
			vCode = vCode + "<TD class='dateCol' WIDTH='14%' HEIGHT=15 ALIGN=CENTER  " +
			this.write_weekend_string(j+m) +
			">&nbsp;" // + m
			+ "</TD>";
	}
	vCode = vCode + "<TR>";
	if(kval == 1){

		for (m=0; m<7; m++) {
			if (this.gYearly)
				vCode = vCode + "<TD class='dateCol' HEIGHT=15 ALIGN=CENTER WIDTH='14%'" + this.write_weekend_string(j+m) +
				"></TD>";
			else
				vCode = vCode + "<TD class='dateCol' WIDTH='14%' HEIGHT=15 ALIGN=CENTER  " +
				this.write_weekend_string(j+m) +
				">&nbsp;"// + m
				+ "</TD>";
		}

	}

	if(kvalfeb == 10){
		vCode = vCode + "</TR>";
		vCode = vCode + "<TR>";
		for (m=0; m<7; m++) {
			if (this.gYearly)
				vCode = vCode + "<TD class='dateCol' HEIGHT=15 ALIGN=CENTER WIDTH='14%'" + this.write_weekend_string(j+m) +
				"></TD>";
			else
				vCode = vCode + "<TD class='dateCol' WIDTH='14%' HEIGHT=15 ALIGN=CENTER  " +
				this.write_weekend_string(j+m) +
				">&nbsp;"// + m
				+ "</TD>";
		}
	}



	return vCode;
}

Calendar.prototype.show = function(p_state) {
	var vCode = "";

	this.gWinCal.document.open();

	// Setup the page...
	this.wwrite("<html>");
	this.wwrite("<head><title></title>");
	this.wwrite("<style type='text/css' HREF='MoM_style.css'></style></head>");

	this.wwrite("<body  TOPMARGIN='0' LEFTMARGIN=0' RIGHTMARGIN='0' bgcolor='#FFFFFF'>" );

	// 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 id='table2' WIDTH='100%' BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#CECFCE'><TR><TD COLSPAN='2' ALIGN=left><B><FONT COLOR='#990033' FACE='Verdana' SIZE='1'> " + "<A HREF=\"" +
			"javascript:Build(" +
			"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "','" + p_state + "'" +
			");" +
			"\"><FONT COLOR='#990033' FACE=Verdana SIZE=1><</FONT><\/A>&nbsp;"  +this.gMonthName + "&nbsp;<A HREF=\"" +
			"javascript:Build(" +
			"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat  + "','" + p_state + "'" +
			");" +
			"\"><FONT COLOR='#990033' FACE=Verdana SIZE=1>></FONT><\/A>" + " </FONT></B></TD> <TD  COLSPAN='2' ALIGN=right><B><FONT FACE='Verdana' COLOR='#990033' SIZE='1'> "+ "<A HREF=\"" +
			"javascript:Build(" +
			"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "','" + p_state + "'" +
			");" +
			"\"><FONT COLOR='#990033' FACE=Verdana SIZE=1><</FONT><\/A>&nbsp;" + this.gYear + "&nbsp;<A HREF=\"" +
			"javascript:Build(" +
			"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "','" + p_state + "'" +
			");" +
			"\"><FONT COLOR='#990033' FACE=Verdana SIZE=1>></FONT><\/A>" + "  </FONT></B></TD></TR><TR><TD WIDTH='25%' ALIGN=center><FONT FACE='Verdana' SIZE='1'>");

	this.wwrite("</FONT></TD></TR></TABLE>");

	// Get the complete calendar code for the month..
	vCode = this.getMonthlyCalendarCode(p_state);
	this.wwrite(vCode);

	this.wwrite("</font></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.showY = function(p_state) {
	var vCode = "";
	var i;
	var vr, vc, vx, vy;     // Row, Column, X-coord, Y-coord
	var vxf = 285;          // X-Factor
	var vyf = 200;          // Y-Factor
	var vxm = 0;            // X-margin
	var vym = 0;                // Y-margin
	if (isIE)   vym = 0;
	else if (isNav) vym = 0;

	this.gWinCal.document.open();

	this.wwrite("<html>");
	this.wwrite("<head><title>"+titleVar+"</title>");
	this.wwrite("<style type='text/css' HREF='MoM_style.css'>\n<!--");
	for (i=0; i<12; i++) {
		vc = i % 3;
		if (i>=0 && i<= 2)  vr = 0;
		if (i>=3 && i<= 5)  vr = 1;
		if (i>=6 && i<= 8)  vr = 2;
		if (i>=9 && i<= 11) vr = 3;

		vx = parseInt(vxf * vc) + vxm;
		vy = parseInt(vyf * vr) + vym;

		this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
	}
	this.wwrite("-->\n</style>");
	this.wwrite("</head>");

	this.wwrite("<body TOPMARGIN='0' LEFTMARGIN=0' RIGHTMARGIN='0' bgcolor='#FFFFFF'>" );
	this.wwrite("<FONT FACE='" + fontface + "' SIZE=1><B>");
	this.wwrite(yearVar+" : " + this.gYear);
	this.wwrite("</B> </FONT>");

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;

	this.wwrite("<TABLE id='table3' WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#FFFFFF'><TR><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
			"javascript:Build(" +
			"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "','" + p_state + "'" +
			");" +
	"\" alt='Prev Year'>"+prevVar+"<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
			"javascript:Build(" +
			"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "','" + p_state + "'" +
			");" +
	"\">"+nextVar+"<\/A>]</TD></TR></TABLE>");

	// Get the complete calendar code for each month..
	var j;
	for (i=11; i>=0; i--) {
		if (isIE)
			this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
		else if (isNav)
			this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");

		this.gMonth = i;
		this.gMonthName = Calendar.get_month(this.gMonth);
		vCode = this.getMonthlyCalendarCode(p_state);
		this.wwrite(this.gMonthName + "/" + this.gYear + "");
		this.wwrite(vCode);

		if (isIE)
			this.wwrite("</DIV>");
		else if (isNav)
			this.wwrite("</LAYER>");
	}

	this.wwrite("</font></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.wwrite = function(wtext) {
	// this.gWinCal.document.writeln(wtext);
	this.gWinCal.innerHTML = this.gWinCal.innerHTML+wtext;    
}

Calendar.prototype.wwriteA = function(wtext) {
	this.gWinCal.document.write(wtext);
}

Calendar.prototype.cal_header = function() {
	var vCode = "";
	if(startday == monVar){
		vCode = vCode + "<TR BGCOLOR='#E8F0F4' height='1px;'>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+monVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+tueVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+wedVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+thuVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+friVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='16%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+satVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gSunColour + "'><B>"+sunVar+"</B></FONT></TD>";
		vCode = vCode + "</TR>";
	} else if(startday == sunVar){
		vCode = vCode + "<TR BGCOLOR='#E8F0F4' height='1px;'>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gSunColour + "'><B>"+sunVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+tueVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+wedVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+thuVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+friVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='14%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+satVar+"</B></FONT></TD>";
		vCode = vCode + "<TD WIDTH='16%' ALIGN=CENTER><FONT SIZE='1' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>"+monVar+"</B></FONT></TD>";
		vCode = vCode + "</TR>";
	}

	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 + "<TR>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<TD WIDTH='14%' HEIGHT=15 ALIGN=CENTER " + this.write_weekend_string(i) + "><FONT SIZE='1' FACE='" + fontface + "'> </FONT></TD>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {
		vCode = vCode + "<TD WIDTH='14%' HEIGHT=15 ALIGN=CENTER "  + this.write_weekend_string(j) + "><FONT SIZE='1' FACE='" + fontface + "'>" +
		"<A style='text-decoration:underline' " +
		"onClick=\"document." + this.gReturnItem + ".value='" +
		this.format_data(vDay) +
		"';document." + this.gReturnItem + ".focus();closeLayer();\" onmouseover=setPointerType(this) >" +
		this.format_day(vDay) +
		"</A>" +
		"</FONT></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++) {
			vCode = vCode + "<TD WIDTH='14%' HEIGHT=15 ALIGN=CENTER "  + this.write_weekend_string(j) + "><FONT SIZE='1' FACE='" + fontface + "'>" +
			"<A style='text-decoration:underline' " +
			"onClick=\"document." + this.gReturnItem + ".value='" +
			this.format_data(vDay) +
			"';"+ "document." + this.gReturnItem + ".focus();closeLayer();\" onmouseover=setPointerType(this) >" +
			this.format_day(vDay) +
			"</A>" +
			"</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  HEIGHT=15 ALIGN=CENTER WIDTH='14%'" + this.write_weekend_string(j+m) +
			"><FONT SIZE='1' FACE='" + fontface + "' COLOR='#FFFFFF'> </FONT></TD>";
		else
			vCode = vCode + "<TD WIDTH='14%' HEIGHT=15 ALIGN=CENTER  " + this.write_weekend_string(j+m) +
			"><FONT SIZE='1' FACE='" + fontface + "' COLOR='#FFFFFF'>" + m + "</FONT></TD>";
	}

	return vCode;
}

Calendar.prototype.format_sunday= function(vday) {
	return ("<FONT COLOR=\"#E5056F\"><B>" + vday + "</B></FONT>");
}

Calendar.prototype.format_day = function(vday) {
	var vNowDay = gNow.getDate();
	var vNowMonth = gNow.getMonth();
	var vNowYear = gNow.getFullYear();
//	Today's date
	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
		return ("<FONT COLOR=\"#E5056F\"><B>" + vday + "</B></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=\"" + weekendColor + "\"");
	}

	return "";
}

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);
	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.toUpperCase()) {
	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-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;
}

function Build(p_item, p_month, p_year, p_format,p_state) {
	var p_WinCal = ggWinCal;
	gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

	// Customize your Calendar here..
	gCal.gBGColor="#788084";
	gCal.gLinkColor="#FFFFFF";
	gCal.gTextColor="#FFFFFF";
	gCal.gHeaderColor="#000000";

	// Choose appropriate show function
	if (gCal.gYearly)   gCal.showY(p_state);
	else    gCal.show(p_state);
}

function show_cal() {
	/*
	 * 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.
	 */
	var top = 291;
	var left = 421;
	var p_state = "false";

	p_item = arguments[0];
	if (arguments[1] == null)
		p_month = new String(gNow.getMonth());
	else
		p_month = arguments[1];
	if (arguments[2] == "" || arguments[2] == null)
		p_year = new String(gNow.getFullYear().toString());
	else
		p_year = arguments[2];
	if (arguments[3] == null)
		p_format = "DD-MON-YYYY";
	else
		p_format = arguments[3];
	if (arguments[4] == null)
		top = 291;
	else
		top = arguments[4];
	if (arguments[5] == null)
		left = 421;
	else
		left = arguments[5];

	if (arguments[6] == null || arguments[6].length==0)
		p_state = "false";
	else
		p_state = arguments[6];        

	var dtls = "width=180,height=115,status=no,resizable=no,top="+top+",left="+left;  

	if(!vWinCal || vWinCal.closed) {
		vWinCal = window.open("", "Calendar","width=180,height=115,status=no,resizable=no,top="+top+",left="+left);
		vWinCal.opener = self;
		ggWinCal = vWinCal;
	} else if(vWinCal) {
		vWinCal.focus();
	}

	Build(p_item, p_month, p_year, p_format,p_state);
}

/** ********** */
var expectedStartDte = new Date();
var expectedEndDte;

/*
 * The parameters passed to calendar component are given below
 * 
 * v1 - The calendar object or text field v2 - The position of the calendar from
 * browser top v3 - The position of the calendar from browser left v4 - To
 * specify if calendar exists as part of the component or is related to a text
 * field true --> related to component false --> individual text field v5 - The
 * selected date in the calendar v6 - The lower limit of the calendar v7 - The
 * upper limit of the calendar v8 - To specify if limit to be applied to
 * calendar navigation v9 - The value is 1 or 2 for showing 1 or 2 monthly
 * calendar respectively
 */

function show_calendar(v1,v2,v3,v4,v5,v6,v7,v8,v9) {

  //alert("1-> "+v1+"   2-> "+v2+"   3-> "+v3+"   4-> "+v4+"   5-> "+v5+"   6-> "+v6+"   7-> "+v7+"   8-> "+v8+"   9-> "+v9);
  /**
	 * for making the date unlimited
	 */
	v8 = 'N';
	var dates=document.getElementById(v1).value.split("/");
	
	var tmpDate=document.getElementById(v1).value;
	tmpDate=tmpDate.replace(/\d{2}\/[0-9]{2}\/\d{4}/,''); 
	if(tmpDate!=''){
		//alert(tmpDate);
    dates=["DD","MMM","YYYY"];
	}
  
	var stDtStr = v6.split("-");

	if(!isNaN(dates[0])&&!isNaN(dates[2])&& !isNaN(dates[1])){
    dates[1] = dates[1]-1;
		if((dates[2] < stDtStr[2]) || ((dates[2] == stDtStr[2]) && ((dates[1]) < stDtStr[1])) 
				|| ((dates[2] == stDtStr[2]) && ((dates[1]) == stDtStr[1]) && dates[0] < stDtStr[0])){
			v5 = v6;
		}else{ 
			v5=dates[0]+"-"+(dates[1])+"-"+dates[2];
		}
	}
	if(v5!=null)
	{
		var arrLst = v5.split("-");
    gNow.setFullYear(arrLst[2],arrLst[1],arrLst[0]); 
	}
	else
	{
		gNow = new Date();
		var elemobj = eval("document."+v1);
		var elemArray = elemobj.value.split("-");       
		if(elemArray.length==3)
		{               
      gNow.setFullYear(elemArray[2],getMonthId(elemArray[1]),elemArray[0]);
		}   
	} 

	if(v8=="n" || v8=="N")
	{
		expectedStartDte = null;
		expectedEndDte = null;
	}
	else
	{
		if(v6!=null && v6.length>0)
		{
			expectedStartDte = v6;                      
		}
		else
		{
			var tmp = new Date();           
			expectedStartDte = tmp.getMonth()+"-"+tmp.getFullYear();        

		}

		if(v7!=null)
			expectedEndDte = v7;
		else
			expectedEndDte=null;        
	}   

	var field = v1;
	var mon = new String(gNow.getMonth());
	var yr = new String(gNow.getFullYear().toString());
	var frmt = p_format = DT_FMT;
	var top = v2;
	var lft = v3;   
	var state = v4;

	if(v9!=null && v9>2)
	{
		v9=2;
	}
	else if(v9==null)
	{
		v9=2;
	}
  
  //alert("---> "+field+" "+mon+" "+yr+" "+frmt+" "+top+" "+lft+" "+state+" "+v9);
	show_2monthly_calendar(field,mon,yr,frmt,top,lft,state,v9); 

	// Setting focus to the calendar
	if(document.getElementById('hidCalLyr'))
	{			
		var layer = document.getElementById('hidCalLyr');		
		// var focusIt = layer.getElementsByTagName('a')[0];//This is an array,
		// get the first link.
		// focusIt.focus();
	}
}



/*
 * 2 Monthly Calendar Code Starts here
 */
function show_2monthly_calendar(p_item, p_month,p_year, p_format) {   

  //alert(p_item+" "+p_month+" "+p_year+" "+p_format);

	var top = 291;
	var left = 421;
	var p_state = "false";

	// ++++++++++++++++++++++++++++++++++++
	var browserName=navigator.appName;
	var agt=navigator.userAgent.toLowerCase();
	var is_opera =     (document.all==undefined);     
	// ++++++++++++++++++++++++++++++++++++++++++++++++++


  /* PLAYGROUND */
  //partenza -> se la data nel calendario di partenza è vuota apre il calendario sul mese corrente
  //partenza -> se c'è una data valida nel calendario di partenza apre il calendario nel mese indicato dalla data
  //ritorno -> se la data nel calendario di ritorno è vuota apre il calendario sul mese relativo alla data di partenza  
  //ritorno -> se la data nel calendario di ritorno è vuota e la data di partenza è vuota apre il calendario sul mese corrente
  //ritorno -> se c'è una data nel calendario di ritorno apre il calendario sul mese indicato dalla data
  if (p_item=="travelDate#trvDate_2"){
    //if(isValidDate(document.getElementById("trvDate_2").value)){
    //  var monthDeparture=document.getElementById("travelDate#trvDate_2").value.split("/");
    //}
    //else{
      var monthDeparture=document.getElementById("travelDate#trvDate_1").value.split("/");
    //}
    
    if (monthDeparture[1]=="01"){p_month=0;}
    if (monthDeparture[1]=="02"){p_month=1;}
    if (monthDeparture[1]=="03"){p_month=2;}
    if (monthDeparture[1]=="04"){p_month=3;}
    if (monthDeparture[1]=="05"){p_month=4;}
    if (monthDeparture[1]=="06"){p_month=5;}
    if (monthDeparture[1]=="07"){p_month=6;}
    if (monthDeparture[1]=="08"){p_month=7;}
    if (monthDeparture[1]=="09"){p_month=8;}
    if (monthDeparture[1]=="10"){p_month=9;}
    if (monthDeparture[1]=="11"){p_month=10;}
    if (monthDeparture[1]=="12"){p_month=11;}
    
    p_year=monthDeparture[2];
    //alert(p_year);  
  }
  /* */
         
  


	p_item = arguments[0];
	if (arguments[1] == null)
		p_month = new String(gNow.getMonth());
	else
		p_month = arguments[1];
	
  /*
  if (arguments[2] == "" || arguments[2] == null)
		p_year = new String(gNow.getFullYear().toString());
	else
		p_year = arguments[2];
	*/
  	
	//alert(p_year);	
		
	if (arguments[3] == null)
		p_format = "DD-MON-YYYY";
	else
		p_format = arguments[3];
	if (arguments[4] == null)
		top = 291;
	else
		top = arguments[4];
	if (arguments[5] == null)
		left = 421;
	else
		left = arguments[5];

	if (arguments[6] == null || arguments[6].length==0)
		p_state = "false";
	else
		p_state = arguments[6];        

	var p_showId = arguments[7];

	var elem = document.createElement("div");
	elem.id = 'hidCalLyr';
	elem.align = "left"
		if(p_showId==2)
		{
			// elem.style.width='390px';


		}
		else if(p_showId==1)
		{      
			elem.style.width='250px';
		}
	elem.style.height='150px';
	elem.style.position='absolute';
	elem.style.top=''+top+'px';
	elem.style.left=''+left+'px';  
	elem.zIndex=3453000; 
	if (!is_opera) {

		var iframeElem = document.createElement("iframe");
		iframeElem.src="javascript:false";
		iframeElem.id = 'hidCalLyrIfr';
		if(p_showId==2)
		{
			 iframeElem.style.width='385px';

		}
		else if(p_showId==1){
			iframeElem.style.width='250px';  
		}

		iframeElem.style.top=(top)+'px';
		iframeElem.style.left=(left+2)+'px';



		iframeElem.style.display='block';

		iframeElem.style.border='0px';
		
		// iframeElem.zIndex=2000;

	}



	if(document.getElementById("hidCalLyr")==null || !document.getElementById("hidCalLyr"))
	{          
		/*
		 * var obj = document.forms[0]; obj.appendChild(iframeElem);
		 * obj.appendChild(elem);
		 */
		var obj = document.getElementsByTagName('body')[0];         
		if (!is_opera){

			obj.appendChild(iframeElem);
		}
		obj.appendChild(elem);          
	} 
	else
	{
		document.getElementById("hidCalLyr").style.display='block';
		document.getElementById("hidCalLyr").innerHTML="";
		document.getElementById("hidCalLyr").style.left=left+'px';
		document.getElementById("hidCalLyr").style.top=(top)+'px'         

		if (!is_opera) {          
			document.getElementById("hidCalLyrIfr").style.left=(left+2)+'px';		 
			document.getElementById("hidCalLyrIfr").style.top=(top+5)+'px'; 
			document.getElementById("hidCalLyrIfr").style.display='block';
			iframeElem.style.height=document.getElementById("hidCalLyrIfr").style.height;
		}

		if(p_showId==2)  {        


		}
		else if(p_showId==1)
		{       
			document.getElementById("hidCalLyr").style.width='250px';
			if (!is_opera)
				document.getElementById("hidCalLyrIfr").style.width='250px';
		}
	}

	ggWinCal=document.getElementById("hidCalLyr");     
  
  /* PLAYGROUND */
  if((p_year=="AAAA")||(p_year=="YYYY")){
    var dataOdierna = new Date();
    p_year=dataOdierna.getFullYear().toString();
  }
  /**/
  
  
  //alert(p_item+" "+p_month+" "+p_year+" "+p_format+" "+p_state+" "+p_showId);
  Build2Monthly(p_item, p_month, p_year, p_format,p_state,p_showId);
}

function compareDates(dte1Month,dte1Year,dte2,dte3,p_showId)
{    
	var tmpDte = dte1Month+"-"+dte1Year;
	var endDte = null;
	var startDte = null;
	if(dte2!=null)
		startDte = dte2.split('-')[1]+"-"+dte2.split('-')[2];
	if(dte3!=null)
		endDte = dte3.split('-')[1]+"-"+dte3.split('-')[2];   

	var startState = checkDateSeq(startDte,tmpDte); // if tmpDte is greater than
	// startDte ..
	// tmpDte>=startDte
	var endState = checkDateSeq(tmpDte,endDte); // if tmpDte is less than endDte
	// .... tmpDte<endDte

	var returnState = "true";    

	if(startState=="failure")
	{
		returnState = "false";
	}   

	if(returnState=="true")
	{

		if(p_showId==2)
		{			
			if(endState=="failure" )
			{
				returnState = "false";
			}	
			else if(endState=="equal" ) {
				returnState = "equal";
			}
		}
		else
		{
			if(endState=="failure")
			{
				returnState = "false";
			}	
		}		
	}

	return returnState;   

}

function checkDateSeq(fromDate,toDate){

	if(fromDate!=null && toDate!=null)
	{
		var firstDateElements = fromDate.split("-");
		var secondDateElements = toDate.split("-"); 

		var firstMonth = parseFloat(firstDateElements[0]);  
		var firstYear = parseFloat(firstDateElements[1]);

		var secMonth = parseFloat(secondDateElements[0]);           
		var secYear = parseFloat(secondDateElements[1]);

		if(secYear < firstYear){        
			return "failure";
		}else if((secYear == firstYear) && (secMonth<firstMonth)){      
			return "failure";
		}else if((secYear == firstYear) && (secMonth==firstMonth)){                     
			return "equal";
		}
	}

	return "true";

} 


function Build2Monthly(p_item, p_month, p_year, p_format,p_state,p_showId) {    
	var p_WinCal = ggWinCal;                    
	if(p_showId==2 && (p_month+"-"+p_year)==expectedEndDte)
	{    		
		var tmp = Calendar.calc_month_year(p_month, p_year, -1);    		
		p_month = ""+tmp[0];
		p_year = ""+tmp[1];    		
		this.gMonth = ""+p_month;
		this.gYear = ""+p_year;
	}    

	var compareState = compareDates(p_month,p_year,expectedStartDte,expectedEndDte,p_showId);        
	if(compareState=="true")
	{

		gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

		// Customize your Calendar here..
		gCal.gBGColor="#788084";
		gCal.gLinkColor="#FFFFFF";
		gCal.gTextColor="#FFFFFF";
		gCal.gHeaderColor="#000000";

		gCal.gWinCal.innerHTML = "";	    	    
		gCal.showMonthly(p_month,p_state,p_showId); 	    
	}
	else if(compareState=="equal")
	{
		var tmpArray = p_item.split('@@');
		var tmpMonthObj = document.getElementById(tmpArray[1]);    	
		if((tmpMonthObj.options.length)==(tmpMonthObj.selectedIndex+1))
		{
			var prevMMYYYY = Calendar.calc_month_year(p_month, p_year, -1);
			p_month = ""+prevMMYYYY[0];
			p_year = ""+prevMMYYYY[1];
			this.gMonth = p_month;
			this.gYear = p_year;

			gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

			// Customize your Calendar here..
			gCal.gBGColor="#788084";
			gCal.gLinkColor="#FFFFFF";
			gCal.gTextColor="#FFFFFF";
			gCal.gHeaderColor="#000000";

			gCal.gWinCal.innerHTML = "";	    	    
			gCal.showMonthly(p_month,p_state,p_showId);
		}   	

	}
	else
	{
		var tmp = expectedStartDte.split("-");
		var mth = parseFloat(tmp[0]);
		var yr = tmp[1];    		

		if(mth==0)
		{
			mth = 11;	
			yr = tmp[1];
		}
		else
		{
			mth = mth-1;	
			yr = parseFloat(tmp[1])+1;
		}

	}
}

function closeLayer(){
	
	/* PLAYGROUND */
  

  if(calOneOrCalTwo==2){
    $('#solo_andata').show();
    $('#tripType').val('RT');
  }


  
  
  //if($('.dateTextbox_2').val()!="One way"){
    //alert("a");
    
  //}
  //alert("2");
  /**/
  
  
  if(document.getElementById("hidCalLyr"))    {
		var oNodeToRemove = document.getElementById("hidCalLyr");
		// oNodeToRemove.style.display="none"
		oNodeToRemove.parentNode.removeChild(oNodeToRemove);
	}

	if(document.getElementById("hidCalLyrIfr"))    {
		var oNodeToRemove = document.getElementById("hidCalLyrIfr");
		// oNodeToRemove.style.display="none";
		oNodeToRemove.parentNode.removeChild(oNodeToRemove);
	}
	//alert($('#trvDate_2').val());
}

function solaAndataState(){
  
  //alert($('#trvDate_2').val());
  if($('.dateTextbox_2').val()!="One way"){
    //alert("a");
    //$('#solo_andata').show();
  }
  
  
  
}





Calendar.prototype.showMonthly = function(p_month,p_state,p_showId) {
	var vCode = "";
	var i;

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;        

	// 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];

	var tmpStartDte = null;
	var tmpEndDte = null;
	if(expectedStartDte!=null)    
		var tmpStartDte = expectedStartDte.split('-')[1]+"-"+expectedStartDte.split('-')[2];
	if(expectedEndDte!=null)    
		tmpEndDte = expectedEndDte.split('-')[1]+"-"+expectedEndDte.split('-')[2];

	var startState = checkDateSeq(tmpStartDte,prevMM+"-"+prevYYYY);
	var endState = checkDateSeq(nextMM+"-"+nextYYYY,tmpEndDte);   


	var navStr = "<table  id='table4' border='0' cellpadding='0' align=right cellspacing='0' height='150' width='100%'>";
	navStr+="<tr><td style=''>&nbsp;</td><td>";
	navStr+= "<table id='table5' bgcolor='"+calendar_bgcolor+"' border='0' cellpadding='0' cellspacing='0' >"; 
	navStr+="<tr><td colspan=2 height='20px'>";



	navStr = navStr+"<table id='table6' width='100%' height='20px' border=0 cellspacing=0 cellpadding=0 bgcolor='"+calendar_bgcolor+"'><tr><td align=left width='175'><b><font color='"+calendar_head_font+"' face='Verdana' size='1'>&nbsp;&nbsp; " 
	if(startState!="failure")
	{
		navStr = navStr + "<a class='calLink' href=\"" + "javascript:Build2Monthly(" +
		"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "','" + p_state + "','" + p_showId + "'" +
		");" +
		"\"><font color='"+calendar_head_font+"' face=Verdana SIZE=1><<" ;
	}   

	var tmpPrevMonth = this.gMonthName;
	var tmpNextMonth = Calendar.get_month(parseFloat(nextMM));
	if(p_showId==1)
	{
		if(startState!="failure")
			tmpPrevMonth = Calendar.get_month(parseFloat(prevMM)); 
		else
			tmpPrevMonth = "";

		if(endState=="failure")
			tmpNextMonth = "";
	}     

	if(p_showId==2 && startState!="failure")
	{
		tmpPrevMonth = Calendar.get_month(parseFloat(prevMM));
	}

	if(startState!="failure")
	{
		navStr = navStr + "&nbsp;"+ prevVar + "<\/a>";
	}
	else
	{
		navStr = navStr + "&nbsp;"+prevVar;
	}

	navStr = navStr + " </font></b></td><td align=center><a href=\"" + "javascript:closeLayer()\">"+closeVar+"</a> </td><td align=right width='175'><b><font color='"+calendar_head_font+"' face='Verdana' size='1'>";

	if(endState=="true")
	{
		navStr = navStr + "<a class='calLink' href=\"" + "javascript:Build2Monthly(" +
		"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "','" + p_state + "','" + p_showId + "'" +
		");" +
		"\"><font color='"+calendar_head_font+"' face=Verdana size=1>"+nextVar+"&nbsp;>></font><\/a>";
	}   
	else
	{
		if(p_showId==2)
			navStr = navStr + ""+tmpNextMonth;
	}

	if(p_showId==1)
	{
		if(endState=="equal")
		{
			navStr = navStr + "<a class='calLink' href=\"" + "javascript:Build2Monthly(" +
			"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "','" + p_state + "','" + p_showId + "'" +
			");" +
			"\"><font color='"+calendar_head_font+"' face=Verdana size=1>"+nextVar+"&nbsp;>></font><\/a>";
		}   
	}

	navStr = navStr + "&nbsp;&nbsp;";       
	navStr = navStr + "</font></td></tr></table>";      


	navStr+="</td></tr><tr>";

	// Get the complete calendar code for each month..
	var j;
	var tmp = p_month;
	var tmp1;
	var tmp2;
	this.gMonthName = Calendar.get_month(this.gMonth); 
	vCode = this.getMonthlyCalendarCode(p_state);
	tmp1 = vCode;

	navStr+="<td align=center><b><font color='"+calendar_head_font+"' face='Verdana' size='1'>"+this.gMonthName + "/" + this.gYear + "</font></b></td>";

	this.gMonth = nextMM;
	this.gYear = new String(nextYYYY);    
	this.gMonthName = Calendar.get_month(this.gMonth);
	vCode = this.getMonthlyCalendarCode(p_state);
	tmp2 = vCode;      

	if(p_showId==2)
	{
		navStr+="<td align=center><b><font color='"+calendar_head_font+"' face='Verdana' size='1'>"+this.gMonthName + "/" + this.gYear + "</font></b></td>";
	}

	navStr+="</tr><tr><td align=center valign=top style='padding:2px'>"+tmp1+"</td>";
	if(p_showId==2)
	{
		navStr+="<td align=center valign=top style='padding:2px'>"+tmp2+"</td>";
	}
	navStr+="</tr></table>";
	navStr+="</td></tr></table>";
	this.wwrite(navStr);    
}

function chkDates(fromDate,toDate){

	if(fromDate!=null && toDate!=null)
	{
		var firstDateElements = fromDate.split("-");
		var secondDateElements = toDate.split("-");

		var firstDate = parseFloat(firstDateElements[0]);
		var firstMonth = parseFloat(firstDateElements[1]);  
		var firstYear = parseFloat(firstDateElements[2]);

		var secDate = parseFloat(secondDateElements[0]);
		var secMonth = parseFloat(secondDateElements[1]);           
		var secYear = parseFloat(secondDateElements[2]);

		if(secYear < firstYear){        
			return "failure";
		}else if((secYear == firstYear) && (secMonth<firstMonth)){      
			return "failure";
		}else if((secYear == firstYear) && (secMonth==firstMonth) && (secDate<firstDate)){                      
			return "failure";
		}else if((secYear == firstYear) && (secMonth==firstMonth) && (secDate==firstDate)){     
			return "equal";
		}
	}

	return "true";

}
function isValidDate(givenDate){ 
	//alert(givenDate.value);
  var isValid=false;
	if(givenDate.length!=0){
		givenDate=new String(givenDate);
		var tmpdate=givenDate.replace(/\d{1,2}\-[A-Za-z]{3}\-\d{4}/,'');
		if(tmpdate==''){
			var dates=givenDate.split("-");
			dates[1]=dates[1].toUpperCase().replace(/JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC/,'');
			if(dates[1]==''){
				isValid=true; 
			}

		}
	} 
	return isValid;
}
function hover(el){
	var html=new String(el.innerHTML);
	if(html.toUpperCase().indexOf("SPAN")<0){ 
		el.className="dateColhover";
	}
}
function mouseout(el){
	el.className="dateCol"
}
function correctElement(el){
	var html=new String(el.innerHTML);
	return html.indexOf("SPAN")<0; 


}

function isInsideCal(el){
	var isInside=false;
	while(el!=null){
		if(el.id=='hidCalLyr'){
			isInside=true;
			break;
		}
		el=el.offsetParent;
	}
	return isInside;

}	  

function closeCalendar(e){
	var srcElement=document.all?e.srcElement:e.target;  
	if((srcElement.onclick==null||srcElement.onclick.toString().indexOf('show_calendar(')<0)&& !isInsideCal(srcElement)){
		if(document.getElementById("hidCalLyr")) 
			closeLayer();
	}

}   

if(document.all)
	document.onclick=function (){closeCalendar(window.event)};
	else{
		document.addEventListener("click",closeCalendar,true);
	}
/**
 * Function for adding the typed value to the hidden field for the text field
 * @param idvalue
 * @param hiddenId
 * @return
 */
function addTypedValueToHidden(idvalue,hiddenId) {
  
  var valueTyped=document.getElementById(idvalue).value;
  
  if(valueTyped.trim().length>0 && valueTyped != "DD/MM/YYYY"){
		if(isaValidDate(valueTyped)){
      document.getElementById(hiddenId).value=toClientDate(valueTyped);
		}else{
			document.getElementById(hiddenId).value = "INVALID_DATE";
		}
	}else{
		document.getElementById(hiddenId).value = "DD/MM/YYYY";
	}
	
	///alert(   $('.dateTextbox_2').val()   );
	//alert($('#trvDate_2').val());
	//alert("1");
	//solaAndataState();
  //alert(firstTime);
  //alert($('.dateTextbox_2').val());
  
  
  
  
  
  
  


  
  	
}

/*
var refreshIntervalId=0;
function trickToGetUpdatedDate() {
  //alert($('.dateTextbox_2').val());
  
  
  
  clearInterval(refreshIntervalId);   
}
*/
