//FUNÇOES DE ENTRADA EM PAGINAS -------------------------------------------

function enviaContato() {
	/*$("#corpoForm").html("");*/
	var nomeContato = document.getElementById("nomeContato").value;
	var empresaContato = document.getElementById("empresaContato").value;
	var dddContato = document.getElementById("dddContato").value;
	var telefoneContato = document.getElementById("telefoneContato").value;
	var emailContato = document.getElementById("emailContato").value;
	var cnpjContato = document.getElementById("cnpjContato").value;
	//alert(nomeContato);
		$.ajax({
			type: "POST",
			cache: false,
			url: "enviaEmail.php",
			data: "nomeContato="+nomeContato+"&empresaContato="+empresaContato+"&dddContato="+dddContato+"&telefoneContato="+telefoneContato+"&emailContato="+emailContato+"&cnpjContato="+cnpjContato,
			success: function(dados){
				if (dados){
					$("#corpoForm").html(dados);
			}else {
					$("#corpoForm").html(dados);
				}
			}
		});
}

function chamaQuali() {
	$("#pedidoPersonal").html("<center><img src='img/loaderRoxo.gif' /></center>");
		$.ajax({
			type: "POST",
			cache: false,
			url: "qualificaTipo.php",
			data: "",
			success: function(dados){
				if (dados){
					$("#pedidoPersonal").html(dados);
			}else {
					$("#pedidoPersonal").html(dados);
				}
			}
		});
}

function pesquisaPedido() {
    var campo = document.forms['formPedido'].elements["tipo"];
	var ok=0;
	var total = campo.length;
	for(k=0; k < total; k++) {
				if(campo[k].checked == true){
					tipo = campo[k].value;
					ok++;
				}
	}
	pesquisa = document.getElementById("pesquisa").value;
	if(pesquisa == ""){
		alert("Preencha o campo da busca");
		return false;
	}
	$("#listaPedidos").html("<center>Pesquisando, Aguarde...<img src='img/loaderRoxo.gif' /></center>");
		$.ajax({
			type: "POST",
			cache: false,
			url: "pedidos.php",
			data: "pesquisa="+pesquisa+"&tipo="+tipo,
			success: function(dados){
				if (dados){
					$("#listaPedidos").html(dados);
			}else {
					$("#listaPedidos").html(dados);
				}
			}
		});
}

function pesquisaEmpresa() {
   var campo = document.forms['formPedido'].elements["tipo"];
	var ok=0;
	var total = campo.length;
	for(k=0; k < total; k++) {
				if(campo[k].checked == true){
					tipo = campo[k].value;
					ok++;
				}
	}
	pesquisa = document.getElementById("pesquisa").value;
	if(pesquisa == ""){
		alert("Preencha o campo da busca");
		setTimeout("document.getElementById('pesquisa').focus()",5);
		return false;
	}
	$("#listaEmpresas").html("<center>Pesquisando, Aguarde...<img src='img/loaderRoxo.gif' /></center>");
		$.ajax({
			type: "POST",
			cache: false,
			url: "empresas.php",
			data: "pesquisa="+pesquisa+"&tipo="+tipo,
			success: function(dados){
				if (dados){
					$("#listaEmpresas").html(dados);
			}else {
					$("#listaEmpresas").html(dados);
				}
			}
		});
}

function mostraPedidos() {
	pesquisa = document.getElementById("lista").value;
	if(pesquisa == ""){
		alert("Preencha o campo da busca");
		return false;
	}
	$("#listaEmpresas").html("<center>Pesquisando, Aguarde...<img src='img/loaderRoxo.gif' /></center>");
		$.ajax({
			type: "POST",
			cache: false,
			url: "mostrapedidos.php",
			data: "pesquisa="+pesquisa,
			success: function(dados){
				if (dados){
					$("#listaEmpresas").html(dados);
			}else {
					$("#listaEmpresas").html(dados);
				}
			}
		});
}

function gerarExcelPedidos(pesquisa){
	$("#geraExcel").html("<center>Gerando Excel, Aguarde...<img src='img/loaderRoxo.gif' /></center>");
	$.ajax({
		type: "POST",
		cache: false,
		url: "",
		data: "",
		success: function(dados){
			if (dados){
				$("#geraExcel").html("Pronto!");
		}else {
				$("#geraExcel").html("Pronto!");
			}
		}
	});

}

