/* 
 	Ajax
	Autor: 	Endrius <endrius@gmail.com>
	Criado: 	30/09/2009
*/

try{
	var xmlhttp = new XMLHttpRequest();
}catch(ee){
	try{
		var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			var xmlhttp = false;
		}
	}
}


function carregando(params){
	//Exibe o texto carregando
	document.getElementById(params).innerHTML = "<table width='100%' height='100%'><tr><td align='center' valign='middle' class='texto'>carregando...<br><img src='img/load.gif'/></td></tr></table>";
}

function carregar( base, params ){
	carregando(params);

		campo = "&acao=" + base;
		xmlhttp.open("POST", "functions/untGeral.php", true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(campo);
		//Executada quando o navegador obtiver o código
			xmlhttp.onreadystatechange = function() {

				if (xmlhttp.readyState == 4){
					//Lê o texto
					texto = xmlhttp.responseText;
					//Desfaz o urlencode
					texto = texto.replace(/\+/g, " ");
					texto = unescape( texto );
					//Exibe o texto no div conteúdo
					document.getElementById(params).innerHTML = "";
					//conteudo.innerHTML = texto;
					document.getElementById(params).innerHTML = texto;
				}
			}

	return xmlhttp;
}

function Contato( base, params ){

	nome = document.getElementById('edtMailNome');
	email = document.getElementById('edtMailMail');
	assunto = document.getElementById('edtMailAssunto');
	mensagem = document.getElementById('edtMailMensagem');

	if(nome.value=="" || nome.value.length<3){
		alert("O campo NOME deve ser preenchido corretamente.");
		nome.focus();
		return false;
	}
	if(email.value.indexOf("@", 0) == -1 || email.value == ""){
		alert('Este não é um E-MAIL valido');
		email.focus();
		return false;
	}
	if(assunto.value ==""){
		alert("O campo Assunto precisa ser preenchido corretamente.");
		assunto.focus();
		return false;
	}
	if(mensagem.value =="" || mensagem.value.length<10){
		alert("O campo Mensagem deve ser preenchido corretamente.");
		mensagem.focus();
		return false;
	}

	campo = "&acao=" + base + "&edtMailNome=" + document.getElementById('edtMailNome').value + "&edtMailMail=" + document.getElementById('edtMailMail').value + "&edtMailAssunto=" + document.getElementById('edtMailAssunto').value + "&edtMailMensagem=" + document.getElementById('edtMailMensagem').value;
	carregando(params);
	xmlhttp.open("POST", "functions/untGeral.php", true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send(campo);
	//Executada quando o navegador obtiver o código
		xmlhttp.onreadystatechange = function() {

			if (xmlhttp.readyState == 4){
				//Lê o texto
				texto = xmlhttp.responseText;
				//Desfaz o urlencode
				texto = texto.replace(/\+/g, " ");
				texto = unescape( texto );
				//Exibe o texto no div conteúdo
				//conteudo.innerHTML = texto;
				document.getElementById(params).innerHTML = texto;
			}
		}

	return xmlhttp;
}

function painel( base, params, code ){
	carregando(params);

		xmlhttp.open("GET", "functions/acoes.php?acao=" + base , true);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		//Executada quando o navegador obtiver o código
			xmlhttp.onreadystatechange = function() {

				if (xmlhttp.readyState == 4){
					//Lê o texto
					texto = xmlhttp.responseText;
					//Desfaz o urlencode
					texto = texto.replace(/\+/g, " ");
					texto = unescape( texto );
					//Exibe o texto no div conteúdo
					//var conteudo=document.getElementById("conteudo");
					//conteudo.innerHTML = texto;
					document.getElementById(params).innerHTML = texto;
				}
			}

	return xmlhttp;
}

function menu( base, params, code ){
	carregando(params);
	if(base == 0){
 		document.getElementById(params).innerHTML = "";
	}
	campo = "&acao=" + base;
	xmlhttp.open("POST", "functions/untGeral.php", true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send(campo);
	//Executada quando o navegador obtiver o código
		xmlhttp.onreadystatechange = function() {

			if (xmlhttp.readyState == 4){
				//Lê o texto
				texto = xmlhttp.responseText;
				//Desfaz o urlencode
				texto = texto.replace(/\+/g, " ");
				texto = unescape( texto );
				//Exibe o texto no div conteúdo
				//conteudo.innerHTML = texto;
				document.getElementById(params).innerHTML = texto;
			}
		}

	return xmlhttp;
}

function artigos( base, params, artigo ){
	carregando(params);
	
	campo = "&id_artigo=" + artigo + "&acao=" + base;

	xmlhttp.open("POST", "functions/untGeral.php", true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send(campo);
	//Executada quando o navegador obtiver o código
		xmlhttp.onreadystatechange = function() {

			if (xmlhttp.readyState == 4){
				//Lê o texto
				texto = xmlhttp.responseText;
				//Desfaz o urlencode
				texto = texto.replace(/\+/g, " ");
				texto = unescape( texto );
				//Exibe o texto no div conteúdo
				//conteudo.innerHTML = texto;
				document.getElementById(params).innerHTML = texto;
			}
		}

	//xmlhttp.send(null);
		return xmlhttp;

}