// JavaScript Documentfunction 
var Browser,Versao,OS,Site, IE=0, Gecko=1, Konqueror=2, Windows=0, Linux=1, Mac=2;
var msg1 = "Campo não pode ficar em branco!";
var msg2 = "Este campo deve ter pelo menos 1 dígito na parte inteira e 2 dígitos para centavos !\n\nEx.: 123.00";
var msg3 = "Este campo ou pode ficar em branco ou deve ter pelo menos 1 dígito na parte inteira e 2 dígitos para centavos !\n\nEx.: 123.00";
function validaForm()
{
	if(document.getElementById('txtvalor').value.length == "")
	{
		alert(msg1);
		document.getElementById('txtvalor').focus();
		return false;
	}
	else
	{
		var Numeros = /[^0-9,]/;
		var Virgula = document.getElementById('txtvalor').value.indexOf(".");
		if(Virgula == -1 || Virgula == 0 || Virgula != document.getElementById('txtvalor').value.length - 3)
		{
			alert(msg2); 
			document.getElementById('txtvalor').focus();
			return false;
		}
	}
		if(document.getElementById('txtsaldo').value.length != "")
		{
			var Numeros = /[^0-9,]/;
			var Virgula = document.getElementById('txtsaldo').value.indexOf(".");
			if(Virgula == -1 || Virgula == 0 || Virgula != document.getElementById('txtsaldo').value.length - 3)
			{
				alert(msg3); 
				document.getElementById('txtsaldo').focus();
				return false;
			}
		}
		
		if(document.getElementById('txtnum_parcel').value =="")
		{
			alert(msg1);
			document.getElementById('txtnum_parcel').focus();
			return false;
		}
		else 
		{
			if(document.getElementById('txtnum_parcel').value > 36 )
			{
				alert("O número máximo de parcelas são 36!");
				document.getElementById('txtnum_parcel').value = 36;
				document.getElementById('txtnum_parcel').focus();
				return false;
			}
		}
	/*	if(document.getElementById('txttr').value.length == "")
		{
			alert(msg1);
			document.getElementById('txttr').focus();
			return false;
		}
		else
		{
			var Numeros = /[^0-9,]/;
			var Virgula = document.getElementById('txttr').value.indexOf(".");
			if(Virgula == -1 || Virgula == 0 || Virgula != document.getElementById('txttr').value.length - 3)
				{
				alert(msg2); 
				document.getElementById('txttr').focus();
				return false;
			}
		}*/
	document.getElementById('form1').submit();	
}

function Numerico(e)
{
	var tecla;
	tecla  = e.keyCode;
	if (tecla == 0) //é mozilla
		tecla = e.charCode; // é para o Mozilla
	
	if (tecla < 30 || (tecla > 47 && tecla < 58)) 
	return;
	
	e.returnValue = false;				
	
	try
	{
		e.preventDefault();  // é para o Mozilla
	}
	catch(e){}							
}	

function NumDec(e)
{
	var Tecla, Valor;
	if(Browser==IE)
	{
		Tecla = e.keyCode;
		if(Tecla == 13)
		{		
			e.returnValue = false;
			return;
		}
		e.cancelBubble = true;
		Valor = e.srcElement.value;
		if(Tecla == 46)
		{
			if(Valor.indexOf(".") == -1)
			{
				if(Valor.length > 0 && Valor.length < e.srcElement.maxLength - 1)
				{
					return;
				}
				else
				{
					e.returnValue = false;
					return
				}
			}
			else
			{
				e.returnValue = false;
				return;
			}
		}
		if((Tecla > 47 && Tecla < 58) || Tecla < 20)
			return;
		else
			e.returnValue = false;
	}
	else
	{
		Tecla = e.charCode;
		if(Tecla == 13)
		{		
			e.preventDefault();
			return;
		}

		Valor = e.target.value;
		if(Tecla == 46)
		{
			if(Valor.indexOf(".") == -1)
			{
				return;
			}
			else
			{
				e.preventDefault();
				return;
			}
		}
		if((Tecla > 47 && Tecla < 58) || Tecla < 20)
			return;
		else
			e.preventDefault();
	}
}
function CampoDecimal(Campo)
{
	if(Campo.value.length != 0)
	{
		var Numeros = /[^0-9,]/;
		var Virgula = Campo.value.indexOf(".");
		if(Virgula == -1 || Virgula == 0 || Virgula != Campo.value.length - 3)
		{
			alert(msg2); 
			Campo.focus();
			return false;
		}
		if(Valor) Valor.value = Campo.value.substr(0, Virgula) + Campo.value.substr(Virgula + 1);
	}
	return true;
}
