/* functions from old generic.js - pre Rebranding */
/*
* 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.id == 'destination') { 
					formField.value = dest;	
				}
                                if (formField.type == 'text' && formField.id == 'departurePoint') {
                                        formField.value = dep;
                                }
			}
		}
	}
}
// get the computed styles on an element 
function getStyle(el,styleProp)
{
	if (el.currentStyle)
		var y = el.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
	return y;
}
// get the computed width of an element 
function getElementWidth(item) {
	if (typeof item.clip !== "undefined") {
		return item.clip.width;
	} else {
		if (item.style.pixelWidth) {
			return item.style.pixelWidth;
		} else {
			return item.offsetWidth;
		}
	}
}
/* 
* 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=='lastmintravelocitycouk') {
		document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=travelocity.co.uk";
	} else {
		document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=lastminute.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=travelocity.co.uk";}
      else {
      	document.cookie="LLAB="+lab_group+";expires=Mon, 14-Jul-2008 00:00:00 GMT;path=/;domain=lastminute.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){	
	if(typeof obj == 'object' && obj.href != undefined) 
		var bubbleContainer = lm.e(obj);
	else if(typeof obj == 'string' && lm.e(obj)) {
		var bubbleContainer = lm.e(obj);
		lm.styles(bubbleContainer, {visibility:'hidden', left:-1000, top:-1000});
		return true
	}
	else return false;
	if(obj.href){ bubbleContainer = lm.e(obj.href.split('#')[1])};
	var masterContainer = lm.e('master_center');
	var positioningDiv = lm.e('page_content');
	var objParent = obj;
	do{
    	objParent = objParent.parentNode
	    currentPosition = getStyle(objParent,'position')
	}
	while((currentPosition != 'relative'  && currentPosition != 'absolute') && objParent != document.body)
		positioningDiv = objParent
	var iframeId = 'underIframe' + obj.href.split('#')[1]
	var popupsOnScreen = lm.getElementsBy({tagName:'div', className:'bubbleText', filter:function(item){
			return (item.style.visibility=='visible' && item.style.display=='block')
		}
	});	
	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',display:'block', left:-1000, top:-1000});
		masterContainer.style.zIndex = '2';
		if (lm.e(iframeId)) positioningDiv.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: positioningDiv, 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(positioningDiv) - (getElementWidth(obj)/2), 
			top: lm.getTop(obj) - lm.getTop(positioningDiv) - bubbleContainer.offsetHeight, 
			width: bubbleContainer.offsetWidth,
			height: bubbleContainer.offsetHeight,
			zIndex: zInd - 1,
			filter: 'alpha(opacity=0)'
		});			
	}
	masterContainer.style.zIndex = '25';
	bubbleContainer.style.display='block'
	lm.styles(bubbleContainer, {visibility:'visible', left: lm.getLeft(obj) - lm.getLeft(positioningDiv) - (getElementWidth(obj)/2), top:lm.getTop(obj) - lm.getTop(positioningDiv) - bubbleContainer.offsetHeight, zIndex: zInd});
}
// Toggle the display of the bubble popup		
function togglePopupBranded(obj,show){
	var offSetFromMouse = [];
	offSetFromMouse[0] = 231;
	offSetFromMouse[1] = 145;
	var divHeight = 0;
	var selects = lm.getElementsBy({parentNode:'page_content', tagName:'select'});	
	if (selects.length) {
		if (show && selects[0].style.visibility != 'hidden'){
			for(var i=0, j = selects.length; i < j; i++) {
				selects[i].style.visibility = 'hidden';
			}
		}		
		else if ( !(show)) {
			for(var i=0, j = selects.length; i < j; i++) {
				selects[i].style.visibility = '';	
			}
		}
	}	
    if (obj.href) {
		var divCont = obj.href.split('#')[1];
		divCont = lm.e(divCont);
		divCont.style.position = 'absolute';
		divCont.style.visibility='visible';
		if (show){
			lm.e('master_center').style.zIndex='12';
			if (divCont.offsetHeight){
				divHeight = divCont.offsetHeight;
			} else if (divCont.style.pixelHeight){
				divHeight=divCont.style.pixelHeight;
			}	
			var curleft = curtop = 0;
			if (obj.offsetParent) {
				curleft = obj.offsetLeft;
				curtop = obj.offsetTop;
				while (obj = obj.offsetParent) {
					curleft += obj.offsetLeft;
					curtop += obj.offsetTop;
				}
			}		
			divCont.style.top=(curtop-offSetFromMouse[1]-divHeight)+'px';
			divCont.style.left=(curleft-offSetFromMouse[0])+'px';
		} else {
			lm.e('master_center').style.zIndex='2';
			divCont.style.left='-1000em';
			divCont.style.top='-1000em';			
		}
	} else {
		divCont = lm.e(obj);	
		divCont.style.position='absolute';
		divCont.style.left='-1000em';
		divCont.style.top='-1000em';
	}
}
/*
* 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 : adds ratefinder popunder to hotels, flights and dp searches
*/
//This function checks the cookie and the flag to determine if the popunder should show
var s_orig, ratefinder_default_cookie_lifetime = 0.014, ratefinder_homepage_cookie_lifetime = 1;
var s_locale = 'es_ES';
function loadPopOrNot() {
	var a_arguments = new Array;
	a_arguments = loadPopOrNot.arguments;
	b_submit = a_arguments[0];
	s_popFlag = a_arguments[1];
	o_form = a_arguments[2];  
	switch(frontierSection)
	{
		case 'main':
			var cookieValue = (lm.cookie.rateFinderMain) ? true : false;
			break;    
		case 'travel/flights':
			var cookieValue = (lm.cookie.rateFinderFlights) ? true : false;
			break;
		case 'travel/hotels':
			var cookieValue = (lm.cookie.rateFinderHotels) ? true : false;
			break;
		case 'travel/holidays/citybreaks':
			var cookieValue = (lm.cookie.rateFinderDP) ? true : false;
			break;
		default:
			var cookieValue = (lm.cookie.rateFinder) ? true : false;
	}
	if ((b_submit) && (s_popFlag == '1') && !cookieValue) {
		if(frontierSection == 'main') lm.cookie.create({name:'rateFinderMain', value:'yes', expire:ratefinder_homepage_cookie_lifetime}) // <--- This sets a cookie for 1 day if the flag is true and there are no form validation prompts
		else if(frontierSection == 'travel/flights') lm.cookie.create({name:'rateFinderFlights', value:'yes', expire:ratefinder_default_cookie_lifetime})
		else if(frontierSection == 'travel/hotels') lm.cookie.create({name:'rateFinderHotels', value:'yes', expire:ratefinder_default_cookie_lifetime})
		else if(frontierSection == 'travel/holidays/citybreaks') lm.cookie.create({name:'rateFinderDP', value:'yes', expire:ratefinder_default_cookie_lifetime})
		else lm.cookie.create({name:'rateFinder', value:'yes'})
		loadpopunder(o_form);
	}
}
function getYearforMonth(m){
    var date = new Date();
    var y = (parseInt(m) >= date.getMonth())? date.getFullYear() : date.getFullYear()+1;
	return y;
}
function replaceChars(str) {
	var oldChar = " "; 
	var newChar = "_"; 
	var temp = str;
	while (temp.indexOf(oldChar)>-1) {
	pos= temp.indexOf(oldChar);
	temp = (temp.substring(0, pos) + newChar + temp.substring((pos + oldChar.length), temp.length));
	}
	return temp;
}
//This function examines the form to see which LOB and the date, then shows the specific ad with params
function loadpopunder(o_form){
 var s_theURL = location.href;
 var formPrefix;
 var i_s59Svc1 = s_theURL.indexOf('S59BT');  // Check for the Site59 tags to disable pops for them
 var s_theDomain = document.location.hostname;
 var s_selectedForm = o_form.name; // Get what form is in focus
 if (s_selectedForm == 'flights_search' || s_selectedForm == 'hotels_search' || s_selectedForm == 'dp_search') {
  if ((s_selectedForm == 'flights_search') || (s_selectedForm == 'dp_search')) {
  	var pu_DepartureDateElement = lm.e('departureDateDay');
	var a_fromDate = pu_DepartureDateElement.options[pu_DepartureDateElement.selectedIndex].value;
	var pu_DepartureMonthElement = lm.e('departureDateMonth');
	var a_fromMonth = pu_DepartureMonthElement.options[pu_DepartureMonthElement.selectedIndex].value;
	var startYear=getYearforMonth(a_fromMonth);
    var pu_DeparturePoint = (lm.e('departurePoint')) ? lm.e('departurePoint') : '';
 	if (pu_DeparturePoint.type == 'text') {
		s_orig = replaceChars(pu_DeparturePoint.value);
		var startingBracket = s_orig.indexOf("(");
		var endingBracket = s_orig.indexOf(")");
		if ((startingBracket!=-1) && (endingBracket!=-1) && (endingBracket>startingBracket)) {
			s_orig = s_orig.substr(startingBracket+1,3);
		}
		if (s_orig==''){
		s_orig = 'ZZZ'; //if input is blank then set to ZZZ
		}
	} else	if (pu_DeparturePoint.type == 'select-one') {
 		s_orig = pu_DeparturePoint.options[pu_DeparturePoint.selectedIndex].value;
 	}
 	var pu_Destination = (lm.e('destination')) ? lm.e('destination') : '';
 	if (pu_Destination.type == 'text') {
		s_dest = replaceChars(pu_Destination.value);
		var startingBracket = s_dest.indexOf("(");
		var endingBracket = s_dest.indexOf(")");
		if ((startingBracket!=-1) && (endingBracket!=-1) && (endingBracket>startingBracket)) {
			s_dest = s_dest.substr(startingBracket+1,3);
		}
		if (s_dest==''){
		s_dest = 'ZZZ'; 
		}
	} else 	if (pu_Destination.type == 'select-one') {
 		s_dest = pu_Destination.options[pu_Destination.selectedIndex].value;
 	} 
	var pu_ReturnDateElement = lm.e('returnDateDay');
	var a_endDate = pu_ReturnDateElement.options[pu_ReturnDateElement.selectedIndex].value;
	var pu_ReturnMonthElement = lm.e('returnDateMonth');
	var a_endMonth = pu_ReturnMonthElement.options[pu_ReturnMonthElement.selectedIndex].value;
	var endYear = getYearforMonth(a_endMonth);
	if (s_selectedForm == 'flights_search') {
		var pu_NoOfAdultsElement = lm.e('adults');
		var noOfAdults= pu_NoOfAdultsElement.options[pu_NoOfAdultsElement.selectedIndex].value ;
	} else if(s_selectedForm == 'dp_search') {
	var pu_NoOfRoomsElement = lm.e('rooms');
	var noOfRooms= pu_NoOfRoomsElement.options[pu_NoOfRoomsElement.selectedIndex].value ;
	var pu_NoOfAdultsElement0 = lm.e('adults0');
	var noOfAdults0= pu_NoOfAdultsElement0.options[pu_NoOfAdultsElement0.selectedIndex].value ;
	var noOfAdults1= lm.e('adults1') ? lm.e('adults1').options[lm.e('adults1').selectedIndex].value : 0;
	var noOfAdults2= lm.e('adults2') ? lm.e('adults2').options[lm.e('adults2').selectedIndex].value : 0;
	var noOfAdults= parseInt(noOfAdults0, 10);
	if (noOfRooms==2) {noOfAdults += parseInt(noOfAdults1, 10)};
	if (noOfRooms==3) {noOfAdults += parseInt(noOfAdults1, 10)+ parseInt(noOfAdults2, 10)};
}
	formPrefix='air';
	urladditions = "\x26noOfAdults=" + noOfAdults + "\x26orig=" +s_orig;
  }
  else {
  //hotels search
  	var pu_DepartureDateElement = lm.e('checkInDay');
	var a_fromDate = pu_DepartureDateElement.options[pu_DepartureDateElement.selectedIndex].value;
	var pu_DepartureMonthElement = lm.e('checkInMonth');
	var a_fromMonth = pu_DepartureMonthElement.options[pu_DepartureMonthElement.selectedIndex].value;
	var startYear=getYearforMonth(a_fromMonth);
 	var pu_Destination = (lm.e('city')) ? lm.e('city') : '';
 	if (pu_Destination.type == 'text'){
		s_dest = replaceChars(pu_Destination.value);
		if (s_dest==''){
			s_dest = 'ZZZ'; 
		}
	 }
 	if (pu_Destination.type == 'select-one') {
 		s_dest = pu_Destination.options[pu_Destination.selectedIndex].value;
 	}
	var pu_ReturnDateElement = lm.e('checkOutDay');
	var a_endDate = pu_ReturnDateElement.value;
	var pu_ReturnMonthElement = lm.e('checkOutMonth');
	var a_endMonth = pu_ReturnMonthElement.value;
	var endYear = getYearforMonth(a_endMonth);
	var pu_NoOfRoomsElement = lm.e('rooms');
	var noOfRooms= pu_NoOfRoomsElement.options[pu_NoOfRoomsElement.selectedIndex].value ;
	var pu_NoOfAdultsElement0 = lm.e('adults0');
	var noOfAdults0= pu_NoOfAdultsElement0.options[pu_NoOfAdultsElement0.selectedIndex].value ;
	var noOfAdults1= lm.e('adults1') ? lm.e('adults1').options[lm.e('adults1').selectedIndex].value : 0;
	var noOfAdults2= lm.e('adults2') ? lm.e('adults2').options[lm.e('adults2').selectedIndex].value : 0;
	var noOfAdults= parseInt(noOfAdults0, 10);
	if (noOfRooms==2) {noOfAdults += parseInt(noOfAdults1, 10)};
	if (noOfRooms==3) {noOfAdults += parseInt(noOfAdults1, 10)+ parseInt(noOfAdults2, 10)};
	formPrefix='hotel';
	urladditions = "\x26noOfAdults=" + noOfAdults + "\x26noOfRooms=" +noOfRooms; 
  }
  var b_bestFareFinder = lm.e('flexibleFlights');
  b_bestFareFinder = (b_bestFareFinder) ?  b_bestFareFinder.checked : false;
  b_bestFareFinder = (b_bestFareFinder) ? true : false;
  var i_dayRange = 16;              // Set valid days between Departure and today
  var b_inDateRng;
  var o_dateDiff=new Date;
  var a_currentYear=o_dateDiff.getFullYear();	
  var o_fromDate=new Date(a_currentYear,a_fromMonth,a_fromDate); // Generate a date Obj from the selection
  var o_currDate= new Date;
  o_dateDiff.setTime(o_fromDate.getTime() - o_currDate.getTime());
  var timeDiff = o_dateDiff.getTime();
  var s_days = Math.floor(timeDiff / (1000 * 60 * 60 * 24)); 
 }
  // Check the Range and Submitted Values
  if((s_days <= i_dayRange) || (b_bestFareFinder)) {
	  if (s_selectedForm == 'dp_search') {s_theAdtoShow = 'ad1';}
	  if (s_selectedForm == 'flights_search') {s_theAdtoShow = 'ad3';}
	  b_inDateRng = true;
  }
  else {
      a_ads = new Array;
	  a_ads[0] = 'ad1'; //Package
  	  a_ads[1] = 'ad3'; //Air
	  s_theAdtoShow = a_ads[Math.floor(Math.random()*2)]; //Package or Air Ad
	  b_inDateRng = false;
  } 
  // Check for WCT Criteria
  if (s_selectedForm == 'hotels_search') {
	  s_theAdtoShow = 'ad2'; //Serves Ad Tag with WCT and Partner Mktg
  }
// *************************************************
var popunderProtocol;
var popunder; 
var winfeatures;
if (s_locale=='en_SG' ) {
	popunderProtocol = (document.location.href.indexOf('site_staging')>-1)? frontierURL : 'http://www.zuji.com.sg/site';
	winfeatures="left=150,top=200,width=720,height=300,scrollbars=0,resizable=1,toolbar=0,location=0,menubar=0,status=1,directories=0";
}else if (s_locale=='en_AU') {
	popunderProtocol = (document.location.href.indexOf('site_staging')>-1)? frontierURL : 'http://www.zuji.com.au/site';
	winfeatures="left=150,top=200,width=720,height=300,scrollbars=0,resizable=1,toolbar=0,location=0,menubar=0,status=1,directories=0";
}else if (s_locale=='en_HK') {
	popunderProtocol = (document.location.href.indexOf('site_staging')>-1)? frontierURL : 'http://www.zuji.com.hk/site';
	winfeatures="left=150,top=200,width=720,height=300,scrollbars=0,resizable=1,toolbar=0,location=0,menubar=0,status=1,directories=0";
}else if (s_locale=='en_IN') {
	popunderProtocol = (document.location.href.indexOf('site_staging')>-1)? frontierURL : 'http://www.travelocity.co.in/site';
	winfeatures="left=150,top=200,width=720,height=300,scrollbars=0,resizable=1,toolbar=0,location=0,menubar=0,status=1,directories=0";
}else {
	popunderProtocol = (document.location.href.indexOf('site_staging')>-1)? frontierURL : 'http://www.lastminute.com/site';
	winfeatures="left=150,top=200,width=510,height=326,scrollbars=0,resizable=1,toolbar=0,location=0,menubar=0,status=1,directories=0";
}
popunder= popunderProtocol + '/commercial/ratefinder_popunder.html';
 var win2 = new Object;
 if(s_theAdtoShow && i_s59Svc1 == '-1'){
	var s_urlString = '?skin='+ frontierSkin + '\x26s_theDomain='+s_theDomain+'\x26s_selectedForm='+s_selectedForm+'\x26a_formPrefix='+formPrefix+'\x26a_fromDate='+a_fromDate+'\x26a_fromMonth='+a_fromMonth+'\x26startYear='+startYear+'\x26endDate='+a_endDate+'\x26endMonth='+a_endMonth+'\x26endYear='+endYear+'\x26s_theAdtoShow='+s_theAdtoShow+'\x26s_dest='+s_dest+'\x26s_ratefinderLocale='+s_locale+urladditions;
// *************************************************
	 win2=window.open(popunder+s_urlString,"adWindow",winfeatures);
	 win2.blur();
	 win2.screenX = 150;
	 win2.screenY = 200;
	 window.focus();
  } 
}
function rateFinderOnload(){
	if(lm.e('flights_search')) {
	lm.addEvent({
		e:lm.e('flights_search'),
		eT:'submit',
		fn:function(){
			o_form = lm.e('flights_search');
			loadPopOrNot(true,'1',o_form);
		}
	})
	} else if(lm.e('lfe_availability')) {
	lm.addEvent({
		e:lm.e('lfe_availability'),
		eT:'submit',
		fn:function(){
			o_form = lm.e('lfe_availability');
			loadPopOrNot(true,'1',o_form);
		}
	})
	}
	if(lm.e('hotels_search')) {
	lm.addEvent({
		e:lm.e('hotels_search'),
		eT:'submit',
		fn:function(){
			o_form = lm.e('hotels_search');
			loadPopOrNot(true,'1',o_form);
		}
	})
	}
}
/* 
* Description: link the radio buttons for the search box categories in IE
*/ 
if (window.addEventListener || window.attachEvent) {
	var fAddOnLoad = 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;
				}
			}
		}
			rateFinderOnload()
	}
	if (window.attachEvent) window.attachEvent("onload", fAddOnLoad); // IE
	else window.addEventListener("load", fAddOnLoad, false); // W3C compliant
}
/* Rebranding JS */
top10Deals = {
	init: function(listId,eventType){
		var DealLists = lm.getElementsBy({tagName:'div', className:listId}) 
		lm.forEach(DealLists,function(item, index){
				var list = lm.getElementsBy({tagName:'ul',parentNode:item})[0]
				var content = lm.getElementsBy({tagName:'div',parentNode:item})[0]
				var content = content.parentNode.tagName == 'DIV' ? content : false
				if(!list) return false;
				var dealListId = index
				if(content){
					var i = 0
					lm.forEach(content.childNodes,function(item,index){
							if(item.tagName=='DIV'){
								item.id= listId +'contentItem'+ dealListId + i
								if(i==0){
									item.removeAttribute('class')
									item.removeAttribute('className')
								}
								i++
							}
						}
					)
				}
				var i = 0;
				lm.forEach(list.childNodes,function(item,index){
					if(item.tagName == 'LI'){																 
						item.id= listId + 'linkItem'+ dealListId + i
						if(!content){
							lm.forEach(item.childNodes,function(item,index){
									if(item.tagName=='DIV'){
										item.id= listId + 'contentItem' + dealListId + i
										if(i==0){
											item.removeAttribute('class')
											item.removeAttribute('className')
										}
									}
								}
							)
						}
						if(i==0){
							item.setAttribute('className','clearFloat active')
							item.className='clearFloat active'
						}
						i++
						lm.addEvent({
									e:item,
									eT:eventType,
									fn:function(){
										var visibleNode = item.id.replace(/link/,'content')
										lm.forEach(lm.getElementsBy({parentNode:list,tagName:'li'}),function(item,index){
												item.className = 'clearFloat';
												if(!content){
													lm.forEach(item.childNodes,function(item,index){
														if(item.tagName=='DIV' && item.id != visibleNode){
															item.setAttribute('class','hide')
															if(item.className != 'hide') item.className='hide'
														}
														else{
															lm.e(visibleNode).removeAttribute('class')
															lm.e(visibleNode).removeAttribute('className')
														}
													})
												}	
										})
										item.setAttribute('class','clearFloat active')
										if(item.className != 'clearFloat active') item.className='clearFloat active'
										if(content){
											lm.forEach(content.childNodes,function(item,index){
													if(item.tagName=='DIV' && item.id != visibleNode){
														item.setAttribute('class','hide')
														if(item.className != 'hide') item.className='hide'
													}
													else{
														lm.e(visibleNode).removeAttribute('class')
														lm.e(visibleNode).removeAttribute('className')
													}
												})
										}
									}
								})
						lm.forEach(item.childNodes,function(item){
								if(item.tagName=='A'){
								   lm.addEvent({
												e:item,
												eT:'click',
												fn:function(e){
													if (!e) e = window.event;
													if (e.preventDefault) e.preventDefault();
													else e.returnValue = false;
												}
										})
								}
									})
					}	
				})
		})
	}
}
top10Deals.init('dealList','mouseover')
top10Deals.init('accordionClick','click')
function mouseOver(){
	var menuNodes = lm.getElementsBy({
									tagName:'li', 
									parentNode:'master_nav',
									filter:function(item){
										    if(item.id) return item;
											}
								})						
	lm.forEach(menuNodes,function(item){
		lm.addEvent({e:item,
					 eT:'mouseover', 
					 fn:function(){
						/*item.setAttribute ("class", "highlight")
						lm.e('tnavSubLinksnav').setAttribute ("class","hidecopy" )
						lm.e('master_nav').setAttribute ("class", "mergebox")*/
						item.className='highlight';
						lm.e('master_nav').className='mergebox';
					}
			})
	})
}
lm.addEvent({fn:mouseOver})
function mouseOut(){
	var menuNodes = lm.getElementsBy({
									tagName:'li', 
									parentNode:'master_nav',
									filter:function(item){
										    if(item.id) return item;
											}
								})						
	lm.forEach(menuNodes,function(item){
		lm.addEvent({e:item,
					 eT:'mouseout', 
					 fn:function(){
						item.removeAttribute('class')
						item.removeAttribute('className')
						lm.e('master_nav').removeAttribute('class')
						lm.e('master_nav').removeAttribute('className')
					}
			})
	})
}
lm.addEvent({fn:mouseOut})
/* IE6 Fix for the main menu dropdown */
navHover = function() {
	var lis = document.getElementById("topMenu").getElementsByTagName("LI");
	for (var i=0; lis.length>i; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", navHover);
/* radio form option switcher */
lm.addEvent({fn: function(){
	if(!lm.e('jsFormSwitcher')) return false
	var searchForms = new Array()
	var linkNodes = lm.getElementsBy({tagName:'A', parentNode:lm.e('jsFormSwitcher')})	
	lm.forEach(linkNodes, 
		function(item,index){
			searchForms.push(item.className)
			if(index != 0 && lm.e(item.className)) lm.e(item.className).style.display = 'none'
		}
	)
	lm.forEach(linkNodes,function(item,index){
		lm.addEvent({
			eT:'click',
			e:item,
			fn: function(){
				var formToDisplay = item.className
				lm.forEach(searchForms, function(item, index){
					if(lm.e(item)){
						if(formToDisplay == item){
							lm.e(item).style.display = "block"
						} else {
							lm.e(item).style.display = "none"
						}
						lm.forEach(lm.getElementsBy({className:item}), function(item,index){
							var linkNode = item
							if(formToDisplay == item.className){
								imgNode = lm.getElementsBy({tagName : 'IMG', parentNode : item})[0]
								imgNode.src = "http://cdn.lastminute.com/site/site_search_button_on_1.gif?skin=lastminute"
								newNode = linkNode.innerHTML
								linkNode.innerHTML = ''
								strongNode = new lm.element.block({p:linkNode, tagName:'strong', innerHTML: newNode})
							} else if (item.firstChild.tagName == 'STRONG'){
								imgNode = lm.getElementsBy({tagName : 'IMG', parentNode : item})[0]
								imgNode.src = "http://cdn.lastminute.com/site/site_search_button_off_1.gif?skin=lastminute"
								strongNode = item.firstChild 
								newNode = strongNode.innerHTML
								linkNode.innerHTML = ''
								linkNode.innerHTML = newNode
							} else {
								imgNode = lm.getElementsBy({tagName : 'IMG', parentNode : item})[0]
								imgNode.src = "http://cdn.lastminute.com/site/site_search_button_off_1.gif?skin=lastminute"
							}
						})
					}
				})
			}
		})
	})
}
})
/*
 * Homepage newsletter form validation - 
*/
if(lm.e('emailAddress')){
	lm.addEvent({fn:function(){
		var emailField = lm.e('emailAddress')
		var errorImageSRC = '/site_staging/ico_error.gif?skin=lastminute'
		var errorArrowSRC = '/site_staging/error_bubble_ico_arrow_right.gif?skin=lastminute'
		var newsLetterBubbleHTML = '<div id="newsLetterErrorBubbleContent" class="text_error clearFloat"><img width="16" height="16" alt="!" src="'+errorImageSRC+'" /><div id="newsLetterErrorBubbleMessage">Please <strong class="text_highlight">enter a valid email address</strong>.</div><div id="newsLetterErrorBubbleLink"><strong>OK</strong> <img alt="&gt;" src="'+errorArrowSRC+'" /></div></div>'
		var newsLetterErrorBubble = lm.ce()
		newsLetterErrorBubble.id = 'newsLetterErrorBubble'
		newsLetterErrorBubble.innerHTML = newsLetterBubbleHTML 
		lm.append(newsLetterErrorBubble)
		lm.e('newsLetterErrorBubbleLink').style.cursor = 'pointer'
		lm.e('newsLetterErrorBubbleLink').style.textDecoration = 'underline'
		lm.e('newsLetterErrorBubble').style.left = lm.getLeft(emailField)+'px'
		lm.e('newsLetterErrorBubble').style.position = 'absolute'
		lm.e('newsLetterErrorBubble').style.zIndex = '1001'
		lm.e('newsLetterErrorBubble').style.display = 'none'
		lm.addEvent({e:lm.e('newsLetterErrorBubbleLink'),
					 eT:'click',
					 fn:function(){
						lm.e('newsLetterErrorBubble').style.display = 'none'
						}
					})
		lm.addEvent({e:emailField,
					 eT:'focus',
					 fn:function(){
						if(lm.e('newsLetterErrorBubble')) lm.e('newsLetterErrorBubble').style.display = 'none'
						if (this.value=='*enter email address*') this.value=''
					}
		})
		lm.addEvent({
			e:emailField,
			eT:'blur',
			fn:function(){
				if (this.value=='') this.value='*enter email address*'
			}
		})
		lm.addEvent({e:lm.e('newsletter_subscribe'),
					 eT:'submit',
					 fn:function(e){
						if (!e) e = window.event;
						var emailField = lm.e('emailAddress');
						if (emailField.value.match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/)) return true
						else {
							lm.e('newsLetterErrorBubble').style.top = (lm.getTop(emailField)-40)+'px'
							lm.e('newsLetterErrorBubble').style.display = 'block'
							if (e.preventDefault) e.preventDefault()
							else e.returnValue = false												 
							return false
						}
					}
				})
							 }
		})
}
function clearField(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}
function hideLeaderBoard(lb) {
    lm.e(lb).style.display = "none";
    lm.e('master_leaderBoard').style.display = "none";
    if (lm.e('master_top')) {
        lm.e('master_top').style.top = "0px";
    }
    if (lm.e('catPromoColumn')) {
        lm.e('catPromoColumn').style.top = "0px";
    }
    if (lm.e('navColumn')) {
        lm.e('navColumn').style.top = "0px";
    }
    if (lm.e('infoColumn')) {
        lm.e('infoColumn').style.top = "0px";
    }
    if (lm.e('centerBottom')) {
	lm.e('centerBottom').style.top = "0px";
    }
    if (lm.e('master_bottom')) {
	lm.e('master_bottom').style.top = "0px";
    }
    if (lm.e('spanAll')) {
	lm.e('spanAll').style.top = "0px";
    }
}
atags = document.getElementsByTagName('A');
for(i=0; i < atags.length;i++){
    atag = atags[i]
    if(atag.href.indexOf('hotels-arbo.html') > -1){
        atag.href = atag.href.replace('hotels-arbo.html','hotels-browse.html')
    }
}
