// JavaScript Document
function cocheIt(champs){
	if (champs.value == ""){
		champs.value = "X";
		}else{
			champs.value = "";
			}
	}
/*
function changeColor(myid, myvar){
	//alert('- '+myvar+' :: '+myid+' => '+document.getElementById(myid).style.color);
	if (document.getElementById(myid).style.color == "#ffffff"){
		document.getElementById(myid).style.color = "#958d88";

	}else{
		var content = myvar;
		alert (content);
	  	//document.getElementById("hidden").innerHTML = content;
		document.getElementById(myid).style.color = "#ffffff";
	}
}
*/

function Lettres_Validator(champs,strNomChamps)
{
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";

  var checkStr = champs.value;
  var allValid = 1;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = 0;
      break;
    }
  }
  if (!allValid)
  {
    alert("Veuillez ne taper que des lettres dans le champ "+strNomChamps+".");
    champs.focus();
    champs.select();
    return (1);
  }
  //if () alert("lettres ok")
  return 0;
}



function Champs_Vide(champs,strNomChamps)
{
	var intLongueur,strChaine
	strChaine=champs.value
	intLongueur=strChaine.length
	while ((strChaine.substring(intLongueur-1,intLongueur)==' ') && (intLongueur!=0))
		intLongueur -= 1;

	if (intLongueur<1)
	{
	    //alert("Saisie obligatoire dans le champ "+strNomChamps+".");
		alert("Tous les champs sont obligatoire. \n("+strNomChamps+")" );
	    champs.focus();
	    champs.select();
	    champs.value="";
	    return 1
	}

	//if () alert("champs non vide")
   	return 0;
}


function ControleAvantSubmit()
{
with (document.formulaire_adhesion)
	{
	//if (!Lettres_Validator(nom,"Nom"))
		//if (!Lettres_Validator(nom_contact,"Votre nom"))
				if (!Champs_Vide(nom,"Nom"))
				 if (!Champs_Vide(region,"Région/Département"))
				 //if (!Champs_Vide(type[0],"Type"))
				   if (!Champs_Vide(url,"url du site"))
				    if (!Champs_Vide(nom_contact,"Votre nom"))
				     if (!Champs_Vide(email,"Email"))
				      if (!Champs_Vide(message,"Message"))
					{
					document.formulaire_adhesion.submit()
					}
					else return
	}
}
function OpenLayer(id){
   if(document.getElementById(id).style.display == "block") {
    document.getElementById(id).style.display = "none" ;

   } else {
    document.getElementById(id).style.display = "block" ;

   }
   window.status =  document.getElementById(id).style.display;
}


/*--------------> Robin <---------------------- */
function blindElement(elementId)
{

	etatElement= document.getElementById(elementId).style.display;
	if(etatElement == "none"){
		new Effect.BlindDown(document.getElementById(elementId),{duration: 0.2});
	}else{
		new Effect.BlindUp(document.getElementById(elementId),{duration: 0.2});
	}
}

/** Fonction permettant la mise à jour automatique des champs. Les valeurs insérrée seront séparées par des vrigules.**/
function majChamp(champNom,valeur)
{
	champ = document.getElementById(champNom);
	valeurDuChamp = champ.value;

	if(valeurDuChamp.search(valeur)== -1){
	// La valeur n'existant pas dans le champ, je l'ajoute.
		if(valeurDuChamp == ""){
			newValeur = valeur;
		}else{
			newValeur = valeurDuChamp + "," + valeur;
		}
	}else{
	//La valeur existant dans le champ, je la retire.
		if(valeurDuChamp.search("," + valeur)== -1){
			newValeur = valeurDuChamp.replace(valeur,"");
		}else{
			newValeur = valeurDuChamp.replace("," + valeur, "");
		}
	}
	//Je supprime la virgule de début si il en reste une.
	newValeur = newValeur.replace(/^\W+/ , '');
	champ.value = newValeur;
	return false;
}


/* Pour cette fonctione, la détection du navigateur est obligatoire car IE traite les couleurs au formats héxa
	alors que FF les traite en triolet RVB ! */
