/*
The validation js funciton.
replaces signup-default.js for aol users
relies on signup-functions.js
*/

function verify(thisForm){

  var count = 1;
  var errstring = "Please fix the following errors: \n";
	errstring +="----------------------------\n";
  var err = false;
  
  // check signupName
 if (thisForm.signupName)
 { 
  if( ! thisForm.signupName.value ){
	errstring += "(" + count + ") You must enter your first name.\n";
	count++;
	err = true;
  } else{
	    if(!isName(thisForm.signupName.value)){
			errstring += "(" + count + ") Your name contains illegal characters.\n";
		    count++;
			err = true;
		}
  }
 }//end signupName
  
  //email
 if(thisForm.signupEmail)
 { 
  if(!thisForm.signupEmail.value ){
	errstring += "(" + count + ") You must enter an email address.\n";
	count++;
	err = true;
  } else {
        thisForm.signupEmail.value = thisForm.signupEmail.value.replace(/\s+/g, '');
		if(!isEmail(thisForm.signupEmail.value)){
		  errstring += "(" + count + ") You must enter a valid email address.\n";
		  errstring += "\t (Cannot have any spaces or illegal characters. \n";
		  errstring += "\t Should be in the general form of:  YourName@domain.xxx \n";
		  errstring += "\t where domain.xxx is your domain such as aol.com, hotmail.com, etc.) \n";
		  count++;
		  err = true;
	    }
  }
  } // end email
  
  // check password
    if(thisForm.password)
    {
        if(thisForm.password.value == ""){
            errstring += "(" + count + ") You must enter a password. \n";
            count++;
            err = true;
        } else if (!isPassword(thisForm.password.value)) {
            errstring += "(" + count + ") Your password may not contain '#', '&', '\\' or quotes.\n";
            count++;
            err = true;
        }
        if (thisForm.password2.value == "") {
            errstring += "(" + count + ") You must verify your password.\n";
            count++;
            err = true;
        }
        else if(thisForm.password2.value != thisForm.password.value){
            errstring += "(" + count + ") Your password fields must match.\n";
            count++;
            err = true;
        }
    } // end of password check
  
	// add check for security question & answer
	// not required, but if a question is chosen, an answer must be provided
  if (thisForm.securityQuestion && thisForm.securityAnswer)
  { 
    if((thisForm.securityQuestion) && (thisForm.securityQuestion.selectedIndex != "0"))
  	{
  		//check for an answer value
  		if (thisForm.securityAnswer.value == "")
  		{
  			errstring += "(" + count + ") You must enter an answer to your password retrieval question.\n";
  			count++;
  			err = true;
  		}
  	
  	
  	// not required, but if an answer is given, a question must be chosen
  	if (thisForm.securityAnswer.value != "")
  	{
  		if((!thisForm.securityQuestion) || (thisForm.securityQuestion.selectedIndex == "0"))
  		{
  			errstring += "(" + count + ")  Please choose a password retrieval question\n";
  			count++;
  			err = true;
  		}
  		
  		// check answer format
  		 if (!(checkSecurityAnswer(thisForm.securityAnswer.value)))
    		{
    			errstring += "(" + count + ")  Please make sure the answer to your password retrieval question\n";
    			errstring += "\t does not use common words such as 'a', 'an', or 'the'.\n";
    			count++;
    			err = true;
    		}	
    	}
    } 
  } // end of security q & a checks


  // check birthdate if it exists
  if (thisForm.month && thisForm.day && thisForm.year)
  {
    if(thisForm.month.selectedIndex == "0" || thisForm.day.selectedIndex == "0" || thisForm.year[thisForm.year.selectedIndex].value == "-1")
    {
	    errstring += "(" + count + ") You must enter your birth date. \n";
	    count++;
	    err = true;
    }
	}
  
    // check horoscope (sunsign) if it exists
  if (thisForm.sign)
  {
    if(thisForm.sign.selectedIndex == "0")
    {
	    errstring += "(" + count + ") You must enter your horoscope sign. \n";
	    count++;
	    err = true;
    }
	}
  
  // check gender
  if(thisForm.gender && !thisForm.gender[0].checked && !thisForm.gender[1].checked){	
	errstring += "(" + count + ") You must enter your gender. \n";
	count++;
	err = true;
  }

	//zipcode check.
	//not required, but has to be in correct format if entered
	if (thisForm.zipcode && thisForm.zipcode.value && (thisForm.zipcode.value != ""))
	{
		if (! isZipcode( thisForm.zipcode.value ) )
		{
			errstring += "(" + count + ") Your zip code needs to be a five digit number.\n";
			count++;
			err = true;
		}
	}
  
	// alert message
  if(err) alert(errstring);
  return (!err);
}
// end of function verify()
