﻿$(document).ready(function () {
    var hasNotification = false;
    var notificationContent = "";

    try {
        var xmlhttp = InitXmlHttp();
        xmlhttp.open("GET", "/homepage/Handler.ashx?page=Homepage", false);
        xmlhttp.send(null);

        var xmlhttpResponse = xmlhttp.responseText;
        var xmlDoc = LoadXml(xmlhttpResponse);

        if (xmlDoc.getElementsByTagName("ActiveNotification")[0].childNodes.length > 0) {
            hasNotification = xmlDoc.getElementsByTagName("ActiveNotification")[0].childNodes[0].nodeValue == "Y" ? true : false;
        }

        if (xmlDoc.getElementsByTagName("Content")[0].childNodes.length > 0) {
            notificationContent = xmlDoc.getElementsByTagName("Content")[0].childNodes[0].nodeValue;
        }
    }
    catch (e) {
        alert(e);
    }

    var divSlider = document.getElementById('divSlider');
    var divNotification = document.getElementById('divNotification');

    if (hasNotification) {
        var divNotificationContent = document.getElementById('divNotificationContent');

        divNotificationContent.innerHTML = notificationContent;

        divSlider.style.display = 'none';
        divNotification.style.display = '';
    }
    else {
        divSlider.style.display = '';
        divNotification.style.display = 'none';
    }
});

function LoadXml(txt) {
    var xmlDoc = null;
    try
		{
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(txt);
        return xmlDoc;
    }
    catch (e) {
        parser = new DOMParser();
        xmlDoc = parser.parseFromString(txt, "text/xml");
        return xmlDoc;
    }
}

function InitXmlHttp() {
    var xmlhttp = null;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E) {
            xmlhttp = false;
        }
    }

    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }

    return xmlhttp;
}
