/*
var objImgBotonIzqDes	 = new Image();
var objImgBotonCentroDes = new Image();
var objImgBotonDerDes	 = new Image();	
var objImgBotonIzqAct	 = new Image();
var objImgBotonCentroAct = new Image();
var objImgBotonDerAct	 = new Image();
*/
var ns;

function cambiaEstMenu(nomMenu, menuActivo, ocltOtNiv, arrayNivelesMenu)
{
	arrayNivelesMenu.sort();
	var i = 0;
	var nodoInicio;
	var nodoAux;
	var nodoAux2;
	var nomCapaActiva;
	var restaAlto = 0;
	var operacion;
	var estNodo;
	var strClass;
	
	while ((arrayNivelesMenu[i] != menuActivo) && (i < arrayNivelesMenu.length))
	{	// En primer lugar se localiza la opción del menú en los arrays
		i++;
	}
		
	if (arrayNivelesMenu[i] == menuActivo)
	{
		if ((i + 1) < arrayNivelesMenu.length)
		{
			nodoInicio = (arrayNivelesMenu[i]).toString();
			nodoAux = (arrayNivelesMenu[i + 1]).toString();
			nomCapaActiva = nomMenu + 'menu' + nodoAux;
			if (nodoAux.length > nodoInicio.length)
			{// si este nivel contiene un submenú
				
				cambiaEstado = true;
				if (ns)
				{
					(document.layers[nomCapaActiva].visibility == 'show')? operacion = 'O': operacion = 'M';
				}
				else
				{
					(document.getElementById(nomCapaActiva).style.visibility == 'visible')? operacion = 'O': operacion = 'M';
				}
				for (var j=i + 1; j < arrayNivelesMenu.length; j++)
				{
					nodoAux = (arrayNivelesMenu[j]).toString();
					nomCapaActiva = nomMenu + 'menu' + nodoAux;

					try
					{
						ns? estNodo=document.layers[nomCapaActiva].visibility: estNodo=document.getElementById(nomCapaActiva).style.visibility;
						if (operacion == 'O')
						{ 
							ns? document.layers[nomCapaActiva].top -= restaAlto: document.getElementById(nomCapaActiva).style.posTop -= restaAlto;
							 //eval("document." + nomMenu + "img" + nodoInicio + ".src = imgArray[0].src;");
						}
						else
						{
							ns? document.layers[nomCapaActiva].top += restaAlto: document.getElementById(nomCapaActiva).style.posTop += restaAlto;
							/*if (nodoInicio.length==1 ) //No tiene submuenús y es primer nivel
							{	
								//eval("document." + nomMenu + "img" + nodoInicio + ".src = imgArray[1].src;");
							}*/
						}

						if(cambiaEstado)
						{
							if(nodoAux.length > nodoInicio.length)
							{
								if(((estNodo == 'show') || (estNodo == 'visible')) && (operacion == 'O'))
								{
									if (ns)
									{
										restaAlto += document.layers[nomCapaActiva].document.height;
										document.layers[nomCapaActiva].visibility = 'hide';
									}
									else
									{
										restaAlto += document.getElementById(nomCapaActiva).offsetHeight;
										document.getElementById(nomCapaActiva).style.visibility = 'hidden';
									}
									/*if((j + 1) < arrayNivelesMenu.length)
									{
										nodoAux2 = arrayNivelesMenu[j + 1].toString();
										if (nodoAux2.length > nodoAux.length)
										{	// si este nivel contiene un submenú
											if (nodoAux2.length==1) //Sólo para los padres	
											{
												//eval("document." + nomMenu + "img" + nodoAux + ".src = imgArray[0].src;");
											}
										}
									}*/
								}
								if((nodoAux.length == nodoInicio.length + 1) && (operacion == 'M'))
								{
									if(ns)
									{
										restaAlto += document.layers[nomCapaActiva].document.height;
										document.layers[nomCapaActiva].visibility = 'show';
									}
									else
									{
										restaAlto += document.getElementById(nomCapaActiva).offsetHeight;
										document.getElementById(nomCapaActiva).style.visibility = 'visible';
										if(!( navigator.appName == "Microsoft Internet Explorer"))
											document.getElementById(nomCapaActiva).style.position = 'relative';
									}
								}
							}
							else
							{
								cambiaEstado = false;
							}
						}
					}
					catch(e)
					{
					}
				}

				if (ocltOtNiv)
				{
					ocultaOtrosNiveles(nomMenu, menuActivo, arrayNivelesMenu); 
				} 
			}
			else
			{	
				if (nodoInicio.length==1)
				{
				 //eval("document." + nomMenu + "img" + nodoInicio + ".src = imgArray[1].src;");
				}
			}
		}
		else
		{
			//Último nivel seleccionado y sin hijos
			if (menuActivo.length==1)
			{
				 //eval("document." + nomMenu + "img" + menuActivo + ".src = imgArray[1].src;");
			}
		}
	}
	
}

