var strLinks;
var NavLeftlength;
var NavToplength;
var strNoLinks;
//var MaxVRBug = 0;

function sendPopUpMarketingSpot(link,httppath,linktitle) {
	/*var begin = link.indexOf("mpe_id");

	var end = link.indexOf("intv_id");
	var mpe_id = link.substring(begin+7, end-1);
	begin = link.indexOf("intv_id");
	end = link.indexOf("URL");
	var intv_id = link.substring(begin+8, end-1);			

	var urlfinal = httppath+"ClickInfo?evtype=CpgnClick&amp;mpe_id="+mpe_id+"&amp;intv_id="+intv_id+link;

	var widthPop = linktitle.substring(0, linktitle.indexOf(","));
	var heightPop = linktitle.substring(linktitle.indexOf(",")+1, linktitle.length);
				  
	var str = "height=" + heightPop + ",innerHeight=" + heightPop +",width=" + widthPop +",innerWidth=" + widthPop;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - 400) / 2;
		var yc = (ah - 120) / 2-50;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}

	pop = window.open(urlfinal ,"pop",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,' + str);*/
}			

function sendMarketingSpot(link,httppath) {
	/*begin = link.indexOf("mpe_id");
	end = link.indexOf("intv_id");
	mpe_id = link.substring(begin+7, end-1);
	begin = end;
	end = link.indexOf("URL=");
	intv_id = link.substring(begin+8, end-1);
	begin = end;

	url = link.substring(begin + 4, link.length);
	
	// pass everything in POST
	document.myForm.URL.value = url;
	document.myForm.evtype.value = "CpgnClick";
	document.myForm.mpe_id.value = mpe_id;
	document.myForm.intv_id.value = intv_id;

	document.myForm.action = httppath + "ClickInfo";
	
	// strip krypto from referer URLs (we get an error otherwise)
	document.myForm.TravelAgency_CustFavPageUrl.value = "";
	document.myForm.TravelAgency_ReferPageUrl.value = "";
	document.myForm.completeURL.value = "";
	
	document.myForm.submit();*/
}


function popWinHostName(urlval,x,y,z){
	//urlval = hostName() + urlval;
	popWin(urlval,x,y,z);
}

function aHrefHostName(urlval){
	//urlval = hostName() + urlval;
	document.location = urlval;
}

function retrieveQuote(){
	//is called to see details for a specified quote number:
	if (document.myForm.elements[FN_BOOKING_NUMBER].value.length <= 0) {
		alert("You must enter a Quote Number:");
	} else {
		document.myForm.action = "PTCLoadItineraryAction.do";
		document.myForm.submit();
	}
}


function addFavorites(pageName) {
	popWin('',400,200,0);
	document.myForm.TravelAgency_CustFavPageTitle.value = pageName;	
	document.myForm.target = 'pop'; 
	document.myForm.action = "MemberFavoritePageAddCmd.do"; 
	document.myForm.submit();
	document.myForm.target = '_top'; 
	}

function logOut(url) {
	createCookie("AutoLogonForUser");
	document.location = "Logoff.do?URL=" + url;
	}
	
function eraseCookie(name)	{
	createCookie(name,"",-1);
	}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	}



function getSelectValue(elm){
	return elm.options[elm.selectedIndex].value;
}

function init()
	{
	
	initlayers();

	// Nav top positioning
	x = 749;
	
	for(navTop=NavToplength; navTop > 0 ; navTop--) {
		tmp = eval("t" + navTop);
		tmpMenu = eval("t" + navTop + "menu");
		
		curX = x-tmp.getwidth();
		
		tmp.setxy(curX,utils.getheight()+5);
				
		tmp.menu = navTop;
		tmp.onmouseover = oversec;
		tmp.onmouseout = outsec;
		tmp.setbgcolor('99CC33');
		
		if(!strLinks) { 
			var xy =  tmp.getx()+tmpMenu.getwidth();
			if(xy > 749) tmpMenu.setx(749-tmpMenu.getwidth());
			else tmpMenu.setx(curX);
			tmpMenu.menu = navTop;
			tmpMenu.onmouseover = oversec;
			tmpMenu.onmouseout = outsec;
			tmpMenu.setbgcolor('0066FF');
			}
			
		tmp.show();
		//x -= tmp.getwidth()+1;
		x -= tmp.getwidth();
		}
	if(NavToplength > 0) searchEngine.show();


	// Nav Left positioning
	y = 139;
	for(navLeft=0; navLeft < NavLeftlength; navLeft++) {
		if (!window["l" + navLeft])
			continue;
		
		var tmpL = eval("l" + navLeft);
		tmpL.menu = navLeft;
		tmpL.onmouseover = oversecL;
		tmpL.onmouseout = outsecL;
		tmpL.setbgcolor('000066');
		tmpL.sety(y);
		tmpL.show();

		if(!strLinks) {				
			var tmpMenuL = eval("l" + navLeft + "menu");
			tmpMenuL.menu = navLeft;
			tmpMenuL.onmouseover = oversecL;
			tmpMenuL.onmouseout = outsecL;
			tmpMenuL.setbgcolor('0066FF');
			tmpMenuL.sety(y-1);
			}
			
		y += tmpL.getheight();
		}	
			
	// detect for the map Of MaxVR
	if(isie) MaxVRBug = (document.all.maxvrmap) ? (isie55up) ? 0 : 1 : 0;
	else MaxVRBug = 0;
	}
	
