//Ajax

carregandoHTML = '<div id="Carregando">&nbsp;<span>Carregando...</span></div>';
carregandoNews = '<br/><br/><br/><div id="Carregando"><span style="margin-left:20px">Enviando...</span></div>';

try{
	xmlhttp = new XMLHttpRequest();
}catch(ee){
	try{
		 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 }catch(e){
		 try{
			 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		 }catch(E){
			 xmlhttp = false;
		 }
	 }
 }

var ajax = {

	camposForm : function(idForm) {
		var aForm = document.getElementById(idForm);
		var elementosFormulario = aForm.elements;
		var qtdElementos = elementosFormulario.length;
		var queryString = "";
		var elemento;

		this.ConcatenaElemento = function(nome,valor) {
			if (queryString.length>0) {
				queryString += "&";
			}
			queryString += encodeURIComponent(nome) + "=" + encodeURIComponent(valor);
		};

		for (var i=0; i<qtdElementos; i++) {
			elemento = elementosFormulario[i];
			if (!elemento.disabled) {
				switch(elemento.type) {
					case 'text': case 'password': case 'hidden': case 'textarea':
							this.ConcatenaElemento(elemento.name,elemento.value);
					break;
					case 'select-one':
							if (elemento.selectedIndex>=0) {
						this.ConcatenaElemento(elemento.name,elemento.options[elemento.selectedIndex].value);
							}
							break;
					case 'select-multiple':
							for (var j=0; j<elemento.options.length; j++) {
						if (elemento.options[j].selected) {
							this.ConcatenaElemento(elemento.name,elemento.options[j].value);
						}
							}
							break;
					case 'checkbox': case 'radio':
							if (elemento.checked) {
						this.ConcatenaElemento(elemento.name,elemento.value);
							}
							break;
				}
			}
		}
//		aForm.reset();
		return queryString;
	},

	cadNewsletter : function(idform){
		param = ajax.camposForm(idform);

		xmlhttp.open('POST', '_newsletter.php', true);
		xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange = ajax.resNewsletter;
		xmlhttp.send(param);
	},

	vdNewsletter : function(idform){
		 d = document.getElementById(idform);
		 if (d.news_nome.value == ""){
			 alert("O campo - Nome - deve ser preenchido!");
			 d.news_nome.focus();
		 	return false;
		 }
		 if (d.news_mail.value == ""){
			 alert("O campo - E-mail - deve ser preenchido!");
			 d.news_mail.focus();
			 return false;
		 }
		 ajax.cadNewsletter(idform);
	 	 return true;
	 },

	resNewsletter : function(){

		 mensagens = document.getElementById('telaNewsletter');
		 mensagens.className='newsletterok';
		 
		 if(xmlhttp.readyState == 1)
		 mensagens.innerHTML = carregandoNews;

		 if(xmlhttp.readyState == 4) {
			 if(xmlhttp.status == 200) {
				 mensagens.innerHTML = xmlhttp.responseText;
			 }
		 }
	 },

	enviaPostMural : function(idform){
		 param = ajax.camposForm(idform);

		 xmlhttp.open('POST', '_torpedo_action.php', true);
		 xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		 xmlhttp.onreadystatechange = ajax.repostasAcao;
		 xmlhttp.send(param);
	},

	vdMural : function(idform){
		 d = document.getElementById(idform);
		 if (d.nome.value == ""){
			 alert("O campo - Nome - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.nome.focus();
		 	return false;
		 }
		 if (d.email.value == ""){
			 alert("O campo - E-mail - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.email.focus();
			 return false;
		 }
		 if (d.para.value == ""){
			 alert("O campo - Para - deve ser preenchido!");
			 d.para.className = 'formcontatoerro';
			 d.para.focus();
			 return false;
		 }
		 if (d.mensagem.value == ""){
			 alert("O campo - Mensagem - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.mensagem.focus();
			 return false;
		 }
		 ajax.enviaPostMural(idform);
	 	 return true;
	 },

	enviaEmail : function(idform){
		 param = ajax.camposForm(idform);

		 xmlhttp.open('POST', 'act_contato.php', true);
		 xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		 xmlhttp.onreadystatechange = ajax.repostasAcao;
		 xmlhttp.send(param);
		 //document.getElementById(idform).reset();
	},
	 
	vdContato : function(idform){
		 d = document.getElementById(idform);
		 if (d.nome.value == ""){
			 alert("O campo - Nome - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.nome.focus();
		 	return false;
		 }
		 if (d.email.value == ""){
			 alert("O campo - E-mail - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.email.focus();
			 return false;
		 }
		 if (d.telefone.value == ""){
			 alert("O campo - Telefone - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.telefone.focus();
			 return false;
		 }
		 if (d.mensagem.value == ""){
			 alert("O campo - Mensagem - deve ser preenchido!");
			 d.nome.className = 'formcontatoerro';
			 d.mensagem.focus();
			 return false;
		 }
		 ajax.enviaEmail(idform);
	 	 return true;
	 },

	ativaBuscaEvento : function(e) {
		cod = (window.event) ? e.keyCode : e.which ;
		if (cod==13){ ajax.vdBuscaEvento();}
	},

	vdBuscaEvento : function(){
		 d = document.getElementById('txt_busca');
		 if (d.value == ""){
			 alert("O campo de busca deve ser preenchido!");
			 d.className = 'formcontatoerro';
			 d.focus();
		 	return false;
		 }
		 str = d.value;
		 ajax.buscaEvento('centroConteudo',str);
	 	 return true;
	 },

	 buscaEvento : function(div,str){

		 local = document.getElementById(div);

		 xmlhttp.open('GET', '_busca_evento.php?s='+str, true);
		 xmlhttp.onreadystatechange = function(){
			 if(xmlhttp.readyState == 1) {
				 local.innerHTML = carregandoHTML;
			 }
			 if(xmlhttp.readyState == 4) {
				 if(xmlhttp.status == 200){
					 local.innerHTML = xmlhttp.responseText;
				 }
			 }
		 }
		 xmlhttp.send(null);
	 },

	 repostasAcao : function(){

		 mensagens = document.getElementById('centroConteudo');
		 
		 if(xmlhttp.readyState == 1)
		 mensagens.innerHTML = carregandoHTML;

		 if(xmlhttp.readyState == 4) {
			 if(xmlhttp.status == 200) {
				 mensagens.innerHTML = xmlhttp.responseText;
			 }
		 }
	 },

	 exibeFoto : function(div,url){

		 local = document.getElementById(div);
		 local.innerHTML = '<img src='+url+'>';
	 },
	 
	 abreLink : function(div,url){

		 local = document.getElementById(div);

		 xmlhttp.open('GET', url, true);
		 xmlhttp.onreadystatechange = function(){
			 if(xmlhttp.readyState == 1) {
				 local.innerHTML = carregandoHTML;
			 }
			 if(xmlhttp.readyState == 4) {
				 if(xmlhttp.status == 200){
					 local.innerHTML = xmlhttp.responseText;
				 }
			 }
		 }
		 xmlhttp.send(null);
	 },

	 getInfo : function(div,url){

		 local = document.getElementById(div);

		 xmlhttp.open('GET', url, true);
		 xmlhttp.onreadystatechange = function(){
			 if(xmlhttp.readyState == 1) {
				 local.innerHTML = '';
			 }
			 if(xmlhttp.readyState == 4) {
				 if(xmlhttp.status == 200){
					 local.innerHTML = xmlhttp.responseText;
				 }
			 }
		 }
		 xmlhttp.send(null);
	 },

	userOnline : function() {
		ajax.getInfo('userOnline','ajax/_useronline.php');
	}
}

try{
	xmlhttpx = new XMLHttpRequest();
}catch(ee){
	try{
		 xmlhttpx = new ActiveXObject("Msxml2.XMLHTTP");
	 }catch(e){
		 try{
			 xmlhttpx = new ActiveXObject("Microsoft.XMLHTTP");
		 }catch(E){
			 xmlhttpx = false;
		 }
	 }
 }

var xajax = {

	camposForm : function(idForm) {
		var aForm = document.getElementById(idForm);
		var elementosFormulario = aForm.elements;
		var qtdElementos = elementosFormulario.length;
		var queryString = "";
		var elemento;

		this.ConcatenaElemento = function(nome,valor) {
			if (queryString.length>0) {
				queryString += "&";
			}
			queryString += encodeURIComponent(nome) + "=" + encodeURIComponent(valor);
		};

		for (var i=0; i<qtdElementos; i++) {
			elemento = elementosFormulario[i];
			if (!elemento.disabled) {
				switch(elemento.type) {
					case 'text': case 'password': case 'hidden': case 'textarea':
							this.ConcatenaElemento(elemento.name,elemento.value);
					break;
					case 'select-one':
							if (elemento.selectedIndex>=0) {
						this.ConcatenaElemento(elemento.name,elemento.options[elemento.selectedIndex].value);
							}
							break;
					case 'select-multiple':
							for (var j=0; j<elemento.options.length; j++) {
						if (elemento.options[j].selected) {
							this.ConcatenaElemento(elemento.name,elemento.options[j].value);
						}
							}
							break;
					case 'checkbox': case 'radio':
							if (elemento.checked) {
						this.ConcatenaElemento(elemento.name,elemento.value);
							}
							break;
				}
			}
		}
//		aForm.reset();
		return queryString;
	},

	procEnquete : function(idform){
		param = xajax.camposForm(idform);

		xmlhttpx.open('POST', '_home_enquete.php', true);
		xmlhttpx.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		xmlhttpx.onreadystatechange = xajax.resEnquete;
		xmlhttpx.send(param);
	},

	resEnquete : function(){

		 msg = document.getElementById('enqueteHome');
		 
		 if(xmlhttpx.readyState == 1)
		 msg.innerHTML = carregandoHTML;

		 if(xmlhttpx.readyState == 4) {
			 if(xmlhttpx.status == 200) {
				 msg.innerHTML = xmlhttpx.responseText;
			 }
		 }
	 }
}
