/**************************************
 * Fonctions Utilitaires
 **************************************/
Array.prototype.in_array = function(p_val,strict) {
	var strict = strict || false;
    for(var i = 0, l = this.length; i < l; i++) {
    	if( (strict && this[i] === p_val) || (!strict && this[i] == p_val) ){
            rowid = i;
            return rowid;
        }
    }
    return false;
}

Array.prototype.concat_assoc = function(ar) {
	for(var i in ar)
	{
		this[i] = ar[i];
	}
}

function TOOL_getMousePosition(event)
{
    var e = event || window.event;
    var scroll = new Array((document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft,(document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop);;
    return new Array(e.clientX + scroll[0] - document.body.clientLeft,e.clientY + scroll[1] - document.body.clientTop);
}

var TOOL_t="";
function TOOL_tempo(duree, fct)
{
	TOOL_t = setTimeout(fct+"()",duree);
}

function TOOL_stoptempo()
{
	clearTimeout(TOOL_t);
}

function TOOL_centerPosition(bloc)
{
	if(bloc)
	{
		var dimensions = bloc.getDimensions();
		bloc.style.marginTop = Math.round(dimensions.height / 2) * -1+'px';
		bloc.style.marginLeft = Math.round(dimensions.width / 2) * -1+'px';
	}
}

function TOOL_stopPropagation(event)
{
   if (event.stopPropagation)
       event.stop.Progration();
   else if(window.event)
      window.event.cancelBubble=true;
}

function TOOL_switch(idgrp,idsel)
{
	var ctns = $$('[id^="'+idgrp+'_"]');
	ctns.each(function(val){val.style.display="none";})
	var ctns = $$('.' + idgrp + '_sup');
	ctns.each(function(val){if($(val.value)){$(val.value).style.display="none";}})
	if($(idgrp + '_' + idsel))
		$(idgrp + '_' + idsel).style.display="";
	//Active les conteneurs supplémentaires
	var ctns_sup = $$('.' + idgrp + '_' + idsel + '_sup');
	ctns_sup.each(function(val){$(val.value).style.display="";})
}

var myrules = {
	//Operations d'administration
	'.adm_switch': function(select){
		TOOL_switch(select.id,select.value);
		select.onchange = function(){
			TOOL_switch(select.id,select.value);
		}	
	}
};
// *******************************************
//
// REGLES COMPORTEMENT ENREGISTREMENT
//
// *******************************************
Behaviour.register(myrules);
