jQuery.fn.extend({
    highlight: function(startColor, endColor, speed) {
        this.animate({ backgroundColor: startColor || '#ffff99' }, speed || 350)
      .animate({ backgroundColor: endColor || '#ffffff' }, speed || 350);
        return this;
    },

    // sends an ajax request and highlights the element who sent the request, return script is not evaluated.
    remoteUpdate: function(url, s) {
        s = jQuery.extend({ type: 'POST', dataType: 'html', global: true, data: '', startColor: '#ffff99', endColor: '#ffffff', errorColor: '#CC0000', error: null, success: null }, s);
        var el = this;
        jQuery.ajax({ url: url, data: s.data, type: s.type, global: s.global, dataType: s.dataType,
            success: function(d, ts) {
                el.highlight(s.startColor, s.endColor);
                if (s.success) s.success(d, ts);
            },
            error: function(xr, ts, e) {
                el.highlight(s.errorColor, s.endColor);
                if (s.error) s.error(xr, ts, e);
            }
        });
    }
});

if(jQuery.validator) {
    jQuery.validator.addMethod("inSet", function(value, element, params) {
        return this.optional(element) || function() {
            var check = false;
            jQuery.each(params, function() { return !(check = (value == this)); });
            return check;
        } ();
    }, "The value is not one of the permitted values");

    jQuery.validator.addMethod("gtDate", function(value, element, param) {
        return this.optional(element) || new Date(value) > (param[0] === '#' ? new Date(jQuery(param).val()) : new Date(param));
    }, "The date is less than the expected date");

    jQuery.validator.addMethod("gteDate", function(value, element, param) {
        return this.optional(element) || new Date(value) >= (param[0] === '#' ? new Date(jQuery(param).val()) : new Date(param));
    }, "The date is less than the expected date");

    jQuery.validator.addMethod("ltDate", function(value, element, param) {
        return this.optional(element) || new Date(value) < (param[0] === '#' ? new Date(jQuery(param).val()) : new Date(param));
    }, "The date is greater than the expected date");

    jQuery.validator.addMethod("lteDate", function(value, element, param) {
        return this.optional(element) || new Date(value) <= (param[0] === '#' ? new Date(jQuery(param).val()) : new Date(param));
    }, "The date is greater than the expected date");

    jQuery.validator.addMethod("gtNum", function(value, element, param) {
        return this.optional(element) || (+value) > (param[0] === '#' ? (+jQuery(param).val()) : (+param));
    }, "The number is less than the expected number");

    jQuery.validator.addMethod("gteNum", function(value, element, param) {
        return this.optional(element) || (+value) >= (param[0] === '#' ? (+jQuery(param).val()) : (+param));
    }, "The number is less than the expected number");

    jQuery.validator.addMethod("ltNum", function(value, element, param) {
        return this.optional(element) || (+value) < (param[0] === '#' ? (+jQuery(param).val()) : (+param));
    }, "The number is greater than the expected number");

    jQuery.validator.addMethod("lteNum", function(value, element, param) {
        return this.optional(element) || (+value) <= (param[0] === '#' ? (+jQuery(param).val()) : (+param));
    }, "The number is greater than the expected number");

    jQuery.validator.addMethod("lteNum", function(value, element, param) {
        return this.optional(element) || (+value) <= (param[0] === '#' ? (+jQuery(param).val()) : (+param));
    }, "The number is greater than the expected number");

    jQuery.validator.addMethod("decimalnumber", function(value, element, param) {
        var reg = new RegExp("^\\d{0,2}(\\.\\d{0,2})?$", "g");
        return reg.test(value);
    }, "Not a valid decimal number");
}

/* EOF */