
	function validateForm(_form_,_data_) {

        if (!(_data_ instanceof Object))
            return false;

        for(var i in _data_) {
            if (!validateInput(i,_data_)) //checkField
                return false;
        }

        return true;
    }

    function validateInput(_input_,_data_) {
        var d = _data_[_input_];
        if (d instanceof Object) {

            var vinput = $('#' + _input_)[0];
            var vvalue = $('#' + _input_).val();

            if (typeof(vinput) != 'object') {

                showmsg(sprintf('El campo "%s" no se encontro', d.name));
                return false;

                }

            unfocused(vinput);

            if (!vvalue.length && !d.allownull) {

                focused(vinput);
                showmsg(sprintf('El campo "%s" es obligatorio', d.name));

                return false;

            } else {

    			if (d.min != null  && vvalue.length < d.min) {

                    focused(vinput);
    				showmsg(sprintf('Es necesario que el campo "%s" tenga por lo menos %d caracteres.', d.name, d.mim));

    				return false;

    			} else if (d.max != null  && vvalue.length > d.max) {

                    focused(vinput);
    				showmsg(sprintf('El campo "%s" no puede contener mas de %d caracteres. Elimine %d caracteres', d.name, d.max, vvalue.length - d.max));

    				return false;

    			}

    			if (d.expresion != null) {

    				if (typeof(d.expresion) == 'string') {
    					var expresion = new RegExp(d.expresion);
    				} else {
    					var expresion = d.expresion;
    				}

    				if (expresion.exec(vvalue) == null) {
    					showmsg(sprintf('Escriba correctamente el texto del campo "%s"', d.name) + (d.format==null ? "" : " " + d.format));

    					focused(vinput);
    					return false;
    				}
    			}

                return true;
            }
        }
    }

	//Estas funciones deberian ser modificadas
	//para otros proyectos.
	function showmsg(msg) {
		//alert(msg);   //Mostrar un mensaje
        $('#alert_menssage').html(msg);
	}

    function deletemsg() {
        showmsg('');
    }

	function focused(element) {

        style_memory[element.name] = savestyle(element,style_focus);
        changestyle(element,style_focus);

	}

    //Eliminar el halo
	function unfocused(element) {

        if (element == null)
            return;

        if (style_memory[element.name] != null) {
            changestyle(element, style_memory[element.name]);
        }

	}

    function unfocused_all(_data_) {

        if (!(_data_ instanceof Object))
            return false;

        for(var i in _data_) {
            unfocused($(i));
        }

    }

    function savestyle(element, styleObj) {

        if (!(styleObj instanceof Object))
            return;

        var r = new Object();
        for(var i in styleObj) {
            //alert('guardar stylo '+i+'='+element.style[i]);
            r[i] = element.style[i];
        }
        return r;
    }

    function changestyle(element, styleObj) {
        if (!(styleObj instanceof Object))
            return;

        for(var i in styleObj) {
            //alert('asignar estilo '+i+'='+styleObj[i]);
            element.style[i] = styleObj[i];
        }
    }
