
/*
---------------------------------------------------------------------
		Petrobras Argentina

		[jvs_menu.01.js]
		-	engine de menu para sitio dinamico.
		-	sin ocultamiento opciones "hermanas" dentro del arbol 
			de opciones.

		Medialab Argentina :: Juan Manuel Melillo, Agosto 08 2004
---------------------------------------------------------------------
*/

//	comienzo --------------------------------------------------------

//	[draw_text_suboption()]
//	define el metodo que dibujara la opcion de segundo nivel de
//	anidamiento para el objeto [text_suboption].
//	no requiere parametros.
	function draw_text_suboption() {
		document.write( "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" );
		document.write( "<tr><td colspan=\"3\"><img src=\"imagenes/x.gif\" width=\"0\" height=\"6\"/></td></tr>");
		document.write("<tr>");
		document.write( "<td width=\"17\"><img src=\"imagenes/x.gif\" width=\"7\" height=\"1\"/></td>" );
		document.write( "<td width=\"11\" align=\"left\" valign=\"top\">" );
		if (this.image_identator == undefined) {
			document.write( "<img src=\"/Imagenes/x.gif\"/>" );
		}else{
			document.write( "<img src=\"" + this.image_identator + "\" />" );
		}
		document.write( "</td>" );
		document.write( "<td width=\"121\" valign=\"top\">" );
		if(hasChilds(this.id)){
			document.write( "<a class=\"" + this.style + "\" href=\"" + this.url + "\" "+ this.target +"  onclick=\"toogle_display( '" + this.id + "' );\">" );
			document.write(  this.caption );
			document.write( "</a></td>");
		}else{
			document.write( "<a class=\"" + this.style + "\" href=\"" + this.url + "\" "+ this.target +"  onclick=\"\">" );
			document.write(  this.caption );
			document.write( "</a></td>");
		}
		document.write( "</tr>");
		document.write( "<tr><td colspan=\"3\"><img src=\"imagenes/x.gif\" width=\"0\" height=\"6\"/></td></tr>");
		document.write("</table>" );
	}

//	[text_suboption( id, caption, style, parent )]
//	define el prototipo del objeto que contiene la informacion de
//	una opcion con segundo nivel de anidamiento.
//	requiere:
//		[string id] 		identificador unico de objeto.
//		[string caption]	texto a mostrar en la opcion.
//		[string style] 		estilo a utilizar para la presentacion de la opcion.
//		[string parent]		identificador de la opcion "padre" con la cual 
//							esta relacionada.
//		[string url]		(opcionla) el URL de la pagina que debe invocar la 
//							opcion del menu.
							 
	function text_suboption( id, caption, style, parent, url , hidden , target , image_identator) {
		this.id	= id;
		this.caption = caption;
		this.style = style;
		this.parent = parent;
//********************************************
		this.url = url || "javascript:void(0)";
		this.isHidden = hidden || 'block';
		this.target = target || "target='_self'" ;
		this.image_identator = image_identator;
// *******************************************		
		this.draw = draw_text_suboption;		
	}

