function checkFormReco(){
	
	var check = true;
	
	var email = document.getElementById("email").value;
	var message = document.getElementById("message").value;
	
	if(!isEmail(email)){
		alert("Merci de rentrer une adresse email valide.");
		check = false;
	}
	if(message==""){
		alert("Merci de renseigner le message.");
		check = false;
	}
	
	if(check){
		alert("Votre envoi a \351t\351 effectu\351.");
		document.getElementById("formulaire_envoi").submit();
	}
}


function EstSirenValide(siren) {
 var estValide;
 if ( (siren.length != 9) || (isNaN(siren)) )
   estValide = false;
 else {
   // Donc le SIREN est un numérique à 9 chiffres
   var somme = 0;
   var tmp;
   for (var cpt = 0; cpt<siren.length; cpt++) {
	 if ((cpt % 2) == 1) { // Les positions paires : 2ème, 4ème, 6ème et 8ème chiffre
	   tmp = siren.charAt(cpt) * 2; // On le multiplie par 2
	   if (tmp > 9)
		 tmp -= 9;    // Si le résultat est supérieur à 9, on lui soustrait 9
	 }
	 else
	   tmp = siren.charAt(cpt);
	 somme += parseInt(tmp);
   }
   if ((somme % 10) == 0)
	 estValide = true;    // Si la somme est un multiple de 10 alors le SIREN est valide
   else
	 estValide = false;
 }
 return estValide;
}

function EstSiretValide(siret) {
 var estValide;
 if ( (siret.length != 14) || (isNaN(siret)) )
   estValide = false;
 else {
	// Donc le SIRET est un numérique à 14 chiffres
	// Les 9 premiers chiffres sont ceux du SIREN (ou RCS), les 4 suivants
	// correspondent au numéro d'établissement
	// et enfin le dernier chiffre est une clef de LUHN.
   var somme = 0;
   var tmp;
   for (var cpt = 0; cpt<siret.length; cpt++) {
	 if ((cpt % 2) == 0) { // Les positions impaires : 1er, 3è, 5è, etc...
	   tmp = siret.charAt(cpt) * 2; // On le multiplie par 2
	   if (tmp > 9)
		 tmp -= 9;    // Si le résultat est supérieur à 9, on lui soustrait 9
	 }
	else
	  tmp = siret.charAt(cpt);
	  somme += parseInt(tmp);
   }
   if ((somme % 10) == 0)
	 estValide = true; // Si la somme est un multiple de 10 alors le SIRET est valide
   else
	 estValide = false;
 }
 return estValide;
}

function sendData(data, page, method, destination, nextfct)
{
	if(document.all)
    {
    	//Internet Explorer
		var XhrObj = new ActiveXObject("Msxml2.XMLHTTP") ;
	}//fin if
 	else
  	{
   		//Mozilla
 	    var XhrObj = new XMLHttpRequest();
    }//fin else
    
	//d&eacute;finition de l'endroit d'affichage:
	if (document.getElementById(destination))
	 	var content = document.getElementById(destination);
    
    //si on envoie par la m&eacute;thode GET:
    if(method == "GET")
    {
    	if(data == 'null')
        {
        	//Ouverture du fichier s&eacute;lectionn&eacute;:
            XhrObj.open("GET", page);
        }//fin if
        else
        {
            //Ouverture du fichier en methode GET
            XhrObj.open("GET", page+"?"+data);
        }//fin else
    }//fin if
    else if(method == "POST")
    {
        //Ouverture du fichier en methode POST
        XhrObj.open("POST", page);
    }//fin elseif
    //Ok pour la page cible
    XhrObj.onreadystatechange = function()
    {
        if (XhrObj.readyState == 4 && XhrObj.status == 200 && document.getElementById(destination))
        {
			content.innerHTML = XhrObj.responseText;
			fct = new Function(nextfct);
			fct();
		}
    }    
    if(method == "GET")
    {
        XhrObj.send(null);
    }//fin if
    else if(method == "POST")
    {
        XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        XhrObj.send(data);
    }//fin elseif
}

function popupC(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);
}

function popup(url, largeur, hauteur) {
    var coordY  = ( screen.height - hauteur ) / 2;
    var coordX  = ( screen.width - largeur ) / 2;
    window.open( url, '', "top=" + coordY + ", left=" + coordX + ", width=" + largeur + ", height=" + hauteur + ", status=no, resizable=no, location=no, directories=no, scrollbars=yes");
}

function popupScroll(url, largeur, hauteur) {
    var coordY  = ( screen.height - hauteur ) / 2;
    var coordX  = ( screen.width - largeur ) / 2;
    window.open( url, '', "top=" + coordY + ", left=" + coordX + ", width=" + largeur + ", height=" + hauteur + ", status=no, resizable=yes, location=no, directories=no, scrollbars=yes");
}

