﻿function swapImage(imageIndex)
{
    try
    {
        $('#imageLinks img').attr('src', productImages[imageIndex]);
        $('#imageLinks a.selected').removeClass('selected');
        $('#imageLink' + imageIndex).addClass('selected');
        return false;
    }
    catch(e)
    {
        return true;
    }
}

function round(number,X) 
{
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function doTotals()
{
    var newTotal = 0;
    for(var op = 0; op < 4; op++)
    {
        for(w=0;w<5;w++)
        {
            var elem = document.getElementById('o'+op+'w'+w);
            if(elem != null)
            {
                newTotal += (elem.selectedIndex * weights[w]);
            }
        }
    }
    $('#BrownTotal').html('You will have a total of ' + round(newTotal,2) + 'kg of this product in your basket.');

    if(newTotal > (prevAmount + availAmount))
        $('#BrownTotalWarning').html('Warning: There might not be enough of the product available to meet the amount you want!<br />');
    else
        $('#BrownTotalWarning').html('');

}