function addPontoVirgula(letras){
	contador = letras.length;
	//alert(contador);
	contador++;
	if(contador % 8){
		
	}else{
		document.getElementById("lista").value += ";";
	}
}


function chamaQualiPersonalizada() {
	$("#pedidoPersonal").html("<center><img src='img/loaderRoxo.gif' /></center>");
		$.ajax({
			type: "POST",
			cache: false,
			url: "qualifica.php",
			data: "",
			success: function(dados){
				if (dados){
					$("#pedidoPersonal").html(dados);
			}else {
					$("#pedidoPersonal").html(dados);
				}
			}
		});
}

//CONSULTA DE CNPJ
function consulCnpj(resu,e) {
	//Mascara('CNPJ',resu,teclaPress);
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	var character = String.fromCharCode(code);
	var conteudo = resu.value + character;
	var tamanho = conteudo.length;
//	alert(conteudo);
//	alert('Character was ' + character);
	
	if(tamanho == 14){
	  $("#carrega").html("<img src='img/loader.gif'>");
	  resu.disabled = true;
			$.ajax({
				type: "POST",
				cache: false,
				url: "logando.php",
				data: "cnpjLogin="+conteudo,
				success: function(dados){
					if (dados){
						//document.getElementById("razaosocial").value = "Razao Social";
						//document.getElementById("nomefantasia").value = "Nome Fantasia";
						$("#corpoForm").html(dados);
				}else {
						$("#corpoForm").html(dados);
					}
				}
			});
	}else{
	  $("#carrega").html("<img src='img/loader.gif'>");
	  $("#digita").html("Continue digitando o CNPJ " + conteudo);
	}
}

function verificaprod(campo){
	var nomecampo = campo.id;
	var valor = campo.value;
	if(nomecampo == "prod1"){
		if(valor == ""){
			document.getElementById("prod2").readOnly = true;
			document.getElementById("prod100").readOnly = true;			
		}else{
			document.getElementById("prod2").readOnly = false;
			document.getElementById("prod100").readOnly = false;						
		}
	}
	if(nomecampo == "prod2"){
		if(valor == ""){
			document.getElementById("prod3").readOnly = true;		
		}else{
			document.getElementById("prod3").readOnly = false;
		}
	}
	if(nomecampo == "prod3"){
		if(valor == ""){
			document.getElementById("prod4").readOnly = true;			
		}else{
			document.getElementById("prod4").readOnly = false;
		}
	}
	if(nomecampo == "prod4"){
		if(valor == ""){
			document.getElementById("prod5").readOnly = true;			
		}else{
			document.getElementById("prod5").readOnly = false;
		}
	}
	if(nomecampo == "prod5"){
		if(valor == ""){
			document.getElementById("prod6").readOnly = true;			
		}else{
			document.getElementById("prod6").readOnly = false;
		}
	}
	if(nomecampo == "prod6"){
		if(valor == ""){
			document.getElementById("prod7").readOnly = true;			
		}else{
			document.getElementById("prod7").readOnly = false;
		}
	}
	if(nomecampo == "prod7"){
		if(valor == ""){
			document.getElementById("prod8").readOnly = true;			
		}else{
			document.getElementById("prod8").readOnly = false;
		}
	}

	if(nomecampo == "prod8"){
		if(valor == ""){
			document.getElementById("prod9").readOnly = true;			
		}else{
			document.getElementById("prod9").readOnly = false;
		}
	}

	if(nomecampo == "prod9"){
		if(valor == ""){
			document.getElementById("prod10").readOnly = true;			
		}else{
			document.getElementById("prod10").readOnly = false;
		}
	}
	if(nomecampo == "prod10"){
		if(valor == ""){
			document.getElementById("prod11").readOnly = true;			
		}else{
			document.getElementById("prod11").readOnly = false;
		}
	}
	if(nomecampo == "prod11"){
		if(valor == ""){
			document.getElementById("prod12").readOnly = true;			
		}else{
			document.getElementById("prod12").readOnly = false;
		}
	}
	if(nomecampo == "prod100"){
		if(valor == ""){
			document.getElementById("prod101").readOnly = true;		
			document.getElementById("prod200").readOnly = true;			
		}else{
			document.getElementById("prod101").readOnly = false;
			document.getElementById("prod200").readOnly = false;						
		}
	}
	if(nomecampo == "prod101"){
		if(valor == ""){
			document.getElementById("prod102").readOnly = true;			
		}else{
			document.getElementById("prod102").readOnly = false;
		}
	}
	if(nomecampo == "prod102"){
		if(valor == ""){
			document.getElementById("prod103").readOnly = true;			
		}else{
			document.getElementById("prod103").readOnly = false;
		}
	}
	if(nomecampo == "prod200"){
		if(valor == ""){
			document.getElementById("prod201").readOnly = true;			
		}else{
			document.getElementById("prod201").readOnly = false;
		}
	}
	if(nomecampo == "prod201"){
		if(valor == ""){
			document.getElementById("prod202").readOnly = true;			
		}else{
			document.getElementById("prod202").readOnly = false;
		}
	}
}

