﻿function onlyNumbers(event) {
    var key;
    
    if (window.event) {
        key = event.keyCode;
    } else {
        key = event.which || event.keyCode;
    }
    if (key == 8 || (key >= 48 && key <= 57) || key == 127 || key == 17 || key == 39 || key == 9) {
        return true;
    } else {
        event.cancel = true;
        event.returnValue = true;
        event.cancelBubble = true;
        return false;
    }
};

function formatMoney(q, c, d, t) {
    var n = q, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "",
    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    return "R$ " + s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t)
    + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};


function popup(sLink, tamWidth, tamHeight) {
    // Tamanho Default
    if (!tamWidth)
        tamWidth = 400;
    if (!tamHeight)
        tamHeight = 400;
    if (window.showModalDialog)      //Internet Explorer
        window.showModalDialog(sLink, new Object(), 'dialogWidth=' + tamWidth + 'px;dialogHeight=' + tamHeight + ' px;resizable=1;scroll=1;status=0;');
    else
        window.open(sLink, 'Pop-up:', 'modal,toolbar=false,location=false,directories=false,status=false,menubar=false,scrollbars=no,resizable=no,left=100,top=100,width=' + tamWidth + ',height=' + tamHeight);
}