function marecherche() {
f=document.recherche;
if (f.rech.value=="" || f.rech.value=="mot clef") {
	if (f.sid=="0") { alert("veuillez sélectionner un secteur d'activité ou taper un mot clé"); }
    else { document.location='pour-'+f.sid.value+'.html'; }
} else {
	if (f.rech.value.length<3) { alert("veuillez rentrer un mot clé d'au moins 3 caractères"); }
	else { f.submit(); }
	}	
}

function isDefined(variable) {
	return (!(!(document.getElementById(variable))))
}

function preloadImages() {
	var d=document; if(d.images){ if(!d.p) d.p=new Array();
	var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
	}


	if (typeof(window["Pic"]) != "undefined") {
	// Fonctions de fondu des images

	var slideShowSpeed = 3000
	var crossFadeDuration = 3

	var t
	var j = 0
	var p = Pic.length

	var preLoad = new Array()
	for (i = 0; i < p; i++){
	preLoad[i] = new Image()
	preLoad[i].src = Pic[i]
	
	}
}

function runSlideShow(){

	if (document.all){
	  document.images.SlideShow.style.filter="blendTrans(duration=2)"
	  document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
	  document.images.SlideShow.filters.blendTrans.Apply()
	}

	document.images.SlideShow.src = preLoad[j].src

	if (document.all){
	   document.images.SlideShow.filters.blendTrans.Play()
	}

	j = j + 1

	if (j > (p-1)) j=0
	t = setTimeout('runSlideShow()', slideShowSpeed)
	}
	




function alterne_produit(img1,img2) {
	if (document.getElementById("imgp").src==("http://www.facilenfil.fr/img/articles/"+img1)) {
		document.getElementById("imgp").src="http://www.facilenfil.fr/img/articles/"+img2;
	} else {
		document.getElementById("imgp").src="http://www.facilenfil.fr/img/articles/"+img1;
	}
	timer=setTimeout("alterne_produit('"+img1+"','"+img2+"')", 2000);
}



function total_commande() {
totalite=0;
quantite=0;
for (i=0;i<document.ref.length;i++) if (document.ref.elements[i].name.substr(0,3)=="qte") {
    total_ligne=document.ref.elements[i].value*document.ref.elements[i+1].value;
    totalite=totalite*1+total_ligne;
    quantite=quantite*1+document.ref.elements[i].value*1;
    document.getElementById('t'+document.ref.elements[i+1].name).innerHTML=format(total_ligne);
    }
	
    document.getElementById('total').innerHTML=format(totalite);
}

function total_liste() {
totalite=0; port=0;
for (i=0;i<document.panier.length;i++) if (document.panier.elements[i].name.substr(0,2)=="ch" && document.panier.elements[i].checked==true) {
    totalite=totalite*1+document.panier.elements[i+1].value*1;
    }
	totalite=Math.round(totalite*100)/100;
    document.panier.hp.value=totalite;
	if (totalite<75 && totalite>0) port=4.7;
	document.panier.port.value=port;
	document.panier.total.value=1*port+1*totalite;
}

function affiche_zoom(a) {
	document.getElementById('zoomeur').style.zIndex="999";
	document.getElementById('zoomeur').style.display=a;
}

function affiche_p(c) {
    if (c) { etat="block"; etat2="inline"; } else { etat="none"; etat2="none"; }
	document.getElementById('discl').style.display=etat2;
	document.getElementById('paiements').style.display=etat2;
    //cond=( (document.panier.adid.value>'0' && c) || (document.panier.adid.value=='0' && document.panier.pays.selectedIndex>0) );
	//alert((document.panier.adid));
}

function affiche_descopt(opt) {
if (document.getElementById('sp'+opt).style.display=='none') 
	document.getElementById('sp'+opt).style.display='inline'; 
else document.getElementById('sp'+opt).style.display='none';
}


function format(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur

    if (decimal == undefined) decimal = 2;
    if (separateur == undefined) separateur = ' ';
	
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}

hexinputr=155  // Initial color value.
hexinputg=175  // Initial color value.
hexinputb=75  // Initial color value.
var inc=-1 //increment variable

function fadingtext(){	         	
if(hexinputb<=256) {	
hexinputr+=5; // increase color value
hexinputg+=4; // increase color value
hexinputb+=10; // increase color value
document.getElementById("fader").style.color="rgb("+hexinputr+","+hexinputg+","+hexinputb+")"; // Set color value.
setTimeout("fadingtext()",40);	
}
else { 	
hexinputr=155  // Initial color value.
hexinputg=175  // Initial color value.
hexinputb=75  // Initial color value.
}
}

function isDefined(variable){
return (typeof(window[variable]) == 'undefined')? false : true;
}

function changePhoto(photo,id,nbphoto) {
	document.images.imgsizeprod.src="photo/"+photo;
	document.images.photozoom.src="photo/"+photo;
	document.getElementById('photoalt'+id).className="photoalternative-on";
	for (i=1;i<=nbphoto;i++) if (id!=i) document.getElementById('photoalt'+i).className="photoalternative";
	
}

function changePort(p) {
	if (p>"0") document.getElementById("leport").innerHTML=p+" €"; else document.getElementById("leport").innerHTML="offert";
	document.getElementById("total").innerHTML=format(1*document.panier.totalttchp.value+1*p);
	
}

function message_mep() {
	document.getElementById('zoommep').style.display="block";
	setTimeout("opacity('zoommep','90','0','400')",4000);	
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
	if(opacStart > opacEnd) {

for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
} else if(opacStart < opacEnd) {
for(i = opacStart; i <= opacEnd; i++) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
}
}