// Bespoke version of the date picker.
// Bespoke changes Copyright © 2005-2006, CTT Group Ltd.  All Rights Reserved.
function xCal_fO(s){return document.getElementById(s);}

// CUSTOM
var PYB_Top=0,PYB_Left=0,PYB_OffsetLeft=0;
var tblWidth='100%',tblHeight='100%';
var isFlight=true;
var PTR='';

var objInputField,gCloseItem;
var eHeight=20;

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) {
	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;
			var cDate2=new Date();if(ret_arr[1]<cDate2.getFullYear()){ret_arr[1]=cDate2.getFullYear();}
		}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;
			var cDate=new Date();if(ret_arr[1]>cDate.getFullYear()+1){ret_arr[1]-=2;}
		}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;
			var cDate2=new Date();if(ret_arr[1]<cDate2.getFullYear()){ret_arr[1]=cDate2.getFullYear();}
		}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;
			var cDate=new Date();if(ret_arr[1]>cDate.getFullYear()+1){ret_arr[1]-=2;}
		}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='"+PTR+"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='"+PTR+"images/box/box_r2_c1.gif' width='180' height='1' alt=' Choose a date ' /></td></tr>" +
		"<tr>" +
			"<td bgcolor='#95BDFF'><img src='"+PTR+"images/box/box_r2_c1.gif' width='1' height='1' /></td>" +
			"<td align='center' valign='top'>");
	
	this.wwrite("<table width='100%' border='0' cellspacing='1' cellpadding='0' bgcolor='#FFFFFF'><tr height='19'><td align='center' colspan='3' bgcolor='#999999'>");

	// 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='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><span style='font-size:11px;color:#FFFFFF;'>"+this.gMonthName+" "+this.gYear+"</span></b></center>");
	this.wwrite("</td><td align='center' nowrap='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+"</font></td><td bgcolor='#95BDFF'><img src='"+PTR+"images/box/box_r2_c1.gif' width='1' height='1' /></td>" +
		"</tr>" +
		"<tr>" +
			"<td colspan='2' bgcolor='#95BDFF'><img src='"+PTR+"images/box/box_r3_c1.gif' width='10' height='1' /></td>" +
			"<td><img src='"+PTR+"images/box/box_r3_c3.gif' width='1' height='1' /></td>" +
		"</tr></table></body></html>");

	this.gWinCalDocument.close();
}

