﻿
function MensagemAlerta(strMsg){
    alert(strMsg);
    return false;
}

/////////////////////////////////////////////////////////////////////////////////

function ModalPopUp(Destino , Nome , Altura , Largura , CtrlRetorno){ 
    var vRetorno; 
    vRetorno = window.showModalDialog(Destino ,  Nome  ,"dialogHeight:" +Altura+ "px;dialogWidth:"+Largura+"px; center: Yes; resizable: No; scroll: No; status: No;");                    
    document.getElementById(CtrlRetorno).value = vRetorno; 
    return false;
} 

/////////////////////////////////////////////////////////////////////////////////

function ModalPopUpEdit(Destino , Nome , Altura , Largura, CtrlRetorno){ 
    var vRetorno; 
    vRetorno = window.showModalDialog(Destino ,  Nome  ,"dialogHeight:" +Altura+ "px;dialogWidth:"+Largura+"px; center: Yes; resizable: No; status: No;");                    
    document.getElementById(CtrlRetorno).value = vRetorno; 
    return false;
} 

/////////////////////////////////////////////////////////////////////////////////

function ModalPopUpError(Destino , Nome , Altura , Largura , CtrlRetorno){ 
//    window.showModalDialog(Destino ,  Nome  ,"dialogHeight:" +Altura+ "px;dialogWidth:"+Largura+"px; center: Yes; resizable: No; scroll:No; status: No;");
//    return false;   

    winwidth    = Largura; 
    winheight   = Altura;  
    winleft     = 200; 
    wintop      = 200; 
  
    if(parseInt(navigator.appVersion)>=4){
        winleft = (screen.width / 2) - (winwidth / 2);  
        wintop = (screen.height / 2) - (winheight / 2) - 9;  
    }
    
    window.open(Destino, Nome , 'top=' + wintop + ',left=' + winleft + ',status=yes,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no, height=' + winheight + ',width=' + winwidth); 
                  
} 

/////////////////////////////////////////////////////////////////////////////////

function ModalPopUpSucesso(Destino , Nome , Altura , Largura , CtrlRetorno){ 
//    window.showModalDialog(Destino ,  Nome  ,"dialogHeight:" +Altura+ "px;dialogWidth:"+Largura+"px; center: Yes; resizable: No; scroll:No; status: No;");
//    return false; 
    winwidth    = Largura; 
    winheight   = Altura;  
    winleft     = 200; 
    wintop      = 200; 
  
    if(parseInt(navigator.appVersion)>=4){
        winleft = (screen.width / 2) - (winwidth / 2);  
        wintop = (screen.height / 2) - (winheight / 2) - 9;  
    }
    
    window.open(Destino, Nome , 'top=' + wintop + ',left=' + winleft + ',status=yes,resizable=no,toolbar=no,menubar=no,location=no,scrollbars=no, height=' + winheight + ',width=' + winwidth); 
                      
} 

/////////////////////////////////////////////////////////////////////////////////

function FecharJanelaValor(CtrlRetorno) 
{ 
    window.returnValue = document.getElementById(CtrlRetorno).value; 
    window.close(); 
} 

/////////////////////////////////////////////////////////////////////////////////

function FecharJanela() 
{ 
    window.close();
} 

/////////////////////////////////////////////////////////////////////////////////

function MM_formtCep(e,src,mask) {
    if(window.event) { _TXT = e.keyCode; } 
    else if(e.which) { _TXT = e.which; }
    if(_TXT > 47 && _TXT < 58) { 
     var i = src.value.length; var saida = mask.substring(0,1); var texto = mask.substring(i)
     if (texto.substring(0,1) != saida) { src.value += texto.substring(0,1); } 
        return true; } else { if (_TXT != 8) { return false; } 
     else { return true; }
   }
}

/////////////////////////////////////////////////////////////////////////////////

