/*
	FIELDCHECK
	<input type="text" id="nombre" name="NOMBRE" control="TEXT" obligatorio="yes" maxlength="1024"/>
 */
window.fwk.common.fieldCheck=
	{
		check : function(ob)
			{
				tipo=$(ob).attr("control");
				//alert(tipo);
				switch(tipo)
				{
					case "TEXT"		: return(this.checkText(ob)); break;
					case "PASSWORD"	: return(this.checkPassword(ob)); break;
					case "DATE"		: return(this.checkDate(ob)); break;
					case "RADIO"	: return(this.checkRadio(ob)); break;
					case "SELECT"	: return(this.checkSelect(ob)); break;
					default			: return(true);
				}
			}
		,checkText : function(ob)
			{
				$this=$(ob);
				id=$this.attr("id");
				obligatorio=$this.attr("obligatorio");
				max=parseInt($this.attr("maxlength"));
				val=$this.val();
				$this_obligatorio=$("#"+id+"_error_obligatorio").hide();
				$this_max=$("#"+id+"_error_max").hide();
				ok=true;
				if(obligatorio=='yes') if(val.length==0) { $this_obligatorio.show(); ok=false; }
				if(max>0) if(val.length>max) { $this_max.show(); ok=false; }
				return(ok);
			}
		,checkPassword : function(ob)
			{
				$this=$(ob);
				id=$this.attr("id");
				obligatorio=$this.attr("obligatorio");
				max=parseInt($this.attr("maxlength"));
				val=$this.val();
				segundo=(id.substr(-1)=='2');
				$this_concordancia=$("#"+id+"_error_concordancia").hide();
				$this_obligatorio=$("#"+id+"_error_obligatorio").hide();
				$this_max=$("#"+id+"_error_max").hide();

				ok=true;
				if(obligatorio=='yes') if(val.length==0) { $this_obligatorio.show(); ok=false; }
				if(max>0) if(val.length>max) { $this_max.show(); ok=false; }
				if(ok && segundo)
				{
					$primero=$("#"+id.substr(0,id.length-1));
					if(val!=$primero.val()) { $this_concordancia.show(); ok=false; }
				}
				return(ok);
			}
		,checkDate : function(ob)
			{
				$this=$(ob);
				id=$this.attr("id");
				obligatorio=$this.attr("obligatorio");
				val=$this.val();
				$this_obligatorio=$("#"+id+"_error_obligatorio").hide();
				ok=true;
				if(obligatorio=='yes')
				{
					datos=val.split("-");
					if( datos[0]=="" || datos[1]=="" || datos[2]=="" ) { $this_obligatorio.show(); ok=false; }
				}
				return(ok);
			}
		,checkRadio : function(ob)
			{
				//los radios se dibujan con la primera opcion chequeada,
				//para no volvernos locos chequeando en JS
				return(true);
			}
		,checkSelect : function(ob)
			{
				$this=$(ob);
				id=$this.attr("id");
				obligatorio=$this.attr("obligatorio");
				val=$this.val();
				$this_obligatorio=$("#"+id+"_error_obligatorio").hide();
				ok=true;
				if(obligatorio=='yes') if(val=="") { $this_obligatorio.show(); ok=false; }
				return(ok);
			}
	}

