/* ########## countinput (copyright e2see.de) ##########
<script>
$(document).ready(function(){
    $('input').countinput_connect();
});
</script>

<input type="text" value="" maxlength="16" maxlength-soft="10" />
*/

$.fn.countinput_connect = function(){
    var OB = this;

    OB.on('input', function(){
            if($('body').children("#count-input_container").length == 0){
                $('body').append('<div id="count-input_container"></div>');
            }

            var position_x = parseInt($(this).offset().left + 3);
            var position_y = parseInt($(this).offset().top -14);
            $('body').children('#count-input_container').css({
                        top: position_y +'px',
                        left: position_x +'px',
                        }).show();

            var value = $(this).val();
            var text = value.length;

            if($(this).is('[maxlength]')){
                max_length = parseInt($(this).attr('maxlength'));
                if(text > max_length){
                    text = max_length;
                    $(this).val(value.substring(0, max_length));
                }
                text = text + ' / ' + max_length;
            } else if($(this).is('[maxlength-soft]')){
                max_length = parseInt($(this).attr('maxlength-soft'));
                /*
                if(text > max_length){
                    text = max_length;
                    $(this).val(value.substring(0, max_length));
                }
                */
                text = text + ' / ' + max_length;
            }
            $('body').children('#count-input_container').text(text);
    });

    OB.on('blur', function(){
            $('body').children("#count-input_container").remove();
    });

}





/* cdn 1ms */