/* ------------------------------------------------------------------------------------------------
Site Area:    SHOP
File:         cat/shop_functions.js
Version:      2.1
Date:         28th October 2007
Copyright:    Jeremy Reece <jreece@gmail.com>
------------------------------------------------------------------------------------------------ */

// Undocumented code... Mwa-ha-ha... (not that it's even remotely complex :P) 
var optMaxQuantity = 1;


function cartQtyChange(index, amount) {
    var t = document.getElementById("optionQty" + index);
    var m = parseInt(document.getElementById("optionMaxQty" + index).value, 10);
    var q;
    
    if (isNaN(parseInt(t.value, 10))) {
        q = 0;
    } else {
        q = parseInt(t.value, 10);
    }
    
    if ((q + amount >= 0) && (q + amount <= m)) {
        t.value = q + amount;
    } else {
        t.value = q;
    }
}
    


function cartQtyManualChange(index) {
    var t = document.getElementById("optionQty" + index);
    var m = parseInt(document.getElementById("optionMaxQty" + index).value, 10);
    var n = document.getElementById("optionName" + index).value;
    var q;
    
    if (isNaN(parseInt(t.value, 10))) {
        q = 0;
    } else {
        q = parseInt(t.value, 10);
    }
    
    if (q >= 0 && q <= m) {
        t.value = q;
    } else {
        if (q < 0) {
            t.value = 0;
        } else {
            alert("Sorry, the maximum quantity of '" + n + "' that you may order is " + m + ".");
            t.value = m;
        }
    }

}



function openHelp() {
    document.getElementById("helpDiv").style.display = "block";
    //helpDiv.style.height = "auto";
}

function hideHelp() {
    document.getElementById("helpDiv").style.display = "none";
}

//EOF