﻿/**
 * @author Administrador
 */
//verifica formulario
if (navigator.appName.indexOf('Microsoft') != -1) {
    clientNavigator = "IE";
}
else {
    clientNavigator = "Other";
}

function validar_campos(stermo){
    var m = ''
    var t = 0
	var qq = true;
    //	var frmForm = document.forms[0];
    var frmForm = document.forms['frmcadastro'];
    
    if (frmForm.nomecompleto.value == '') {
        m += '-> Preencha seu nome completo por favor.\t\n';
        t = 1
    }
    if (frmForm.nomeusuario.value == '') {
        m += '-> Preencha seu nome de usuário por favor.\t\n';
        t = 1
    }
    if (frmForm.sexo.value == '0') {
        m += '-> Preencha seu sexo por favor.\t\n';
        t = 1
    }
//    if (frmForm.datanascimento.value == '') {
  //      m += '-> Preencha sua data de nascimento por favor.\t\n';
    //    t = 1
//    }
  //  if (frmForm.ddd1.value == '') {
    //    m += '-> Preencha o número do DDD por favor.\t\n';
//        t = 1
  //  }
//    if (frmForm.telefone.value == '') {
  //      m += '-> Preencha seu telefone por favor.\t\n';
//        t = 1
//    }
    if (frmForm.email.value == '') {
        m += '-> Preencha seu e-mail por favor.\t\n';
        t = 1
    }
    if (frmForm.repeteemail.value == '') {
        m += '-> Preencha a confirmação do seu e-mail por favor.\t\n';
        t = 1
    }
    if (frmForm.senha.value == '') {
        m += '-> Preencha a sua senha por favor.\t\n';
        t = 1
    }
    if (frmForm.repetesenha.value == '') {
        m += '-> Preencha a confirmação de senha por favor.\t\n';
        t = 1
    }
	if (frmForm.senha.value != frmForm.repetesenha.value  ) {
        m += '-> Campo senha e confirmação de senha não conferem.\t\n';
        t = 1
    }
    if (frmForm.enderecocompleto.value == '') {
        m += '-> Preencha o seu endereço completo por favor.\t\n';
        t = 1
    }
    if (frmForm.numero.value == '') {
        m += '-> Preencha o número do seu endereço por favor.\t\n';
        t = 1
    }
    if (frmForm.bairro.value == '') {
        m += '-> Preencha seu bairro por favor.\t\n';
        t = 1
    }
    if (frmForm.cidade.value == '') {
        m += '-> Preencha a sua cidade por favor.\t\n';
        t = 1
    }

    if (frmForm.estado.value == '23') {
		if (frmForm.estado.value == '0') {
			m += '-> Preencha seu estado por favor.\t\n';
			t = 1
		}
	}
    if (frmForm.quest1.value == '0') {
        m += '-> Você esqueceu de responder a pergunta do questionário.\t\n';
        t = 1
    }
    if (frmForm.quest2.value == '0') {
        m += '-> Você esqueceu de responder a pergunta do questionário.\t\n';
        t = 1
    }
    if (frmForm.codigo.value == '') {
        m += '-> Preencha o código de validação.\t\n';
        t = 1
    }
    if (t == 1) {
        alert('Campos Inválidos.\n\n' + m);
        return false
    }
    if (frmForm.senha.value.length < 5) {
        alert('Sua senha tem menos que 5 caracteres.');
        return false
    }
    if (frmForm.senha.value != frmForm.repetesenha.value) {
        alert('Senha e Repetição de Senha não coincidem.');
        return false
    }
    if (frmForm.email.value != frmForm.repeteemail.value) {
        alert('E-mail e Repetição de E-mail não coincidem.');
        return false
    }
    
    /* validando check box
   var elements = document.forms['frmcadastro'].elements;
    var count = 0;
    var c = 0;
    
    for (x = 0; x < elements.length; x++) {
      if (elements[x].type == 'checkbox') {
        if (elements[x].checked == true) {
                c++;
            }
        }
    }
    if (document.forms['frmcadastro'].newsletter.checked == true) {
        c--;
    }
    if (c < 5) {
	    alert('Marque no mínimo 5 opções...');
        setaImagemNo('imgCheckProgramas');
	    return false;
		qq = false; 
    }
    else {
        setaImagemOk('imgCheckProgramas');
    }
    */
    // validando captha
    var codx = document.forms['frmcadastro'].codigo.value;
    if (codx.toLowerCase() == rdm.toLowerCase()) {
		if (qq == false ){
			return false;
	//	} else {
	//        return true;	
		}
    }
    else {
        alert('O código de verificação não confere !');
        atualizaCaptcha();
        return false;
    }
	if (stermo == '1') {
		var termo = document.getElementById("chkTermoResponsabilidade").checked;
		if (termo == false) {
			m += '-> Você deve confirmar o termo de responsabilidade !!!\n';
			alert('Termo de Responsabilidade\n\n' + m);
			return false
		}
	}
	
}

