function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validatename(theForm.Name);
  reason += validateEmail(theForm.Email);
  reason += validateUsername(theForm.UserID);
  reason += validatePassword(theForm.Password);
  reason += confirmPassword(theForm.ConfirmPassword);
  reason += MatchPassword(theForm.Password,theForm.ConfirmPassword);


      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

   return SRCM_NewCustomerRegistrationForm_wfsubmit('BUTTON',12296,0);
}


function validatename(fld) {
    var error = "";
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\%\!\"\£\$\^\&\*\~\#\¬\`\|\+\=\?\[\]]/ ;
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter your name.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow'; 
        error = "Your name contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}


function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a user ID.\n";
    } else if ((fld.value.length < 0) || (fld.value.length > 6)) {
        fld.style.background = 'Yellow'; 
        error = "User ID is too long. The user ID should be a maximum of 6 characters.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "Your user ID contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    } 
    return error;
}

function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 6) || (fld.value.length > 20)) {
        error = "Your password must be between 6 and 20 characters in length.\n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
} 

function confirmPassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't confirm your password.\n";
    } else {
        fld.style.background = 'White';
    }
   return error;
} 

function MatchPassword(fld,fld2) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
	
    if (fld.value != "" && fld2.value != ""){
    if (fld.value != fld2.value) {
	fld.style.background = 'Yellow';
        fld2.style.background = 'Yellow';
        error = "The passwords that you have entered do not match.\n";
    } else {
	if (fld.value == "") {
	  fld.style.background = 'yellow';
	}
	else
	{
	  fld.style.background = 'white';
	}

	if (fld2.value == "") {
	  fld2.style.background = 'yellow';
	}
	else
	{
	  fld.style.background = 'white';
	}

    }
   }
   return error;
}      




