var vpwF = 0;
var vevF = 0;

function pwPreVerify() {
	vpwF = 1;
}


function pwVerify() {
	if(vpwF !== 0){
		if(document.regform.upw.value !== document.regform.uvpw.value){
			document.regform.upw.value = "";
			document.regform.uvpw.value = "";
			alert("Password not verified, please re-enter password.");
			document.regform.upw.focus();
		}
	}
}

function preValidate() {
	vevF = 1;
}

function validateAddress() {
	if (vevF != 0) {
		var emailstring = document.regform.uem.value;
		var ampIndex = emailstring.indexOf("@");
		var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
			// find a dot in the portion of the string after the ampersand only
		var dotIndex = afterAmp.indexOf(".");
			// determine dot position in entire string (not just after amp portion)
		dotIndex = dotIndex + ampIndex + 1;
			// afterAmp will be portion of string from ampersand to dot
		afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
			// afterDot will be portion of string from dot to end of string
		var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
		var beforeAmp = emailstring.substring(0,(ampIndex));
			//var email_regex = /^[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~])*\@(((\w+[\w\d\-]*[\w\d]\.)+(\w+[\w\d\-]*[\w\d]))|((\d{1,3}\.){3}\d{1,3}))$/;
		var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/ 
			// index of -1 means "not found"
		if ((emailstring.indexOf("@") != "-1") &&
			(emailstring.length > 5) &&
			(afterAmp.length > 0) &&
			(beforeAmp.length > 1) &&
			(afterDot.length > 1) &&
			(email_regex.test(emailstring)) ) {
			  return true;
		} else {
				alert("Please check your email address. It appears to be in the wrong format.");
				document.regform.uem.focus();
				return false;
		}
	}
}


function passShow(){
	if (document.regform.user_pass_member.checked == true){
		document.getElementById("regpasssection").style.display="block";
		document.regform.user_pass_discount.checked=true;
	}else{
		document.getElementById("regpasssection").style.display="none";
		document.regform.user_pass_discount.checked=false;
	}

}

function processRegForm() {
	//check that they want access to something
	if (document.regform.user_coaches_registry.checked !=true && document.regform.user_forum_user.checked != true && document.regform.user_pass_member.checked != true) {
		alert("You must choose at least one area you want access to.");
		return false;
	}else {
		// check for empty required fields		
		if (document.regform.user_first_name.value == "" || document.regform.user_last_name.value == "" || document.regform.user_address.value == "" || document.regform.user_city.value == "" || document.regform.user_zip.value == "" || document.regform.user_home_phone.value == "" || document.regform.user_work_phone.value == "" || document.regform.user_email.value == "" || document.regform.user_pw.value == "" || document.regform.user_vpw.value == "") {
			alert("One or more required fields is empty. Please check and submit again.");
			return false;
		}else {
			// check for empty pass fields
			if (document.regform.user_pass_member.checked == true) {
				if (document.regform.user_pass_team_names.value == "" || document.regform.user_pass_league.value == "") {
					alert("One or more required fields is empty. Please check and submit again.");
					return false;
				}
			}
		}
	}		
		
}