function MM_formtCPF(formato, objeto)
{
    campo = eval (objeto);
    if (formato=='CPF')
    {
        caracteres = '01234567890';
        separacoes = 3;
        separacao1 = '.';
        separacao2 = '-';
        conjuntos = 4;
        conjunto1 = 3;
        conjunto2 = 7;
        conjunto3 = 11;
        conjunto4 = 14;
        if ((caracteres.search(String.fromCharCode (window.event.keyCode))!=-1) && campo.value.length < 
        (conjunto4))
        {
        if (campo.value.length == conjunto1) 
        campo.value = campo.value + separacao1;
        else if (campo.value.length == conjunto2) 
        campo.value = campo.value + separacao1;
        else if (campo.value.length == conjunto3) 
        campo.value = campo.value + separacao2;
    }
    else 
    event.returnValue = false;
  } 
}

/////////////////////////////////////////////////////////////////////////////////

function MM_formtCNPJ(Campo, teclapres){

   if(window.event){
    var tecla = teclapres.keyCode;
   }else  tecla = teclapres.which;

   var vr = new String(Campo.value);
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("/", "");
   vr = vr.replace("-", "");

   tam = vr.length + 1;
   if (tecla > 47 && tecla < 58){
      if (tam > 2 && tam < 6)
         Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
      if (tam >= 6 && tam < 9)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
      if (tam >= 9 && tam < 13)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
      if (tam >= 13 && tam < 15)
         Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
    }
    else
        return false;
}

/////////////////////////////////////////////////////////////////////////////////

function Numero(e)
{
    navegador = /msie/i.test(navigator.userAgent);
    if (navegador)
        var tecla = event.keyCode;
    else
        var tecla = e.which;

    if(tecla > 43 && tecla < 58){
       if(tecla != 45 && tecla != 46)
          return true;
        else
          return false;
     }
    else
    {
    if (tecla != 8) // backspace
        return false;
    else
        return true;
  }
}

/////////////////////////////////////////////////////////////////////////////////

function setfocus(t) {
    document.getElementById(t).focus();
    return;
}

//////////////////////////////////////////////////////////////////////////////////

function TABEnter(oEvent){
  var oEvent = (oEvent)? oEvent : event;
  if(oEvent.keyCode==13)
        oEvent.keyCode = 9;
}

///////////////////////////////////////////////////////////////////////////////////

function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
        if (whichCode == 13 || whichCode == 8) return true;
        key = String.fromCharCode(whichCode); // Valor para o código da Chave
        if (strCheck.indexOf(key) == -1) return false; // Chave inválida
        len = objTextBox.value.length;
        //alert(len);
        for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
        aux = '';
        for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
        aux += key;
        len = aux.length;
        // alert(len);
        if (len == 9999){
        return false;
        }
            if (len == 0) objTextBox.value = '';
            if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + '0' + aux;
            if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
            if (len == 3) objTextBox.value = '0'+ SeparadorDecimal + aux;
        //if (len == 4) objTextBox.value = '0'+ SeparadorDecimal + aux;
        //alert(len);
        if (len > 3) {
        aux2 = '';
        for (j = 0, i = len - 4; i >= 0; i--) {
        if (j == 3) {
        aux2 += '.';
        j = 0;
        }
        aux2 += aux.charAt(i);
        //alert(aux2);
        j++;
        }
        objTextBox.value = '';
        //alert('1');
        len2 = aux2.length;
        //alert('2');
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 3, len);
        //alert(aux.substr(len - 4, len));
        //alert(objTextBox.value)
    }
 return false;
}

///////////////////////////////////////////////////////////////////////////////////

function WindowOpen(Destino , Nome, Altura, Largura){

    winwidth    = Largura; 
    winheight   = Altura;  
    winleft     = 200; 
    wintop      = 200; 
  
    if(parseInt(navigator.appVersion)>=4){
        winleft = (screen.width / 2) - (winwidth / 2);  
        wintop = (screen.height / 2) - (winheight / 2) - 9;  
    }
    
    window.open(Destino, Nome , 'top=' + wintop + ',left=' + winleft + ',status=yes,resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=yes, height=' + winheight + ',width=' + winwidth); 
}

/////////////////////////////////////////////////////////////////////////////////
