﻿var _BaseClassName = "acLnk";
var isLogEnabled = (typeof logSeo == 'function' && typeof console == 'object');
var IENavigator = false;
var concierge_excludes = [];
for (var exclude in "id,class,onmousedown,onmouseup,onclick,ondblclick,onmouseover,onmouseout,onmousemove,oncontextmenu,onkeydown,onkeyup,onkeypress,onfocus,onblur,onload,onunload,onabort,onerror,onsubmit,onreset,onchange,onselect,oninput,onpaint,onpopupShowing,onpopupShown,onpopupHiding,onpopupHidden,onclose,oncommand,onbroadcast,oncommandupdate,ondragenter,ondragover,ondragexit,ondragdrop,ondraggesture,onresize,onscroll,overflow,onunderflow,onoverflowchanged,onsubtreemodified,onnodeinserted,onnoderemoved,onnoderemovedfromdocument,onnodeinsertedintodocument,onattrmodified,oncharacterdatamodified".toLowerCase().split(",")) {
    concierge_excludes[exclude] = true;
}
if (navigator.appName.toLowerCase().indexOf("microsoft") > -1) { IENavigator = true; }

function gebcn(className) {
    className = className.toLowerCase();
    var retour = [];
    var sps = document.getElementsByTagName("span");
    if (sps) {
        var i = sps.length;
        while (i) {
            var current = sps[i--];
            if (current && current.className) {
                var p = current.className.toLowerCase().indexOf(className + " ");
                if ((p >= 0)) {
                    retour.push(current);
                }
            }
        }
    }
    return retour;
}

if (IENavigator) {
    window.switchElement = function(oldElt, newElt, id) {
        oldElt.className = "hide guybrushThreepwood";
        if (id) {
            oldElt.id = "";
            newElt.id = id;
        }
    };
    //$(document).ready(function() { $(".darthVader").empty.remove() });
}
else {
    window.switchElement = function(oldElt, newElt, id) {
        oldElt.parentNode.removeChild(oldElt);
        if (id) {
            newElt.id = id;
        }
    }
}

this.AcConcierge = function(runonce) {
    var spanstotos = (!IENavigator) ? document.getElementsByClassName(_BaseClassName) : gebcn(_BaseClassName);
    var nbspanstotos = spanstotos.length;
    if (isLogEnabled) {
        logSeo(nbspanstotos);
    }
    var _base16 = "0A12B34C56D78E9FULONYXTIZKJSHVPWQMGR";

    var str, rurl = "";
    var curSpan, rclassn, ln = null;
    var ch, cl, j, p, d = 0;

    var i = nbspanstotos;

    while (i--) {
        curSpan = spanstotos[i];

        p = curSpan.className.indexOf(' ');
        d = curSpan.className.indexOf(' ', p + 1);
        if (d == -1) {
            d = curSpan.className.length;
        }
        rurl = "";
        if (p > 0) {
            str = curSpan.className.substr(p + 1, d - p - 1);
            for (j = 0; j < str.length; j += 2) {
                ch = _base16.indexOf(str.charAt(j));
                cl = _base16.indexOf(str.charAt(j + 1));
                rurl += String.fromCharCode((ch * 16) + cl);
            }
        }
        rclassn = curSpan.className.substr(d + 1, curSpan.className.length - d - 1);
        ln = document.createElement("a");
        ln.href = rurl;
        var id = "";
        for (var j = 0; j < curSpan.attributes.length; j++) {
            var currAttrName = curSpan.attributes[j].name.toLowerCase();
            if (currAttrName == 'id') {
                id = curSpan.getAttribute(currAttrName);
            }
            else if (!concierge_excludes[currAttrName]) {
                if ((d = curSpan.getAttribute(currAttrName))) {
                    ln.setAttribute(currAttrName, d);
                }
            }
        }

        ln.className = "xXx " + rclassn;
        j = curSpan.childNodes.length;

        if (j) {
            var parent = curSpan.parentNode;
            while (j--) {
                ln.appendChild(curSpan.childNodes[0]);
            }

            parent.insertBefore(ln, curSpan);
            switchElement(curSpan, ln, id);
        }
    }

    if (!runonce) {
        this.setTimeout("AcConcierge()", 100);
    }
};

this.AcConcierged = function(value) {
    if (value) {
        var rurl = "";
        var _base16 = "0A12B34C56D78E9FULONYXTIZKJSHVPWQMGR";
        for (j = 0; j < value.length; j += 2) {
            ch = _base16.indexOf(value.charAt(j));
            cl = _base16.indexOf(value.charAt(j + 1));
            rurl += String.fromCharCode((ch * 16) + cl);
        }
        return rurl;
    }
    return value;
}
this.AcConcierge();

