//Menu 
function ajaxPrincipal(url){
	
	if (document.getElementById) { //Verifica se o Browser suporta DHTML.
		if(window.XMLHttpRequest) {
			try {
				HttpReq = new XMLHttpRequest();
			} catch(e) {
				HttpReq = false;
			}
		} else if(window.ActiveXObject) {
			try {
				HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					HttpReq = false;
				}
			}
		}
		if(HttpReq) {
			HttpReq.onreadystatechange = XMLHttpRequestChange_1;
			HttpReq.open("GET", url, true);
			HttpReq.send(null);
		}		  
	}
}

function XMLHttpRequestChange_1() {
	if (HttpReq.readyState == 1) {
		var texto1 = document.getElementById("tudo");
		texto1.innerHTML = '<div class="verdana_11_preto" style="position:absolute; left:45%; top:0; width:100px;   z-index:1;padding-top:5px;padding-left:10px;padding-bottom:5px"><img src="img/carregando.gif" border="0"></div>';
	}
	
	
	if (HttpReq.readyState == 4 && HttpReq.status == 200){
      var result = HttpReq.responseText;
      var texto = document.getElementById("tudo");
		texto.innerHTML = result;
   }
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////

//conteudo 
function ajaxMenu(url, cod){
	
	if (document.getElementById) { //Verifica se o Browser suporta DHTML.
		if(window.XMLHttpRequest) {
			try {
				HttpReq = new XMLHttpRequest();
			} catch(e) {
				HttpReq = false;
			}
		} else if(window.ActiveXObject) {
			try {
				HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					HttpReq = false;
				}
			}
		}
		url = url+'?cod='+cod;
//		alert(url);
		if(HttpReq) {
			HttpReq.onreadystatechange = XMLHttpRequestChange_2;
			HttpReq.open("GET", url, true);
			HttpReq.send(null);
		}		  
	}
}

function XMLHttpRequestChange_2() {
	if (HttpReq.readyState == 1) {
		var texto1 = document.getElementById("principal_centro");
		texto1.innerHTML = '<div class="verdana_11_preto" style="position:absolute; left:70%; top:27%; width:100px;  z-index:1;padding-top:5px;padding-left:10px;padding-bottom:5px"><img src="img/carregando.gif" border="0"></div>';
	}

	if (HttpReq.readyState == 4 && HttpReq.status == 200){
      var result = HttpReq.responseText;
      var texto = document.getElementById("principal_centro");
		texto.innerHTML = result;
   }
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////


//conteudo 
function ajaxMenu_2(url){
	
	if (document.getElementById) { //Verifica se o Browser suporta DHTML.
		if(window.XMLHttpRequest) {
			try {
				HttpReq = new XMLHttpRequest();
			} catch(e) {
				HttpReq = false;
			}
		} else if(window.ActiveXObject) {
			try {
				HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					HttpReq = false;
				}
			}
		}
		if(HttpReq) {
			HttpReq.onreadystatechange = XMLHttpRequestChange_3;
			HttpReq.open("GET", url, true);
			HttpReq.send(null);
		}		  
	}
}

function XMLHttpRequestChange_3() {
	if (HttpReq.readyState == 1) {
		var texto1 = document.getElementById("coluna_direita");
		texto1.innerHTML = '<div class="verdana_11_preto" style="position:absolute; left:70%; top:27%; width:100px;  z-index:1;padding-top:5px;padding-left:10px;padding-bottom:5px"><img src="img/carregando.gif" border="0"></div>';
	}

	if (HttpReq.readyState == 4 && HttpReq.status == 200){
      var result = HttpReq.responseText;
      var texto = document.getElementById("coluna_direita");
		texto.innerHTML = result;
   }
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
function limpa(campo)	{
	campo.value = "";
}

//Newsletter 
function ajaxNewsletter(url, form){
	var email = form.text.value;
	
	if (email == "") {
		alert('Digite um email para prosseguir');
		return;
	}
	
	if(!checarEmail(email))	{
		alert('Email invalido.');
		return;
	}
	
	form.text.value = '';
	
	if (document.getElementById) { //Verifica se o Browser suporta DHTML.
		if(window.XMLHttpRequest) {
			try {
				HttpReq = new XMLHttpRequest();
			} catch(e) {
				HttpReq = false;
			}
		} else if(window.ActiveXObject) {
			try {
				HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					HttpReq = false;
				}
			}
		}
		url = url+'?email='+email;
//		alert(url);
		if(HttpReq) {
			HttpReq.onreadystatechange = XMLHttpRequestChange_4;
			HttpReq.open("GET", url, true);
			HttpReq.send(null);
		}		  
	}
}

function XMLHttpRequestChange_4() {
	if (HttpReq.readyState == 4 && HttpReq.status == 200){
      var result = HttpReq.responseText;
      var texto = document.getElementById("cadOK");
		texto.innerHTML = result;
   }
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////

//Enviar Email
function ajaxEmail(url, form){
	var nome = form.nome.value;
	var email = form.email.value;
	var telefone = form.telefone.value;
	var texto = form.texto.value;
	
	if (document.getElementById) { //Verifica se o Browser suporta DHTML.
		if(window.XMLHttpRequest) {
			try {
				HttpReq = new XMLHttpRequest();
			} catch(e) {
				HttpReq = false;
			}
		} else if(window.ActiveXObject) {
			try {
				HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					HttpReq = false;
				}
			}
		}
		url = url+'?email='+email+'&nome='+nome+'&telefone='+telefone+'&texto='+texto;
//		alert(url);
		if(HttpReq) {
			HttpReq.onreadystatechange = XMLHttpRequestChange_5;
			HttpReq.open("GET", url, true);
			HttpReq.send(null);
		}		  
	}
}

function XMLHttpRequestChange_5() {
	if (HttpReq.readyState == 1) {
		var texto1 = document.getElementById("coluna_direita");
		texto1.innerHTML = '<div class="verdana_11_preto" style="position:absolute; left:70%; top:27%; width:100px;  z-index:1;padding-top:5px;padding-left:10px;padding-bottom:5px"><img src="img/carregando.gif" border="0"></div>';
	}

	if (HttpReq.readyState == 4 && HttpReq.status == 200){
      var result = HttpReq.responseText;
      var texto = document.getElementById("coluna_direita");
		texto.innerHTML = result;
   }
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////
//Valida EMAIL
///////////////////////////////////////////////////
function checarEmail(campo){
	email=campo;
  	carac_invalido = " /:,;";
  	if (email == ""){
    	return false;
  	}
  	for (i=0; i<carac_invalido.length; i++){
    	carac_errado = carac_invalido.charAt(i);
    	if (email.indexOf(carac_errado,0) > -1){
      	return false;

    	}
  	}

  	atPos = email.indexOf("@",1);
  	if (atPos == -1){
 		return false;
  	}

  	if (email.indexOf("@",atPos+1) != -1){
    	return false;
  	}
  	periodPos = email.indexOf(".",atPos)

  	if (periodPos == -1){
    	return false;
  	}

  	if (periodPos+3 > email.length){
	   return false;
  	}
  return true
}
