function MM_displayLayers() { //v3.0
	var i, p, v, obj, args = MM_displayLayers.arguments;

	for (i = 0; i < (args.length - 2); i += 3)
		if ((obj = MM_findObj(args[i])) != null)	{
			d = args[i + 2];

			if (obj.style) {
				obj = obj.style;
			}
			obj.display = d;
		}
}

function MM_checkBrowser(NSvers, NSpass, NSnoPass, IEvers, IEpass, IEnoPass, OBpass, URL, altURL) { //v4.0
	var newURL = '', verStr = navigator.appVersion, app = navigator.appName, version = parseFloat(verStr);

	if (app.indexOf('Netscape') != -1)	{
		if (version >= NSvers)	{
			if (NSpass > 0)
				newURL = (NSpass == 1) ? URL : altURL;
		} else	{
			if (NSnoPass > 0)
				newURL = (NSnoPass == 1) ? URL : altURL;
		}
	}

	else if (app.indexOf('Microsoft') != -1)
		{
		if (version >= IEvers || verStr.indexOf(IEvers) != -1)	{
			if (IEpass > 0)
				newURL = (IEpass == 1) ? URL : altURL;
		} else	{
			if (IEnoPass > 0)
				newURL = (IEnoPass == 1) ? URL : altURL;
		}
		}

	else if (OBpass > 0)
		newURL = (OBpass == 1) ? URL : altURL;

	if (newURL)	{
		window.location = unescape(newURL);
		document.MM_returnValue = false;
	}
}

function MM_reloadPage(init) { //reloads the window if Nav4 resized
	if (init == true)
		with (navigator)
			{
			if ((appName == "Netscape") && (parseInt(appVersion) == 4))	{
				document.MM_pgW = innerWidth;
				document.MM_pgH = innerHeight;
				onresize = MM_reloadPage;
			}
			}

	else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH)
		location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
	var p, i, x;

	if (!d)
		d = document;

	if ((p = n.indexOf("?")) > 0 && parent.frames.length)	{

		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}

	if (!(x = d[n]) && d.all)
		x = d.all[n];

	for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];

	for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);

	if (!x && document.getElementById)
		x = document.getElementById(n);
	return x;
}

function MM_openBrWindow(theURL, winName, features) { //v2.0
	window.open(theURL, winName, features);
}

function MM_showHideLayers() { //v3.0
	var i, p, v, obj, args = MM_showHideLayers.arguments;

	for (i = 0; i < (args.length - 2); i += 3)
		if ((obj = MM_findObj(args[i])) != null)	{
			v = args[i + 2];

			if (obj.style)	{
				obj = obj.style;
				v = (v == 'show') ? 'visible' : (v = 'hide') ? 'hidden' : v;
			}

			obj.visibility = v;
		}
}

//this function is used when user selects a different hotel set (different set of packages) on availability page
//or select hotel page.
function moreHotelOptionsSegmentIdx(idx, selectOptionIndex) {
	if (document.TravelRequestForm.action.indexOf("SelectHotel.do") >= 0) {
		document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "DisplayHotels.do");
	}
	document.TravelRequestForm.submitAction.value = "moreHotelOptions";
	document.TravelRequestForm.dtIdx.value = idx;
	//unlike flights, hotels display one destination
	document.TravelRequestForm.stIdx0.value = selectOptionIndex;
	document.TravelRequestForm.submit();
}

function newWindow(url, title, w, h, features) {
	if (screen.width)	{
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
	} else	{
		winl = 0;
		wint = 0;
	}

	if (winl < 0)
		winl = 0;

	if (wint < 0)
		wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(url, 'title', settings);
}


//setup process insurance
function processInsurance() {
	document.forms[0].submitAction.value = "processInsurance";
	document.forms[0].submit();
}

/* See the above routine */
function ReturnChecker(fieldDepartDate, fieldReturnDate) {
	dtDepart = new Date(fieldDepartDate.value);
	dtReturn = new Date(fieldReturnDate.value);
	/*
		// This code allows for the validation scheme to automatically
		// place the Departure Date one day before the Return Date.
		// It has been commented out for now. NY - 06/25/2002.
	
		day = dtReturn.getDate();
		month = dtReturn.getMonth();
		year = dtReturn.getYear();
		dtReturn.setDate(day - 1);
		newReturn = (dtReturn.getMonth() + 1) + "/" + dtReturn.getDate() + "/" + dtReturn.getYear();
	
		if (dtReturn < dtDepart) {
			fieldDepartDate.value = newReturn;
		}
	*/

	if (dtReturn < dtDepart) {
		fieldDepartDate.value = fieldReturnDate.value;
	}
}


