﻿String.prototype.tirm = function() {
    if (this.indexOf(" ") >= 0)
        return this.replace(" ", "").tirm();
    else
        return this;
}

String.prototype.isNumber = function() {
    if (this == "" || this == null)
        return false;
    try {
        var n = parseFloat(this);
        return !(isNaN(n));
    } catch (e) {
        return false;
    }
}

Number.prototype.to2Bit = function() {
    var num = Math.round(parseFloat(this) * 100) / 100;
    var len = num.toString().length;
    var index = num.toString().indexOf(".");
    if (index <= -1)
        return num + ".00";
    else {
        if ((len - index) <= 2)
            return num + "0";
        else
            return num;
    }
}

//inject Asp.Net validation control
//need jquery
//$(document).ready(function() {
//    this._display_msg = null;

//    var inspect = Page_ClientValidate;
//    Page_ClientValidate = function(group) {
//        var is_empty = true;
//        for (var i = 0; i < Page_Validators.length; i++) {
//            var val = Page_Validators[i];
//            if (val.evaluationfunction.toString().indexOf("RequiredFieldValidatorEvaluateIsValid") >= 0) {
//                if (!_isEmpty(val)) {
//                    is_empty = false;
//                    break;
//                }
//            }
//        }

//        if (typeof (_display_msg) == "function") {
//            //_display_msg(is_empty);
//        }
//        return inspect(group);
//        if (is_empty == true) {
//            Page_IsValid = true;
//            ValidationSummaryOnSubmit(group);
//            Page_BlockSubmit = true;
//            return false;
//        } else {
//            return inspect(group);
//        }
//    };

//    var _isEmpty = function(val) {
//        var obj = document.all ? document.all[val.controltovalidate] : document.getElementById(val.controltovalidate);
//        if (obj.tagName == "INPUT")
//            return obj.value == "";
//        else if (obj.tagName == "SELECT") {
//            return obj.value == "";
//        }
//        else {
//            return false;
//        }
//    };

//    var _reset = function(val) {
//        val.isvalid = true;
//        ValidatorUpdateDisplay(val);
//    }
//});
