var tabs = new Array();
tabs[0] = "info";
tabs[1] = "alcool";
tabs[2] = "drogue";
tabs[3] = "medic";
tabs[4] = "bio";
tabs[5] = "rosace";
tabs[6] = "proposition";
tabs[7] = "prescription";
tabs[8] = "satisfaction";
tabs[9] = "consultation";

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
		else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
		else if (document.layers)
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}

function checkObj(name)
{
	name = "tab-" + name;
	if (document.getElementById)
	{
		 if (document.getElementById(name))
			 return true;
	}
		else if (document.all)
	{
		if (document.all[name])
			return true;
	}
		else if (document.layers)
	{
		if (document.layers[name])
			return true;
	}
	return false;
}

function displayTab(name)
{
	for (var i = 0; i < tabs.length; i++)
	{
		var tname = tabs[i];
		if (checkObj(tname))
		{
			var div = new getObj("div-" + tname);
			var tab = new getObj("tab-" + tname);
			if (tname == name)
			{
				div.style.display = "block";
				tab.obj.className = "highlight";
			}
			else
			{
				div.style.display = "none";
				tab.obj.className = "";
			}
		}
	}
}

function calculJour()
{
	var tmp = 0;
	var i1 = new getObj("alc_4_5_jour");
	var i2 = new getObj("alc_8_12_jour");
	var i3 = new getObj("alc_16_20_jour");
	var i4 = new getObj("alc_40_jour");

	if (i1.obj.value && parseInt(i1.obj.value))
		tmp = Math.floor(tmp + parseInt(i1.obj.value));

	if (i2.obj.value && parseInt(i2.obj.value))
		tmp = Math.floor(tmp + parseInt(i2.obj.value));

	if (i3.obj.value && parseInt(i3.obj.value))
		tmp = Math.floor(tmp + parseInt(i3.obj.value));

	if (i4.obj.value && parseInt(i4.obj.value))
		tmp = Math.floor(tmp + parseInt(i4.obj.value));

	var t1 = new getObj("total_jour");
	t1.obj.value = tmp;
}

function calculOcc()
{
	var tmp = 0;
	var i1 = new getObj("alc_4_5_occ");
	var i2 = new getObj("alc_8_12_occ");
	var i3 = new getObj("alc_16_20_occ");
	var i4 = new getObj("alc_40_occ");

	if (i1.obj.value && parseInt(i1.obj.value))
		tmp = Math.floor(tmp + parseInt(i1.obj.value));

	if (i2.obj.value && parseInt(i2.obj.value))
		tmp = Math.floor(tmp + parseInt(i2.obj.value));

	if (i3.obj.value && parseInt(i3.obj.value))
		tmp = Math.floor(tmp + parseInt(i3.obj.value));

	if (i4.obj.value && parseInt(i4.obj.value))
		tmp = Math.floor(tmp + parseInt(i4.obj.value));

	var t1 = new getObj("total_occ");
	t1.obj.value = tmp;
}
/*
function addStructure()
{
	var box = document.rose.structures_select;
 	var index = box.options.selectedIndex;
	if (index == "")
		return;

	var text = box.options[index].text;

	var rand = parseInt(Math.random()*1000000);
	var tmp = new getObj("structures-root");
	var newFields = tmp.obj.cloneNode(true);
	var rand = parseInt(Math.random()*1000000);
	newFields.id = rand;
	newFields.style.display = "block";
	var insertHere = new getObj("structures-contenu");
	insertHere.obj.parentNode.insertBefore(newFields, insertHere.obj);
	var label = new getObj("structures-name");
	label.obj.innerHTML = text;
	label.obj.id = "";
}

function delStructure(id)
{
	var deleted = eval("new getObj('" + id + "')");
	deleted.obj.innerHTML = "";
	deleted.style.display = "none";
}

function cloneStructures()
{
	var tmp = new getObj("structures-root");
	var newFields = tmp.obj.cloneNode(true);
	var rand = parseInt(Math.random()*1000000);
	newFields.id = rand;
	newFields.style.display = "block";
	var insertHere = new getObj("structures-write");
	insertHere.obj.parentNode.insertBefore(newFields, insertHere.obj);
}
*/

/*
function addStructure()
{
	var box = document.rose.structures_select;
 	var index = box.options.selectedIndex;
	var text = box.options[index].text;

	if (index == 0)
		return;

	var tmp = new getObj("structures-root");
	var newFields = tmp.obj.cloneNode(true);
	newFields.id = ""; // parseInt(Math.random()*1000000);
	newFields.style.display = "block";
	var newField = newFields.childNodes;
	for (var i = 0; i < newField.length; i++)
	{
		var theId = newField[i].id;
		if (theId == "cLabel")
		{
			newField[i].innerHTML = "";
			newField[i].innerHTML = text;
			newField[i].id = "";
		}
		if (theId == "cType")
		{
			newField[i].value = index;
			newField[i].id = "";
		}
	}
	var insertHere = new getObj("structures-contenu");
	insertHere.obj.appendChild(newFields);
}
*/

function addStructure()
{
	var box = new getObj("structures_select");
 	var index = box.obj.options.selectedIndex;
	var text = box.obj.options[index].text;

	if (index == 0)
	{
		alert("Vous devez choisir une structure.");
		return;
	}

	var tmp = new getObj("structures-root");
	var newFields = tmp.obj.cloneNode(true);
	newFields.id = ""; // parseInt(Math.random()*1000000);
	newFields.style.display = "block";
	var newField = newFields.childNodes;
	for (var i = 0; i < newField.length; i++)
	{
		var theId = newField[i].id;

		if (theId == "cLabel")
		{
			newField[i].innerHTML = "";
			newField[i].innerHTML = text;
			newField[i].id = "";
		}

		if (theId == "cType")
		{
			newField[i].value = index;
			newField[i].id = "";
		}
	}

	var uniqID = parseInt(Math.random()*1000000);

	var inputList = newFields.getElementsByTagName("INPUT");
	for (var i = 0; i < inputList.length; i++)
	{
		if (inputList[i].id == "tmpdate")
			inputList[i].id = uniqID;
	}

	var aList = newFields.getElementsByTagName("A");
	for (var i = 0; i < aList.length; i++)
	{
		if (aList[i].id == "tmpcal")
			aList[i].onclick = function () { return showCalendar(uniqID, '%d/%m/%Y'); }
	}

	var insertHere = new getObj("structures-contenu");
	insertHere.obj.appendChild(newFields);
}