<!--

function validateFormOnSubmit(theForm) {
  var reason = "";
  reason += validateUsername(theForm.user);
  reason += validateEmail(theForm.email);
  reason += validatePasswords(theForm.pass,theForm.retype_pass);
  reason += validatePassword(theForm.pass);
  reason += validatePassword(theForm.retype_pass);
  reason += validateCode(theForm.validation);
  reason += validateChecked(theForm.condition);
   
  if (reason != "") {
    alert("Unele campuri nu sunt completate corect:\n\n" + reason);
    return false;
  }

  return true;
}

function validateChecked(fld) {
    var error = "";
  
    if (!fld.checked) {
        fld.style.background = '#fbf2f6'; 
        error = "Va puteti inregistra doar daca sunteti de acord cu Termenii si Conditiile de utilizare.\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 = '#fbf2f6'; 
        error = "Nu ati introdus un nume.\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 20)) {
        fld.style.background = '#fbf2f6'; 
        error = "Numele trebuie sa aiba cel putin 4 caractere.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#fbf2f6'; 
        error = "Pentru nume folositi doar cifre, litere si caracterul '_' .\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 = '#fbf2f6';
        error = "Nu ati introdus o parola.\n";
    } else if ((fld.value.length < 4) || (fld.value.length > 20)) {
        error = "Parola trebuie sa aiba cel putin 4 caractere. \n";
        fld.style.background = '#fbf2f6';
    } else if (illegalChars.test(fld.value)) {
        error = "Pentru parola folositi doar cifre si litere.\n";
        fld.style.background = '#fbf2f6';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.background = '#fbf2f6';
    } else {
        fld.style.background = 'White';
    }
   return error;
}

function validatePasswords(fld1,fld2) {
 var error = "";
 if (fld1.value != fld2.value) {
  error = "Parolele nu coincid.\n";
 }
 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 = '#fbf2f6';
        error = "Nu ati introdus o adresa de email.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#fbf2f6';
        error = "Nu ati introdus o adresa de email valida.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#fbf2f6';
        error = "Adresa de email contine caractere neacceptate.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateCode(fld) {
  var error = "";
  var illegalChars = /[\W_]/; // allow only letters and numbers

   if (fld.value == "") {
        error = "Nu ati introdus codul de validare.\n";
        fld.style.background = '#fbf2f6';
    } else if (illegalChars.test(fld.value)) {
        error = "Codul de validare contine doar cifre si litere.\n";
        fld.style.background = '#fbf2f6';
    } else if (fld.value.length != 5) {
        error = "Codul nu are lungimea corecta. \n";
        fld.style.background = '#fbf2f6';
	} else {
        fld.style.background = 'White';
    }
    return error;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

-->