function changeColor(monid){

	//Détection du navigateur
	navigateur = navigator.appName;
	couleurActuelle = document.getElementById(monid).style.color;
	if(navigateur == "Netscape"){
		if(couleurActuelle != "rgb(255, 255, 255)" ){
			document.getElementById(monid).style.color = "rgb(255, 255, 255)";
			return;
		}else{
			document.getElementById(monid).style.color = "rgb(149, 141, 136)";
		}
	}else{
		if(couleurActuelle != "#ffffff" ){
			document.getElementById(monid).style.color = "#ffffff";
			return;
		}else{
			document.getElementById(monid).style.color = "#958D88";
		}
	}
}

function test(num){
	if (num.charAt(0) == "/"){
		//var long = num.length;
		var dep = num.substring(1, 3);
	}else{
		dep = num;
	}

	codepost = document.recherche.cp.value;
	verif = codepost.indexOf(dep);

	if (verif == -1){
		if (document.recherche.cp.value == ""){
			document.recherche.cp.value = dep;
		}else{
			document.recherche.cp.value += ", "+dep;
		}
	}
}

function FormatStr(Str){
        StrNewStr="";
        for(i=0;i<=Str.length;i++){
            StrChar=Str.substring(i,i+1);
            if(StrChar != " "){
                StrNewStr += StrChar;
            }
        }
       return StrNewStr;
    }

function efface(num){
	codepost = document.recherche.cp.value;
	tosearch = num + ",";
	verif = codepost.indexOf(num);

	trouver = false;

	if (verif == -1){
		verif2 = codepost.indexOf(tosearch);

		if (verif2 != -1){
			trouver = true;
			tosupp = tosearch;
		}

	}else{
		verif2 = codepost.indexOf(tosearch);

		if (verif2 != -1){
			trouver = true;
			tosupp = tosearch;
		}else{
			trouver = true;
			tosupp = num;
		}
	}

	if (trouver == true){

		tabCode = codepost.split(",");
		//alert(trouver+" :: "+tosupp+" :: "+tabCode[0]);

		newCode = "";
		//alert (tabCode.length);
		for (i=0; i<tabCode.length; i++){
			StrNewStr="";
			for(u=0;u<=tabCode[i].length;u++){
           		StrChar = tabCode[i].substring(u,u+1);
            	if(StrChar != " "){
                	StrNewStr += StrChar;
          		}
       		}

			if(i == 0){
				if (StrNewStr != num){
					newCode += tabCode[i];
				}
			}else{
				if (StrNewStr != num){
					newCode += ","+tabCode[i];
				}
			}
		}
	//alert(newCode);
	if (newCode.charAt(0) == ","){
		document.recherche.cp.value = newCode.substring(1, newCode.length);
		}else{
			document.recherche.cp.value = newCode;
			}
	}
}
function OpenLayer(id){
   if(document.getElementById(id).style.display == "block") {
    document.getElementById(id).style.display = "none" ;

   } else {
    document.getElementById(id).style.display = "block" ;

   }
   window.status =  document.getElementById(id).style.display;
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='ad_fact.php?id_client="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpCrit(targ,selObj,restore,page,id_client) { //created by Marouane
  eval(targ+".location='ad_detail.php?page="+page+"&id_client="+id_client+"&id_crit="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenuStat(targ,selObj,restore,crit){ //Marouane version
  eval(targ+".location='ad_stats.php?id_crit="+crit+"&id_client="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}



function MM_jumpCritStat(targ,selObj,restore,id_client) { //created by Marouane
  eval(targ+".location='ad_stats.php?id_crit="+selObj.options[selObj.selectedIndex].value+"&id_client="+id_client+"'");
  if (restore) selObj.selectedIndex=0;
}

function desableField(idCheck,idChamp)
{
	champFerme = document.getElementById(idCheck).checked;
	if(champFerme){
		document.getElementById(idChamp).readOnly = 'true';
		document.getElementById(idChamp).style.backgroundColor = '#CCCCCC';
		document.getElementById(idChamp).value = 'fermé';
	}else{
		document.getElementById(idChamp).readOnly = '';
		document.getElementById(idChamp).style.backgroundColor = '#FFFFFF';
		document.getElementById(idChamp).value = '0';
	}
}
function swhowPartnerEdition(id)
{
	etat = document.getElementById("edit_" + id).style.display;
}