//Erland Added
function regionIslandChecker() {
	if (includesHotel())	{
		var SelectedIsland = getHawaiianIslandByAirportCode(document.TravelRequestForm.to.value);
		var SelectedRegion =
			document.TravelRequestForm.region.options[document.TravelRequestForm.region.selectedIndex].value;

		if (SelectedIsland == "")	{
			alert(
				'Please select an Island Destination and Island Region before submitting the Travel Package Request.');
			return false;
		}
		if (SelectedRegion == "")	{
			alert('Please select an Island Region before submitting the Travel Package Request.');
			return false;
		}
	}
	return true;
}


//setup to return user appropriately
function returnBack(returnAvailabilityPage) {
	if (returnAvailabilityPage) {
		document.TravelRequestForm.submitAction.value = "showDetailHotels";
	} else	{
		document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "ReturnItinerary.do");
	}
	document.TravelRequestForm.submit();
}

//general javascript
function replaceActionName(oldName, newName) {
	var name = oldName.substring(0, oldName.lastIndexOf('/') + 1);
	name += newName;
	return name;
}


// CREATED BY CW - 08/04/2004 FOR INDEX.PHP
function sendOff(object) {
	var strConfirm = '';
	var now = new Date();

	// ---------------------------------------------
	// *** SET LOCALDISCOUNT TO 0/1 ***
	if (eval("document.TravelRequestForm.localDiscount[0].checked") == true
		&& eval("document.TravelRequestForm.localDiscount[1].checked") == false) {
		// HI RESIDENT = YES
		document.TravelRequestForm.localDiscount.value = 1;
	} else if (eval("document.TravelRequestForm.localDiscount[0].checked") == false
		&& eval("document.TravelRequestForm.localDiscount[1].checked") == true) {
		// HI RESIDENT = NO
		document.TravelRequestForm.localDiscount.value = 0;
	} else {
		document.TravelRequestForm.localDiscount.value = 0;
	}

	//alert("document.TravelRequestForm.localDiscount.value = " + document.TravelRequestForm.localDiscount.value);
	// ---------------------------------------------
	// *** CREATE TODAY'S DATE BASED ON BROWSER TYPE ***
	if (navigator.appName == 'Microsoft Internet Explorer')	{
		var today = parseInt(now.getMonth() + 1, 10) + '/' + now.getDate() + '/' + parseInt(now.getYear(), 10);
	}

	else if (navigator.appName == 'Netscape')
		{
		var today = parseInt(now.getMonth() + 1, 10) + '/' + now.getDate() + '/' + parseInt(now.getYear() + 1900, 10);
		}

	else
		{
		var today = parseInt(now.getMonth() + 1, 10) + '/' + now.getDate() + '/' + parseInt(now.getYear() + 1900, 10);
		}

// ---------------------------------------------
// *** CHECK THAT DEP & ARR CITIES HAVE VALUES ENTERED ***
//			if (!document.TravelRequestForm.from.value && (eval("document.TravelRequestForm.typeOfPackage[4].checked")==false)) {
	if (!document.TravelRequestForm.from.value) {
		strConfirm += 'Please select a Departure City' + '\n';
	}

	if (!document.TravelRequestForm.to.value) {
		strConfirm += 'Please select an Arrival City' + '\n';
	}

	// ---------------------------------------------
	// *** CHECK THAT DEP & ARR CITIES ARE DIFFERENT ***
	if (document.TravelRequestForm.from.value && document.TravelRequestForm.to.value
		&& (document.TravelRequestForm.from.value == document.TravelRequestForm.to.value)) {
		strConfirm += 'Departing and Arrival cities must be different' + '\n';
	}

	// ---------------------------------------------
	// *** VALID DEP & ARR DATES? ***
	if (!checkdate(document.TravelRequestForm.itineraryStartDate)) {
		strConfirm += 'Departure Date is not filled in correctly' + '\n';
	}

	if (!checkdate(document.TravelRequestForm.itineraryEndDate)) {
		strConfirm += 'Arrival Date is not filled in correctly' + '\n';
	}

	// ---------------------------------------------
	// *** ARE DEP & ARR DATES GREATER THAN TODAY? ***
	if (daysElapsed(document.TravelRequestForm.itineraryStartDate.value, today) <= 0) {
		strConfirm += 'Departure Date should be greater than today' + '\n';
	}

	if (daysElapsed(document.TravelRequestForm.itineraryEndDate.value, today) <= 0) {
		strConfirm += 'Arrival Date should be greater than today' + '\n';
	}

	// ---------------------------------------------
	// *** IS DEP DATE EARLIER THAN ARR DATE? ***
	// COMMENTED BY CW - 09/14/2004
/*
	if (daysElapsed(document.TravelRequestForm.itineraryEndDate.value, document.TravelRequestForm.itineraryStartDate.value)<=0) {
		strConfirm += 'Arrival Date should be greater than the Departure Date' + '\n';
	}
*/
	// ---------------------------------------------
	// *** ARE DEP & ARR DATES WITHIN 330 DAYS OF TODAY? ***
	if (daysElapsed(date_diff(today), document.TravelRequestForm.itineraryStartDate.value) < 0) {
		strConfirm += 'Please set the Departure Date within 330 days from today' + '\n';
	}

	if (daysElapsed(date_diff(today), document.TravelRequestForm.itineraryEndDate.value) < 0) {
		strConfirm += 'Please set the Arrival Date within 330 days from today' + '\n';
	}

	// ---------------------------------------------
	// *** FINAL CHECK ***
	if (strConfirm.length > 0) {
		alert(strConfirm);
	} else	{
		if (regionIslandChecker() && checkInfantsVersusAdults() && checkNumOfPassengers() && dateChecker())	{
			document.TravelRequestForm.action = 'http://pts.get2hawaii.com/ots/Index.do';
			document.TravelRequestForm.submit();
		}
	}
}


