function contaBanner(idd){

	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}
	
	url = "ajax_contador.asp?idd="+idd;
	http.open("GET", url, true);
	http.onreadystatechange=function() {
		if(http.readyState == 4) {
//			if(http.responseText == "ok"){
					window.location = "http://www.twitter.com/sitequerocomer";
//				redir_();
//				document.form1.action = "http://www.twitter.com/sitequerocomer";
//				document.form1.method = "post";
//				document.form1.target = "_blank";
//				document.form1.submit();
//			}
		}
	}
	http.send(null);
}

function redir_(){
					document.location = "http://www.twitter.com/sitequerocomer";
}

// Mensagens de erro

err_1 = "Informe ao menos 3 caracteres para a busca.";
err_2 = "Digite um texto para a busca.";
err_3 = "Informe seu e-mail.";
err_4 = "E-mail incorreto!";
err_5 = "Digite sua senha.";
err_6 = "Informe o seu nome.";
err_7 = "Informe pelo menos 1 email.";
err_8 = "Digite uma palavra para a buscar um vídeo.";
err_9 = "Digite uma palavra com pelo menos 3 letras.";

err_10 = "Informe seu e-mail.";
err_11 = "Digite uma senha.";
err_12 = "Confirme sua senha.";
err_13 = "Confirmação de senha diferente da senha digitada.";
err_14 = "Informe o dia do seu aniversário.";
err_15 = "Informe o mês do seu aniversário.";
err_16 = "Informe o ano do seu nascimento com 4 dígitos.";
err_17 = "Dia de aniversário inválido.";
err_18 = "Dia de aniversário inválido para o ano informado.";
err_19 = "Dia de aniversário inválido para o mês informado.";
err_20 = "Informe o sexo.";
err_21 = "Informe a cidade onde você mora.";
err_22 = "Selecione a sua cidade.";
err_23 = "Informe o bairro que você mora.";
err_24 = "CEP incompleto. Informe no formato XXXXX-XXX.";
err_25 = "Informe seu endereço completo.";
err_26 = "Informe o DDD para o telefone informado.";
err_27 = "DDD incompleto.";
err_28 = "Informe o CEP do seu endereço.";
err_29 = "O e-mail informado já está cadastrado.";
err_30 = "Informe pelo menos 1 telefone de contato.";
err_31 = "Telefone 1 incompleto.";
err_32 = "Selecione a área ou assunto da sua mensagem.";
err_33 = "Digite a sua mensagem.";
err_34 = "Informe um telefone contato, fixo ou celular.";
err_35 = "Informe o código DDD da sua cidade.";
err_36 = "Número de telefone incompleto. Informe o número com 8 dígitos.";
err_37 = "E-mail não cadastrado!";
err_38 = "Digite a resposta da promoção."
err_39 = "Preencha os campos Endereço, Bairro e Telefone."
err_40 = "Digite uma palavra para a buscar um livro.";
err_41 = "O e-mail informado já consta em nosso banco de dados."


// Mensagens de aviso

avi_1 = "Indicação enviada com sucesso!";
avi_2 = "Pressione Ctrl+D no seu teclado.";
avi_3 = "E-mail cadastrado com sucesso!";


// ativa somente teclas numéricas

function tNum(tId,oCamp){
	
	if(tId == 91 || tId >= 33 && tId <= 34 || tId >= 144 && tId <= 145 || tId >= 113 && tId <= 114 || tId == 9 || tId == 13 || tId == 27 || tId >= 16 && tId <= 20 || tId >= 96 && tId <= 105 || tId == 8 || tId >= 35 && tId <= 39 || tId >= 45 && tId <= 46 || tId >= 48 && tId <= 57){
		return true;
	}else{
		document.form1[oCamp].value = document.form1[oCamp].value.substring(0,document.form1[oCamp].value.length-1);
		return false;
	}
	
}


// verificador de email

function checkMail(email) {

    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!%/:,;ç";

    if (email == "") {
        return false;
    }

    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
            return false;
        }
    }
	
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
        return false;
    }
	
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
        return false;
    }
	
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
            return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }

    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;
}


// Caixa de alerta erro

var buscatimer;
function msgErro(erId){
	clearTimeout(buscatimer);
	alert(eval('err_'+erId));
//	if(erId != "fecha"){
//		document.getElementById("msgBoxText").innerHTML = eval('err_'+erId);
//		document.getElementById("msgBox1").style.visibility = "visible";
//		buscatimer = setTimeout("msgErro('fecha')",10000);
//	} else{
//		document.getElementById("msgBox1").style.visibility = "hidden";
//	}

//	document.getElementById("msgBox1").style.top = ((screen.availHeight/2)-168)+document.documentElement.scrollTop+"px";
}

