

// REVISION BY JC 08182005

var loadTheIslands = true;
var IslandCheckFlag = false;
var selRegionName = "Any Region";

var Regions = new Array();
var RegionIDs = new Array();
var Segments = new Array();
var Island = new Array(); //the airport/island name to display
var IslandID = new Array(); //the airport name passed to server
var IslandNames = new Array(); //the island name passed to server

IslandID[0]='';
Island[0]='Any Region';
IslandNames[0]="";
Regions[0]='Any Region';
RegionIDs[0]='Any Region';

IslandID[1]='ITO';
Island[1]='Hilo, Hawaii/Big Island (ITO)';
IslandNames[1]="Hawaii";
Regions[1]='Any Region,Hilo,Kohala Coast,Kona';
RegionIDs[1]='0:6,11:6,10:6,9:6';

IslandID[2]='HNL';
IslandNames[2]="Oahu";
Island[2]='Honolulu, Oahu (HNL)';
Regions[2]='Any Region,HNL Airport,North Shore,Waikiki/Honolulu,West Oahu';
RegionIDs[2]='0:2,18:2,48:2,2:2,47:2';

IslandID[3]='MKK';
IslandNames[3]="Molokai";
Island[3]='Hoolehua, Molokai (MKK)';
Regions[3]='Molokai';
RegionIDs[3]='24:3';

IslandID[4]='OGG';
IslandNames[4]="Maui";
Island[4]='Kahului, Maui (OGG)';
Regions[4]='Any Region,Hana,Kahului,Kihei/Wailea,Lahaina/Kaanapali,West Maui';
RegionIDs[4]='0:4,42:4,15:4,4:4,3:4,41:4';

IslandID[5]='JHM';
IslandNames[5]="Maui";
Island[5]='Kapalua, Maui (JHM)';
Regions[5]='Any Region,Hana,Kahului,Kihei/Wailea,Lahaina/Kaanapali,West Maui';
RegionIDs[5]='0:4,42:4,15:4,4:4,3:4,41:4';

IslandID[6]='KOA';
Island[6]='Kona, Hawaii/Big Island (KOA)';
IslandNames[6]="Hawaii";
Regions[6]='Any Region,Hilo,Kohala Coast,Kona';
RegionIDs[6]='0:6,11:6,10:6,9:6';

IslandID[7]='LNY';
IslandNames[7]="Lanai";
Island[7]='Lanai City, Lanai (LNY)';
Regions[7]='Lanai';
RegionIDs[7]='25:5';

IslandID[8]='LIH';
IslandNames[8]="Kauai";
Island[8]='Lihue, Kauai (LIH)';
Regions[8]='Any Region,Lihue/Kapaa,Poipu/Waimea,Princeville';
RegionIDs[8]='0:1,16:1,13:1,14:1';


function ClearList(OptionList, TitleName, ValueName) {
OptionList.length = 0;
//don't need this any more
OptionList.options[0] = new Option(TitleName, ValueName, true, true);
}

function LoadRegions(Index) {
if (Index >= 0) {
var CurrentRegions = Regions[Index].split(',');
var CurrentRegionIDs = RegionIDs[Index].split(',');
var sel = 0;

 for (var i=0; i<CurrentRegions.length; i++) {
if (CurrentRegions[i] == selRegionName)
sel = i;
document.TravelRequestForm.region.options[i] = new Option(CurrentRegions[i], CurrentRegionIDs[i], false, false);
}

// next line sets "Region" to selected state until chosen
document.TravelRequestForm.region.options[sel].selected = true;
}


// *********************************************
// ADDED BY CW - 06/28/2004
var now = new Date();
var startDate = new Date();

newDate = new Date(now.getTime() + (3*24*60*60*1000));
startDate = (newDate.getMonth()+1) + "/" + newDate.getDate() + "/" + newDate.getFullYear();
document.TravelRequestForm.itineraryStartDate.value = startDate;

newDate = new Date(now.getTime() + (10*24*60*60*1000));
endDate = (newDate.getMonth()+1) + "/" + newDate.getDate() + "/" + newDate.getFullYear();
document.TravelRequestForm.itineraryEndDate.value = endDate;
// *********************************************

}

function LoadIslands() {
loadTheIslands = false;
for (var i=0; i<Island.length; i++)
document.TravelRequestForm.to.options[i] = new Option(IslandID[i], Island[i], false, false);
document.TravelRequestForm.to.options[0].selected = true;
ChangeRegion(0);
}


// -------------------------------
function show(object) {
if (document.getElementById && document.getElementById(object) != null)
node = document.getElementById(object).style.visibility='visible';
else if (document.layers && document.layers[object] != null)
document.layers[object].visibility = 'visible';
else if (document.all)
document.all[object].style.visibility = 'visible';
}
// -------------------------------
function hide(object) {
if (document.getElementById && document.getElementById(object) != null)
node = document.getElementById(object).style.visibility='hidden';
else if (document.layers && document.layers[object] != null)
document.layers[object].visibility = 'hidden';
else if (document.all)
document.all[object].style.visibility = 'hidden';
}

