var errstring;
var count;
var err;

function verify(thisForm){

  count = 1;
  errstring = "Please fix the following errors: \n";
	errstring +="----------------------------\n";
  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
  
  
  // check country
  if(thisForm.country)
  {
	if(thisForm.country.selectedIndex == "0")
	{
		errstring += "(" + count + ") Select a country.\n";
  		count++;
  		err = true;
	}
  }
  
  // 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;
    }
    var cutoffDate=new Date();
    cutoffDate.setDate(cutoffDate.getDate()-(13*365));
    var userBDate = new Date(thisForm.year[thisForm.year.selectedIndex].value, thisForm.month.selectedIndex - 1, thisForm.day.selectedIndex);
    if ( userBDate > cutoffDate ){
        // This is the only error message underage people get 
	    errstring = "Sorry we are not able to accept your registration at this time.\n";
        alert(errstring);
        return(false);
    }

  }
  
  // check gender
  if(thisForm.gender && ! thisForm.gender.id == 'confirm_page_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;
		}
	}
// check forumLogin, This can be an empty field
 if (thisForm.forumLogin)
 { 
     if(thisForm.forumLogin.value && !isForumName(thisForm.forumLogin.value)){
         errstring += "(" + count + ") Your forum User Name contains illegal characters and-or contains spaces\n";
         count++;
         err = true;
     }
     if( thisForm.forumLogin.value && isForumName(thisForm.forumLogin.value) ){
        // This does me no good because I cannot save it
        var startURL = '/ajax/proxy.php';
        var params = 'ajax_name=checkForumLogin.php&forumLogin=' + $F('forumLogin');
        // Asynhronous option does not work on Firefox, so this message only shows when ther are other issues.
        var url = startURL + '?' + params;
        if (window.XMLHttpRequest) {              
            AJAX=new XMLHttpRequest();              
        } else {                                  
          AJAX=new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (AJAX) {
           //window.setTimeout( function(){if ( callInProgress(AJAX) ){alert("Timing out for Forum login query.");AJAX.abort();}}, 5000 );
           AJAX.open("GET", url, false);                             
           AJAX.send(null);
           if(AJAX.responseText > 0){
               window.errstring += ("(" + count + ") Forum login " + $F('forumLogin') + " is already in use.\n");
               window.err = true;
               window.count = window.count+1;
           }
        } else {
           alert("Login check, please submit again.");
        }
/*
        var ajax_auth = new Ajax.Request(startURL,
           { method:'get',
             asynchronous: true,
             parameters: params,
             onSuccess: function(t) { if (t.responseText > 0){ window.errstring += ("(" + count + ") Forum login " + $F('forumLogin') + " is already in use.\n"); window.err = true; if (count == 1){ alert( "Forum login " + $F('forumLogin') + " is already in use.  Go to http://www.tarot.com/forum to create an account.");} window.count = window.count+1;}}
           });
*/
     } 

     
 }  // End forum login
	// alert message
  if(err) alert(errstring);
  return (!err);
}
// end of function verify()

