jQuery.fn.shake = function(intShakes, intDistance, intDuration) {
        this.each(function() {
            var jqNode = $(this);
            jqNode.css({position: 'relative'});
            for (var x=1; x<=intShakes; x++) {
            jqNode.animate({left: (intDistance * -1)},(((intDuration / intShakes) / 4)))
            .animate({left: intDistance},((intDuration/intShakes)/2))
            .animate({left: 0},(((intDuration/intShakes)/4)));
        }
    });
return this;
}

function resent(num,v1,v2,v3){
            var lastnum = parseInt(num.toString().slice(-1));            
            
            console.log(lastnum);
            
            if(lastnum == 1) v = v1;
            else if(lastnum >= 2 && lastnum <= 4) v = v2;
            else v = v3;
                
            return num+'&nbsp;'+v;
        }

jQuery.fn.fields = function(text) {
    this.each(function() {
            var jqNode = $(this);
            jqNode.val(text);
            var color=jqNode.css('color');
            jqNode.css('color','#CCCCCC');
            jqNode.click(function() {
                var node=$(this);
                if(node.val()==text){
                    node.css('color',color);
                    node.val('');
                }
            });
            jqNode.blur(function() {
                var node=$(this);
                if(node.val()==''){
                    node.css('color','#CCCCCC');
                    node.val(text);
                }
            });
    });
    return this;
}

jQuery.fn.fields = function(text) {
    this.each(function() {
            var jqNode = $(this);
            jqNode.val(text);
            var color=jqNode.css('color');
            jqNode.css('color','#CCCCCC');
            jqNode.click(function() {
                var node=$(this);
                if(node.val()==text){
                    node.css('color',color);
                    node.val('');
                }else{node.select();}
            });
            jqNode.blur(function() {
                var node=$(this);
                if(node.val()==''){
                    node.css('color','#CCCCCC');
                    node.val(text);
                }
            });
    });
    return this;
}

jQuery.fn.timepicker = function() {
    var mask='09:00';
    this.each(function() {
            var time=mask.split(':');
            var jqNode=$(this);
            jqNode.attr('value',mask).hide();
            var elemstr='<div class="timepicker ui-corner-all ui-widget-header" style="width:70px;height:25px;text-align:center;font-size:20px;"><input type="text" class="hour" style="width:25px;border:medium none;background:transparent;font-size:18px;text-align:left;height:25px;" value="'+time[0]+'"/>:<input type="text" class="minute" style="width:25px;border:medium none;background:transparent;font-size:18px;text-align:left;height:25px;" value="'+time[1]+'"/></div>';
            jqNode.before(elemstr);
            realtimepicker=jqNode.prev();
            hour=realtimepicker.find('input.hour');
            minute=realtimepicker.find('input.minute');
            var ctime=mask;
            realtimepicker.find('input').digit().change(function(){
                ctime=hour.val()+':'+minute.val();
                jqNode.attr('value',ctime);
            }).click(function(){$(this).val('');}).focus(function(){$(this).val('');});
    });
    $('.timepicker .hour').keypress(function(event){
        var jqNode=$(this);
        var num=parseInt(String.fromCharCode(event.which));
        var cval=jqNode.val();
        var next=parseInt(cval+''+num);
        // Фокус на след. поле если len(s)==2
        if(jqNode.val().length>=2){
            minute.val(String.fromCharCode(event.which)).focus();
            return false;
        }
        // 2x
        if(cval==2){
            if(num>=0 && num<=4){
                jqNode.val(next);
                return false;
            }else{return false;}
        }
        // 1x
        if(cval==1){
            return true;
        }
        // 2> && <10
        if(num<10 && num>2){
            jqNode.val('0'+num);
            minute.focus();
            return false;
        }
        return true;
    });
    $('.timepicker .minute').keypress(function(event){
        var jqNode=$(this);
        var num=parseInt(String.fromCharCode(event.which));
        var cval=jqNode.val();
        var next=parseInt(cval+''+num);
        if(cval.length>=2){
            realtimepicker.parents('form').find('input:visible:first').focus();
            return false;
        }
        if(next==60){
            var nexthour=parseInt($('.timepicker .hour').val())+1;
            jqNode.val('00');
            $('.timepicker .hour').val(nexthour);
            return false;
        }
        if(next>59){return false;}
        return true;
    });
    return this;
}

jQuery.fn.digit = function(isfloat) {
    this.each(function() {
            //digit={48:0,49:0,50:0,51:0,52:0,53:0,54:0,55:0,56:0,57:0};
            //control={37:0,39:0,8:0,9:0,44:0,46:0}
            var jqNode = $(this);
            jqNode.keypress(function(event){
                // ","
                if(typeof isfloat!=undefined && isfloat==true && event.which==44){return true;}
                // Стрелки и бэк дел
                if(event.keyCode==37 || event.keyCode==39 || event.keyCode==46 || event.keyCode==9 || event.which==8){return true;}
                // 0 - 9
                if(event.which>=48 && event.which<=57){return true;}
                return false;
            });
    });
    return this;
}

