/*DESENVOLVIDO POR:
Max Holanda
max.brejo@gmail.com
*/

function Ajax(){
	var xmlhttp=false;
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E){
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}



function enviaAjax(url){
    var carregando = document.getElementById("carregar");
	document.getElementById("carregando").style.background = '#000000';
	document.getElementById("carregando").style.display = 'inline';
	document.getElementById("carregar").style.display = 'inline';
	carregando.innerHTML = fazJanela("<div align=\"center\"><img src=\"imagens/load.gif\" /> carregando...</div>");

	ajax=Ajax();
	//Especifica o arquivo da consulta e as variaveis
	ajax.open("GET", url);

	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {

			carregando.innerHTML = null;
			carregando.innerHTML = fazJanela(ajax.responseText);
		}
	}
	ajax.send(null);
}

function ConfirmDialog(url, tabela,id,voto){
	enviaAjax(url+"?id="+id+"&tabela="+tabela+"&voto="+voto);
}

function ExibePagina(url,tipo, resolucao, idioma){
    	 //div onde ira o resultado
	 divListado = document.getElementById("resultado");

	 var carregando = document.getElementById("resultado");
	 carregando.innerHTML='<img src="imagens/load.gif" /> carregando...';

	ajax=Ajax();
	//Especifica o arquivo da consulta e as variaveis
	ajax.open("GET",url+"?tipo="+tipo+"&resolucao="+resolucao+"&idioma="+idioma);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			carregando.innerHTML = null;
			var resposta = unescape(ajax.responseText);
			divListado.innerHTML = resposta;
   		}
	}

	ajax.send(null)
}

function validaComent(){
	var nota = document.getElementById("nota").value;
	var notas = document.getElementsByName("nota");
	var nome = document.getElementById("nome").value;
	var cidade = document.getElementById("cidade").value;
	var estado = document.getElementById("estado").value;
	var comentario = document.getElementById("comentario").value;

	if ((notas[0].checked)||(notas[1].checked)||(notas[2].checked)||(notas[3].checked)||(notas[4].checked)){}else{alert("Selecione uma nota");nota.focus(); return false}
	if ((nome=="nome")||(nome=="")){alert("Digite um nome");nome.focus(); return false;}
	if ((cidade=="cidade")||(cidade=="")){alert("Digite a cidade");nota.focus(); return false;}
	if (estado=="#"){alert("Escolha o estado"); return false;}
	if ((comentario=="digite seu comentário aqui")||(comentario=="")){alert("Digite o comentario"); return false;}
	return true;
}

function enviaComentario(url, idCont, tipo)
{
 if (!(validaComent())){}else{
	var nota = document.getElementById("nota").value;
	var nome = document.getElementById("nome").value;
	var cidade = document.getElementById("cidade").value;
	var estado = document.getElementById("estado").value;
	var comentario = document.getElementById("comentario").value;

	enviaAjax(url+"?idcont="+idCont+"&tipo="+tipo+"&nota="+nota+"&nome="+nome+"&cidade="+cidade+"&estado="+estado+"&comentario="+comentario);
	}
}

function validaPedido(){
	var nome = document.getElementById("nome").value;
	var email = document.getElementById("email").value;
	var obs = document.getElementById("obs").value;
	

    validacao = email.indexOf("@");
    validacao2 = email.lastIndexOf(".");
	if ((validacao<=0)||(validacao2<=validacao)||(email=="")){alert("Digite um E-mail válido");email.focus(); return false;}

	if ((nome=="nome")||(nome=="")){alert("Digite um nome");nome.focus(); return false;}
	if ((obs=="Observações")||(obs=="")){alert("Digite o comentario"); return false;}
	return true;
}

function fazPedido()
{
 if (!(validaPedido())){}else{
	var nome = document.getElementById("nome").value;
	var email = document.getElementById("email").value;
	var obs = document.getElementById("obs").value;

	enviaAjax('cdcm_enviaPedido.php?nome='+nome+'&email='+email+'&obs='+obs);
	}
}

function validaPedidoConf(){
	var nome = document.getElementById("nome").value;
	var email = document.getElementById("email").value;
	var endereco = document.getElementById("endereco").value;
	var numero = document.getElementById("numero").value;
	var bairro = document.getElementById("bairro").value;
	var complemento = document.getElementById("complemento").value;
	var cidade = document.getElementById("cidade").value;
	var estado = document.getElementById("estado").value;
	var cep = document.getElementById("cep").value;
	var obs = document.getElementById("obs").value;


    validacao = email.indexOf("@");
    validacao2 = email.lastIndexOf(".");
	if ((validacao<=0)||(validacao2<=validacao)||(email=="")){alert("Digite um E-mail válido");email.focus(); return false;}

	if ((nome=="nome")||(nome=="")){alert("Digite um nome");nome.focus(); return false;}

    if ((endereco=="endereco")||(endereco=="")){alert("Digite um endereco"); return false;}
    if ((numero=="nº")||(numero=="")){alert("Digite um numero"); return false;}
    if ((bairro=="bairro")||(bairro=="")){alert("Digite um bairro"); return false;}
    if ((cidade=="cidade")||(cidade=="")){alert("Digite uma cidade"); return false;}
    if ((estado=="estado")||(estado=="")){alert("Digite um estado");return false;}
    if ((cep=="cep")||(numero=="")){alert("Digite um cep"); return false;}
 	return true;
}

