function AtualizarRotuloCaracteres(idCampo,idCampoRotulo,countCaracteres,mensagem,e) {

     var campoTexto = $get(idCampo); 
     var rotuloTextoLimite = $get(idCampoRotulo); 
     
     rotuloTextoLimite.innerHTML = mensagem.replace("{0}", (countCaracteres - campoTexto.value.length));
          
     if (campoTexto.value.length > countCaracteres - 1)
     {
        if (!PermitirTeclaPressionada(e.keyCode))
        {
            e.returnValue = false; 
            campoTexto.value = campoTexto.value.substring(0,countCaracteres);           
        }
     }
}

function PermitirTeclaPressionada(codigoTecla) {
        var arrCodigosCaracteres = [8,16,33,34,35,36,37,38,39,40,45,46];   
      
        for (a = 0; a < arrCodigosCaracteres.length; a++){               
            if (codigoTecla == arrCodigosCaracteres[a])             
                return true;
        }        
        return false;
}

function LimparTexto(idCampoTexto) {

    var txt = $get(idCampoTexto);
    if(txt != null) txt.value = '';
}

function Click(idCampo) {
    var campo = document.getElementById(idCampo);
    if(campo != null)    
        campo.click();            
}

function ExecutarPost(nome, nomeEvento) {  				
    setTimeout("__doPostBack(\'" + nome + "\',\'" + nomeEvento + "\')", 0);		    
}

function ExecutarFuncao(strFuncao) {
    setTimeout(strFuncao, 0);		    
}

function AtualizarRotuloPalavras(idCampo,idCampoRotulo,countPalavras,mensagem,strCaracterDivisor,e) {

     var campoTexto = $get(idCampo); 
     var rotuloTextoLimite = $get(idCampoRotulo); 
     
     rotuloTextoLimite.innerHTML = mensagem.replace("{0}", (countPalavras - ContarPalavras(campoTexto.value, strCaracterDivisor)));
               
     while (ContarPalavras(campoTexto.value,strCaracterDivisor) > countPalavras)
     {     
         campoTexto.value = campoTexto.value.substring(0,(campoTexto.value.length-1)); 
     
        //Virgula, código ascii
        if (e.keyCode == 110)        
            e.returnValue = false;                    
        
        rotuloTextoLimite.innerHTML = mensagem.replace("{0}", 0);
     }
}

function ContarPalavras(strTexto, strCaracterDivisor) {    
    var palavras = strTexto.split(strCaracterDivisor);
    
    //Se não tiver caracter
    if(strTexto.length == 0)
        return 0;    
    else     
        return palavras.length;
}

//Exibe uma mesnagem se o check
function CheckClickMensagem(idCheck, mensagem) {
        
    var chk = $get(idCheck);
    var bResposta;    
    
    //Se não tiver checkado, pois ao clickar, a primeira coisa que faz e trocar o estado do chk e depois entra no evento.
    if(!chk.checked)        
        bResposta = confirm(mensagem);
    else
        bResposta = true;
        
        if(bResposta)
            ExecutarPost(idCheck, "onclick");
        
    //Representa se troca ou não o estado do chk.
    return bResposta;
}

function AbrirJanela(pagina, nome, largura, altura)
{
    window.open(pagina);
    //window.open(pagina,nome,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,menubar=no,width=' + largura + ',height=' + altura + ',top=' + ((screen.height - altura)/2)+ ', left=' +((screen.width - largura)/2) );
    //window.open(pagina,nome,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,menubar=no,width=' + largura + ',height=' + altura + ',top=' + ((screen.height - altura)/2)+ ', left=' +((screen.width - largura)/2) + '');
//	if(janela != null) janela.resizable = 'no';
//	janela.focus();
}




function getWidth()
{
    return window.innerWidth ? window.innerWidth : /* For non-IE */
    document.documentElement ? document.documentElement.clientWidth : /* IE 6+ (Standards Compilant Mode) */
    document.body ? document.body.clientWidth : /* IE 4 Compatible */
    window.screen.width; /* Others (It is not browser window size, but screen size) */
}

function getHeight()
{
    return window.innerHeight ? window.innerHeight : /* For non-IE */
    document.documentElement ? document.documentElement.clientHeight : /* IE 6+ (Standards Compilant Mode) */
    document.body ? document.body.clientHeight : /* IE 4 Compatible */
    window.screen.height; /* Others (It is not browser window size, but screen size) */
}

//Aperta o botão necessário quando uma pessoa aperta
//a tecla "Enter" em um campo de texto
function PressionarEnter(IdBotaoApertar, e)
{
    var charCode = (e.which) ? e.which : e.keyCode;
    if(charCode == 13)
    {
        Click(IdBotaoApertar);
    }
}

function TratarTextBox(idTextBox, frasePadrao, event) {
    var objTxt = document.getElementById(idTextBox);
    if (objTxt) {
        if (objTxt.value == frasePadrao || objTxt.value == "") {
            objTxt.value = frasePadrao;
        }
    }
}

function LimparTextBox(idTextBox, event) {
    var objTxt = document.getElementById(idTextBox);
    if (objTxt) {
            objTxt.value = "";
    }
}