// verifica se o nome esta completo
function vNomeCompleto(){
    var snome = document.forms['frmcadastro'].nomecompleto;
    if (snome.value == "" || snome.value.length < 8) {
        snome.focus();
        //alert('Digite o nome completo!');
        setaImagemNo('imgNomeCompleto');
        return false;
    }
    else {
        setaImagemOk('imgNomeCompleto');
        return true;
    }
}

// insere imagem "ok" na div
function setaImagemOk(id){
    document.getElementById(id).innerHTML = '<img src="imagem/ok.gif">';
}

// insere imagem "no" na div
function setaImagemNo(id){
    document.getElementById(id).innerHTML = '<img src="imagem/no.gif">';
}

// remove os espaços em branco
function removeEspaco(obj){
    var espaco = /\s/g;
    obj.value = obj.value.replace(espaco, "");
    vNomeUsuario();
    
}

// verifica se já existe o nome de usuário
function vNomeUsuario(){
    var ajaxObj;
    var nomeusuario = document.forms['frmcadastro'].nomeusuario;
    
    try {
        // Firefox, Opera 8.0+, Safari...
        ajaxObj = new XMLHttpRequest();
    } 
    catch (e) {
        // Internet Explorer
        try {
            ajaxObj = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            try {
                ajaxObj = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {
                alert("Seu navegador n�o possui suporte ao AJAX!");
                return false;
            }
        }
    }
    ajaxObj.onreadystatechange = function(){
        if (ajaxObj.readyState == 4) {
        
            if (ajaxObj.responseText == 1) {
                setaImagemNo('imgNomeUsuario');
                alert('Este nome de usuário já existe, por favor escolha outro nome de usuário !');
            }
            else 
                if (ajaxObj.responseText == 0) {
                    setaImagemOk('imgNomeUsuario');
                }
        }
    }
    ajaxObj.open("GET", "tvi_cadastro_verifica_nome_usuario.asp?nomeusuario=" + nomeusuario.value, true);
    ajaxObj.send(null);
}

// validando o campo sexo
function validar_sexo(){
    var s = document.forms['frmcadastro'].sexo.value;
    if (s == '0') {
        setaImagemNo("imgSexo");
    }
    else {
        setaImagemOk("imgSexo");
    }
}

// validando a data de nascimento


function validar_data(){
	a = document.forms['frmcadastro'].datanascimento.value;
	b = "";
	a = a.split("/");
	dia = a[0];
	mes = a[1];
	ano = a[2];
	situacao = "";
	// verifica o dia valido para cada mes 
	if ((dia < 01) || (dia < 01 || dia > 30) && (mes == 04 || mes == 06 || mes == 09 || mes == 11) || dia > 31) {
		situacao = "falsa";
	}
	// verifica se o mes e valido 
	if (mes < 01 || mes > 12) {
		situacao = "falsa";
	}
	// verifica se e ano bissexto 
	if (mes == 2 && (dia < 01 || dia > 29 || (dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
		situacao = "falsa";
	}
	//      if (document.forms[0].data.value == "") { 
	//           situacao = "falsa"; 
	//     } 
	if (document.forms['frmcadastro'].datanascimento.value != "") {
		if (situacao == "falsa") {
			setaImagemNo("imgDataNascimento");
			//document.forms['frmcadastro'].datanascimento.focus();
		}
		else {
			setaImagemOk("imgDataNascimento");
		}
	}
	
	if (document.forms['frmcadastro'].datanascimento.value == ""){
		setaImagemBranco("imgDataNascimento");
	}

}

// bloqueando os caracteres
function Bloq_Caracteres(input, evnt){
    //só permite digitação de números   
    if (input.value.length == 5) {
        if (clientNavigator == "IE") {
            input.value += "-";
        }
        else {
            if (evnt.keyCode == 0) {
                input.value += "-";
            }
        }
    }
    //Chama a função Bloqueia_Caracteres para só permitir a digitação de números   
    return Bloqueia_Caracteres(evnt);
}

function Bloqueia_Caracteres(evnt){
    //Função permite digitação de números   
    if (clientNavigator == "IE") {
        if (evnt.keyCode < 48 || evnt.keyCode > 57) {
            return false
        }
    }
    else {
        if ((evnt.charCode < 48 || evnt.charCode > 57) && evnt.keyCode == 0) {
            return false
        }
    }
}

// validando tel residencial
function vTelResidencial(){
    var d = document.forms['frmcadastro'].ddd1.value;
    var t = document.forms['frmcadastro'].telefone.value;
    
	  if (d != "" || t != "") {
    
        if (d == '' || t == '') {
            setaImagemNo('imgTelefoneResi');
        }
        else 
            if (d.length < 2 || t.length < 8) {
                setaImagemNo('imgTelefoneResi');
            }
            else {
                setaImagemOk('imgTelefoneResi');
            }
    }
    else {
        setaImagemBranco('imgTelefoneResi');
    }
	
}

// validando tel comercial
function vTelComercial(){
    var d = document.forms['frmcadastro'].ddd2.value;
    var t = document.forms['frmcadastro'].telefonecomercial.value;
    
    if (d != "" || t != "") {
    
        if (d == '' || t == '') {
            setaImagemNo('imgTelefoneCom');
        }
        else 
            if (d.length < 2 || t.length < 8) {
                setaImagemNo('imgTelefoneCom');
            }
            else {
                setaImagemOk('imgTelefoneCom');
            }
    }
    else {
        setaImagemBranco('imgTelefoneCom');
    }
}

//validando o campo celular
function vTelCelular(){
    var d = document.forms['frmcadastro'].ddd3.value;
    var t = document.forms['frmcadastro'].celular.value;
    
    if (d != "" || t != "") {
    
        if (d == '' || t == '') {
            setaImagemNo('imgTelefoneCel');
        }
        else 
            if (d.length < 2 || t.length < 8) {
                setaImagemNo('imgTelefoneCel');
            }
            else {
                setaImagemOk('imgTelefoneCel');
            }
    }
    else {
        setaImagemBranco('imgTelefoneCel');
    }
}

//verifica e-mail
function veremail(semail){
    var bvalido = false;
    var theStr = new String(semail.value);
    var index = theStr.indexOf("@");
    if (index > 0) {
        var pindex = theStr.indexOf(".", index);
        if ((pindex > index + 1) && (theStr.length > pindex + 1)) 
            bvalido = true;
        //'agora vai buscar no db
        vEmailExiste();
    }
    if (!bvalido) {
        alert("Formato de E-Mail Inválido !");
        document.frmcadastro.email.focus();
    }
    return bvalido;
}

function vEmailExiste(){
    var ajaxObj;
    var emailcadastro = document.forms['frmcadastro'].email.value;
    
    imgLoading('imgEmail');
    
    try {
        // Firefox, Opera 8.0+, Safari...
        ajaxObj = new XMLHttpRequest();
    } 
    catch (e) {
        // Internet Explorer
        try {
            ajaxObj = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            try {
                ajaxObj = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {
                alert("Seu navegador n�o possui suporte ao AJAX!");
                return false;
            }
        }
    }
    ajaxObj.onreadystatechange = function(){
        if (ajaxObj.readyState == 4) {
        
            if (ajaxObj.responseText == 1) {
                setaImagemNo('imgEmail');
                alert('Este e-mail já está cadastrado, por favor escolha outro e-mail !');
            }
            else 
                if (ajaxObj.responseText == 0) {
                    setaImagemOk('imgEmail');
                    
                }
        }
    }
    ajaxObj.open("GET", "tvi_cadastro_verifica_email.asp?mail=" + emailcadastro, true);
    ajaxObj.send(null);
}

// mostra o loading
function imgLoading(id){
    document.getElementById(id).innerHTML = '<img src="images/loading.gif">';
}

// remove loading
function removeLoading(id){
    document.getElementById(id).innerHTML = '';
}

// imagem em branco
function setaImagemBranco(id){
    document.getElementById(id).innerHTML = '';
}

// remove imagem
function removeImagemNo(id){
    document.getElementById(id).innerHTML = '';
}

// confirmar o e-mail
function confirmar_email(){
    var m1 = document.forms['frmcadastro'].email.value;
    var m2 = document.forms['frmcadastro'].repeteemail.value;
    
    if (m1 == m2) {
        setaImagemOk("imgEmailRepete");
    }
    else {
        var mail = document.forms['frmcadastro'].repeteemail;
        setaImagemNo("imgEmailRepete");
    }
}

// validando a senha
function validar_senha(){
    var senha = document.forms['frmcadastro'].senha;
    if (senha.value.length < 5) {
        setaImagemNo("imgSenha");
       	document.forms['frmcadastro'].senha.focus();
    }
    else {
        setaImagemOk("imgSenha");
    }
}

// confirmar senha
function confirmar_senha(){
    var s1 = document.forms['frmcadastro'].senha.value;
    var s2 = document.forms['frmcadastro'].repetesenha.value;
    
    if (s1 == s2) {
        setaImagemOk("imgSenhaRepete");
    }
    else {
        var senha = document.forms['frmcadastro'].repetesenha;
 //       senha.focus();
        setaImagemNo("imgSenhaRepete");
    }
    
}

// validando o campo CEP
function validar_cep(){
    var cep = document.forms['frmcadastro'].cep.value;
    //verifica se o browser tem suporte a ajax
    try {
        ajax = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    catch (e) {
        try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (ex) {
            try {
                ajax = new XMLHttpRequest();
            } 
            catch (exc) {
                alert("Esse browser não tem recursos para uso do Ajax");
                ajax = null;
            }
        }
    }
    //se tiver suporte ajax
    if (ajax) {
        CarregandoCEPAguarde();
        imgLoading('imgCEP');
        ajax.open("GET", "tvi_busca_cep.asp?cep=" + cep, true);
        ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        
        ajax.onreadystatechange = function(){
            //enquanto estiver processando...emite a msg de carregando
            if (ajax.readyState == 1) {
                CarregandoCEPAguarde();
            }
            //após ser processado - chama função processXML que vai varrer os dados
            if (ajax.readyState == 4) {
                TrataRetornoCep(ajax.responseText);
            }
        }
    }
    ajax.send(null);
}

// desabilita os campos
function CarregandoCEPAguarde(){
    document.forms['frmcadastro'].enderecocompleto.disabled = true;
    document.forms['frmcadastro'].bairro.disabled = true;
    document.forms['frmcadastro'].cidade.disabled = true;
    document.forms['frmcadastro'].estado.disabled = true;
}

// trata o retorno do cep
function TrataRetornoCep(retorno){
    var r = retorno, i, resultado, resultadotxt, cep, uf, cidade, bairro, tipo_logradouro, logradouro;
    
    resultado = r.substring(0, (i = r.indexOf('&')));
    r = r.substring(++i);
    resultado = r.substring(0, (i = r.indexOf('&')));
    r = r.substring(++i);
    var vResultado = resultado.substr(resultado.indexOf('=') + 1); // pega o valor do retorno
    resultadotxt = r.substring(0, (i = r.indexOf('&')));
    r = r.substring(++i);
    var vResultadoTxt = resultadotxt.substr(resultadotxt.indexOf('=') + 1); // pega o valor do resultadotxt
    uf = r.substring(0, (i = r.indexOf('&')));
    r = r.substring(++i);
    var vUF = uf.substr(uf.indexOf('=') + 1); // pega o valor da UF
    cidade = r.substring(0, (i = r.indexOf('&')));
    r = r.substring(++i);
    var vCidade = cidade.substr(cidade.indexOf('=') + 1); // pega o valor da cidade
    bairro = r.substring(0, (i = r.indexOf('&')));
    r = r.substring(++i);
    var vBairro = bairro.substr(bairro.indexOf('=') + 1); // pega o valor do bairro
    tipologradouro = r.substring(0, (i = r.indexOf('&')));
    r = r.substring(++i);
    var vTipoLogradouro = tipologradouro.substr(tipologradouro.indexOf('=') + 1); // pega o valor do tipologradouro
    logradouro = r.substring(0, r.length);
    var vLogradouro = logradouro.substr(logradouro.indexOf('=') + 1); // pega o valor do logradouro
    if (vResultado == '1') {
        document.forms['frmcadastro'].enderecocompleto.value = unescape(vTipoLogradouro) + ' ' + unescape(replaceAll(vLogradouro, '+', ' '));
        document.forms['frmcadastro'].bairro.value = unescape(replaceAll(vBairro, '+', ' '));
        document.forms['frmcadastro'].cidade.value = unescape(replaceAll(vCidade, '+', ' '));
        var opt = document.forms['frmcadastro'].estado;//.option['2'].selected = true;
        for (i = 0; i < opt.length; i++) {
            if (opt.options[i].getAttribute("value") == vUF) {
                opt.selectedIndex = i;
            }
        }
        removeLoading('imgCEP');
        setaImagemOk('imgCEP')
        CarregandoCEPOk();
		document.forms['frmcadastro'].numero.focus();
    }
    else {
        alert('O número do CEP não foi encontrado, digite manualmente !');
        CarregandoCEPOk();
        LimparCamposCEP();
        removeLoading('imgCEP');
    }
}

// habilitando os campos 
function CarregandoCEPOk(){
    document.forms['frmcadastro'].enderecocompleto.disabled = false;
    document.forms['frmcadastro'].bairro.disabled = false;
    document.forms['frmcadastro'].cidade.disabled = false;
    document.forms['frmcadastro'].estado.disabled = false;
}

// limpa os campos do CEP
function LimparCamposCEP(){
    document.forms['frmcadastro'].enderecocompleto.value = '';
    document.forms['frmcadastro'].bairro.value = '';
    document.forms['frmcadastro'].cidade.value = '';
}

//acrescenta barra na data dd/mm/yyyy
function barradata(objeto){
    if (objeto.value.length == 2 || objeto.value.length == 5) {
        objeto.value = objeto.value + "/";
    }
}

function focusOn(current, next){
    if (current.value.length >= current.maxLength) {
        element = document.getElementsByName(next)[0];
        element.focus();
    }
}

// atualizando captcha
function atualizaCaptcha(){
    var captcha = document.getElementById("capthacode");
    captcha.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="130" height="25" title="Valida Form">' +
    '<param name="movie" value="validaform.swf" />' +
    '<param name="quality" value="high" />' +
    '<embed src="validaform.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="130" height="25"></embed>' +
    '</object>';
    
}

function validar_quest_a(){
    var quest = document.forms['frmcadastro'].quest1.value;
    if (quest == '0') {
        setaImagemNo("imgQuest1");
    }
    else {
        setaImagemOk("imgQuest1");
    }
}

function validar_quest_b(){
    var quest = document.forms['frmcadastro'].quest2.value;
    if (quest == '0') {
        setaImagemNo("imgQuest2");
    }
    else {
        setaImagemOk("imgQuest2");
    }
}

// só deixa escolher uma opção de checkbox
function ckcheck(id){
  var total = 0;
  var minhaDiv = document.getElementById("enquete");  
  var listaMarcados = minhaDiv.getElementsByTagName("INPUT");   
  for (loop = 0; loop < listaMarcados.length; loop++) {   
     var item = listaMarcados[loop];   
     if (item.type == "checkbox" && item.checked) {
	 	total = total + 1;
	 }
	 if (total > 1 ){
	 	item.checked =false;
		alert('Você só pode escolher 1 opção !!!');
		return false;
	 } 
  }  
}

// validando a enquete
function validarEnquete() { 

  var resultado = false;
  var valor = "";
  var minhaDiv = document.getElementById("enquete");    
  var listaMarcados = minhaDiv.getElementsByTagName("INPUT");   
  for (loop = 0; loop < listaMarcados.length; loop++) {   
     var item = listaMarcados[loop];   
     if (item.type == "checkbox" && item.checked) {   
		resultado = true;
		valor = item.value;
     }   
  }   
  if (resultado == false) {
  		alert('Escolha pelo menos uma opção !!!');
  		return false;
  } else {
		if (valor != ""){
			votar_enquete(valor);
		}
  }
}  
// chama a função loadVoto 
function votar_enquete(valor)
{
    loadVoto("voto_enquete.asp",valor);
}

// envia os dados 
function loadVoto(url,valor)
{
    req = null;

    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url+'?voto='+valor, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url+'?voto='+valor, true);
            req.send();
        }
    }
}
// verifica o status 
function processReqChange()
{
    //document.getElementById('atualiza').innerHTML = '<select name=tipo style=\"WIDTH: 140px; vertical-align:middle; background-color:#FBF5EC;\" class=\"fonte9\"><option>Carregando...</option></select>';
    if (req.readyState == 4) {
        if (req.status == 200) {
            document.getElementById('enquete').innerHTML = req.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + req.statusText);
        }
    }
}


function validaMsgAovivo(){
	var m = ''
	var t = 0
	var txt = document.getElementById("txtMsgAoVivo").value;
	if (txt=='') { m += '-> Digite a mensagem a ser enviada !!!\n';t=1 }
		if (t==1) { 
			alert('Mensagem Inválida:\n\n' + m );
		}else if (t==0){
			ajaXEnviaMsgAoVivo(txt);
	}
}

function ajaXEnviaMsgAoVivo(valor)
{
    req = null;
	var url = "tvi_enviar_msg_aovivo.asp";
	var envia = 'txt='+encodeURI(valor);
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange2;
        req.open("POST", url, true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.setRequestHeader('Content-length', envia.length);
        req.send(envia);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange2;
	        req.open("POST", url, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.setRequestHeader('Content-length', envia.length);
            req.send(envia);
        }
    }
}

function processReqChange2()
{
    //document.getElementById('atualiza').innerHTML = '<select name=tipo style=\"WIDTH: 140px; vertical-align:middle; background-color:#FBF5EC;\" class=\"fonte9\"><option>Carregando...</option></select>';
    if (req.readyState == 4) {
        if (req.status == 200) {

			if(req.responseText==1) {
//         		document.location.href="autenticar.asp?run=exec";
//				MostrarDivLogon();
         		document.getElementById('txtMsgAoVivo').value = '';
         		document.getElementById('msgenvi').innerText = 'mensagem enviada ao apresentador!';
         	} else if (req.responseText==0) {
         		alert('Sua mensagem não pode ser enviada tente novamente !!!');
			} else if (req.responseText==2) {
				alert('Você não pode enviar mensagem, você não está logado ao sistema !!!');
         	}

        } else {
            alert("Houve um problema ao obter os dados:\n" + req.statusText);
        }
    }
}

function validarColunaPost(){
	var m = ''
	var t = 0
	var titulo = document.getElementById("titulo").value;
	var txt = document.getElementById("txt").value;
	if (titulo=='') { m += '-> Digite o título da coluna !!!\n';t=1 }
	if (txt=='') { m += '-> Digite o conteudo da coluna !!!\n';t=1 }
		if (t==1) { 
			alert('Mensagem Inválida:\n\n' + m );
			return false
		}else if (t==0){
			return true
	}
}

function validarBusca(){
	var m = ''
	var t = 0
	var txt = document.getElementById("txtbusca").value;
	var q = document.getElementById("q").value;
	if (txt=='') { m += '-> Digite o critério de busca !!!\n';t=1 }
		if (t==1) { 
			alert('Mensagem Inválida:\n\n' + m );
			return false
		}else if (t==0){
			location.href='index.asp?run=busca&q='+q+'&txtbusca='+txt;
	}
}
function validarBuscaBlog(){
	var m = ''
	var t = 0
	var txt = document.getElementById("txtbuscablog").value;
	if (txt=='') { m += '-> Digite o critério de busca !!!\n';t=1 }
		if (t==1) { 
			alert('Mensagem Inválida:\n\n' + m );
			return false
		}else if (t==0){
			location.href='index.asp?run=busca&q=3&txtbusca='+txt;
	}
}


/////////////////////////////////////////////////////////////////////

var rdm;
var arr;
function exibir(x){
    arr = x;
    rdm = "";
    arr = arr.split("#");
    for (y = 0; y <= 3; y++) {
        rdm = rdm + arr[y];
    }
}

// dá um replace 
function replaceAll(string, p, pn){
    while (string.indexOf(p) != -1) {
        string = string.replace(p, pn);
    }
    return string;
}

function vMsgForum(){
    var nomeforum = document.getElementById('forum_nome').value;
    var emailforum = document.getElementById('forum_email').value;
    var msgforum = document.getElementById('forum_mensagem').value;
    
    if (nomeforum == "") {
        alert('Informe seu nome !');
        return false;
    }
    if (emailforum == "") {
        alert('Informe seu e-mail !');
        return false;
    }
    if (msgforum == "") {
        alert('Você não digitou uma mensagem !');
        return false;
    }
    else {
        ajaxEnviaMsgForum();
    }
}

function trocaPais()
{
	var frmCad = document.forms['frmcadastro'];
	if (document.getElementById("pais").value == '23')
	{ // Brasil
		frmCad.cep.value = '';		
		frmCad.cep.disabled = false;
		frmCad.enderecocompleto.value = '';
		frmCad.enderecocompleto.disabled = false;
		frmCad.numero.value = '';
		frmCad.numero.disabled = false;
		frmCad.bairro.value = '';
		frmCad.bairro.disabled = false;
		frmCad.cidade.value = '';
		frmCad.cidade.disabled = false;
		frmCad.estado.disabled = false;

	}
	else
	{
		frmCad.cep.value = '';			
		frmCad.cep.disabled = true;
		frmCad.enderecocompleto.value = '';		
		frmCad.enderecocompleto.disabled = false;
		frmCad.numero.value = '';
		frmCad.numero.disabled = false;
		frmCad.bairro.value = '';
		frmCad.bairro.disabled = false;
		frmCad.cidade.value = '';
		frmCad.cidade.disabled = false;
		frmCad.estado.disabled = true;
		frmCad.estado.selectedIndex =0;

	}
}
function validarBuscaVideos(){
	var txt = document.getElementById('txtvideos').value;
	var opt = document.getElementById('tipo_busca').value;
	if (txt == '' ) {
		alert('Digite o critério de busca !');
		return false;		
	}
}
function validarBuscaNoticias(){
	var txt = document.getElementById('txtnoticias').value;
	var opt = document.getElementById('tipo_busca').value;
	if (txt == '' ) {
		alert('Digite o critério de busca !');
		return false;		
	}
}
function Bloq_CaracteresN(input, evnt){
    var i 
    for (i=0;i<document.frmBuscarNoticias.tipo_busca.length;i++){ 
       if (document.frmBuscarNoticias.tipo_busca[i].checked) 
          break; 
    } 
    if (document.frmBuscarNoticias.tipo_busca[i].value == 'data') {
	
		//só permite digitação de números   
		if (input.value.length == 5) {
			if (clientNavigator == "IE") {
				input.value += "-";
			}
			else {
				if (evnt.keyCode == 0) {
					input.value += "-";
				}
			}
		}
		//Chama a função Bloqueia_Caracteres para só permitir a digitação de números   
		return Bloqueia_Caracteres(evnt);
	}
}

function Bloq_CaracteresX(input, evnt){
    var i 
    for (i=0;i<document.frmBuscarVideos.tipo_busca.length;i++){ 
       if (document.frmBuscarVideos.tipo_busca[i].checked) 
          break; 
    } 
    if (document.frmBuscarVideos.tipo_busca[i].value == 'data') {
	
		//só permite digitação de números   
		if (input.value.length == 5) {
			if (clientNavigator == "IE") {
				input.value += "-";
			}
			else {
				if (evnt.keyCode == 0) {
					input.value += "-";
				}
			}
		}
		//Chama a função Bloqueia_Caracteres para só permitir a digitação de números   
		return Bloqueia_Caracteres(evnt);
	}
}
function barradatavideos(objeto){
	var i 
    for (i=0;i<document.frmBuscarVideos.tipo_busca.length;i++){ 
       if (document.frmBuscarVideos.tipo_busca[i].checked) 
          break; 
    } 
    if (document.frmBuscarVideos.tipo_busca[i].value == 'data') {
		if (objeto.value.length == 2 || objeto.value.length == 5) {
			objeto.value = objeto.value + "/";
		}
	}
}

function barradatanoticias(objeto){
	var i 
    for (i=0;i<document.frmBuscarNoticias.tipo_busca.length;i++){ 
       if (document.frmBuscarNoticias.tipo_busca[i].checked) 
          break; 
    } 
    if (document.frmBuscarNoticias.tipo_busca[i].value == 'data') {
		if (objeto.value.length == 2 || objeto.value.length == 5) {
			objeto.value = objeto.value + "/";
		}
	}
}

function LimparBuscaVideos(){
	hoje = new Date()
	dia = hoje.getDate()
	mes = hoje.getMonth()
	ano = hoje.getFullYear()
	if (dia < 10) {
		dia = "0" + dia;
	}
	if (mes < 10){
		mes = "0" + (mes+1);
	}
	if (ano < 2000) {
		ano = "19" + ano;
	}

	for (i=0;i<document.frmBuscarVideos.tipo_busca.length;i++){ 
       if (document.frmBuscarVideos.tipo_busca[i].checked) 
          break; 
    } 
    if (document.frmBuscarVideos.tipo_busca[i].value == 'data') {
		document.getElementById('txtvideos').value = dia+"/"+mes+"/"+ano;
		document.getElementById('txtvideos').onfocus;
		
	} else {
		document.getElementById('txtvideos').value = '';
		document.getElementById('txtvideos').onfocus;		
	}
}

function LimparBuscaNoticias(){
	hoje = new Date()
	dia = hoje.getDate()
	mes = hoje.getMonth()
	ano = hoje.getFullYear()
	if (dia < 10) {
		dia = "0" + dia;
	}
	if (mes < 10){
		mes = "0" + (mes+1);
	}
	if (ano < 2000) {
		ano = "19" + ano;
	}

	for (i=0;i<document.frmBuscarNoticias.tipo_busca.length;i++){ 
       if (document.frmBuscarNoticias.tipo_busca[i].checked) 
          break; 
    } 
    if (document.frmBuscarNoticias.tipo_busca[i].value == 'data') {
		document.getElementById('txtnoticias').value = dia+"/"+mes+"/"+ano;
		document.getElementById('txtnoticias').onfocus;
		
	} else {
		document.getElementById('txtnoticias').value = '';
		document.getElementById('txtnoticias').onfocus;		
	}
}
