function Tecla_apenas_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 Formata_apenas_numero(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
var dec=decimal

  

campo.value = vr.substr( 0, tam)   ;


}



function Minha_funcao_Left_inputjs(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Minha_funcao_Right_inputjs(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function Limpar(valor, validos) {
// retira caracteres invalidos da string
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_valor_real_peso(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
var dec=decimal


if  (tam ==0){
 vr='00'+vr;

}

if  (tam ==1){
 vr='00'+vr;

}
if  (tam ==2){
 vr='0'+vr;
}
if  (tam ==3){
 vr='0'+vr;
}
if (tam>4) {
   if (vr.substr( 0, 1)=='0') {
      vr= vr.substr(1,(tam-1));
      tam=tam-1;
      }

}

campo.value = vr.substr( 0, tam - dec ) + "." + vr.substr( tam - dec, 3 ) ;


}





function Formata_valor_real(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
var dec=decimal


if  (tam ==0){
 vr='00'+vr;

}

if  (tam ==1){
 vr='00'+vr;

}
if  (tam ==2){
 vr='0'+vr;
}
if (tam>3) {
   if (vr.substr( 0, 1)=='0') {
      vr= vr.substr(1,(tam-1));
      tam=tam-1;
      }

}

campo.value = vr.substr( 0, tam - dec ) + "." + vr.substr( tam - dec, 2 ) ;


}


function Formata_valor_inteiro(campo,tammax,teclapres,dec) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;

if  (tam ==0){
 vr='00'+vr;

}

if  (tam ==1){
 vr='00'+vr;

}
if  (tam ==2){
 vr='0'+vr;
}
if (tam>3) {
   if (vr.substr( 0, 1)=='0') {
      vr= vr.substr(1,(tam-1));
      tam=tam-1;
      }

}

campo.value = vr.substr( 0, tam - dec ) ;


}






function ativa_txt_financeiro(ativa) {

		if ( ativa == 'A' ) {
				document.all.tr_marca_c.style.display = '';
				document.all.tr_marca_m.style.display = 'none';
				document.all.tr_equip_c.style.display = '';
				document.all.tr_equip_m.style.display = 'none';
				document.all.td_comb_c.style.display  = '';
		} else {
				document.all.tr_marca_c.style.display = 'none';
				document.all.tr_marca_m.style.display = '';
				document.all.tr_equip_c.style.display = 'none';
				document.all.tr_equip_m.style.display = '';
				document.all.td_comb_c.style.display  = 'none';
		}

}







function NewWindow(mypage, myname, w, h, scroll) {
         var winl = (screen.width - w) / 2;
         var wint = (screen.height - h) / 2;
         winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
         win = window.open(mypage, myname, winprops)
         if (parseInt(navigator.appversion) >= 4) { win.window.focus(); }
         }

function NewWindowPlano(mypage, myname, w, h, scroll) {
         var winl = (screen.width - w) / 2;
         var wint = (screen.height - h) / 2;
         winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
         win = window.open(mypage, myname, winprops)
         if (parseInt(navigator.appversion) >= 4) { win.window.focus(); }
}

function plano_user_contas(id_obj) {
         var retorno;
 		 retorno = showModalDialog('plano_user.php?title=Plano de contas&usercnpjcpf='+document.all[id_obj].value,'resizable: no; help: no; status: no; scroll: no;');
         return;
         }




function plano_user_movimento(id_obj,id_parametros,id_filtro) {
         var retorno;
 		 retorno = showModalDialog('plano_user.php?filtro='+document.all[id_filtro].value+'&valordocampoanterior='+document.all[id_obj].value+'&parametros='+document.all[id_parametros].value,document.all[id_obj].value,'resizable: no; help: no; status: no; scroll: no;');
         if ( !retorno )
		    return;
		 document.all[id_obj].value = retorno;
         document.all[id_filtro].value='';
         }







function escolhe_e_altera_lista(id_obj,id_parametros,id_filtro) {

		var retorno;
 		retorno = showModalDialog('escolha_lista.php?filtro='+document.all[id_filtro].value+'&valordocampoanterior='+document.all[id_obj].value+'&parametros='+document.all[id_parametros].value,document.all[id_obj].value,'resizable: no; help: no; status: no; scroll: no;');

				
		
		

		if ( !retorno )
				return;
		document.all[id_obj].value = retorno;
        document.all[id_filtro].value='';

  }






function altera_value_cor(id_obj) {
		var cor;
		var id_obj_view = id_obj+'_mostra';
		var id_obj_hexa = id_obj+'_hexa';
		
		cor = showModalDialog('input_cor.php',document.all[id_obj].value,'resizable: no; help: no; status: no; scroll: no;');
		if ( !cor )
				return;
		document.all[id_obj].value        = cor;
		document.all[id_obj_view].bgColor = cor;
		document.all[id_obj_hexa].value   = cor;
}





function altera_value_som_topo(id_obj) {
		var modelo;
		modelo = showModalDialog('includes/input_som_topo.php?som_topo='+document.all[id_obj].value,document.all[id_obj].value,'resizable: no; help: no; status: no; scroll: no;');
		if ( !modelo )
				return;
		document.all[id_obj].value = modelo;
}



function altera_value_gerente(id_obj) {
		var gerente;
		gerente = showModalDialog('input_gerente.php?gerente='+document.all[id_obj].value,document.all[id_obj].value,'resizable: no; help: no; status: no; scroll: no;');
		if ( !gerente )
				return;
		document.all[id_obj].value = gerente;
}




function altera_value_cliente(id_obj) {
		var cliente;
		cliente = showModalDialog('includes/input_cliente.php?cliente='+document.all[id_obj].value,document.all[id_obj].value,'resizable: no; help: no; status: no; scroll: no;');
		if ( !cliente )
				return;
		document.all[id_obj].value = cliente;
}

function retira_pontos ( s ) {
		var aux = "";

        function Limpar(valor, validos) {
        // retira caracteres invalidos da string
        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;
}





		for (i = 0; i < s.length; i++) {
				c = s.charAt(i);
				if ( c != '.' && c != ',' )
						aux += c;
		}

		return aux;
}
// 1.300.500,00
// 130050000
function formata_valor ( campo ) {
		var aux = "";
		var c   = 0;
		var s   = retira_pontos(document.all[campo].value);
		var fim = s.length;
		var strCheck = '0123456789';

		if ( fim > 2 ) {
				aux = "." + s.substring(fim-2, fim);
				for (i = fim-3; i >= 0; i--) {

						aux = s.charAt(i) + aux;
				}
		} else {
				aux = s;
		}

		document.all[campo].value = aux;
}

function formata_valor4 ( campo ) {
		var aux = "";
		var c   = 0;
		var s   = retira_pontos(document.all[campo].value);
		var fim = s.length;
		var strCheck = '0123456789';

		if ( fim > 2 ) {
				aux = "." + s.substring(fim-4, fim);
				for (i = fim-5; i >= 0; i--) {

						aux = s.charAt(i) + aux;
				}
		} else {
				aux = s;
		}

		document.all[campo].value = aux;
}


