//*************************
// VIDAGE D'UN CHAMPS
function vide(id){
  document.getElementById(id).value="";
}
// FIN VIDAGE D'UN CHAMPS
//*************************

//*************************
// CONTROLE D'UN CHAMPS
function check_champs(chaine){
  var tab=chaine.split(",");
  var alert=false;
  for(var i=0;i<tab.length;i++)
  {
    if(document.getElementById(tab[i]).value=="")
    {
      document.getElementById(tab[i]).className="input_error";
      alert=true;
    }
    //ON ENLEVE LA CLASS ERROR SI LE CHAMPS EST REMPLI
    if(document.getElementById(tab[i]).value!="" && document.getElementById(tab[i]).className=="input_error")
      document.getElementById(tab[i]).className="";
  }
}
// FIN CONTROLE D'UN CHAMPS
//*************************

//*************************
// CONTROLE D'UN FORM
function check_form(chaine,nom_form){
 var tab=chaine.split(",");
  var alerte=false;
  var error=false;
  //****************
  //CHECK DU TEMPLATE
  //****************
  for(var i=0;i<tab.length;i++)
  {
  	//*************
  	//ON CHECK SI YA UN SELECT
  	var tab2=tab[i].split("|");
	if(tab2[1])
	{
		if(document.getElementById(tab2[0]).value=="choisir")
		 {
			document.getElementById(tab2[0]).className="input_error";
			alerte=true;
			//ON STOCK LE PREMIER CHAMP NON REMPLI
			if(!error)
      {
          var first_error=document.getElementById(tab2[0]);
          error=true;
      }
		 }
		//ON ENLEVE LA CLASS ERROR SI LE CHAMPS EST REMPLI
		if(document.getElementById(tab2[0]).value!="choisir" && document.getElementById(tab2[0]).className=="input_error")
		  document.getElementById(tab2[0]).className="";
	}
	//***************
	//SINON PROCEDURE NORMALE
	else
	{
		if(document.getElementById(tab[i]).value=="")
		  {
			document.getElementById(tab[i]).className="input_error";
			alerte=true;
			//ON STOCK LE PREMIER CHAMP NON REMPLI
			if(!error)
      {
        var first_error=document.getElementById(tab[i]);
        error=true;
      }
		  }
		//ON ENLEVE LA CLASS ERROR SI LE CHAMPS EST REMPLI
		if(document.getElementById(tab[i]).value!="" && document.getElementById(tab[i]).className=="input_error")
		  document.getElementById(tab[i]).className="";
	}//fin else
  }//FIN FOR
  if(!alerte)
    document.getElementById(nom_form).submit();
  else
     first_error.focus();
}
// FIN CONTROLE D'UN ROM
//*************************

//*************************
// CHANGE USER
function change_user(){
  document.getElementById('lien_change').className="invisible_";
  document.getElementById('user').className="invisible_";
  document.getElementById('login').className="visible_ defaut_input_connexion";
  document.getElementById('p_login').className="visible_ no_margin gras gauche";
  document.getElementById('login').focus();
}
// FIN CHANGE USER
//*************************


//*************************
// LOGIN
function login(ev){
    
  if(ev.keyCode == 13)
   {
    
    //ON RECUPE LES VALEURS DES 2 CHAMPS
    var login=document.getElementById('login').value;
    var pwd=document.getElementById('password').value;
    
    //ON CHECK SI CHAMPS REMPLIS
    if(document.getElementById('login').className=="invisible_")//CAS AUTO USER
      var alert=check_champs('password');
    else
      var alert=check_champs('login,password');
    
    //SI CHAMPS OK ON CHECK LOG DANS LA BDD
    if(!alert)
    {
      document.getElementById("content_connexion").innerHTML="<p class='centrer gras' style='background-color:#4e4e4e;border:1px solid #000;padding:5px'>Connexion en cours...</p>";
      var xhr=null;
      // SI Firefox
        if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 
      // Si Internet Explorer
      else if(window.ActiveXObject) xhr = new ActiveXObject("Microsoft.XMLHTTP");
      //Sinon Erreur
      else alert("Votre navigateur ne prend pas en charge XmlHttpRequest");
      
      //Fonctions xhr
      xhr.open('POST', 'import/ajax/login.php', true);
      xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      xhr.onreadystatechange=function() { 
        //fonction
        if(xhr.readyState==4)
          {
            if(xhr.status==200)
              {
                if(xhr.responseText=="false")
                  document.getElementById("content_connexion").innerHTML="<p class='input_error' style='padding:10px;color:#000;text-align:left'><img style='float:left;margin:0 5px 15px 5px' src='images/chk_off' alt='' />Ces informations ne correspondent à aucun compte.</p>";
                else
                  location.href="journal.php";
              }
          }
      }//FIN FONCTIONS
      xhr.send("login="+login+"&pwd="+pwd);
     }//FIN SI CHAMPS OK
   }//FIN SI KEY = ENTER
}
// FIN CHANGE USER



