function CreateArray(length)
{
	this.size=(length+3);
	for(var i = 1; i <= length+3; i++)
		this[i] = "Unacceptable character\nOnly alpha-numerics, underscores, hyphens and periods are allowed.";
}

function Validate(email)
{
	address = new String(email.value);
	
      invalidchars = new Array(' ', ',', '[', ']', '/', '=', ';', '`', '+', '!', '#', '$', '%', '^', '&', '*', '(', ')', '~', ':', '\"', '\'', '\b', '<', '>', '?', '|', '{', '}');
      
      var numchars = invalidchars.length;
       
	error_messages = new CreateArray(numchars);  

      error_messages[0] = "Valid";
      error_messages[1] = "Address must have an @ then a \'.\'\nand cannot begin with @";
      error_messages[2] = "Address cannot have \'.\' next to @ or as final character";
      error_messages[3] = "Spaces are invalid";
      error_messages[4] = "Commas are invalid";
      error_messages[5] = "Brackets are invalid";
      error_messages[6] = "Brackets are invalid";
      error_messages[7] = "Slashes are invalid";
      error_messages[8] = "Equals are invalid";
      error_messages[9] = "Semi-Colons are invalid";
      error_messages[10] = "Accents are invalid";


	var atloc=address.indexOf('@')
	var dotloc=address.lastIndexOf('.')
         
      //Tests For one '.' and one '@' in correct order
      //And makes sure first substring isn't null
      if(atloc<1||dotloc==-1||dotloc<atloc)
      	{
         	alert("Invalid E-Mail Address\n"+error_messages[1]
			+"\nExample: bob@foo.com"		
			+"\nError Number 1");           
	      return 1;
      	}
                
	//Tests second and third substrings for nullness
      else if(dotloc < atloc+2 || address.length < dotloc+2)
      	{
		alert("Invalid E-Mail Address\n"+error_messages[2]
			+"\nExample: bob@foo.com"		
			+"\nError Number 2");     
	    	return 2;
          	}             
        
	//Tests for individual syntax errors
      //Only common keystroke errors included!        

      for(var ct=0;ct<numchars;ct++)
		{
            status=invalidchars[ct];
		if(address.indexOf(invalidchars[ct])!=-1)
			{
			alert(
                    "Invalid E-mail Address\n"
                    +error_messages[ct+3]
					+"\nExample: bob@anyname.com"
                    +"\nError Number: "
                    +(ct+3)
                  );
			tf=0;
			return (ct+3);
			}
		}
	return 0;
}
function TestEmail(email)
{
if(Validate(email)!=0)
	return false;
}

