//
// CAJA CANTABRIA - Menú desplegable
// (c) 2004
//     Gerencia ADM
//     Dpto. Desarrollo
//     Mundivía, S.A.
//     [07-10-2002]
//


var anchoMenu=160;
var altoMenu=23;
var anchoSubMenu=160;
var altoSubMenu=37;


function Menu( tipo, descripcion, accion, targ) {
	//tipo: 0 - nada, 
	//		1 - Link
	//		2 - abrir_contenido
	//descripción: Literal de la opción de menú
	//Acción: Si es link, la dirección, si es contenido, el nombre de la página.
	//Target: Si es enlace y tiene un target diferente.
	this.tipo = tipo;
	this.descripcion = descripcion;
	this.accion = accion;
	this.targ = targ;
}



function EscribeMenu(){

	var txt='';
	
	var antOpc;
	var subMenu;
	var ind=0;
	var desplegable=0;
	
	for(x=1;x<=num_opc;x++){
	
		cual = x;
		if (x.toString().length==1){
			cual = "0"+x
		}
	
		txt+='<div id="Menu' + cual + '00" style="position:absolute;top:0;left:0;visibility:visible;width:0;height:0">';

                
              //  <td bgcolor="#D9E3EE" class="forTexts">&nbsp;<a href="./inicio.html" class="linkMenu" target="pagina"><b>INICIO</b></a></td>


			txt+='<table border="0" width="' + anchoMenu + '" height="' + altoMenu + '" cellpading="1" cellspacing="1">';
			txt+='<tr><td bgcolor="#4F7DB0" class="forTexts" width="2">&nbsp;</td>';
			
			if (menu[ind].tipo==0){
				txt+='<td id="td' + cual + '00" bgcolor="#D9E3EE" class="forTexts" onMouseOver="On(this,true,\'' + cual + '\')" onMouseOut="On(this,false,\'' + cual + '\')" onclick="activaMenu(this,\'' + cual + '\')"><a href="javascript:void(null);" class="linkMenu"><b>' + menu[ind].descripcion + '</b></a>&nbsp;&nbsp;<br></td>';
			}
			else if (menu[ind].tipo==1){
				txt+='<td id="td' + cual + '00" bgcolor="#D9E3EE" class="forTexts" onMouseOver="On(this,true,\'' + cual + '\')" onMouseOut="On(this,false,\'' + cual + '\')" onclick="activaMenu(this,\'' + cual + '\');cargaPagina(\'' + menu[ind].accion + '\',\'' + menu[ind].targ + '\')"> <a href="javascript:void(null)" class="linkMenu"><b>' + menu[ind].descripcion + '</b></a>&nbsp;&nbsp;<br></td>';
			}
			else if (menu[ind].tipo==2){
				txt+='<td id="td' + cual + '00" bgcolor="#D9E3EE" class="forTexts" onMouseOver="On(this,true,\'' + cual + '\')" onMouseOut="On(this,false,\'' + cual + '\')" onclick="activaMenu(this,\'' + cual + '\')" >' + menu[ind].descripcion + '&nbsp;&nbsp;<br></td>';
			}
			
			txt+='</tr><tr><td class="fondoLineaMenu"><img src="./imagenes/trans.gif" width="1" height="1"><br></td></tr>';
			txt+='</table><br>';
		txt+='</div><br>';
		ind++;
		for(y=1;y<=Opc_Menu[x];y++){
			cualSub = y;
			if (x.toString().length==1){
				cualSub = "0"+y
			}
			//txt+='<div id="Menu' + cual + cualSub + '" style="color:#28316B;background-color:#D0D3E1;position:absolute;top:0;left:0;visibility:hidden;width:0;height:0">';
			txt+='<div id="Menu' + cual + cualSub + '" style="position:absolute;top:0;left:0;visibility:hidden;width:0;height:0">';
			txt+='<table border="0" width="' + anchoMenu + '" height="' + altoMenu + '" cellpading="1" cellspacing="1">';
			txt+='<tr><td bgcolor="#4F7DB0" class="forTexts" width="2">&nbsp;</td>';
			txt+='<td bgcolor="#D9E3EE" class="forTexts" onMouseOver="OnSub(this,true)" onMouseOut="OnSub(this,false)" onclick="cargaPagina(\'' + menu[ind].accion + '\',\'' + menu[ind].targ + '\')"><a href="javascript:void(null);" class="linkMenu">' + menu[ind].descripcion + '</a>&nbsp;&nbsp;<img src="./imagenes/trans.gif" border="0" width="1" height="1"></td>';
			txt+='</tr></table><br>';
			txt+='</div><br>';
			ind++;

			//txt+='<a href="' + menu[ind].accion + '" target="' + menu[ind].targ + '" title="Productos y clientes"><img name="Mp2" src="imagenes/menu/Mp2_off.gif" vspace=0 border=0 onMouseover="on(\'2\',true)" onMouseout="on(\'2\',false)"></a><br>';
		}
	}
	document.write (txt);
}