//****************************
//AFFICHE / CACHE UN BLOC
//****************************
function show_close(id){
	switch(document.getElementById('show'+id).name){
	case 'plus' :
		//document.getElementById('bloc'+id).style.marginBottom="0";
		document.getElementById('bloc'+id).style.borderBottom="0";
		document.getElementById('show'+id).src="images/moins.jpg";
		document.getElementById('show'+id).name="moins";
		//save_bloc(id,1);
		break;
	case 'moins' :
		//document.getElementById('bloc'+id).style.marginBottom="15px";
		document.getElementById('bloc'+id).style.borderBottom="1px solid #a8daf5";
		document.getElementById('show'+id).src="images/plus.jpg";
		document.getElementById('show'+id).name="plus";
		//save_bloc(id,0);
		break;
	}
}
//****************************
//FIN AFFICHE / CACHE UN BLOC
//****************************


//***********************************
//SAUVEGARDE DE L'AFFICHAGE DES BLOCS
//***********************************
function save_bloc(id_bloc,mode){
  var xhr = null;
	if(window.ActiveXObject)
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	else
		xhr = new XMLHttpRequest();
 
    //Methode
    xhr.open('GET', 'import/ajax/save_bloc.php?id_bloc='+id_bloc+'&mode='+mode, true);
    xhr.onreadystatechange = function() { 
    if(xhr.readyState==4) 
    { document.getElementById('requete').innerHTML=xhr.responseText; }//fin if
    }//fin fonction 
	xhr.send(null);
}
//***********************************
//SAUVEGARDE DE L'AFFICHAGE DES BLOCS
//***********************************


//****************************
//FONCTION TEST
//****************************
function test() {
  alert('test');
}
//****************************
//FIN FONCTION TEST
//****************************