// Caixa de alerta aviso

function msgAviso(avId){

	if(avId != "fecha"){
		document.getElementById("msgBoxText2").innerHTML = eval('avi_'+avId);
		document.getElementById("msgBox2").style.visibility = "visible";
		buscatimer = setTimeout("msgAviso('fecha')",10000);
	} else{
		clearTimeout(buscatimer);
		document.getElementById("msgBox2").style.visibility = "hidden";
	}

	document.getElementById("msgBox2").style.top = eval(document.documentElement.scrollTop+240)+"px";
}

// BUSCA LIVROS

function buscarLivro(){
	var liberado = true;

	if(document.form1.buscaLiv.value.length == 0 && liberado){
		msgErro('40');
		document.form1.buscaLiv.focus();
		liberado = false;
	}

	if(document.form1.buscaLiv.value.length < 3 && liberado){
		msgErro('9');
		document.form1.buscaLiv.focus();
		liberado = false;
	}

	if (liberado){
		document.form1.action = 'busca.asp';
		document.form1.submit();
	}
}


// BUSCA VÍDEOS

function buscarVideo(){
	var liberado = true;

	if(document.form1.buscaVid.value.length == 0 && liberado){
		msgErro('8');
		document.form1.buscaVid.focus();
		liberado = false;
	}

	if(document.form1.buscaVid.value.length < 3 && liberado){
		msgErro('9');
		document.form1.buscaVid.focus();
		liberado = false;
	}

	if (liberado){
		document.form1.action = 'busca.asp';
		document.form1.submit();
	}
}


// BUSCA

function submete(teclapres){  
	if (teclapres.keyCode == 13){
		var liberado = true

		if(document.form1.buscaInicial.value.length == 0 && liberado){
			msgErro('2');
			document.form1.buscaInicial.focus();
			liberado = false;
		}
		if(document.form1.buscaInicial.value.length < 3 && liberado){
			msgErro('1');
			document.form1.buscaInicial.focus();
			liberado = false;
		}

		if (liberado){
			buscar();
		}
	}
}

function buscar(){
	var liberado = true;

	if(document.form1.buscaInicial.value.length == 0 && liberado){
		msgErro('2');
		document.form1.buscaInicial.focus();
		liberado = false;
	}

	if(document.form1.buscaInicial.value.length < 3 && liberado){
		msgErro('1');
		document.form1.buscaInicial.focus();
		liberado = false;
	}

	if (liberado){
		document.form1.action = 'busca.asp';
		document.form1.submit();
	}
}


function abrirUrl(setor,f){

	curl = f.options[f.selectedIndex].value;

	if (curl != ""){
		if(setor != "outras"){
			document.form1.action = curl;
		} else {
			document.form1.action = "busca2.asp?" + curl;
		}
		document.form1.submit();
	}
}

function acesso_restrito(){
	
	var liberado = true;

	if(document.form1.rest_email.value.length < 1 && liberado){
		msgErro('3');
		document.form1.rest_email.focus();
		liberado = false;
	}

	if(!checkMail(document.form1.rest_email.value) && liberado){
		msgErro('4');
		document.form1.rest_email.focus();
		liberado = false;
	}

	if(document.form1.rest_senha.value.length < 1 && liberado){
		msgErro('5');
		document.form1.rest_senha.focus();
		liberado = false;
	}

	if(liberado){
		alert("ok");
	}

}

// Tamanho do texto

tamTxt_1 = "1";
tamTxt_2 = "1.1";
tamTxt_3 = "1.2";
tamTxt_4 = "1.3";
tamTxt_5 = "1.4";

txtAtual = 1

function zTxt(tam,area){
	if(tam == "menor"){
		txtAtual-=1;
		if (txtAtual == 0) { txtAtual = 1; }
	} else {
		txtAtual+=1;
		if (txtAtual == 6) { txtAtual = 5; }
	}
		document.getElementById(area).style.fontSize = eval('tamTxt_'+txtAtual)+"em";
	
}

// esconder forms
function escondeForms(escId){
	finput = document.getElementsByTagName("input");
	fselect = document.getElementsByTagName("select");
	for(i=0;i<finput.length;i++){
		finput.item(i).style.visibility = escId;
	}
	for(i=0;i<fselect.length;i++){
		fselect.item(i).style.visibility = escId;
	}
	return;
}