// -------------------------------
// CREATED BY CW - 08/04/2004 FOR INDEX.PHP
function sendOff(object) {
var strConfirm='';
var now = new Date();
// ---------------------------------------------
// *** 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 ***

//*** COMMENTED NEW JOE
//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 (dateChecker()) {

document.TravelRequestForm.action='http://pts.get2hawaii.com/ots/Index.do';
document.TravelRequestForm.submit();
}
}
}
// -------------------------------
// CREATED BY CW - 08/04/2004
function date_diff(val) {
// GET THE DATE 330 DAYS FROM TODAY
    var date330 = "";
    // parse val for month, day, year
var dateArray = val.split('/');
// ---------------------------------------------
strDate = new Date(dateArray[2],parseInt(dateArray[0],10)-1,dateArray[1]);
// ---------------------------------------------
// figure out day, month, year 330 days from today
date330 = new Date(strDate.getTime() + (330 * 86400000));
// ---------------------------------------------
if (navigator.appName == 'Microsoft Internet Explorer') {
var tmpYear = parseInt(date330.getYear(), 10);
} else if (navigator.appName == 'Netscape') {
var tmpYear = parseInt(date330.getYear()+1900, 10);
} else {
var tmpYear = parseInt(date330.getYear()+1900, 10);
}
// ---------------------------------------------
// return value
return (parseInt(date330.getMonth()+1, 10))
+ '/'
+ date330.getDate()
+ '/'
+ tmpYear
//+ (parseInt(date330.getYear()+1900, 10));
}
// -------------------------------
// CREATED BY CW - 08/04/2004
function daysElapsed(date1, date2) {
// CALL FUNCTION BY: daysElapsed(FormValue, 330Days)
// ---------------------------------------------
var dateArray1 = date1.split('/');
var dateArray2 = date2.split('/');
// ---------------------------------------------
date1 = new Date(dateArray1[2],parseInt(dateArray1[0],10)-1,dateArray1[1]);
date2 = new Date(dateArray2[2],parseInt(dateArray2[0],10)-1,dateArray2[1]);
// ---------------------------------------------
var difference =
Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0)
- Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
// ---------------------------------------------
return difference/1000/60/60/24;
}

// CREATED BY CW - 08/04/2004
function y2k(number) {
return (number < 1000) ? number + 1900 : number;
}
// -------------------------------
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 dateChecker() {
//if it is multiIsland, dont allow for 1 day.
 if (
 document.TravelRequestForm.typeOfPackage.value == "fullPackage" ||
document.TravelRequestForm.typeOfPackage.value == "AIR-CAR-HOTEL"
) {

if (isInterislandPkg() &&
 document.TravelRequestForm.typeOfTour[0].checked=="0" &&
 document.TravelRequestForm.typeOfTour[1].checked=="1"
 ) {
dtStart = new Date(document.TravelRequestForm.itineraryStartDate.value);
dtEnd = new Date(document.TravelRequestForm.itineraryEndDate.value);
endDay = new Date((dtEnd.getMonth() + 1) + "/" + dtEnd.getDate() + "/" + dtEnd.getFullYear());
startDay = new Date((dtStart.getMonth() + 1) + "/" + (dtStart.getDate()+ 2) + "/" + dtStart.getFullYear());

if(endDay < startDay) {
alert("Please make sure that the number of days you specify for this Multi-Island trip exceeds 1 day of travel.");
return false;
} else {
return true;
}
}
}
return true;
}

// -------------------------------
// HAWAII RESIDENT WARNING

// -------------------------------
function displayLayers() {
  var i, p, v, obj, args = displayLayers.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') ? 'block' : (v = 'hide') ? 'none' : v;
}
  obj.display=v;
}
}
// -------------------------------
    //Hide or display child age selection.
    //Excuted when numberOfChildren is changed
function changeNumberOfChildren() {
var countChildren = document.TravelRequestForm.numberOfChildren.value;
var age;
for (var i=0; i< 6; i++) {
if (i < countChildren) {
displayLayers('divchild' + i,'','show');
 age = getValueOfSelectObject("childAge" + i);
 if (age != "" && age == "0")
     displayLayers('divinfant' + i,'','show');
}
else{
displayLayers('divchild' + i,'','hide');
displayLayers('divinfant' + i,'','hide');
}
}
}
// -------------------------------
    //Hide or display infant seat selection.
    //Excuted when childAge is changed
function changeChildAge() {
//infant selection does not apply to non-air
var countChildren = document.TravelRequestForm.numberOfChildren.value;
var age;
for (var i=0; i< countChildren; i++){
age = getValueOfSelectObject("childAge" + i);
if (age != "" && age == "0")
displayLayers('divinfant' + i,'','show');
else
displayLayers('divinfant' + i,'','hide');
}
}

// -------------------------------
function getValueOfSelectObject(objectName) {
for (var i=0; i<document.TravelRequestForm.elements.length; i++){
if ( (document.TravelRequestForm.elements[i].name == objectName)
&& (document.TravelRequestForm.elements[i].type == "select-one"))  {
return document.TravelRequestForm.elements[i].value;
}
}
//not found
return "";
}