function ocultaOtrosNiveles(strNomMenu, vivMenuAct, arrayNiveles)
{
	var menuAux;
	var restaAlto = 0;
	var estNodo;
	var nomCapa;
	var nodoInicio;
	var nodoAux;

	for (var i = 0; i < arrayNiveles.length; i++)
	{
		menuAux = (arrayNiveles[i]).toString();
		nomCapa = strNomMenu + "menu" + menuAux;
		try
		{
			ns? document.layers[nomCapa].top -= restaAlto: document.getElementById(nomCapa).style.posTop -= restaAlto;
			if (i < arrayNiveles.length)
			{
				if ((menuAux.length > vivMenuAct.length) && 
				    ((menuAux).indexOf(vivMenuAct) != 0))
				{//El menú a ocultar no es hijo del menú
					ns? estNodo=document.layers[nomCapa].visibility: estNodo=document.getElementById(nomCapa).style.visibility;
					if ((estNodo == 'show') || (estNodo == 'visible'))
					{
						if(ns)
						{
							restaAlto += document.layers[nomCapa].document.height;
							document.layers[nomCapa].visibility = 'hide';
						}
						else
						{
							restaAlto += document.getElementById(nomCapa).offsetHeight;
							document.getElementById(nomCapa).style.visibility = 'hidden';
						}
								
						if (i > 0)
						{
							nodoInicio = arrayNiveles[i - 1].toString();
							nodoAux = arrayNiveles[i].toString();
							if (nodoAux.length > nodoInicio.length)
							{	// si este nivel contiene un submenú
								 //eval("document." + strNomMenu + "img" + nodoInicio + ".src = imgArray[0].src;");
							}
						}
					}
				}
			}
		}
		catch(e){}
	}
}

function SobreBoton1(obj)
{

	if(obj.id != undefined)
	{
		if(obj.className.length > 3)
		{
			if(obj.className.substr(obj.className.length -3, 3) == 'Sel')
			{
				return;
			}
		}
		var strNivel = obj.id.toString();
		if(strNivel.length)
		{
			document.getElementById("DivActivo" + strNivel).style.display = "inline";
			document.getElementById("DivInactivo" + strNivel).style.display = "none";			
		}
	}
}

function FueraBoton1(obj)
{

	if(obj.id != undefined)
	{
		if(obj.className.length > 3)
		{
			if(obj.className.substr(obj.className.length -3, 3) == 'Sel')
			{
				return;
			}
		}
		var strNivel = obj.id.toString();
		if(strNivel.length)
		{
			document.getElementById("DivActivo" + strNivel).style.display = "none";
			document.getElementById("DivInactivo" + strNivel).style.display = "inline";
		}
	}
}

//onmouseover="overGris('1')" 
function SobreBoton(elemento)
{
	//alert(elemento);
	document.getElementById("TablaActivoNivel"+elemento).style.backgroundColor = "#868686";
}

//onmouseout="overNegro('1')"
function FueraBoton(elemento)
{
	document.getElementById("TablaActivoNivel"+elemento).style.backgroundColor = "#015095";
}



