// JavaScript Document
function validaBB () {
	var erro="";
	if (document.bb.id_cliente2.value == 0) {
		erro = erro + "\n O número do seu código junto ao sindicato deve ser preenchido!";
	} 	
	if (erro=="") {
		return true;
	}	else {
		alert ("Atenção!\n" + erro);
		return false;
	}		
}

function validaCaixa () {
	var erro="";
	
	if (document.caixa.id_cliente.value== 0) {
		erro = erro + "\n O NÚMERO DO SEU CÓDIGO junto ao Sindicato deve ser preenchido!";
	} 	
	if (document.caixa.vencimento.value== "") {
		erro = erro + "\n A DATA DE VECIMENTO é de preenchimento obrigatório!";
	} 	
	if (document.caixa.exercicio.value== "") {
		erro = erro + "\n O ANO DE EXERCÍCIO é de preenchimento obrigatório!";
	} 	
	if (erro=="") {
		return true;
	}	else {
		alert ("Atenção!\n" + erro);
		return false;
	}		
}


function retorna(){
	var para     = "";
	var sRetorno = "";
	param = "&id_titulo=" + document.bb.id_cliente.value;

	window.returnValue = param;
    window.close();
}

function retorna(){
	var para     = "";
	var sRetorno = "";
	param = "&id_titulo=" + document.caixa.id_cliente2.value;

	window.returnValue = param;
    window.close();
}

function buscaId_cliente2(campo){
	var codigo = window.showModalDialog('pesquisa.php','buscaId_cliente2','dialogWidth:400px; dialogHeight:320px; center:no; status:no; resizable=no');
	if (codigo != null){
		if (codigo != document.bb.id_cliente2.value) {
			document.bb.id_cliente2.value = codigo;
		}
	}
}


function buscaId_cliente(campo){
	var codigo = window.showModalDialog('pesquisa.php','buscaId_cliente','dialogWidth:400px; dialogHeight:320px; center:no; status:no; resizable=no');
	if (codigo != null){
		if (codigo != document.caixa.id_cliente.value) {
			document.caixa.id_cliente.value = codigo;
		}
	}
}

function Limpar(valor, validos) {
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}

function Formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

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 <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
campo.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 numerico(e){
		if (document.all) // Internet Explorer
			var tecla = event.keyCode;
	 	else if(document.layers) // Nestcape
	  		var tecla = e.which;
	  	if (tecla > 47 && tecla < 58) // numeros de 0 a 9
	   		return true;
	  	else{
			if (tecla != 8) // backspace
		 		event.keyCode = 0;
		 		//return false;
			else
		 		return true;
	  	 }
	}

	function decimal(e){
		if (document.all) // Internet Explorer
			var tecla = event.keyCode;
		else if(document.layers) // Nestcape
			var tecla = e.which;
	  
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else{
			if (tecla != 8 && tecla != 44) // backspace e virgula
	   			event.keyCode = 0;
	   			//return false;
	 		else
	   			return true;
	 	}
	}		
