// Bespoke version of the date picker.
// Bespoke changes Copyright © 2005-2006, CTT Group Ltd.  All Rights Reserved.

function show_helloworld() { alert('hello world'); }

// CUSTOM
var PYB_Top = 0, PYB_Left = 0, PYB_OffsetLeft = 0;
var isFlight = true;
//var objDay, objMonth, objYear;
var objInputField, gCloseItem;

var weekend = [0,6];
var weekendColor = "#e0e0e0";   //#DDF2F9
var fontface = "Verdana";
var fontsize = 1;

var gNow = new Date();
var ggWinCal;
var gWinCalDocument;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

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) {
//	return;
	if ((p_month == null) && (p_year == null))	return;

	if (p_WinCal == null)
		this.gWinCal = ggWinCal;
	else
		this.gWinCal = p_WinCal;

	this.gWinCalDocument = (isIE ? this.gWinCal.document : this.gWinCal.contentDocument );
	
	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 = "white";
	this.gFGColor = "black";
	this.gTextColor = "black";
	this.gHeaderColor = "black";
	this.gReturnItem = p_item;

	this.gCloseItem = gCloseItem;
}

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. 
	*/
	monthNo = parseInt(monthNo);
	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;
			if(p_Year=="2006") 
				ret_arr[1] = parseInt(p_Year);
		}
		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;
			if(p_Year=="2007")
				ret_arr[1] = parseInt(p_Year);
		}
		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() {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";
	
	// Begin Table Drawing code here..
	vCode = vCode + "<TABLE BORDER=0 BGCOLOR=\"" + this.gBGColor + "\" cellpadding=0 cellspacing=2>";

	vHeader_Code = this.cal_header();
	vData_Code = this.cal_data();
	vCode = vCode + vHeader_Code + vData_Code;
	
	vCode = vCode + "</TABLE>";
	return vCode;
}

Calendar.prototype.show = function() {
	var vCode = "";
	
	this.gWinCalDocument.open();

	// Setup the page...
	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("<link rel=\"stylesheet\" href=\"/shared/packyourbags_calendar-styles.css\" type=\"text/css\">");
	this.wwrite("</head>");

	this.wwrite("<body " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\" bgcolor='#FFFFFF'>");

	this.wwrite("<table cellpadding=0 cellspacing=0 border=0 width='100%' height='100%'>" + 
		"<tr>" +
		"	<td colspan=3 bgcolor='#95BDFF'><img src='images/box/box_r2_c1.gif' width='180' height='1' border='0' alt=' Choose a date '></td>" +
		"</tr>" +
		"<tr>" +
		"	<td bgcolor='#95BDFF'><img name='box_r2_c1' src='images/box/box_r2_c1.gif' width='1' height='1' border='0' alt=''></td>" +
		"	<td align=center valign=top>");
	
	this.wwrite("<TABLE WIDTH='100%' BORDER=0 CELLSPACING='1' CELLPADDING= BGCOLOR='#FFFFFF'><TR HEIGHT='19'><TD ALIGN=center colspan='3' bgcolor='#999999'>");
/*
	if(this.gYear==2006)
		this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
			");" +
			"\" style='color:#7987FF'>2005<\/A>");
		//</TD></tr><tr><TD ALIGN=center>

	if(this.gYear==2005)
		this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
			");" +
			"\" style='color:#7987FF'>2006<\/A>");

	this.wwrite("</TD></tr><tr><TD ALIGN=center>");
*/
	// 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("<div align=center nowrap><A HREF=\"" +
		"javascript:window.parent.Build(" + 
		"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\" style=\"font-size:12px;text-decoration: none;color:#FFFFFF;\">&#9668; <\/A></a></TD><TD width=\"130\" bgcolor='#999999'>");


	this.wwriteA("<center><FONT FACE='" + fontface + "'><B>");     // SIZE=2
	this.wwriteA("<span style=\"font-size:11px;color:#FFFFFF;\">"+this.gMonthName + " " + this.gYear + "</span>");
	this.wwriteA("</B></center>");