function isEmail(adresse) {
	var place = adresse.indexOf("@",1);
	var point = adresse.indexOf(".",place+1);

	if ((place > -1)&&(adresse.length >2)&&(point > 1))
		return(true);
	else
		return(false);
}

function chechmail(objThis)
{
	if(isEmail(objThis.value)==false)
	{

		
		document.getElementById('msg_email').className="zone_erreur";
		document.getElementById('lbl_email').style.display="inline";
		document.getElementById('email').focus();
		return false;
		
	}
	else
	{
		document.getElementById('msg_email').className="";
		document.getElementById('lbl_email').style.display="none";	
		return true;
	}
	
}

function isDate(d) 
{
    if (d == "")
	{
        return false;
    }else{
	    e = new RegExp("^[0-9]{1,2}/[0-9]{1,2}/([0-9]{2}|[0-9]{4})$");

	    if (e.test(d)==false)
		{
	        return false;
		}else{
		    j = parseInt(d.split("/")[0],10); // jour
		    m = parseInt(d.split("/")[1],10); // mois
		    a = (d.split("/")[2]); // année

			switch(a.length)
			{
				case 2:
					a=parseInt(a);
				    if (a < 1000)
					{
				        if (a < 89)
						{
							a+=2000; // Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
						}else{
							a+=1900;
						}
				    }
					break;
				case 4:
					a=parseInt(a);
					break;
				default:
					return(false);
					break;			
			}
		    if (a%4 == 0 && a%100 !=0 || a%400 == 0)
			{
				fev = 29;
			}else{
			    fev = 28;
			}
		    nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
		    return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );
		}
	}
}

function getExtention( chaine ) {
	var exp		= new RegExp("[^\.]*$","gi");
	var res		= chaine.match(exp);
	if( res != null ) {
		return res[0];
	}
	else {
		return '';
	}
}

function FocusText(BoxName)
{
	if (BoxName.value == BoxName.defaultValue)
	{
		BoxName.value = '';
	}
}

function BlurText(BoxName)
{
	if (BoxName.value == '')
	{
		BoxName.value = BoxName.defaultValue;
	}
}

function sendDataWait(data, page, method,destination,waitAction)
{
	if(document.all)
    {
    	//Internet Explorer
		var XhrObj = new ActiveXObject("Msxml2.XMLHTTP") ;
	}//fin if
 	else
  	{
   		//Mozilla
 	    var XhrObj = new XMLHttpRequest();
    }//fin else
    
	//d&eacute;finition de l'endroit d'affichage:
 	var content = document.getElementById(destination);
    
    //si on envoie par la m&eacute;thode GET:
    if(method == "GET")
    {
    	if(data == 'null')
        {
        	//Ouverture du fichier s&eacute;lectionn&eacute;:
            XhrObj.open("GET", page);
        }//fin if
        else
        {
            //Ouverture du fichier en methode GET
            XhrObj.open("GET", page+"?"+data);
        }//fin else
    }//fin if
    else if(method == "POST")
    {
        //Ouverture du fichier en methode POST
        XhrObj.open("POST", page);
    }//fin elseif
    //Ok pour la page cible
    XhrObj.onreadystatechange = function()
    {
        if (XhrObj.readyState == 4 && XhrObj.status == 200)
		{
            content.innerHTML = XhrObj.responseText ;
			if (waitAction=="rechargeMotsCles")
			{
				rechargeMotsCles(true);
			}
		}
    }    
    if(method == "GET")
    {
        XhrObj.send(null);
    }//fin if
    else if(method == "POST")
    {
        XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        XhrObj.send(data);
    }//fin elseif
}

function supprCommentaire(monForm)
{
	document.forms[monForm].hid_actionMode.value="delete";
	document.forms[monForm].submit();
}

function afficheCedant(idCedant, myForm)
{
	document.forms[myForm].action = "cedant_consult.php4";
	document.forms[myForm].idCedant.value = idCedant;
	document.forms[myForm].submit();
}

function afficheAcquereur(idAcquereur, myForm)
{
	document.forms[myForm].action = "acquereur_consult.php4";
	document.forms[myForm].idAcquereur.value = idAcquereur;
	document.forms[myForm].submit();
}

function afficheSucces(idSucces, myForm)
{
	document.forms[myForm].action = "succes_consult.php4";
	document.forms[myForm].idSucces.value = idSucces;
	document.forms[myForm].submit();
}

