/* 
	JavaScript for handling the form validation on "Art on Stage" website
	Dec. 9th 2002. Mikkel Bo Rasmussen <webmeaster@artonstage.dk>
*/

function validateEmail(address){
	// Boolean to be returned
	var validEmail = true;
	// Can we use regular expressions? Then make complete check
	if(window.RegExp){
		var re = /^([\w-_]+(\.[\w-_]+)*@[\w-_]+(\.[\w-_]+)+\s*[,;]?\s*)+$/;
		var validEmail = re.test(new String(address));
	}
	// If not, then make a basic check
	else {
	// Check presence of @ and . characters
		var validEmail = (address.indexOf("@") > 0) && (address.indexOf(".") > 0)
		if(validEmail){
				// . must come after @
			if (address.indexOf(".") > address.indexOf("@")){
				// OK, e-mail is probably valid
				validEmail = true;
			}
			else {
				// Nope, e-mail is invalid
				validEmail = false;
			}
		}
	}
	if(!validEmail) { 
		// Warn user of invalid e-mail
		alert("Du har angivet en ugyldig e-mail-adresse. Kontrollér din indtastning.");
		document.forms["newsletter"].elements["email"].focus();
	}
	// Return true or false
	return validEmail;
}
