﻿
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: Yes; 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: Yes; 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: Yes; scroll:No; status: No;");
    return false;                     
} 

/////////////////////////////////////////////////////////////////////////////////

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;                     
} 

/////////////////////////////////////////////////////////////////////////////////

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;
}