// only allow numbers in a text box

function isNumberKey(evt, point, id){    
    var charCode = (evt.which) ? evt.which : event.keyCode   
    if ((charCode > 31 && ((charCode < 48)|| charCode > 57)) && !(charCode==46 && point==1))   
        return false;
    
    if (charCode==46 && point == 1) {
        var rgx=/(\.)/;

        if (rgx.test($(id).value)) {
             return false;
        }
    }

    return true;
}




function addCommas(id){
    var nStr = $(id).value;

    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');
    }
    nStr = x1 + x2;
    if (nStr.length>0 && nStr != '0'){
        $(id).value = x1 + x2;
    }
    else {
        $(id).value = '0';
    }
    
}

function removeCommas(id) {
    var nStr = $(id).value;
    if (nStr != '0') {
        nStr = nStr.replace(/,/g,'');
        nStr = nStr.replace(/ /g,'');
        $(id).value = nStr;
    }
    else {
        $(id).value = '';
    }
}

function intval( mixed_var, base ) {
    var tmp;
 
    var type = typeof( mixed_var );
 
    if(type == 'boolean'){
        if (mixed_var == true) {
            return 1;
        } else {
            return 0;
        }
    } else if(type == 'string'){
        tmp = parseInt(mixed_var * 1);
        if(isNaN(tmp) || !isFinite(tmp)){
            return 0;
        } else{
            return tmp.toString(base || 10);
        }
    } else if(type == 'number' && isFinite(mixed_var) ){
        return Math.floor(mixed_var);
    } else{
        return 0;
    }
}

function getVal(id) {
document.getElementById(id).value = intval(document.getElementById(id).value);

}
