﻿$(document).ready(function() {
    $.get("/products/RPCProducts.csv", function(data) {
        productArray = $.csv()(data);
        $('tr[productID]').each(function(i) {
            var productID = $(this).attr('productID');
            for (var x = 1; x < productArray.length - 1; x++) {
                if (jQuery.trim(productArray[x][0]) == productID) {
                    var row = '<td class="itemData-title">' + jQuery.trim(productArray[x][1]);
                    if (jQuery.trim(productArray[x][5]) != '') {
                        row += '<br />' + jQuery.trim(productArray[x][5]);
                    }
                    row += '</td><td class="itemData-code">Y21' + jQuery.trim(productArray[x][0]) +
                        '</td><td class="itemData-price">' + jQuery.trim(productArray[x][2]) + '</td>';
                    if (jQuery.trim(productArray[x][3]).toUpperCase() == 'YES') {
                        row += '<td class="itemData-qty"><input class="qty-cart" type="text" name="txtCartQuantity" value="" />' +
                        '<input type="hidden" name="txtProductID" value="' + jQuery.trim(productArray[x][0]) + '" /></td>';
                    } else {
                        row += '<td>&nbsp;</td>';
                    }
                    $('tr[productID=' + productID + ']').empty();
                    $('tr[productID=' + productID + ']').html(row);
                    if ((i + 1) % 2 == 0) {
                        $('tr[productID=' + productID + ']').addClass("grayItemData");
                    }
                    break;
                }
            }; // for loop
        }); // each
    }); // get
});

