<!--
var formObj;
// For validation
var requiredFields = new Array("FirstName","LastName","Email","Address","City","State","Zip","Phone","UserName","Password","Confirm");
var requiredFieldNames = new Array("First Name","Last Name","Email","Address","City","State","Zip", "Phone","Preferred User Name","Preferred Password","Confirm Password");
//----------------------------------------------------------------------
// submit this form
function submitThisForm()
{
	if (verifyFormData())
		formObj.submit();
	
}
//----------------------------------------------------------------------
// Validate all Required Fields

function verifyFormData()
{
  if(!validate(requiredFields, requiredFieldNames, "Email", false))
    { return false; }
  else
    {    
      formObj["action"].value = "Continue";
      return true;
    }
}
//----------------------------------------------------------------------
// validate the email address
function validateEmail(inString)
{ 
// get the index of the 1st @
At = inString.indexOf("@");
if(At <= 0)
  { return false; }
// check char before @
currentChar = inString.charAt(At-1);
if((currentChar > "Z" && currentChar < "a") || 
   (currentChar > "9" && currentChar < "A") || 
   (currentChar < "0") || (currentChar > "z")
   ){ return false; }
// check char after @  
currentChar = inString.charAt(At+1);
if((currentChar > "Z" && currentChar < "a") || 
   (currentChar > "9" && currentChar < "A") || 
   (currentChar < "0") || (currentChar > "z")
  ){ return false; }
// check user name
username = inString.substring(0, At);
// dot can't be 1st char
if(username.indexOf(".") == 0) 
  { return false; }
for(i=0; i < username.length; i++)
  {
    currentChar = username.charAt(i);
    if((currentChar > "Z" && currentChar < "_") || 
	   (currentChar > "9" && currentChar < "A") ||
	   (currentChar < "-" || currentChar > "z") ||
	   (currentChar == "`" || currentChar == "/")
	   )
      { return false; }

    // dots can't be together
    if(i + 1 <= username.length && currentChar == ".")
	  { 
        if(username.charAt(i+1) == ".")
		  { return false; }
	  }	
  }
// check domain name
domainname = inString.substring(At + 1);
// domain extension must have 2 or 3 chars
if((domainname.length - (domainname.lastIndexOf(".") + 1)) < 2 || 
   (domainname.length-(domainname.lastIndexOf(".") + 1)) > 3) 
   { return false; }

for(i=0; i < domainname.length; i++)
  {
    currentChar = domainname.charAt(i);
    if((currentChar > "Z" && currentChar < "a") || 
	   (currentChar > "9" && currentChar < "A") ||
	   (currentChar < "-" || currentChar > "z") ||
	   (currentChar == "/")
	   )
      { return false; }

    // dots can't be together
    if(i + 1 <= domainname.length && currentChar == ".")
	  { 
        if(domainname.charAt(i+1) == ".")
		  { return false; }
	  }	
  }
return true;
}
//----------------------------------------------------------------------
// validate the data before it gets sent back to the server.
function validate(fieldsArray, namesArray, emailName, emailRequired)
{ 
var error = false;
var errMsg = "";
var firstError = "";
// Check for blank fields
for(i=0; i < fieldsArray.length; i++)
   { 
     if(formObj [fieldsArray[i]].value == "")
       { if(error)
           { errMsg += "\n- "+namesArray[i]; }
         else
           { error = true;
             errMsg = "The following required information has been omitted:\n\n";
             errMsg += "- "+namesArray[i];
             firstError = fieldsArray[i];
          }
       }
   }
// Verify email syntax
if(emailName != "" && !error)
  { 
    if(formObj [emailName].value != "" || emailRequired)
      {
		if(!validateEmail(formObj [emailName].value))
		  { error = true; 
		    errMsg = "Email address \"" + formObj [emailName].value + "\" contains invalid syntax.";
			firstError = emailName;
		  }
      }
  } 
if(!error) 
 {
 if(formObj["Password"].value != formObj["Confirm"].value)
	{ error = true; 
	  errMsg = "Your Preferred Password and\nConfirm Password do not match."
	  firstError = "Password"
	  formObj["Password"].value = "";
	  formObj["Confirm"].value = "";
	} 
 }
 if(!error) 
 {
 if(formObj["UserName"].value.length < 4)
	{ error = true; 
	  errMsg = "Your Preferred UserName must be\nat least 4 characters long."
	  firstError = "UserName"
	} 
 }
  
if(error)
  { alert(errMsg);
    if(document.images)
	  {// document.images seems to also cover the browsers that can adequately focus...
       formObj [firstError].focus();
       formObj [firstError].select();
	  }
    return false;
  }
return true;
}
//----------------------------------------------------------------------
function init()
{ 
  formObj = document.forms[1];
}
//----------------------------------------------------------------------
function username()
{ 
  alert('The username is already used.\nPlease choose another.');
  formObj["UserName"].focus();
  formObj["UserName"].select();
}
//----------------------------------------------------------------------
//-->