function oversec() {
	if((isns4) && (this.menu > 4) && (!strLinks)) searchEngine.hide();
	
	tmp = eval("t" + this.menu);
	tmp.setbgcolor('CCFF66');		
	if(!strLinks) {
		tmp = eval("t" + this.menu + "menu");
		tmp.show();
		}
	}	

function outsec() {
	if((isns4) && (this.menu > 4)) searchEngine.show();

	tmp = eval("t" + this.menu);
	tmp.setbgcolor('99CC33');	
	tmp = eval("t" + this.menu + "menu");
	tmp.hide();
	}

function oversecL() {
	tmp = eval("l" + this.menu);
	tmp.setbgcolor('000099');
	if(!strLinks) {
		tmp = eval("l" + this.menu + "menu");
		tmp.show();
		}

	if((MaxVRBug) && (this.menu == 11)) document.all.maxvrmap.style.visibility = "hidden";
	}	

function outsecL() {
	tmp = eval("l" + this.menu);
	tmp.setbgcolor('000066');
	tmp = eval("l" + this.menu + "menu");
	tmp.hide();

	if((MaxVRBug) && (this.menu == 11)) document.all.maxvrmap.style.visibility = "visible";
	}


function popWin(url,w,h,scroll) {

	if (arguments.length == 5){
		w = arguments[2];
		h = arguments[3];
		scroll = arguments[4];
	}
  	var str = "height=" + h + ",innerHeight=" + h;
	str += ",width=" + w + ",innerWidth=" + w;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = (aw - w) / 2;
		var yc = (ah - h) / 2;

		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
		}
		
		open(url,"pop",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + scroll + ',resizable=1,' + str)
	//	pop = window.open(url,"pop",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + scroll + ',resizable=1,' + str);
	}

	/*
function filterAmpersands(stringIn) {
	var stringOut = "";
	var pos = 0;
	while (pos < stringIn.length) {
		var end = stringIn.length;
		if (stringIn.indexOf("&amp;", pos) > -1) {
			end = stringIn.indexOf("&amp;", pos);
		}
		stringOut += stringIn.substring(pos, end) + "&";
		pos = end + 5;
	}
	return stringOut;
	}
	*/

function getSearchAsArray() {
	var paramString = window.location.search;
	if (paramString == "" && gTheme.length > 4) {
	  // reconstitute parameters from gTheme array
    paramString = "?dateBegin=" + gTheme[4] + "&dateEnd=" + gTheme[5] + "&disabledDays=" + gTheme[6] + "&disabledRanges=" + gTheme[7];
	}
	
	var pos = 1;
	var params = new Array();
	
	while (pos < paramString.length) {
		var name = paramString.substring(pos, paramString.indexOf('=', pos));
		var end = paramString.length;
		if (paramString.indexOf('&', pos) > -1) {
			end = paramString.indexOf('&', pos);
		}
		var value = paramString.substring(paramString.indexOf('=', pos) + 1, end);
		
		params[name] = unescape(value);
		pos = end + 1;
		}
	return params;
	}

function trim(strToTrim) {
	while (strToTrim.charAt(strToTrim.length-1)==' ') {
		strToTrim = strToTrim.substring(0, strToTrim.length-1);
		}
	return strToTrim;
	}

var WaitWindow = null;
var WaitWindow_closed = false;

