﻿var numberOfItemsSelected = 0;

function CalculateNumberOfSelectedItems(checkBox, comparisationLabel) {
    var oldNumberofItems = numberOfItemsSelected + " ";

    if (checkBox.is(':checked')) {
        numberOfItemsSelected++;
    }
    else {
        numberOfItemsSelected--;
    }

    comparisationLabel.text(comparisationLabel.text().replace(oldNumberofItems, numberOfItemsSelectedWarn + " "));
}

var numberOfItemsSelectedWarn = 0;

function CalculateNumberOfSelectedItemsWarn(checkBox, comparisationLabel) {
    var oldNumberofItems = numberOfItemsSelectedWarn + " ";

    if (checkBox.checked) {
        var prevItems = numberOfItemsSelectedWarn;
        numberOfItemsSelectedWarn++;

        if (prevItems == 3 && numberOfItemsSelectedWarn == 4) {
            $('#compareError').dialog('open');
            checkBox.checked = false;
            numberOfItemsSelectedWarn--;
        }
    }
    else {
        numberOfItemsSelectedWarn--;
    }

    comparisationLabel.innerText = comparisationLabel.innerText.replace(oldNumberofItems, numberOfItemsSelectedWarn + " ");     
}

function ResetCompareCount() {
    numberOfItemsSelectedWarn = 0;
}

// reset the numbers when a async postback is done
$(document).ready(function() {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function() { ResetCompareCount(); });
});
