
var win;

function MakeNewList(direction, newvalue, newtext, maxkey)
{
	if (direction != "back")
	{
		history1[hindex] = new Array();
		history2[hindex] = new Array();
		
		for (i=0 ; i<document.modform.list.length ; i++)
		{
			history1[hindex][i] = document.modform.list.options[i].value;
			history2[hindex][i] = document.modform.list.options[i].text;
		}
		
		hindex++;
	}
	
	if (direction == "back" && hindex > 0)
	{
		hindex--;
		document.modform.list.length = history1[hindex].length;
		
		for (i=0 ; i<history1[hindex].length ; i++)
		{
			document.modform.list.options[i].value = history1[hindex][i];
			document.modform.list.options[i].text = history2[hindex][i];
		}
	}
	
	if (direction == "add")
	{
		if (newvalue == 0) return;
		//alert(newvalue+newtext);
		
	 	if (document.modform.list.length < maxkey)
		{
			for (i=0 ; i<document.modform.list.length ; i++)
			{
				//if (document.modform.list.options[i].value == newvalue) return;
				if (document.modform.list.options[i].value == 0)
				{
					document.modform.list.length = 0;
					break;
				}
			}
			
			document.modform.list.length++;
			document.modform.list.options[document.modform.list.length-1].value = newvalue;
			document.modform.list.options[document.modform.list.length-1].text = newtext + " (touche " + (i+1) + ")";
			document.modform.list.selectedIndex = document.modform.list.length-1;
			return;
		}
		else
		{
			document.getElementById('maxmod').style.display='block';
			return;
		}
	}
	
	var flag = 0;
	var index = document.modform.list.selectedIndex;
	if (index < 0 || index > (document.modform.list.length-1)) return;
	
	var text = document.modform.list.options[index].text;
	var value = document.modform.list.options[index].value;
	
	if (direction == 'up' || direction == "down")
	{
		var ObjReg = new RegExp("touche [0-9]", "ig"); 
		
		if (direction == 'up') flag=-1
		if (direction == 'down') flag=1;
		
		var index2 = index + flag;
		if (index2 < 0 || index2 > (document.modform.list.length-1)) return;
		var text2 = document.modform.list.options[index2].text;
		var value2 = document.modform.list.options[index2].value;
		
		a = text.lastIndexOf(" ");
		b = text2.lastIndexOf(" ");
		
		document.modform.list.options[index].text = text2.substr(0, b+1) + (index+1) + ")";
		document.modform.list.options[index2].text = text.substr(0, a+1) + (index+flag+1) + ")";
		
		document.modform.list.options[index].value = value2;
		document.modform.list.options[index2].value = value;
		
		document.modform.list.selectedIndex = index + flag;
		return;
	}
	
	if (direction == "delete")
	{
		for (i=index ; i<document.modform.list.length-1 ; i++)
		{
			var index2 = i+1;
			var text2 = document.modform.list.options[index2].text;
			var value2 = document.modform.list.options[index2].value;
			
			document.modform.list.options[i].text = text2;
			document.modform.list.options[i].value = value2;
		}
		
		document.modform.list.length--;
		
		if (document.modform.list.length == 0)
		{
			document.modform.list.length = 1;
			document.modform.list.options[0].text = "";
			// document.modform.list.options[0].text = "Arborescence vide";
			document.modform.list.options[0].value = 0;
		}
		
		return;
	}
}

function CheckModifyModule()
{
	var arbo = "";
	
	for (i=0 ; i<document.modform.list.length ; i++)
	{
		if (document.modform.list.options[i].value != 0)
			arbo = arbo + document.modform.list.options[i].value + "|";
	}
	
	document.modform.arbo.value = arbo.substr(0, (arbo.length-1));
	
	return true;
}

function OpenWindow(file, width, height)
{
	if (width && height)
	{
		l = screen.width/2 - width/2;
		t = screen.height/2 - height/2;
		win = window.open(file, "", "width="+width+", height="+height+", scrollbars=yes, resizable=no, top="+t+", left="+l);
	}	
	else
	{
		width = screen.width - 10;
		height = screen.height - 80;
		win = window.open(file, "", "width="+width+", height="+height+", top=0, left=0, toolbar=no, location=no, status=yes, menubar=no, scrollbars=yes, resizable=no");
	}
}


function ConfirmDelete(page)
{
	a = confirm("Etes-vous sūr de vouloir effacer cet enregistrement ?");
	if (a) document.location=page;
}


function CheckHour(hour)
{
	if (hour.value < 0 || hour.value > 24) hour.value="";
}


function CheckMinute(minute)
{
	if (minute.value < 0 || minute.value > 59) minute.value="";
}


function OpenInfos(infos, width)
{
	document.onmousemove = GetMouse;
	
	var content = "<table bgcolor='#FFFFFF' border='0' style='border: 1px solid' bordercolor='#000000' cellpadding='3' cellspacing='0'";
	if (width) content = content + " width='"+width+"'";
	else content = content + ">";
	content = content + "<tr><td>";
	if (width) content = content + infos;
	else content = content + "<nobr>"+infos+"</nobr>";
	content = content + "</td></tr>";
	content = content + "</table>";
	
	bubble.style.left = event.x + document.body.scrollLeft + 15;
	bubble.style.top  = event.y + document.body.scrollTop + 15;
	
	document.all("bubble").innerHTML = content;
	bubble.style.visibility = "visible";
}


function GetMouse(e)
{
	if (bubble.style.visibility == "visible")
	{
		bubble.style.left = event.x + document.body.scrollLeft + 15;
		bubble.style.top  = event.y + document.body.scrollTop + 15;
	}
}


function CloseInfos()
{
	bubble.style.visibility = "hidden";
}


function PlanningState(state)
{
	for (u=1 ; u<=7 ; u++)
	{
		for (l=1 ; l<=8 ; l++)
		{
			document.getElementById("slap_"+u+"_"+l).disabled = state;
			
			if (state == true)
			{
				document.getElementById("slap_"+u+"_"+l).value = "";
				document.getElementById("slap_"+u+"_"+l).style.background = "#EAEAEA";
			}
			else
				document.getElementById("slap_"+u+"_"+l).style.background = 'url("templates/default/images/bg_input.gif")';
		}
	}
}


function popon(width, height) 
{
	var ie = (document.all);
	var nav = ((document.getElementById ||document.layers)&&(!document.all))
	var skn = (nav) ? document.getElementById("topdeck") : topdeck.style;
	
	l = (document.body.clientWidth-740)/2 + 140 + 15;
	t = document.body.clientHeight/2 - height/2;
	
	if (t < 210) t=210;
	
	if (ie) { 
		skn.visibility = "visible";  
		skn.left = l;
		skn.top = t;
	} else {
		skn.style.visibility = "visible";
		skn.style.left = l;
		skn.style.top = t;
	}
}


function popoff() 
{
	var ie = (document.all);
	var nav = ((document.getElementById ||document.layers)&&(!document.all))
	var skn = (nav) ? document.getElementById("topdeck") : topdeck.style;
	
	if (ie) { 
		skn.visibility = "hidden";  
	} else {
		skn.style.visibility = "hidden";
	}
}


function ChangeDIV(field, value)
{
  if(document.getElementById)
    document.getElementById(field).innerHTML = value;
}


function StateBar()
{
	window.status = "";
	
	tempoAnimEtat2 = setTimeout("StateBar()", 100)
}

function StateBar2()
{
	window.status = "";
	clearTimeout(tempoAnimEtat2);
}

window.onload = StateBar;
window.onunload = StateBar2;
window.defaultStatus = "";


