function cacher(cacher,decrouler)
{
	if (document.getElementById(cacher).style.display=='none')
	{
		document.getElementById(cacher).style.display='block';
		document.getElementById(decrouler).style.display='none';
	}
	else
	{
		document.getElementById(cacher).style.display='none';
		document.getElementById(decrouler).style.display='block';
	}
		
}


// *********************************************** \\
// fonctions pour le "diaporama" des collections
function stop() {
	clearInterval(interv);
	encours=0;
	compteur = 0;
}

function init() {
	encours=1;
	compteur = 1;
	interv=setInterval("callSdt()",5000);
}

function callSdt() {
	if(encours == 1) {
		sendData('ajaxDetailCollection','id_collection='+compteur,'ajax/ajax_detailcollection.php');
		compteur++;
	}
	//alert(compteur);
}
// *********************************************** \\

// fonction d'appel du terminal de paiement Caisse d'Epargne
function Ouvrir_Spplus(url) {
	// on nomme la fenêtre pour afficher la page de retour internaute dans cette page
	self.name="sitecom";
	// Largeur et hauteur préconisées de la fenêtre SPPLUS
	var PopupSpplus_largeur	= 750;
	var PopupSpplus_hauteur	= 560;

	// Position haut et gauche de la fenêtre SPPLUS pour affichage centré dans l'écran
	var PopupSpplus_top	=((screen.height-PopupSpplus_hauteur)/2);
	var PopupSpplus_left=((screen.width-PopupSpplus_largeur)/2);

	// Ouverture du popup SPLUS avec barre état uniquement et focus sur la fenêtre
	var win = window.open(url, "SPPLUS","status=yes,top="+PopupSpplus_top+",left="+PopupSpplus_left+",width="+PopupSpplus_largeur+",height="+PopupSpplus_hauteur);
	win.focus();
}

// mise à jour de l'id du produit en paramètre dans le comparatif
function maj_comparatif(idv) {
	if(idv && idv > 0)
		location.href = "maj_comparatif.php?id="+idv;
		return false;
}

