function selCidade(cidade) {
	switch (cidade) {
		case "gyn":
			cidade 		= "Goiânia";
			cidade_id	= 968;
			break;
			
		case "bsb":
			cidade 		= "Brasília";
			cidade_id	= 798;
			break;

		case "sjp":
			cidade 		= "São José do Rio Preto";
			cidade_id 	= 5187;
			break;

		case "blm":
			cidade 		= "Belém";
			cidade_id	= 2396;
			break;
		
		case "plm":
			cidade 		= "Palmas";
			cidade_id	= 5362;
			break;
			
		case "udia":
			cidade 		= "Uberlândia";
			cidade_id	= 2146;
			break;
			
		case "sp":
			cidade 		= "São Paulo";
			cidade_id	= 5193;
			break;

		case "rio":
			cidade 		= "Rio de Janeiro";
			cidade_id	= 3507;
			break;
	}
	
	document.getElementById("rotuloCidade").innerHTML = "Eventos em " + cidade;

	document.frmBusca.cidade.value=cidade_id;
	document.frmBusca.cidade_nome.value=cidade;
	document.frmBusca.submit();
}

function valorIngresso() {
	cfgTotalCategs 	= document.frmConfigurar.cfgTotalCategs.value;
	cfgTaxaServico	= document.frmConfigurar.cfgTaxaServico.value;
	total_parcial	= 0;
	
	for (i=0; i<=cfgTotalCategs-1; i++) {
		ingresso = document.frmConfigurar["ingresso_"+i].value;
		
		try {
			qtd 	= document.frmConfigurar["qtd_"+ingresso].value;
			valor 	= moeda2float(document.getElementById("valor_"+ingresso).innerHTML);
			
			total = valor * qtd;
			
			total_parcial = total_parcial + total;

		} catch(err) {}
	}
	
	document.getElementById("valor_total_parcial").innerHTML = float2moeda(total_parcial);

	taxa_servico	= roundNumber(total_parcial * (cfgTaxaServico/100));
	valor_compra 	= total_parcial + taxa_servico;
	
	document.getElementById("valor_taxa_servico").innerHTML = float2moeda(taxa_servico);
	document.getElementById("valor_total").innerHTML = float2moeda(valor_compra);
	
	//parcelas(float2moeda(valor_compra), 1);
	
	document.frmConfigurar.cfg_valor_total_parcial.value 	= float2moeda(total_parcial);
	document.frmConfigurar.cfg_valor_servico.value 			= float2moeda(taxa_servico);
	document.frmConfigurar.cfg_valor_compra.value			= float2moeda(valor_compra);
}

function validaCarrinho() {
	if (!document.frmConfigurar.cfg_valor_total_parcial.value) {
		alert("Informe a quantidade desejada de cada ingresso!");
		return false;
	}
}

function senha(form) {
	if (form == 1)
		var email = document.frmLogin.email;		
	else if (form == 2)
		var email = document.frmLoginPainel.email;
	
	if (!email.value || email.value == "e-mail") {
		alert("Informe seu e-mail!");
		email.focus();
	} else {
		window.open("/exec.php?action=senha&email="+email.value+"&form="+form, "hddFrame");
	}
}

function displayMSG(msg, trDisplay, opt) {
	if (!trDisplay) {
		switch (opt) {
			case "":
			case 1:
			case "1":
				parent.document.getElementById('txtMsg').innerHTML=msg;
				break;
			
			case 2:
			case "2":
				parent.document.getElementById('txtMsg2').innerHTML=msg;
				break;
		}
		
		window.setTimeout("displayMSG('', '1',"+opt+")", 2000);
		
	} else {
		switch (opt) {
			case "":
			case 1:
			case "1":
				parent.document.getElementById('txtMsg').innerHTML='';
				break;
			
			case 2:
			case "2":
				parent.document.getElementById('txtMsg2').innerHTML='';
				break;
		}
	}
}

function displayMSG2(msg, trDisplay) {
	if (!trDisplay) {
		parent.document.getElementById('rotuloPainel').innerHTML=msg;	
		window.setTimeout("displayMSG2('', 1)", 2000);
	} else {
		parent.document.getElementById('rotuloPainel').innerHTML='<h4>Painel de controle</h4>';
	}
}

