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);
           
   if(address.length == 0) return 0; 
        
   invalidchars = new Array(' ', ',', '[', ']', '/', '=', ';', '`', '+', '!', '#', '$', '%', '^', '&', '*', '(', ')', '~', ':', '\"', '\'', '\b', '<', '>', '?', '|', '{', '}');
   var numchars = invalidchars.length;
   var atloc=address.indexOf('@');
   var dotloc=address.lastIndexOf('.');
   var strOpt="\n\nYou also may simply leave this field blank";
         
   // Tests For one '.' and one '@' in correct order
   // And makes sure first substring isn't null
   if(atloc<1||dotloc==-1||dotloc<atloc)
   {
		alert("\nPlease enter a valid email address");
      //alert("\nInvalid E-Mail Address\n" + error_messages[1] + "\nExample: foo@bar.com");           
      return 1;
   }
                
   // Tests second and third substrings for nullness
   else if(dotloc < atloc+2 || address.length < dotloc+2)
   {
      alert("\nPlease enter a valid email address");
	  //alert("\nInvalid E-Mail Address\n"+error_messages[2] + "\nExample: foo@bar.com");     
      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("\nPlease enter a valid email address");
		 //alert("\nInvalid E-mail Address\n" + error_messages[ct+3] + "\nExample: foo@bar.com");
         return (ct+3);
      }
   }
   return 0;
}

function checkEmail() {
	if (!checkField('email')) {
			return false;
	}
	else {	
		if (Validate(document.contact.email)!=0) {
			document.contact.email.focus();
	      		return false;
		}
		else 
			return true
	}
}

// called by checkForm and passed name of field 
function checkField(listField) {
	if (eval('document.contact.' + listField + '.value.length == 0')) {
		if(listField == 'firstname'){
			alert('Please enter your First Name');
		}
		else if(listField == 'surname'){
			alert('Please enter your Surname');
		}					
		else if(listField == 'email'){
			alert('Please enter your Email Address');
			}
		eval('document.contact.' + listField + '.focus()');
		return false;
	}	
	else 
		return true	
}

// called when all fields complete and catches entry errors
function check_form() {
	if (!checkField('firstname'))
		return false
	if (!checkField('surname'))
		return false
	if(!checkEmail())
		return false								
	return true
}
