﻿
jQuery.format = function(source, params) {
    if (arguments.length == 1)
        return function() {
            var args = jQuery.makeArray(arguments);
            args.unshift(source);
            return jQuery.format.apply(this, args);
        };
    if (arguments.length > 2 && params.constructor != Array) {
        params = jQuery.makeArray(arguments).slice(1);
    }
    if (params.constructor != Array) {
        params = [params];
    }
    jQuery.each(params, function(i, n) {
        source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
    });
    return source;
};


jQuery.validator.addMethod(
    'RequiredSelection', 
    function(value, element) 
    {
        if (element.value == '0' || element.value == '') 
        {
            return false;
        }
        else 
        {
            return true;
        }
    },
    'This field is required.'
);
        
jQuery.validator.addMethod(
    'ImageOnly', 
    function(val, element) 
    {
        if (val == '') return true;
                                    
        var ext = val.split('.').pop().toLowerCase(); 
        var allow = new Array('gif','png','jpg','jpeg'); 

        if(jQuery.inArray(ext, allow) == -1) { 
            return false; 
        }
                
        return true;
    },
    'Only image file are allowed.'
);