function isEmail(field) {	
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field))) { 
		return false;
	} else {
		return true;
	}
}

function trim(field) {
	return field.replace(/^\s*/, "").replace(/\s*$/, "");
}

function validaCadastro() {
	var nome			 = trim(document.formCadastro.nome.value);
	var data_nascimento  = trim(document.formCadastro.data_nascimento.value); 
	var fone_fixo		 = trim(document.formCadastro.fone_fixo.value); 
	var fone_celular	 = trim(document.formCadastro.fone_celular.value); 
	var validadeCPF		 = validaCPF(document.formCadastro.cpf.value);
	
	if (nome == "") {
		alert("Informe seu nome!");
		document.formCadastro.nome.focus();
		return false;

	} else if (nome.length < 8) {
		alert("Preencha seu nome de forma correta!");
		document.formCadastro.nome.focus();
		return false;
		
	} else if (document.formCadastro.cpf.value.length < 14) {
		alert("CPF inválido!");
		document.formCadastro.cpf.focus();
		return false;
	
	} else if (!validadeCPF) {
		alert("CPF inválido!!");
		document.formCadastro.cpf.focus();
		return false;

	} else if (data_nascimento == "") {
		alert("Informe sua data de nascimento!");
		document.formCadastro.data_nascimento.focus();
		return false;
		
	} else if (data_nascimento.length < 10) {
		alert("Preencha sua data de nascimento de forma correta!");
		document.formCadastro.data_nascimento.focus();
		return false;

	} else if (fone_fixo == "") {
		alert("Informe um telefone fixo para contato");
		document.formCadastro.fone_fixo.focus();
		return false;

	} else if (fone_fixo.length < 14) {
		alert("Preencha o telefone fixo de forma correta!");
		document.formCadastro.fone_fixo.focus();
		return false;

	} else if (document.formCadastro.sexo.value == "") {
		alert("Informe seu sexo!");
		document.formCadastro.sexo.focus();
		return false;
	
	} else if (document.formCadastro.hddEmail.value == "" && document.formCadastro.codigo_seg.value == "") {
		alert("Digite o código de segurança!");
		document.formCadastro.codigo_seg.focus();
		return false;

	} else if (document.formCadastro.endereco.value == "") {
		alert("Informe seu endereço!");
		document.formCadastro.endereco.focus();
		return false;
		
	} else if (document.formCadastro.bairro.value == "") {
		alert("Informe seu bairro!");
		document.formCadastro.bairro.focus();
		return false;

	} else if (document.formCadastro.cep_.value == "") {
		alert("Informe seu CEP!");
		document.formCadastro.cep_.focus();
		return false;
		
	} else if (document.formCadastro.cidade.value == "" || document.formCadastro.cidade.value == "0") {
		alert("Informe sua cidade!");
		return false;

	} else if (!isEmail(document.formCadastro.email.value)) {
		alert("E-mail inválido!");
		document.formCadastro.email.focus();
		return false;
		
	} else if (document.formCadastro.email.value != document.formCadastro.email2.value) {
		alert("E-mails não são iguais!");
		document.formCadastro.email.focus();
		return false;
		
	} else if (document.formCadastro.senha.value == "") {
		alert("Informe sua senha!");
		document.formCadastro.senha.focus();
		return false;
		
	} else if (document.formCadastro.senha.value != document.formCadastro.senha2.value) {
		alert("Senhas não são iguais!");
		document.formCadastro.senha.focus();
		return false;

	} else {
		//document.getElementById("btSubmit").value="aguarde...";
		
		document.getElementById("btSubmit").disabled=true;
		return true;		
	}
}

function ir(url, destino) {
	if (!destino) {
		window.location=url;	
	} else {
		window.open(url, destino);
	}
}

function logoff() {
	var redir = document.frmLoginPainel.redir.value;
	
	window.open("/exec.php?action=logoff&redir="+redir, "hddFrame");
}

