// check that the user entered a valid username (doesn't have to be an email address) and a password
function submitLogin(myForm) {
	if (myForm.login_email.value == "") { 
		alert ("Please enter your login username.");
		myForm.login_email.focus();
		myForm.login_email.select();
		return false;
	}
	if (myForm.login_password.value == "") { 
		alert ("Please enter your password.");
		myForm.login_password.focus();
		myForm.login_password.select();
		return false;
	}
	return true;
}

// check that all required fields are entered properly for the New User Account
function submitNew(myForm) {
	$flag = 0;
	$msg = "The following form fields are required:\n";

	if (!verify(myForm.email.value)) { $msg += "- a valid email address\n"; $flag=1; }
	if (myForm.password.value == "") { $msg += "- your login password\n"; $flag=1; }
	if (myForm.firstname.value == "") { $msg += "- your first name\n"; $flag=1; }
	if (myForm.lastname.value == "") { $msg += "- your last name\n"; $flag=1; }
	if (myForm.company.value == "") { $msg += "- your company name\n"; $flag=1; }
	if (myForm.address.value == "") { $msg += "- your street address\n"; $flag=1; }
	if (myForm.city.value == "") { $msg += "- your city of business\n"; $flag=1; }
	if (myForm.state.value == "") { $msg += "- your state of business\n"; $flag=1; }			
	if (!validateNum(myForm.zip.value, 5)) { $msg += "- the zip code of your business\n"; $flag=1; }	
	if (!validateNum(myForm.phone1.value, 3) || !validateNum(myForm.phone2.value, 3) || !validateNum(myForm.phone3.value, 4))
		 { $msg += "- your phone #\n"; $flag=1; }	

	// if they filled in the optional fax fields, verify that the entries are numeric
	$fax_flag = 0;
	if (myForm.fax1.value != "") {
		if (!validateNum(myForm.fax1.value, 3)) { $fax_flag=1; }	
	}
	if (myForm.fax2.value != "") {
		if (!validateNum(myForm.fax2.value, 3)) { $fax_flag=1; }	
	}
	if (myForm.fax3.value != "") {
		if (!validateNum(myForm.fax3.value, 4)) { $fax_flag=1; }	
	}
	if ($fax_flag > 0) { $msg += "- a valid fax #\n"; $flag=1; }	
	$msg += "\nIf you would prefer to register over the phone, call (801) 627-1403.  Thank you.\n";
	if ($flag > 0) {
		alert ($msg);
		return false;
	} else {
		return true;
	}
}

// verifies that the given email address is valid
function verify(email) {
 invalidChars = " /:,;"
 if (email == "") {
  return false;
 }

 for (i=0; i<invalidChars.length; i++) {
  badChar = invalidChars.charAt(i)
  if (email.indexOf(badChar,0) > -1) {
   return false;
  }
 }
 atPos = email.indexOf("@",1);
 if (atPos == -1) {
  return false;
 }
 if (email.indexOf("@",atPos+1) > -1) {
    return false;
 }
 periodPos = email.indexOf(".",atPos);
 if (periodPos == -1) {
  return false;
 }
 if (periodPos+3 > email.length) {
  return false;
 }
 return true;
}

// ensures that the field contains all numeric values (for zip and phone fields, and fax if !empty
function validateNum(field, num) {
	var valid = "0123456789";
	if (field.length != num) {
		return false;
	}
	for (var i=0; i < field.length; i++) {
		temp = "" + field.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") {
			return false;
		}
	}
	return true;
}

// when the maxlength is met for a form field, jumps to the next field; used for phone & fax fields
function toUnicode(elmnt,content)
{
if (content.length==elmnt.maxLength)
	{
	next=elmnt.tabIndex
	if (next<document.newUser.elements.length)
		{
		document.newUser.elements[next].select()
		}
	}
}