/* validate username and password */

function validateInput(update) 

{

  var invalid = " "; // invalid character is a space

  var minLength = 6; // minimum length

  var maxLength = 40; // maximum length



  var pw1 = document.myForm.passwd.value;

  var pw2 = document.myForm.repasswd.value;



  /* check required fields */

  var mesg = "";

  if(trim(document.myForm.firstName.value) == '')

    mesg =  mesg + "First Name is required\n";

  if(trim(document.myForm.lastName.value) == '')

    mesg =  mesg + "Last Name is required\n";

  if(trim(document.myForm.address.value) == '')

    mesg =  mesg + "Address is required\n";

  if(trim(document.myForm.city.value) == '')

    mesg =  mesg + "City is required\n";

  if(trim(document.myForm.state.value) == '')

    mesg =  mesg + "State is required\n";

  if(trim(document.myForm.zip.value) == '')

    mesg =  mesg + "Zip is required\n";

  if(trim(document.myForm.country.value) == '')

    mesg =  mesg + "Country is required\n";

  if(trim(document.myForm.phone.value) == '')

    mesg =  mesg + "Phone is required\n";

  if(trim(document.myForm.email.value) == '')

    mesg =  mesg + "Email Address is required\n";

    if ((document.myForm.birthMonth.selectedIndex == 0 ) ||
	    	(document.myForm.birthDay.selectedIndex == 0) ||
	    	(document.myForm.birthYear.selectedIndex == 0) )
    mesg =  mesg + "Birth Date is required\n";

  if(!document.myForm.gender[0].checked && !document.myForm.gender[1].checked)

    mesg =  mesg + "Gender is required\n";

  if(trim(document.myForm.secretQuestion.value) == '')

    mesg =  mesg + "Secret Question is required\n";

  if(trim(document.myForm.questionAnswer.value) == '')

    mesg =  mesg + "Secret Question Answer is required\n";



  if(mesg != '')

  {

    alert(mesg);

    return false;

  }

  

  /* check for user name */

  /* for new account only */

  if(!update)

  {

    var username = document.myForm.username.value;

    

    if(username == '')

    {

      alert("User Name should not be empty");

      return false;

    }

  

    if(username.length < minLength)

    {

      alert("User Name should be between " + minLength + " and " + maxLength + " characters long.");

      return false;

    }

  

    if(username.indexOf(invalid) > -1) 

    {

      alert("Spaces are not allowed in the User Name.");

      return false;

    }

  }

  

  /* check for password */

  if(update)

  {

    if(pw1 == '' && pw2 == '') 

      return true;

  }

  

  if(pw1 == '' || pw2 == '')

  {

    alert("Please enter your password twice.");

    return false;

  }

  

  if(pw1.length < minLength)

  {

    alert("Password should be between " + minLength + " and " + maxLength + " characters long.");

    return false;

  }

  

  if(pw1.indexOf(invalid) > -1) 

  {

    alert("Spaces are not allowed in the Password.");

    return false;

  }

  else 

  {

    if(pw1 != pw2) 

    {

      alert("You did not enter the same password. Please re-enter your password.");

      return false;

    }

    

  }

}

