//função para limitar o tamanho de caracteres em um textarea
//onkeyup='bloc(this.id, this.value)'
function bloc(id, valor)
{
//alert("Conteúdo: " + valor);
//alert("ID: " + id);
    quant = 250;
    total = valor.length;
//alert("caracteres: " + total);    
    if(total <= quant)
    {
       resto = quant - total;
       document.getElementById('cont').innerHTML = resto;
       // alert("dentro dos limites: ");
    }
    else
    {
     //   alert("ultrapassou: ");
		document.getElementById(id).value = valor.substr( 0, quant);
    }
}

		function ajuda() {
			var msgWindow;
			msgWindow=window.open('','','toolbar=yes,menubar=yes,resizable=no,width=800,height=600,dependent=yes,scrollbars=yes,left=0,top=0');
			msgWindow.document.clear();
			msgWindow.document.write ("<HTML><BODY>")
			msgWindow.document.write ("1ª via - cliente<div align='center'>")
			msgWindow.document.write (document.getElementById("tit").innerHTML);
			msgWindow.document.write ("</div><hr>2ª via - arquivo")
			msgWindow.document.write ("<div align='center'>")
			msgWindow.document.write (document.getElementById("tit").innerHTML);
			msgWindow.document.write ("<a href='#' onclick='window.print(); return false;'><IMG src='./images/cprint.jpg' height='25' width='100'></a>")
			msgWindow.document.write ("</HTML></BODY>")
			//msgWindow.print();
			msgWindow.document.close();
		}



		
function cria_janela_cent(horizontal,vertical,nome, pagina) {
var res_ver = screen.height
var res_hor = screen.width
var pos_ver_fin = (res_ver - vertical)/2
var pos_hor_fin = (res_hor - horizontal)/2

window.open(pagina,nome,"width="+horizontal+",height="+vertical+",top="+pos_ver_fin+",left="+pos_hor_fin+",status=yes");
}

//<a href="javascript:cria_janela_cent(300,200,'pop','despliquidar.php')">clica aqui!</a>

function faleConosco(id) { 
window.open('formprotesto.htm', '', 'height=400, width=750, top=20, left=20, toolbar=0, scrollbars=1, directories=no, location=0, statusbar=0, titlebar=0, menubar=0, resizable=0,'); 
}



/*//Forma de colcoar em um link
<a href="/desp.php" target="_blank" onClick="window.open(this.href, this.target, ‘width=600,height=350‘); return false;">Abrir</a>
*/

//onBlur="controle(this.id)"

function controle(contrato) {
//var test = document.contrato(id).value;
//var test = document.getElementById(id).value;
alert("Conteúdo: " + contrato);
}
// test = document.contrato.value; (undefined)
// test = document.contrato.id.value; (undefined)
// test = document.contrato.(id).value; (nada)
// test = document.contrato(id).value; (nada)

// alert("Escreveste: " + contrato); this.id me dá o id do objeto
// alert("Escreveste: " + contrato); this.value me dá o valor digitado
// alert("Escreveste: " + contrato); this.maxlenght (undefined)


/* poossiveis valores
this.size
this.name

*/


 
//onKeyPress='FormataValor(this.id, 10, event)'

//style="text-align:right" alinhar texto a direita para campo moedas
// tabindex="2" colocando isso no TEXTAREA ele fica de tabulação separada dos demais controles

