                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
//  ******************* CLIENT_SIDE SNIFFER CODE *******************
//	stylesheet selection removed - used for some DHTML stuff that is not on every page, but is on
//	enough to justify being in global file

// comment out this line when doing javascript debugging
self.onerror = function() {return true;}

var agt=navigator.userAgent.toLowerCase();

//  BROWSER VERSION
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

//  BROWSER TYPE
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1));
var is_nav4up = (is_nav && (is_major >= 4 && is_major < 5));
var is_nav6 = (is_nav && (is_major >= 5 ));
var is_ie   = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up  = (is_ie  && (is_major >= 4));
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);

//  PLATFORM
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);
var is_linux = (agt.indexOf("inux")!=-1);
var is_unix  = ((agt.indexOf("x11")!=-1) || is_linux);


// Reroute non-dom browsers

if(!document.getElementById){
	document.location="/browser_upgrade.html";	
}


// DATE FUNCTIONALITY
var today = new Date();
var thisDay = today.getDate();
var thisMonth = today.getMonth();
var thisYear = y2k(today.getYear());

var monthArray = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var dayArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

function y2k (number) {
	return (number < 1000) ? number + 1900 : number;
}

function setArrays() {
	if (((thisYear % 4 == 0) && (thisYear % 100 != 0)) || (thisYear % 400 == 0))
		dayArray[1] = 29;
}

// this function is currently irrelevent, and could be merged with changeDateGen,
// but i'm leaving here in case further abstraction is necessary down the road.
function changeDate (ddArray,whichDD) {
	if (ddArray.length >= 4) {
		var sMo = ddArray[0];
		var sDy = ddArray[1];
		var eMo = ddArray[2];
		var eDy = ddArray[3];
		if (whichDD != 3 && whichDD != 4) // put in because of in-stream change of date-chaning rules.
			changeDateGen(sMo,sDy,eMo,eDy,whichDD);
	}
}

// generic date changing function
// only thing missing is safeguard against dates that don't exist (e.g. nov 31)
function changeDateGen (sMo,sDy,eMo,eDy,whichDD) {
	var sMoIndex = sMo.options.selectedIndex;
	var sDyIndex = sDy.options.selectedIndex;
	var eMoIndex = eMo.options.selectedIndex;
	var eDyIndex = eDy.options.selectedIndex;

	var sDate = getDDdate(sMo,sDy);
	var eDate = getDDdate(eMo,eDy);

	if (whichDD==0 && sDate>eDate) {
		if (whichCal==1) {
			setDDdate(eMo,eDy,addDays(sDate,tripLength));
		} else if (whichCal==2) {
			setDDdate(sMo,sDy,addDays(eDate,-1*tripLength));
		}
	} else if (sMoIndex>eMoIndex) {
		if (whichDD==1) {
			eMo.options.selectedIndex = sMoIndex;
			if (sDyIndex>eDyIndex) setDDdate(eMo,eDy,addDays(sDate,tripLength));
		} else if (whichDD==3) {
			sMo.options.selectedIndex = eMoIndex;
			if (sDyIndex>eDyIndex) setDDdate(sMo,sDy,addDays(eDate,-1*tripLength));
		}
	} else if (sMoIndex==eMoIndex && sDyIndex>eDyIndex) {
//		these two lines should be there instead of the two lines that follow.
//		if (whichDD==1 || whichDD==3) {
//			eDy.options.selectedIndex = Math.min(sDy.options.selectedIndex+tripLength,getMonthLength(eMo.options[eMoIndex].value)-1);
		if (whichDD==1) { // put in because of in-stream change of date-chaning rules.
			setDDdate(eMo,eDy,addDays(sDate,tripLength));
		} else if (whichDD==2) {
			setDDdate(eMo,eDy,addDays(sDate,tripLength));
		} else if (whichDD==4) {
			setDDdate(sMo,sDy,addDays(eDate,-1*tripLength));
		}
	}
}

function getDDdate (moDD,dyDD) {
	var moYr = moDD.options[moDD.options.selectedIndex].value.split(" ");
	var mo = moYr[0].substr(0,3);
	var yr = (moYr.length > 1) ? moYr[1] : thisYear;
	var dy = dyDD.options[dyDD.options.selectedIndex].value;

	for (i=0;i<monthArray.length;i++) {
		if (monthArray[i] == mo) break;
	}
	return new Date(yr,i,dy);
}

function getMonthLength (mo) {
	mo = mo.substr(0,3).toLowerCase();
	for (var i=0;i<monthArray.length;i++) {
		if (monthArray[i].toLowerCase() == mo) break;
	}
	return dayArray[i];
	return 31;
}