// Indicar o Querocomer

function fechaIndica(mostra){

	document.getElementById("bMask").style.height = document.getElementById("topo").offsetHeight+document.getElementById("geral").offsetHeight+document.getElementById("rodape").offsetHeight+20+"px";
	document.getElementById("indicarForm").style.top = (screen.availHeight/2)-250+document.documentElement.scrollTop+"px";
	document.getElementById("bMask").style.visibility = mostra;
	document.getElementById("indicarForm").style.visibility = mostra;
	document.getElementById("indicarMsgs").innerHTML = "";
}

function indicarQC(){

	ilib = true;
	
	if(document.form1.iqc_nome.value.length < 2 && ilib){
		document.getElementById("indicarMsgs").innerHTML = "** Informe o seu nome **";
		document.form1.iqc_nome.focus();
		ilib = false;
	}

	if(document.form1.iqc_email.value.length < 1 && ilib){
		document.getElementById("indicarMsgs").innerHTML = "** Informe o seu e-mail **";
		document.form1.iqc_email.focus();
		ilib = false;
	}

	if(!checkMail(document.form1.iqc_email.value) && ilib){
		document.getElementById("indicarMsgs").innerHTML = "** E-mail incorreto. **";
		document.form1.iqc_email.focus();
		ilib = false;
	}

	if(document.form1.iqc_emails.value.length < 1 && ilib){
		document.getElementById("indicarMsgs").innerHTML = "** Informe pelo menos 1 e-mail de um amigo **";
		document.form1.iqc_emails.focus();
		ilib = false;
	}

	if(ilib){
		document.getElementById("indicarMsgs").innerHTML = "<b style='color: #666'>Enviando...</b>";
		var http = false;

		if(navigator.appName == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}

		url = "ajax_indicar.asp";
		url = url + "?nome="+document.form1.iqc_nome.value;
		url = url + "&email="+document.form1.iqc_email.value;
		url = url + "&emails="+document.form1.iqc_emails.value;
		url = url + "&acao=Enviar";

		http.open("GET", url, true);
		http.onreadystatechange=function(){
			if(http.readyState == 4) {
			document.getElementById("indicarMsgs").innerHTML = "<b style='color:#FF9904'>Indicação enviada com sucesso! Obrigado por indicar o Querocomer.</b>";
			document.form1.iqc_nome.value = "";
			document.form1.iqc_email.value = "";
			document.form1.iqc_emails.value = "";
			}
		}
		http.send(null);
	}

}

// IMPRIMIR CUPOM
function fechaImpCup(mostra,cod_desconto,cod_estabelecimento,cod_cup){
	document.getElementById("btimpNew").style.visibility = "hidden";
	document.getElementById("bMask").style.height = document.getElementById("topo").offsetHeight+document.getElementById("geral").offsetHeight+document.getElementById("rodape").offsetHeight+20+"px";
	document.getElementById("impcupForm").style.top = (screen.availHeight/2)-250+document.documentElement.scrollTop+"px";
	document.getElementById("cupCadForm").style.top = (screen.availHeight/2)-250+document.documentElement.scrollTop+"px";
	document.getElementById("bMask").style.visibility = mostra;
	document.getElementById("impcupForm").style.visibility = mostra;
	document.getElementById("impcMsgsCad").innerHTML = "";
	document.getElementById("impcMsgs").innerHTML = "";

	document.form1.cupcad_nome.value="";
	document.form1.cupcad_email.value="";
	document.form1.cupcad_ddd.value="";
	document.form1.cupcad_tel.value="";

if(cod_desconto == "fecha1"){
		document.getElementById("cupCadForm").style.visibility = mostra;
	}else{
		cdd = "document.form1.cod_descontocup"+cod_desconto;
		cde = "document.form1.cod_estabelecimentocup"+cod_desconto;
		eval(cdd).value = cod_desconto;
		eval(cde).value = cod_estabelecimento;
	}

	if(mostra == "hidden"){
		document.getElementById("cadsuces").style.visibility = mostra;
		document.getElementById("cupCadForm").style.visibility = mostra;
	}else{
		document.getElementById("cupNomeRest").innerHTML = document.getElementById("nomerest"+cod_cup).innerHTML;
		document.form1.impc_email.focus();
	}
}

