﻿//MODAL POPUP
objBox = document.getElementById("ctl00_ContentPlaceHolder1_cboPais"); 

function MudarImg(img,valor){
   __doPostBack('ctl00$ContentPlaceHolder1$lkbAtualizarLista',''); 
}

function verificaCaracterInvalido(obj){
    var re = obj.value
    if(re.match(['[-!@#$=+%¨&*+´`^~;:?áÁéÉíÍóÓúÚãÃçÇ|\?,./{}"<>() ]'])){
    alert("Caracteres não permitidos !!\n [-@#$%¨&*+´`^~;:?áÁéÉíÍóÓúÚãÃçÇ|\?,./{}<>() ] !!");
    obj.value = "";
    return false;
  }else{
    return true;
 }
}

function DivLogado(){
    $("divDeslogado").hide();
    $("divLogado").show();
}

function DivDeslogado(){
    $("divDeslogado").show();
    $("divLogado").hide();
}
  
  
//Controle Avaliação        
//var valorInicial = PegaValorInicial(txtValorInicial);
function MudaImagem(booMudaImagem,strImgInativa,strImgAtiva,intValor,HyperLink,txtValorInicial,lblPontos) {
valorInicial = PegaValorInicial(txtValorInicial);

    var totalImagens = 5;
    TrocaImagem(totalImagens,strImgInativa,HyperLink)
    
    if (booMudaImagem) {
        ExibePontos(intValor,true,lblPontos)
        TrocaImagem(intValor,strImgAtiva,HyperLink)
        }
    
    if (!booMudaImagem) {
        ExibePontos(intValor,false,lblPontos)
        TrocaImagem(valorInicial,strImgAtiva,HyperLink)
       }
}
    
function TrocaImagem(intValor,strImg,HyperLink) {
        var link = HyperLink.substring(0,HyperLink.length -1)
        for (i=1;i<=intValor;i++){
        objHyper = document.getElementById(link + i);
        if (objHyper != null)
        {
            document.getElementById(link + i).style.backgroundImage = "url(" + "../App_Themes/Default/" + strImg + ")";
        }
     }
}
    
    
    function ExibePontos(intValor,booExibe,lblPontos){
        var strResultado = "";
        objPontos = document.getElementById(lblPontos);
        if (booExibe) {
            switch(intValor){
                case 0: strResultado = "0 pontos";break;
                case 1: strResultado = "10 a 20 pontos";break;
                case 2: strResultado = "21 a 40 pontos";break;
                case 3: strResultado = "41 a 60 pontos";break;
                case 4: strResultado = "61 a 80 pontos";break;
                case 5: strResultado = "81 a 100 pontos";break;
                default: strResultado = "default";break;
        }
            if (objPontos != null)
            {
                document.getElementById(lblPontos).innerHTML = strResultado;
            }
        }
        
        if (!booExibe) {
            if (objPontos != null)
            {
                 document.getElementById(lblPontos).innerHTML = "";
            }
        }
    }
    
    function MudaValor(intValor,HyperLink,txtValorInicial,lblPontos) {
    objValor = document.getElementById(txtValorInicial);
    if (objValor != null)
    {
         document.getElementById(txtValorInicial).value = intValor
    }else{
         intValor = intValor
    }
         MudaImagem(true,'EmptyStar.png','FilledStar.png',intValor,HyperLink,txtValorInicial,lblPontos)
    }

    function PegaValorInicial(txtValorInicial){
    objValor = document.getElementById(txtValorInicial); 
    if (objValor != null)
    {
        return parseInt(document.getElementById(txtValorInicial).value);
    }else{
        return 3;
    }
   }
   
   function DivAvaliacao(Div,exibeDiv,exibeLista)
   {
    obj = document.getElementById("ctl00_ContentPlaceHolder1_tdlstAvaliacao")
    if (obj != null)
    {
        if (document.getElementById(Div) != null)
        {
         document.getElementById(Div).style.display = exibeDiv;
        }
         document.getElementById("ctl00_ContentPlaceHolder1_tdlstAvaliacao").style.display = exibeLista;
         document.getElementById("ctl00_ContentPlaceHolder1_txtVinhoAvaliacao").value = "";
    }else {
        
        if (document.getElementById(Div) != null)
        {
         document.getElementById(Div).style.display = exibeDiv;
        }
        
    }
   }  
   
  function MostraDiv(Div,exibe) {
    obj = document.getElementById(Div)
    if (obj != null){
         document.getElementById(Div).style.display = exibe;
    }
   }
   
function ExecutaPostBack(v){__doPostBack(v,'');}
   
function MudaImagemCarregando(btnFavorito, strImagem){
    document.getElementById(btnFavorito).src = strImagem;
}

function AbreCarregando(){
   $('.divHide').hide(); 
   $('.divShow').show();
}

function AddHash(strHash){
    location.hash = '#' + strHash; 
    AbreCarregando();
}

function CarregaMenu(imgFavoritar, intSiteID){ 
    MudaSiteFavorito(imgFavoritar, intSiteID, true);
}

function MudaFavorito(lnk, img, intID){

    var hlkFavoritar = $("#"+lnk);
    var imgFavoritar = $("#"+img);
    var strNovaClasse;
    var strClasseAtual;
    
    imgFavoritar.unbind('click');
    imgFavoritar.removeClass(); 
    imgFavoritar.addClass('ajaxLoader'); 

    $.post("WebService/MarcarPostFavorito.aspx?Automatico=1&PostID=" + intID, 
    function (data){ 
        switch (data){
            case 'False' : strNovaClasse = 'imbMarcarFavorito'; break;
            case 'True' : strNovaClasse = 'imbMarcadoFavorito'; break;
        } 
        
        imgFavoritar.removeClass();  
        imgFavoritar.addClass(strNovaClasse);
        
        imgFavoritar.click(function(){
            MudaFavorito(img, intID);
        })           
    })
}

function MarcarPostVotado(img, intID){

    var imgVoto = $("#"+img);    
    imgVoto.unbind('click');
    imgVoto.removeClass(); 
    imgVoto.addClass('ajaxLoader'); 

    $.post("WebService/MarcarPostVotado.aspx?PostID=" + intID, 
    function (){ 
        imgVoto.removeClass();  
        imgVoto.addClass('handMaisHover');
    });
}


function VerificaCampos(obj, intTotal, booInicio){
    if(booInicio){obj = document.getElementById(obj);}
    var intAtual = obj.value.length;
    $(".limite").text(intAtual);
    if(intAtual > intTotal){
        obj.value = obj.value.substr(0, intTotal);
        return false;
    }
} 