function validateForget(theForm) {
var reason = "";

	reason += validateNames(theForm.sub_pseudo, "nick");
	reason += validateMail(theForm.sub_mail);

  if (reason != "")
    return false;
  else
    return true;
}
function validateForgetl(theForm) {
var reason = "";

	reason += validateNames(theForm.sub_pseudo, "nick");

  if (reason != "")
    return false;
  else
    return true;
}
function validatePass(theForm) {
var reason = "";
reason += validateNames(theForm.sub_pseudo, "nick");
reason += validateMail(theForm.sub_mail);
reason += validateEmpty(theForm.sub_pass);
reason += validateEmpty(theForm.sub_pass1);
if(theForm.sub_pass!=theForm.sub_pass1) reason+="Passwords don't match\n"

  if (reason != "")
    return false;
  else
    return true;
}

function validateSubscribe(theForm) {
var reason = "";

	reason += validateNames(theForm.sub_pseudo, "nick");
	reason += validateEmpty(theForm.sub_pass);
	reason += validateMail(theForm.sub_mail);

  if (reason != "")
    return false;
  else
    return true;
}

function validateForgot(theForm) {
var reason = "";

	reason += validateMail(theForm.forgot_mail);

  if (reason != "")
    return false;
  else
    return true;
}


function validateLogin(theForm) {
var reason = "";

	reason += validateNames(theForm.log_pseudo, "nick");
	reason += validateEmpty(theForm.log_pass);

  if (reason != "")
    return false;
  else
    return true;
}


function trim(s){
  return s.replace(/^\s+|\s+$/, '');
}



function validateNames(fld, name) {
    var error = "";
    var illegalChars = /^([a-zA-Z0-9-])*$/; // allow letters, numbers and dashes
 
    if (fld.value == "") {
        fld.style.background = '#fff799'; 
        error = "Le champ " + name + " est vide.\n";
    } else if (!illegalChars.test(fld.value)) {
        fld.style.background = '#fff799'; 
        error = "Caractères invalide dans le champ " + name + ".\n";
    } else {
        fld.style.background = '#FFFFFF';
    }
    return error;
}


function validateMail(fld) {
	var error = "";
	var mask = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
	
    if (fld.value == "") {
        fld.style.background = '#fff799'; 
        error = "Le champ mail est vide.\n";
	} else if (!mask.test(fld.value)) {
        fld.style.background = '#fff799'; 
        error = "Le mail doit etre au format exemple@domaine.ext\n";
    } else {
        fld.style.background = '#FFFFFF';
    }
    return error;
}

function validateEmpty(fld, name) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#fff799'; 
        error = "Le champ " + name + " est vide.\n";
    } else {
        fld.style.background = '#FFFFFF';
    }
    return error;  
}