//Função que faz passar o cursor de um textbox para outro (frente e trás)
function ValidaData(obj)
{
	var tecla;
	var destino;
	var campo;
	var accao;
	
	if (document.layers)
	{
		tipo = e.type;
		tecla=e.which;
		destino=e.target;
	}
	else
	{
		tipo = event.type;
		tecla=event.keyCode;
		destino=event.srcElement;
	}

		x=(obj.value.length);
		k=(obj.name);
		
		//alert(tecla);
		
		//alert(k);
		//alert(x);
		
		if (tipo == "keyup" && tecla != 8)
		{
			switch (k)
			{
			
				case "dia_inicial":
					if (x==2)
					{
						document.form_montante.mes_inicial.focus();
					}
					break;
					
				case "mes_inicial":
					if (x==2)
					{
						document.form_montante.ano_inicial.focus();
					}
					break;
					
				case "ano_inicial":
					if (x==4)
					{
						document.form_montante.dia_final.focus();
					}
					break;	
				
				case "dia_inicial2":
					if (x==2)
					{
						document.form_montante.mes_inicial2.focus();
					}
					break;
					
				case "mes_inicial2":
					if (x==2)
					{
						document.form_montante.ano_inicial2.focus();
					}
					break;
					
				case "ano_inicial2":
					if (x==4)
					{
						document.form_montante.dia_resgate.focus();
					}
					break;
					
				case "dia_resgate":
					if (x==2)
					{
						document.form_montante.mes_resgate.focus();
					}
					break;
					
				case "mes_resgate":
					if (x==2)
					{
						document.form_montante.ano_resgate.focus();
					}
					break;
					
				case "dia_final":
					if (x==2)
					{
						document.form_montante.mes_final.focus();
					}
					break;		
				
				case "mes_final":
					if (x==2)
					{
						document.form_montante.ano_final.focus();
					}
					break;
					
				case "ano_final":
					if (x==4)
					{
						document.form_montante.taxa_futuro.focus();
					}
					break;				
				
				case "dia_inicial_pro":
					if (x==2)
					{
						document.form_montante.mes_inicial_pro.focus();
					}
					break;				
					
				case "mes_inicial_pro":
					if (x==2)
					{
						document.form_montante.taxa_bruta.focus();
					}
					break;					
				
			}
		}
	
		else if (tipo == "keyup" && tecla == 8)
		{
			switch (k)
			{
				case "taxa_futuro":
					if (document.form_montante.taxa_futuro.value.length == 0)
					{
						document.form_montante.ano_final.focus();
						
						if (document.all)
						{
							tr = document.form_montante.ano_final.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
					
				case "ano_final":
					if (document.form_montante.ano_final.value.length == 0)
					{
						document.form_montante.mes_final.focus();
						
						if (document.all)
						{
							tr = document.form_montante.mes_final.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
					
				case "mes_final":
					if (document.form_montante.mes_final.value.length == 0)
					{
						document.form_montante.dia_final.focus();
						
						if (document.all)
						{
							tr = document.form_montante.dia_final.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
					
				case "dia_final":
					if (document.form_montante.dia_final.value.length == 0)
					{
						document.form_montante.ano_inicial.focus();
						
						if (document.all)
						{
							tr = document.form_montante.ano_inicial.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;		
						
					
				case "ano_inicial":
					if (document.form_montante.ano_inicial.value.length == 0)
					{
						document.form_montante.mes_inicial.focus();
						
						if (document.all)
						{
							tr = document.form_montante.mes_inicial.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;

				case "mes_inicial":
					if (document.form_montante.mes_inicial.value.length == 0)
					{
						document.form_montante.dia_inicial.focus();

						if (document.all)
						{
							tr = document.form_montante.dia_inicial.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
			
				case "ano_inicial":
					if (document.form_montante.mes_inicial.value.length == 0)
					{
						document.form_montante.dia_inicial.focus();

						if (document.all)
						{
							tr = document.form_montante.dia_inicial.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
				
				case "mes_inicial2":
					if (document.form_montante.mes_inicial2.value.length == 0)
					{
						document.form_montante.dia_inicial2.focus();

						if (document.all)
						{
							tr = document.form_montante.dia_inicial2.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
				
				case "ano_inicial2":
					if (document.form_montante.ano_inicial2.value.length == 0)
					{
						document.form_montante.mes_inicial2.focus();

						if (document.all)
						{
							tr = document.form_montante.mes_inicial2.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
				
				case "dia_resgate":
					if (document.form_montante.dia_inicial.value.length == 0)
					{
						document.form_montante.ano_inicial2.focus();

						if (document.all)
						{
							tr = document.form_montante.ano_inicial2.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
				
				case "mes_resgate":
					if (document.form_montante.mes_resgate.value.length == 0)
					{
						document.form_montante.dia_resgate.focus();

						if (document.all)
						{
							tr = document.form_montante.dia_resgate.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;

				case "ano_resgate":
					if (document.form_montante.ano_resgate.value.length == 0)
					{
						document.form_montante.mes_resgate.focus();

						if (document.all)
						{
							tr = document.form_montante.mes_resgate.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;

				case "dia_final":
					if (document.form_montante.mes_inicial.value.length == 0)
					{
						document.form_montante.dia_inicial.focus();

						if (document.all)
						{
							tr = document.form_montante.dia_inicial.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
				
				case "mes_final":
					if (document.form_montante.mes_inicial.value.length == 0)
					{
						document.form_montante.dia_inicial.focus();

						if (document.all)
						{
							tr = document.form_montante.dia_inicial.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
					
				case "ano_final":
					if (document.form_montante.mes_inicial.value.length == 0)
					{
						document.form_montante.dia_inicial.focus();

						if (document.all)
						{
							tr = document.form_montante.dia_inicial.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
					
				case "mes_inicial_pro":
					if (document.form_montante.mes_inicial_pro.value.length == 0)
					{
						document.form_montante.dia_inicial_pro.focus();

						if (document.all)
						{
							tr = document.form_montante.dia_inicial_pro.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
				
				case "taxa_bruta":
					if (document.form_montante.taxa_bruta.value.length == 0)
					{
						document.form_montante.mes_inicial_pro.focus();

						if (document.all)
						{
							tr = document.form_montante.mes_inicial_pro.createTextRange()
							tr.moveStart("word",1)
							tr.select()
						}
					}
					break;
					
			}
		}	
}

if(document.layers)
{
	document.captureEvents(Event.KEYPRESS);
	document.onkeypress=ValidaData;
	document.captureEvents(Event.KEYUP);
	document.onkeyup=ValidaData;
}