function f_pgto(p) {
	
	document.getElementById("divFP").style.display="none";
	document.getElementById("trProsseguir").style.display="block";
	
	switch (p) {
		case "visa":
			document.getElementById("formPagamentoCartao").style.display="block";
			rotulo  = "Cartão: <b>VISA</b>";
			p 		= "Visa";
			break;

		case "master":
			document.getElementById("formPagamentoCartao").style.display="block";
			rotulo  = "Cartão: <b>MASTERCARD</b>";
			p 		= "Mastercard";
			break;
		
		case "boleto":
			document.getElementById("formPagamentoBoleto").style.display="block";
			rotulo  = "<b>BOLETO BANCÁRIO</b>";
			p 		= "Boleto";
			break;

	}
	
	rotulo = rotulo + " <a href='javascript:void(0);' onClick='f_pgto_trocar();'>[trocar]</a>";
	
	document.getElementById("divCartao").innerHTML=rotulo;
	document.frmPedido.bandeira.value = p;
}

function f_pgto_trocar() {
	document.getElementById("divFP").style.display="block";
	document.getElementById("formPagamentoCartao").style.display="none";
	document.getElementById("formPagamentoBoleto").style.display="none";
	document.getElementById("trProsseguir").style.display="none";
}

function validaFinalPedido() {
	if (!document.frmPedido.chkTermosUso.checked) {
		alert("É necessário aceitar os termos de uso para concluir seu pedido.");
		document.getElementById("termosUso").innerHTML="<b>Li e aceito os termos de uso acima</b>";
		document.frmPedido.chkTermosUso.focus();
		return false;
	} else {
		document.frmPedido.btFinalizar.disabled=true;
		document.frmPedido.btFinalizar.value='aguarde ...';
	}
}

function validaCPF(cpf){ // Verifica a validade do CPF informado
	var msg = "CPF válido";
	var sch;
	var nRecebeCPF, nSoma, nresultado1, nresultado2, ns, nx;
	var arrNumero = Array(11);

	nRecebeCPF = cpf;
	ns = "";
	for(nx=0;nx<nRecebeCPF.length;nx++){
		sch = nRecebeCPF.substring(nx,nx+1);
		sch = parseInt(sch);
		sch = new String(sch);
		if(sch != "NaN"){
			ns += sch;
		}
	}

	nRecebeCPF = ns

	tudoIgual = 1; // Verifica se todos os números são iguais
	for (i = 1; i < nRecebeCPF.length; i++) {
		if (nRecebeCPF.substring(i-1, i) != nRecebeCPF.substring(i, i+1)){
			tudoIgual = 0;
		}
	}

	if(nRecebeCPF.length != 11){
		msg = "Quantidade de dígitos inferior a quantidade de dígitos de CPF";
		resultado = false;
	}
	else if(tudoIgual == 1){
		msg = "Todos us números são iguais";
		resultado = false;
	}
	else if(nRecebeCPF == "12345678909"){
		msg = "Número de CPF inexistente";
		resultado = false;
	}
	else{
		arrNumero[0] = nRecebeCPF.substring(0,1);
		arrNumero[1] = nRecebeCPF.substring(1,2);
		arrNumero[2] = nRecebeCPF.substring(2,3);
		arrNumero[3] = nRecebeCPF.substring(3,4);
		arrNumero[4] = nRecebeCPF.substring(4,5);
		arrNumero[5] = nRecebeCPF.substring(5,6);
		arrNumero[6] = nRecebeCPF.substring(6,7);
		arrNumero[7] = nRecebeCPF.substring(7,8);
		arrNumero[8] = nRecebeCPF.substring(8,9);
		arrNumero[9] = nRecebeCPF.substring(9,10);
		arrNumero[10] = nRecebeCPF.substring(10,11);

		nSoma = 10 * arrNumero[0] + 9 * arrNumero[1] + 8 * arrNumero[2] + 7 * arrNumero[3] + 6 * arrNumero[4] + 5 * arrNumero[5] + 4 * arrNumero[6] + 3 * arrNumero[7] + 2 * arrNumero[8]
		nSoma = nSoma-(11*parseInt(nSoma/11));

		if(nSoma == 0 || nSoma == 1){
			nresultado1 = 0;
		}
		else{
			nresultado1 = 11-nSoma;
		}

		if(nresultado1 == arrNumero[9]){
			nSoma = arrNumero[0] * 11 + arrNumero[1] * 10 + arrNumero[2] * 9 + arrNumero[3] * 8 + arrNumero[4] * 7 + arrNumero[5] * 6 + arrNumero[6] * 5 + arrNumero[7] * 4 + arrNumero[8] * 3 + arrNumero[9] * 2
			nSoma = nSoma-(11*parseInt(nSoma/11));
			if(nSoma == 0 || nSoma == 1){
				nresultado2 = 0;
			}
			else{
				nresultado2 = 11 - nSoma;
			}

			if(nresultado2 == arrNumero[10]){
				resultado = true;
			}
			else{
				msg = "CPF inválido";
				resultado = false;
			}
		}
		else{
			msg = "CPF inválido";
			resultado = false;
		}
	}
	//resultado = msg;
	return resultado;
}