//prevYYYY
//this.gYear

/*	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 00 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">J<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 01 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">F<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 02 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">M<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 03 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">A<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 04 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">M<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 05 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">J<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 06 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">J<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 07 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">A<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 08 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">S<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 09 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">O<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 10 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">N<\/A> ");
	this.wwrite("<A HREF=\"" +
			"javascript:window.parent.Build(" + 
			"'" + this.gReturnItem + "', '" + 11 + "', '" + this.gYear + "', '" + this.gFormat + "'" +
			");" +
			"\" style=\"font-size:12px;\">D<\/A> ");

*/	this.wwrite("</td><td align=center nowrap bgcolor='#999999'><A HREF=\"" +
		"javascript:window.parent.Build(" + 
		"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\" style=\"font-size:12px;text-decoration: none;color:#FFFFFF;\"> &#9658;<\/A>");

	this.wwrite("</TD></TR></TABLE><BR>");

	// Get the complete calendar code for the month..

	vCode = this.getMonthlyCalendarCode();

	this.wwrite(vCode);
// return;
	this.wwrite("</font></td>" + 				
		"	<td bgcolor='#95BDFF'><img name='box_r2_c3' src='images/box/box_r2_c1.gif' width='1' height='1' border='0' alt=''></td>" +
		"</tr>" +
		"<tr>" +
		"	<td colspan='2' bgcolor='#95BDFF'><img name='box_r3_c1' src='images/box/box_r3_c1.gif' width='10' height='1' border='0' alt=''></td>" +
		"	<td><img name='box_r3_c3' src='images/box/box_r3_c3.gif' width='1' height='1' border='0' alt=''></td>" +
		"</tr>" +
		"</table>" +
		"</body></html>");

	this.gWinCalDocument.close();
}


