
(function($) {

    var Shanti = function()
    {
        $(document).ready(this.ready);
    }

    Shanti.prototype = {

        ready: function()
        {

            $('form input[type="string"]').keyup(function() {
                if ($(this).val().length >= $(this).attr('maxlength')
                    && (next = $(':input')[ $(':input').index(this) + 1 ])) {
                    $(next).focus();
                }
            });

            $('input.myclass').each(function() {

                var value = $(this).val();

                $(this).attr( {
                    initValue: value,
                    lastValue: value
                } );

            });

            $('input.myclass').unbind()
            .keyup(function() {

                var value = $(this).val();

                if (/^([1-9]\d*)?$/.test(value)) {
                    $(this).attr('lastValue', value);
                } else {
                    $(this).val($(this).attr('lastValue'));
                }
            })
            .blur(function() {

                if (/^$/.test($(this).val())) {
                    $(this).val('1');
                }

                if ($(this).val() != $(this).attr('initValue')) {
                    $(this).closest('form').submit();
                }
            });
        }
    }

    $.Shanti = new Shanti();

}) (jQuery)