//select room - display flights
function selectRoomDisplayFlights(destinationIdx, resKey) {
	document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "DisplayFlights.do");
	document.TravelRequestForm.submitAction.value = "1";
	document.TravelRequestForm.selectedRoom.value = resKey;
	document.TravelRequestForm.submit();
}


//select flight
function selectFlight(idx, resKey) {
	document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "SelectFlight.do");
	document.TravelRequestForm.dtIdx.value = idx;

	switch (idx) {
		case 0:
			document.TravelRequestForm.selectedFlight0.value = resKey;
			break;

		case 1:
			document.TravelRequestForm.selectedFlight1.value = resKey;
			break;

		case 2:
			document.TravelRequestForm.selectedFlight2.value = resKey;
			break;

		case 3:
			document.TravelRequestForm.selectedFlight3.value = resKey;
			break;

		case 4:
			document.TravelRequestForm.selectedFlight4.value = resKey;
			break;

		case 5:
			document.TravelRequestForm.selectedFlight5.value = resKey;
			break;

		default:
		}

	document.TravelRequestForm.submit();
}

//select hotel
function selectHotel(destinationIdx, resKey) {
	//when select a hotel in UDSell in Hotel Info page, keep the action
	if (document.TravelRequestForm.action.indexOf("HotelInfo.do") < 0) {
		document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "SelectHotel.do");
	} else	{
		document.TravelRequestForm.submitAction.value = 6; //HotelInfoAction.ACTION_SELECT_UD_HOTEL
	}
	document.TravelRequestForm.dtIdx.value = destinationIdx;
	document.TravelRequestForm.dtRes.value = resKey;
	document.TravelRequestForm.submit();
}


//forward to the page that show hotel information

//show hotel info page
function showHotel(dtIdx, roomId, submitAction) {
	//var strOpen="HotelInfo.do?roomId="+roomId+ "&dtIdx=" + dtIdx;
	//set the navigation id as 1 by default, which is overview
	document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "HotelInfo.do");
	document.TravelRequestForm.dtIdx.value = dtIdx;
	document.TravelRequestForm.dtRes.value = roomId;

	if (document.TravelRequestForm.selectedRoom != null) {
		document.TravelRequestForm.selectedRoom.value = roomId;
	}
	document.TravelRequestForm.submitAction.value = submitAction;
	document.TravelRequestForm.submit();
}


//retrieve the terms for display in new window
function showTerm(url, title, w, h, features) {
	if (window.checkG2HPageTimeOut && checkG2HPageTimeOut()) {
		return;
	} else if (window.startG2HPageTimeOut) {
		startG2HPageTimeOut();
	}

	var win1 = 0;
	var wint = 0;

	if (screen.width)	{
		winl = (screen.width - w) / 2;
		wint = (screen.height - h) / 2;
	}

	if (winl < 0)
		winl = 0;

	if (wint < 0)
		wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(url, 'title', settings);
}