function popWaitWindow(type) {
  	var str = "height=400,innerHeight=400,width=400,innerWidth=400";
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - 400) / 2;
		var yc = (ah - 400) / 2-50;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}
	WaitWindow = window.open("RequestProcessing.do?type=" + type,"WaitWindowID",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,' + str);
	
	if (WaitWindow_closed) {
		WaitWindow_closed = false;
    	}
}
	
function closePopWaitWindow() {
    if (WaitWindow != null) {
        if (!WaitWindow_closed) {
            WaitWindow_closed = true;
            WaitWindow.close();
        	}
    	}
	}

function errorMessage(msg) {
    msgTxt = msg;
    setTimeout('alert(msgTxt)',500);

	}
	
/**
 * Email validation method.
 * This method goes through every character in the parameter string,
 * and makes sure it is a valid e-mail.
 *
 * Email will be separated in segments and separators for verification.
 * Segments may include any alphanumerical characters, as well as the dash(-) and underscore(_).
 * Separators can be either dots(.) or the at(@) character.
 * Other characters are NOT allowed.
 *
 * The rules are as follows:
 * -There must be one and only one at (@) separator.
 * -Each segment must be at least 2 characters long.
 * -Email must start and end with segments.
 * -There must be at least two segments after the @ character.
 */

function isEmail(email){
	if (new String(email) == "undefined") { return false; }

    var reg = /^[A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)*[@][A-Za-z0-9_\-]+([.][A-Za-z0-9_\-]+)+$/;
	
	if (reg.test(email)) { return true; }
	return false;
}
function checkEmail(str){
	var isValid = isEmail(str);
    if (str.length == 0) {
		alert("Please enter an e-mail address.");
	}
	else if (!isValid) {
		alert("\"" + str + "\" is not a valid e-mail address.\nPlease enter a correct address.");
	}
   
   return isValid;
}


/***************************************************************************
 * This function allows a drop list to be filtered according to a pattern, *
 * with elements of the drop list which match the pattern at the top       *
 * and the ones that don't at the bottom, separated by a white line.       *
 ***************************************************************************/

