function gE(ID,corpo)  { return corpo.getElementById(ID); }
function gT(tag,corpo) { return corpo.getElementsByTagName(tag); }

window.onload = inicia;

function inicia(){
	trocarLinks();	
}

function trocarLinks() {		
	var menuPEC 		= gE("menuPEC",document);
	var menuPrincipal = gE("menuPrincipal",document);
	var conteudo 		= gE("conteudo",document);
	novoLink(menuPEC);
	novoLink(menuPrincipal);
	novoLink(conteudo);
}

function novoLink(recipiente){
	var links = gT("a",recipiente);	
	for (var i=0; i < links.length; i++) { 
		if(links[i].target=="_blank"){ urchinTracker(links[i].href); return true; }
		links[i].onclick = function() {	
			var nLink = String(this.href);			
			nLink = nLink.split("=");
			openContent(nLink[1]);	
			urchinTracker(this.href);
			return false; 
		}
	}		
}

function getText(template, div) {
	var http = openAjax();
	if (http) {
		http.open('GET',template, true);
		http.onreadystatechange = function() {
			if (http.readyState == 1) { showStatus (div,'carrega'); }
			if (http.readyState == 4) {
				if (http.status == 200) {
					var retorno = http.responseText;
					var recipiente = gE(div,document);
					recipiente.innerHTML = retorno;
					novoLink(recipiente);		
				} else {
					showStatus(div,'erro');
				}
			}		
		}
		http.send(null);
	}
	else showStatus(div,'noAjax');
}	

function openContent(referencia){	
	var urlConteudo = 'geraInternas.php?exc='+referencia+'&ajax=true';
	getText(urlConteudo,'conteudo');	
}