function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function f_soNumeros(v){
    return v.replace(/\D/g,"")
}

function float2moeda(num) {
   x = 0;

   if(num<0) {
      num = Math.abs(num);
      x = 1;
   }   if(isNaN(num)) num = "0";
      cents = Math.floor((num*100+0.5)%100);

   num = Math.floor((num*100+0.5)/100).toString();

   if(cents < 10) cents = "0" + cents;
      for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
         num = num.substring(0,num.length-(4*i+3))+'.'
               +num.substring(num.length-(4*i+3));   ret = num + ',' + cents;   if (x == 1) ret = ' - ' + ret;return ret;
}

function moeda2float(moeda){
   moeda = moeda.replace(".","");
   moeda = moeda.replace(",",".");
   return parseFloat(moeda);
}

function roundNumber(rnum) {
   return Math.round(rnum*Math.pow(10,2))/Math.pow(10,2);
}

// ********* ********* ********* ********* *********

var xmlhttp = null;
function cont(pagina,local,form,metodo,valor){
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new XMLHttpRequest();
			}catch(e){
				xmlhttp = false;
			}
		}		
	}
	
	if(xmlhttp){
		var loc = document.getElementById(local);
		xmlhttp.onreadystatechange = function ()
		{
			if(xmlhttp.readyState == 1)
			{
				loc.innerHTML = '<center class="carregando"><p>&nbsp;</p>Carregando...<br><img src="images/ajax-loader.gif" style="margin-top:10px;margin-bottom:50px;"></center>';
			}
			if(xmlhttp.readyState == 4){
				if(xmlhttp.status == 200){
					loc.innerHTML = xmlhttp.responseText;
				}else{
					alert('Problema:'+xmlhttp.statusText);
				}
			}
		}
	
		if(document.getElementsByName(form).length == 0 && metodo == undefined && valor == undefined)
		{
			xmlhttp.open("GET", pagina+".php");
			xmlhttp.setRequestHeader('Content-Type',"text/html; charset=iso-8859-1");
			xmlhttp.setRequestHeader('encoding', 'ISO-8859-1');
			xmlhttp.send(null);
		}
		else
		{				
			var obj=document.getElementsByName(form);
			var valores="";
			var parametro="";
				
			if(metodo == 'GET'){
				metodo = 'GET';
				pagina = pagina+".php"+valor;
				parametro='null';
			}else{
				for(i=0;i<obj[0].length;i++)
				{
					if(obj[0].elements[i].type == 'checkbox' && obj[0].elements[i].checked==true)
					{
						valores+=obj[0].elements[i].name+'='+obj[0].elements[i].value+"&";
					}
					else if(obj[0].elements[i].type != 'checkbox')
					{
						valores+=obj[0].elements[i].name+'='+obj[0].elements[i].value+"&";
					}
				}
				metodo = 'POST';
				pagina = pagina+".php";
				parametro=valores.substr(0,valores.length-1);
			}
			
			xmlhttp.open(metodo, pagina,true);
			xmlhttp.setRequestHeader('Content-Type',"application/x-www-form-urlencoded");
			xmlhttp.setRequestHeader('Content-length',valores.length);
			xmlhttp.send(parametro);
		}
	}
}

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