function valImpCup(cod_desconto,cod_estabelecimento){

	iclib = true;
	
	if(document.form1.impc_email.value.length < 1 && iclib){
		document.getElementById("impcMsgs").innerHTML = "** Informe o seu e-mail **";
		document.form1.impc_email.focus();
		iclib = false;
	}

	if(!checkMail(document.form1.impc_email.value) && iclib){
		document.getElementById("impcMsgs").innerHTML = "** E-mail incorreto **";
		document.form1.impc_email.focus();
		iclib = false;
	}

	if(iclib){
		document.getElementById("impcMsgs").innerHTML = "<b style='color: #666'>Por favor, aguarde...</b>";
		var http = false;

		if(navigator.appName == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}

		cdd2 = "document.form1.cod_descontocup"+eval(cdd).value+".value";
		cde2 = "document.form1.cod_estabelecimentocup"+eval(cdd).value+".value";

		url = "ajax_mopuc.asp";
		url = url + "?cod_desconto="+eval(cdd2);
		url = url + "&cod_estabelecimento="+eval(cde2);
		url = url + "&email="+document.form1.impc_email.value;

		http.open("GET", url, true);
		http.onreadystatechange=function(){
			if(http.readyState == 4) {
				document.getElementById("impcMsgs").innerHTML = "";
				if(http.responseText == 0){
					document.getElementById("impcMsgs").innerHTML = "";
					document.getElementById("impcupForm").style.visibility = "hidden";
					document.getElementById("cupCadForm").style.visibility = "visible";
					document.form1.cupcad_nome.focus();
					document.form1.cupcad_email.value = document.form1.impc_email.value;
				}else{
	//					document.getElementById("impcupForm").style.visibility = "hidden";
//					document.getElementById("bMask").style.visibility = "hidden";
					document.getElementById("btimpNew").innerHTML = http.responseText;
					document.getElementById("btimpNew").style.visibility = "visible";
				}
			}
		}
		http.send(null);
	}

}

function fCadCup(){
	
	document.getElementById("cupCadForm").style.visibility = "hidden";
	document.getElementById("cadsuces").style.visibility = "hidden";
	document.getElementById("impcupForm").style.visibility = "visible";

	document.form1.impc_email.value = document.form1.cupcad_email.value;

	document.form1.cupcad_nome.value = "";
	document.form1.cupcad_ddd.value = "";
	document.form1.cupcad_tel.value = "";
	valImpCup();
}

function valrcad(){

rcadlib = true;

	if(document.form1.cupcad_nome.value.length < 2 && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** informe seu nome **";
		document.form1.cupcad_nome.focus();
		document.form1.cupcad_nome.select();
		rcadlib = false;
	}

	if(document.form1.cupcad_email.value.length < 1 && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** informe seu e-mail **";
		document.form1.cupcad_email.focus();
		rcadlib = false;
	}

	if(!checkMail(document.form1.cupcad_email.value) && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** E-mail incorreto **";
		document.form1.cupcad_email.focus();
		document.form1.cupcad_email.select();
		rcadlib = false;
	}

	if(document.form1.cupcad_ddd.value.length < 2 && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** informe o DDD com 2 dígitos **";
		document.form1.cupcad_ddd.focus();
		document.form1.cupcad_ddd.select();
		rcadlib = false;
	}

	if(document.form1.cupcad_tel.value.length < 1 && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** informe o seu telefone **";
		document.form1.cupcad_tel.focus();
		rcadlib = false;
	}

	if(rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "<b style='color: #666'>Por favor, aguarde...</b>";
		var http = false;

		if(navigator.appName == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}

		url = "ajax_cadrapido.asp";
		url = url + "?cupcad_nome="+document.form1.cupcad_nome.value;
		url = url + "&cupcad_email="+document.form1.cupcad_email.value;
		url = url + "&cupcad_ddd="+document.form1.cupcad_ddd.value;
		url = url + "&cupcad_tel="+document.form1.cupcad_tel.value;

		http.open("GET", url, true);
		http.onreadystatechange=function(){
			if(http.readyState == 4) {
				if(http.responseText == "err"){
					document.getElementById("impcMsgsCad").innerHTML = "** O e-mail informado já está cadastrado **";
					document.form1.cupcad_email.focus();
					document.form1.cupcad_email.select();
				}else{
//					document.getElementById("cadsuces").style.visibility = "visible";
					document.getElementById("impcMsgsCad").innerHTML = "";
					fCadCup();
				}
			}
		}
		http.send(null);
	}

}


