//function to format number
calPoints();
function commafyValue(nStr)
{
    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');
    }
    return x1 + x2;
}
//calculate total base on points 
function calPoints()
{
    var points = document.getElementById('points');
    var contracts = document.getElementById('contracts');
    var myindex  = contracts.selectedIndex
    var contracts = contracts.options[myindex].value
    
    var amountcon = document.getElementById('amount');
    var contVal = contracts * 50;
    amountcon.value = '$'+commafyValue(points.value * contVal);
    
}
//calculate total base on pips
function calPips() {
    var pips = document.getElementById('pips');
    var perpips = document.getElementById('perpips');
    var myindex  = perpips.selectedIndex
    var perpips = perpips.options[myindex].value
        
    var pipamount = document.getElementById('pipamount');
    var total = pips.value * perpips;
    
    pipamount.value = commafyValue(total);
    
}
