// checkFormSite.js


function checkMailSite() {
	document.getElementById('action').value="1";
	document.cartouche.submit();
	return "#";
}

function removeSpaces(str){
   var newstr = new String();
   for (count=0;count < str.length; count++){
      ch = str.charAt(count);
      if((ch==' ')||(ch== '\t')||(ch=='\n')||(ch=='\r')) continue;
      newstr+=ch; 
   }
   return(newstr); 
}

function checkModifForm() {
	if (document.getElementById('divciv'))
		document.getElementById('divciv').style.color = "#000000";
	if (document.getElementById('divrealname'))
		document.getElementById('divrealname').style.color = "#000000";
	if (document.getElementById('divfirstname'))
		document.getElementById('divfirstname').style.color = "#000000";
	if (document.getElementById('divnumcard'))
		document.getElementById('divnumcard').style.color = "#000000";
	if (document.getElementById('divadresse'))
		document.getElementById('divadresse').style.color = "#000000";
	if (document.getElementById('divpostalcode'))
		document.getElementById('divpostalcode').style.color = "#000000";
	if (document.getElementById('divtown'))
		document.getElementById('divtown').style.color = "#000000";
	if (document.getElementById('divcountry'))
		document.getElementById('divcountry').style.color = "#000000";
	if (document.getElementById('divphone1'))
		document.getElementById('divphone1').style.color = "#000000";
	if (document.getElementById('divphone2'))
		document.getElementById('divphone2').style.color = "#000000";
	if (document.getElementById('divmail'))
	document.getElementById('divmail').style.color = "#000000";
	var msg = ''; 
	var valide = true;
	if (document.modif_profil.elements['civility'] != null){
		var civ = document.modif_profil.elements['civility'].value; 
		if (civ=='') {
			valide=false;
			document.getElementById('divciv').style.color = "#FF0000";
			msg = msg + 'Le champs Civilité est obligatoire\n';
		}
	}
	
	if (document.modif_profil.elements['realName'] != null){
		var nom = document.modif_profil.elements['realName'].value; 
		if (nom=='') {
			valide=false;
			document.getElementById('divrealname').style.color = "#FF0000";
			msg = msg + 'Le champs Nom est obligatoire\n';
		}
	}
	
	if (document.modif_profil.elements['firstName'] != null){
		var prenom = document.modif_profil.elements['firstName'].value; 
		if (prenom=='') {
			valide=false;
			document.getElementById('divfirstname').style.color = "#FF0000";
			msg = msg + 'Le champs Prénom est obligatoire\n';
		}
	}
	
	if (document.modif_profil.elements['numberCard'] != null){
		var num = document.modif_profil.elements['numberCard'].value; 
		if (num=='') {
			valide=false;
			document.getElementById('divnumcard').style.color = "#FF0000";
			msg = msg + 'Le champs Numéro de Carte est obligatoire\n';
		} else {
			if (isNaN(num)) {
				valide=false;
				document.getElementById('divnumcard').style.color = "#FF0000";
				msg = msg + 'Le champs Numéro de Carte doit être numérique\n';
			}
		}
	}
	
	
	var adresse = document.modif_profil.elements['address'].value; 
	if (adresse=='') {
		valide=false;
		document.getElementById('divadresse').style.color = "#FF0000";
		msg = msg + 'Le champs Adresse est obligatoire\n';
	} 
	var ville = document.modif_profil.elements['town'].value; 
	if (ville=='') {
		valide=false;
		document.getElementById('divtown').style.color = "#FF0000";
		msg = msg + 'Le champs Ville est obligatoire\n';
	} 
	var codepostal = document.modif_profil.elements['postalCode'].value; 
	if (codepostal=='') {
		valide=false;
		document.getElementById('divpostalcode').style.color = "#FF0000";
		msg = msg + 'Le champs Code postal est obligatoire\n';
	} 
	var country = document.modif_profil.elements['country'].value; 
	if (country=='') {
		valide=false;
		document.getElementById('divcountry').style.color = "#FF0000";
		msg = msg + 'Le champs Pays est obligatoire\n';
	}
	var phone1 = document.modif_profil.elements['phone1'].value;
	if (isNaN(phone1)) {
		valide=false;
		document.getElementById('divphone1').style.color = "#FF0000";
		msg = msg + 'Le champs Téléphone doit être numérique\n';
	}
	var phone2 = document.modif_profil.elements['phone2'].value;
	if (isNaN(phone2)) {
		valide=false;
		document.getElementById('divphone2').style.color = "#FF0000";
		msg = msg + 'Le champs Mobile doit être numérique\n';
	}					
	var email = document.modif_profil.elements['email'].value; 
	if (email=='') {
		valide=false;
		document.getElementById('divmail').style.color = "#FF0000";
		msg = msg + 'Le champs e-mail est obligatoire\n';
	}
	else {
		if (checkMail(email)) {
			valide=false;
			document.getElementById('divmail').style.color = "#FF0000";
			msg = msg + 'Le champs e-mail est invalide\n';
		}
	}
	/* alerte ou validation */ 
	if (valide==false) {
		alert("Impossible de valider le formulaire : \n\n" + msg + "\n"); 
		return false;
	}
	document.modif_profil.submit();
} 

	function checkMail(param) {
		if (param.search(/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9]+)+(\.[a-zA-Z0-9]+)*$/) == -1)
			return true;
		else
			return false;
	}

	function redPopup(popup, id,  width, left, top) {
		document.getElementById(popup).style.display = '';
		document.getElementById(id).style.width = width;
		document.getElementById(id).style.left = left;
		document.getElementById(id).style.top = top;
		return "#"+popup;
	}
	   
	function redPopupRayon(popup, id,  width, left, top,id_url,rayon_url) {
		document.getElementById(popup).style.display = '';
		document.getElementById(id).style.width = width;
		document.getElementById(id).style.left = left;
		document.getElementById(id).style.top = top;
		document.getElementById(id_url).value=rayon_url;
		return "#"+popup;
	}
	
	function valideFormConcours(form, nbQuestions){
		i = 0;
		while (i < nbQuestions) {
			if (document.getElementById("question" + (i+1))){
				monchamps = eval("form.question" + (i+1));
				if (!valideRadioSelect(monchamps)){
					alert("Veuillez répondre à la question " + (i+1) + ".");
					return false;
				}
			}else if (document.getElementById("tbSaisieLibre" + (i+1))){
				if (removeSpaces(document.getElementById("tbSaisieLibre" + (i+1)).value)==""){
					alert("Veuillez répondre à la question " + (i+1) + ".");
					document.getElementById("tbSaisieLibre" + (i+1)).focus();
					return false;
				}
			}
			i++;
		}
		return true;
	}

	function valideFormJeux(form){
		if (document.getElementById("reponse")){
			monchamps = eval("form.reponse");
			if (!valideRadioSelect(monchamps)){
					alert("Veuillez répondre à la question.");
					return false;
				}
		}else{
			return false;
		}
		return true;
	}


	function valideRadioSelect(champsRadio){
		j=0;
		for (j=0; j<champsRadio.length; j++)
			if (champsRadio[j].checked)
				return true;
		return false;
	}
	
	function valideFormRecetteList()
	{
		if (document.getElementById('typeDePlat').value.length == 0 &&
		document.getElementById('categorie').value.length == 0 && 
		document.getElementById('temps').value.length == 0 &&
		document.getElementById('difficulte').value.length == 0 &&
		document.getElementById('cout').value.length == 0)
		{
			alert("Veuillez saisir un critère de recherche.");
			return false;
		}
		else
			return true;
	}
	   
	function valideFormRecetteMotClef()
	{
		if (document.getElementById('motsCles').value == "")
		{
			alert("Veuillez saisir un critère de recherche.");
			return false;
		}
		else
			return true;
	}	