function ValidateLawyerSignupForm(theForm) {
var reason = "";

  reason += validateFirstname(theForm.signup_firstname);
  reason += validateLastname(theForm.signup_lastname);
  reason += validateEmail(theForm.signup_email);

  reason += validateUsername(theForm.signup_username);
  reason += validatePassword(theForm.signup_password);
  reason += validatePasswordConfirm(theForm.signup_password_confirm);
  
  
  reason += validateCell(theForm.signup_cell);
  reason += validatePhone(theForm.signup_phone);
  reason += validateEmpty(theForm.signup_address);
  reason += validateEmpty(theForm.signup_city);
  reason += validateEmpty(theForm.signup_state);
  reason += validateEmpty(theForm.signup_zipcode);  
  reason += validateEmpty(theForm.licence_number);  
  
  	  if (reason != "") {
		document.getElementById('error_message_area').innerHTML = reason; return false;
	  }else{
		return true;
	  }
}
///////////////////////////////////////
function validateFirstname(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "First Name ?<br/>"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

/////////////////
function validateLastname(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "Last Name ?<br/>"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
/////////////////
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 = "Email ?<br/>";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.<br/>";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.<br/>";
    } 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 = "Username ?<br/>";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = 'Yellow'; 
        error = "The username is the wrong length.<br/>";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "The username contains illegal characters.<br/>";
    } 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 = "Password ?<br/>";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length. <br/>";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains atleast 8 letters and no illegal characters.<br/>";
        fld.style.background = 'Yellow';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.<br/>";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}  
////////////////
function validatePasswordConfirm(fld) {
    var error = "";
	pass = document.forms.lawyer_signup_form.signup_password.value;
 	if(pass != fld.value){
	    fld.style.background = 'Yellow'; 
        error = "Wrong Password Confirm ?<br/>"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
////////////////
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
//////////////////
function validateCell(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "Cell ?<br/>";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.<br/>";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The cell number is the wrong length. Make sure you included an area code.<br/>";
        fld.style.background = 'Yellow';
    }
    return error;
}
//////////////////
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "Phone ?<br/>";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.<br/>";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.<br/>";
        fld.style.background = 'Yellow';
    }
    return error;
}
/////////////////
function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "Check Highlighted!<br/>"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
/////////////////