// Confirmation of new signup form
function checkSignupForm(frm) {
    var why = "";
    why += checkEmail(document.signup.FRM_reg_email.value);
    why += checkPassword(document.signup.FRM_reg_password.value);

    if (why != "") {
       alert(why);
       return false;
    }

    document.signup.submit();
}


// http://artlung.com/lab/scripting/validate_image/

// Confirmation of new registration form
function checkWholeForm() {
    //alert('validating');
    var why = "";
    why += checkFirstName(document.registration.FRM_user_first_name.value);
    why += checkLastName(document.registration.FRM_user_last_name.value);
    why += checkEmail(document.registration.FRM_user_email.value);
    why += isDifferent(document.registration.FRM_email_confirm.value);
    why += checkPassword(document.registration.FRM_user_password.value);
    why += isDifferent2(document.registration.FRM_password_confirm.value);

    if (why != "") {
       alert(why);
       return false;
    }
    //alert('ok validated');
    
    document.registration.submit();
}



// Confirmation of user edited registration form
function checkUserEditForm() {
    var why = "";
    why += checkFirstName(document.registration.FRM_user_first_name.value);
    why += checkLastName(document.registration.FRM_user_last_name.value);
    why += checkEmail(document.registration.FRM_user_email.value);
    why += isDifferent(document.registration.FRM_email_confirm.value);
    if (document.registration.FRM_user_password.value.length > 0) {
      // check passwords only if filled in
      why += checkPassword(document.registration.FRM_user_password.value);
      why += isDifferent2(document.registration.FRM_password_confirm.value);
    }

    if (why != "") {
       alert(why);
       return false;
    }
    //alert('ok validated');
    
    document.registration.submit();
}


// ************************************
// ***** helper functions *************
// ************************************

// First Name - at least one character, uc, lc, and underscore only.

function checkFirstName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
}

    if (strng.length < 1) {
       error = "First name must be filled in, it is currently "+strng.length+" characters.\n";
    }
return error;
}

// Last Name - at least one character, uc, lc, and underscore only.

function checkLastName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a last name.\n";
}

    if (strng.length < 1) {
       error = "Last name must be filled in, it is currently "+strng.length+" characters.\n";
    }
return error;
}

// Address - at least one character, uc, lc, and underscore only.

function checkAddress (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a street address.\n";
}

    if (strng.length < 1) {
       error = "Address must be filled in, it is currently "+strng.length+" characters.\n";
    }
return error;
}

// City - at least one character, uc, lc, and underscore only.

function checkCity (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a city.\n";
}

    if (strng.length < 1) {
       error = "City must be filled in, it is currently "+strng.length+" characters.\n";
    }
return error;
}

// State - at least two characters, uc, lc, and underscore only.

function checkState (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a state.\n";
}

    if (strng.length < 2) {
       error = "State must be filled in, it is currently "+strng.length+" characters.\n";
    }
return error;
}

// Zip code - strip out delimiters and check for 5+ digits

function checkZip (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a zip code.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The zip code contains illegal characters.\n";

    }
    if (stripped.length < 5) {
	error = "Zip code must be at least 5 digits, it is currently "+strng.length+" digits.\n";
    }
return error;
}

// Email - check for correct characters and length

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an e-mail address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) {
       error = "E-mail must contain an AT symbol (@) and a period.\n";
    }
return error;
}


// password - between 6-8 chars, uppercase, lowercase, and numeral
// rev 1/7/04 - must have one char

function checkPassword (strng) {
var error = "";
  if (strng == "") {
     error = "You didn't enter a password.\n";
  }

// rev 1/7/04 - must have one char
    return error;


    var illegalChars = /[\W_]/; // allow only letters and numbers

    if ((strng.length < 6) || (strng.length > 10)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    }
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }
    return error;
}

// email verification -- both fields must match

function isDifferent(strng) {
var error = "";
  if (strng != (document.registration.FRM_user_email.value)) {
     error = "E-mail addresses must be the same: the Verify E-mail is not the same as the e-mail address you typed.\n";
  }
return error;
}

// password verification -- both fields must match

function isDifferent2(strng) {
var error = "";
  if (strng != (document.registration.FRM_user_password.value)) {
     error = "Passwords must be the same: the Verify password is not the same as the password you typed.\n";
  }
return error;
}