function cargaPagina(cual,donde){
	eval('parent.' + donde + '.location.href="' + cual + '"');
}

function inicioMenu(){

	x=PosInicial;
	for (i=1;i<=numOpciones;i++){
		cual = i;
		if (i.toString().length==1){
			cual = "0"+i
		}
		opcionMenu="Menu" + cual + "00";

		document.getElementById(opcionMenu).style.visibility="visible";
		document.getElementById(opcionMenu).style.width=160;
		document.getElementById(opcionMenu).style.height=20;
		document.getElementById(opcionMenu).style.top=x;
		x=x+altoMenu;
	}

}


function activaMenu(obj, cualActivo){
	
	var cual;
	var x=PosInicial;
	var sw=false;
	var vClase;
	for (i=1;i<=numOpciones;i++){
		cual = i;
		if (i.toString().length==1){
			cual = "0"+i
		}
		opcionMenu="Menu" + cual + "00";
		
		opcionTd="td" + cual + "00";
		
		document.getElementById(opcionMenu).style.visibility="visible";
		document.getElementById(opcionMenu).style.width=160;
		document.getElementById(opcionMenu).style.height=20;
		document.getElementById(opcionMenu).style.top=x;
		x=x+altoMenu;
		
		vClase = "forTexts"
		if (cualActivo==cual){
			vClase = "forTexts"	
		}
		document.getElementById(opcionTd).className=vClase;

		for (y=1;y<=Opc_Menu[i];y++){
			cualSub = y;
			if (y.toString().length==1){
				cualSub = "0"+y
			}
			opcionMenu="Menu" + cual + cualSub;
			if (cual==cualActivo && cual!=menuActivo){
				document.getElementById(opcionMenu).style.visibility="visible";
				document.getElementById(opcionMenu).style.width=160;
				document.getElementById(opcionMenu).style.height=20;
				document.getElementById(opcionMenu).style.top=x;
				
				x=x+altoSubMenu;
			}
			else{
				document.getElementById(opcionMenu).style.visibility="hidden";
				document.getElementById(opcionMenu).style.width=0;
				document.getElementById(opcionMenu).style.height=0;
			}
		}
		
	}
	if (cualActivo==menuActivo){
		menuActivo=0;
	}
	else{
		menuActivo=cualActivo;
	}
	
}

function On ( obj, accion, cual ) {

	if (menuActivo!=cual){
		if (accion){
			obj.className="forTexts";
		 	obj.style.cursor = 'hand';
		}
		else{
			obj.className="forTexts";
			obj.style.cursor = 'default';
		}
	}
}

function OnSub ( obj, accion, cual ) {

	if (accion){
		obj.bgColor="#80A0C6";
	 	obj.style.cursor = 'hand';
	}
	else{
		obj.bgColor="#D9E3EE";
		obj.style.cursor = 'default';
	}
 
}