function trim_string(strValue)
{{
	//alert(elemento);
	document.getElementById("TablaActivoNivel"+elemento).style.backgroundColor = "#868686";
}
    var ichar, icount;
    ichar = strValue.length - 1;
    icount = -1;
    while (strValue.charAt(ichar)==' ' && ichar > icount)
        --ichar;
    if (ichar!=(strValue.length-1))
        strValue = strValue.slice(0,ichar+1);
    ichar = 0;
    icount = strValue.length - 1;
    while (strValue.charAt(ichar)==' ' && ichar < icount)
        ++ichar;
    if (ichar!=0)
        strValue = strValue.slice(ichar,strValue.length);
    return strValue;
}
function GetAnchoMenu(Nivel)
{
	var Ancho = 0;
	switch(parseInt(Nivel))
	{
		//Mapas
		case 1: 
				Ancho = 50;
				break;
		// V y T
		case 2: 
				Ancho = 105;
				break;
		//S en R
		case 3: 
				Ancho = 105;
				break;
		//Guia YPF
		case 4: 
				Ancho = 60;
				break;
		//Mi Guia YPF
		case 5: 
				Ancho = 80;
				break;
	}
	return Ancho;
}
	
function CreaMenu(nomMenu, posIniX, posIniY, longMenu, anchoMenu, anchoCol, estVisible, ocltOtNiv, nodoActivo, nomArrayNivMenu)
{
	var nivelNodo;
	var nivelNodoAux;
	var nomCapa;
	var nivelesMenu;	
	nivelesMenu = eval(nomArrayNivMenu);
   
	//=====================================================================================================
	//									Inicio de definición de funciones
	//=====================================================================================================
	
	
	function ordenaArray()
	{
		
		var nivelesMenuAux, txtMenuAux;
		nivelesMenuAux = new Array();
		var encontrado;
		var j;
		for (var i=0; i < nivelesMenu.length; i++)
		{
			nivelesMenuAux[i] = nivelesMenu[i];
			
		}
		nivelesMenuAux.sort();
		txtMenuAux = new Array();
		
		for (var i=0; i < nivelesMenuAux.length; i++)
		{
			j = 0;
			encontrado = false;
			while(!(encontrado) && (j < txtMenu.length))
			{
				if(nivelesMenuAux[i] == nivelesMenu[j])
				{
					txtMenuAux[i] = txtMenu[j];
					encontrado = true;
				}
				j++;
			}
		}
		nivelesMenu = nivelesMenuAux;
		txtMenu = txtMenuAux;
		
	}

	function compruebaEstados()
	{
		var nivelNodoActivo;
		var i;
		nivelNodoActivo = "";

		i = 0;		
		while ((nivelesMenu[i] != nodoActivo) && (i < nivelesMenu.length))
		{	// En primer lugar se localiza la opción del menú en los arrays
			i++;
		}
		
		//if (i < nivelesMenu.length - 1){
		if (nivelesMenu[i] == nodoActivo)
		{
			for (var i=0; i<nodoActivo.length; i++)
			{
				nivelNodoActivo = nivelNodoActivo + nodoActivo.charAt(i);				
				// esto da error
				try
				{
					cambiaEstMenu(nomMenu, nivelNodoActivo, ocltOtNiv, nivelesMenu);
				}
				catch(e){}
			}			
		}
	}
	//=====================================================================================================
	//									Fin de definición de funciones
	//=====================================================================================================
	ordenaArray();
	//var posBotoneraIniY = 113;
	//var posBotoneraIniX = 260;//131;
	//var anchoBotonera	= 620;

	
	document.writeln('<div  id="divContenedor" style="position:absolute;top:105;width:780px;text-align:center">');

	
	//LOGO 
	document.writeln('<div id="divLogo" style="position:absolute;top:28;left:20;z-index:105">');
	document.writeln('<a href="/guiaypf/ar_es/home/home.aspx">');
	document.writeln('<img src="/guiaypf/images/logo.gif" border="0">');
	document.writeln('</a></div>');

	//------------------------------------------------------------------------------------------------
	//Tabla que contiene el menu Horizontal: Calcula Tu Ruta - Viajes y Recreacion - Etc.
	//MODIFICADO
	if (ns)
	{
		document.writeln('<layer id="enlaces" style="position:relative;text-align:right">');
		document.writeln('<layer id="OpcionesMenu" style="width:100%">');
	}
	else
	{
		document.writeln('<div id="enlaces" style="position:relative;text-align:right">');
		document.writeln('<div id="OpcionesMenu" style="width:100%">'); //border:1px solid
	}
	
	
	//Linea gris
	document.writeln('<table id="tblLineaGris" border=0 cellspacing=0 cellpadding=0 width="100%"><tr><td bgcolor="#CCCCCC" style="font-size:1px" colspan="7">');
	document.writeln('<img src="/GuiaYPF/images/void.gif" width=2 height=9>');
	document.writeln('</td></tr></table>');
	
	//Tabla principal con los botones
	document.writeln('<table cellpadding=2 cellspacing=0 border=0 width="100%" align="center" bgcolor="#015095">'); //TABLA menu
	document.writeln('<tr>');

	//Agrego un td para ocupar el ancho de la pagina a la izquierda
	document.writeln('<td width="130px"></td>');
	
	for (var i = 0; i < txtMenu.length; i++)
	{
		nivelNodo = (nivelesMenu[i]).toString();		
		
		if (i < txtMenu.length - 1)
		{ //Si este no es el último nodo del menú
			nivelNodoAux = (nivelesMenu[i + 1]).toString();
			if ((nivelNodoAux.length > nivelNodo.length) && (nivelNodo != 'A') && (nivelNodoAux.length <= 2))
			{
				document.writeln('<td>');
				document.writeln('<table id="TablaActivoNivel' + nivelNodo.toString() + '" cellspacing="0" cellpadding="0" align="center" border="0"><tr>');
				document.writeln('<td><img src="/GuiaYPF/images/void.gif" width=5 height=1></td>');
																																																					// width="'+ GetAnchoMenu(nivelNodo)+'" nowrap>'
				document.writeln('<td style="font-size: 11px; color: white; text-decoration: none; font-family: Arial, Helvetica, sans-serif;" id="tdBotonera' + nivelNodo + 'centro" align="center" class="textoOpcion" nowrap >');
				document.writeln(txtMenu[i]);
				//alert(txtMenu[i]);
				document.writeln('</td>');
				
				//<td style="background:#FFFFFF;">
				document.writeln('<td><img src="/GuiaYPF/images/void.gif" width="5" height="100%"></td>');
				document.writeln('</tr></table></td>');
				
			}//FIN FOR
		}
		nomCapa = nomMenu + "menu" + nivelNodo;
	} 
	
	//Agrego un td para ocupar el ancho de la pagina
	document.writeln('<td width="60px"></td>');
			

	document.writeln('</tr></table>');//fin tabla principal botones

	
	if(ns)
	{
		document.writeln('		</layer></layer></layer>');
		/*if (nivelNodo.length == 1)
		{
			document.layers['botonera'].visibility = 'show';
		}*/
	}
	else
	{						//divCentrado, divContenedor, div enlaces
		document.writeln('		</div></div></div>'); //fin div agregado
		//document.getElementById('botonera').style.visibility = 'visible';
	}	
	//------------------------------------------------------------------------------------------------
	
	//------------------------------------------------------------------------------------------------
	//Rutina de armado del menu de la izquierda
	//Hay una tabla por cada link del menu, todas encerradas en un DIV
	//debugger;
	
	//MODIFICADO
	document.writeln('<div id="menuizq" style="position:absolute;top:265;width:160px;text-align:left;">');

	//RECORRE TODO EL MENU IZQUIERDO Y LO DIBUJA OCULTANDO LOS ITEMS QUE NO SE DEBEN MOSTRAR
	for(var i = 0; i < txtMenu.length; i++)
	{
		nivelNodo = (nivelesMenu[i]).toString();		
		if (i < txtMenu.length - 1)
		{
			nivelNodoAux = (nivelesMenu[i + 1]).toString();
			
			if(ns)
			{
				document.writeln('		<layer id="' + nomMenu + 'menu' + nivelNodo + '" top="' + (posIniY + longMenu) + '" width="' + anchoMenu + '" left="' + posIniX + '" visibility="hide">');
			}
			else
			{
				//document.writeln('		<div id="' + nomMenu + 'menu' + nivelNodo + '" style="position:absolute; top:' + (posIniY + longMenu)+ 'px; left:' + posIniX + 'px; width:' + anchoMenu + 'px; visibility: hidden; vertical-align:left">');
				//document.writeln('		<div id="' + nomMenu + 'menu' + nivelNodo + '" style="position:absolute; top:' + (posIniY + longMenu)+ 'px; left:' + posIniX + 'px; width:' +  + 'px; visibility: hidden; vertical-align:left">');
				
				//ok
				//document.writeln('<div id="' + nomMenu + 'menu' + nivelNodo + '" style="position:absolute; top:' + (210 + longMenu)+ 'px; left:' + posIniX + 'px; width:' + anchoMenu + 'px; visibility: hidden; vertical-align:left">');
				
				//MODIFICADO
				//alert(nomMenu + 'menu' + nivelNodo); TEST
				document.writeln('<div id="' + nomMenu + 'menu' + nivelNodo + '" style="position:absolute; top:' + (longMenu-13)+ 'px; left:'+ 2 + 'px; width:' + anchoMenu + 'px; visibility: hidden; vertical-align:left">');
				
			}
			
			
			if ( !( (nivelNodoAux.length > nivelNodo.length) && (nivelNodoAux.length <=2) ) )
			{				
				document.writeln('<table border="0" width="' + anchoMenu + '" cellspacing="0" cellpadding="0">');
				document.writeln(' <tr>');
				document.writeln('  <td>' + txtMenu[i] + '</td>');
				document.writeln(' </tr>');
				document.writeln('</table>');
				nomCapa = nomMenu + "menu" + nivelNodo;
			}			
			
			
			//MUESTRA EL ITEM DEL MENU SI CORRESPONDE
			if(ns)
			{
				document.writeln('		</layer>');
				if(nivelNodo.length == 1)
				{
					
					if (!(nivelNodoAux.length > nivelNodo.length))
					{						
						document.layers[nomCapa].visibility = 'show';						
						longMenu += document.layers[nomCapa].document.height;
					}
				}
			}
			else
			{
				//alert(nivelNodo.substring(0,1) + " - " + nodoActivo.substring(0,1)); //TEST
				document.writeln('</div>');//div de cada item del menu
				if((nivelNodo.length == 1)&&((nivelNodo.substring(0,1)==nodoActivo.substring(0,1))||(nivelNodo.substring(0,1)=='0')))
				{
					if (nivelNodoAux.length > nivelNodo.length)
					{
						longMenu += document.getElementById(nomCapa).offsetHeight;
					}
					else
					{		
						longMenu += document.getElementById(nomCapa).offsetHeight;
						document.getElementById(nomCapa).style.visibility = 'visible';
					}					
				}
			}
			

		}//FIN IF
	}//FIN FOR
	
	//document.writeln('</table>');
	document.writeln('</div>'); //MODIFICADO
	//------------------------------------------------------------------------------------------------

   //NUEVA FUNCIONALIDAD
   var desplegarNivel = true; //despliega todo el nivel padre y sus hijos


	if(estVisible || desplegarNivel) 
	{
		for (var x=0; x<txtMenu.length; x++)
		{
			nivelNodo = (nivelesMenu[x]).toString();
			
			if( (estVisible) ||
			    (desplegarNivel && (nivelNodo.substring(0,1)==nodoActivo.substring(0,1))) //ALEJANDRA
		      )
			{
				if (x < txtMenu.length - 1)
				{ //Si este no es el último nodo del menú
					nivelNodoAux = (nivelesMenu[x + 1]).toString();
					if (nivelNodoAux.length > nivelNodo.length)
					{ //Si el siguiente nodo de menú es submenú
						cambiaEstMenu(nomMenu, nivelNodo, ocltOtNiv, nivelesMenu);
					}
				}
			}
		} //end for
	}//enf if
	else
	{
		if(nodoActivo != '0')
		{
			compruebaEstados();
		}
		else
		{
			if(nodoActivo.length == 1) 
			{
				 //eval("document." + nomMenu + "img" + nodoActivo + ".src = imgArray[1].src;");
			}
		}
	}
	
	//Lineas Menu
	/*
	if (nodoActivo != 0)
	{
		var strImg = "";		
		var strNodoActivo = nodoActivo.toString();
		
		if(strNodoActivo != '')
			strImg = 'SeparadorNivel'+ strNodoActivo.substring(0, 1) +'.gif';		
		
		if (strImg.length>0)
			document.writeln('<div style="Z-INDEX:-1; position:absolute; top:135px; left:100px;"><img src="/GuiaYPF/images/' + strImg + '"></div>');
	}
	*/
}