// Descriere meniu: numele meniului, link, 0, 0, array submeniuri
		var color_subm = "#66FF99";
		var color_meniu = "#00CC33";
		var color_highlight = "#009900";
		var white = "#FFFFFF";
		var color_border_meniu = "#009900";
		var id_interval = "";
		var tab_space = " &nbsp;&nbsp;&nbsp;&nbsp;";
		var MENU_HEIGHT = 26;
		var FONT_SIZE = 12;

		function getNumeMeniu (i) { return (MENUS [5 * i]);	}
		function getLinkMeniu (i) { return (MENUS [5 * i + 1]); }
		
		function getIndexMeniu (i) { return (MENUS [5 * i + 2]); } // index = nr randului din tabel pe care se afla meniul
		function setIndexMeniu (i, ind) { MENUS [5 * i + 2] = ind; }
		
		function isExpandat (i) { return (MENUS [5 * i + 3]); }
		function setExpandat (i, exp) { MENUS [5 * i + 3] = exp; }

		function show_menu (smenu_deschis)
		{
			var row, cell;
			var id_meniu;
			var nr_meniuri = MENUS.length / 5;
			
			//alert("meniu de deschis: " + smenu_deschis);
			if (MENUS.length % 5 != 0)
			{
				alert ("Eroare la definirea meniului.");
				return;
			}

			// numerotam index-i meniurilor
			for (var i=0; i < nr_meniuri; i++)
			{
				setIndexMeniu (i, i);
			}

			// afisam meniul principal
			for (var i=0; i < nr_meniuri; i++)
			{
				id_meniu = "meniu" + i;

				row = document.getElementById('menu_table').insertRow(i);
				cell = row.insertCell (0);
				cell.link = getLinkMeniu (i);
				cell.height = MENU_HEIGHT;

				// daca meniul are submeniuri (linkul asociat meniului e null)
				if (cell.link == null)
				{
					cell.innerHTML = "<span id='" + id_meniu + "' >&nbsp; " + getNumeMeniu (i) + "</span>";
					cell.are_subm = 1;
				}
				else // daca meniul are un link asociat (nu are submeniuri)
				{
					cell.innerHTML = "<span id='" + id_meniu + "'>&nbsp; " + getNumeMeniu (i) + "</span>";
					cell.are_subm = 0;
				}
				//cell.style.background = color_meniu;
				cell.style.backgroundImage = "url(btn_meniu.gif)";
				cell.style.borderColor = color_border_meniu;
				cell.style.fontSize = FONT_SIZE;
				
				cell.id_meniu = id_meniu;
				cell.i = i;
				cell.onmouseover = on_mouse_over_meniu_select; // comm by mihai
				cell.onclick = on_mouse_over_meniu;		// add by mihai
				cell.onmouseout = on_mouse_out_meniu; // comm by mihai
				cell.style.cursor = "pointer"; // add by mihai


				if (cell.link != null)
				{
					cell.onclick = function() {
						window.location = this.link;
					}
				}
			}
			if (smenu_deschis != 0 && getLinkMeniu (smenu_deschis - 1) == null) {
				expand_menu(smenu_deschis - 1);
				//alert ("expand " + (smenu_deschis - 1));
			}

		}
		
		function on_mouse_over_meniu_select () 
		{
			this.style.backgroundImage = "url(btn_highlight.gif)";
			//this.style.background = color_highlight;
			this.style.color = white;
		}


		function on_mouse_over_meniu () 
		{
			this.style.backgroundImage = "url(btn_highlight.gif)";
			//this.style.background = color_highlight;
			this.style.color = white;
			
						
			if (this.are_subm)
			{
				expand_menu (this.i);
				this.focus ();
				this.expandat = 1;
			}
			else 
			{
				this.style.cursor = "pointer";
			}
		}

		function on_mouse_out_meniu() 
		{ 
			//if (!this.expandat)
				//this.style.background = color_meniu; 
				this.style.backgroundImage = "url(btn_meniu.gif)";
				this.style.color = "#000000";
				
			if (!this.are_subm)
				this.style.cursor = "default";
		}



		function insert_subm (index_meniu, array_subm)
		{
			var x, y;
			var nr_subm = array_subm.length;
			var id_subm; // ID submeniu

			for (var i=0; i < nr_subm; i++)
			{
				x = document.getElementById('menu_table').insertRow (index_meniu + 1 + i);
				y = x.insertCell(0);
				y.height = MENU_HEIGHT;
				
				y.style.backgroundImage = "url(btn_subm.gif)";
				y.style.borderColor = color_border_meniu;
				y.style.fontSize = FONT_SIZE;


				id_subm = "subm" + index_meniu + "" + i; 
				y.id = id_subm;
				
				y.innerHTML = "<span id='" + id_subm + "' >" + 
					tab_space + array_subm[i][0] + "</span>";
				//y.style.background = color_subm;
				
				y.link = array_subm[i][1];
				
				// evenimente
				y.onmouseover = function() { 
					//this.style.background = color_highlight; 
					this.style.backgroundImage = "url(btn_highlight.gif)";
					this.style.color = white;
					this.style.cursor = "pointer";	
				}
				y.onmouseout = function() { 
					//this.style.background = color_subm; 
					this.style.backgroundImage = "url(btn_subm.gif)";
					this.style.color = "#000000";
					this.style.cursor = "default";
				}
				y.onclick = function() {
					window.location = this.link;
				}
			}
		}

		// sterge i2 submeniuri incepand cu pozitia i1
		function remove_subm (i1, i2)
		{
			var table = document.getElementById('menu_table');
			
			i2 = i1 + i2;
			for (var i = i1; i < i2; i++)
			{
				table.deleteRow (i1);
			}
		}

		function expand_menu (index)
		{
			var nr_meniuri = MENUS.length / 5;
			
			//alert(index);

			delay (400);
			
			// colapsam meniurile deschise
			for (var i=0; i < nr_meniuri; i++)
			{
				if (isExpandat (i))
				{
					// stergem submeniurile 
					remove_subm (getIndexMeniu (i) + 1, MENUS [5 * i + 4].length);
					// setam meniul colapsat
					setExpandat (i, 0);
				}
			}

			// daca meniul nu a fost deja expandat, il expandam
			if (! isExpandat (index))
			{
				var x, y, nr_subm, index_meniu;

				array_subm = MENUS[5 * index + 4];
				nr_subm = array_subm.length;
				index_meniu = getIndexMeniu (index);

				insert_subm (index_meniu, array_subm);
				
				// setam meniul expandat
				setExpandat (index, 1);
			}
		}

		function delay (durata) // durata in milisecunde 
		{ 
			var then, now; 
			then = new Date().getTime();
			now = then;
			while ((now - then) < durata)
			{
				now = new Date().getTime();
			}
		}