/*
  Author: Justin Whitford
  Source: www.evolt.org
*/
function filtery(pattern, list){
  /*
  if the dropdown list passed in hasn't
  already been backed up, we'll do that now
  */
  if (!list.bak){
    /*
    We're going to attach an array to the select object
    where we'll keep a backup of the original dropdown list
    */
    list.bak = new Array();
    for (n=0;n<list.length;n++){
      list.bak[list.bak.length] = new Array(list[n].value, list[n].text);
    }
  }

  /*
  We're going to iterate through the backed up dropdown
  list. If an item matches, it is added to the list of
  matches. If not, then it is added to the list of non matches.
  */
  match = new Array();
  nomatch = new Array();
  for (n=0;n<list.bak.length;n++){
    if(list.bak[n][1].toLowerCase().indexOf(pattern.toLowerCase())!=-1){
      match[match.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }else{
      nomatch[nomatch.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }
  }

  /*
  Now we completely rewrite the dropdown list.
  First we write in the matches, then we write
  in the non matches
  */
  for (n=0;n<match.length;n++){
    list[n].value = match[n][0];
    list[n].text = match[n][1];
  }
  for (n=0;n<nomatch.length;n++){
    list[n+match.length].value = nomatch[n][0];
    list[n+match.length].text = nomatch[n][1];
  }

  /*
  Finally, we make the 1st item selected - this
  makes sure that the matching options are
  immediately apparent
  */
  list.selectedIndex=0;
}



/***************************************************************************
 * This version of the function searches for a pattern FIRST in the keys,  *
 * then in the text values of the list.                                    *
 ***************************************************************************/
function filtery2(pattern, list){
  /*
  if the dropdown list passed in hasn't
  already been backed up, we'll do that now
  */
  if (!list.bak){
    /*
    We're going to attach an array to the select object
    where we'll keep a backup of the original dropdown list
    */
    list.bak = new Array();
    for (n=0;n<list.length;n++){
      list.bak[list.bak.length] = new Array(list[n].value, list[n].text);
    }
  }

  /*
  We're going to iterate through the backed up dropdown
  list. If an item matches, it is added to the list of
  matches. If not, then it is added to the list of non matches.
  */
  codePattern = 'code__.__';
  match = new Array();
  nomatch = new Array();

  for (n=0;n<list.bak.length;n++){
    if(list.bak[n][0].toLowerCase().indexOf(codePattern + pattern.toLowerCase())!=-1){
      match[match.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }
  }

  for (n=0;n<list.bak.length;n++){
    if(list.bak[n][1].toLowerCase().indexOf(pattern.toLowerCase())!=-1){
      if(list.bak[n][0].toLowerCase().indexOf(codePattern + pattern.toLowerCase())==-1){
        match[match.length] = new Array(list.bak[n][0], list.bak[n][1]);
      }
    }else{
      nomatch[nomatch.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }
  }

  /*
  Now we completely rewrite the dropdown list.
  First we write in the matches, then we write
  in the non matches
  */
  for (n=0;n<match.length;n++){
    list[n].value = match[n][0];
    list[n].text = match[n][1];
  }
  for (n=0;n<nomatch.length;n++){
    list[n+match.length].value = nomatch[n][0];
    list[n+match.length].text = nomatch[n][1];
  }

  /*
  Finally, we make the 1st item selected - this
  makes sure that the matching options are
  immediately apparent
  */
  list.selectedIndex=0;
}


function filteryIC(pattern, list){

  /*
  We're going to iterate through the backed up dropdown
  list. If an item matches, it is added to the list of
  matches. If not, then it is added to the list of non matches.
  */
  codePattern = 'code__.__';
  match = new Array();
  nomatch = new Array();

   for (n = 1; n < departureCityList.length; n++){
      if(departureCityList[n].value.toLowerCase().indexOf(codePattern + pattern.toLowerCase())!=-1){
         match[match.length] = new Array(departureCityList[n].value, departureCityList[n].text);
      }
   }
  
  // Search for city name
  for (n = 1; n < departureCityList.length; n++){
    if(departureCityList[n].text.toLowerCase().indexOf(pattern.toLowerCase())!=-1){
      if (departureCityList[n].value.toLowerCase().indexOf(codePattern + pattern.toLowerCase())== -1){
        match[match.length] = new Array(departureCityList[n].value, departureCityList[n].text);
      }
    }else{
		nomatch[nomatch.length] = new Array(departureCityList[n].value, departureCityList[n].text);
    }
  }

  /*
  Now we completely rewrite the dropdown list.
  First we write in the matches, then we write
  in the non matches
  */
  clearOptionList(list);
  
  for (n = 0; n < match.length; n++){
	list[n] = new Option(match[n][1],match[n][0])
    //list[n].value = match[n][0];
    //list[n].text = match[n][1];
  }
  
  var matchLength = match.length;
	if (match.length > 0){
		list[matchLength] = new Option("","");
		matchLength++;
	}
	
  for (n = 0; n < nomatch.length; n++){
	list[n + matchLength] = new Option(nomatch[n][1],nomatch[n][0])
  }

  /*
  Finally, we make the 1st item selected - this
  makes sure that the matching options are
  immediately apparent
  */
 
  if (match.length > 0){
	list.options[0].selected = true;
   departureCityOID_click(list);
  }
  else
	list.selectedIndex = -1;
}




	
/****************************************************************************************
 * These two functions allow you to handle pages that have submit buttons and other     *
 * fields that require a page refresh.  Fields that require a page refresh should call  *
 * the refresh() method, supplying the following arguments:                             *
 *                                                                                      *
 *    refreshSourceField   field of the form that will contain the name of field that   *
 *                         initiated the refresh.  It will be set using the value in    *
 *                         the refreshSource parameter.                                 *
 *    refreshSource        Name of the field that initiated the refresh.  Used to set   *
 *                         the value of the refreshSourceField field.                   *
 *    formToSubmit         Form that must be submitted to refresh the page.             *
 *    formToSubmitAction   Optional parameter.  If set, the function will change the    *
 *                         target URL of the form to this value.                        *
 *                                                                                      *
 * Other submit buttons or anchor tags should invoke the submit() method, supplying     *
 * the following arguments:                                                             *
 *                                                                                      *
 *    submitActionField    field of the form that will contain the name of action that  *
 *                         was requested.  It will be set using the value in the        *
 *                         submitAction parameter.                                      *
 *    submitAction         Name of the requested action for the post.  Used to set the  *
 *                         value of the submitActionField field.                        *
 *    formToSubmit         Form that must be submitted.                                 *
 *    formToSubmitAction   Optional parameter.  If set, the function will change the    *
 *                         target URL of the form to this value.                        *
 ****************************************************************************************/

var refreshFormMessage = "A change to one of the fields of the form requires a refresh of the page, the form was not submitted but the page will refresh.";
var requiresRefresh = false;
var refreshForm;
var undefined = null;

function refresh(refreshSourceField, refreshSource, formToSubmit, formToSubmitAction) {
	refreshSourceField.value = refreshSource;
	requiresRefresh = true;
	refreshForm = formToSubmit;
	if (formToSubmitAction != undefined) {
		formToSubmit.action = formToSubmitAction;
		}
		setTimeout("refreshForm.submit();", 300);
	}

function submit(submitActionField, submitAction, formToSubmit, formToSubmitAction) {
	if (requiresRefresh) {
		setTimeout("alert(refreshFormMessage);", 100);
		return;
		}
	submitActionField.value = submitAction;
	if (formToSubmitAction != undefined) {
		formToSubmit.action = formToSubmitAction;
		}
	formToSubmit.submit();
	}

function formatMoney( v ){
	if (isNaN(v)){
		return "";
	}
	else{
		// patch for decimal with parseFloat method
		v = v * 100;
		v = new String(v);
		if (v.indexOf(".") != -1)
			v = v.substr(0, v.indexOf("."));

        if (v < 100)
            v = "0." + v.substring(v.length-2, v.length)		
        else
            v = v.substring(0,v.length - 2) + "." + v.substring(v.length-2, v.length)      
		//------
        
		var re = new RegExp(/^\d+\.\d{2}$/); // 0.00
		var re1 = new RegExp(/^\d+\.\d$/); // 0.0
		var re2 = new RegExp(/^\d+$/); // 0
        
		if (re.test(v))
			v = v;
		else if (re1.test(v))
			v = v + "0";
		else if (re2.test(v))
		 	v = v + ".00";
		return v;
	}
}

function PHFormatMoney( v ){
    v = formatMoney(v)
    return pComma(v);
}
   
      function pComma(v){
		
      		v = new String(v);
		if (v.length > 6) {
			v = v.substring(0, ( v.length - 6)) + "," + v.substr(v.length - 6, v.length)
      		}
      		
		if (v.length > 10) {
			v = v.substring(0, ( v.length - 10)) + "," + v.substr(v.length - 10, v.length)
      		}
      		return v;
      }

// ***********************************************************
// Code to disable click on the page, and reactivate it when the page is loaded.
// ***********************************************************	
var ns = (document.layers)? true:false;
var ie = (document.all)? true:false;
//if (ns) document.captureEvents(Event.MOUSEDOWN || Event.CLICK);
//document.onclick = disableClick;
//document.onmousedown = disableClick;

// ***********************************************************
function disableClick(e) {
  if (ns&&(e.which==1)) alert('Please wait, the page is loading...');
  else if (ie&&(window.event.button==1)) alert('Please wait, the page is loading...');
  else return true;
  }

//***********************************************************
function enableClick() {
	if(ns) { 
		document.releaseEvents(Event.MOUSEDOWN || Event.CLICK);
	} else {
		document.onclick = null;
		document.onmousedown = null;
		}
	}

function isAlphabetic(testVal) {
	var legalChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
	var i;

	for (i = 0; i < testVal.length; i++) {
		var aChar = testVal.charAt(i);

		if (legalChars.indexOf(aChar) == -1) return false;
	}

	return true;
}

// Javascript Basic Hashtable
/**
 * USAGE : 
 *
 * //declare an instance
 * var items = new Hashtable();
 *
 * //add values to the hashtable
 * items.put("key1", "value1");
 * items.put("key2", "value2");
 * items.put("key3", "value3");
 *
 * //get an item from the hastable
 * alert(items.get("key2"));
 * 
 * N.B.: The Hashtable is also in Utils.js
 */

Hashtable.prototype.hash = null;
Hashtable.prototype.keys = null;
Hashtable.prototype.location = null;

function Hashtable(){
	this.hash = new Array();
	this.keys = new Array();

	this.location = 0;
}

Hashtable.prototype.get = function (key){
	return this.hash[key];
}

Hashtable.prototype.put = function (key, value){
	if (value == null){ return null; }
	if (this.hash[key] == null){ this.keys[this.keys.length] = key; }
	this.hash[key] = value;
}