function confirmaPedido()
{
 if (!(validaPedidoConf())){}else{
	var nome = document.getElementById("nome").value;
	var email = document.getElementById("email").value;
	var endereco = document.getElementById("endereco").value;
	var numero = document.getElementById("numero").value;
	var bairro = document.getElementById("bairro").value;
	var complemento = document.getElementById("complemento").value;
	var cidade = document.getElementById("cidade").value;
	var estado = document.getElementById("estado").value;
	var cep = document.getElementById("cep").value;
	var obs = document.getElementById("obs").value;

	enviaAjax('cdcm_enviaPagamento.php?nome='+nome+'&email='+email+'&endereco='+endereco+'&numero='+numero+'&bairro='+bairro+'&complemento='+complemento+'&cidade='+cidade+'&estado='+estado+'&cep='+cep+'&obs='+obs);
	}
}

function validaDica(){
	var nome1 = document.getElementById("nome1").value;
	var nome2 = document.getElementsByName("nome2");
	var email2 = document.getElementById("email2").value;

	if ((nome1=="seu nome")||(nome1=="")){alert("Digite seu nome");nome1.focus(); return false;}
	if ((nome2=="nome do amigo")||(nome2=="")){alert("Digite o nome do seu amigo");nome2.focus(); return false;}
	if ((email2=="email do amigo")||(email2=="")){alert("Digite o e-mail do amigo");nota2.focus(); return false;}

	return true;
}

function enviaDica(url, idCont, tipo)
{
 if (!(validaDica())){}else{
	var nome1 = document.getElementById("nome1").value;
	var nome2 = document.getElementById("nome2").value;
	var email2 = document.getElementById("email2").value;

    enviaAjax(url+"?idcont="+idCont+"&tipo="+tipo+"&nome1="+nome1+"&nome2="+nome2+"&email2="+email2);
	}
}

function cancelaNews(email,codigo,cancela){
    enviaAjax("delnews.php?email="+email+"&cod="+codigo+"&cancela="+cancela);
}

function enviaContato(url)
{
	var nome = document.getElementById("nome").value;
	var cidade = document.getElementById("cidade").value;
	var estado = document.getElementById("estado").value;
	var email = document.getElementById("email").value;
	var assunto = document.getElementById("assunto").value;
	var mensagem = document.getElementById("mensagem").value;
	
	enviaAjax(url+"?nome="+nome+"&cidade="+cidade+"&estado="+estado+"&email="+email+"&assunto="+assunto+"&mensagem="+mensagem);
}

function validaNews(){
	var email = document.getElementById("email_news").value;
    validacao = email.indexOf("@");
    validacao2 = email.lastIndexOf(".");
	if ((validacao<=0)||(validacao2<=validacao)||(email=="")){alert("Digite um E-mail válido");email.focus(); return false;}
	return true;
}

function enviaNews(url)
{
    if ((validaNews())){
	   var email = document.getElementById("email_news").value;
	   enviaAjax(url+"?email="+email);
	}
}



function HideDiv(){
	document.getElementById("carregando").style.display = 'none';
	document.getElementById("carregar").style.display = 'none';
}

function fazJanela(texto){
	return "<div id=\"ajax_externa\"><div id=\"ajax_l_u\"><img src=\"imagens/estrutura/alphacube/left-top.gif\" width=\"10\" height=\"25\"></div><div id=\"ajax_top\" align=\"right\"><div id=\"ajax_fechar\"><a onclick=\"HideDiv()\"><img src=\"imagens/estrutura/alphacube/button-close-focus.gif\" border=\"0\" width=\"23\" height=\"23\"></a></div></div><div id=\"ajax_r_u\"><img src=\"imagens/estrutura/alphacube/right-top.gif\" width=\"10\" height=\"25\"></div><br><div id=\"ajax_left\">&nbsp;</div><div id=\"ajax_centro\">"+texto+"</div><div id=\"ajax_right\">&nbsp;</div><div id=\"ajax_l_d\"><img src=\"imagens/estrutura/alphacube/bottom-left-c.gif\" width=\"7\" height=\"7\"></div><div id=\"ajax_bottom1\"><img src=\"imagens/ponto.gif\" widht=\"1\" height=\"1\"></div><div id=\"ajax_bottom\"><img src=\"imagens/ponto.gif\" widht=\"1\" height=\"1\"></div><div id=\"ajax_bottom2\"><img src=\"imagens/ponto.gif\" widht=\"1\" height=\"1\"></div><div id=\"ajax_r_d\"><img src=\"imagens/estrutura/alphacube/bottom-right-c.gif\" width=\"7\" height=\"7\"></div></div>";
}