//	[draw_text_option()]
//	define el metodo que dibujara la opcion de primer nivel de
//	anidamiento para el objeto [text_option].
//	no requiere parametros.

	function draw_text_option() {
		document.write( "<table style=\"padding-bottom:0px; display:"+ this.isHidden +"\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" );		
		document.write( "<tr><td colspan=\"3\"><img src=\"imagenes/x.gif\" width=\"0\" height=\"4\"/></td></tr>" );
		document.write( "<tr><td width=\"1%\" align=\"left\" valign=\"top\">" );
		if (this.image_identator == undefined) {
			document.write( "<img height=\"0\" width=\"19\"  src=\"/Imagenes/x.gif\"/>" );
		}else{
			if(hasChilds(this.id)){
				document.write( "<img name=\"imgShowHide" + this.id + "\" id=\"imgShowHide" + this.id + "\"  src=\"" + this.image_identator + "\" />" );
				document.write( "<img name=\"imgShowHideOn" + this.id + "\" id=\"imgShowHideOn" + this.id + "\"  src=\"" + this.image_identator_sel + "\" style=\"display:none\" />" );
			}else{
				document.write( "<img name=\"imgShowHide" + this.id + "\" id=\"imgShowHide" + this.id + "\"  src=\"" + this.image_identator + "\" />" );
				document.write( "<img name=\"imgShowHideOn" + this.id + "\" id=\"imgShowHideOn" + this.id + "\"  src=\"" + this.image_identator + "\" style=\"display:none\" />" );
			}
		}
		document.write( "</td>" );
		document.write( "<td align=\"left\" valign=\"middle\">" );
		if(hasChilds(this.id)){
			document.write( "<a class=\"" + this.style + "\" " + this.url + "\" "+ this.target + " onclick=\"toogle_display( '" + this.id + "' );\">" );
			document.write(  this.caption );
			document.write( "</a></td>");
		}else{
			document.write( "<a class=\"" + this.style + "\" " + this.url + "\" "+ this.target + " onclick=\"\">" );
			document.write(  this.caption );
			document.write( "</a></td>");
		}
		document.write( "<td width=\"5%\" align=\"left\" valign=\"middle\">&nbsp;</td></tr>" );
		document.write( "<tr><td colspan=\"3\"><img src=\"imagenes/x.gif\" width=\"0\" height=\"4\"/></td></tr>" );
		if (this.parent.match("root") && this.lastOption) {
			document.write("<tr><td colspan=\"3\" height=\"3\"><img src=\"/Imagenes/eInst/VapImages/VerticalNavigation/borda-bottom-verde-esquerda.gif\"/></td></tr>");
		}//else{
			//document.write("<tr><td colspan=\"3\"><img src=\"/Imagenes/x.gif\"/></td></tr>");
		//}
		document.write( "</table>" );
	}

//	[text_option( id, caption, style, parent )]
//	define el prototipo del objeto que contiene la informacion de
//	una opcion con primer nivel de anidamiento.
//	requiere:
//		[string id] 		identificador unico de objeto.
//		[string caption]	texto a mostrar en la opcion.
//		[string style] 		estilo a utilizar para la presentacion de la opcion.
//		[string parent]		identificador de la opcion "padre" con la cual 
//							esta relacionada.
//		[string url]		(opcional) el URL de la pagina que debe invocar la 
//							opcion del menu.
//		[string target]		(opcional) el Target de la pagina que permite detectar
//							cuando abrir el link en la próxima página

	function text_option( id, caption, style, parent, url , hidden , target , image_identator , 
							image_identator_sel , lastOption) {
		
		this.id	= id;
		this.caption = caption;
		this.style = style;
		this.parent = parent;
		if (url == "none"){
			this.url = "";
		}else{
			this.url = "href=\"" + (url || "javascript:void(0)") + "\"";
		}
		
		this.isHidden = hidden || 'block' ;
		this.target = target || "target='_self'" ;		
		this.image_identator_sel = image_identator_sel;
		this.image_identator = image_identator;
		this.draw = draw_text_option;
		//Cuando es el ultimo no dibuja linea divisioria de abajo
		
		if (lastOption == undefined)
			this.lastOption = 1;
		else
			this.lastOption = lastOption;
	}

