// written, compilled and modified by David Harris mediarevolutionary.com
// functions for validating user registration and contact form



function noName(l) { // name required
	if(l.length == 0) {
		alert('please enter your name or pseudonym.');
		document.register.userName.focus(); 
	} 
}

// confirm password, match
//
//
function confirmPass(a, b) { // matches password and confirmed password
	if(a !== b) {
		alert('please re-confirm password.  they do not match.');
		document.register.confirmPassword.focus();
	} 
}
function noPassword(t) { // password required
	if(t.length == 0) {
		alert('please enter a password.');
		document.register.password.focus(); 
	} 
	if(t.length > 8 || t.length < 4) { // password only 4-8 chars.
		alert('must be between 4 and 8 characters.');
		document.register.password.focus();
	}
}
	


// validate email addy
//
//
function validEmail(email) { // push user email value
		var emailRegExp = /^(\w+@)([a-z0-9\-]{2,}.([a-z]{2,}.)?([a-z]{2,}.)?([a-z]{2,}.)?[a-z]{2,})$/i	 
		// allows for 2+ letters/nums follwed by @ with 2+ letters/nums . with 2+ letters/nums
		// xtra ([a-z]{2,}.)? allow for foreign email addys ie. tgmcduff@cuyamaca.cc.ca.us
		if(emailRegExp.test(email)) {
			return
		} else {
			alert("please enter a valid email.");
			document.register.email.focus(); 
		}
	}
//
//
// /validEmailAddy

// confirm email addy
//
//
  function confirmEmail(m) { // matches email and confirmed email
	if(m != document.register.emailConfirm.value) {
	  	alert('please reenter your email. they don\'t match.');
		document.register.emailConfirm.focus(); 
	  } 
	}
//
//
// /confirmEmailAddy



// batch validates form
//
//
function batchValidate(register) { // just in case batch validation
	// pass form
	var errorMessage = 'please add ';
	var error = false; // sets error to false if all fields filled
	if (register.userName.value.length == 0) {
		errorMessage += 'your name,';
		error = true;
	}
	if (register.email.value.length == 0) {
		errorMessage += 'your email,';
		error = true;
	}		
	/* if (register.password.value.length == 0) {
		errorMessage += 'your password,';
		error = true;
	} */
	if (register.city.value.length == 0) {
		errorMessage += 'your city,';
		error = true;
	}
	if (register.country.value.length == 0) {
		errorMessage += 'your country,';
		error = true;
	}		
	if (error) { 
		alert(errorMessage + 'thank you.'); // concatenated message depending on fields empty
		return false// does not submit
	} else register.submit()

}

function batchValidate2(register) { // just in case batch validation
	// pass form
	var errorMessage = 'please add ';
	var error = false; // sets error to false if all fields filled
	if (register.userName.value.length == 0) {
		errorMessage += 'your name,';
		error = true;
	}
	if (register.email.value.length == 0) {
		errorMessage += 'your email,';
		error = true;
	}		
	if (register.subject.value.length == 0) {
		errorMessage += 'the subject,';
		error = true;
	}
	if (register.message.value.length == 0) {
		errorMessage += 'your message,';
		error = true;
	}
	if (error) { 
		alert(errorMessage + 'thank you.'); // concatenated message depending on fields empty
		return false// does not submit
	} else register.submit()

}
//
//
// /batch validate
