
// ------------------------
// COULEURS DES CHAMPS 
// ------------------------

var couleurValide = "#000000";
var couleurInvalide = "#000000";

// ------------------------
// URL
// ------------------------


//var complementURL = "investir-lmp.fr/";
var complementURL = "";

function extraireServeurPath() {

	var path = document.location.href;
	var reg = new RegExp("^(http\:\/\/[A-Za-z0-9\.\-]{1,50}\/)");
	var server = path.split(reg)[1];
	
	return server;
	
}

// ------------------------
// EXPRESSIONS RATIONNELLES
// ------------------------

function definirType(type) {

	switch(type) {
		case "rempli" :
			var pattern = "[^]";
			break;
		case "texte" :
			var pattern = "^[A-Za-z\ \-]{1,20}$";
			break;
		case "numerique" :
			var pattern = "^[0-9\.]{1,20}$";
			break;
		case "alphanumerique" :
			var pattern = "^[A-Za-z0-9\.\-\_\ \']{1,50}$";
			break;
		case "paragraphe" :
			var pattern = "^[A-Za-z0-9\.\-\_\ \'\n]{1,1000}$";
			break;
		case "liste" :
			var pattern = "^[A-Za-z\ \.\,\-\;\_\:]{1,50}$";
			break;
		case "date" :
			var pattern = "^[0-9]{2}/[0-9]{2}/[0-9]{4}$";
			break;
		case "telephone" :
			var pattern = "^[0-9]{10}$";
			break;
		case "cp" :
			var pattern = "^[0-9]{5}$";
			break;
		case "email" :
			var pattern = "^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$";
			break;
		case "vrai" :
			var pattern = "[^0]";
			break;
		default :
			alert('Type de champ invalide !')
			break;
	}
	
	return pattern

}

// ------------------------
// FONCTION DE VERIFICATION
// ------------------------

function verificationChamp(champ,type) {
		
	var expression = new RegExp(definirType(type))
	
	if (expression.test(champ.value)) {
		
		champ.style.color = couleurValide;
		champ.style.background = "url("+templatePath+"images/tinyApply.png) no-repeat right #fff";
		//champ.style.backgroundImage = "url("+extraireServeurPath()+"style/images/tinyApply.png)";
		//champ.style.backgroundRepeat = "no-repeat";
		//champ.style.backgroundPosition = "right";
		
		return true;
		
		
	}  else {
		
 		champ.style.color = couleurInvalide;
 		champ.style.background = "url("+templatePath+"images/tinyCross.png) no-repeat right #fff";
 		//champ.style.backgroundImage = "url("+extraireServeurPath()+"style/images/tinyApply.png)";
		//champ.style.backgroundRepeat = "no-repeat";
		//champ.style.backgroundPosition = "right";
		
		return false;
	}

}


// ------------------------
// VERIFICATION GLOBALE DU FORMULAIRE
// ------------------------

function verificationGlobale(idFormulaire,tabChamps) {
	
	var validation = true;
	
	for (var i=0;i<tabChamps.length;i++) {
		
		//alert(tabChamps[i][0])
		
		if (!verificationChamp(document.getElementById(idFormulaire).elements[tabChamps[i][0]],tabChamps[i][1])) validation = false;
		
	}
	
	
	return validation;
	
}


