

var frontierProtocol = 'http';
var frontierHTTPHost = 'ctest.best-rez.com';
var frontierBaseUrl = '/site';
var frontierURL = frontierProtocol+'://'+frontierHTTPHost+''+frontierBaseUrl;
var frontierSkin = 'ctest.best-rez.com';
var frontierLocale = 'en_GB';

/*
* Description : Adds to DOM the jsEnabled class name to indicate javascript availability 
*/
if (document.documentElement && document.getElementById) {
	document.documentElement.setAttribute('class','jsEnabled');
	document.documentElement.className = 'jsEnabled'; //For IE
}

/*
* Description: Include the lm library - important
*/
if( (typeof lm!='object') || (typeof lm == 'object' && !lm.loaded) ){		
	document.write('<script type="text/javascript" src="' + frontierURL + '/lm.js?skin=' + frontierSkin + '"></script>');
	document.write('<script type="text/javascript" src="' + frontierURL + '/lm_recently_search_template_title.js?skin=' + frontierSkin + '"></script>');
}


/*
* Description - Legacy onload function to use lm library addEvent
*/
function SafeAddOnload(f){	
	lm.addEvent({fn:f});
}

/*
* Description: Cookie read and create, and query string read param functions below
*/
function createCookie(name, value, days) {
	lm.cookie.create({name: name, value: value, expire: days});	
}

function readCookie(name){
	if (lm.cookie && lm.cookie[name]) {		
		return lm.cookie[name];		
	} else {
		return '0';
	}
}

function readQueryString(param) {
	if (lm.querystring[param]) {
		return lm.querystring[param];
	} else {
		return false;		
	}
}

/*
* Define a random number variable. Used as a param to js ads in master banners 
*/
var randNum = new Date().getTime();


/*
* Description: 
*/
function RTeCollector(strParam) {var intHeight = 460; var intWidth = 640; var intTop= ((screen.height/2)-(intHeight/2)); var intLeft= ((screen.width/2)-(intWidth/2)); var strFeatures='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,height='+intHeight+',width='+intWidth+',top='+intTop+',left='+intLeft;var winEcollector = window.open('http://ecollector.responsetek.com/eCollector.asp?' + strParam, 'eCollector', strFeatures); }
function RenderPopup(windowsource,windowname,width,height,scrollbars,directories,location,menubar,status,toolbar,resizable) {  var windowfeatures = 'width=' + width +  ',height=' + height + ',directories=' + directories +  ',location=' + location + ',menubar=' + menubar +  ',scrollbars=' + scrollbars + ',status=' + status +  ',toolbar=' + toolbar + ',resizable=' + resizable;  window.open(windowsource, windowname, windowfeatures);  }
function LMN_showhidelayer(lyrName, show) { if (document.getElementById) {var obj = lm.e(lyrName); obj.style.display = show ? "block" : "none"; } else if(document.all) {document.all[lyrName].style.display = show ? "block" : "none";} else if(document.layers) {document.layers[lyrName].display = show ? "block" : "none";}}
function isValidEmail(emailAddress) {var atIndex = emailAddress.indexOf('@');var dotIndex = emailAddress.indexOf('.',atIndex);if( (0 < atIndex) && (atIndex < dotIndex) && (dotIndex < emailAddress.length-1) ) {var firstChar = emailAddress.charAt(0); if( (firstChar >= 'a' && firstChar <= 'z') || (firstChar >='A' && firstChar <= 'Z') || (firstChar >= '0' && firstChar <='9') ) { for (var i=1, j = emailAddress.length; i < j; ++i) {  if(emailAddress.charCodeAt(i) <= 0x20){  if(emailAddress.charAt(i) == ' ') {   alert("There are no spaces allowed in your email address"); }  else { alert("The character \"" + emailAddress.charAt(i) + "\" is not allowed in your email address");   }  return false;  }   }  return true;     }   alert("The first character in your email address, \"" + firstChar + "\" is not allowed"); } alert("Please enter a full email address"); return false; }

