// JavaScript Document

function validar(){
	
	//var emailRegEx = /^((\w\.){2,}@)\w{3,}\.\w{2,4}((\.(\w{2}))?)?$/
	var emailRegEx = /^[^@ ]+@[^@ ]+.[^@ .]+$/

	if (document.signup_form.username.value.length<6 || document.signup_form.username.value.length>12){
       alert("Username must contain between 6-12 characters.")
       document.signup_form.username.focus()
       return false;
    }
	
	if (document.signup_form.pass.value.length<6 || document.signup_form.pass.value.length>12){
       alert("Password must contain between 6-20 characters.")
       document.signup_form.pass.focus()
       return false;
    }

	if(document.signup_form.email.value == "") {
		document.signup_form.email.focus()
		alert("Email field is empty.")
		return false;
	} else {
		if(!document.signup_form.email.value.match(emailRegEx)) {
			document.signup_form.email.focus()
			document.signup_form.email.value = ""
			alert("Please enter a valid email adress.")
			return false;
		}
	}
	
	if(document.signup_form.confirmemail.value == "") {
		document.signup_form.confirmemail.focus()
		alert("Please confirm your email.")
		return false;
	} else {
		if(!document.signup_form.confirmemail.value.match(emailRegEx)) {
			document.signup_form.confirmemail.focus()
			document.signup_form.confirmemail.value = ""
			alert("The confirmation email you have entered is not valid.")
			return false;
		}
	}
	
	if (document.signup_form.firstname.value.length < 1){
       alert("Please enter your First Name.")
       document.signup_form.firstname.focus()
       return false;
    }
	
	if (document.signup_form.lastname.value.length < 1){
       alert("Please enter your Last Name.")
       document.signup_form.lastname.focus()
       return false;
    }

	if (document.signup_form.address.value.length < 1){
       alert("Please enter your Address.")
       document.signup_form.address.focus()
       return false;
    }
	if (document.signup_form.zip.value.length < 1){
       alert("Please enter your ZIP/Postal Code.")
       document.signup_form.zip.focus()
       return false;
    }
	if (document.signup_form.city.value.length < 1){
       alert("Please enter your City.")
       document.signup_form.city.focus()
       return false;
    }
	if (document.signup_form.terms.checked == false ||
	    document.signup_form.privacy.checked == false)
		{
		alert ('You must agree to our Terms & Conditions and to our Privacy Policy before signing up.');
		return false;
		}

	return true;
	
} 