function setDDdate (moDD,dyDD,theDate) {
	var maxMoYr = moDD.options[moDD.options.length-1].value;
	maxMoYr = maxMoYr.split(" ");
	var maxDy = getMonthLength(maxMoYr[0]);
	//BCL - temp js fix
	//theDate = new Date(Math.min(new Date(maxMoYr[0]+" "+maxDy+", "+maxMoYr[1]),theDate));

	var yr = theDate.getFullYear();
	var mo = monthArray[theDate.getMonth()];
	var dy = theDate.getDate();
	var matchedMo = -1;

	var matchVal = (yr==thisYear) ? mo : mo + " " + yr;
	for (var i=0;i<moDD.options.length;i++) {
		if (moDD.options[i].value == matchVal) {
			matchedMo = i;
			break;
		}
	}
	if (matchedMo == -1) dy = 1;

	moDD.options.selectedIndex = Math.max(0,matchedMo);
	dyDD.options.selectedIndex = dy-1;
}

function addDays (theDate,days) {
	if (!days) days = 0;
	var mseconds = theDate.getTime() + 86400000 * days;
	return new Date(mseconds);
}

var theForm;
var dateDDs = new Array();
var whichCal = 0;
var tripLength = 7;

function selectDate (dy,moYr) {
	moYr = moYr.split(" ");
	var mo = moYr[0].substr(0,3);
	var yr = moYr[1];
	var theDate = new Date(mo + " " + dy + ", " + yr);

	var moDD, dyDD;
	moDD = dateDDs[(whichCal*2)-2];
	dyDD = dateDDs[(whichCal*2)-1];
	setDDdate (moDD,dyDD,theDate,0);

	if (dateDDs.length == 4) changeDateGen (dateDDs[0],dateDDs[1],dateDDs[2],dateDDs[3],0);
	else if (dateDDs.length > 4) changeMultiDate(whichCal,0);
	whichCal = 0;
}

function changeMultiDate (whichDate,whichDD) {
	var whichMoDD = (whichDate-1)*2;
 	var whichDyDD = whichMoDD+1;
	var dateDiff = 0;
	var i, firsti, whichDDofFour;
	whichCal=2;
	for (i=firsti=whichDate-1;i>=1;i--) {
		dateDiff = (firsti-i) * 2;
		whichDDofFour = (i==firsti && whichDD>0) ? whichDD+2 : 0;
		changeDateGen(dateDDs[whichMoDD-dateDiff-2],dateDDs[whichDyDD-dateDiff-2],dateDDs[whichMoDD-dateDiff],dateDDs[whichDyDD-dateDiff],whichDDofFour);
	}
	whichCal=1;
	for (i=firsti=whichDate+1;i<=(dateDDs.length/2);i++) {
		dateDiff = (i-firsti) * 2;
		whichDDofFour = (i==firsti && whichDD>0) ? whichDD : 0;
		changeDateGen(dateDDs[whichMoDD+dateDiff],dateDDs[whichDyDD+dateDiff],dateDDs[whichMoDD+dateDiff+2],dateDDs[whichDyDD+dateDiff+2],whichDDofFour);
	}
	whichCal=0;
}

// ONFOCUS & ONBLUR FUNCTIONALITY
// how to call: [onFocus="textFocus(this);" onBlur="textBlur(this);"]
function textFocus (el,val) {
	if (val) {
		el.defaultValue = val;
		if (el.value == val) el.select();
	}
	else if ((el.value != "")||(el.value != " ")) {
		//el.defaultValue = el.value;
		el.select();
	}
}

function textBlur (el,val) {
	if (val) el.defaultValue = val;
	if ((el.value == "")||(el.value == " ")) {
		//el.value = el.defaultValue;
	}
}


//reloads the window if Nav4 resized
function MM_reloadPage (init) {
 	if (init) 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();
	}
}

//img swap
function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-1); i+=2) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+1];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

MM_reloadPage(true);

function isXPSP2(){
var isSP2=window.navigator.userAgent.indexOf("SV1") != -1;
return isSP2;
}


function msgUserPopUpBlockerIsOn(){
	//alert("It appears that you currently have pop-up blocking turned on.\n In order to view this content, please use the Control key when clicking the link.");
	if (document.getElementById("blockedPUMesgBox")) {
		document.getElementById("blockedPUMesgBox").style.display = "block";
	}
}