function controleDiv() { //v9.0
  var i,p,v,obj,args=controleDiv.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='mostra')?'visible':(v=='inibe')?'hidden':v; }
    obj.visibility=v; }
}

function mostraImg(img) {
	$("#imgAjuda").html("<br /><br /><br /><br /><br /><br /><center><img src='img/loaderRoxo.gif' /></center>");
	$.ajax({
		type: "POST",
		cache: false,
		url: "img.php",
		data: "img="+img,
		success: function(dados){
			if (dados){
				$("#imgAjuda").html(dados);
		}else {
				$("#imgAjuda").html(dados);
			}
		}
	});
}

function alterarVencto(data, pedido) {
	$("#alterar").html("<center><img src='img/loaderRoxo.gif' /></center>");
	document.getElementById("alterar").style.display = '';
	$.ajax({
		type: "POST",
		cache: false,
		url: "altera.php",
		data: "vencto="+data+"&pedido="+pedido,
		success: function(dados){
			if (dados){
				$("#alterar").html(dados);
		}else {
				$("#alterar").html(dados);
			}
		}
	});
}

function geraExcelFeira() {
	$("#listaEmpresas").html("<center><img src='img/loaderRoxo.gif' /></center>");
	evento = document.getElementById("evento").value;
	$.ajax({
		type: "POST",
		cache: false,
		url: "gerarExcelFeira.php",
		data: "evento="+evento,
		success: function(dados){
			if (dados){
				$("#listaEmpresas").html(dados);
		}else {
				$("#listaEmpresas").html(dados);
			}
		}
	});
}

function alterarValor(valor, pedido) {
	$("#alterar").html("<center><img src='img/loaderRoxo.gif' /></center>");
	document.getElementById("alterar").style.display = '';
	$.ajax({
		type: "POST",
		cache: false,
		url: "alteravalor.php",
		data: "valor="+valor+"&pedido="+pedido,
		success: function(dados){
			if (dados){
				$("#alterar").html(dados);
		}else {
				$("#alterar").html(dados);
			}
		}
	});
}

function carrega(div, pagina, campo, valor){
	var posting = '';
	if(valor != ""){
		val = document.getElementById(valor).value;
		posting = campo+"="+val;
	}
	$("#"+div).html("<center><img src='img/loaderRoxo.gif' /></center>");
	$.ajax({
		type: "POST",
		cache: false,
		url: pagina,
		data: posting,
		success: function(dados){
			if (dados){
				$("#"+div).html(dados);
		}else {
				$("#"+div).html(dados);
			}
		}
	});
}


function alterarEmail(envia) {
	var idexpositor = document.getElementById('empresa').value;
	var email = document.getElementById('email').value;
	var email2 = document.getElementById('emailadd').value;
	$("#alterar"+idexpositor).html("<center><img src='img/loaderRoxo.gif' /></center>");
	$.ajax({
		type: "POST",
		cache: false,
		url: "emailAdd.php",
		data: "idexpositor="+idexpositor+"&email="+email+"&email2="+email2+"&envia="+envia,
		success: function(dados){
			if (dados){
				$("#alterar"+idexpositor).html(dados);
		}else {
				$("#alterar"+idexpositor).html(dados);
			}
		}
	});
}

function validaMotivo(){
	var motivo = document.getElementById('motivo').value;
	if(motivo == ""){
		alert("Preencha o motivo do cancelamento!");
		return false;
	}
}