/*
postForm(nomeFormulario, localRetorno, urlLocation)
Posta um formulario ajax utilizando o metodo POST e retornando o valor em um id especifico (objeto do browser)
	nomeFormulario 	-> objeto do formulario cujo os elementos devem ser submetidos
	localRetorno 	-> objeto onde deve ser colocado o resultado do retorno do formulario
	urlLocation 	-> localiza?o do script que ira processar as informa?es e retornar o resultado
*/
function postForm(formulario, localRetorno, urlLocation) {

    var query = '';
    for( i=0; i < formulario.length; i++ )
    {
    	campo=formulario.elements[i].name;
    	valor=escape(formulario.elements[i].value);
        query = query + campo +'='+ valor +'&';
    }
	
	//urlLocation = antiCacheRand(urlLocation);
	
    var req = getXmlHttp();
	
	try {
		localRetorno.innerHTML = '<center class="carregando"><p>&nbsp;</p>Carregando...<br><img src="images/ajax-loader.gif" style="margin-top:10px;margin-bottom:50px;"></center>';
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.status == 200) {
					localRetorno.innerHTML = req.responseText;
				} else {
					localRetorno.innerHTML = "Ajax: Error code " + req.status;
				}
				
			} 
		}
		
	
		req.open( 'POST', ( urlLocation ), true );
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
		req.setRequestHeader("Content-Language", "pt-br" );
		req.setRequestHeader("Content-Length", query.length );
		req.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		req.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		req.setRequestHeader("Pragma", "no-cache");
		req.send( query );
		return(true);
	} catch(err) {
		localRetorno.innerHTML = "<p><font color='red'>Erro Ajax!</font><br>Error description: " + err.description + "</p>";
		return(false);
	}
}


Base64 = {
        charset: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
        charset_urlsafe: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=',
        
        encode: function(data, urlsafe) {
                var charset = urlsafe ? Base64.charset_urlsafe : Base64.charset;
                
                var i = 0;
                var len = data.length;
                var output = '';
                var c1, c2, c3;
                var e1, e2, e3, e4;
                
                while (i < len) {
                        c1 = data.charCodeAt(i++);
                        c2 = data.charCodeAt(i++);
                        c3 = data.charCodeAt(i++);
                        
                        e1 = c1 >> 2;
                        e2 = ((c1 & 0x3) << 4) | (c2 >> 4);
                        e3 = ((c2 & 0xf) << 2) | (c3 >> 6);
                        e4 = c3 & 0x3f;
                        
                        if (isNaN(c2)) {
                                e3 = e4 = 64;
                        } else if (isNaN(c3)) {
                                e4 = 64;
                        }
                        
                        output += charset.charAt(e1);
                        output += charset.charAt(e2);
                        output += charset.charAt(e3);
                        output += charset.charAt(e4);
                }
                
                return output;
        },
        
        decode: function(data, urlsafe) {
                var charset = urlsafe ? Base64.charset_urlsafe : Base64.charset;
                
                var i = 0;
                var len = data.length;
                var output = '';
                
                var e1, e2, e3, e4;
                var c1, c2, c3;
                
                while (i < len) {
                        e1 = charset.indexOf(data.charAt(i++));
                        e2 = charset.indexOf(data.charAt(i++));
                        e3 = charset.indexOf(data.charAt(i++));
                        e4 = charset.indexOf(data.charAt(i++));
                        
                        c1 = (e1 << 2) | (e2 >> 4);
                        c2 = ((e2 & 0xf) << 4) | (e3 >> 2);
                        c3 = ((e3 & 0x3) << 6) | e4;
                        
                        output += String.fromCharCode(c1);
                        if (e3 != 64) output += String.fromCharCode(c2);
                        if (e4 != 64) output += String.fromCharCode(c3);
                }
                
                return output;
        }
};

function mostraMenu(menu) {
	try	{
		qtdItemArray = 0;
		vetMenu = new Array(qtdItemArray);
		
		vetMenu[0] = menu;
		
		for (i=0; i<=qtdItemArray; i++) {
			if (vetMenu[i] == menu) {
				if (document.getElementById(vetMenu[i]).style.display == "table-row") {
					document.getElementById(vetMenu[i]).style.display = "none";
				} else {
					document.getElementById(vetMenu[i]).style.display = "table-row";
				}
			} else {
				document.getElementById(vetMenu[i]).style.display = "none";	
			}
		}
	} catch (e) {}
}


function validaHD() {
	if (document.formHD.id.value == "") {
		if (trim(document.formHD.assunto.value) == "") {
			alert("Informe o assunto.");
			document.formHD.assunto.focus();
			return false;
		}
	}
	
	if (trim(document.formHD.mensagem.value) == "") {
		alert("Informe sua mensagem.");
		document.formHD.mensagem.focus();
		return false;
	}
}