function showDetailHotels() {
	document.TravelRequestForm.submitAction.value = "showDetailHotels";
	document.TravelRequestForm.submit();
}


//Determine if airport note should be displayed
//Return true if airport is (JHM island airport), false otherwise
function showAirportNote() {
	var toDisplay = false;

	if ((document.TravelRequestForm.from0.type == "select-one")
		&& (document.TravelRequestForm.to0.type == "select-one"))	{
		if (document.TravelRequestForm.from0.options[document.TravelRequestForm.from0.selectedIndex].value == "JHM"
			|| document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "JHM") {
			toDisplay = true;
		}
	}

	else if ((document.TravelRequestForm.from0.type == "text") && (document.TravelRequestForm.to0.type == "select-one"))
		{
		if (document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "JHM") {
			toDisplay = true;
		}
		}

	else if ((document.TravelRequestForm.from0.type == "select-one") && (document.TravelRequestForm.to0.type == "text"))
		{
		if (document.TravelRequestForm.from0.options[document.TravelRequestForm.from0.selectedIndex].value == "JHM") {
			toDisplay = true;
		}
		}

	if (toDisplay) {
		displayLayers('airportNote', '', 'show');
	} else	{
		displayLayers('airportNote', '', 'hide');
	}
}

//Determine if airport note should be displayed
//Return true if airport is (JHM), false otherwise
function showAirportNoteMulti(lastDestination) {
	var toDisplay = false;
	var fromValue, toValue;

	for (var i = 0; i < (lastDestination + 1); i++)
		{
		toValue = getValueOfSelectObject("to" + i);
		fromValue = getValueOfSelectObject("from" + i);

		if (toValue == "JHM" || fromValue == "JHM")	{
			toDisplay = true;
			break;
		}
		}

	if (toDisplay) {
		displayLayers('airportNote', '', 'show');
	} else	{
		displayLayers('airportNote', '', 'hide');
	}
	return toDisplay;
}

//Determine if international airport note should be displayed
//Return true if airport is (PPT, SYD, MNL), false otherwise
function showInternationalAirportNote() {
	var toDisplayPPT = false;
	var toDisplaySYD = false;
	var toDisplayMNL = false;
	var toDisplayPPG = false;

	//International is always drop-down
	if (document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "PPT") {
		toDisplayPPT = true;
	} else if (document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "SYD") {
		toDisplaySYD = true;
	} else if (document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "MNL") {
		toDisplayMNL = true;
	} else if (document.TravelRequestForm.to0.options[document.TravelRequestForm.to0.selectedIndex].value == "PPG") {
		toDisplayPPG = true;
	}

	if (toDisplayPPT) {
		displayLayers('airportNotePPT', '', 'show');
	} else	{
		displayLayers('airportNotePPT', '', 'hide');
	}

	if (toDisplaySYD) {
		displayLayers('airportNoteSYD', '', 'show');
	} else	{
		displayLayers('airportNoteSYD', '', 'hide');
	}

	if (toDisplayPPG) {
		displayLayers('airportNotePPG', '', 'show');
	} else	{
		displayLayers('airportNotePPG', '', 'hide');
	}
}

function showMoreOptions() {
	displayLayers('moreOptions', '', 'show');

	//the code below is used to track if the user has clicked showMoreOptions. If it has been clicked, keep the
	//layer open
	if (document.TravelRequestForm.showMoreOptions != null) {
		document.TravelRequestForm.showMoreOptions.value = "show";
	}
}


/*
 It is called when users click on Select Different Car/Hotel Dates
 */
function selectDifferentDates(destination, component) {
	document.TravelRequestForm.submitAction.value = "SelectDifferentDates";
	document.TravelRequestForm.currentDestination.value = destination;
	document.TravelRequestForm.currentComponent.value = component;
	validateAndSubmit();
}


//Set the multicity return flight default date
function setMulticityReturnFlightDefaultDate() {
	if (document.TravelRequestForm.returnFlightDefaultDate && document.TravelRequestForm.multiCityPkgLastIdx)	{
		last = document.TravelRequestForm.multiCityPkgLastIdx.value;
		document.TravelRequestForm.returnFlightDefaultDate.value = getValueOfTextObject("itineraryStartDate"
			+ last);
	}
}

