(function($) {

$.validator.addMethod("xss", function(value, element) {
    if (value.length == 0)
        return true;
    
    var startIndex = 0;
    while (true) {
        var pos = value.indexOf('&', startIndex);
        if (pos < 0)
            pos = value.indexOf('<', startIndex);
        if (pos < 0)
            return true;
        if (pos == value.length - 1)
            return true;
        var ch = value.charAt(pos);
        var ch2 = value.charAt(pos + 1);
        if (ch != '&') {
            if ((ch == '<') && ((((ch2 >= 'a' && ch2 <= 'z') || (ch2 >= 'A' && ch2 <= 'Z')) || (ch2 == '!')) || (ch2 == '/')))
                return false;
        }
        else if (ch2 == '#')
            return false;
         
        startIndex = pos + 1;
    }
});

$.validator.addMethod("datePI", function(value, element) {
    return this.optional(element) || $.pi.parseDate(value) != false;
});

$.validator.addMethod("decimalPI", function(value, element) {
    return this.optional(element) ||!isNaN($.pi.parseDecimal(value));
});

$.validator.addMethod("decimalMax42PI", function(value, element) {
    if (this.optional(element) || !isNaN($.pi.parseDecimal(value))) {
       value = $.trim(value) || '';
       var p = value.indexOf($.pi.defaultDecimalChar);
       return ((p < 0 && value.length < 3) ||
               (p > 0 && p <= 2 && value.length - p - 1 < 3));
    }
    return false;
});


$.validator.addMethod("decimalMax182PI", function(value, element) {
    if (this.optional(element) || !isNaN($.pi.parseDecimal(value))) {
       value = $.trim(value) || '';
       var p = value.indexOf($.pi.defaultDecimalChar);
	console.log(p);
       return ((p < 0 && value.length < 17) ||
               (p > 0 && p <= 16 && value.length - p - 1 < 3));
    }
    return false;
});

$.validator.addMethod("integerPI", function(value, element) {
    return this.optional(element) ||!isNaN($.pi.parseInteger(value));
});

$.validator.addMethod("anyvalue", function(value, element) {
    return true;
});

})(jQuery);