Calendar.prototype.showY = function() {
	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 = 10;			// X-margin
	var vym;				// Y-margin
	if (isIE)	vym = 75;
	else if (isNav)	vym = 25;
	
	this.gWinCalDocument.open();

	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("<style type='text/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 " + 
		"link=\"" + this.gLinkColor + "\" " + 
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwrite("<FONT FACE='" + fontface + "'><B>");    // SIZE=2
	this.wwrite("Year : " + this.gYear);
	this.wwrite("</B><BR>");

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;
	
	this.wwrite("<TABLE WIDTH='100%' BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#FFFFFF'><TR><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.parent.Build(" + 
		"'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
	
	this.wwrite("[<A HREF=\"" +
		"javascript:window.parent.Build(" + 
		"'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
		");" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");

	// 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();
		this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
		this.wwrite(vCode);

		if (isIE)
			this.wwrite("</DIV>");
		else if (isNav)
			this.wwrite("</LAYER>");
	}

	this.wwrite("</font></body></html>");
	this.gWinCalDocument.close();
}

Calendar.prototype.wwrite = function(wtext) {
	this.gWinCalDocument.writeln(wtext);
}

Calendar.prototype.wwriteA = function(wtext) {
	this.gWinCalDocument.write(wtext);
}

Calendar.prototype.cal_header = function() {
	var vCode = "";
	
	vCode = vCode + "<TR>";
	vCode = vCode + "<TD WIDTH='14%' align=center><B>Sun</B></TD>";
	vCode = vCode + "<TD WIDTH='14%' align=center><B>Mon</B></TD>";
	vCode = vCode + "<TD WIDTH='14%' align=center><B>Tue</B></TD>";
	vCode = vCode + "<TD WIDTH='14%' align=center><B>Wed</B></TD>";
	vCode = vCode + "<TD WIDTH='14%' align=center><B>Thu</B></TD>";
	vCode = vCode + "<TD WIDTH='14%' align=center><B>Fri</B></TD>";
	vCode = vCode + "<TD WIDTH='16%' align=center><B>Sat</B></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 vNowDay = gNow.getDate();
	var vNowMonth = gNow.getMonth();
	var vNowYear = gNow.getFullYear();

	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%'" + this.write_weekend_string(i) + " align=center><FONT FACE='" + fontface + "'> </FONT></TD>";  //SIZE='2' 
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {
/*
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + " align=center><FONT FACE='" + fontface + "'>" +   // SIZE='2'
			"<u " + 
				"onClick=\"window.parent.document." + this.gReturnItem + ".value=" + 
				this.format_data(vDay) + 
				";window.close();\" style='cursor:pointer;'>" + 
				this.format_day(vDay) + 
			"</u>" + 
			"</FONT></TD>";
*/
//(vNowDay+3)
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + " align=center><FONT FACE='" + fontface + "'>";
		if ((vDay >= vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear) || (this.gMonth > vNowMonth && this.gYear >= vNowYear) || (this.gYear > vNowYear)) {
			vCode = vCode + "<u " + 
				"onClick=\"window.parent.document.getElementById('" + this.gReturnItem + "').value='" + 
				this.format_data(vDay) + 
				"\/"+(((this.gMonth+1).toString().length < 2) ? "0" + (this.gMonth+1) : (this.gMonth+1))+"\/"+this.gYear+"';";
			if(isFlight) { 
				vCode = vCode + "if (window.parent.CheckFlightSearchDateFields(true,"+(this.gReturnItem=='CTTPage_PageContent_FlightMainSearch_FlightDateDeparture' || this.gReturnItem=='FlightDateDeparture' ? 'true' : 'false')+")) { window.parent.document.getElementById('" + this.gCloseItem + "').style.visibility = 'hidden'; }\"";
			} else {
				vCode = vCode + "window.parent.document.getElementById('" + this.gCloseItem + "').style.visibility = 'hidden';\"";
			}
			vCode = vCode + " style='cursor:pointer;'>" + 
				this.format_day(vDay) + 
			"</u>";
		} else {
			vCode = vCode + this.format_day(vDay);
		}
		vCode = vCode + "</FONT></TD>";

		vDay=vDay + 1;
		//format_data
	}
	vCode = vCode + "</TR>";

	// Write the rest of the weeks
	for (k=2; k<7; k++) {
		vCode = vCode + "<TR>";

		for (j=0; j<7; j++) {  //SIZE='2' 
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + " align=center><FONT FACE='" + fontface + "'>";
//(vNowDay+3)
			if ((vDay >= vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear) || (this.gMonth > vNowMonth && this.gYear >= vNowYear) || (this.gYear > vNowYear)) {
				vCode = vCode + "<u " + 
					"onClick=\"window.parent.document.getElementById('" + this.gReturnItem + "').value='" + 
					this.format_data(vDay) + 
					"\/"+(((this.gMonth+1).toString().length < 2) ? "0" + (this.gMonth+1) : (this.gMonth+1))+"\/"+this.gYear+"';";
			if(isFlight) { 
				vCode = vCode + "if (window.parent.CheckFlightSearchDateFields(true,"+(this.gReturnItem=='CTTPage_PageContent_FlightMainSearch_FlightDateDeparture' || this.gReturnItem=='FlightDateDeparture' ? 'true' : 'false')+")) { window.parent.document.getElementById('" + this.gCloseItem + "').style.visibility = 'hidden'; }\"";
			} else {
				vCode = vCode + "window.parent.document.getElementById('" + this.gCloseItem + "').style.visibility = 'hidden';\"";
			}
			vCode = vCode + "style='cursor:pointer;'>" + 
					this.format_day(vDay) + 
				"</u>";

//(vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
//(this.gMonth+1)
//(((this.gMonth+1).toString().length < 2) ? "0" + (this.gMonth+1) : (this.gMonth+1))

			} else {
				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;
	}
//return vCode;
	// 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 WIDTH='14%'" + this.write_weekend_string(j+m) + 
			" align=center><FONT FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";    //SIZE='2' 
		else
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) + 
			" align=center><FONT FACE='" + fontface + "' COLOR='gray'><!--" + m + "--></FONT></TD>";   //SIZE='2' 
	}
	
	return vCode;
}

Calendar.prototype.format_day = function(vday) {
	var vNowDay = gNow.getDate();
	var vNowMonth = gNow.getMonth();
	var vNowYear = gNow.getFullYear();

	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear) {
		return ("<FONT COLOR=\"GREEN\"><B><STRIKE>" + vday + "</STRIKE></B></FONT>");
	} else {
//(vNowDay+3)
		if ((vday >= vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear) || (this.gMonth > vNowMonth && this.gYear >= vNowYear) || (this.gYear > vNowYear)) {
			return (vday);
/*
			return ("<u " + 
					"onClick=\"window.parent.document." + this.gReturnItem + ".value='" + vday + "\/" + 

this.gMonth + "\/" + this.gYear + "';window.close();\" style='cursor:pointer;'>" + vday + "</u>");
*/

		} else { return ("<strike>"+vday+"</strike>"); }
	}
/*
	if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
		return ("<FONT COLOR=\"GREEN\"><B><STRIKE>" + vday + "</STRIKE></B></FONT>");
	else
		if 	if (vday >= (vNowDay+3) && this.gMonth >= vNowMonth && this.gYear >= vNowYear) {
			return ("<u " + 
					"onClick=\"window.parent.document." + this.gReturnItem + ".value='" + vday + "/" + this.gMonth + "/" + this.gYear + "';window.close();\" style='cursor:pointer;'>" + vday + "</u>");
		else { return ("<strike>"+vday+"</strike>"); }
*/
/*
				"<u " + 
					"onClick=\"window.parent.document." + this.gReturnItem + ".value=" + 
					this.format_data(vDay) + 
					";window.close();\" style='cursor:pointer;'>" + 
				this.format_day(vDay) + 
				"</u>" + 
*/
}

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).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;
	}

	switch (vMonth) {
		case "01" : vMonth="1"; break;
		case "02" : vMonth="2"; break;
		case "03" : vMonth="3"; break;
		case "04" : vMonth="4"; break;
		case "05" : vMonth="5"; break;
		case "06" : vMonth="6"; break;
		case "07" : vMonth="7"; break;
		case "08" : vMonth="8"; break;
		case "09" : vMonth="9"; break;
	}
	if (vMonth=="10") 
		vMonth="10";
	if (vMonth=="11") 
		vMonth="11";
	if (vMonth=="12") 
		vMonth="12";

	//if (p_item == "CTTPage_PageContent_MainSearch_Day")
