// --- [start /site/generic.js] ---
/* 
* Author : UI Development Team
* Description : lastminute.com Javascript - site wide functionality
* Contact : uidevelopment@lastminute.com
* Resource : http://www.prettyprinter.de - Used for formatting. 
*/

/* Description: Variables to detect environment */

var frontierProtocol = 'http';
var frontierHTTPHost = 'www.lastminute.com';
var frontierBaseUrl = '/site';
var frontierURL = frontierProtocol+'://'+frontierHTTPHost+''+frontierBaseUrl;
var frontierSkin = 'enhk.zuji.com.hk';
var frontierLocale = 'en_HK';

/*
* 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>');
}

// get the computed styles on an element 
function getStyle(el,styleProp)
{
if(el){
	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;
		}
	}
}


/*
* 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;	
				}
			}
		}
	}
}



/*
* 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')
		}
	});	
	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)) 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';
	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 = 'en_HK';

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
}

/*
* Description : adds a js file to head of page - specifically needed for multimap
*/
function addJS(src) {
	var pageHead = document.getElementsByTagName('head')[0];
	var mapScript = document.createElement('script');
	mapScript.setAttribute('type','text/javascript');
	mapScript.setAttribute('src',src);
	pageHead.appendChild(mapScript);
}
addJS('http://cdn.lastminute.com/site/enhancedMap.js?skin=enhk.zuji.com.hk');

			function addMMKey() {
				addJS('http://clients.multimap.com/API/maps/1.2/lastminute_api?locale=en-hk');
			}

function clearField(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}
// --- [end prdpwgbd4608:5001 - /site/generic.js - Sep 30, 2009 10:21 am GMT - v1-akamaitech,akamai,pwg4,pwg7 - 5niw1wqoTGIAAH7POMEAAAAQ - cache 1800 ] ---
