String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"").replace(/\s+/g," ");
}
function checkEmail(email) {
	var filter=/^[^ @<>]+@[^ @<>]+\.[a-z]{2,}$/i;
	email=email.trim();
	if(filter.test(email)==false) {
		//sendAnyway=confirm("You seem to have provided an invalid e-mail address.\nDo you want to send your message anyway?");
		//if(!sendAnyway) return(false);
		if (email != "")
		{
			alert('You appear to have provided an invalid e-mail address. Please provide a correct address, or leave the field blank.');
			return false;
		}
	}
	return(true);
}


function validate_feedback_form(form, mode) {
	var error = "";

	if(form.username.value == "") {
		error += "You forgot to put your name!\n"; 
	}
	if(form.subject.value == "") {
		error += "You forgot to put a subject!\n"
	}
	if(form.message.value == "") {
		error += "You forgot to type a message!\n"; 
	}
	if(form.swear && form.swear.checked != true) {
		error += "You forgot to swear that the content of your message is true!"; 
	}
	if(form.spam_check.value == "") {
		error += "You forgot to enter the phrase proving that you are human and not some SPAM-bot!!\n"; 
	} else {
		var spamPhrase = form.spam_check.value.toLowerCase();
		if(spamPhrase.indexOf("i am human") < 0) {
			error += "You incorrectly entered the phrase to prove that you are human and not some SPAM-bot!!";
		}
	}
	if(error != "") {
		alert(error);
		return(false);
	} else {
		if(mode == 'email') return(checkEmail(form.mail.value));
		return(true);
	}
}

function check(form) {
	if(form.name.value=="") {
		alert("You forgot to put your name!"); 
		return(false);
	}
	if(form.comments.value=="") {
		alert("You forgot to type a message!"); 
		return(false);
	}
	if(form.swear.checked!=true) {
		alert("You forgot to swear that the content of your message is true!"); 
		return(false);
	}

	if(form.spam_check.value == "") {
		alert("You forgot to enter the phrase proving that you are human and not some SPAM-bot!!"); 
		return(false);
	}
	var spamPhrase = form.spam_check.value.toLowerCase();
	if(spamPhrase.indexOf("i am human") < 0) {
		alert("You incorrectly entered the phrase to prove that you are human and not some SPAM-bot!!"); 
		return(false);
	}

	return(checkEmail(form.mail.value));
}