//	window.document.getElementById(objMonth).value=vMonth;
	
	//if (p_item == "selectForm.Day")
//	window.document.getElementById(objYear).value=vY4;
	
	//if (p_item == "selectForm.Day2")
	//window.document.selectForm.Month2.value=vMonth;
	
	//if (p_item == "selectForm.Day2")
	//window.document.selectForm.Year2.value=vY4;
	


	//window.document.getElementById(this.gReturnItem).value=vData;
	return vDD;
}

function Build(p_item, p_month, p_year, p_format) {
	var p_WinCal = ggWinCal;
	gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

	// Customize your Calendar here..
	gCal.gBGColor="white";
	gCal.gLinkColor="black";
	gCal.gTextColor="black";
	gCal.gHeaderColor="darkgreen";

	// Choose appropriate show function

	if (gCal.gYearly) { gCal.showY(); }
	else { gCal.show(); }
}


function show_calendar_CTT() {
//		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.

//return;
	objInputField=arguments[0];
	gCloseItem=arguments[1];
	isFlight=(arguments[2] == true ? true : false );

	var initialValue = new String(window.document.getElementById(objInputField).value);
	
	var fMonth=initialValue.substring(3,5);
	var fyear=initialValue.substring(6);
//alert("Month="+fMonth+",Year="+fyear);
	
//	objDay=arguments[0];
//	objMonth=arguments[1];
//	objYear=arguments[2];
	
//alert(objDay+","+objMonth+","+objYear);
	//return true;
	//p_item = window.document.getElementById("CTTPage_PageContent_MainSearch_Day").value; //arguments[0];
	//p_item = "__aspnetForm."+objDay; //arguments[0];
//p_item = "__aspnetForm."+objInputField;
p_item = objInputField;
//	var fmonth
//	var fyear
		//if (p_item == "CTTPage_PageContent_MainSearch_Day")
//	fMonth=window.document.getElementById(objMonth).value;
		//if (p_item == "selectForm.Day2")
		//fMonth=window.document.selectForm.Month2.value;
	
	switch (fMonth) {
		case "01" : fMonth=00; break;
		case "02" : fMonth=01; break;
		case "03" : fMonth=02; break;
		case "04" : fMonth=03; break;
		case "05" : fMonth=04; break;
		case "06" : fMonth=05; break;
		case "07" : fMonth=06; break;
		case "08" : fMonth=07; break;
		case "09" : fMonth=08; break;
		case "10" : fMonth=09; break;
		case "11" : fMonth=10; break;
		case "12" : fMonth=11; break;
	}

		//if (p_item == "selectForm.Day")
//	fyear=window.document.getElementById(objYear).value;
		//if (p_item == "selectForm.Day2")
		//fyear=window.document.selectForm.Year2.value;	
		
	p_month = new String(fMonth);
	p_year = new String(fyear);
	p_format = "DD/MM/YYYY";


//		if (arguments[1] == null)
//			p_month = new String(fMonth);
//		else
//			p_month = arguments[1];
//		if (arguments[2] == "" || arguments[2] == null)
//			p_year = new String(fyear);
//		else
//			p_year = arguments[2];
//		if (arguments[3] == null)
//			p_format = "MM/DD/YYYY";
//		else
//			p_format = arguments[3];

//	vWinCal = window.open("", "Calendar", 
//			"width=200,height=230,status=no,resizable=no,top=200,left=200");

	MoveCalendar();

	if (document.getElementById("packyourbags_calendar_container").style.visibility == "visible") {
		document.getElementById("packyourbags_calendar_container").style.visibility = "hidden";
	} else { 
		//vWinCal = document.frames["Packyourbags_Calendar_iframe"];
		vWinCal = (isIE ? document.frames["Packyourbags_Calendar_iframe"] : document.getElementById("Packyourbags_Calendar_iframe"));

		//vWinCal = document.getElementById("Packyourbags_Calendar_iframe");
		document.getElementById("packyourbags_calendar_container").style.visibility = "visible";
			//	document.getElementById("packyourbags_calendar_container").style.display = "block";
	
			//document.frames["Packyourbags_Calendar_iframe"].document.write("<B>hello world</b>");
	
		vWinCal.opener = document.getElementById("Packyourbags_Calendar_iframe"); //window;
		ggWinCal = vWinCal;

//alert(p_month+","+p_year);
		Build(p_item, p_month, p_year, p_format);
	}
//	this.gWinCalDocument = (isIE || isNav ? this.gWinCal.document : this.gWinCal.currentDocument );
}


