var timeoutList = null;
var openList = null;
var iframeList = 0;

function showList(id, e)
{
	var y;
	var divHeight;
	var div = document.getElementById(id+'Div');
	var sel = document.getElementById(id+'Table');
	var height;

	//Si une liste est deja ouverte, on la ferme
	if (openList != null && openList != id)
		hideList(openList);
	if (openList != null && openList == id)
	{
//		alert('openlist : '+openList + ' --> id : ' + id);
		hideList(openList);
		return;
	}

	if(navigator.appName == 'Netscape')
		y = e.pageY;
	else
		y = event.y;

	
	//Pour savoir de combien on a scroller
	var scrollY;
	if (self.pageYOffset) // all except Explorer
		scrollY = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
		scrollY = document.documentElement.scrollTop;
	else if (document.body) // all other Explorers
		scrollY = document.body.scrollTop;
	//Recupere la hauteur de la page
//	height = document.getElementById('pageHeight').offsetHeight;
	divHeight = div.style.height;

	

//	if (((sel.offsetTop + sel.offsetHeight) + parseInt(divHeight)) > (height + scrollY))
//		div.style.top = (sel.offsetTop - parseInt(divHeight))+'px';
//	else
	div.style.top = (sel.offsetTop + sel.offsetHeight)+'px';
	//Cherche l'element selectionne
	var tab_value = document.getElementsByName(id+'Radio');
	var topSelected = 0;
	
	var onechecked=0;
	for (var i = 0; i < tab_value.length; i++)
	{
		if (tab_value[i].checked){
			onechecked=1;
			break;
		}
		topSelected += parseInt(document.getElementById(tab_value[i].value).style.height);
	}
	if(onechecked==0){
		topSelected=0;
	}
	
	if (document.all)
	putFrame(id+'Div');
	div.style.display = 'block';
	div.scrollTop = (topSelected - (parseInt(divHeight) / 2));
	openList = id;
}

function keepList(id)
{
	if (openList == id)
		clearTimeout(timeoutList);
}

function hideList(id)
{
	document.getElementById(id+'Div').style.display = 'none';
	if (iframeList)
		document.body.removeChild(iframeList);
	if (timeoutList)
		clearTimeout(timeoutList);
	iframeList = 0;
	timeoutList = null;
	openList = null;
}

function timeoutHideList(id)
{
	if (openList != null && openList == id)
	{
		timeoutList = setTimeout('hideList("'+id+'")', 600);
		openList = id;
	}
}

function selectOption(id, val, valShow, obj, ajax_operation)
{
	var tab = document.getElementsByName(id+'Radio');

	/*Cherche si il y a une case selectionner pour remettre les couleurs normal*/
	for (var i = 0; i < tab.length; i++)
	{
		if (tab[i].checked)
		{
			var td = document.getElementById(tab[i].value);
			var textColorTmp = td.style.color;
			var backgroundTmp = td.style.backgroundColor;
			
			td.style.color = backgroundTmp;
			td.style.backgroundColor = textColorTmp;
			tab[i].checked = false;
		}
	}
	/*Check la case qui est selectionner*/
	document.getElementById(obj.id+'Radio').checked = true;

	document.getElementById(id).value = val;
	document.getElementById(id+'Show').innerHTML = valShow;
	hideList(id);
	if(typeof(ajax_operation)=='string'){ 
		eval(ajax_operation);
		//alert(ajax_operation);
	}
	
}

function changeColor(id)
{
	var td = document.getElementById(id);
	
	if (!document.getElementById(id+'Radio').checked)
	{
		var textColorTmp = td.style.color;
		var backgroundTmp = td.style.backgroundColor;

		td.style.color = backgroundTmp;
		td.style.backgroundColor = textColorTmp;
	}	
}

function putFrame(id)
{
	iframeList = document.createElement("iframe");
	var d = document.getElementById(id);

	with(iframeList.style)
	{
		position	= "absolute";
	 	width    	= d.offsetWidth+"px";
	  	height		= d.offsetHeight+"px";;
	 	top			= d.offsetTop+"px";
	  	left		= d.offsetLeft+"px";
	   	zIndex		= "1";
	}
	document.body.appendChild(iframeList);
}