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

  reason += validateUsername(theForm.fname);
  reason += validatePass(theForm.pass);
  reason += validateE(theForm.email);
  reason += validatePass2(theForm.cpass2);

      
  if (reason != "") {
    return false;
  }

  return true;
}

function validateUsername(fld) {
    var error = "";
    
    if (fld.value == "") {
       error = "You didn't enter a username.\n";
	   document.getElementById('name-msg').style.display = 'block';
	   document.getElementById('name-msg').innerHTML="Please enter your name here!";
	   document.getElementById('name-mess').innerHTML="<img style='cursor:pointer' title='Please enter your name here!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
    } else if ((fld.value.length < 3) || (fld.value.length > 20)) {
	  error = "The username is the wrong length!";
	   document.getElementById('name-msg').style.display = 'block';
	   document.getElementById('name-msg').innerHTML="Please enter at least three characters name!";
	   document.getElementById('name-mess').innerHTML="<img style='cursor:pointer' title='Please enter at least six characters name!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
    } else {
		document.getElementById('name-msg').style.display = 'none';
		document.getElementById('name-msg').innerHTML="";
        document.getElementById('name-mess').innerHTML="<img src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-correct.png' border='0' />";
    }
    return error;
}

function validatePass(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
	document.getElementById('pass1-msg').style.display = 'block';
    document.getElementById('pass1-msg').innerHTML="You forgot to enter a password!";
	document.getElementById('pass1-mess').innerHTML="<img style='cursor:pointer' title='You forgot to enter a password!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
		document.getElementById('pass1-msg').style.display = 'block';
        document.getElementById('pass1-msg').innerHTML="Please enter a password greater than six characters!";
        error = "The password is the wrong length. \n";
         document.getElementById('pass1-mess').innerHTML="<img style='cursor:pointer' title='Please enter a password greater than six characters!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
		document.getElementById('pass1-msg').style.display = 'block';
        document.getElementById('pass1-msg').innerHTML="The password contains illegal characters!";
        document.getElementById('pass1-mess').innerHTML="<img style='cursor:pointer' title='The password contains illegal characters!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
    } else {
		document.getElementById('pass1-msg').style.display = 'none';
        document.getElementById('pass1-mess').innerHTML="<img src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-correct.png' border='0' />";
    }
   return error;
}   


function validatePass2(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
		document.getElementById('pass2-msg').style.display = 'block';
    	document.getElementById('pass2-msg').innerHTML="You forgot to enter a password!";
        document.getElementById('pass2-mess').innerHTML="<img style='cursor:pointer' title='You forgot to enter a password!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length. \n";
		document.getElementById('pass2-msg').style.display = 'block';
        document.getElementById('pass2-msg').innerHTML="Please enter a password greater than six characters!";
         document.getElementById('pass2-mess').innerHTML="<img style='cursor:pointer' title='Please enter a password greater than six characters!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
		document.getElementById('pass2-msg').style.display = 'block';
        document.getElementById('pass2-msg').innerHTML="The password contains illegal characters!";
        document.getElementById('pass2-mess').innerHTML="<img style='cursor:pointer' title='The password contains illegal characters!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
    } else {
		document.getElementById('pass2-msg').style.display = 'none';
        document.getElementById('pass2-msg').innerHTML="";
        document.getElementById('pass2-mess').innerHTML="<img src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-correct.png' border='0' />";
    }
   return error;
}

function validateE(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
		document.getElementById('email-msg').style.display = 'block';
        document.getElementById('email-msg').innerHTML="Please enter email address!";
		document.getElementById('email-mess').innerHTML="<img style='cursor:pointer' title='Please enter email address!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
	document.getElementById('email-msg').style.display = 'block';
        document.getElementById('email-msg').innerHTML="Please enter a valid email address!";
        document.getElementById('email-mess').innerHTML="<img style='cursor:pointer' title='Please enter a valid email address!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
		document.getElementById('email-msg').style.display = 'block';
        document.getElementById('email-msg').innerHTML="The email address contains illegal characters!";
        document.getElementById('email-mess').innerHTML="<img style='cursor:pointer' title='The email address contains illegal characters!' src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-error1.png' border='0' />";
        error = "The email address contains illegal characters.\n";
    } else {
		document.getElementById('email-msg').style.display = 'block';
        document.getElementById('email-msg').innerHTML="";
        document.getElementById('email-mess').innerHTML="<img src='http://www.logiixx.com/wp-content/themes/logiixx/images/form-correct.png' border='0' />";
    }
    return error;
}