(function (window, undefined) {
    var ISIE = /*@cc_on!@*/0;

    function FlariaLoad(p) {

        var http;

        try {
            http = new XMLHttpRequest;
        } catch (e) {
            try {
                http = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http = newActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    return false;
                }
            }
        }

        http.onreadystatechange = function () {

            if (http.readyState == 4 && http.status == 200) {
                var str = http.responseText;
                if (ISIE) {
                    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.async = "false";
                    xmlDoc.loadXML(str);
                } else {
                    var domParser = new DOMParser;
                    var xmlDoc = domParser.parseFromString(str, "application/xml");
                }
                var x = xmlDoc.firstChild.childNodes;
                for (var i = 0; i < x.length; i++) {
                    var id = x[i].nodeName;

                    // node content
                    var str = x[i].childNodes[0].nodeValue;
                    // SEF urls
                    //if(FlariaPath!=""){var str = str.replace(/\?\//g, FlariaPath);};
                    document.getElementById(id).innerHTML = str;
                    FlariaSelect()
                }
                FlariaAJAX();
            }
        };
        http.open("GET", FlariaPath + "flaria/wysiwyg/php/xmlLoad.php?id=" + p + "&p=" + FlariaPath);
        http.send(null);
    }

    function FlariaSelect() {

        var a;
        ISIE ? a = document.all.tags("a") : a = document.getElementsByTagName("a");
        for (var i = 0; i < a.length; i++) {

            var href = a[i].getAttribute("href").replace(FlariaPath, '');
            var rel = a[i].getAttribute("rel");
            var cl = a[i].getAttribute("class");
            if (cl == null) cl = "";

            var aref = href.replace(/\//g, '').replace("#", "").replace("?", "");
            var sref = window.location.search.replace(/\//g, '').replace("#", "").replace("?", "");
            var hsref = window.location.hash.replace(/\//g, '').replace("#", "").replace("?", "");

            a[i].setAttribute("class", cl.replace(/flaria-selected /g, ''));

            if ((aref == sref || aref == hsref)&&href!='?/') {
                a[i].setAttribute("class", 'flaria-selected ' + cl);
            }
        }

    }

    function FlariaAJAX() {
        var a;
        ISIE ? a = document.all.tags("a") : a = document.getElementsByTagName("a");
        for (var i = 0; i < a.length; i++) {

            var href = a[i].getAttribute("href").replace(FlariaPath, '');
            var rel = a[i].getAttribute("rel");
            var aref = href.replace(/\//g, '').replace("#", "").replace("?", "");

            if (rel == "ajax") {
                a[i].setAttribute("href", '#/' + aref + '/');
                a[i].setAttribute("onClick", "FlariaLoad('" + aref + "')");
            }
        }
    }
    FlariaAJAX(document);

    var h = window.location.hash;
    if (h != h.replace("#", "")) {
        FlariaLoad(h.replace(/\//g, '').replace("#", ""))
    };

    FlariaSelect()

    window.FlariaLoad = FlariaLoad;
})(window);