//****************************
//FONCTION POP UP
//****************************
function PopupCentrer(page,largeur,hauteur,options) {
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
//****************************
//FIN FONCTION POP UP
//****************************


//**************************
// FONCTION SUGGESTION RECHERCHE
function suggestions(mot){
    document.getElementById("res_suggestions").innerHTML="<p class='no_margin centrer gras'><img src='images/loading.gif' alt=''> Recherche en cours...</p>";
    var xhr=null;
    // SI Firefox
      if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 
    // Si Internet Explorer
    else if(window.ActiveXObject) xhr = new ActiveXObject("Microsoft.XMLHTTP");
    //Sinon Erreur
    else alert("Votre navigateur ne prend pas en charge XmlHttpRequest");
    
    //Fonctions xhr
    xhr.open('POST', 'import/ajax/suggestions.php', true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.onreadystatechange=function() { 
      //fonction
      if(xhr.readyState==4)
        {
          if(xhr.status==200)
          {
            //eval(xhr.responseText);
            document.getElementById("res_suggestions").innerHTML=xhr.responseText;
            //document.getElementById("requete").innerHTML=xhr.responseText;
            //document.getElementById("res_suggestions").style.display="block";
          }
      }
      /*else
        alert('Code erreur : ' + xhr.status);*/
      //fin fonction
    }
    xhr.send("client_cometik="+mot);
}
// FIN FONCTION SUGGESTION RECHERCHE
//**************************

//**************************
// FONCTION CAB DEJA UTILISE
function liste_cab_utilise(cab){
    document.getElementById("liste_code").innerHTML="<p class='no_margin gauche gras'><img src='images/loading.gif' alt=''> Recherche en cours...</p>";
    var xhr=null;
    // SI Firefox
      if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 
    // Si Internet Explorer
    else if(window.ActiveXObject) xhr = new ActiveXObject("Microsoft.XMLHTTP");
    //Sinon Erreur
    else alert("Votre navigateur ne prend pas en charge XmlHttpRequest");
    
    //Fonctions xhr
    xhr.open('POST', 'import/ajax/liste_code_utilise.php', true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.onreadystatechange=function() { 
      //fonction
      if(xhr.readyState==4)
        {
          if(xhr.status==200)
          {
            document.getElementById("liste_code").innerHTML=xhr.responseText;;
          }
      }
      /*else
        alert('Code erreur : ' + xhr.status);*/
      //fin fonction
    }
    xhr.send("cab="+cab);
}
// FIN FONCTION CAB DEJA UTILISE
//**************************

//**************************
// FONCTION RECHERCHE VILLE
function liste_ville(cp,champ){
    document.getElementById("liste"+champ).innerHTML="<p class='no_margin gauche gras'><img src='images/loading.gif' alt=''> Recherche en cours...</p>";
    var xhr=null;
    // SI Firefox
      if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 
    // Si Internet Explorer
    else if(window.ActiveXObject) xhr = new ActiveXObject("Microsoft.XMLHTTP");
    //Sinon Erreur
    else alert("Votre navigateur ne prend pas en charge XmlHttpRequest");
    
    //Fonctions xhr
    xhr.open('POST', 'import/ajax/liste_ville.php', true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xhr.onreadystatechange=function() { 
      //fonction
      if(xhr.readyState==4)
        {
          if(xhr.status==200)
          {
            document.getElementById("liste"+champ).innerHTML=xhr.responseText;
          }
      }
      /*else
        alert('Code erreur : ' + xhr.status);*/
      //fin fonction
    }
    xhr.send("cp="+cp+"&champ="+champ);
}
// FIN FONCTION RECHERCHE VILLE
//**************************

//****************************
//FONCTION MEME ADRESSE
function meme_adresse1(){
  document.getElementById('adresse').value=document.getElementById('adresse_siege').value;
  document.getElementById('cp').value=document.getElementById('cp_siege').value;
  document.getElementById('ville').value=document.getElementById('ville_siege').value;
}
//****************************

//****************************
//FONCTION MEME CIVILITE
function meme_civilite1(){
  document.getElementById('titre_contact').value=document.getElementById('titre_dirigeant').value;
  document.getElementById('nom_contact').value=document.getElementById('nom_dirigeant').value;
  document.getElementById('prenom_contact').value=document.getElementById('prenom_dirigeant').value;
  document.getElementById('mobile_contact').value=document.getElementById('mobile_dirigeant').value;
}
//****************************

//ON PASSE 1 AU MESSAGE LU
function lire(id,place){
	var xhr = null;
	if(window.ActiveXObject)
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	else
		xhr = new XMLHttpRequest();
 
    //Methode
    xhr.open('POST', 'taches/lire.php', true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=ISO-8859-15');
    xhr.onreadystatechange = function() { 
    if(xhr.readyState==4) 
    {
      document.getElementById('lien'+id).style.fontWeight = "normal";
      document.getElementById('mail_'+id).style.display="none";
      document.getElementById('mail2_'+id).style.display="block";
	}//fin if
    }//fin fonction 
	xhr.send('id='+id+'&place='+place);
}
//FIN 1 MESSAGE LU

//ON PASSE 1 A LA TACHE VALIDEE
function valider_tache(id,secu,place){
	var xhr = null;
	if(window.ActiveXObject)
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	else
		xhr = new XMLHttpRequest();
 
    //Methode
    xhr.open('POST', 'taches/valider_tache.php', true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=ISO-8859-15');
    xhr.onreadystatechange = function() { 
    if(xhr.readyState==4) 
    { 
      document.getElementById('error').innerHTML=xhr.responseText; 
     }//fin if
    }//fin fonction 
	xhr.send('id='+id+'&place='+place);
	location.reload();
}
//FIN 1 A LA TACHE VALIDEE


//ON DELETE LE MESSAGE
function delete_tache(id,secu,place){
	var xhr = null;
	if(window.ActiveXObject)
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	else
		xhr = new XMLHttpRequest();
 
    //Methode
    xhr.open('POST', 'taches/delete.php', true);
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=ISO-8859-15');
    xhr.onreadystatechange = function() { 
    if(xhr.readyState==4) 
    {
		document.getElementById('tr_'+id).style.display="none";
	}//fin if
    }//fin fonction 
	xhr.send('id='+id+"&secu="+secu+'&place='+place);
}
//FIN DELETE MESSAGE

//ONMOUSEOVER
function lien_blanc(id){
	document.getElementById('lien'+id).style.color="#fff";
}
//FIN ONMOUSEOVER


//ONMOUSEOUT
function lien_noir(id){
	document.getElementById('lien'+id).style.color="#000";
}
//FIN ONMOUSEOUT


function close_taches(x){
	var pix=x;
	document.getElementById('bloc_taches').style.marginTop = pix+"px";
	pix-=5;
	if(pix>-205)
	{ setTimeout(function(){close_taches(pix)},10); }
}

function open_taches(x){
	document.getElementById('bloc_taches').style.display="block";
	var pix=x;
	document.getElementById('bloc_taches').style.marginTop = pix+"px";
	pix+=5;
	if(pix<5)
	{ setTimeout(function(){open_taches(pix)},10); }
}



