function dosubmit() {

  var error = 0;
  var error_message = "Please Correct The Following Errors (Some special characters are not allowed): \n \n";

pattern = /^[a-zA-Z0-9\.\-\'_\, ]+$/;

  if ((document.CustomerRegistration.firstname.value== "") || (!document.CustomerRegistration.firstname.value.match(pattern))) {
    error_message += "Enter Your First Name\n";
    error = 1;
 }
  if ((document.CustomerRegistration.lastname.value== "") || (!document.CustomerRegistration.lastname.value.match(pattern))) {
    error_message += "Enter Your Last Name\n";
    error = 1;
 }
  if ((document.CustomerRegistration.address1.value== "")  || (!document.CustomerRegistration.address1.value.match(pattern))){
    error_message += "Enter Your Invoice Address\n";
    error = 1;
 }
  if ((document.CustomerRegistration.city.value== "") || (!document.CustomerRegistration.city.value.match(pattern))) {
    error_message += "Enter Your Invoice City Name\n";
    error = 1;
 }   
  if ((document.CustomerRegistration.country.value== "") || (!document.CustomerRegistration.country.value.match(pattern))) {
    error_message += "Enter The Name of Your Invoice Country\n";
    error = 1;
 }
 
pattern = /^[a-zA-Z0-9\.\-_]+@[a-zA-Z0-9\.\-_]+\.[a-zA-Z0-9\.\-_]+$/;  
 
  if ((document.CustomerRegistration.email.value== "") || (!document.CustomerRegistration.email.value.match(pattern))) {
    error_message += "Enter Your Email Address\n";
    error = 1;
 }
 
pattern = /^[0-9 \+]+$/;  
 
  if (document.CustomerRegistration.telephone.value== "") {
    error_message += "Enter Your Telephone Number\n";
    error = 1;
 }
  if (document.CustomerRegistration.istrade.checked) {

  document.CustomerRegistration.traderetail.value = "trade"
  }
  else
  {
  document.CustomerRegistration.traderetail.value = "retail"
  }
  
  pattern = /^[a-zA-Z0-9\.\-\'_\, ]+$/;  
  
  if (((document.CustomerRegistration.company.value== "") || (!document.CustomerRegistration.company.value.match(pattern))) && (document.CustomerRegistration.istrade.checked))
  {
    error_message += "Enter Your Company Name\n";
    error = 1;
 }
   
  if ((document.CustomerRegistration.username.value== "") || (!document.CustomerRegistration.username.value.match(pattern))){
    error_message += "Enter A Username\n";
    error = 1;
 }
  if (document.CustomerRegistration.password.value== "") {
    error_message += "Enter A Password\n";
    error = 1;
 }
  if (document.CustomerRegistration.confirmpassword.value== "") {
    error_message += "Confirm Your Password\n";
    error = 1;
 }
 if (!(document.CustomerRegistration.confirmpassword.value == document.CustomerRegistration.password.value)) {
    error_message += "Ensure Passwords Match\n";
    error = 1;
 }
 
/* optional fields but if present need to match against patterns */

pattern = /^[a-zA-Z0-9\.\-\'_\, ]+$/;

  if ((document.CustomerRegistration.address2.value != "") && (!document.CustomerRegistration.address2.value.match(pattern))){
    error_message += "Some special characters are not allowed in Invoice Address 2\n";
    error = 1;
 }
 
   if ((document.CustomerRegistration.address3.value != "") && (!document.CustomerRegistration.address3.value.match(pattern))){
    error_message += "Some special characters are not allowed in Invoice Address 3\n";
    error = 1;
 }

   if ((document.CustomerRegistration.county.value != "") && (!document.CustomerRegistration.county.value.match(pattern))){
    error_message += "Some special characters are not allowed in Invoice County\n";
    error = 1;
 }

  if ((document.CustomerRegistration.postcode.value!= "") && (!document.CustomerRegistration.postcode.value.match(pattern))) { 
    error_message += "Some special characters are not allowed in Invoice Postcode\n";
    error = 1;
 }

   if ((document.CustomerRegistration.firstname2.value != "") && (!document.CustomerRegistration.firstname2.value.match(pattern))){
    error_message += "Some special characters are not allowed in Delivery First Name\n";
    error = 1;
 }

   if ((document.CustomerRegistration.lastname2.value != "") && (!document.CustomerRegistration.lastname2.value.match(pattern))){
    error_message += "Some special characters are not allowed in Delivery Last Name\n";
    error = 1;
 }

   if ((document.CustomerRegistration.company2.value != "") && (!document.CustomerRegistration.company2.value.match(pattern))){
    error_message += "Some special characters are not allowed in Delivery Company\n";
    error = 1;
 }

   if ((document.CustomerRegistration.address21.value != "") && (!document.CustomerRegistration.address21.value.match(pattern))){
    error_message += "Some special characters are not allowed in Delivery Address 1\n";
    error = 1;
 }

   if ((document.CustomerRegistration.address22.value != "") && (!document.CustomerRegistration.address22.value.match(pattern))){
    error_message += "Some special characters are not allowed in Delivery Address 2\n";
    error = 1;
 }

   if ((document.CustomerRegistration.address23.value != "") && (!document.CustomerRegistration.address23.value.match(pattern))){
    error_message += "Some special characters are not allowed in Delivery Address 3\n";
    error = 1;
 }

   if ((document.CustomerRegistration.city2.value != "") && (!document.CustomerRegistration.city2.value.match(pattern))){
    error_message += "Some special characters are not allowed in Delivery City\n";
    error = 1;
 }

   if ((document.CustomerRegistration.county2.value != "") && (!document.CustomerRegistration.county2.value.match(pattern))){
    error_message += "Some special characters are not allowed in Delivery County\n";
    error = 1;
 }  

   if ((document.CustomerRegistration.country2.value != "") && (!document.CustomerRegistration.country2.value.match(pattern))){
    error_message += "Some special characters are not allowed in Delivery Country\n";
    error = 1;
 }  

   if ((document.CustomerRegistration.postcode2.value != "") && (!document.CustomerRegistration.postcode2.value.match(pattern))){
    error_message += "Some special characters are not allowed in Delivery Postcode\n";
    error = 1;
 }

pattern = /^[0-9 \+]+$/; 

   if ((document.CustomerRegistration.fax.value != "") && (!document.CustomerRegistration.fax.value.match(pattern))){
    error_message += "Fax must be numeric\n";
    error = 1;
 } 
 
  if (error == 1) {
    alert(error_message);
    return;
  } else {
    document.CustomerRegistration.submit();
  }
}
