﻿function popUpWindow(link, height, width) {
    var url = link.getAttribute("href");
    return popUpWindowUrl(url, height, width);
}

function popUpWindowUrl(url, height, width) {

    if (height == null)
        height = 600;
    if (width == null)
        width = 740;

    var newWin = window.open(url, "newwindow", "menubar=1,location=0,resizable=0,scrollbars=1,width="+ width+",height="+height);
    newWin.focus();
    return false;
}

function formatCurrency(amount) {
    // added 0.1 because of .999999999 rounding error with IEEE numbers
    var amountString = "" + Math.floor(amount * 100 + 0.1);
    if (amount == 0) {
        amountString = "000";
    }

    var dollars = amountString.substring(0, amountString.length - 2);
    var cents = amountString.substring(amountString.length - 2);

    return currencyPrefix + dollars + currencySeparator + cents + currencySuffix;
}

function calcWinnings2(multiplier, wagerAmount)
{
    var NICKELS_PER_DOLLAR = 20;

    var amountInDollars = multiplier * wagerAmount;

    // convert to nickels
    var amountInNickels = amountInDollars * NICKELS_PER_DOLLAR;

    // round up to nearest nickel
    var roundedNickels = Math.ceil(amountInNickels);

    // convert to dollars
    var winnings = (roundedNickels / NICKELS_PER_DOLLAR).toFixed(2);

//    var aaa = "multiplier: " + multiplier;
//    aaa += "\n wagerAmount: " + wagerAmount;
//    aaa += "\n amountInDollars: " + amountInDollars;
//    aaa += "\n amountInNickels: " + amountInNickels;
//    aaa += "\n roundedNickels: " + roundedNickels;
//    aaa += "\n winnings: " + winnings;
//    alert(aaa);

    return winnings;
}

function calcWinnings(odds, wagerAmount)
{
    var MULTIPLIER_DECIMAL_PLACES = 2;
    var multiplier = 1.0;
    
    for (var i = 0; i < odds.length; i++)
    {
        multiplier = multiplier * odds[i];
    }

    // round (up) multiplier to N decimal places
    var roundedMultiplier = multiplier.toFixed(MULTIPLIER_DECIMAL_PLACES);

    var winnings = calcWinnings2(roundedMultiplier, wagerAmount);

    return winnings;
}
