
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.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
        http.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        http.setRequestHeader("Pragma", "no-cache");
                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 iniciar() {	

var items = [], allItems = document.getElementsByTagName("li");
	
for (var i = 0; i < allItems.length; i++) {				
	allItems[i].onclick = function() {

    	if(this.className!= 'submenu'){
		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");	






        function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
		hash[1] = unescape(hash[1]);
		vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}


var pedaco = getUrlVars();
var tempit = pedaco['cat'];

if(typeof tempit == 'undefined'){
var url = 'receber.php?pagina=' + pagina;
}
else{

var url = 'receber.php?pagina=' + pagina + '&cat=' + tempit;
}
		mostrar_pagina(url, 'conteudo');
		
		}

	}
}	

var aba = document.getElementsByTagName("menu_dropdown");

	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);

