var arrMonth = ["01 -", "02 -", "03 -", "04 -", "05 -", "06 -", "07 -", "08 -", "09 -", "10 -", "11 -", "12 -"];
var g_intDay, g_strMonthYear;

var winWidth = window.innerWidth;
winWidth=(winWidth/2)-125
var ie=false;
if (document.all)
{
	ie=true;
}
var n6=(navigator.appName=="Netscape" && navigator.appVersion.substring(0,1)>="5") 

function Load()
{
if (ie || n6)
	f1 = document.frmHome;
else
	f1 = document.layers["L1"].document.frmHome;
f1.CD1.focus();
}

function swapDisplay()
{
	if (n6) 
	{
		document.getElementsByName("MP")[0].style.display="none";
		document.getElementsByName("SP")[0].style.display="block";
	}
	else if (ie)
	{
		document.all.MP.style.display="none";
		document.all.SP.style.display="block";
	}
	else 
	{
		document.layers["L3"].visibility = "show";
		document.layers["L1"].visibility = "hide";
	}
}

function CheckForm()
{
	if (!CheckDate())
		return false;
	else if (!IsDepDestValid())
		return false;

	return true;
}


function IsDepDestValid()
{
var strDep, strDest;
strDep = document.frmHome.CD1.value;
strDest = document.frmHome.CA1.value;

if (strDep.length < 3)
{
	alert("Please choose a departure airport");
	return false;
}
if (strDest.length < 3)
{
	alert("Please choose a destination airport");
	return false;	
}
return true;
}
function submithotell(){
	document.resrvForm.submit();
}
function SubmitIt()
{
if (CheckForm())
	{
	document.frmHome.submit();
	swapDisplay();
	}
}

function CheckDate()
{
var strDepartDay=document.frmHome.DD1[document.frmHome.DD1.selectedIndex].value;
var strReturnDay=document.frmHome.DD2[document.frmHome.DD2.selectedIndex].value;
var strDepartDate=document.frmHome.MD1[document.frmHome.MD1.selectedIndex].value;
var strReturnDate=document.frmHome.MD2[document.frmHome.MD2.selectedIndex].value;

if (IsReturnDateAfterDepartureDate(strDepartDay, strReturnDay,  strDepartDate, strReturnDate)!=1 )
{
	alert("Return Date MUST BE AFTER Departure Date");
	return false;
}
return true;
}

function IsReturnDateAfterDepartureDate(vD1,vD2,vM1,vM2)
{
var m1,y1,m2,y2;

if (vM1.substr(0,1) == "0")
	m1=parseInt(vM1.substr(1,1));
else
	m1=parseInt(vM1.substr(0,2));

y1=parseInt(vM1.substr(2,4));

if (vM2.substr(0,1) == "0")
	m2=parseInt(vM2.substr(1,1));
else
	m2=parseInt(vM2.substr(0,2));

y2=parseInt(vM2.substr(2,4));
vD1=parseInt(vD1);vD2=parseInt(vD2);

if (y1>y2)
	return 0;
else if (y1==y2)
{
	if (m1>m2)
		return 0;
	else if ((m1==m2) && (vD1>=vD2))
		return 0;
}
return 1;
}

function GenerateDayList(strID, intDaysOffset)
{

	GenerateBookDate(intDaysOffset);

	document.write('<select name="' + strID + '" onSubmit="CheckDate()">');
	
	var intCount;
	for(intCount=1; intCount <= 31; intCount++)
	{
		document.write('<option value="' + intCount + '"');
		if (g_intDay == intCount)
			document.write(' selected');
		document.write('>' + intCount + '</option>');
	}
	
	document.write('</select> ');
}

function GenerateMonthList(strID, intDaysOffset)
{

	document.write('<select name="' + strID + '" onSubmit="CheckDate()">');
	GenerateBookDate(intDaysOffset);
	var dateCurrent = new Date();
	dateCurrent.setDate(1);
	var intCount, strCurMonthYear, strMonthYearValue;
	for(intCount=0; intCount < 12; intCount++)
	{
		strCurMonthYear = arrMonth[dateCurrent.getMonth()] + " " + dateCurrent.getFullYear();
		if (dateCurrent.getMonth() < 9)
			strCurMonthYearValue = "0" + (dateCurrent.getMonth()+1) + dateCurrent.getFullYear();
		else
			strCurMonthYearValue = "" + (dateCurrent.getMonth()+1) + dateCurrent.getFullYear();
		document.write('<option value="' + strCurMonthYearValue + '"');
		if (strCurMonthYear == g_strMonthYear)
			document.write(' selected');
		document.write('>' + strCurMonthYear + '</option>');
		
		// Add a month to the current date
		dateCurrent.setMonth(dateCurrent.getMonth()+1);
	}
	
	document.write('</select>');
}

function GenerateBookDate(intDaysOffset)
{
	// Get the current date

	var dateBook = new Date;
	
	// Add 7 days to the date
	g_intDay = dateBook.getDate() + 7 + intDaysOffset;
	dateBook.setDate(g_intDay);
	
	// Get the booking date
	g_intDay = dateBook.getDate();
	g_strMonthYear = arrMonth[dateBook.getMonth()] + " " + dateBook.getFullYear();
	return dateBook;
}


