function addMyEvent(el,eventType,func,mode)
{
	if (navigator.appName == "Microsoft Internet Explorer" && el.attachEvent) 
	{
		el.attachEvent("on"+eventType, func);
		//el.setAttribute("on"+eventType, func);
	}
	else if(el.addEventListener)
		el.addEventListener(eventType, func, (mode)?mode:false);
}

function trim (chaine) 
{
 	return chaine.replace(/(^\s*)|(\s*$)/g, "");
}

/***************/
/*** DSELECT ***/
/***************/

var DSelect = function(MyclassListOn, MyclassListOff, MyidSelectListe, MyidSelectContent, MyidSelectTxt, MyidSelectInput)
{
	this.classListOn = MyclassListOn;
	this.classListOff = MyclassListOff;
	this.idSelectListe = MyidSelectListe;
	this.idSelectTxt = MyidSelectTxt;
	this.idSelectContent = MyidSelectContent;
	this.idSelectInput = MyidSelectInput;
	this.init();
};

DSelect.prototype.init = function()
{
	var MyIdListe = this.idSelectListe;
	var MyClassListOn = this.classListOn;
	var MyClassListOff = this.classListOff;
	var MyidSelectInput = this.idSelectInput;
	var MyIdSelectTxt = this.idSelectTxt ;
	
	//Attributions des evenements pour selectContent
	var selectContent = document.getElementById(this.idSelectContent);
	if(selectContent)
	{
		addMyEvent(selectContent,'click',function(){switch_select_liste(MyIdListe,MyClassListOn,MyClassListOff);});
		addMyEvent(selectContent,'mouseout',function(){close_select_liste(MyIdListe,MyClassListOff);});
		
		//Exception de correction de bogue sous Internet Explorer
		if(navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer")
		{
			var selectList = document.getElementById(MyIdListe);
			addMyEvent(selectList,'mousemove',function(){show_select_liste(MyIdListe,MyClassListOn);});
		}
		
		//Attributions des evenements pour selectList
		var selectList = document.getElementById(this.idSelectListe);
		if(selectList)
			addMyEvent(selectList,'mouseover',function(){show_select_liste(MyIdListe,MyClassListOn);});
	}
}

/**********************************/
/*** FONCTIONS EXTERNES DSELECT ***/
/**********************************/
function show_select_liste(idListe,MyClassListOn)
{
	var liste = document.getElementById(idListe);
	if(liste)
	{
		if(trim(liste.innerHTML) != '' && liste.className!=MyClassListOn)
			liste.className=MyClassListOn;
	}
}

function close_select_liste(idListe,MyClassListOff)
{
	var liste = document.getElementById(idListe);
	if(liste)
	{
		if(liste.className!=MyClassListOff)
			liste.className=MyClassListOff;
	}
}

function switch_select_liste(idListe,MyClassListOn,MyClassListOff)
{
	var liste = document.getElementById(idListe);
	if(liste)
	{
		if(liste.className==MyClassListOff)
			show_select_liste(idListe,MyClassListOn);
		else
			close_select_liste(idListe,MyClassListOff);
	}
}

function updateContent(idSelectTxt,idSelectInput,Value,el)
{
	if (!(el))
		el = this;
		
	var selectTxt = document.getElementById(idSelectTxt);
	var inputTxt = document.getElementById(idSelectInput);
	if(inputTxt)
		inputTxt.value = Value;
	
	if(selectTxt)
	{
		if(el)
			selectTxt.innerHTML = el.innerHTML;
	}
}

function updateContent2(idSelectTxt,idSelectInput,Value,txt)
{
	if (!(txt))
		txt = this;
		
	var selectTxt = document.getElementById(idSelectTxt);
	var inputTxt = document.getElementById(idSelectInput);
	if(inputTxt)
		inputTxt.value = Value;
	
	if(selectTxt)
	{
		if(txt)
			selectTxt.innerHTML = txt;
	}
}
