﻿//
// Revium jquery extensions
// Copyright (c) 2009 Revium pty ltd http://revium.com.au
// Licensed under the GPL licence:
// http://www.gnu.org/licenses/gpl.html
//

(function($) {
    // To capitalise text input when user types in (to make just the 1st symbol uppercase)
    // Developed by Evgeny Petrov, Revium
    // Ver 1.0, 24/11/2009
    $.fn.capitalise = function() {
        $(this).keyup(function() {
            var el = $(this);
            var value = "";
            if (el.length > 0) {
                value = el.val().toString().substr(0, 1).toUpperCase() + el.val().toString().substr(1);
            }
            el.val(value);
        });
    }

    // To cancel clipboard paste event
    // Developed by Evgeny Petrov, Revium
    // Ver 1.0, 24/11/2009
    $.fn.nopaste = function() {
        $(this).bind('paste', function(e) {
            e.preventDefault();
        });
    }

    //To click default button when Enter key is hit. 
    //Custom selectors are used insead of predefined (aka "deafult" class) to give it extra flexibility.
    // Developed by Evgeny Petrov, Revium
    // Ver 1.0, 13/01/2010
    $.fn.clickbutton = function(button_selector) {
        $(this).keypress(function(e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                $(button_selector).click();
                return false;
            } else {
                return true;
            }
        });
    }

})(jQuery);

function SetValidationMsg(rule, msg) {
    if (typeof $.validator != 'function') {
        return;
    }
    
    if (typeof $.validator.messages[rule] == 'string') {
        $.validator.messages[rule] = msg;
    } else if (typeof $.validator.messages[rule] == 'function') {
        $.validator.messages[rule] = $.validator.format(msg);
    }
}

