function criarNo(cod,nome,materia,mes,ano,pai)
{

	var it			= new Item();
	it.cod 			= cod;
	it.nome 		= nome;
	it.materia		= materia;
	it.mes			= mes;
	it.ano			= ano;
	it.pai 			= pai;

//	alert("pai "+pai);
	if(it.pai == null || it.pai == "" || it.pai == "0")
	{
		ArrMenu.push(it);
	} else {
//		alert("Vc viu meu pai "+it.pai+" ?");
		var superior = buscaNo(it.pai,ArrMenu);
		it.pai = superior.cod;
		superior.filhos.push(it);
	}

	return it;
}

function carregar(codpai)
{
	var param = "codPai=";

	if(codpai != null)
	{
		param+= codpai;
		
		var no = buscaNo(codpai,ArrMenu);
		if(no.buscou == "S")
		{
			mostrarMenu(codpai,0);
			return;
		}
		tipo = 0;
		if(no.ano != "" && no.ano != 0)
		{
			param+="&ano="+no.ano;
			tipo++;
		}

		if(no.mes != "" && no.mes != 0)
		{
			param+="&mes="+no.mes;
			tipo++;
		}
		
		if(tipo >0)
		{
			param+="&tipo="+tipo;
		}
		no.filhos = new Array();
		no.buscou = "S";
	} else {
		ArrMenu = new Array();
	}

	var http = objPost("blogode/treeView/xml/menuItem.asp",param);

	http.onreadystatechange=function() {
		if (http.readyState == 1) {
			//botao.disabled = true;
		}
		if (http.readyState == 4) { 

			var xmlRetorno = http.responseXML;

			try{
				lerxml(xmlRetorno.getElementsByTagName("item"),1);
			} catch(erro){
				msg = http.responseText;
				alert(erro);
			}
			mostrarMenu(codpai,0);
		}
	}
	http.send(param); // This time, we need to send the text.
}
function lerxml(x,tp)
{
	var retorno = null;
	for(i=0;i<x.length;i++)
	{
		var pai = x[i].getElementsByTagName("MNU_CODIGO_SUPERIOR")[0].firstChild.nodeValue;

		if(pai == "-x-" || pai == "null")
		{
			pai = null;
		}
		if(tp ==1)
		{
			retorno = criarNo(x[i].getElementsByTagName("MNU_CODIGO")[0].firstChild.nodeValue,
					x[i].getElementsByTagName("MNU_NOME")[0].firstChild.nodeValue,
					x[i].getElementsByTagName("MNU_MATERIA")[0].firstChild.nodeValue,
					x[i].getElementsByTagName("MNU_MES")[0].firstChild.nodeValue,
					x[i].getElementsByTagName("MNU_ANO")[0].firstChild.nodeValue,
					pai);
		}
	}
	return retorno;
}