String.prototype.trim = function() { 
	return this.replace(/^\s+|\s+$/g, ''); 
};

function verifMail() {

	var email=document.getElementById('email').value;
	var expressionEMail = /^[0-9a-zA-Z\._-]+@[0-9a-zA-Z\._-]+\.[0-9a-zA-Z]+$/;
	
	if ( !email.match(expressionEMail) ) {			
		alert("Please write correctly your email address");
		document.getElementById('email').focus();
		document.getElementById('email').select();
		return false;
	}
	else {		
		return true;	
	}
}

function verifMailFriend() {

	var email=document.getElementById('friend_email').value;
	var expressionEMail = /^[0-9a-zA-Z\._-]+@[0-9a-zA-Z\._-]+\.[0-9a-zA-Z]+$/;
	
	if ( !email.match(expressionEMail) ) {			
		alert("Please write correctly your friend's email address");
		document.getElementById('friend_email').focus();
		document.getElementById('friend_email').select();
		return false;
	}
	else {		
		return true;	
	}
}


function validSearch() {
		document.formSearch.submit();
}

String.prototype.trim = function() { 
	return this.replace(/^\s+|\s+$/g, ''); 
};

function validApply() {	
	fields = new Array( "first_name", "last_name", "phone", "comments" );
	
	for ( var i = 0; i < fields.length; i++ ){														
		if ( document.getElementById(fields[i]).value.trim() == "" ){
			alert( 'Please write correctly all of the required fields');
			document.getElementById(fields[i]).focus();
			document.getElementById(fields[i]).select();
			return false;
		}
	}
	
	if ( !verifMail() ) {
		return false;
	}
	
	document.formApply.submit();;
	
}

function validContact() {	
	fields = new Array( "name", "comments" );
	
	for ( var i = 0; i < fields.length; i++ ){														
		if ( document.getElementById(fields[i]).value.trim() == "" ){
			alert( 'Please write correctly all of the required fields');
			document.getElementById(fields[i]).focus();
			document.getElementById(fields[i]).select();
			return false;
		}
	}
	
	if ( !verifMail() ) {
		return false;
	}
	
	document.formContact.submit();;
	
}

function validFriend() {	
	fields = new Array( "name", "friend_name" );
	
	for ( var i = 0; i < fields.length; i++ ){														
		if ( document.getElementById(fields[i]).value.trim() == "" ){
			alert( 'Please write correctly all of the required fields');
			document.getElementById(fields[i]).focus();
			document.getElementById(fields[i]).select();
			return false;
		}
	}
	
	if ( !verifMail() ) {
		return false;
	}
	
	if ( !verifMailFriend() ) {
		return false;
	}
	
	document.formFriend.submit();;
	
}
