/** FHRSWidget.Core.js: shared functionality for widgets **/
// Namespace definition : All Widget Classes should be created in this namespace  //
if (!window.FHRSWidget1032548) {
    window.FHRSWidget1032548 = {};
}
// Widget Core Constructor //
FHRSWidget1032548.Core = function () {
    // Write out Parent Div where script is placed
    // Widget content can then be attached to this div through the DOM
    this.parentDivId = 'CoreJsBaseDiv-1032548';
    document.write('
');
};
// Widget Core Class Definition //
FHRSWidget1032548.Core.prototype =
    {
        // Create any HTML element //
        createTag: function (tagName, innerHtml, cssClass) {
            var tag = $c_1032548(tagName);
            if (cssClass) {
                this.setCssClass(tag, cssClass);
            }
            if (innerHtml) {
                tag.innerHTML = innerHtml;
            }
            return tag;
        },
        // Create Unordered List of Hyperlinks //
            createHyperlinkList: function (dataCollection, businessUrl, ratingImageUrl, listId, cssClass) {
            this.parentDiv = $g_1032548(this.parentDivId);
            // Remove existing list with this Id, if exists
            // Create list
            var list;
            list = $c_1032548('div');
            list.id = listId;
            list.name = listId;
            if (cssClass !== '') {
                this.setCssClass(list, cssClass);
            }
            // Add items to list
            var div;
            for (index in dataCollection) {
                var item = dataCollection[index];
                div = $c_1032548('div');
                var businessName = item.BusinessName;
                var ratingKey = item.RatingKey;
                var postCode = item.PostCode;
                if (businessName) {
                    var hyperlink = this.createHyperlink(null, businessName, businessUrl + item.FHRSID, null, 'listhyperlink');
                    div.appendChild(hyperlink);
                    var image = this.createTag('div', postCode, null);
                    div.appendChild(image);
                    image = this.createTag('div', ' ', null);
                    div.appendChild(image);
                }
                else {
                    var norating = this.createTag('div', '
', null);
                    div.appendChild(image);
                }
                else {
                    var norating = this.createTag('div', ' ', null);
                    div.appendChild(norating);
                }
                list.appendChild(div);
            }
            return list;
        },
        // Create a hyperlink and attach event handlers if needed //
        createHyperlink: function (hyperlinkId, text, href, onClickFunction, cssClass, target) {
            hyperlink = $c_1032548('a');
            if (hyperlinkId) {
                hyperlink.id = hyperlinkId;
                hyperlink.name = hyperlinkId;
            }
            hyperlink.title = text;
            hyperlink.innerHTML = ('
', null);
                    div.appendChild(norating);
                }
                list.appendChild(div);
            }
            return list;
        },
        // Create a hyperlink and attach event handlers if needed //
        createHyperlink: function (hyperlinkId, text, href, onClickFunction, cssClass, target) {
            hyperlink = $c_1032548('a');
            if (hyperlinkId) {
                hyperlink.id = hyperlinkId;
                hyperlink.name = hyperlinkId;
            }
            hyperlink.title = text;
            hyperlink.innerHTML = ('' + text + '
'); //text));
            if (href) {
                hyperlink.href = href;
            }
            if (cssClass !== null && cssClass !== '') {
                this.setCssClass(hyperlink, cssClass);
            }
            if (target) {
                hyperlink.setAttribute("target", target);
            }
            // Attach onclick event handlers
            if (onClickFunction) {
                hyperlink.onclick = onClickFunction;
                var onClickHandler = new Function(hyperlink.onclick);
                if (hyperlink.addEventListener) {
                    hyperlink.addEventListener('click', onClickHandler, false);
                } else if (hyperlink.attachEvent) {
                    hyperlink.attachEvent('onclick', onClickHandler);
                }
            }
            return hyperlink;
        },
        // Adds CSS Class to any element //
        setCssClass: function (elem, cls) {
            elem.setAttribute('class', cls);
            elem.setAttribute('className', cls);
        },
        // Attach a Stylesheet to document  //
        attachStyleSheet: function (path, linkId) {
            var doc = document.getElementsByTagName('head').item(0);
            var link = $c_1032548('link');
            link.rel = 'stylesheet';
            link.type = 'text/css';
            link.href = path;
            link.id = linkId;
            doc.appendChild(link);
            return false;
        },
        // Attach a new script, useful for simulating postbacks //
        attachScript: function (path, scriptId) {
            script = $c_1032548('script');
            script.src = path;
            script.type = 'text/javascript';
            script.id = scriptId;
            this.parentDiv.appendChild(script);
            return false;
        }
    };
// Shortcut for GetElementsById //
function $g_1032548(elem)
{
  return document.getElementById(elem);
}
// Shortcut for CreateElement //
function $c_1032548(elem)
{
  return document.createElement(elem);
}
// Construct a new core object
var core1032548 = new FHRSWidget1032548.Core();
/** FHRSWidget.Widget.js: renders list of dev events **/
// Widget Constructor //
FHRSWidget1032548.Widget = function()
{
    // Get reference to main div. All widget content will be children of this div
    this.parentDiv = document.getElementById(core1032548.parentDivId);
    this.businessUrl = "https://ratings.food.gov.uk/business/";
    this.ratingImageUrl = "https://api1-ratings.food.gov.uk/images/scores/small/";
    this.fhrsEstablishmentData = [{"AddressLine1":"The Swan","AddressLine2":"119 Acton Lane","AddressLine3":"Chiswick","AddressLine4":"","BusinessName":"The Swan","BusinessType":"Pub\/bar\/nightclub","BusinessTypeID":7843,"Distance":null,"FHRSID":1032548,"Geocode":{"Latitude":51.4979019,"Longitude":-0.265642},"LocalAuthorityBusinessID":"PI000069214","LocalAuthorityCode":"509","LocalAuthorityEmailAddress":"foodsafety@ealing.gov.uk","LocalAuthorityName":"Ealing","LocalAuthorityWebSite":"https:\/\/www.ealing.gov.uk\/info\/201150\/food_hygiene_and_safety","NewRatingPending":false,"PostCode":"W4 5HH","RatingDate":"26 July 2025","RatingKey":"fhrs_4_en-gb","RatingValue":"4","ReInspectionResult":null,"RightToReply":"","SchemeType":"FHRS","Scores":{"ConfidenceInManagement":0,"Hygiene":10,"Structural":10}}];
}
// Widget : Core Class Definition  //
FHRSWidget1032548.Widget.prototype =
    {
        // Main function for Events Widget : Handles rendering the widget to the consuming site //
        render: function () {
            var child1 = core1032548.createHyperlinkList(this.fhrsEstablishmentData, this.businessUrl, this.ratingImageUrl, 'eventList1032548', 'widgetcontainer');
            var child2 = core1032548.createTag('br');
            var els = document.getElementsByClassName("1032548");
            for (var i = 0; i < els.length; i++) {
                // Create Border and Shadow and return Content Div
                var contentDiv = this.createContentBorder(els[i]);
                // Create and Attach Events List
                contentDiv.appendChild(child1);
                contentDiv.appendChild(child2);
            }
        },
        // Create Border, Shadow, and Content Div //
        createContentBorder: function (localParentDiv) {
            var outerDiv = core1032548.createTag('div', '', 'widget1');
            var innerDiv = core1032548.createTag('div', '', 'widget2');
            var contentDiv = core1032548.createTag('div', '', 'widget3');
            innerDiv.appendChild(contentDiv);
            outerDiv.appendChild(innerDiv);
            localParentDiv.appendChild(outerDiv);
            return contentDiv;
        }
    };
// Create Widget Object
var ev_w_1032548 = new FHRSWidget1032548.Widget();
ev_w_1032548.render();