	function limpa_string(S) // Deixa só os digitos no numero
	{
			var Digitos = "0123456789";
			var temp = "";
			var digito = "";
			var primeiro = "";
			var ultimo = "";
			var soma = 1;
			
		   	for (var i=0; i<S.length; i++)
			{
				digito = S.charAt(i);
				if (Digitos.indexOf(digito)>=0)
				{
					if (i==1)
					{
						primeiro = digito;
					}
					
					if (parseInt(digito)==parseInt(primeiro))
					{
						soma++;
					}					
					
					temp=temp+digito
				}
			}
			
			if (soma > 7)
			{
				temp = "";
			}
			return temp
	}
		
	function validar_num(campo)
	{
		nome=campo.name
		num = limpa_string(campo.value);
		campo.value = num;
	}
	
	function validaCompras(formu)
	{
		if (formu.QTD_OFE.value==0 || formu.QTD_OFE.value=="")
		{
			alert("Informe corretament a quantidade");
			formu.QTD_OFE.focus();
			return false;
		}
		if (formu.VAL_OFE.value==0 || formu.VAL_OFE.value=="")
		{
			alert("Informe corretament o Valor");
			formu.VAL_OFE.focus();
			return false;
		}
		
	}
	
	function retornaValoresCombo(formu)
{		
		var tamanho = formu.length;		
		var valortxt="";
		
		for (i=0;i<tamanho; i++)
		{
				//nomeCampo = formu.name;
				campo = formu.elements[i];
				nomeCampo = campo.name;
				tipo = campo.type;
				
				alert(tipo);
				
				if (tipo=="combo" &&  nomeCampo!="STA_OPO" )
				{
					if (campo.selected == true)
					{
						if (valortxt!=""){valortxt=valortxt + ",";}				
						valor = campo.value;
						valortxt = valortxt + valor;
					}
				}				
		}
		return valortxt;
}

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;
}

//Formata número tipo moeda usando o evento onKeyDown

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 abreJanela(url)
{
	var Janela = window.open(url, "Janela", "width=200, height=200, scrollbars=yes, top=1, left=1");
	Janela.focus();

}

