﻿function OpenWindow(url,height,width)
{
   config=""
   config+="toolbar=yes,";
   config+="resizable=yes," 
   config+="scrollbars=yes,"
   config+="width="+width+","
   config+="height="+height
   var window=open(url,"",config);
   window.focus();
   
   //<a href="javascript:OpenWindow('http://www.google.com',400,500);"> Clique aqui para abrir a janela </a>
}

function Poup(sURL, width, height, scroll, nome_janela, resizable){
    var popup = null;    
    var url = sURL + '&rnd=' + Math.round(Math.random() * 899999) + 100000;
    var nome;
    
    if (nome_janela == ''){
         nome = 'popup_erc';
    }else{
        nome = nome_janela.replace(' ', '_');
    }
    
    if (resizable == ''){
         resizable = 'no';
    }
    
    if (popup!=null && !popup.closed){
        popup.focus();
    }else{
     
        LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
        TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
        
        settings = 'height='+ height +',width='+ width +',top=' + TopPosition + ',left='+ LeftPosition + ',scrollbars=' + scroll + ',resizable=' + resizable;
        
        popup = window.open(url, nome.replace(' ', '_'), settings);
        
        //popup = window.open(url,'popup_erc','height=' + height + ',width=' + width);
        popup.focus();      
    }
}

function MascaraCNPJ(cnpj){
    if(mascaraInteiro(cnpj)==false){
        event.returnValue = false;
    }    
    return formataCampo(cnpj, '00.000.000/0000-00', event);
}

//adiciona mascara de cep
function MascaraCep(cep){
        if(mascaraInteiro(cep)==false){
        event.returnValue = false;
    }    
    return formataCampo(cep, '00.000-000', event);
}

//adiciona mascara de data
function MascaraData(data){
    if(mascaraInteiro(data)==false){
        event.returnValue = false;
    }    
    return formataCampo(data, '00/00/0000', event);
}

//adiciona mascara ao telefone
function MascaraTelefone(tel){    
    if(mascaraInteiro(tel)==false){
        event.returnValue = false;
    }    
    return formataCampo(tel, '(00) 0000-0000', event);
}

//adiciona mascara ao CPF
function MascaraCPF(cpf){
    if(mascaraInteiro(cpf)==false){
        event.returnValue = false;
    }    
    return formataCampo(cpf, '000.000.000-00', event);
}

//valida telefone
function ValidaTelefone(tel){
    exp = /\(\d{2}\)\ \d{4}\-\d{4}/
    if(!exp.test(tel.value))
        alert('Numero de Telefone Invalido!');
}

//valida CEP
function ValidaCep(cep){
    exp = /\d{2}\.\d{3}\-\d{3}/
    if(!exp.test(cep.value))
        alert('Numero de Cep Invalido!');        
}

//valida data
function ValidaData(data){
    exp = /\d{2}\/\d{2}\/\d{4}/
    if(!exp.test(data.value))
        alert('Data Invalida!');            
}

