﻿function rol_addCommas(obj) {
    var nStr = obj.value.replace(/,/g, "");
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    obj.value = x1 + x2;
}

function rol_keyDownNumeric(event) {
    var curChar = "";
    if (window.event) {
        //backspace/tab/delete
        if (event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 46)
            return;
        curChar = String.fromCharCode(event.keyCode);
    }
    else {
        curChar = String.fromCharCode(event.which);
        //firefox requires 0 for tab
        if (event.which == 8 || event.which == 9 || event.which == 46 || event.which == 0)
            return;
    }
    var result = curChar.match('^[0-9]+$');
    if (!result) {
        if (window.event) {
            event.returnValue = false;
            event.cancel = true;
        }
        else {
            event.preventDefault();
            return;
        }
    }
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function replaceAll(text, strA, strB) {
    while (text.indexOf(strA) != -1) {
        text = text.replace(strA, strB);
    }
    return text;
}

function newWindow(mypage, myname, w, h, features) {
    try {
        if (screen.width) {
            var winl = (screen.width - w) / 2;
            var wint = (screen.height - h) / 2;
        } else { winl = 0; wint = 0; }
        if (winl < 0) winl = 0;
        if (wint < 0) wint = 0;
        var settings = 'height=' + h + ',';
        settings += 'width=' + w + ',';
        settings += 'top=' + wint + ',';
        settings += 'left=' + winl + ',';
        settings += features;
        win = window.open(mypage, myname, settings);
        win.window.focus();
    }
    catch (e) {
        window.status = e.message
    }
}