// general popup - specify href, width, and height in function call
function popUpGen (page,w,h,id,globalProps) {
	if (!id) id="popup";
	if (!globalProps) globalProps = "resizable=yes,menubar=no,status=no,scrollbars=yes,toolbar=no,directories=no,location=no";
	if (!w||w=='') w=500;
	if (!h||h=='') h=500;
	var win;
	if (navigator.appName == 'Netscape') {
		win = window.open(page,id,'width='+w+',height='+h+','+globalProps+',screenX=0,screenY=0');
	} else {
		win = window.open(page,id,'width='+w+',height='+h+','+globalProps+',top=0,left=0');
	}

	if(isXPSP2() && win==null){
			msgUserPopUpBlockerIsOn();
		} else {	
		win.focus();
		}
  	return false;
}

//	hotwire popup
function popUpHotwire(page) {
	return popUpGen(page,760,620,'hotwire','resizable=yes,menubar=yes,status=yes,scrollbars=yes,toolbar=yes,directories=yes,location=yes');
}


function popUpPrintItin(url){
	return popUpGen(url, 635,600,'print','resizable=yes,menubar=yes,status=no,scrollbars=yes,toolbar=no,directories=no,location=no');
	}

// standard popup
function popUp(page) {
	return popUpGen('/'+page+'.jsp',420,400,'popup');
}

// specialized popup functions
function popUpHelp (page) {
	return popUpGen('/help/'+page+'.jsp',420,400,'popuphelp');
}

var calendarLink = "/App/ViewCalendar?";
function popUpCal (n) {
	whichCal = n;
	var setMonth = "";
	setMonth = dateDDs[(n-1)*2].options[dateDDs[(n-1)*2].options.selectedIndex].value.split(" ");
	var setYear = setMonth[1] ? setMonth[1] : "";
	setMonth = setMonth[0];
	return popUpGen(calendarLink+"?n="+n+"&view=calendar&setMonth="+setMonth+"&setYear="+setYear,200,390,'popupcal','resizable=yes,menubar=no,status=no,scrollbars=no,toolbar=no,directories=no,location=no');
}

function popUpAirCode() {
	return popUpGen('/global/airportCodes.jsp',600,725,'popupaircode');
}

function popUpLearnMore (url) {
	return popUpGen(url,500,400,'popuplearnmore');
}

// privacy and terms
function popUpReg(page) {
	return popUpGen('/App/global/legal/'+page+'.jsp',550,500);
}

// close window
function closeWin () {
	window.close();
	return true;
}

//Used for dynamically generated booking path section numbers
var sCount=0;
function stepCount(){
	sCount++;
	document.write(sCount);
}

var field_length=0;

function tabNext (obj,event,len,next_field) {
	if (event == "down") {field_length=obj.value.length;}
	else if (event == "up") {
		if (obj.value.length != field_length) {
			field_length=obj.value.length;
			if (field_length == len) {next_field.focus();}
		}
	}
}

// onkeyup="tabNext(this,'up',3,this.form.elements['NEXTFIELD'])" onkeydown="tabNext(this,'down',3)"

function selectCheck(formName,checkName){
	if (document.forms[formName].elements[checkName].checked){document.forms[formName].elements[checkName].checked=false;}
	else {document.forms[formName].elements[checkName].checked=true;}
}

// Netscape style sheet modifications
var text = "";
text += '<style type="text/css">\n';
text += 'td			{font-family: arial, sans-serif; font-size: 12px;}\n';
text += 'p			{font-family: arial, sans-serif; font-size: 12px;}\n';
text += 'input		{font-family: arial, sans-serif; font-size: 12px; margin: 0px;}\n';
text += 'select		{font-family: arial, sans-serif; font-size: 12px; margin: 0px}\n';
text += '.t1		{font-family: arial, sans-serif; font-size: 10px;}\n';
text += '.t2		{font-family: arial, sans-serif; font-size: 11px;}\n';
text += '.t3		{font-family: arial, sans-serif; font-size: 12px;}\n';
text += '.dealList	{padding-bottom: 0px; padding-right: 0px; line-height: normal;}\n';
text += '</style>';

if (document.layers) {document.write(text);}

//	Windows IE stylesheet mods

var ieStyle = "";
ieStyle += '<style type="text/css">\n';
ieStyle += '.radioOutdent	{margin-left: -6px;}\n'
ieStyle += '.checkOutdent	{margin-left: -4px;}\n'
ieStyle += '</style>';

if (is_ie4up && is_win) {document.write(ieStyle);}


// NN 6+ stylesheet mods

var nnStyle = "";
nnStyle += '<style type="text/css">\n';
nnStyle += '.radioMargin	{margin-right: 6px;}\n'
nnStyle += '</style>';

if (is_nav6 && is_win) {document.write(nnStyle);}



function bonusDays (el,legs) {
	// unsure why this function is needed. i don't think it's ever called.
	if (el.checked) {
		dateDDs[0].selectedIndex = 0;
		dateDDs[1].selectedIndex = 0;
		if (legs == 2) {
			dateDDs[2].selectedIndex = 0;
			dateDDs[3].selectedIndex = 0;
		}
	}
}


