/**
 *
 * @access public
 * @return void
 **/
function $(id){
	return document.getElementById(id);
}

function file_ajax(fichier_ajax_a_appeler, callback) {
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);

		xhr_object.onreadystatechange  = function() {
			if(xhr_object.readyState  == 4 && (xhr_object.status  == 200 || xhr.status == 0)) {
				callback(xhr_object.responseText);
			}
		};

	xhr_object.open( "GET", fichier_ajax_a_appeler,  true);
	xhr_object.send(null);
}



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);
}


function afficheId(baliseId)
  {
  if (document.getElementById && document.getElementById(baliseId) != null)
    {
    document.getElementById(baliseId).style.display='block';
    document.getElementById(baliseId).style.display='';
    }
  }

function cacheId(baliseId)
  {
  if (document.getElementById && document.getElementById(baliseId) != null)
    {
    document.getElementById(baliseId).style.display='none';
    }
  }

function writeresults(sortiebrute) {
	if (sortiebrute!="") {
		afficheId("listechk");
		document.getElementById('listechk').innerHTML = sortiebrute;
		//$('debug').innerHTML='sortiebrute : '+sortiebrute;
		document.getElementById('contenudesonglets').style.display = 'none';
	}

	if (sortiebrute=="") {
		cacheId("listechk");
	}
}

function lire_touche(evt) {
	var keyCode = evt.which ? evt.which : evt.keyCode;
	//alert(evt.keyCode);
	memoiretouche=keyCode;
	if(keyCode==27) {
		document.getElementById('casederecherche').value='';
		document.getElementById('listechk').style.display='none';
		document.getElementById('listechk').innerHTML='';
	}
	return true;
}

function chkmoteur(critere) {
	lire_touche(event);
	//document.getElementById('debug').innerHTML=memoiretouche;
	if(memoiretouche!=27 || document.getElementById('casederecherche').value!=''){
		var table_mots_critere=critere.split(" ");
		var critere_final="";
		var i;
		for(i=0; i<table_mots_critere.length-1; i++) {
			critere_final=critere_final+table_mots_critere[i]+'-';
		}
		critere_final=critere_final+table_mots_critere[table_mots_critere.length-1];
		file_ajax('./scripts2011/bddchk_orto2011.php3?moteur='+critere_final, writeresults);
	}
	//writeresults(liste_produits);
}


var Timer_vert;
var Pas_vert = 3;
function moveLayer_vert(Sens_vert) {
	Objet=document.getElementById("listechk");
    if(parseInt(Objet.style.top) + (Pas_vert*Sens_vert)>0)  {
		clearTimeout(Timer_vert);
	}
	else if(parseInt(Objet.style.top) + (Pas_vert*Sens_vert)<-(Objet.offsetHeight-document.getElementById("listechk").offsetHeight)) {
		clearTimeout(Timer_vert);
	}
    else {
        Objet.style.top = (parseInt(Objet.style.top) + (Pas_vert*Sens_vert)) + "px";
	}
	Timer_vert = setTimeout("moveLayer_vert(" + Sens_vert + ");", 30);
}

function formatnombre(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un 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;
}

function afficheminmax(num_page,prixmin,prixmax) {
	document.all["afficheprix"].innerHTML="<p style=\"margin-left: 10px\"><font color=\"#783C96\">Sur la page "+formatnombre(num_page,0,"")+" les prix vont de "+formatnombre(prixmin,2,"")+" € &agrave; "+formatnombre(prixmax,2,"")+"  €</font></p>";
	document.all["afficheprix2"].innerHTML="<p style=\"margin-left: 10px\"><font color=\"#783C96\">Sur la page "+formatnombre(num_page,0,"")+" les prix vont de "+formatnombre(prixmin,2,"")+" € &agrave; "+formatnombre(prixmax,2,"")+"  €</font></p>";
}

var Timer;
var Pas = 3;
function moveLayer(Sens) {
	Objet=document.getElementById("contenu");

    if(parseInt(Objet.style.left) + (Pas*Sens)>0)  {
		clearTimeout(Timer);
	}
	else if(parseInt(Objet.style.left) + (Pas*Sens)<-(Objet.offsetWidth-document.getElementById("support").offsetWidth)) {
		clearTimeout(Timer);
	}
    else {
        Objet.style.left = (parseInt(Objet.style.left) + (Pas*Sens)) + "px";
	}
//	document.getElementById("sortie").innerHTML=Objet.style.left+ "px";
	Timer = setTimeout("moveLayer(" + Sens + ");", 30);
}

var basTimer;
var basPas = 3;
function basmoveLayer(Sens) {
	Objet=document.getElementById("contenu2");

    if(parseInt(Objet.style.left) + (basPas*Sens)>0)  {
		clearTimeout(basTimer);
	}
	else if(parseInt(Objet.style.left) + (basPas*Sens)<-(Objet.offsetWidth-document.getElementById("support2").offsetWidth)) {
		clearTimeout(basTimer);
	}
    else {
        Objet.style.left = (parseInt(Objet.style.left) + (basPas*Sens)) + "px";
	}
	basTimer = setTimeout("basmoveLayer(" + Sens + ");", 30);
}

function setPointer(theRow, thePointerColor, theNormalBgColor)
{
    var theCells = null;

    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    var currentColor = null;
    var newColor     = null;
    // Opera does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        newColor     = (currentColor.toLowerCase () == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
        }
    }

    return true;
} // end of the 'setPointer()' function

function ga(o,e){
	if (document.getElementById){
		a=o.id.substring(1);
		p = "";
		r = "";
		g = e.target;
		if (g) {
			t = g.id;f = g.parentNode;
			if (f) {
				p = f.id;h = f.parentNode;
				if (h)
				r = h.id;
			}
		} else{
			h = e.srcElement;f = h.parentNode;
			if (f)
				 p = f.id;
			 t = h.id;
		 }
		 if (t==a || p==a || r==a)
		 return true;
		 location.href=document.getElementById(a).href
	 }
}
