/**
 * Permet d'ouvrir une page du catalogue
 */
  function setOpenPageCatalogue(lookFiche) {
    if ( lookFiche == 'gamme-1') {
      document.getElementById("gamme-1").style.display  = "block";
      document.getElementById("gamme-6").style.display  = "none";
      
      $("#gam-1").css('color','#BA3807');
      $("#gam-1").css('font-weight','bold');
      $("#gam-6").css('color','#000000');
      $("#gam-6").css('font-weight','normal');
    }
    
    if ( lookFiche == 'gamme-6') {
      document.getElementById("gamme-6").style.display  = "block";
      document.getElementById("gamme-1").style.display  = "none";
      
      $("#gam-6").css('color','#BA3807');
      $("#gam-6").css('font-weight','bold');
      $("#gam-1").css('color','#000000');
      $("#gam-1").css('font-weight','normal');
    }

			var hauteur      = document.getElementById('navcontainer').offsetHeight;
			var haut_content = document.getElementById('outercontent').offsetHeight;
			hauteur = hauteur + 500 + "px";
			document.getElementById('outercontent').style.height=hauteur;
  }

/**
 * LIMITER LES CARACTERES DANS UN TEXTAREA
 **/
function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ 
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}

function displaylimit(thename, theid, thelimit){
if ( thelimit == -1 ) { thelimit = 0; }
var ns6=document.getElementById&&!document.all
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text=''; //-- <b><span id="'+theform.toString()+'">'+thelimit+'</span></b> Car. Max.
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}
 

/**
 * CHANGER LA COULEUR D'UN TR DE TABLE AU SURVOL DE LA SOURIS
 **/ 
function changeCouleurTr() {
  var ligne=document.getElementsByTagName('tr');
  for(var j=0;j<ligne.length;j++) {
    ligne[j].onmouseover=function(){this.className='trColorHover';};
    ligne[j].onmouseout=function(){this.className='trColorHoverNone';};
  }
}

/**
 * CHANGER LA CLASSE DE STYLE D'UN ELEMENT
 **/ 
function changeStyle(id) {
  document.getElementById(''+ id +'').style.display  = "block";
  document.getElementById(''+ id +'').setAttribute("class", "actualize_qte_yes");
}

/**
 *    PERMET DE VERIFIER UNE LONGUEUR MIN/MAX LORSQUE L'ON AJOUTE UNE PLAQUE
 **/ 
function verifLongueur(lgProduit,idProduit,limite,form) {
//   alert('ajax/ajax-longueur.php?lgProduit=' + lgProduit + '&idProduit=' + idProduit);
  if(lgProduit != '') {
    if ( ( result = file('ajax/ajax-longueur.php?lgProduit=' + lgProduit + '&idProduit=' + idProduit) ) && ( lgProduit.length > 2 ) ) {
//       alert(result);
      if ( result == 1 ) {
        writeDiv('alert-form','');
      } 
      
      if ( result == 2 ) {
        writeDiv('alert-form','Attention, la longueur n\'est pas comprise entre ' + limite + ' cm');
      }

      if ( result == 3 ) {
        document.getElementById('longueurPlaques').setAttribute("value", "");
        writeDiv('alert-form','Vous devez saisir une longueur entière sans . ou ,');
      }

    }
  }
}

/**
 * ECRITURE D'UNE DIV
 **/ 
function writeDiv(id,texte) {
  document.getElementById(''+ id +'').style.display  = "block";
  document.getElementById(''+ id +'').innerHTML = texte;
}

/*******************************************************************************
 *    PERMET DE DEMANDER UNE CONFIRMATION AVANT REINITILISATION DE LA BASE
 ******************************************************************************/ 
function confirmErase() {
	var mes = 'Cette action est ferme et définitive, je ne pourrais revenir en arrière, J\'accepte les conditions ?';
	if ( confirm(mes) ) {
		document.submit();
	}
	else {
		return false;
	}
}

/*******************************************************************************
 *    PERMET DE DEMANDER UNE CONFIRMATION AVANT SUPPRESSION
 ******************************************************************************/ 
function confirmDel(uri,strToScreen) {
	var mes = 'Etes vous sûr de vouloir supprimer : ' + strToScreen + ' ?';
	if ( confirm(mes) ) {
		document.location.href=uri;
	}
	else {
		return false;
	}
}

/*******************************************************************************
 *    PERMET DE DEMANDER UNE CONFIRMATION AVANT ACTION
 ******************************************************************************/ 
function confirmMessage(uri,strToScreen) {
	var mes = ' ' + strToScreen + ' ';
	if ( confirm(mes) ) {
		document.location.href=uri;
	}
	else {
		return false;
	}
}


/**
 * Permet d'ouvrir ou non des élément de la page avec un changement de classe
 */
  function setZoom(lookFiche, obj) {
  alert('dede');
    if (document.getElementById(""+ lookFiche +"").style.display == 'none') {
      $("#"+ lookFiche +"").slideDown("slow");
      document.getElementById("link-"+ lookFiche +"").className = "titreSearchCritOpen";
    } else if (document.getElementById(""+ lookFiche +"").style.display == 'block') {
      $("#"+ lookFiche +"").slideUp("slow");
      if(lookFiche == 'result-engine') {
        document.getElementById(""+ lookFiche +"").style.display  = "none";
      }
      if(lookFiche == 'stats-general') {
        document.getElementById(""+ lookFiche +"").style.display  = "none";
      }
      if(lookFiche == 'stats-link') {
        document.getElementById(""+ lookFiche +"").style.display  = "none";
      }
      document.getElementById("link-"+ lookFiche +"").className = "titreSearchCritClose";
    }
  }
/**
 * Permet d'ouvrir ou non des élément de la page avec un changement de classe
 */
  function setZoomProduit(lookFiche, typeOfPush) {
    if (document.getElementById(""+ lookFiche +"").style.display == 'none') {
      $("#"+ lookFiche +"").slideDown("slow");
    } else if (document.getElementById(""+ lookFiche +"").style.display == 'block') {
      $("#"+ lookFiche +"").slideUp("slow");
//       document.getElementById(""+ lookFiche +"").style.display  = "none";
    }
    
    if ( typeOfPush != 'actu' ) {
    	var hauteur      = document.getElementById('navcontainer').offsetHeight;
			var haut_content = document.getElementById('content').offsetHeight;
			hauteur = haut_content + 200 + "px";
			document.getElementById('outercontent').style.height=hauteur;
    }
  }
  
/**
 * Permet d'ouvrir ou non des élément de la page avec un changement de classe
 */
  function setCheckingBox(lookFiche, obj, boxName, form) {
    if (document.getElementById(""+ lookFiche +"").style.display == 'none') {
      document.getElementById(""+ lookFiche +"").style.display  = "block";
      GereChkbox("" +  boxName + "",'1');
      document.parametre.submit();
    } else if (document.getElementById(""+ lookFiche +"").style.display == 'block') {
      document.getElementById(""+ lookFiche +"").style.display  = "none";
      GereChkbox("" +  boxName + "",'0');
      document.parametre.submit();
    }
  }


/** 
 * LANCEMENT DE LA RQT AJAX
 **/ 
function file(fichier) {
  if(window.XMLHttpRequest) // FIREFOX
    xhr_object = new XMLHttpRequest();
  else if(window.ActiveXObject) // IE
    xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  else
    return(false);
    xhr_object.open("GET", fichier, false);
    xhr_object.send(null);
    if(xhr_object.readyState == 4) return(xhr_object.responseText);
  else return(false);
}