// enlève les espaces en début et en fin de chaine
function LRTrim(sString) {
    while (sString.substring(0,1) == ' ' || sString.substring(0,1) == '\t' || sString.substring(0,1) == '\r' || sString.substring(0,1) == '\n') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ' || sString.substring(sString.length-1, sString.length) == '\t' || sString.substring(sString.length-1, sString.length) == '\r' || sString.substring(sString.length-1, sString.length) == '\n') {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

// compter le nombre de mots d'une chaine
function Compter(chaine) {
	var exp = new RegExp("[a-zA-Z0-9éèêëàáâäóòôöíìîïçÉÈÊËÀÁÂÄÒÓÔÖÌÍÎÏÇ-]+","g");
	var tabNom = chaine.match(exp);
	var nbm;
	if (tabNom == null) {
		nbm = 0;
	}
	else {
		nbm = tabNom.length;
	}
	return nbm;
}

// vérifie que le chaine de recherche contient au moins 3 caractères
function checkSearch(valid) {
	var val = document.recherche.q.value;
	val = LRTrim(val);
	if(val == "Mots clés" || val == "" || val.length < 3 || val.length == 0) {
		/*$(document).ready(function() {
		tb_show('', 'controlleur/messagethickboxControlleur.php?action=informerMessage&width=250&height=110&erreur=&message=nbCarac', 'false');
		});*/
		document.getElementById('erreurNbCarac').style.display='block';
		return false;
	}
	else {
		var nb_mots = Compter(val);
		// si la recherche contient plusieurs mots, on propose de choisir le format
		if(nb_mots > 1) {
			$(document).ready(function() {tb_show('', 'controlleur/messagethickboxControlleur.php?action=recherche&width=400&height=300', 'false');
			});
			return false;
		}
		else {
				document.recherche.submit();
				return false;
		}
	}
}	

function checkSearchGal() {
	//alert(document.getElementById('txtNewsletter').value);
	//var val = document.recherche.txtRech.value;
	var val = document.getElementById('txtRechGal').value;
	val = LRTrim(val);
	if(val == "Mots clés" || val == "" || val.length < 3 || val.length == 0) {
		alert("Veuillez saisir au moins 3 caractères");
		return false;
	}
	else {
		sendData('ajaxGalerie','op=recherche&motif='+val,'ajax/ajax_galerie.php');
		return false;
	}
}

function checkSearchProdGal() {
	var val = document.getElementById('txtRechReal').value;
	val = LRTrim(val);
	if(val == "Mots clés" || val == "" || val.length < 3 || val.length == 0) {
		alert("Veuillez saisir au moins 3 caractères");
		return false;
	}
	else {
		sendData('ajaxRechercheProd','op=recherche&motif='+val,'ajax/ajax_rechprod.php');
		return false;
	}
}

function checkPortable(prefixe,num_tel,id_service) {
	var regl = new RegExp("["+prefixe+"]","g");
	if(num_tel.match(regl)) {
		/*sendData('ajaxValideCmd','op=maj_tel_port&tel_port='+numtel,'ajax/ajax_validecommande.php');
		sendData('ajaxValideCmd','op=selection_services&id='+id_service,'ajax/ajax_validecommande.php');
		return hs.close(this);*/
		alert('Le préfixe est OK!');
		return true;
	}
	else {
		alert('Veuillez recopier le bon préfixe!');
		return false;
	}
}

function AfficheChampSocieteSiren(formulaire, val_objet){
	//alert("affiche champ autre donneur - form = " + formulaire + " - val_objet = " + val_objet);
	if(val_objet == "Particulier" || val_objet == "Association" || val_objet == "") {
		if(num_objet == "Professionnel"){
			ShowHide('int_societe');
			ShowHide('int_siren');
		}
		num_objet = val_objet;
	}
	if(val_objet == "Professionnel") {
		ShowHide('int_societe');
		ShowHide('int_siren');
		num_objet = val_objet;
	}
}
var num_objet = "Particulier";




function fenetre2(url) {
	window.open(url,"Sanitaire.fr | Conditions générales de vente",'location=no,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,width=610,height=550,top=50,left=100,screenY=50,screenX=100');
}

function switche() {
	if (!document.all) return;
	var mr = document.getElementById('newsletter');
	var tromp = document.getElementById('trompeloeil');
	if (mr.style.display == "block" || mr.style.display == "") {
		//alert('on cache/ on affiche le trompeloeil');
		mr.style.display = "none";
		tromp.style.display = "block";
	}
	else {
		//alert('on affiche/on cache le trompeloeil');
		mr.style.display = "block";
		tromp.style.display = "none";
	}
}

//Pour formulaire de contact
function mouvementchamps(element,navIE)
{
	x = 1;
	if (navIE)
	{
		texte = 'alpha(opacity=';
		opacite = 20;
	}
	else
		opacite = 0.2;
	
	while (x < 5) { 
		//filter : alpha(opacity=0.1);
		
		if (navIE)
		{
			setTimeout("document.getElementById('"+element+"').style.filter =  '"+texte+opacite+")'",parseInt(x+'00'));
			opacite += 20;
		}
		else
		{
			setTimeout("document.getElementById('"+element+"').style.opacity = "+opacite,parseInt(x+'00'));
			opacite += 0.2;
			opacite = Math.round(opacite*100)/100; 
		}
		x++;
	}
}

//Vérification des champs du formulaire de contact
function verifFormContact()
{	
	if (navigator.appName == "Microsoft Internet Explorer")
		navIE = true;
	else
		navIE = false;
		
	valide=true;
	
	if (document.getElementById('nom').value=="")
	{

		document.getElementById('nom').style.background ="#fd8686";
		
		document.getElementById('nomErreur').style.display="block";
		mouvementchamps('nomErreur',navIE);
		
		mouvementchamps('nom',navIE);

		valide=false;
	}
	else
	{
		document.getElementById('nomErreur').style.display="none";
		document.getElementById('nom').style.background ="#ffffff";
		mouvementchamps('nom',navIE);

	}
		
	if ((document.getElementById('telephone').value=="")&& (document.getElementById('mailcontact').value!="") && (verifmail(document.getElementById('mailcontact').value)==false))
	{

		document.getElementById('mailcontact').style.background ="#fd8686";
		document.getElementById('messageMailNonValide').style.display="block";
		
		document.getElementById('mailErreur').style.display="block";
		mouvementchamps('mailErreur',navIE);
		
		mouvementchamps('messageMailNonValide',navIE);
		
		mouvementchamps('mailcontact',navIE);
		
		valide=false;
	}
	else
	{
		if ((document.getElementById('telephone').value=="") && (verifmail(document.getElementById('mailcontact').value)==false))
		{	

			document.getElementById('mailcontact').style.background ="#fd8686";
			
			document.getElementById('mailErreur').style.display="block";
			mouvementchamps('mailErreur',navIE);
			
			mouvementchamps('messageMailNonValide',navIE);
			
			mouvementchamps('mailcontact',navIE);
			
			valide=false;

		}
		else
		{
			document.getElementById('mailErreur').style.display="none";
			document.getElementById('mailcontact').style.background ="#ffffff";
			document.getElementById('messageMailNonValide').style.display="none";
			mouvementchamps('mailcontact',navIE);
		}
	}	
	
	if ((document.getElementById('mailcontact').value=="")&&(document.getElementById('telephone').value==""))
	{
		document.getElementById('telephone').style.background ="#fd8686";
		
		document.getElementById('telErreur').style.display="block";
		
		mouvementchamps('telErreur',navIE);
		
		mouvementchamps('telephone',navIE);
		
		valide=false;
	}
	else
	{
		document.getElementById('telErreur').style.display="none";
		document.getElementById('telephone').style.background ="#ffffff";
		mouvementchamps('telephone',navIE);
	}	
	
	if (document.getElementById('titre').value=="")
	{
		document.getElementById('titre').style.background ="#fd8686";
		document.getElementById('titreErreur').style.display="block";
		mouvementchamps('titreErreur',navIE);
		
		mouvementchamps('titre',navIE);
		valide=false;
	}
	else
	{
		document.getElementById('titreErreur').style.display="none";
		document.getElementById('titre').style.background ="#ffffff";
		mouvementchamps('titre',navIE);
	}	
	if (document.getElementById('zone_Text').value=="")
	{
		document.getElementById('zone_Text').style.background ="#fd8686";
		document.getElementById('texteErreur').style.display="block";
		mouvementchamps('texteErreur',navIE);
		
		mouvementchamps('zone_Text',navIE);
		valide=false;
	}
	else
	{
		document.getElementById('texteErreur').style.display="none";
		document.getElementById('zone_Text').style.background ="#ffffff";
		mouvementchamps('zone_Text',navIE);
	}
	if (valide)
	{
		document.getElementById('phraseErreur').style.display="none";
		document.form_contact.submit();
	}
	else
	document.getElementById('phraseErreur').style.display="block";

		
	return valide;
}


//Verifie l'adresse E-Mail
function verifmail(adrr){
  var reg= /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
  if(reg.test(adrr)==true) return true ;
  else return false;  
}