//Shows the seating class note
function showClassNote() {
	if (document.TravelRequestForm.flightClass.selectedIndex == 1) {
		displayLayers('seatingclass', '', 'show');
	} else	{
		displayLayers('seatingclass', '', 'hide');
	}
}

// This function is called when the submit image or link is clicked. The validations done here should
// really be done in supporting Java code, but in the interest of time we added them here.
/*function submitForm() {
	if (
	regionIslandChecker() &&
	checkInfantsVersusAdults() &&
	checkNumOfPassengers() &&
	dateChecker()
//	&& discountChecker() // COMMENTED BY CW - 8/16/2004
	) {
		document.TravelRequestForm.submit();
	}
}

function submitForm1() {
	if (
	regionIslandChecker() &&
	checkNumOfPassengers() &&
	dateChecker()
//	&& discountChecker() // COMMENTED BY CW - 8/16/2004
	) {
		document.TravelRequestForm.submit();
	}
}*/
//-->


function showPopup() {
	window.open('http://www.bbbonline.org/cks.asp?id=10203151846422324',null,"scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=no,status=no,width=525,height=475,top=0,left=0");
	return false;
}

function trim(str)
	{
	return str.replace(/^\s*|\s*$/g, "");
	}


//update - selected car
function updateCar(destinationIdx, resKey) {
	document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "SelectCar.do");
	document.TravelRequestForm.submitAction.value = "SelectCar";
	document.TravelRequestForm.dtIdx.value = destinationIdx;
	document.TravelRequestForm.dtRes.value = resKey;
	document.TravelRequestForm.submit();
}


//filter hotels by view/area, used in SelectHotel
function viewByHotels() {
	document.TravelRequestForm.submitAction.value = "viewByHotels";
	document.TravelRequestForm.action = replaceActionName(document.TravelRequestForm.action, "DisplayHotels.do");
	document.TravelRequestForm.submit();
}

//Return true if src is in the right email address format
function validateEmailAddressFormat(src) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(src);
}

// This function is called when the submit image or link is clicked. The validations done here should
// really be done in supporting Java code, but in the interest of time we added them here.
/*    function submitForm() {
		//The following fields are not always available in all departure pages
		if (document.TravelRequestForm.submitAction) document.TravelRequestForm.submitAction.value="";
		if (document.TravelRequestForm.currentDestination) document.TravelRequestForm.currentDestination.value=0;
		if (document.TravelRequestForm.currentComponent) document.TravelRequestForm.currentComponent.value="";
			validateAndSubmit();
	}*/


/*******************
 ** view and search enhancement
 ********************/

//validate the departure date
function validateDepartureDate() {
	if (checkdate(document.TravelRequestForm.itineraryStartDate)) {
		DepartChecker(document.TravelRequestForm.itineraryStartDate, document.TravelRequestForm.itineraryEndDate,
			'<%=indexObj.getNumberOfNights()%>');
	}
}

//validate the return date
function validateReturnDate() {
	if (checkdate(document.TravelRequestForm.itineraryEndDate)) {
		ReturnChecker(document.TravelRequestForm.itineraryStartDate, document.TravelRequestForm.itineraryEndDate);
	}
}


/*
It is called from CustomHotelDates and CarDates to validate date inputs
*/
function validateDateRange(dateInput, startDateRangeValue, endDateRangeValue, errorMsg, isStartDate) {
	if (checkdate(dateInput))	{
		dateDt = new Date(getDateStr(dateInput.value));
		if (isStartDate)	{
			if (startDateRangeValue != null && startDateRangeValue != "")	{
				startDateDt = new Date(getDateStr(startDateRangeValue));
				if (dateDt < startDateDt && endDateRangeValue != null && endDateRangeValue != "")	{
					alert(errorMsg);
					return false;
				}

				else if (dateDt < startDateDt)
					{
					alert(errorMsg);
					return false;
					}
			}
		} else	{
			if (endDateRangeValue != null && endDateRangeValue != "")	{
				endDateDt = new Date(getDateStr(endDateRangeValue));
				if (dateDt > endDateDt && startDateRangeValue != null && startDateRangeValue != "")	{
					alert(errorMsg);
					return false;
				}

				else if (dateDt > endDateDt)
					{
					alert(errorMsg);
					return false;
					}
			}
		}
	}
	return true;
}


// CREATED BY CW - 08/04/2004
function y2k(number)	{
	return(number < 1000) ? number + 1900 : number;
}