function valrcad2(){
rcadlib = true;

	if(document.form1.cupcad_nome.value.length < 2 && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** informe seu nome **";
		document.form1.cupcad_nome.focus();
		document.form1.cupcad_nome.select();
		rcadlib = false;
	}

	if(document.form1.cupcad_email.value.length < 1 && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** informe seu e-mail **";
		document.form1.cupcad_email.focus();
		rcadlib = false;
	}

	if(!checkMail(document.form1.cupcad_email.value) && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** E-mail incorreto **";
		document.form1.cupcad_email.focus();
		document.form1.cupcad_email.select();
		rcadlib = false;
	}

	if(document.form1.cupcad_ddd.value.length < 2 && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** informe o DDD com 2 dígitos **";
		document.form1.cupcad_ddd.focus();
		document.form1.cupcad_ddd.select();
		rcadlib = false;
	}

	if(document.form1.cupcad_tel.value.length < 1 && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** informe o seu telefone **";
		document.form1.cupcad_tel.focus();
		rcadlib = false;
	}

	if(document.form1.cupcad_bairro.value.length < 1 && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** informe o seu bairro **";
		document.form1.cupcad_bairro.focus();
		rcadlib = false;
	}

	trabs = false;

	for(i=0;i<document.form1.kuat_resp.length;i++){
		if(document.form1.kuat_resp[i].checked){
			trabs = true;
			radiovalue = form1.kuat_resp[i].value;
		}
	}

	if(!trabs && rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "** Por favor, marque SIM ou NÃO **";
		rcadlib = false;
	}


	if(rcadlib){
		document.getElementById("impcMsgsCad").innerHTML = "<b style='color: #666'>Por favor, aguarde...</b>";
		var http = false;

		if(navigator.appName == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}

		url = "ajax_cadrapido.asp";
		url = url + "?cupcad_nome="+document.form1.cupcad_nome.value;
		url = url + "&cupcad_email="+document.form1.cupcad_email.value;
		url = url + "&cupcad_ddd="+document.form1.cupcad_ddd.value;
		url = url + "&cupcad_tel="+document.form1.cupcad_tel.value;
		url = url + "&cupcad_bairro="+document.form1.cupcad_bairro.value;
		url = url + "&cupcad_kuat_resp="+radiovalue;

		http.open("GET", url, true);
		http.onreadystatechange=function(){
			if(http.readyState == 4) {
				if(http.responseText == "err"){
					document.getElementById("impcMsgsCad").innerHTML = "** O e-mail informado já está cadastrado **";
					document.form1.cupcad_email.focus();
					document.form1.cupcad_email.select();
				}else{
//					document.getElementById("cadsuces").style.visibility = "visible";
					document.getElementById("impcMsgsCad").innerHTML = "";
					fCadCup();
				}
			}
		}
		http.send(null);
	}

}


function abreCadrapido(){
	document.getElementById("impcMsgs").innerHTML = "";
	document.getElementById("impcupForm").style.visibility = "hidden";
	document.getElementById("cupCadForm").style.visibility = "visible";

	document.form1.cupcad_nome.focus();
}

function cupcadDDD(ddd_){

	if(ddd_.length == 2){ document.form1.cupcad_tel.focus(); }

}

function mailCad(){
	mcadlib = true;
	if(document.form1.seu_email.value == "Digite seu e-mail" || document.form1.seu_email.value.length < 1 && mcadlib){
		msgErro('3');
		mcadlib = false;
	}

	if(!checkMail(document.form1.seu_email.value) && mcadlib){
		msgErro('4');
		mcadlib = false;
	}

	if(mcadlib){
		var http = false;

		if(navigator.appName == "Microsoft Internet Explorer") {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			http = new XMLHttpRequest();
		}

		url = "ajax_cadrapido.asp?cupcad_nome=nc&cupcad_email="+document.form1.seu_email.value;


		http.open("GET", url, true);
		http.onreadystatechange=function(){
			if(http.readyState == 4) {
				alert(http.responseText)
			}
		}
		http.send(null);
	}
}

function fechaMsgBox(boxId){
	document.getElementById('msgBox'+boxId).style.visibility = "hidden";
}

// ADICIONAR FAVORITOS
function add_bookmark(){
	if(navigator.appName == "Microsoft Internet Explorer"){
		window.external.AddFavorite("http://www.querocomer.com.br", "Site Querocomer");
	}else{
		msgAviso('2');
	}
}
