﻿function init_Supplies(_moduleid, _iseditable) {

    var i;
    var html = "";
    var summary = "";
    var style = "";

    var url;
    url = (_iseditable) ? "/desktopmodules/sitebuilder/components/WebService.asmx/FetchSupplies_All" : "/desktopmodules/sitebuilder/components/WebService.asmx/FetchSupplies_Current";

    $.ajax({
        type: "POST",
        url: url,
        // pass parameters to webmethod
        data: "{ModuleID: " + _moduleid + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            // clear all current modules
            $('#placeholder').empty();
            // if data is returned, iterate through response
            if (null != msg) {
                for (i = 0; i < msg.length; i++) {
                    
                    style = (msg[i].Display) ? "" : "noshow";

                    html += (_iseditable == 'True') ? '<h2 class="' + style + '"><a class="lnkedit" rel=' + msg[i].ItemID + ' href="' + _privateurl + '?skin=' + _SiteSkin + '&mode=supplies&ItemID=' + msg[i].ItemID + '"><img src="/desktopmodules/sitebuilder/images/edit.gif" alt="edit" /></a>' : '<h2>';

                    summary = msg[i].Description.replace(/<(.|\n)*?>/g, '');

                    if (summary.length > 300) { summary = truncate(summary, 300, '', msg[i].ItemID); }
                    html += msg[i].Title + '</h2><div class="toggle_' + msg[i].ItemID + '">' + summary

                    html += (summary.length > 300) ? '<p><a class="lnktoggle" rel="' + msg[i].ItemID + '" href="#">More...</a></p></div><div class="toggle_' + msg[i].ItemID + '" style="display:none;"><p>' + msg[i].Description + '</p><p><a class="lnktoggle" rel="' + msg[i].ItemID + '" href="#">Less...</a></p></div>' : '</div>';
                }
            }

            $('#modulebody').append(html);

            $('.lnktoggle').click(function() {
                $('.toggle_' + $(this).attr("rel")).toggle();
                return false;
            });

            SetEditControls(_iseditable, _moduleid, 'supplies');

        }
    });
}