/*
Yearly Calendar Code Starts here
*/
function show_yearly_calendar(p_item, p_year, p_format) {
	// Load the defaults..
	if (p_year == null || p_year == "")
		p_year = new String(gNow.getFullYear().toString());
	if (p_format == null || p_format == "")
		p_format = "DD/MM/YYYY";

	var vWinCal = window.open("", "Calendar", "scrollbars=yes");
	vWinCal.parent = self;
	ggWinCal = vWinCal;

	Build(p_item, null, p_year, p_format);
}



// CUSTOM
function MoveCalendar() {
	if (document.getElementById("packyourbags_calendar_container") == null) return;
	var myWidth = 0, myHeight = 0, varNewLeft = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
//	screenObject = window.screen;
	containerObject = document.getElementById("packyourbags_calendar_container");
	varNewLeft = (myWidth / 2) - PYB_OffsetLeft;
	if (varNewLeft < PYB_Left) { varNewLeft = PYB_Left; }
	containerObject.style.top = PYB_Top;
	containerObject.style.left = varNewLeft;
}

function SetDefaults(MinTop,MinLeft,OffsetLeft) {
	PYB_Top=MinTop;
	PYB_Left=MinLeft;
	PYB_OffsetLeft=OffsetLeft;
}

function CheckFlightSearchDateFields(showMsg,isDepartureDate) { 
//	if (isDepartureDate == true || isDepartureDate == 'true') { return true; } 
//alert(isDepartureDate);
	var fromDay,fromMonth,fromYear,toDay,toMonth,toYear; 
//	var fromDate=document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateDeparture').value;
//	var toDate=document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateArrival').value;
	var fromDate;
	if(document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateDeparture')){fromDate=document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateDeparture').value}else{fromDate=document.getElementById('FlightDateDeparture').value;}
	var toDate;
	if(document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateArrival')){toDate=document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateArrival').value}else{toDate=document.getElementById('FlightDateArrival').value; }
	var isFailure=false; 
	fromDay=fromDate.substring(0,2); 
	fromMonth=fromDate.substring(3,5); 
	fromYear=fromDate.substring(6); 
	toDay=toDate.substring(0,2); 
	toMonth=toDate.substring(3,5); 
	toYear=toDate.substring(6); 
	if(toYear<fromYear){isFailure=true;}
	//.replace(/0/,'')
	if(!isFailure && parseInt(StripN(toMonth))<parseInt(StripN(fromMonth)) && toYear <= fromYear){isFailure=true;}
