var idmenu
function _ColorOver(Obj)  {
	Obj.style.background="#fce861";
}

function _ColorOut(Obj)  {
	Obj.style.background= "";//Obj.id != idmenu  ? "" : "#fce861";
}

function _ColorClick(Obj)  {
	//idmenu = Obj.id
	//Obj.style.background="#fce861";
}

function crearObjetoXML(archivoXML){
	//alert(archivoXML);
	//--- Compruebo si se trata de IE o no.
	//--- Si es IE el objeto ActiveXObject existirá.
	try{
	if(window.ActiveXObject){
		//--- Creo un nuevo objeto de la librería Microsoft.XMLDOM que es la que se encarga
		//--- en Internet Explorer de 'parsear' un archivo XML.
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		//--- Defino la asincronización a false
		xmlDoc.async = false;
		xmlDoc.load(archivoXML);
		parsearXML();
	}else if(document.implementation && document.implementation.createDocument){
		xmlDoc = document.implementation.createDocument("","",null);
		xmlDoc.load(archivoXML);
		//--- Le decimos que cuando haya terminado de cargar el XML
		//--- ejecute la función de parsear el mismo.
		//--- NOTA: Se le llama a la función sin los paréntesis. Si se le colocan no funciona
		xmlDoc.onload = parsearXML;
	}else{
		alert ('Su navegador no puede soportar este script');
	}
	}// cierre try
	catch(e){
		try{
		   var xmlhttp = new window.XMLHttpRequest();

		   xmlhttp.open("GET",archivoXML,false);
		   xmlhttp.send(null);
//		  xmlDoc.async=false;   	
		  xmlDoc = xmlhttp.responseXML.documentElement;
			parsearXML();

		   } catch(e){
			   alert(e.message);
			   }
	}
	//alert(xmlDoc)
}

function hidShow(id){
	obj = document.getElementById(id);
	if (obj.style.display=='none'){
	    obj.style.display='block'
   }
	else
	    obj.style.display='none'
	
}

function _AbrirMenu(Id){
  with (document.getElementById(Id)){
  		if (style.display == "none")
		    new Effect.SlideDown(Id);
		else
		   new Effect.SlideUp(Id);
  }
}


//1.- Creo la funcion 'parsearXML' que se encargar de sacar los valores del XML
//    y asignarlos a los <div> mediante su id
function parsearXML(){
 try{
	var contenido = document.getElementById("contenidoMenu");
	//var longitudXML = xmlDoc.firstChild.childNodes.length;
	var out = "";
	var Cmlls=String.fromCharCode(34);

	
    var numItems = xmlDoc.getElementsByTagName("ITEM").length;
	var Item = xmlDoc.getElementsByTagName("ITEM");
	//alert(numItems)
	//alert(xmlDoc.getElementsByTagName("ITEM")[0].getElementsByTagName("item1")[0].getElementsByTagName("item2").length )


	// NIVEL 0

	var con = 0;
	out += "<img src='http://www.corona.cl/tpl/00005/espacio.gif' height='3' border=0><table border=0 cellspacing=\"0\" cellpadding=\"0\>";
	for (x=0;x<numItems;x++ ){
	out +="<tr><td>";
		out += "<table border=0 width=150 class='' cellspacing=\"0\" cellpadding=\"0\">"
	    out += "<tr>";
		out +=   "<td  class='' >"
		if (Item[x].getAttribute("TIPOLNK") == 1 ){
				out +=     "<a href="+Cmlls+"javascript:GoToCategory('"+Item[x].getAttribute("LINK")+"')"+Cmlls+"  onclick=hidShow('div_"+x+"')>";
				out += 		 	Item[x].getAttribute("SRC") ? "<img src="+Item[x].getAttribute("SRC")+" border=0>" :  Item[x].getAttribute("label") + "";
				out +=     "</a></td></tr><tr><td>";
		}else{
				out += 		 	Item[x].getAttribute("SRC") ? "<img src="+Item[x].getAttribute("SRC")+">" :  Item[x].getAttribute("label") + "";
				out +=     "</td></tr><tr><td>";
		}

		
					// NIVEL 1
					if (Item[x].getAttribute("unid")){
						c = Item[x].getElementsByTagName(Item[x].getAttribute("unid")).length 
						Item1 = Item[x].getElementsByTagName(Item[x].getAttribute("unid")) // Sig. Item
					}else
						c=0
					con++; 	
					out += "<table border=0 style=display: id=div_"+x+" width=100% class='borde-amarillo' cellspacing=\"0\" cellpadding=\"0\">"
					ultimo = c - 1;
					for (i=0;i<c; i++){
						if (Item1[i].getAttribute("TIPOLNK") == 1 )
							lnk  = "GoToCategory('"+Item1[i].getAttribute("LINK")+"')";
						else
						  lnk = "_AbrirMenu('div"+con+"_"+i+"')";

						out += "<tr>";
						
						if (i!=ultimo){
							alto = 18;
						}else{
							alto = 10;
						}
						out +=   "<td style='cursor:pointer;border-top:1px solid #FFFF33'' height='"+alto+"' style=' onMouseOver='_ColorOver(this)'  onMouseOut='_ColorOut(this)'  id='"+con+"_"+i+"' onclick="+lnk+">"
						//out +=     "<a href='#' onclick=hidShow('div"+con+"_"+i+"')>&nbsp;&nbsp;";
						//out +=     "<a href='#' onclick=_AbrirMenu('div"+con+"_"+i+"')>&nbsp;&nbsp;";

									

						out += "&nbsp;&nbsp;"
						out +=			 Item1[i].getAttribute("label")
						out +=     "</td></tr> <tr><td>";
						
									// NIVEL 2
									if (Item1[i].getAttribute("unid")){
										c1 = Item1[i].getElementsByTagName(Item1[i].getAttribute("unid")).length
										Item2 = Item1[i].getElementsByTagName(Item1[i].getAttribute("unid"))
										
									}else
										c1=0

									//out += "<table border=0 style=display:none id=div"+con+"_"+i+"  width=100% cellspacing=0 cellpadding=0>"
									out += "<div style='display:none'  id=div"+con+"_"+i+"  >"
									out += "<ul>";
									
									for (y=0; y<c1; y++ ){
										//out += "<tr>";
										//out +=   "<td >&nbsp;&nbsp;"

										out +=		"<li><a href="+Cmlls+"javascript:GoToCategory('"+Item2[y].getAttribute("LINK")+"')"+Cmlls+"  class='menu1'>" +  Item2[y].getAttribute("label") + "</a></li>";

										//out +=   "</td>";
										//out += "</tr>"
									}// FIN NIVEL 2

									out +=  "</ul>";
									out +=  "</div>";
									//out +=  "</table>"

						out +=   "</td>";
						out += "</tr>"
					}// FIN NIVEL 1
					out += "</table>"

		out +=   "</td>";
		out += "</tr>"
		out += "<tr><td><img src='http://www.corona.cl/tpl/00002/p3.jpg'></td></tr></table>"	
	out += "</td></tr><tr><td><img src='http://www.corona.cl/tpl/00005/espacio.gif' height='10' border=0></td></tr>"
	}// FIN NIVEL 0
	out += "</table>";

	contenido.innerHTML = out
 }catch(e){
	alert(e.name + " " + e.message)
 }
}