function afficheSuccesOpFinanc(idSucces, myForm)
{
	document.forms[myForm].action = "succes_op_financ_consult.php4";
	document.forms[myForm].idSucces.value = idSucces;
	document.forms[myForm].submit();
}

function verifCAMinEtMax()
{
	if (document.frmInfo.txt_filtre_ca_min.value!="" && isNaN(parseInt(document.frmInfo.txt_filtre_ca_min.value)))
	{
		alert(saisir_nombre_ca_min_recherche);
		document.frmInfo.txt_filtre_ca_min.focus();
		return false;
	}
	else if (document.frmInfo.txt_filtre_ca_max.value!="" && isNaN(parseInt(document.frmInfo.txt_filtre_ca_max.value)))
	{
		alert(saisir_nombre_ca_max_recherche);
		document.frmInfo.txt_filtre_ca_max.focus();
		return false;
	}
	else if(document.frmInfo.txt_filtre_ca_min.value!="" && document.frmInfo.txt_filtre_ca_max.value!="")
	{
		if (parseInt(document.frmInfo.txt_filtre_ca_min.value)>=parseInt(document.frmInfo.txt_filtre_ca_max.value))
		{
			alert(saisir_ca_min_inf_max_recherche);
			document.frmInfo.txt_filtre_ca_min.focus();
			return false;
		}
		
	}
	return true;
}

function verifPrixMinEtMax()
{
	if (document.frmInfo.txt_prix_achat_min.value!="" && isNaN(parseInt(document.frmInfo.txt_prix_achat_min.value)))
	{
		alert(saisir_nombre_prix_min_recherche);
		document.frmInfo.txt_prix_achat_min.focus();
		return false;
	}
	else if (document.frmInfo.txt_prix_achat_max.value!="" && isNaN(parseInt(document.frmInfo.txt_prix_achat_max.value)))
	{
		alert(saisir_nombre_prix_max_recherche);
		document.frmInfo.txt_prix_achat_max.focus();
		return false;
	}
	else if(document.frmInfo.txt_prix_achat_min.value!="" && document.frmInfo.txt_prix_achat_max.value!="")
	{
		if (parseInt(document.frmInfo.txt_prix_achat_min.value)>=parseInt(document.frmInfo.txt_prix_achat_max.value))
		{
			alert(saisir_prix_min_inf_max_recherche);
			document.frmInfo.txt_prix_achat_min.focus();
			return false;
		}
		
	}
	return true;
}

function rechercher(isStricts,typeFiche)
{
	if (isStricts)
	{
		document.frmInfo.hid_type_recherche.value = "normal";
	}
	else
	{
		document.frmInfo.hid_type_recherche.value = "fromfiche";
	}
	if (document.frmInfo.recherche_cs[0].checked)
	{
		// on nettoie les parametres caches qui pourraient nous gener
		document.frmInfo.sel_type_succes.value="";
		document.frmInfo.sel_id_caisse_bp_filtre.value="";
		document.frmInfo.sel_id_code_naf_filtre.value="";
		
		document.frmInfo.action = "recherche.php4?typeRecherche="+typeFiche;
		document.frmInfo.submit();
	}
	else
	{
		// on nettoie les parametres caches qui pourraient nous gener
		document.frmInfo.hid_type_recherche.value="";
		
		document.frmInfo.action = "recherche_succes.php4";
		document.frmInfo.submit();
	}
}

function Imprimer()
{
var version = navigator.appVersion;
var navigateur = navigator.appName;
	//verification du systeme d'exploitation
	if (version.indexOf('Macintosh') != -1)
	{
		alert("Pour imprimer cette page utilisez la fonction \"Imprimer...\" du menu contextuel.");
		
	}
	//si le navigateur est IE
	if (navigateur.indexOf('Microsoft') != -1)
	{
		var lg_chaine = version.length;
		var ver1 = version.substring(22,lg_chaine-10);
		ver1 = parseFloat(ver1);
		if (ver1 >= 5)
		{

			self.print();
		}
		if (ver1 >= 4 && ver1 < 5)
		{
			alert("Impression en cours ...");
			var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
			document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
			WebBrowser1.ExecWB(6, 2);
			WebBrowser1.outerHTML = "";  
		}
		if (ver1 < 4)
		{
			alert("Pour imprimer cette page utilisez la fonction \"Imprimer...\" du menu contextuel.");
		}

	}
	//si le navigateur est Netscape
	if (navigateur.indexOf('Netscape') != -1)
	{
		ver_n = parseFloat(version);
		if (ver_n >= 4)
		{
			self.print();
		}
		else
		{
			alert("Pour imprimer cette page utilisez la fonction \"Imprimer...\" du menu contextuel.");
		}
	}
}