Calendar.prototype.showIE=function() { //dumps the new HTML into the nominated container object.
	var vCode='',sBody='';
	sBody="<table cellpadding='0' cellspacing='0' border='0' width='"+tblWidth+"' height='"+tblHeight+"' style='position:absolute;top:0;left:0;z-Index:300;' bgcolor='#FFFFFF'>" + 
		"<tr><td colspan='3' bgcolor='#95BDFF'><img src='"+PTR+"images/box/box_r2_c1.gif' width='180' height='1' alt=' Choose a date ' /></td></tr>" +
		"<tr>" +
			"<td bgcolor='#95BDFF'><img src='"+PTR+"images/box/box_r2_c1.gif' width='1' height='1' /></td>" +
			"<td align='center' valign='top'>" + 
			"<table width='100%' border='0' cellspacing='1' bgcolor='#FFFFFF'><tr height='19'><td align='center' bgcolor='#999999'>";
	// 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];

	sBody+="<div align='center' nowrap='nowrap'><a href=\"" +
		"javascript:window.parent.Build('"+this.gReturnItem+"','"+prevMM+"','"+prevYYYY+"','"+this.gFormat+"');" +
		"\" style='font-size:12px;text-decoration:none;color:#FFFFFF;'>&#9668; </a></td><td width='130' bgcolor='#999999'>" + 
		"<center><font face='"+fontface+"'><b>" + 
		"<span style=\"font-size:11px;color:#FFFFFF;\">"+this.gMonthName+" "+this.gYear+"</span>" + 
		"</b></center>" + 
		"</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>" + 
		"</td></tr></table><br>";
	vCode=this.getMonthlyCalendarCode(); // Get the complete calendar code for the month..
	sBody+=vCode+"</font></td>" + 				
			"<td bgcolor='#95BDFF'><img src='"+PTR+"images/box/box_r2_c1.gif' width='1' height='1' /></td>" +
		"</tr>" +
		"<tr>" +
			"<td colspan='2' bgcolor='#95BDFF'><img src='"+PTR+"images/box/box_r3_c1.gif' width='10' height='1' border='0' /></td>" +
			"<td><img src='"+PTR+"images/box/box_r3_c3.gif' width='1' height='1' border='0' /></td>" +
		"</tr>" +
		"</table>";
	if(isIE){document.frames("Packyourbags_Calendar_iframe").document.getElementById('xCal').innerHTML=sBody;}
	else{document.getElementById("Packyourbags_Calendar_iframe").contentDocument.write(sBody);}
}

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>" + 
		"<head><title>Calendar</title>" + 
		"<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>Year : "+this.gYear+"</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+="<tr>" + 
			"<td width='14%' align='center'><b>Sun</b></td>" + 
			"<td width='14%' align='center'><b>Mon</b></td>" + 
			"<td width='14%' align='center'><b>Tue</b></td>" + 
			"<td width='14%' align='center'><b>Wed</b></td>" + 
			"<td width='14%' align='center'><b>Thu</b></td>" + 
			"<td width='14%' align='center'><b>Fri</b></td>" + 
			"<td width='16%' align='center'><b>Sat</b></td>" + 
		"</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>";}
	// 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+"'>";
		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=='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;
	}
	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%'"+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=='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+"</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 width='14%'"+this.write_weekend_string(j+m)+" align='center'><font face='"+fontface+"' color='gray'> </font></td>";
		}else{vCode=vCode+"<td width='14%'"+this.write_weekend_string(j+m)+" align='center'><font face='"+fontface+"' color='gray'><!--"+m+"--></font></td>";}
	}
	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{
		if((vday>=vNowDay && this.gMonth==vNowMonth && this.gYear==vNowYear) || (this.gMonth>vNowMonth && this.gYear>=vNowYear) || (this.gYear>vNowYear)){
			return (vday);
		}else{return ("<strike>"+vday+"</strike>");}
	}
}
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";}
	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{if(isIE){gCal.showIE();}else{gCal.showIE();}}
}
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.
	objInputField=arguments[0];
	gCloseItem=arguments[1];
	isFlight=(arguments[2]==true?true:false);
	PTR=arguments[3];

	var initialValue=new String(window.document.getElementById(objInputField).value);
	var fMonth=initialValue.substring(3,5);
	var fyear=initialValue.substring(6);
	p_item=objInputField;
	
	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;
	}
	p_month=new String(fMonth);
	p_year=new String(fyear);
	p_format="DD/MM/YYYY";
	if(isIE){document.frames["Packyourbags_Calendar_iframe"].document.write("<html><head><link rel='stylesheet' href='"+PTR+"shared/packyourbags_calendar-styles.css' type='text/css'></head><body><span id='xCal'></span></body></html>");
	}else{document.getElementById("Packyourbags_Calendar_iframe").contentDocument.write("<html><head><link rel='stylesheet' href='"+PTR+"shared/packyourbags_calendar-styles.css' type='text/css'></head><body><span id='xCal'></span></body></html>");}

	if (document.getElementById("packyourbags_calendar_container").style.visibility=="visible"){
		document.getElementById("packyourbags_calendar_container").style.visibility="hidden";
	}else{ 
		vWinCal=(isIE?document.frames["Packyourbags_Calendar_iframe"]:document.getElementById("Packyourbags_Calendar_iframe"));
		document.getElementById("packyourbags_calendar_container").style.visibility="visible";
		vWinCal.opener=document.getElementById("Packyourbags_Calendar_iframe");
		ggWinCal=vWinCal;
		Build(p_item,p_month,p_year,p_format);
	}
}
/*
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;
	}
	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(document.getElementById('FlightDateArrival'))
{ 
	var fromDay,fromMonth,fromYear,toDay,toMonth,toYear; 
	var fromDate;
	if(document.getElementById('FlightDateDeparture')){fromDate=document.getElementById('FlightDateDeparture').value}else{fromDate=document.getElementById('FlightDateDeparture').value;}
	var toDate;
	if(document.getElementById('FlightDateArrival')){toDate=document.getElementById('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;}
	if(!isFailure && parseInt(StripN(toMonth))<parseInt(StripN(fromMonth)) && toYear <= fromYear){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;}
	if(isFailure){
		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)){
				if(showMsg){alert('You have selected a date prior to the departure date. Please amend.');}
				return false;
			}
		}
		var vLastDay=parseInt(Calendar.get_daysofmonth(parseInt(StripN(fromMonth))-1,fromYear));
		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=(fDay<10?'0'+fDay:fDay);
			fromMonth=(parseInt(fromMonth)<10?'0'+parseInt(fromMonth):parseInt(fromMonth));
		}
		if(document.getElementById('FlightDateArrival')){
			document.getElementById('FlightDateArrival').value=fromDay+'/'+fromMonth+'/'+fromYear;
		}else{document.getElementById('FlightDateArrival').value=fromDay+'/'+fromMonth+'/'+fromYear;}
		if(isDepartureDate != true && isDepartureDate != 'true'){return true;}else{return true;}
	}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('FlightDateArrival')){
			document.getElementById('FlightDateArrival').value=document.getElementById('FlightDateDeparture').value;
		}else{document.getElementById('FlightDateArrival').value=document.getElementById('FlightDateDeparture').value;}
	} 
}
function FlightType(blnReturnFlight) {
	if(document.getElementById('FlightDateArrival')){
		if(blnReturnFlight){document.getElementById('FlightDateArrival').disabled=false;
		}else{document.getElementById('FlightDateArrival').disabled=true;}
	}else{if(blnReturnFlight){document.getElementById('FlightDateArrival').disabled=false;}else{document.getElementById('FlightDateArrival').disabled=true;}}
}
// Added 25/09/2006
function Repos(){
	if(!gO(objInputField)){return false;}
	if(!gO(gCloseItem)){return false;}
	var co=findPos(gO(objInputField));
	gO(gCloseItem).style.left=co[0];
	gO(gCloseItem).style.top=co[1]+eHeight;
}
function findPos(o){
	var cl=ct=0;
	if(o.offsetParent){cl=o.offsetLeft;ct=o.offsetTop;while(o=o.offsetParent){cl+=o.offsetLeft;ct+=o.offsetTop;}}
	return [cl,ct];
}
function setPos(obj,cObj){var co=findPos(obj);SetDefaults(co[1]+eHeight,co[0],(co[0]-GetCentre())*-1);}
function setPosition(obj,cObj){
	eHeight=getElementHeight(obj);
	var co=findPos(obj);
	cObj.style.left=co[0];cObj.style.top=(co[1]+eHeight);
}
function GetCentre(){
	if(typeof(window.innerWidth)=='number'){return (window.innerWidth/2); //Non-IE
	}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){ //IE 6+ in 'standards compliant mode'
		return (document.documentElement.clientWidth/2);
	}else if(document.body && (document.body.clientWidth || document.body.clientHeight)){return (document.body.clientWidth/2);} //IE 4 compatible
}