//	[draw_image_option()]
//	define el metodo que dibujara la opcion de nivel raiz de
//	anidamiento para el objeto [image_option].
//	no requiere parametros.

	function draw_image_option( ) { 
		document.write( "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">" );	
		document.write( "<tr><td background=\"" + this.out_image + "\"  width=\"100%\" height=\"15\"  >" );		
	    	document.write( "<spacer>" );
		document.write( "</td></tr>");	
		document.write( "</table>" )	
	}

//	[image_option( id, caption, style, parent )]
//	define el prototipo del objeto que contiene la informacion de
//	una opcion con nivel raiz.
//	requiere:
//		[string id] 		identificador unico de objeto.
//		[string out_image]	imagen a mostrar en el estado "normal" de la opcion.
//		[string ovr_image]	imagen a mostrar en el estado "mouse over" de la opcion.
//		[string parent]		identificador de la opcion "padre" con la cual 
//							esta relacionada.
//		[string url]		(opcionla) el URL de la pagina que debe invocar la 
//							opcion del menu.

	function image_option( id, out_image, ovr_image, parent, url, target ) {
		this.id	= id;
		this.ovr_image = ovr_image;
		this.out_image = out_image;		
		this.parent = parent;
		this.url = url || "javascript:void(0)";		
		this.target = target;
		this.draw = draw_image_option;
	}		

//	[toogle_display( id )]
//	define el procedimiento necesario para realizar la presentacion
//	y el ocultamiento de las restantes opciones al hacer click en una
//	de ellas -- determinando el comportamiento del menu.
//	requiere:
//		[string id] 		identificador unico de objeto.

	function toogle_display( id ) {
		
		if(option_collection[id].parent.match("root"))  
			restoreAllImageRoot();
		
		for( father in option_collection )
		 
			if( father != id && option_collection[ father ].parent == option_collection[ id ].parent ) 
			{
				document.all.item( father ).style.display = "none";
			
				for( child in option_collection ) if( child != id && option_collection[ child ].parent == father ) 
					document.all.item( child ).style.display = "none";
			}
		
		var imgname = "imgShowHide"+id;
		var imgnameOn = "imgShowHideOn"+id;
		if( document.all.item( id ).style.display == "" ) {
			document.all.item( id ).style.display = "none";
		} else {
			if (document.images) {
	            var imgOff = eval("document.images." + imgname);
	            var imgOn = eval("document.images." + imgnameOn);
	            
	            if (imgOff && imgOn) {
	            	imgOff.style.display = "none";
	            	imgOn.style.display = "";
	            }
        	}
			document.all.item( id ).style.display = "";
		}
	}
	
	/*
	[restoreAllImageRoot]
	Realiza cambiar la imagen identadora a la por default
	*/
	function restoreAllImageRoot() {
		var ids;
		
		for( ids in option_collection )
		{
			if( option_collection[ids].parent.match("root") ) 
			{
				imgToChange = document.getElementById("imgShowHide"+ids);
				imgToChangeOn = document.getElementById("imgShowHideOn"+ids);
				
				if (imgToChange != null && imgToChangeOn != null){
					imgToChange.style.display = "";
					imgToChangeOn.style.display = "none";
				}
			}
		}
	}

//	[draw_option( id )]
//	realiza la renderizaciion de cada opcion e invoca
//	a la renderizacion de cada opcion hija en el arbol de opciones.
//	requiere:
//	[string id] 		identificador unico de objeto.

	function draw_option( id ) {
		
		for( op in option_collection ) if( option_collection[ op ].parent == id ) {
			option_collection[ op ].draw();
			document.write( "<div id=\"" + option_collection[ op ].id + "\" style=\"display:none\">" );
			draw_option( option_collection[ op ].id );
			document.write( "</div>" );
		}
	}
	
//	[show_option( id )]
//	despliega la opcion correspondiente para cada pagina.
//	requiere:
//		[string id] 		identificador unico de objeto.

	function show_option( id ) {
		toogle_display( id );
		if( !option_collection[ id ].parent.match("root")  ) show_option( option_collection[ id ].parent );
	}

//	[render_menu()]
//	dibuja el menu en la pagina invocando a [draw_option()].
//	no requiere parametros.

	function render_menu(selRoot) {
		document.write( "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>" );
		draw_option(selRoot);
		document.write( "</td><tr></table>" );
	}
	
//	[option_collection]
//	necesario para la creacion del arbol de opciones.

	var option_collection = new Array();
	
// [evalua si un nodo tiene hijos para renderizar]
	function hasChilds(nodeId){
		var fatherId = nodeId;
		var hasAtLeastoneChild = false;
		for( node in option_collection ){
		 	//alert("is hidden " + option_collection[node].isHidden)
			if( node != fatherId && option_collection[node].isHidden!="none" && option_collection[ node ].parent == fatherId ) 
			{
				hasAtLeastoneChild = true;
				break;
			}
		}
		return hasAtLeastoneChild;
	}	
	
//	final ----------------------------------------------------------

