// --- [start /site/errorBubbleScripts_lm.js] ---
// --- [start /site/portal_skins/DEFAULT/errorBubbleScripts_lm.js] ---
	function createMessageShell_from_string(){
		if(typeof formUtility != 'undefined' )
		{
			var ico_error = '/site/trans.gif?skin=default';
			var ico_error_arrow_right = '/site/trans.gif?skin=default';
			var html = '<div id="lmErrorBubbleContent" class="text_error clearFloat"><div id="lmErrorBubbleMessage"></div><div id="lmErrorBubbleLink"><a href="javascript:formUtility.message.hide()" class="text_error"><strong>OK</strong>&nbsp;</a></div></div>';	
			formUtility.message.builtShell(html, 'lmErrorBubble', 'lmErrorBubbleMessage');
		}
	}
if(typeof lm == 'object'){
    lm.addEvent({fn:createMessageShell_from_string});
}

function isValidStringValue(item){
	return (item.match(/<|None/gim) || item.replace(/ /g, '').length==0 )
}

function isValidEmailAddress(item){
	return item.match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/)
}

// Used for "Flights + Hotels" and "Flight"
// RULES -> The "Departure" field must be selected from the dropdown or a string value must be written
function nonValidDeparturePoint(){
	return isValidStringValue(lm.e('departurePoint').value);
};

// Used for "Flights + Hotels" and "Flight"
// RULES -> The "Destination" field must be selected from the dropdown or a string value must be written
function nonValidDestination(){
	return isValidStringValue(lm.e('destination').value);
};

// Used for "Hotels" city or postcode field and country validation
// RULES -> The "City or postcode" field cannot be empty if the "Country" field is not selected. The "City or postcode" field can be empty if the "Country" field is selected 
function nonValidDestinationHotel(){
    var city = lm.e('city');
	return (isValidStringValue(city.value) );
};

function nonValidDestinationHotelBlankCity(){
	return isValidStringValue(lm.e('city').value);
};

function nonValidDestinationHotelAirportCodes(){
	var airportCodes;
	if(airportCodes = lm.e('airportCodesId')){
		return ( isValidStringValue(airportCodes.value))	
	}else{
		return false;
	}
};
// Used for "Flights + Hotels" and "Flight"
// RULES -> A size of 9 passengers or less
function nonValidPassengersNumber() {
    var totalPassenger = 0;
    var fields = ['adults', 'seniors', 'child', 'infants', 'adults0', 'adults1', 'adults2']
    for(var i=0;i < fields.length;i++){
		if(lm.e(fields[i])){
	        totalPassenger += parseInt(lm.e(fields[i]).value)
		}
    }
    return (totalPassenger > 9);
};

// Used for "Flights + Hotels" and "Flight"
// RULES -> At least 1 adult or senior passenger is required
function nonValidMinimumPassenger(){
    var totalPassenger = 0;
    var fields = ['adults', 'seniors', 'adults0', 'adults1', 'adults2', 'children0', 'children1', 'children2']
    for(var i=0;i < fields.length;i++){
		if(lm.e(fields[i])){
	        totalPassenger += parseInt(lm.e(fields[i]).value)
		}
    }
    return (totalPassenger == 0);
}


function nonValidCheckInDate(){
    var day = lm.e('checkInDay');
    var month = lm.e('checkInMonth');
    return ((parseInt(lm.e('checkInMonth').value)-1==lm.now.getMonth()) && parseInt(lm.e('checkInDay').value) < lm.now.getDate())
};

/*
 * Return a date object from the day and month past as param 
 * The function will automaticly calculate the year value 
 * The time of the date is default to 00:00:00
 * @param {Number} d
 * @param {Number} m
 */
function formatDateForValidation(d,m){
    m--;
    var date = new Date();
    var y = (parseInt(m) >= date.getMonth())? date.getFullYear() : date.getFullYear()+1;
    date.setDate(d);
    date.setMonth(parseInt(m));
    date.setYear(y);
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    return date;
}

/*
 * return false if either the departure date or the return date are 
 * set in the past of the current day or set more then 329 day in advance from the current date  
 */
