﻿/*--------------------------------------------------------------
/  Responsável pelas funções usadas nas telas do sistema
/  
/  Criação 01/07/2008
---------------------------------------------------------------*/



// Imprime mensagem de erro
function MostraErroGeral(msg) {
    document.getElementById('LblErro').style.display='block';
    document.getElementById('LblErroMsg').innerHTML = msg;
}

//--------------------------------------------------------------------------

function Pesquisa() 
{
    document.getElementById('cxPesquisa').style.display='block';
    document.getElementById('cxRedefinir').style.display='none';
}

//--------------------------------------------------------------------------

function DesabilitaBotao(botao, img)
{
    botao.src = img;
    botao.disabled = true;    
}

function HabilitaBotao(botao, img)
{
    botao.src = img;
    botao.disabled = false;
}

//--------------------------------------------------------------------------

function DesejaExcluir()
{
    return confirm('Deseja excluir?');
}

//--------------------------------------------------------------------------
// Coloca ação de submit quando Enter em um campo
function submitFormEnter(myfield,e,btnSubmit)
{        
    var keycode;
    
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13)
    {
        document.getElementById(btnSubmit).click();
        return false;
    }
    else
    {
        return true;
    }
}  

//--------------------------------------------------------------------------
// Somente números no campo
function validaNumeros(e) {    
  if(window.event) {
    key = e.keyCode;
  } else if(e.which) {
    key = e.which;
  }

  if (key!=8 || key < 48 || key > 57) return (((key > 47) && (key < 58)) || (key==8));
     return true;
}

function somente_numero(campo) {
    var digits="0123456789"
    var campo_temp 
    for (var i=0;i<campo.value.length;i++){
      campo_temp=campo.value.substring(i,i+1)    
      if (digits.indexOf(campo_temp)==-1){
            campo.value = campo.value.substring(0,i);
            break;
       }
    }
}

//--------------------------------------------------------------------------
// Somente números e vírgula no campo
function validaReais(e) {

  if(window.event) {
    key = e.keyCode;
  } else if(e.which) {
    key = e.which;
  }
  
  if (key!=8 || key < 48 || key > 57 || key != 44)
    return (((key > 47) && (key < 58)) || (key==8) || (key==44));
     
  return true;
     
}

//--------------------------------------------------------------------------
// Formata CPF
function FormataCPF(Campo, teclapres) {
        var tecla = teclapres.keyCode;        
        var vr = new String(Campo.value);        
        vr = vr.replace(".", "");        
        vr = vr.replace(".", "");        
        vr = vr.replace("-", "");        
        tam = vr.length + 1;        
        if(tecla != 9 && tecla !=8) {        
            if(tam > 3 && tam < 7)		             
            Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);         
            if(tam >= 7 && tam <10)		             
            Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);        
            if(tam >= 10 && tam < 12)             
            Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);       
        }
}


//--------------------------------------------------------------------------
// Formata Data
function FormataData(Campo, teclapres) {
        var tecla = teclapres.keyCode;        
        var vr = new String(Campo.value);        
        vr = vr.replace("/", "");
        vr = vr.replace("/", "");        
        tam = vr.length + 1;
        if(tecla!=9 && tecla !=8 && tecla!=47) {
            if(tam > 2 && tam < 5)
            Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
            if(tam >= 5)
            Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,tam);        
            return true;
        }else{
            return false;
        }
}

//--------------------------------------------------------------------------
// Formata Data (mes e ano)
function FormataDataMesAno(Campo, teclapres) {
        var tecla = teclapres.keyCode;        
        var vr = new String(Campo.value);        
        vr = vr.replace("/", "");
        vr = vr.replace("/", "");        
        tam = vr.length + 1;
        if(tecla != 9 && tecla !=8) {        
            if(tam > 2 && tam < 5)
            Campo.value = vr.substr(0, 2) + '/' + vr.substr(2, tam);
        }
}

//--------------------------------------------------------------------------
// Formata CEP
function FormataCEP(Campo, teclapres) {
        var tecla = teclapres.keyCode;
        var vr = new String(Campo.value);
        vr = vr.replace("-", ""); 
        tam = vr.length + 1;
        if(tecla != 9 && tecla !=8) {        
            if(tam > 5)
            Campo.value = vr.substr(0, 5) + '-' + vr.substr(5, tam);
        }
}

//--------------------------------------------------------------------------
// Abre uma popup para escolher o CEP
function JanelaCep(id)
{
    window.open('PesquisaCep.aspx?id=' + id, 'PesquisaCEP' , 'height=428,width=580,menubar=0,location=0,status=0,scrollbars=0,toolbar=0,resizable=0');
}

//--------------------------------------------------------------------------
// Abre uma popup para escolher o vendedor
function JanelaVendedor()
{
    window.open('PesquisaVendedor.aspx', 'PesquisaVendedor' , 'height=250,width=300,menubar=0,location=0,status=0,scrollbars=0,toolbar=0,resizable=0');
}

//--------------------------------------------------------------------------
// Abre janela de ajuda
function JanelaAjuda(url)
{
    if(url == null)
        url = "Ajuda.aspx";
    var janela = window.open("Ajuda/" + url, 'Ajuda' , 'height=320,width=280,menubar=0,location=0,status=0,scrollbars=yes,toolbar=0,resizable=0');
    janela.focus();
}

//--------------------------------------------------------------------------
// Retorna a data atual
function mostraDataAtual()
{
    day = new Date()
    dia = day.getDate()
    if(dia < 10) dia = '0' + dia;
    mes = day.getMonth()+1
    if(mes < 10) mes = '0' + mes;
    ano = day.getYear()
    return dia + '/' + mes + '/' + ano;
}

   
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------    