function addValue(el, val, min, max)
{
    el = $(el);
    var i = parseInt(el.val());
    i += parseInt(val);
    if (i > max) {
        i = max;
    }
    if (i < min) {
        i = min;
    }
    el.val(i);
}

function checkValue(el, min, max)
{
    el = $(el);

    var i = parseInt(el.val());
        
    if (isNaN(i)) {
        i = min;
    } else {
        if (i > max) {
            i = max;
        }
        if (i < min) {
            i = min;
        }
    }
    el.val(i);
}

function autoArea(obj)
{
    var t = obj.value;
    var ts = t.split(/\n/);
    h = ts.length * 20;
    if (h < 60) {
        h = 45;
    }
    obj.style.height = h + 'px';
}

jQuery.fn.defaultText = function (text, cls) {
    if (!cls) {
        cls = 'default';
    }

    $(this).each(function () {
        if (this.value=='') {
            this.value = text;
        }
        this.tmpValue = text;
        this.originalClass = this.className;
        this.className = this.originalClass + ' ' + cls;
        $(this).focus(function () {
            if (this.value == this.tmpValue) {
                this.value = '';
                this.className = this.originalClass;
            }
        });
        $(this).blur(function () {
            if (this.value == '') {
                this.value = this.tmpValue;
                this.className = this.originalClass + ' ' + cls;
            }
        });
        $(this.form).submit(function () {
            if (this.value == this.tmpValue) {
                this.value = '';
            }
        });
        this.blur();
    });
}

if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}
