// --- [start /site/portal_skins/DEFAULT/errorBubbleScripts_lm.js] ---
	function createMessageShell_from_string(){
		if(typeof formUtility != 'undefined' )
		{
			var ico_error = 'http://cdn.lastminute.com/site/ico_error.gif?skin=engb.whitelabel';
			var ico_error_arrow_right = 'http://cdn.lastminute.com/site/error_bubble_ico_arrow_right.gif?skin=engb.bmibaby';
			var html = '<div id="lmErrorBubbleContent" class="text_error clearFloat"><img src="'+ico_error+'" alt="!" width="16" height="16" /><div id="lmErrorBubbleMessage"></div><div id="lmErrorBubbleLink"><a href="javascript:formUtility.message.hide()" class="text_error"><strong>OK</strong>&nbsp;<img src="'+ico_error_arrow_right+'" alt="&gt;" /></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,})$/)
}

function isValidPassword(item){
    if(item.match(/<|^None$/gim)|| item.replace(/ /g, '').length < 8)return false
    //if(!item.match(/[A-Z]{1,}/g)) return false
    //if(!item.match(/[0-9]{1,}/g)) return false
    return true
}

// 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 nonValidReturnDateDPLongStay(){
    return nonValidReturnDate('dpLongStay')
};
function nonValidReturnDateDPDatePast(){
    return nonValidReturnDate('dpDateInPast')
};
function nonValidDPReturnDatePast(){
    return nonValidReturnDate('dpReturnDateInPast')
};

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+1)) ? nowYear + 1 : nowYear; 
	
	var retDay = lm.e('returnDateDay').value*1;
	var retMonth =  lm.e('returnDateMonth').value*1;
	var retYear = (retMonth < (nowMonth+1))? 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 'dpReturnDateInPast':		
			if((retMonth==nowMonth && retDay < nowDay) || (getNumDay(rd - now.getTime()) > 330)) return true
			else return false
			break    
		case 'dpReturnBeforeDep':
			if(rd <= dd) return true
			else return false
			break
		case 'dpLongStay':
			if(getNumDay(rd-dd)>28) 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)
}


//used for self service login form
function nonValidEmail() {
	if(isValidEmailAddress(lm.e('userEmail').value)) return false
	else return true
}

function nonValidPassword() {
	return isValidStringValue(lm.e('userPassword').value)
}

//used for self service change email form
function nonValidNewEmail() {
	if(isValidEmailAddress(lm.e('userNewEmail').value)) return false
	else return true
}

function nonValidConfirmationEmail() {
	if(lm.e('userNewEmail').value == lm.e('userNewEmailConf').value) return false
	else return true
}

//used for self service change password form
function nonValidNewPassword() {
	if(isValidPassword(lm.e('userNewPassword').value)) return false
	else return true
}

function nonValidConfirmationPassword() {
	if(lm.e('userNewPassword').value == lm.e('userNewPasswordConf').value) return false
	else return true
}
// --- [end prdpwgbd4803:5002 - /site/portal_skins/DEFAULT/errorBubbleScripts_lm.js - Feb 9, 2010 4:46 pm GMT - v1-akamaitech,akamai,pcth0406,pct0410 - qWBNjwqoQroAABSk2zkAABBu - cache 1800 ] ---
