﻿/* Red Buttons */
$(".red-button").live("mousedown", function() {
    $(this).removeClass("red-button-up");
    $(this).addClass("red-button-down");
});
$(".red-button").live("mouseup", function() {
    $(this).addClass("red-button-up");
    $(this).removeClass("red-button-down");
});
$(".red-button").live("mouseout", function() {
    $(this).addClass("red-button-up");
    $(this).removeClass("red-button-down");
});
$(".red-button").live("mouseover", function() {
    $(this).addClass("red-button-up");
});
/* end Red Buttons */

function include(jsFile) {
    $("head").append('<script type="text/javascript" src="/Scripts/'
    + jsFile + '"></scr' + 'ipt>');
}

function isNumeric(value) {
    if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
    return true;
}

function isPositiveInteger(value) {
    if (value == null || !value.toString().match(/^\d*$/)) return false;
    return true;
}

function formatCurrency(amount) {
    var i = parseFloat(amount);
    if (isNaN(i)) { i = 0.00; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if (s.indexOf('.') < 0) { s += '.00'; }
    if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s;
}

// fix indexOf in Internet Explorer
if (!Array.indexOf) {
    Array.prototype.indexOf = function(obj) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == obj) {
                return i;
            }
        }
        return -1;
    }
}

function destroyArray(array) {
    if (array && array.length) {
        while (array.length > 0) {
            if (array[0].destroy) array[0].destroy();
            array[0] = null;
            array.splice(0, 1);
        }
        array = null;
    }
}

function toggleCategory(categoryName) {
    var categoryItems = $(".categoryItem");
    for (var i = 0; i < categoryItems.length; i++) {
        if ($(categoryItems[i]).attr("category") == categoryName) {
            if ($(categoryItems[i]).attr("hidden") && $(categoryItems[i]).attr("hidden") == "1") {
                $(categoryItems[i]).show();
                $(categoryItems[i]).attr("hidden", "0");
            }
            else {
                $(categoryItems[i]).hide();
                $(categoryItems[i]).attr("hidden", "1");
            }
        }
    }
}
