
function XMLHTTPRequest() { 
	var http = 0;
	if (window.XMLHttpRequest) {
		http = new XMLHttpRequest();
	} else {
		try { 
			http = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try { 
			http = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) { 
				http = false; 
			} 
		}
	} 
	return http; 
}

function mostrar_pagina(url, div) {
	var http = XMLHTTPRequest();
	if (http) {
		http.onreadystatechange = function() {
			if (http.readyState == 4) {
				if (http.status == 200) {
					var retorno = unescape(http.responseText.replace(/\+/g," "));
					document.getElementById(div).innerHTML = retorno
				} else {
					alert('There was a problem with the request.');
				}
			}		
		}
		http.open('GET', url, true);
		http.send(null);
	}
	else {
		alert('Erro seu navegador nao suporta ajax');
	}
}	

function addEvent(obj, evType, fn) {
	if (typeof obj == "string") {
		if (null == (obj = $(obj))) {
			throw new Error("Cannot add event listener: HTML Element not found.");
		}
	}
	if (obj.attachEvent) {
		return obj.attachEvent(("on" + evType), fn);
	} else if (obj.addEventListener) {
		return obj.addEventListener(evType, fn, true);
	} else {
		throw new Error("Your browser doesn't support event listeners.");
	}
}

function strReplaceChr(texto) {
	var chrEspeciais = new Array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë",
				     "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö",
				     "ú", "ù", "û", "ü", "ç",
				     "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë",
				     "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö",
				     "Ú", "Ù", "Û", "Ü", "Ç");
	var chrNormais = new Array("a", "a", "a", "a", "a", "e", "e", "e", "e",
				   "i", "i", "i", "i", "o", "o", "o", "o", "o",
				   "u", "u", "u", "u", "c",
				   "A", "A", "A", "A", "A", "E", "E", "E", "E",
				   "I", "I", "I", "I", "O", "O", "O", "O", "O",
				   "U", "U", "U", "U", "C");
	for (index in chrEspeciais) {
		texto = texto.replace(chrEspeciais[index], chrNormais[index]);
	}

	return texto;
	}

function iniciar() {	

var items = [], allItems = document.getElementsByTagName("li");
	
for (var i = 0; i < allItems.length; i++) {				
	allItems[i].onclick = function() {	
		for (var item = this.parentNode.firstChild; item; item = item.nextSibling) {		
			item.className = 'normal';			
		}
		this.className = 'current';				
		var padrao = /(<span(.*?)>(.*?)<\/span>)/i;	
		var pagina = this.innerHTML.replace(padrao, "$3");	
		pagina = strReplaceChr(pagina);
		var url = 'receber.php?pagina=' + pagina;						
		mostrar_pagina(url, 'conteudo');						
				
	}				
}	

var aba = document.getElementsByTagName("span");

	for (var j = 0; j < aba.length; j++) {		
		aba[j].onmouseover = function() {		
			if(this.className != 'link'){					
				this.className = 'link';
			} 	
		}		
		aba[j].onmouseout = function() {	
			if(this.className != 'normal'){		
				this.className = 'normal';
			} 	
		}
	}	
}

// quando terminar o carregamento da página, executa a "iniciarMudancaDeEnterPorTab"
addEvent(window, "load", iniciar);