function activateCkbox(id){
	//this function is designed to *only* turn a checkbox on.  Use toggleCheckbox for toggling
	document.getElementById(id).checked=true;
}

function toggleCheckbox (el) {
	el.checked = !el.checked;
}

function changeStatus (txt) {
	if (!txt) txt="";
	window.status=txt;
	return true;
}

function stripYears(x) {
	for (var i = x.options.length - 1; i >= 0; i--)  {
		noYear = x.options[i].text.split(' ');
		x.options[i].text = noYear[0];
	}
}

function changeCreditCard (slc) {
	var val = slc.options[slc.options.selectedIndex].value;
	var theImg = document.images['card_back'];
	var newImgSrc = "/img/air/";
	var showOrHide = "show";
	switch (val) {
		case "MasterCard": case "Orbitz MasterCard": newImgSrc += "cc_mc.gif"; break;
		case "Visa": newImgSrc += "cc_visa.gif"; break;
		case "American Express": newImgSrc += "cc_amex.gif"; break;
//		case "Discover": newImgSrc += "cc_dis.gif"; break;
		default: showOrHide = "hide"; newImgSrc = "/d.gif";
	}
	if (theImg) {
		theImg.src = newImgSrc;
		MM_showHideLayers("cc-card",showOrHide);
		MM_showHideLayers("cc",showOrHide);
	}
}

function pageInit () {
	//will be redefined on any page that needs it.
}

function init () {
	setArrays();
	pageInit();
}

var isDynamicPackage=false;
var nothing="";//don't ask


//--------------------------------------------------------
// Use for long select boxes

var alphabet = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

//Jumps down select box to first option text that starts with letter

function goToLetter(selectBox,letter) {
    var idx;
    for (var n = 0; n < selectBox.options.length; n ++) {
        var firstLetter = selectBox.options[n].text.charAt(0).toUpperCase();
        if (firstLetter == letter) {
            idx = n;
            var scroll = selectBox.options.length - 1;
           //This places selected option at top of select box
            selectBox.selectedIndex = scroll;
            selectBox.selectedIndex = idx;
            break;
        } else if (n == selectBox.options.length - 1) {
            if (letter == "A") {
                selectBox.selectedIndex = 0;
            } else if (letter == "Z") {
                selectBox.selectedIndex = selectBox.options.length - 1;
            } else {
                for (var t = 0; t < alphabet.length; t ++) {
                    if (alphabet[t] == letter) {
                        var newLetter = alphabet[t + 1];
                    }
                }
                //IF no options begin with letter, display option that begins with next letter in alphabet
                goToLetter(selectBox,newLetter);
            }
        }
    }
}

function toggleCkbox(id){
	if(document.getElementById){
			document.getElementById(id).checked=true;
			}
		}


//--------------------------------------------------------

//global catch for the exit app
var runUnLoadActivity=true;

// declaring exitapp functions as blank, they get redefined by exitApp.js,
// but this way, if they are called by a page that doesn't call exitApp.js,
// they won't cause errors. - this eliminates the need for switches in the
// body tag.
function unLoadActivity(){};
function onLoadActivity(){};
function noEA(){
	runUnLoadActivity=false;
}

function formHIASubmit() {
// usage - formSubmit('formName', 'replaceFormAction', 'firstElement|firstElementNewValue', 'secondElement|secondElementNewValue')
	var a=formHIASubmit.arguments;
    var f=document[formHIASubmit.arguments[0]];
    f.action = formHIASubmit.arguments[1];
	l=a.length;
	for (i=2; i<l; i+=1){
		pair = a[i].split('|');
		el = pair[0];
		newVal = pair[1];
		f[el].value = newVal;
	}
	f.submit();
	return false;
}

function formSubmit() {
// usage - formSubmit('formName', 'firstElement|firstElementNewValue', 'secondElement|secondElementNewValue')
// you can use as many element/value pairs as you want
	var a = formSubmit.arguments;
	var f = document[formSubmit.arguments[0]];
	for (var i = 1; i < a.length; i++){
		var pair = a[i].split('|');
		var el = pair[0];
		var newVal = pair[1];
		f[el].value = newVal;
	}
	f.submit();
	return false;
}

function dpToggle(x){
	document.getElementById('check' + x).checked=true;
	document.dpswitch.submit();
}

function goTo(URL) {
	self.location = URL;
}

//Set the max characters on a textarea (doesnt accept "maxlength" property like text fields) - onkeyup, onkeypress, onkeydown events
function restrictLength(field,n) { //n is the max characters allowed
	if (field.value.length > n) {
		field.value = field.value.substring(0,n);
	}
}