function nonValidFlightReturnDate(){
	
	function getDate(d,m,y,flag){
        var date = new Date(y,m,d);
		switch(flag){
			case 'year':	
				return (date.getYear() < 1900)? date.getYear()+1900 : date.getYear();
				break
			case 'date':
				return date;
				break
			default :
				return date.getTime();
		}
    };
	
    function getNumDay(t){
        return (t/1000/60/60/24)
    }
	
	var now = new Date()
	var nowMonth = now.getMonth() + 1;
	var nowYear = now.getFullYear();
	
	var depDay = lm.e('departureDateDay').value*1;
	var depMonth = lm.e('departureDateMonth').value*1;
	var depYear = (depMonth < nowMonth)? nowYear + 1 : nowYear; 
	
	var retDay = lm.e('returnDateDay').value*1;
	var retMonth =  lm.e('returnDateMonth').value*1;
	var retYear = (retMonth < nowMonth)? nowYear + 1 : nowYear; 
	
	var dd = getDate(depDay, depMonth-1, depYear);
	var rd = getDate(retDay, retMonth-1, retYear);
	
	var nowDay = now.getDate();
	var nowMonth = now.getMonth()+1;
	
	/* CODE TO HELP WITH DEBUGGING
	var oneDay = 1000*60*60*24;
	daysUntilDeparture = Math.ceil( (now-dd)/oneDay );	
	console.log(daysUntilDeparture); 
	console.log(depDay+', '+depMonth)
	console.log(dd + '||' + rd); 
	console.log(depDay+'-'+depMonth+'-'+depYear + '||' + retDay+'-'+retMonth+'-'+retYear); */

	if(rd < dd || getNumDay(dd - now.getTime()) > 330 || getNumDay(rd - now.getTime()) > 330 || (depMonth==nowMonth && depDay < nowDay)) return true 
	else return false			
}


/*function nonValidReturnDateDP(){
    return nonValidReturnDate('dp')
};*/

function nonValidReturnDateDPReturnBeforeDep(){
    return nonValidReturnDate('dpReturnBeforeDep')
};

function nonValidReturnDateDPDatePast(){
    return nonValidReturnDate('dpDateInPast')
};

function nonValidReturnDateES(){
    return nonValidReturnDate('es')
};

function nonValidReturnDate(flag){

    function getDate(d,m,y,flag){
        var date = new Date(y,m,d);
	switch(flag){
		case 'year':	
			return (date.getYear() < 1900)? date.getYear()+1900 : date.getYear();
			break
		case 'date':
			return date;
			break
		default :
			return date.getTime();
	}
    };
	
    function getNumDay(t){
        return (t/1000/60/60/24)
    }
	
	var now = new Date()
	var nowMonth = now.getMonth();
	var nowYear = now.getFullYear();
	
	var depDay = lm.e('departureDateDay').value*1;
	var depMonth = lm.e('departureDateMonth').value*1;
	var depYear = (depMonth < nowMonth)? nowYear + 1 : nowYear; 
	
	var retDay = lm.e('returnDateDay').value*1;
	var retMonth =  lm.e('returnDateMonth').value*1;
	var retYear = (retMonth < nowMonth)? nowYear + 1 : nowYear; 
	
	var dd = getDate(depDay, depMonth-1, depYear);
	var rd = getDate(retDay, retMonth-1, retYear);
	
	var nowDay = now.getDate();
	var nowMonth = now.getMonth()+1;
	
	/* CODE TO HELP WITH DEBUGGING
	var oneDay = 1000*60*60*24;
	daysUntilDeparture = Math.ceil( (now-dd)/oneDay );	
	console.log(daysUntilDeparture); 
	console.log(depDay+', '+depMonth)
	console.log(dd + '||' + rd); */
	
	switch(flag) {
		case 'dpDateInPast':		
			if((depMonth==nowMonth && depDay < nowDay) || getNumDay(dd - now.getTime()) > 330) return true
			else return false
			break    
		case 'dpReturnBeforeDep':
			if(rd <= dd) return true
			else return false
			break
		case 'es':
			if (getNumDay(rd - lm.now) > 121 || rd <= dd) return true
			else return false
			break
		default:
			if(rd < dd || getNumDay(dd - now.getTime()) > 330) return true 
			else return false		
	}
};

function Destination_equal_Departure() {
	return (lm.e('destination').value==lm.e('departurePoint').value)
};

// Used for Hotels
// RULES -> If children dropdown as a selected value for the number of children each children age must be selected
function nonValidChildAge() {
	var roomsIndex = lm.e('rooms').selectedIndex;
	//loop through each room
	for (i=0;i <= roomsIndex;i++) {
		var childNum = lm.e('children' + i).selectedIndex;
		//loop through each child age
		for (j=0;j < childNum;j++) {
			if (lm.e('room' + i + '_childAge' + j).selectedIndex==0) return true;
		}
	}
	return false;
}

//used for homepage newsletter form
function nonValidEmailAddress() {
	if(isValidEmailAddress(lm.e('emailAddress').value)) return false
	else return true
}

//used for homepage keyword form
function nonValidKeyword() {
	return isValidStringValue(lm.e('keyword').value)
}
// --- [end prdpctbd5701:4002 - /site/portal_skins/DEFAULT/errorBubbleScripts_lm.js - Apr 14, 2008 1:04 pm GMT - Z2UID8fc9e311-639c-446e-8734-4f3b5c02b2c3 - cache 1800 ] ---
// --- [end prdpctbd5301:5002 - /site/errorBubbleScripts_lm.js - Nov 22, 2009 6:57 pm GMT - akamai,pcth0412,pct0410 - SIYA3wqoQsAAAAVB4koAADAV - cache 1800 ] ---
