// 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 closeDivPopup() {
	// CCX 08/03/2006 ------------------------------------ fermer popup div.
	if (typeof(vertical)=="undefined") vertical=false;
	/*if (document.all) {
		changeSelectsVisibility(null, false);
	}*/
	
	$('futur_popup').hide();
		
	//document.body.style.overflow = "auto";
	
	//return sendData(null, "/_popup/vide.php", "GET", "futur_popup");
	
	new Ajax.Updater(
		"futur_popup", 
		"/_popup/vide.php?" + null, 
		{ method: 'get' } 
	);
	//$('futur_popup').innerHTML = '<div id="back_transparent_popup"></div>';
}

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 (document.all) {
		changeSelectsVisibility();
	}*/
	
	
	//document.body.style.overflow = "hidden";
	
	//$('futur_popup').innerHTML = '<div id="back_transparent_popup"></div>';
	$('futur_popup').show();
	
	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";
	}
	
	$('futur_popup').style.height=newHeight;
	$('futur_popup').style.width=newWidth;
	
	//var ret=sendData(params+"&pv="+(vertical?"on":""), "/_popup/view.php", "GET", "futur_popup");
	if (typeof(vertical)=="undefined")
	{
		vertical=false;
		divIdContenu="contenu_popup";
	} else {
		divIdContenu="contenu_popup_vertical";
	}
	new Ajax.Updater(
		"futur_popup", 
		"/_popup/view.php?" + params+"&pv="+(vertical?"on":""), 
		{ 
			method: 'get',
			onComplete: function()
			{
				//new Effect.Appear(divIdContenu);
				$(divIdContenu).show();
			}
		} 
	);
	
	//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");
		}
	}
}

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



// Affiche et cache des éléments passés oar tableau ; UTILISE LA LIBRAIRIE JAVASCRIPT PROTOTYPE
function toggleElement(show, hide)
{
	for(var i = 0; i < hide.length; i++)
	{
		$(hide[i]).hide()
	}
	for(var i = 0; i < show.length; i++)
	{
		$(show[i]).show()
	}
}

function addEvent(obj, evType, fn, useCapture){
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
	else {
		alert("Handler could not be attached");
	}
}

function manageOptions(listeFrom, listeTo, opt)
{
	if (listeFrom.options.selectedIndex != -1)
	{
		for(var i = 0; i < listeFrom.options.length; i++)
		{
			if(listeFrom.options[i].selected)
			{
				var option = new Option(listeFrom.options[i].text, listeFrom.options[i].value, false, true);
				listeTo.options[listeTo.options.length] = option; 
			}
		}
		for(var j = listeFrom.options.length - 1; j >= 0; j--)
		{
			if(listeFrom.options[j].selected)
			{
				listeFrom.options[j] = null;
			}
		}
		if(opt) getOptions($('secteurs'));
	} else {
		alert("Sélectionnez un élément dans la liste");
		listeFrom.setStyle({
		  backgroundColor: '#ffcc00'
		});
		listeTo.setStyle({
		  backgroundColor: '#fff'
		});
	}
}
function selectAllOptions(liste, label)
{
	for(i = 0; i < liste.options.length; i++)
	{
		liste.options[i].selected = true;
	}
	if(liste.options.length == 0) 
	{
		liste.style.backgroundColor='#ffcc00';
		alert('Remplissez le champs ' + label);
		return false;
	} else {
		return true;
	}
}

function getOptions(gselect)
{
	var url = "";
	for(i = 0; i < gselect.options.length; i++)
	{
		url = url + gselect.options[i].value + ',';
	}
	if(url != '') location.href = '/rep-membres/adm_mbres-add/secteur-' + url.substring(0,url.length-1) + '.html';
	else location.href = '/rep-membres/adm_mbres-add.html';
}

function free_of_distant_frame()
{
	if (top.location != self.document.location)
	{
		top.location = self.document.location;
	}
} 
addEvent(window, 'load', free_of_distant_frame, false);

var Akstools = {
	_Flash: function() {
		if(typeof(doFlash) == 'function') doFlash();
	},
	
	_Str_pad: function(chaine,pad_len,pad_string,pad_type) {
		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;
	},
	
	load: function() {
		new Event.observe(window, 'load', function() {
			// Flash
			Akstools._Flash();
		});
	}
}

Akstools.load();