// Function used on travel/flights/deals section pages to populate the flights search form
function prePopulate(dep,dest,airline) {
	if (document.getElementById) {
		var fieldsId = ['departurePoint','destination','airline'];
		var formField;		
		for(var i=0, j=fieldsId.length; i < j; i++) {
			if(formField = lm.e(fieldsId[i])) {				
				if(formField.type == 'select-one') {					
					for (var x=0, y=formField.length; x < y; x++) {
						if(formField.options[x].text == dep || formField.options[x].text == airline) { 
							formField.selectedIndex = 1;
						}							
						if (!(airline)) {
							formField.selectedIndex = 0; 
						}
					}				
				} 				
				if (formField.type == 'text') { 
					formField.value = dest;	
				}
			}
		}
	}
}


/* 
* Descriotion: Set a LAB cookie for (Lightweight A-B Testing) 
*/
var lab_numGroups=6;
function lab_getCookieVal(offset){var endstr=document.cookie.indexOf(";",offset);if(endstr==-1){endstr=document.cookie.length;}return unescape(document.cookie.substring(offset, endstr));}
function lab_getCookie(name){var arg=name + "=";var alen=arg.length;var clen=document.cookie.length;var i=0;while(i < clen){var j = i + alen;if (document.cookie.substring(i, j) == arg) return lab_getCookieVal (j);i = document.cookie.indexOf(" ", i) + 1;if (i == 0) break;}return null;}
var labIndex = document.location.href.indexOf('LAB=');
if(labIndex>-1)	{
	var lab_group = document.location.href.slice(labIndex+4,labIndex+5);
    if(s_account=='ctest.best-rez.com') {
		document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=ctest.best-rez.com";
	} else {
		document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=ctest.best-rez.com";
	}
} else {	
	var lab_group = lab_getCookie('LLAB');
	if (lab_group==null) {
		lab_group=''+Math.floor(Math.random()*lab_numGroups);
      if(frontierSkin=='engb.travelocity.co.uk') { //Use skin to detect domain
         document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=ctest.best-rez.com";}
      else {
      	document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=ctest.best-rez.com"; }
      }
}

/*
* Description: View product images thumbnail as larger image - on UI details pages
*/
function thumbnailSwitch(targetId,imageSrc,caption){
	lm.e(targetId).src = imageSrc;	
	if (lm.e(targetId + 'Caption')) {
		lm.e(targetId + 'Caption').innerHTML = caption;
	}
}

/*
* Toggle popups
*/
function togglePopup(obj){	
	var bubbleContainer = lm.e(obj.href.split('#')[1]);
	var masterContainer = lm.e('master_center');
	var pageContent = lm.e('page_content');
	var iframeId = 'underIframe' + obj.href.split('#')[1]
	var popupsOnScreen = lm.getElementsBy({tagName:'div', className:'bubbleText', filter:function(item){
			return (item.style.visibility=='visible')
		}
	});	
	var zInd = (popupsOnScreen.length) ? popupsOnScreen[popupsOnScreen.length-1].style.zIndex+1 : Math.floor(Math.random() * 1000);
	lm.addEvent({e:bubbleContainer.getElementsByTagName('a')[0], eT:'click', fn:function(e){		
		lm.styles(bubbleContainer, {visibility:'hidden', left:-1000, top:-1000});
		masterContainer.style.zIndex = '2';
		if (lm.e(iframeId)) pageContent.removeChild(lm.e(iframeId));		
		if (!e) e = window.event;
		if (e.preventDefault) {
			e.preventDefault();
		} else {
			e.returnValue = false;															 
		}
	}});
	var isIE6 = /msie ([0-6]{1,}[\.0-9]{0,})/.test(navigator.userAgent.toLowerCase());
	if ( !lm.e(iframeId) && isIE6 && navigator.userAgent.indexOf('opera')==-1) {		
		new lm.element.block({p: 'page_content', tagName: 'iframe', id: iframeId, frameBorder: '0', scrolling: 'no', src: 'javascript:false;'})
		var iframeReference = lm.e(iframeId);		
		lm.styles(iframeReference, {
			position: 'absolute',
			left: lm.getLeft(obj) - lm.getLeft(pageContent) - 35, 
			top: lm.getTop(obj) - lm.getTop(pageContent) - bubbleContainer.offsetHeight, 
			width: bubbleContainer.offsetWidth,
			height: bubbleContainer.offsetHeight,
			zIndex: zInd - 1,
			filter: 'alpha(opacity=0)'
		});			
	}
	masterContainer.style.zIndex = '25';
	lm.styles(bubbleContainer, {visibility:'visible', left: lm.getLeft(obj) - lm.getLeft(pageContent) - 30, top:lm.getTop(obj) - lm.getTop(pageContent) - bubbleContainer.offsetHeight, zIndex: zInd});
}

/*
* Toggle popups - left nav hack
*/
function togglePopupLeft(obj){	
	var bubbleContainer = lm.e(obj.href.split('#')[1]);
	var masterContainer = lm.e('master_left');
	var pageContent = lm.e('dpLeftNav');
	var iframeId = 'underIframe' + obj.href.split('#')[1]
	var popupsOnScreen = lm.getElementsBy({tagName:'div', className:'bubbleText', filter:function(item){
			return (item.style.visibility=='visible')
		}
	});	
	var zInd = (popupsOnScreen.length) ? popupsOnScreen[popupsOnScreen.length-1].style.zIndex+1 : Math.floor(Math.random() * 1000);
	lm.addEvent({e:bubbleContainer.getElementsByTagName('a')[0], eT:'click', fn:function(e){		
		lm.styles(bubbleContainer, {visibility:'hidden', left:-1000, top:-1000});
		masterContainer.style.zIndex = '2';
		if (lm.e(iframeId)) pageContent.removeChild(lm.e(iframeId));		
		if (!e) e = window.event;
		if (e.preventDefault) {
			e.preventDefault();
		} else {
			e.returnValue = false;															 
		}
	}});
	var isIE6 = /msie ([0-6]{1,}[\.0-9]{0,})/.test(navigator.userAgent.toLowerCase());
	if ( !lm.e(iframeId) && isIE6 && navigator.userAgent.indexOf('opera')==-1) {		
		new lm.element.block({p: 'page_content', tagName: 'iframe', id: iframeId, frameBorder: '0', scrolling: 'no', src: 'javascript:false;'})
		var iframeReference = lm.e(iframeId);		
		lm.styles(iframeReference, {
			position: 'absolute',
			left: lm.getLeft(obj) - lm.getLeft(pageContent), 
			top: lm.getTop(obj) - lm.getTop(pageContent) - bubbleContainer.offsetHeight, 
			width: bubbleContainer.offsetWidth,
			height: bubbleContainer.offsetHeight,
			zIndex: zInd - 1,
			filter: 'alpha(opacity=0)'
		});			
	}
	masterContainer.style.zIndex = '25';
	lm.styles(bubbleContainer, {visibility:'visible', left: lm.getLeft(obj) - lm.getLeft(pageContent), top:lm.getTop(obj) - lm.getTop(pageContent) - bubbleContainer.offsetHeight, zIndex: zInd});
}


/* 
* Description - Price formatter functions
*/

function currencyStrip(amount) {
	if (amount.constructor.name == "String") return parseFloat(amount.match(/(\d{1,3},?)+([,|.]\d+)?/g)[0].replace(/,/g,''));
}

function currencyFormat(amount, currencyCode, locale, decimalPoints, currencyRoundUp) {
 	var decimalPoints = decimalPoints || 0;
	var currencyRoundUp = currencyRoundUp || false;
	var amount = (currencyRoundUp) ? amount + '' : parseFloat(amount).toFixed(decimalPoints); 
 	if (currencyRoundUp){
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(amount)) {
			amount = amount.replace(rgx, '$1' + ',' + '$2');
		}		
	}

	var currencyCodes = {
		'EUR' : "&euro;",
		'GBP' : "&pound;",
		'INR' : "Rs",
		'HKD' : "HKD",
		'AUD' : "AUD",
		'SGD' : "SGD"};
 
	switch(locale) {
	case 'en_GB':
		return currencyCodes[currencyCode] + amount;
		break
	case 'es_ES':		
	case 'fr_FR':
		return amount + ' ' + currencyCodes[currencyCode];
		break
	case 'en_IN':
	case 'it_IT':
	case 'en_HK':
	case 'en_AU':
	case 'en_SG':
		return currencyCodes[currencyCode] + ' ' + amount;
		break
	default:
		return amount + '?';
	}
}

/*
* Description : Airport code finder
*/
var originOrDestination = 'D'; //Updates the airport name field in Search with the name found by the service
//Takes the value entered and send this to the page calling the service
function findDestination(url,field) {
    var airportCodes = lm.e(field);
	var value = (airportCodes)? airportCodes.value : '';
	var urlString = url;		
	if (urlString.indexOf('?') == -1) {
		var location = '?location=';
	}		
	else {
		var location = '&'+'location=';	
	}		
	var url = urlString + location + value + '&'+'fieldName=' + field;
	window.open(url,'findAiports','width=300,height=300,resizable=0,status=yes,scrollbars=yes');
	originOrDestination = 'D'
}

/* 
 * Description: Replace the value of the field with the value found by the service
 */
function setDestination(text, field) {
	lm.e(field).value = text;
}

/*
* Description : calendar positioning hack
*/
var hijackShowCalendarTimer=-1;var calendarIframe=false;function hijackShowCalendar(){if(typeof showCalendar=="function"){clearTimeout(hijackShowCalendarTimer);showCalendar=function(e){var o=(typeof event!="undefined")?event.srcElement:e.target;var _3=lm.e("cIframe");if(!calendarIframe){_3.style.visibility="hidden";calendar.show(0,0);calendarIframe={left:lm.getLeft(_3),top:lm.getTop(_3)};_3.style.visibility="visible";}calendar.show((lm.getLeft(o)-calendarIframe.left)+o.width+5,lm.getTop(o)-calendarIframe.top);};}else{hijackShowCalendarTimer=setTimeout("hijackShowCalendar()",500);}}hijackShowCalendar();function stopHijackShowCalendarLoop(){if(typeof showCalendar != "function" && hijackShowCalendarTimer != -1){clearTimeout(hijackShowCalendarTimer);}}if(typeof calendar=="object"){var hijackOldOnload = window.onload; if(typeof hijackOldOnload == "function"){window.onload=function(){stopHijackShowCalendarLoop(); hijackOldOnload(); } ; } else {window.onload=stopHijackShowCalendarLoop;}}


/*
* Description : accent strip library
*/
function stripVowelAccent(str, str_type) {var s=str;	var stripped=str; var rExps=[ /[\xC0-\xC5]/g, /[\xE0-\xE5]/g,	/[\xC8-\xCB]/g, /[\xE8-\xEB]/g,	/[\xCC-\xCF]/g, /[\xEC-\xEF]/g,	/[\xD2-\xD6]/g, /[\xF2-\xF6]/g,	/[\xD9-\xDC]/g, /[\xF9-\xFc]/g,/[\xD1]/g, /[\xF1]/g, /[\xC7]/g, /[\xE7]/g ]; var repChar=['A','a','E','e','I','i','O','o','U','u','N','n','C','c']; for(var i=0; i<rExps.length; i++) {	stripped=stripped.replace(rExps[i],'_'); s=s.replace(rExps[i],repChar[i]); } return s; }

/* 
* Description: link the radio buttons for the search box categories in IE
*/ 

if (window.attachEvent){
window.attachEvent("onload", function () {
								var inputs = document.getElementsByTagName('input')
								for(var i = 0;i < (inputs.length -1); i++){
									var input = inputs[i]
									if(input.type=='radio' && input.checked==false && input.name=='' && input.parentNode.tagName=='A'){
										input.onclick = function(){ 
														window.location = this.parentNode.href;
														this.checked = true
													  }
									}
								}
							}				   
					)
}
// --- [end prdpctbd4201:4001 - /site/generic.js - Jul 31, 2008 6:25 am GMT - pct2,pct9 - 8XoZtAqoTFMAADrWrmwAAAAW - cache 1800 ] ---
