/*
http://codemark.tuxfamily.org/librairie-de-validation-des-formulaires-javascript/

exemple :
		if (!IsMail(V('mail'))) {
			alert("Saisissez mail");
			return false;
		}

Toutes les fonctions retournent un boolean sauf la fonction O() et V()
La fonction O() retourne un objet existant dans la page , au lieu d’utiliser document.getElementById(’id_elem’)
La fonction V() retourne la valeur d’un champ
La fonction IsEmpty() : Test si un champ est vide ou non
La fonction IsMail() : Test la validité d’un adresse mail
La fonction isIP() : Test la validité d’un adresse IP
La Fonction isURL() : Test la validité d’un adresse web
La Fonction isSSN() : Test la validité du format du numero de securité social
La Fonction IsNumeric() : Test si le champ contient une valeur numerique

*/

String.prototype.trim = function() {
    return this.replace(/^\s*|\s*$/g, "");
};

function O(elem){
	return document.getElementById(elem);
};

function V(elem) {
	return O(elem).value;
};

function IsEmpty(string){
    return (string.trim()=='');
};

function IsMail(email){
    return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email));
};

function IsNumeric(number){
    return (/^[0-9]+$/.test(number));
};

function IsIP(ip){
	return (/^(([0-2]*[0-9]+[0-9]+)\.([0-2]*[0-9]+[0-9]+)\.([0-2]*[0-9]+[0-9]+)\.([0-2]*[0-9]+[0-9]+))$/.test(ip));
};

function IsURL(string){
    return (/^(((ht|f)tp(s?))\:\/\/)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/.test(string.toLowerCase()));
};

function IsSSN(number){
    return (/^\d{3}-\d{2}-\d{4}$/.test(number));
};



/////////////////////////////////////////////////

function CheckMail(elem, coul_ok, coul_no) {
	if (!IsMail(V(elem))) {
		O(elem).style.backgroundColor = coul_no;
		return false;
	} else {
		O(elem).style.backgroundColor = coul_ok;
		return true;
	}
}	

function CheckVide(elem, coul_ok, coul_no) {
	if (IsEmpty(V(elem))) {
		O(elem).style.backgroundColor = coul_no;
		return true;
	} else {
		O(elem).style.backgroundColor = coul_ok;
		return false;
	}
}	