function demanderAcces()
{
	document.frmInfo.hid_actionMode.value = "demandeAcces";
	document.frmInfo.submit();
}

function commenter()
{
	if (document.frmInfo.txt_commentaire.value=="")
	{
		alert(saisir_commentaire_fiche);
		document.frmInfo.txt_commentaire.focus();
	}
	else
	{
		document.frmInfo.hid_actionMode.value = "commentaire";
		document.frmInfo.submit();
	}
}

function alerter()
{
	document.frmInfo.hid_actionMode.value = "alerte";
	document.frmInfo.submit();
}

function inviter()
{
	if (document.frmInfo.sel_email_invite[document.frmInfo.sel_email_invite.selectedIndex].value=="")
	{
		alert(selectionner_un_utilisateur);
		document.frmInfo.sel_email_invite.focus();
	}
	else
	{
		document.frmInfo.hid_actionMode.value = "inviter";
		document.frmInfo.submit();
	}
}

function donnerAcces(idUser)
{
	if (eval("document.frmInfo.chk_acces_fichier"+idUser+".checked")==true)
	{
		document.frmInfo.hid_acces_fichier.value 	= "oui";
	}
	else
	{
		document.frmInfo.hid_acces_fichier.value 	= "non";
	}
	document.frmInfo.hid_id_utilisateur.value 	= idUser;
	document.frmInfo.hid_actionMode.value 		= "donnerAcces";
	document.frmInfo.submit();
}

function supprimerAcces(idUser)
{
	document.frmInfo.hid_id_utilisateur.value 	= idUser;
	document.frmInfo.hid_actionMode.value 		= "supprimerAcces";
	document.frmInfo.submit();
}

function refuserAcces(idUser)
{
	document.frmInfo.hid_id_utilisateur.value 	= idUser;
	document.frmInfo.hid_actionMode.value 		= "refuserAcces";
	document.frmInfo.submit();
}

function donnerAccesFichier(idUser)
{
	if (eval("document.frmInfo.chk_a_acces_fichier"+idUser+".checked")==true)
	{
		document.frmInfo.hid_acces_fichier.value 	= "oui";
	}
	else
	{
		document.frmInfo.hid_acces_fichier.value 	= "non";
	}
	document.frmInfo.hid_id_utilisateur.value 	= idUser;
	document.frmInfo.hid_actionMode.value 		= "donnerAccesFichier";
	document.frmInfo.submit();
}
 
function rechargeImage(idUser)
{
	if (eval("document.frmInfo.chk_acces_fichier"+idUser+".checked")==true)
	{
		document.getElementById("imgPdf"+idUser).src = "img/puce_pdf.gif";
	}
	else
	{
		document.getElementById("imgPdf"+idUser).src = "img/puce_pdf_moins.gif";
	}
}

function afficheDivPopup(blnAffiche, elementToShow, elementToHide)
{
	if (!blnAffiche)
	{
		if (document.getElementById(elementToHide))
		{
			document.getElementById(elementToHide).style.visibility='visible';
		}
		document.getElementById(elementToShow).style.visibility='hidden';
	}
	else
	{
		if (document.getElementById(elementToHide))
		{
			document.getElementById(elementToHide).style.visibility='hidden';
		}
		document.getElementById(elementToShow).style.visibility='visible';
	}
}

function affecteValeur(div,zoneText,elementToShow, elementToHide)
{
	document.getElementById(div).innerHTML=document.getElementById(zoneText).value.substr(0, 150)+"<a href=\"#\" onClick=\"afficheDivPopup(true,'"+elementToShow+"','"+elementToHide+"')\" style=\"color:#000000;font-weight:bold;text-decoration:none;\"> [...]</a>";
}

function changePage(idPage)
{
	document.frmInfo.hid_id_page.value	= idPage;	
	document.frmInfo.submit();
}

function email_newsletter()
{
	if(isEmail(document.newsletter.email_addr.value))
		document.newsletter.submit();
	else
		alert("Merci de vérifier votre email.");
}

function newsletter(email){
			
	var formulaire = document.getElementById("formnews");
	var input = document.getElementById("mail_inscription_");
	
	if(isEmail(email)){
		
		input.value = email;
		formulaire.submit();		
		
	}else{
		alert("Votre email est incorrecte.");
	}
	
}

function newsletterRubrique(){
			
	var formulaire = document.getElementById("formnews");
	var input = document.getElementById("mail_inscription_");
	
	if(isEmail(input.value)){
		
		formulaire.submit();		
		
	}else{
		alert("Votre email est incorrecte.");
	}
	
}




function newsShow(){
	document.getElementById("cont-news-des").style.display="block";
}

function newsHide(){
	document.getElementById("cont-news-des").style.display="none";
}

