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 == 'name'){
			alert('Please enter your name');
		}
		else if(listField == 'company'){
			alert('Please enter your company name');
			}
		else if(listField == 'telephone'){
			alert('Please enter your telephone number');
			}
		else if(listField == 'fax'){
			alert('Please enter your fax number');
			}
		else if(listField == 'email'){
			alert('Please enter your email address');
			}
		else if(listField == 'address'){
			alert('Please enter your address');
			}
		else if(listField == 'postcode'){
			alert('Please enter your post code');
			}
		else if(listField == 'country'){
			alert('Please enter your country');
			}
		eval('document.contact.' + listField + '.focus()');
		return false;
	}	
	else 
		return true	
}

// called when all fields complete and catches entry errors
function check_order_form() {
	if (!checkField('name'))
		return false
	if (!checkField('company'))
		return false
	if (!checkField('telephone'))
		return false
	if (!checkField('fax'))
		return false
	if (!checkEmail('email'))
		return false
	if (!checkField('address'))
		return false
	if (!checkField('postcode'))
		return false
	if (!checkField('country'))
		return false
	return true
}
