// FICHIER JAVASCRIPT
// ==================================================================================
// function RunFoo()
// function openPOPUP(theURL,WinName,width,height,Center,WinProps)
// function str_pad(chaine,pad_len,pad_string,pad_type)
// function sendData(data, page, method, div, navigateur)
// ==================================================================================
// -- DEBUT DU SCRIPT --
function openPOPUP(theURL,WinName,width,height,Center,WinProps)
{
	var left=((screen.width)-width)/2;
	var top=((screen.height)-height)/2;
	Center = typeof(Center)=='undefined'?'':'top='+top+',left='+left;
	WinProps = 'width='+width+',height='+height+','+Center+','+WinProps;
	window.open(theURL,WinName,WinProps);
}
// -- FIN DU SCRIPT

// -- DEBUT DU SCRIPT --
function str_pad(chaine,pad_len,pad_string,pad_type)
{
	// pad_type : -1 à gauche et 1 à droite
	// prérequis : if faut que pad_len soit supérieur

	str_len=chaine.length;

	if (pad_len>=str_len)
	{
		diff=pad_len-str_len;
		if (diff!=0)
		{
			if (pad_string.length>diff) pad_string=pad_string.substring(0,diff);
			nb_string=Math.floor(diff/pad_string.length);

			ii=0; remp='';
			while ((ii++)<nb_string) remp=remp+pad_string;

			if (pad_type==-1)
				return pad_string+chaine;
			else
				return chaine+pad_string;
		}
		else
			return chaine;
	}
	else
		return chaine;
}
// -- FIN DU SCRIPT --

// -- DEBUT DU SCRIPT --
/* Permet d'envoyer des données en GET ou POST en utilisant les XmlHttpRequest */
function sendData(data, page, method, div)
{
	if(window.XMLHttpRequest) // Firefox et autres
	   XhrObj = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try {
                XhrObj = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                XhrObj = new ActiveXObject("Microsoft.XMLHTTP");
            }
	}
    
    //définition de l'endroit d'affichage:
    var content = document.getElementById(div);
    
    //si on envoie par la méthode GET:
    if(method == "GET")
    {
        if(data == 'null')
        {
            //Ouverture du fichier sélectionné:
            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(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
}//fin fonction SendData
// -- FIN DU SCRIPT --

function confirmation(message,lien)
{ if (confirm(message)) location.href=lien;	}

function closeDivPopup() {
	// CCX 08/03/2006 ------------------------------------ fermer popup div.
	if (typeof(vertical)=="undefined") vertical=false;
	if (document.all) {
		changeSelectsVisibility(null, false);
	}
	document.getElementById("futur_popup").style.visibility="hidden";
	
	return sendData(null, "/_popup/vide.php", "GET", "futur_popup");
}

function openDivPopup(params, vertical) {
	// CCX 08/03/2006 ------------------------------------ ouvrir popup div.
	// params: paramètres utilisateur ajoutés à view.php
	// vertical: si vertical ou non
	if (typeof(vertical)=="undefined") vertical=false;
	if (document.all) {
		changeSelectsVisibility();
	}
	document.getElementById("futur_popup").style.visibility="visible";
	var newHeight="100%";
	var newWidth="100%";
	if (document.all) {
		newHeight=document.body.scrollHeight+"px";
		//newWidth=document.body.scrollWidth+"px";
	} else {
		newHeight=document.documentElement.scrollHeight+"px";
		//newWidth=document.documentElement.scrollWidth+"px";
	}
	
	document.getElementById("futur_popup").style.height=newHeight;
	document.getElementById("futur_popup").style.width=newWidth;
	var ret=sendData(params+"&pv="+(vertical?"on":""), "/_popup/view.php", "GET", "futur_popup");
	
	
	return ret;
}

function changeSelectsVisibility(oWindow, hidden) {
	// oWindow: objet fenetre à traiter.
	if (typeof(oWindow)=="undefined" || oWindow==null) {
		oWindow=window;
	}
	
	if (typeof(hidden)=="undefined") {
		hidden=true;
	}
	
	var i;
	
	for(i=0; i<oWindow.frames.length; i++) {
		changeSelectsVisibility(oWindow.frames[i], hidden);
	}
	
	var oSelects=document.getElementsByTagName("select");
	for (i=0; i<oSelects.length; i++) {
		var oElement=oSelects[i];

		if (oElement.tagName.toLowerCase()=="select") {
			oElement.style.visibility=(hidden?"hidden":"visible");
		}
	}
}

// Affiche et cache des éléments et change le style des liens choisis ; UTILISE LA LIBRAIRIE JAVASCRIPT PROTOTYPE
function toggleElementC(show)
{
	var list = ['cuisines', 'equipe', 'mot_chef_eric_gaggio', 'produits_qualite'];
	
	list.each(Element.hide);
	list.each(function(s) {
		$(s + '_link').removeClassName('list_cadeaux_on');
	});
	
	$(show + '_link').addClassName('list_cadeaux_on');
	$(show).show();
}
