msgCPVide 				= "code postal vide"; 
msgCPNumeric 			= "num&eacute;rique uniquement"; 
msgCP5chiffres			= "5 chiffres exactement";

msgErrorNom				= "nom vide";
msgErrorPrenom			= "pr&eacute;nom vide";
msgErrorRaison			= "raison sociale vide";
msgErrorMessage			= "message vide";

msgErrorEmailVide		= "adresse mail vide";
msgErrorEmailIncorrect	= "adresse mail incorrecte";

msgErrorTelVide 		= "t&eacute;l&eacute;phone vide"; 
msgErrorTel10chiffres 	= "10 chiffres exactement";
msgErrorTelIncorrect 	= "format t&eacute;l&eacute;phone incorrect";
msgErrorTelNumeric 		= "num&eacute;rique uniquement";

msgErrorDateVide		= "&nbsp;&nbsp;date vide";
msgErrorHeureVide		= "&nbsp;heure vide";

classError = "ddd_error";

/**
 * Controle Code Postal a la validation ou a la sortie du champ
 * 
 * @param string champs
 * @param string errorBox
 */
function CheckCodePostal(champs, errorBox) {
	
	numChars = "0123456789";
	var isNum = true;
	var index = 0;
	
	while ((index < $F(champs).length) && (isNum)){
		isNum = (numChars.indexOf($F(champs).charAt(index)) != -1);
		index ++;
	}
	
	if (isNum && ($F(champs) != '') && ($F(champs).length == 5)){
		$(errorBox).innerHTML = "&nbsp;";
		$(errorBox).className = '';
		$(champs).style.background = '';
		return true;
	}
	else {
		
		if($F(champs) == '') {
			$(errorBox).innerHTML = msgCPVide;
		}
		else if(!isNum) {
			$(errorBox).innerHTML = msgCPNumeric;
		}
		else if($F(champs).length != 5) {
			$(errorBox).innerHTML = msgCP5chiffres;
		}
		
		$(errorBox).className = 'errorcp';
		$(champs).style.background = '#F0B2B2';
		
		return false
	}
} 

/*
 * Controle de saisie d'un champ Text (Nom, Prenom, ...)
 */
function checkText(champs, errorBox, msgErrorType) {
	
	if($F(champs).length > 0) {
	
		$(errorBox).innerHTML = "";
		$(champs).className = '';
		$(champs).style.background = '';
		return true;
	}
	else {
		
		$(errorBox).innerHTML = msgErrorType;
		$(champs).className = 'ddd_error';
		$(champs).style.background = '#F0B2B2';
		return false;
	}
}

/*
 * Fonction de controle de validit� des adresses mail
 */
function validate_email(champs) {
	var new_string = new String($F(champs));
    if (!new_string.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) {
		return false;
	} else {
		return true;
	}
}

function checkEmail(champs, errorBox) {
	if (validate_email(champs)) {
		$(errorBox).innerHTML = "";
		$(champs).className = '';
		$(champs).style.background = '';
		return true;
	} else {
		if($F(champs).length > 0) {
			$(errorBox).innerHTML = msgErrorEmailIncorrect;
		}
		else if($F(champs).length == 0) {
			$(errorBox).innerHTML = msgErrorEmailVide;
		}
		$(champs).className = 'ddd_error';
		$(champs).style.background = '#F0B2B2';
		return false;
	}
}

/**
 * Controle d'un champ Telephone
 * 
 * @param string champs
 * @param string errorBox
 */
function checkTelephone(champs, errorBox) {
	numChars = "0123456789";
	var isNum = true;
	var isTel = true;
	var index = 0;
	
	while ((index < $F(champs).length) && (isNum)){		
		isNum = (numChars.indexOf($F(champs).charAt(index)) != -1);
		index ++;
	}
	
	var deb = $F(champs).substr(0, 2);
	if(deb!='01' && deb!='02' && deb!='03' && deb!='04' && deb!='05' && deb!='06' && deb!='08' && deb!='09') {
		isTel = false;
	}
	
	if (isNum && isTel && ($F(champs) != '') && ($F(champs).length == 10) ) {
		$(errorBox).innerHTML = "";
		$(champs).className = '';
		$(champs).style.background = '';
		return true;
	} 
	else {
		if($F(champs) == '') {
			$(errorBox).innerHTML = msgErrorTelVide;
		} 
		else if(!isNum) {
			$(errorBox).innerHTML = msgErrorTelNumeric;
		} 
		else if($F(champs).length != 10) {
			$(errorBox).innerHTML = msgErrorTel10chiffres;
		}
		else if(!isTel) {
			$(errorBox).innerHTML = msgErrorTelIncorrect;
		}
		
		$(champs).className = 'ddd_error';
		$(champs).style.background = '#F0B2B2';
		
		return false;
	}
}

/**
 * Controle d'un champ Date
 * 
 * @param string champs
 * @param string errorBox
 */
function checkDateRappel(champs, errorBox) {
	
	if (($F(champs) != '' && $F(champs) != "jj/mm/aaaa")) {
		$(champs).className = '';
		$(errorBox).innerHTML = "";
		return true;
	}
	else {
	
		if($F(champs) == '' || $F(champs) == "jj/mm/aaaa") {
			$(errorBox).innerHTML = msgErrorDateVide;
			$(champs).className = 'ddd_error';
		}
		
		return false
	}
}

/**
 * Controle du champ Heure de Rappel
 * 
 * @param string champs
 * @param string errorBox
 */
function checkHeureRappel(champs, errorBox) {
	
	if (($F(champs) != '' && $F(champs) != "-1")) {
		$(champs).className = '';
		$(errorBox).innerHTML = "";
		return true;
	}
	else {
	
		if($F(champs) == '' || $F(champs) == "-1") {
			$(errorBox).innerHTML = msgErrorHeureVide;
			$(champs).className = 'ddd_error';
		}
		
		return false
	}
}

