﻿var BasketItemKeys = null;

function LoadBasketItemKeys(url) {
    
    $.ajax({
        url: url,
        dataType: "json",
        type: "POST",
        success: LoadBasketItemKeysSuccess
    });
    
}

function LoadBasketItemKeysSuccess(result) {
    
    BasketItemKeys = result;
    CheckButtons();
}

function CheckButtons() {

    $(".productlayout li").each(function(i) {

        var batchbarcode = $(this).find('.barcode').val();
        
        if (CheckKey(batchbarcode)) {
            $(this).find('.AddButton').hide();
            $(this).find('.AddAllButton').hide();
            $(this).find('.RemoveButton').show();
            $(this).find('.RemoveAllButton').show();
            
        }
        else {
            $(this).find('.AddButton').show();
            $(this).find('.AddAllButton').show();
            $(this).find('.RemoveButton').hide();
            $(this).find('.RemoveAllButton').hide();
        }
    });
}

function CheckKey(batchbarcode) {

    var found = false;
    $.each(BasketItemKeys, function(i, val) {
        
        if (val == batchbarcode) {
            found = true;
            return false;
        }

    });
    return found;

}