//	if(!isFailure && ((((toDay.replace(/0/,'') < fromDay.replace(/0/,'') && toMonth.replace(/0/,'') <= fromMonth.replace(/0/,'')) || toMonth.replace(/0/,'') <= fromMonth.replace(/0/,'')) && toYear <= fromYear))){alert('3');isFailure=true;} 

	if(!isFailure && ((((parseInt(StripN(toDay))<parseInt(StripN(fromDay)) && parseInt(StripN(toMonth)) <= parseInt(StripN(fromMonth)))) && toYear <= fromYear))){isFailure=true;} 

	if(!isFailure && isDepartureDate && ((parseInt(StripN(toDay))+7)>parseInt(StripN(fromDay)))){isFailure=true;}
	if(!isFailure && isDepartureDate && (((parseInt(StripN(fromDay))+7)-parseInt(Calendar.get_daysofmonth(parseInt(StripN(fromMonth))-1,fromYear)))>parseInt(StripN(toDay)) && (parseInt(StripN(toMonth))>parseInt(StripN(fromMonth))))){isFailure=true;}

// || (parseInt(toDay.replace(/0/,'')) < (parseInt(fromDay.replace(/0/,''))+7) && toMonth.replace(/0/,'') <= fromMonth.replace(/0/,'') && toYear <= fromYear)
//	if (isFailure) { if (showMsg) { alert('Please correct the return date as it must not be before the departure date.'); } return false; } else { return true; } 
	if(isFailure){
//alert('failure detected');
//We have corrected the return date for you.  Please change it if required.
		//if (showMsg) { alert('You have selected a date prior to the departure date.  Please amend.'); } 
		if(isDepartureDate != true && isDepartureDate != 'true'){
			if((toYear<fromYear) || (parseInt(StripN(toMonth))<parseInt(StripN(fromMonth)) && toYear <= fromYear) || (parseInt(StripN(toDay))<parseInt(StripN(fromDay)) && parseInt(StripN(toMonth))==parseInt(StripN(fromMonth)) && toYear <= fromYear)){
//alert('to:'+StripN(toMonth)+'|from:'+StripN(fromMonth)+' and toYear:'+toYear+'|fromYear:'+fromYear);
				if(showMsg){alert('You have selected a date prior to the departure date.  Please amend.');}
				return false;
			}
		}
//alert('vLastDay='+fromMonth+','+fromYear);
		var vLastDay=parseInt(Calendar.get_daysofmonth(parseInt(StripN(fromMonth))-1,fromYear));
//alert('vLastDay='+vLastDay);
//alert('DayDiff='+(parseInt(toDay.replace(/0/,''))-parseInt(fromDay.replace(/0/,''))));
//alert('Month compare='+(parseInt(fromMonth.replace(/0/,''))==parseInt(toMonth.replace(/0/,''))));
		fromDay2=fromDay;
		fromDay=(fromDay<10?parseInt(StripN(fromDay)):parseInt(fromDay));
		if((vLastDay>=parseInt(fromDay+7)) || (((parseInt(StripN(toDay))-parseInt(StripN(fromDay2)))<7) && (parseInt(StripN(fromMonth))==parseInt(StripN(toMonth))))){
			fromDay=(parseInt(fromDay+7)<10?'0'+parseInt(fromDay+7):parseInt(fromDay+7));
			vLastDay=parseInt(Calendar.get_daysofmonth(parseInt(StripN(fromMonth))-1,fromYear));
			if(vLastDay<parseInt(fromDay) && parseInt(fromDay) != 0){
				fromDay=fromDay-vLastDay;
				fromDay=(fromDay<10?'0'+fromDay:fromDay);
				fromMonth=(fromMonth<10?parseInt(StripN(fromMonth))+1:parseInt(fromMonth)+1);
				if(fromMonth>12){fromMonth=1;fromYear++;}
				fromMonth=(fromMonth<10?'0'+fromMonth:fromMonth);
			}
		} else {
			fromMonth=(fromMonth<10?parseInt(StripN(fromMonth))+1:parseInt(fromMonth)+1);
			if(parseInt(fromDay + 7)==vLastDay){fDay=vLastDay;}else{fDay=parseInt(fromDay+7)-vLastDay;}
			if(fromMonth>12){fromMonth=1;fromYear++;}
			if(fDay==0){fDay=1;} //fDay=vLastDay;fromMonth--;}
//			fromDay = ((parseInt(fromDay + 7) - vLastDay) < 10 ? '0'+(parseInt(fromDay + 7) - vLastDay) : parseInt(fromDay + 7) - vLastDay);
			fromDay=(fDay<10?'0'+fDay:fDay);
			fromMonth=(parseInt(fromMonth)<10?'0'+parseInt(fromMonth):parseInt(fromMonth));
//alert(fromDay+'/'+fromMonth+'/'+fromYear);
		}
		if(document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateArrival')){
			document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateArrival').value=fromDay+'/'+fromMonth+'/'+fromYear;
		}else{document.getElementById('FlightDateArrival').value=fromDay+'/'+fromMonth+'/'+fromYear;}
		//document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateDeparture').value;
		if(isDepartureDate != true && isDepartureDate != 'true'){
			//if(showMsg){alert('You have selected a date prior to the departure date.  Please amend.');}
			return true; //return false;
		}else{return true;}
	}else{return true;}
} 
function StripN(n){
	n=new String(n);
	if(n.substr(0,1)=='0'){return n.substr(1,1);}else{return n;}
}
function UpdateFlightReturnDateFields() { 
	if(!CheckFlightSearchDateFields(false,false)){
		if(document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateArrival')){
			document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateArrival').value=document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateDeparture').value;
		}else{
			document.getElementById('FlightDateArrival').value=document.getElementById('FlightDateDeparture').value;
		}
	} 
}
function FlightType(blnReturnFlight) {
	if(document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateArrival')){
		if(blnReturnFlight){
			document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateArrival').disabled=false;
		}else{
			document.getElementById('CTTPage_PageContent_FlightMainSearch_FlightDateArrival').disabled=true;
		}
	}else{if(blnReturnFlight){document.getElementById('FlightDateArrival').disabled=false;}else{document.getElementById('FlightDateArrival').disabled=true;}}
}