//variable global para el menu
var sMenuGeneral = "";
var iCtrl = 0;
var iPos = -1;

function xloadS(pag)
{ //S&iacute;ncrono
	var sreturn = "";
	if (typeof window.ActiveXObject != 'undefined' )
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		req = new XMLHttpRequest();
	}

	req.open("GET", pag, false);
	req.send(null);
	sreturn = req.responseText;
	req = "";		
	//return req.responseText;
	return sreturn
}


function xmlLoad(pag)
{ //S&iacute;ncrono

	var sreturn = "";
	if (typeof window.ActiveXObject != 'undefined' )
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		req = new XMLHttpRequest();
	}

	req.open("GET", pag, false);
	req.send(null);
	sreturn = req.responseXML;
	req = "";

	return sreturn
}

	

function GeneraMenu(oItem)
{
	var sMenu = "";

	if (oItem.length > 0)
	{
		for (var iItem = 0; iItem < oItem.length; iItem++)
		{
			//Esta validación es para cuando se usa Firefox
			if (oItem[iItem].nodeType == 3)
			{
				continue;
			}
			
			if (iItem == 0 )
			{
				if (iCtrl == 0)
				{
					iCtrl = 1;
					sMenu = "<ul class=\"dropdownmenu\">\r\n";
				}
				else
				{
					sMenu = "<ul>\r\n";
				}
			}
			else if(sMenu == "")
			{
				//Esta validación es para cuando se usa Firefox
				sMenu = "<ul>\r\n";
			}
	

			if (oItem[iItem].getAttribute('Url').length == 0)
			{
				sMenu += ( "<li><div class=\"menuBloque\">" + oItem[iItem].getAttribute('Descripcion') + "<img src=\"http://www.rosarito.gob.mx/rto/scripts/menubar/right.gif\" class=\"rightarrowclass\" style=\"border:0;\" /></div>");
			}
			else
			{
				iPos = oItem[iItem].getAttribute('Url').indexOf("||rel=");
				
				if (oItem[iItem].getAttribute('Descripcion') == "--" && oItem[iItem].getAttribute('Url') == "--")
				{
					sMenu += ( "<li><div class=\"menuBloque\"><hr></div>");
				}
				else if(iPos > 0)
				{
					sMenu += ( "<li><a href=\"" + oItem[iItem].getAttribute('Url').substring(0, iPos) + "\" " + oItem[iItem].getAttribute('Url').substring(iPos + 2) + ">" + oItem[iItem].getAttribute('Descripcion') + "</a>");
				}
				else
				{
					sMenu += ( "<li><a href=\"" + oItem[iItem].getAttribute('Url') + "\">" + oItem[iItem].getAttribute('Descripcion') + "</a>");
				}
			}
	
			if(oItem[iItem].hasChildNodes())
			{
				sMenu += "\r\n";
				sMenu += GeneraMenu(oItem[iItem].childNodes);
			}
	
			sMenu += "</li>\r\n";
		}

		if (sMenu.length > 0)
		{
			sMenu += "</ul>\r\n";
		}
	}
	else
	{
		if (oItem.getAttribute('Url').length == 0)
		{
			sMenu += ( "<li><div class=\"menuBloque\">" + oItem.getAttribute('Descripcion') + "</div></li>\r\n");
		}
		else
		{
			iPos = oItem[iItem].getAttribute('Url').indexOf("||rel=");
			
			if (oItem[iItem].getAttribute('Descripcion') == "--" && oItem[iItem].getAttribute('Url') == "--")
			{
				sMenu += ( "<li><div class=\"menuBloque\"><hr></div></li>\r\n");
			}
			else if(iPos > 0)
			{
				sMenu += ( "<li><a href=\"" + oItem[iItem].getAttribute('Url').substring(0, iPos) + "\" " + oItem[iItem].getAttribute('Url').substring(iPos + 2) + ">" + oItem[iItem].getAttribute('Descripcion') + "</a></li>\r\n");
			}
			else
			{
				sMenu += ( "<li><a href=\"" + oItem.getAttribute('Url') + "\">" + oItem[iItem].getAttribute('Descripcion') + "</a></li>\r\n");
			}
		}
	}

	return sMenu;
}

function estandares(soption, sDivName){
	var xmlDoc = xmlLoad(soption);
	//alert(xmlDoc.xml);

	sMenuGeneral = GeneraMenu(xmlDoc.getElementsByTagName('Item'));

	if ( sDivName == "" || sDivName == null || sDivName == undefined)
	{
		ddsmoothmenu.init({
			mainmenuid: "smoothmenu2", //Menu DIV id
			orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
			classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
			//classname: '' //ruben
			//customtheme: ["#804000", "#482400"],
			contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
		})
		document.getElementById("smoothmenu2").innerHTML = sMenuGeneral;
	}
	else
	{
		ddsmoothmenu.init({
			mainmenuid: sDivName, //Menu DIV id
			orientation: 'v', //Horizontal or vertical menu: Set to "h" or "v"
			classname: 'ddsmoothmenu-v', //class added to menu's outer DIV
			//customtheme: ["#804000", "#482400"],
			contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
		})
		document.getElementById(sDivName).innerHTML = sMenuGeneral;
	}
	
	//alert(sMenuGeneral);
	xmlDoc = "";
}


