﻿var numberOfItemsSelected = 0;

function CalculateNumberOfSelectedItems(checkBox, comparisationLabel) {
    var oldNumberofItems = numberOfItemsSelected + " ";

    if (checkBox.checked) {
        numberOfItemsSelected++;
    }
    else {
        numberOfItemsSelected--;
    }

    comparisationLabel.innerText = comparisationLabel.innerText.replace(oldNumberofItems, numberOfItemsSelected + " ");
}

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(); });
});