//onkeypress='return SomenteNumero(event)'
function FormataValor(id,tammax,teclapres) {
    
        if(window.event) { // Internet Explorer
         var tecla = teclapres.keyCode; }
        else if(teclapres.which) { // Nestcape / firefox
         var tecla = teclapres.which;
        }
    

vr = document.getElementById(id).value;
vr = vr.toString().replace( "/", "" );
vr = vr.toString().replace( "/", "" );
vr = vr.toString().replace( ",", "" );
vr = vr.toString().replace( ".", "" );
vr = vr.toString().replace( ".", "" );
vr = vr.toString().replace( ".", "" );
vr = vr.toString().replace( ".", "" );
tam = vr.length;

if (tam < tammax && tecla != 8){ tam = vr.length + 1; }

if (tecla == 8 ){ tam = tam - 1; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
if ( tam <= 2 ){
document.getElementById(id).value = vr; }
if ( (tam > 2) && (tam <= 5) ){
document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
if ( (tam >= 6) && (tam <= 8) ){
document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
if ( (tam >= 9) && (tam <= 11) ){
document.getElementById(id).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
if ( (tam >= 12) && (tam <= 14) ){
document.getElementById(id).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
if ( (tam >= 15) && (tam <= 17) ){
document.getElementById(id).value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
}
}

$(function() {
			$('input[@name=data]').mask('99/99/9999');
			$('input[@name=data2]').mask('99/99/9999');
			$('input[@name=data3]').mask('99/99/9999');
			$('input[@name=cep]').mask('99999-999');
			$('input[@name=cep2]').mask('99999-999');
			$('input[@name=cpf1]').mask('999.999.999-99');
			$('input[@name=cpf2]').mask('999.999.999-99');
			$('input[@name=cnpj]').mask('99.999.999/9999-99');
			$('input[@name=cnpj2]').mask('99.999.999/9999-99');
			$('input[@name=cnpj3]').mask('99.999.999/9999-99');
			$('input[@name=cnpj4]').mask('99.999.999/9999-99');
			$('input[@name=tele1]').mask('(99)9999-9999');
			$('input[@name=tele2]').mask('(99)9999-9999');
			$('input[@name=tele3]').mask('(99)9999-9999');
			$('input[@name=tele4]').mask('(99)9999-9999');
			$("#moeda").mask('9.999.999,99');
			//$('input[@name=ed3]').mask('9.999.999,99');		
			});

function validausu()
{
if (document.cadastro.nomec.value=="" || document.cadastro.nivelc.value=="" || document.cadastro.cnpj.value=="" || document.cadastro.senhac.value=="" || document.cadastro.senha2c.value=="")
{
alert("Todos os campos são de preenchimento obrigatório!")
return(false)
}
else
{
//document.form1.ok.value="sim"
return(true)
}
}

function validausu2()
{
if (document.cadastro.nomec.value=="" || document.cadastro.nivelc.value=="" || document.cadastro.cnpj.value=="")
{
alert("Todos os campos são de preenchimento obrigatório!")
return(false)
}
else
{
//document.form1.ok.value="sim"
return(true)
}
}

//validar os campos na tela alterar cadastro
function validausu2()
{
if (document.alt_dados.nomeusuario.value=='' || document.alt_dados.nivel.value=='')
{
alert('Todos os campos são de preenchimento obrigatório!')
return(false)
}
else
{
//document.form1.ok.value='sim'
return(true)
}
}

//função para validar o cadastro de clientes
function validacli()
{
if (document.cadastrocli.ed1.value=="" || document.cadastrocli.ed2.value=="" || document.cadastrocli.ed3.value=="" || document.cadastrocli.ed4.value=="" || document.cadastrocli.cpf1.value==""|| document.cadastrocli.ed15.value=="")
{
alert("Todos os campos com asteriscos(*) são de preenchimento obrigatório!")
return(false)
}
else
{
//document.form1.ok.value="sim"
return(true)
}
}

//função para validar o cadastro de fornecedores
function validafor()
{
if (document.fornecedores.ed1.value=="" || document.fornecedores.ed2.value=="" || document.fornecedores.ed3.value=="" || document.fornecedores.ed4.value=="" || document.fornecedores.tele1.value==""|| document.fornecedores.ed10.value==""|| document.fornecedores.cnpj.value=="")
{
alert("Todos os campos com asteriscos(*) são de preenchimento obrigatório!")
return(false)
}
else
{
//document.form1.ok.value="sim"
return(true)
}
}

//função para validar o cadastro de obras
function validaobra()
{
if (document.obras.ed1.value=="" || document.obras.ed2.value=="" || document.obras.ed3.value=="" || document.obras.data.value=="" || document.obras.ed5.value=="" || document.obras.ed6.value=="")
{
alert("Todos os campos são de preenchimento obrigatório!")
return(false)
}
else
{
//document.form1.ok.value="sim"
return(true)
}
}

//função para validar o cadastro de despesas
function validades()
{
if (document.despesa.ed11.value=="" || document.despesa.data.value=="" || document.despesa.ed6.value=="" || document.obras.data.value=="" || document.obras.ed5.value=="" || document.obras.ed6.value=="")
{
alert("Os campos (Observações/Data Vencimento/Valor) são de preenchimento obrigatório!")
return(false)
}
else
{
//document.form1.ok.value="sim"
return(true)
}
}

<!-- Idea by:  Nic Wolfe -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=0, width=100, height=100, left = 300, top = 150');");
}
// End -->



// BAck space 8
// Tab 9
// DELETE 46
// Ctrl 17
// Alt 18
// Espace 32
// Esc 27
// Shift 16

//função para pegar o conteúdo digitado e gerar quantos alerts equivalentes
//onkeyup='bloc(this.id, this.value)'
//onblur='bloc(this.id, this.value)'
//onkeypress="return SomenteNumero(event)" AO DIGITAR

function gerapaga(id, valor, i)
{
if (valor > 0){
//alert("ID: " + id + "- Conteúdo: " + valor);
for (i=1; i<=valor; i++) { 
alert ("Parcela "+ i);
} 
alert ("Total parcelas "+ valor);
}
}






/*
//var saudacao = "Olá! Tudo bom?";
alert( saudacao );
alert( "Esta é uma segunda janela do tipo alert." );
*/
/*
var 
gosta = confirm("Deseja Continuar?");
function Confirma(gosta){
//document.write( gosta );
if ( gosta == true)
{
//  document.write("<p>Eu também gosto!<\/p>");
}
else
{
//  document.write( "<p>Não gosta???<\/p>" );
}}
*/




/*
var nome  = prompt( "Qual o seu nome?" );
var idade = prompt( "Qual a sua idade?" );
var cor   = prompt( "Qual a sua cor favorita?", "cinza" );

document.write( "<p>Seu nome: " + nome + "<\/p>" );
document.write( "<p>Sua idade: " + idade + "<\/p>" );
document.write( "<p>Sua cor favorita: " + cor + "<\/p>" );
*/


//OnKeyUp="mascaraData(this);"

//Aqui quando a pessoa digita ele preenche com as barras
function mascaraCEP(campoData){
              var data = campoData.value;
              if (data.length == 5){
                  data = data + '-';
                  document.forms[0].ed16.value = data;
      return true;              
              }
                       }
//OnKeyUp="mascaraCEP(this);"   

//onkeypress="return SomenteNumero(event)" AO DIGITAR                     
function SomenteNumero(e){
var tecla=(window.event)?event.keyCode:e.which;
if((tecla > 47 && tecla < 58)) 
return true;
else{
if (tecla != 8) 
return false;
else 
return true;
}
}

function LimpaCep(cep)
{
    return cep.toString().replace(/[^0-9]/, "");
}

//onkeyup="this.value = LimpaCep(this.value)"> AO SAIR


7