var No_enter_form	= Class.create();
No_enter_form.prototype = {
	initialize : function(id_forma,instancia)
	{
		try{
			this.id_forma				= id_forma;
			this.instancia				= instancia;
			this.Num 					= 0;
			this.siguiente_bandera		= 0;
			this.elementos				= Form.getElements($(this.id_forma));
			this.key_saltar				= new Array();
			this.key_saltar[0]			= "37";//'left'
			this.key_saltar[1]			= "39";//'rigth'
			this.key_saltar[2]			= "40";//'down'
			this.key_saltar[3]			= "38";//'up'
			this.key_saltar[4]			= "35";//'fin'
			this.key_saltar[5]			= "36";//'inicio'
			this.key_saltar[6]			= "39";//'tab'
			this.key_saltar[7]			= "46";//'supr'
			this.reactivar();
		}catch(ex)
		{
			alert("initialize::" + ex);
		}
	}
	,
	actualizar_elementos:function()
	{
		try{
			this.elementos	= Form.getElements($(this.id_forma));
		}catch(ex)
		{
			alert("actualizar_elementos::" + ex);
		}
	}
	,
	nuevo_elemento:function(elemento)
	{
		try{
			eval("Event.observe($('" + elemento + "'), 'keypress', function(e){if(!e)e=window.event; if (e.keyCode) code=e.keyCode; else if (e.which) code=e.which; " + this.instancia + ".no_enter(code,'" + elemento + "')});");
			eval("Event.observe($('" + elemento + "'), 'keyup', function(e){if(!e)e=window.event; if (e.keyCode) code=e.keyCode; else if (e.which) code=e.which; " + this.instancia + ".maxlen(code,'" + elemento + "')});");
		}catch(ex)
		{
			alert("nuevo_elemento::" + ex);
		}
	}
	,
	refrescar_id:function(id)
	{
		try{
			this.actualizar_elementos();
			temp_elementos	= Form.getElements($(id));
			for(var i=0;i<=temp_elementos.length;i++)
			{
				if(typeof(temp_elementos[i]) == 'object')
				{
					if(temp_elementos[i].id)
					{
						this.nuevo_elemento(temp_elementos[i].id);
					}
				}
			}
		}catch(ex)
		{
			alert("refrescar_id::" + ex);
		}
	}
	,
	reactivar:function()
	{
		try{
			this.refrescar_id(this.id_forma);
		}catch(ex)
		{
			alert("reactivar::" + ex);
		}
	}
	,
	no_enter_recurcion:function (code,id_campo)
	{
		try{
			this.no_enter(code,id_campo);
		}catch(ex)
		{
			alert("no_enter_recurcion::" + ex);
		}
	}
	,
	siguiente:function (Siguiente)
	{
		try{
		   this.actualizar_elementos();
			if (Siguiente <this.elementos.length)
			{
				if((this.elementos[Siguiente].disabled==false) && (this.elementos[Siguiente].style.visibility!='hidden') && (this.elementos[Siguiente].style.display!='none') && (this.elementos[Siguiente].type!='hidden') && (this.elementos[Siguiente].id!='undefined'))
				{
					try{
						this.elementos[Siguiente].focus();
	     				}catch(ex){}
				}
				else if ((Siguiente + 1)<this.elementos.length)
				{
					no_enter_recursivo_siguiente(this.instancia,(Siguiente + 1));
				}
				else
				{
					no_enter_recursivo_siguiente(this.instancia,1);
				}
			}
			else
			{
				no_enter_recursivo_siguiente(this.instancia,1);
			}
		}catch(ex)
		{
			alert("siguiente::" + ex);
		}
	}
	,
	maxlen:function(code,id_campo)
	{
		try{
			if(($(id_campo).maxLength > 0 && ( $F(id_campo).length )>=$(id_campo).maxLength) || (this.siguiente_bandera==1) )
			{
				this.actualizar_elementos();
				var validacion = 1;
				for(var n=0; n<=this.key_saltar.length; n++)
				{
					if(this.key_saltar[n]==code)
					{
						validacion = 0;
					}
				}
			}
			if(($(id_campo).maxLength > 0 && ( $F(id_campo).length )>=$(id_campo).maxLength) )
			{
				if(validacion==1)
				{
					var seguridad=1;
					for(var i=0;i<=this.elementos.length;i++)
					{
						Siguiente=i+1;
						if(seguridad==1 && typeof(this.elementos[i]) == 'object' && $(id_campo).id==this.elementos[i].id && Siguiente<this.elementos.length)
						{
							this.Siguiente_seleccionado	= Siguiente;
							this.siguiente_bandera		= 1;
							seguridad					= 0;
							break;
						}
					}
				}
			}
			if(this.siguiente_bandera==1 && validacion==1)
			{
				this.siguiente(this.Siguiente_seleccionado);
			}
		}catch(ex)
		{
			alert("maxlen::" + ex);
		}
	}
	,
	no_enter:function(code,id_campo)
	{
		try{
		   this.actualizar_elementos();
			this.siguiente_bandera	= 0;
			if(code=='13' )
			{
				var seguridad=1;
				for(var i=0;i<=this.elementos.length;i++)
				{
					Siguiente=i+1;
					if(seguridad==1 && typeof(this.elementos[i]) == 'object' && $(id_campo).id==this.elementos[i].id && Siguiente<this.elementos.length)
					{
						this.Siguiente_seleccionado	= Siguiente;
						this.siguiente_bandera		= 1;
						seguridad=0;
						break;
					}
				}
			}
		}catch(ex)
		{
			alert("no_enter::" + ex);
		}
	}
 };
function no_enter_recursivo_siguiente(instancia,numero)
{
	try{
		eval(instancia + ".siguiente(" + numero + ")");
	}catch(ex)
	{
		alert("no_enter_recursivo_siguiente::" + ex);
	}
}
