//JABR MOSS SITE SCRIPTS Do not mdify or delete
var selectedLinkTabId;
function SI_body() {
    var d = document;

    if (d.body && d.body.style) {
        d.body.style.height = "26px";
        d.body.style.height = "auto";
    }
}

function SI_positionFooter() {
    var d = document, w = window, dE = d.documentElement, dB = d.body; ;
    if (!d.getElementById || !d.body.offsetHeight) return;

    // Reset our footer's margin-top...
    var footer = d.getElementById('footer');

    if (!footer) return;

    var mt = (footer.style.marginTop) ? parseInt(footer.style.marginTop) : 0;

    var windowH = (typeof (w.innerHeight) == 'number') ? w.innerHeight : (dE && dE.clientHeight) ? dE.clientHeight : (dB && dB.clientHeight) ? dB.clientHeight : 0;

    var contentH = d.getElementById('container').offsetHeight - mt;


    var footerMT = (contentH <= windowH) ? windowH - contentH : 0;
    if (footerMT > 0) {
        d.getElementById('footer').style.marginTop = footerMT + 'px';
    }
}

function SI_init() {
    SI_positionFooter();
    SI_body();

}
window.onload = SI_init;
window.onresize = SI_positionFooter;
//**************************// FAQ expand / collapse  END //************************************

function MM_swapImgRestore() { //v3.0

    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

//v3.0
function MM_swapImage() {
    var i, j = 0, x, a = MM_swapImage.arguments;
    document.MM_sr = new Array;
    for (i = 0; i < (a.length - 2); i += 3) {
        if ((x = MM_findObj(a[i])) != null) {
            document.MM_sr[j++] = x;
            x.oSrc = x.src; x.src = a[i + 2];
        }
    }
}

function swap603(id, index, image) {
    for (i = index; i > 0; i--) {
        var idcurrent = id.replace(eval('/star' + index + '/'), 'star' + i.toString())
        var img = document.getElementById(idcurrent);
        img.src = image;
    }
}

/*
* -----------------------------------------
* C605(ProductSelectBox)
* -----------------------------------------
*/
//var currentImageIndex = 0;
function ShowNextImage(id, index, pInfo) {
    index--;
    if (index < 0) {
        index = pInfo.length - 1;
    }
    var a = document.getElementById(id + '_currentImage');
    a.innerHTML = pInfo[index].productImage;
    a.href = pInfo[index].productLink;
    document.getElementById(id + '_productLinkId').innerHTML = pInfo[index].productDisplayName;
    document.getElementById(id + '_productLinkId').href = pInfo[index].productLink;
    return index;
}
function ShowPreviousImage(id, index, pInfo) {
    index++;
    if (index > pInfo.length - 1) {
        index = 0;
    }
    var a = document.getElementById(id + '_currentImage');
    a.innerHTML = pInfo[index].productImage;
    a.href = pInfo[index].productLink;

    document.getElementById(id + '_productLinkId').innerHTML = pInfo[index].productDisplayName;
    document.getElementById(id + '_productLinkId').href = pInfo[index].productLink;
    return index;
}

function ShowNextAccessory(id, index, pInfo) {
    index++;
    if (index > pInfo.length - 1) {
        index = 0;
    }
    var a = document.getElementById(id + '_currentImage');
    a.innerHTML = pInfo[index].productImage;
    a.href = pInfo[index].productLink;

    document.getElementById(id + '_productLinkId').innerHTML = pInfo[index].productDisplayName;
    document.getElementById(id + '_productLinkId').href = pInfo[index].productLink;
    return index;
}

function ShowPreviousAccessory(id, index, pInfo) {

    index--;
    if (index < 0) {
        index = pInfo.length - 1;
    }
    var a = document.getElementById(id + '_currentImage');
    a.innerHTML = pInfo[index].productImage;
    a.href = pInfo[index].productLink;
    document.getElementById(id + '_productLinkId').innerHTML = pInfo[index].productDisplayName;
    document.getElementById(id + '_productLinkId').href = pInfo[index].productLink;
    return index;
}

//************************** FAQ expand / collapse  ************************************

var _h = {};
// constructor
_h.Tree = function (id) {

    //img/htree_item.gif
    this.id = id;
    this.cookiePath = "/";
    this.useIcons = true;
    this.useCookies = false;
    this.foldersAsLinks = false;
    this.oneSibling = true;
    this.icon = {
        align: "left",
        open: "/sites/Jabra/Style Library/Images/arrow_open.gif",
        closed: "/sites/Jabra/Style Library/Images/arrow_closed.gif",
        item: "/sites/Jabra/Style Library/Images/blank.gif"
    };
    this.navigation = this._keyNavigation;
};
_h.Tree.prototype.isSupported = (document.createElement &&
											document.getElementById &&
											document.getElementsByTagName);
_h.Tree.prototype.build = function () {
    if (!this.isSupported) return;
    this._list = document.getElementById(this.id);
    if (!this._list) return;
    this._list.className = "hTreeJS";
    var aLI = this._list.getElementsByTagName("li");
    for (var i = 0; i < aLI.length; i++) {
        var oLI = aLI[i];
        var aUL = oLI.getElementsByTagName("ul");
        if (aUL.length > 0) {
            var oUL = aUL[0];
            oLI._hTree_folder = true;
            oUL.setAttribute('id', this.id + '-' + i);
            this.CreateTreeFolder(oLI, oUL);
        } else {
            oLI._hTree_folder = false;
            this.CreateTreeItem(oLI);
        }
    }
};
_h.Tree.prototype.CreateTreeFolder = function (oLI, oUL) {
    var me = this;

    if (this.useCookies) { oLI._hTree_open = ((_h.getCookie(oUL.id)) == '1') ? true : false; }
    oLI._hTree_open = (_h.hasClass(oUL, "open")) ? true : oLI._hTree_open;
    oLI._hTree_open = (_h.hasClass(oUL, "closed")) ? false : oLI._hTree_open;

    /* Link */
    var aLinks = oLI.getElementsByTagName("a");
    if (!aLinks) this.CreateTreeItem(oLI);

    var oLink = aLinks[0];
    if (oLink.parentNode != oLI) this.CreateTreeItem(oLI);

    if (this.foldersAsLinks == false) {
        oLink.href = "#";
        oLink.onclick = function () {
            me.toggle(oLI);
            return false;
        }
    }
    oLink.onkeydown = function (e) {
        var code;
        if (!e) var e = window.event;
        if (e.keyCode) code = e.keyCode;
        else if (e.which) code = e.which;
        me.navigation(code, oLI);
    }

    oLink._hTree_oLI = oLI;


    /* IMG */
    var oIMG = null;
    if (this.useIcons) {
        oIMG = document.createElement("img");

        oIMG.src = oLI._hTree_open ? this.icon.open : this.icon.closed;
        oIMG.alt = oLI._hTree_open ? "-" : "+";
        oIMG.onclick = function () {
            me.toggle(oLI);
            return false;
        }
        oIMG._hTree_oLI = oLI;

        if (this.icon.align == "left") {
            oLI.insertBefore(oIMG, oLink);
        } else {
            oLI.insertBefore(oIMG, oLink.nextSibling);
        }
    }

    oLI._hTree_oUL = oUL;
    oLI._hTree_oIMG = oIMG;
    oLI._hTree_oLink = oLink;

    oUL._hTree_oLI = oLI;
    oUL.style.display = oLI._hTree_open ? 'block' : 'none';
};

_h.Tree.prototype.CreateTreeItem = function (oLI) {
    var me = this;

    var aLinks = oLI.getElementsByTagName("a");
    if (aLinks) {
        var oLink = aLinks[0];
        if (oLink) {
            if (oLink.parentNode == oLI) {
                oLink.onkeydown = function (e) {
                    var code;
                    if (!e) var e = window.event;
                    if (e.keyCode) code = e.keyCode;
                    else if (e.which) code = e.which;
                    me.navigation(code, oLI);
                }
            }
            oLI._hTree_oLink = oLink;
        }
    }

    oLI._hTree_open = false;

    if (this.useIcons) {
        var oIMG = document.createElement("img");

        oIMG.src = this.icon.item;
        oIMG.alt = ""; //alt-text on item img
        if (this.icon.align == "left") {
            oLI.insertBefore(oIMG, oLI.firstChild); // 
            //oLI.insertBefore(oIMG,oLI.firstChild);	
        } else {
            oLI.insertBefore(oIMG, oLI.firstChild.nextSibling);
        }
    }
};
_h.Tree.prototype.toggle = function (oLI) {
    if (oLI._hTree_folder == true) {
        if (oLI._hTree_open == true) {
            this.collapse(oLI);
        } else {
            if (this.oneSibling == true) {
                this.closeSiblings(oLI);
            }
            this.expand(oLI);
        }
    }
};
_h.Tree.prototype.collapse = function (oLI) {
    var oIMG = oLI._hTree_oIMG;
    var oUL = oLI._hTree_oUL;

    oUL.style.display = "none";
    if (oIMG) {
        oIMG.src = this.icon.closed;
        oIMG.alt = "+";
    }
    oLI._hTree_open = false;
    _h.setCookie(oUL.id, "0", this.cookiePath);
}
_h.Tree.prototype.expand = function (oLI) {
    var oIMG = oLI._hTree_oIMG;
    var oUL = oLI._hTree_oUL;

    oUL.style.display = "block";
    if (oIMG) {
        oIMG.src = this.icon.open;
        oIMG.alt = "-";
    }
    oLI._hTree_open = true;
    _h.setCookie(oUL.id, "1", this.cookiePath);
}
_h.Tree.prototype.select = function (oLI) {
    if (oLI._hTree_oLink)
        oLI._hTree_oLink.focus()
};
_h.Tree.prototype.closeSiblings = function (oLI) {
    var oUL = oLI.parentNode;
    for (var x = oUL.childNodes.length - 1; x >= 0; x--) {
        if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
        if (oUL.childNodes[x] != oLI) {
            if (oUL.childNodes[x]._hTree_open) {
                this.collapse(oUL.childNodes[x]);
            }
        }
    }
};
_h.Tree.prototype.getNextLI = function (oLI) {
    var oUL = oLI.parentNode;
    var bCurrentLI = false;
    for (var x = 0; x < oUL.childNodes.length; x++) {
        if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
        if (oLI == oUL.childNodes[x]) {
            bCurrentLI = true;
            continue;
        }
        if (bCurrentLI == true) {
            return oUL.childNodes[x];
        }
    }
    return this.getNextLI(oUL.parentNode);
};
_h.Tree.prototype.getPrevLI = function (oLI) {
    var oUL = oLI.parentNode;
    var bCurrentLI = false;
    for (var x = oUL.childNodes.length - 1; x >= 0; x--) {
        if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
        if (oUL.childNodes[x] == oLI) {
            bCurrentLI = true;
            continue;
        }
        if (bCurrentLI == true) {
            if (oUL.childNodes[x]._hTree_open) {
                return this.getLast(oUL.childNodes[x]);
            } else {
                return oUL.childNodes[x];
            }
        }
    }
    return oUL.parentNode;
};
_h.Tree.prototype.getLast = function (oLI) {
    var oUL = oLI._hTree_oUL;
    for (var x = oUL.childNodes.length - 1; x >= 0; x--) {
        if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
        if (oUL.childNodes[x]._hTree_open) {
            return this.getLast(oUL.childNodes[x]);
        } else {
            return oUL.childNodes[x];
        }
    }
};
_h.Tree.prototype._keyNavigation = function (code, oLI) {
    if ((code == 37) || (code == 38) || (code == 39) || (code == 40)) {
        var oIMG = oLI._hTree_oIMG;
        var oUL = oLI._hTree_oUL;

        if (code == 37) { /* Left */
            if (oLI._hTree_open) {
                this.toggle(oLI);
            } else {
                this.select(oLI.parentNode.parentNode);
            }
        } else if (code == 38) { /* Up */
            var oLI_prev = this.getPrevLI(oLI);
            if (oLI_prev) { this.select(oLI_prev); }
            return false;
        } else if (code == 39) { /* Right */
            if (oLI._hTree_open) {
                if (oLI.getElementsByTagName("li")) {
                    this.select(oLI.getElementsByTagName("li")[0])
                }
            } else {
                this.toggle(oLI);
            }
        } else if (code == 40) { /* Down */
            if (oLI._hTree_open) {
                if (oLI.getElementsByTagName("li")) {
                    this.select(oLI.getElementsByTagName("li")[0])
                }
            } else {
                var oLI_next = this.getNextLI(oLI);
                if (oLI_next) { this.select(oLI_next); }
            }
        }
    } else {
        return true;
    }
};


// Helper functions
_h.getCookie = function (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            var endstr = document.cookie.indexOf(";", j);
            if (endstr == -1) endstr = document.cookie.length;
            return unescape(document.cookie.substring(j, endstr));
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
_h.setCookie = function (key, value, path) {
    document.cookie = key + "=" + escape(value) + ((path) ? "; path=" + path : "");
}
_h.hasClass = function (el, className) {
    var cs, j
    cs = el.className.split(" ");
    for (j = 0; j < cs.length; j++) {
        if (cs[j] == className) {
            return true;
        }
    }
    return false;
}
_h.addClass = function (el, className) {
    if (el.className == null)
        el.className = '';
    el.className += (el.className.length > 0 ? ' ' : '') + className;
}
_h.removeClass = function (el, className) {
    var cs, j, remainClass
    remainClass = new Array();
    cs = el.className.split(" ");
    for (j = 0; j < cs.length; j++) {
        if (cs[j] != className) {
            remainClass.push(cs[j]);
        }
    }
    el.className = remainClass.join(" ");
}
_h.addEvent = function (oEl, sEvent, sFunction, useCapture) {
    if (oEl) {
        if (oEl.addEventListener) { // MOZ
            oEl.addEventListener(sEvent, sFunction, useCapture);
            return true;
        } else if (oEl.attachEvent) { // IE5
            var r = oEl.attachEvent("on" + sEvent, sFunction);
            return r;
            //		} else if (document.all) { // IE4
            //			eval('oEl.on'+sEvent+'='+sFunction+';');
            //		} else {
            //		  alert("Handler could not be attached");
        }
    }
}

// Array.push() - Add an element to the end of an array
if (typeof (Array.prototype.push) == 'undefined') {
    Array.prototype.push = function () {
        var currentLength = this.length;
        for (var i = 0; i < arguments.length; i++) {
            this[currentLength + i] = arguments[i];
        }
        return this.length;
    };
}

//**************************// FAQ expand / collapse  END //************************************ 

//********************** expand / collapse for sitemap START //**********************
var _s = {};
// constructor
_s.SiteTree = function (id) {

    //img/htree_item.gif
    this.id = id;
    this.cookiePath = "/";
    this.useIcons = true;
    this.useCookies = false;
    this.foldersAsLinks = false;
    this.oneSibling = true;
    this.icon = {
        align: "left",
        open: "../Images/black_open1_1601.gif",
        closed: "../Images/black_closed1_1601.gif",
        item: "../Images/red_closed_1601.gif"
    };
    this.navigation = this._keyNavigation;
};
_s.SiteTree.prototype.isSupported = (document.createElement &&
											document.getElementById &&
											document.getElementsByTagName);
_s.SiteTree.prototype.build = function () {
    if (!this.isSupported) return;
    this._list = document.getElementById(this.id);
    if (!this._list) return;
    this._list.className = "sSiteTreeJS";
    var aLI = this._list.getElementsByTagName("li");
    for (var i = 0; i < aLI.length; i++) {
        var oLI = aLI[i];
        var aUL = oLI.getElementsByTagName("ul");
        if (aUL.length > 0) {
            var oUL = aUL[0];
            oLI._sSiteTree_folder = true;
            oUL.setAttribute('id', this.id + '-' + i);
            this.CreateSiteTreeFolder(oLI, oUL);
        } else {
            oLI._sSiteTree_folder = false;
            this.CreateSiteTreeItem(oLI);
        }
    }
};
_s.SiteTree.prototype.CreateSiteTreeFolder = function (oLI, oUL) {
    var me = this;

    if (this.useCookies) { oLI._sSiteTree_open = ((_s.getCookie(oUL.id)) == '1') ? true : false; }
    oLI._sSiteTree_open = (_s.hasClass(oUL, "open")) ? true : oLI._sSiteTree_open;
    oLI._sSiteTree_open = (_s.hasClass(oUL, "closed")) ? false : oLI._sSiteTree_open;

    /* Link */
    var aLinks = oLI.getElementsByTagName("a");
    if (!aLinks) this.CreateSiteTreeItem(oLI);

    var oLink = aLinks[0];
    if (oLink.parentNode != oLI) this.CreateSiteTreeItem(oLI);

    if (this.foldersAsLinks == false) {
        oLink.href = "#";
        oLink.onclick = function () {
            me.toggle(oLI);
            return false;
        }
    }
    oLink.onkeydown = function (e) {
        var code;
        if (!e) var e = window.event;
        if (e.keyCode) code = e.keyCode;
        else if (e.which) code = e.which;
        me.navigation(code, oLI);
    }

    oLink._sSiteTree_oLI = oLI;


    /* IMG */
    var oIMG = null;
    if (this.useIcons) {
        oIMG = document.createElement("img");

        oIMG.src = oLI._sSiteTree_open ? this.icon.open : this.icon.closed;
        oIMG.alt = oLI._sSiteTree_open ? "-" : "+";
        oIMG.onclick = function () {
            me.toggle(oLI);
            return false;
        }
        oIMG._sSiteTree_oLI = oLI;

        if (this.icon.align == "left") {
            oLI.insertBefore(oIMG, oLink);
        } else {
            oLI.insertBefore(oIMG, oLink.nextSibling);
        }
    }

    oLI._sSiteTree_oUL = oUL;
    oLI._sSiteTree_oIMG = oIMG;
    oLI._sSiteTree_oLink = oLink;

    oUL._sSiteTree_oLI = oLI;
    oUL.style.display = oLI._sSiteTree_open ? 'block' : 'none';
};

_s.SiteTree.prototype.CreateSiteTreeItem = function (oLI) {
    var me = this;

    var aLinks = oLI.getElementsByTagName("a");
    if (aLinks) {
        var oLink = aLinks[0];
        if (oLink) {
            if (oLink.parentNode == oLI) {
                oLink.onkeydown = function (e) {
                    var code;
                    if (!e) var e = window.event;
                    if (e.keyCode) code = e.keyCode;
                    else if (e.which) code = e.which;
                    me.navigation(code, oLI);
                }
            }
            oLI._sSiteTree_oLink = oLink;
        }
    }

    oLI._sSiteTree_open = false;

    if (this.useIcons) {
        var oIMG = document.createElement("img");

        oIMG.src = this.icon.item;
        oIMG.alt = ""; //alt-text on item img
        if (this.icon.align == "left") {
            oLI.insertBefore(oIMG, oLI.firstChild); // 
            //oLI.insertBefore(oIMG,oLI.firstChild);	
        } else {
            oLI.insertBefore(oIMG, oLI.firstChild.nextSibling);
        }
    }
};
_s.SiteTree.prototype.toggle = function (oLI) {
    if (oLI._sSiteTree_folder == true) {
        if (oLI._sSiteTree_open == true) {
            this.collapse(oLI);
        } else {
            if (this.oneSibling == true) {
                this.closeSiblings(oLI);
            }
            this.expand(oLI);
        }
    }
};
_s.SiteTree.prototype.collapse = function (oLI) {
    var oIMG = oLI._sSiteTree_oIMG;
    var oUL = oLI._sSiteTree_oUL;

    oUL.style.display = "none";
    if (oIMG) {
        oIMG.src = this.icon.closed;
        oIMG.alt = "+";
    }
    oLI._sSiteTree_open = false;
    _s.setCookie(oUL.id, "0", this.cookiePath);
}
_s.SiteTree.prototype.expand = function (oLI) {
    var oIMG = oLI._sSiteTree_oIMG;
    var oUL = oLI._sSiteTree_oUL;

    oUL.style.display = "block";
    if (oIMG) {
        oIMG.src = this.icon.open;
        oIMG.alt = "-";
    }
    oLI._sSiteTree_open = true;
    _s.setCookie(oUL.id, "1", this.cookiePath);
}
_s.SiteTree.prototype.select = function (oLI) {
    if (oLI._sSiteTree_oLink)
        oLI._sSiteTree_oLink.focus()
};
_s.SiteTree.prototype.closeSiblings = function (oLI) {
    var oUL = oLI.parentNode;
    for (var x = oUL.childNodes.length - 1; x >= 0; x--) {
        if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
        if (oUL.childNodes[x] != oLI) {
            if (oUL.childNodes[x]._sSiteTree_open) {
                this.collapse(oUL.childNodes[x]);
            }
        }
    }
};
_s.SiteTree.prototype.getNextLI = function (oLI) {
    var oUL = oLI.parentNode;
    var bCurrentLI = false;
    for (var x = 0; x < oUL.childNodes.length; x++) {
        if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
        if (oLI == oUL.childNodes[x]) {
            bCurrentLI = true;
            continue;
        }
        if (bCurrentLI == true) {
            return oUL.childNodes[x];
        }
    }
    return this.getNextLI(oUL.parentNode);
};
_s.SiteTree.prototype.getPrevLI = function (oLI) {
    var oUL = oLI.parentNode;
    var bCurrentLI = false;
    for (var x = oUL.childNodes.length - 1; x >= 0; x--) {
        if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
        if (oUL.childNodes[x] == oLI) {
            bCurrentLI = true;
            continue;
        }
        if (bCurrentLI == true) {
            if (oUL.childNodes[x]._sSiteTree_open) {
                return this.getLast(oUL.childNodes[x]);
            } else {
                return oUL.childNodes[x];
            }
        }
    }
    return oUL.parentNode;
};
_s.SiteTree.prototype.getLast = function (oLI) {
    var oUL = oLI._sSiteTree_oUL;
    for (var x = oUL.childNodes.length - 1; x >= 0; x--) {
        if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
        if (oUL.childNodes[x]._sSiteTree_open) {
            return this.getLast(oUL.childNodes[x]);
        } else {
            return oUL.childNodes[x];
        }
    }
};
_s.SiteTree.prototype._keyNavigation = function (code, oLI) {
    if ((code == 37) || (code == 38) || (code == 39) || (code == 40)) {
        var oIMG = oLI._sSiteTree_oIMG;
        var oUL = oLI._sSiteTree_oUL;

        if (code == 37) { /* Left */
            if (oLI._sSiteTree_open) {
                this.toggle(oLI);
            } else {
                this.select(oLI.parentNode.parentNode);
            }
        } else if (code == 38) { /* Up */
            var oLI_prev = this.getPrevLI(oLI);
            if (oLI_prev) { this.select(oLI_prev); }
            return false;
        } else if (code == 39) { /* Right */
            if (oLI._sSiteTree_open) {
                if (oLI.getElementsByTagName("li")) {
                    this.select(oLI.getElementsByTagName("li")[0])
                }
            } else {
                this.toggle(oLI);
            }
        } else if (code == 40) { /* Down */
            if (oLI._sSiteTree_open) {
                if (oLI.getElementsByTagName("li")) {
                    this.select(oLI.getElementsByTagName("li")[0])
                }
            } else {
                var oLI_next = this.getNextLI(oLI);
                if (oLI_next) { this.select(oLI_next); }
            }
        }
    } else {
        return true;
    }
};


// Helper functions
_s.getCookie = function (name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            var endstr = document.cookie.indexOf(";", j);
            if (endstr == -1) endstr = document.cookie.length;
            return unescape(document.cookie.substring(j, endstr));
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
_s.setCookie = function (key, value, path) {
    document.cookie = key + "=" + escape(value) + ((path) ? "; path=" + path : "");
}
_s.hasClass = function (el, className) {
    var cs, j
    cs = el.className.split(" ");
    for (j = 0; j < cs.length; j++) {
        if (cs[j] == className) {
            return true;
        }
    }
    return false;
}
_s.addClass = function (el, className) {
    if (el.className == null)
        el.className = '';
    el.className += (el.className.length > 0 ? ' ' : '') + className;
}
_s.removeClass = function (el, className) {
    var cs, j, remainClass
    remainClass = new Array();
    cs = el.className.split(" ");
    for (j = 0; j < cs.length; j++) {
        if (cs[j] != className) {
            remainClass.push(cs[j]);
        }
    }
    el.className = remainClass.join(" ");
}
_s.addEvent = function (oEl, sEvent, sFunction, useCapture) {
    if (oEl) {
        if (oEl.addEventListener) { // MOZ
            oEl.addEventListener(sEvent, sFunction, useCapture);
            return true;
        } else if (oEl.attachEvent) { // IE5
            var r = oEl.attachEvent("on" + sEvent, sFunction);
            return r;
            //		} else if (document.all) { // IE4
            //			eval('oEl.on'+sEvent+'='+sFunction+';');
            //		} else {
            //		  alert("Handler could not be attached");
        }
    }
}

// Array.push() - Add an element to the end of an array
if (typeof (Array.prototype.push) == 'undefined') {
    Array.prototype.push = function () {
        var currentLength = this.length;
        for (var i = 0; i < arguments.length; i++) {
            this[currentLength + i] = arguments[i];
        }
        return this.length;
    };
}

//**************************// expand / collapse for sitemap END //************************************


function COWSetProductDropDown(elm) {
    var sel = document.getElementById('selectproductname');
    if (elm.value != '') {
        if (allproductlist) {
            var i = 0;
            var len = 1;
            if (sel) {
                sel.options.length = 1;
            }
            for (var i = 0; i < allproductlist.length; i++) {
                if (elm.value == allproductlist[i].family) {
                    sel.options.length = sel.options.length + 1;
                    sel.options[len].value = i;
                    sel.options[len].text = allproductlist[i].name;
                    len = len + 1;
                }
            }
            sel.disabled = false;
        }
    } else {
        sel.options.length = 1;
        sel.disabled = true;
    }
}

function COWSelectProduct(elm) {
    if (elm.value != '') {
        if (allproductlist) {
            var url = allproductlist[elm.value].url;
            window.location = url;
        }
    }
}

//************************** Component 102 Start ************************************  

function CMASelectCategory(elm) {
    window.location = elm.value;
}

//************************** Component 102 End ************************************ 

//************************** Component 501 Starts *********************************
var AllChoiceSets = new Array();

function Choice(id) {
    this.id = id;
    this.isOn = false;
    this.isEnabled = false;
}

function ChoicesSet() {
    var choices;
    var formvarid;
}

function VerifyChoices(products) {
    for (var formvarid in AllChoiceSets) {
        var choicesObject = AllChoiceSets[formvarid];
        var formelement = document.getElementById(formvarid);
        for (var choiceid in choicesObject.choices) {
            var yes = false;
            choiceobject = choicesObject.choices[choiceid];
            for (var idx in products) {
                yes |= products[idx][choiceid];
                if (yes) {
                    choiceobject.isEnabled = true;
                    var optionobjectlabel = document.getElementById(lblval + choiceid);
                    if (optionobjectlabel != null) {
                        optionobjectlabel.className = 'w200_tx_501';
                    }
                    else if (formelement.tagName == "SELECT") {
                        PopulateSelect(formelement, choiceid, true);
                    }
                    break;
                }
            }
            if (!yes) {
                choiceobject.isEnabled = false;
                var optionobjectlabel = document.getElementById(lblval + choiceid);
                if (optionobjectlabel != null) {
                    optionobjectlabel.className = 'w200_tx_501_disab';
                }
                else if (formelement.tagName == "SELECT") {
                    PopulateSelect(formelement, choiceid, false);
                }
            }
        }
    }
}

function Switch(choiceid) {
    var choicesObject = GetChoicesObject(choiceid);
    if (choicesObject != null) {
        var choiceobject = choicesObject.choices[choiceid];

        if (choiceobject.isEnabled) {
            var formelement = document.getElementById(choicesObject.formvarid);
            if (formelement.tagName == "SELECT") {
                for (var id in choicesObject.choices) {
                    choicesObject.choices[id].isOn = false;
                }
                if (formelement.value != '') {
                    choiceobject.isOn = true;
                }
            }
            else {
                var choiceimg = document.getElementById(imgval + choiceid);
                if (choiceimg != null) {
                    if (choiceimg.src == imgoff.src) {
                        choiceobject.isOn = true;
                        choiceimg.src = imgon.src;
                        UnSelectOthers(choicesObject, choiceid);
                    }
                    else {
                        choiceobject.isOn = false;
                        choiceimg.src = imgoff.src;
                    }
                }
                formelement.value = choiceid;
            }
            if (SomeSelected()) {

                VerifyOtherChoices(choiceid);
                Search();
            }
            else {
                VerifyChoices(Search());
            }
        }
    }
}

function VerifyOtherChoices(choiceid) {
    var choicesObjectForCurrent = GetChoicesObject(choiceid);

    var resultsForOtherChoices = new Array();
    var otherOnChoices = new Array();
    for (var formvarid in AllChoiceSets) {
        var choicesObject = AllChoiceSets[formvarid];
        if (formvarid != choicesObjectForCurrent.formvarid) {
            for (var idt in choicesObject.choices) {
                if (choicesObject.choices[idt].isOn) {
                    otherOnChoices[idt] = choicesObject.choices[idt];
                }
            }
        }
    }

    for (var idx1 in p) {
        var yes = true;
        for (var id1 in otherOnChoices) {
            yes &= p[idx1][id1];
        }
        if (yes && resultsForOtherChoices[p[idx1].FamilyId] == null) {
            resultsForOtherChoices[p[idx1].FamilyId] = p[idx1];
            resultsForOtherChoices[p[idx1].FamilyId].ProductId = p[idx1].ProductId;
            resultsForOtherChoices[p[idx1].FamilyId].FamilyId = p[idx1].FamilyId;
        }
    }

    for (var formvarid in AllChoiceSets) {
        var resultsToScan;
        var choicesObject = AllChoiceSets[formvarid];
        if (formvarid != choicesObjectForCurrent.formvarid) {
            resultsToScan = GetResultsForOtherChoices(choicesObject);
        }
        else {
            resultsToScan = resultsForOtherChoices;
        }

        var formelement = document.getElementById(formvarid);
        for (var id in choicesObject.choices) {
            var yes = false;
            choiceobject = choicesObject.choices[id];
            for (var idx in resultsToScan) {
                yes |= resultsToScan[idx][id];
                if (yes) {
                    choiceobject.isEnabled = true;
                    var optionobjectlabel = document.getElementById(lblval + id);
                    if (optionobjectlabel != null) {
                        optionobjectlabel.className = 'w200_tx_501';
                    }
                    else if (formelement.tagName == "SELECT") {
                        PopulateSelect(formelement, id, true);
                    }
                    break;
                }
            }
            if (!yes) {
                choiceobject.isEnabled = false;
                var optionobjectlabel = document.getElementById(lblval + id);
                if (optionobjectlabel != null) {
                    optionobjectlabel.className = 'w200_tx_501_disab';
                }
                else if (formelement.tagName == "SELECT") {
                    PopulateSelect(formelement, id, false);
                }
            }
        }
    }
}

function GetResultsForOtherChoices(choicesObject) {
    var resultsForOtherChoices = new Array();
    var otherOnChoices = new Array();
    for (var formvarid in AllChoiceSets) {
        if (formvarid != choicesObject.formvarid) {
            for (var idt in AllChoiceSets[formvarid].choices) {
                if (AllChoiceSets[formvarid].choices[idt].isOn) {
                    otherOnChoices[idt] = AllChoiceSets[formvarid].choices[idt];
                }
            }
        }
    }

    for (var idx1 in p) {
        var yes = true;
        for (var id1 in otherOnChoices) {
            yes &= p[idx1][id1];
        }
        if (yes && resultsForOtherChoices[p[idx1].FamilyId] == null) {
            resultsForOtherChoices[p[idx1].FamilyId] = p[idx1];
            resultsForOtherChoices[p[idx1].FamilyId].ProductId = p[idx1].ProductId;
            resultsForOtherChoices[p[idx1].FamilyId].FamilyId = p[idx1].FamilyId;
        }
    }
    return resultsForOtherChoices;
}

function Search() {
    var count = 0;
    var results = new Array();
    for (idx = 0; idx < p.length; idx++) {
        var yes = true;
        if (SomeSelected()) {
            for (var formvarid in AllChoiceSets) {
                var choiceobjects = AllChoiceSets[formvarid];
                for (var choiceid in choiceobjects.choices) {
                    var choiceobject = choiceobjects.choices[choiceid];
                    if (choiceobject.isOn) {
                        yes &= p[idx][choiceid];
                    }
                }
            }
        }
        if (yes && results[p[idx].FamilyId] == null) {
            results[p[idx].FamilyId] = p[idx];
            results[p[idx].FamilyId].ProductId = p[idx].ProductId;
            results[p[idx].FamilyId].FamilyId = p[idx].FamilyId;
            count++;
        }
    }
    DrawResults(results, count);
    return results;
}

function SomeSelected() {
    var yes = false;
    for (var formvarid in AllChoiceSets) {
        var choicesObject = AllChoiceSets[formvarid];
        for (var choiceid in choicesObject.choices) {
            yes |= choicesObject.choices[choiceid].isOn;
            if (yes) {
                return yes;
            }
        }
    }
    return yes;
}

function UnSelectOthers(choicesObject, choiceid) {
    for (var id in choicesObject.choices) {
        if (id != choiceid) {
            var choiceobject = choicesObject.choices[id];
            if (choiceobject.isEnabled && choiceobject.isOn) {
                choiceobject.isOn = false;
                var choiceimg = document.getElementById(imgval + id);
                choiceimg.src = imgoff.src;
            }
        }
    }
}

function GetChoicesObject(choiceid) {
    var choiceObject;
    for (var formvarid in AllChoiceSets) {
        if (AllChoiceSets[formvarid].choices[choiceid] != null) {
            return AllChoiceSets[formvarid];
        }
    }
}

function PopulateSelect(sel, choiceid, enabled) {
    var arrayname = GetChoicesObject(choiceid).arrayopts;
    sel.disabled = false;
    if (sel.options[0] == null) {
        var count = 0;
        for (var x in arrayname) {
            if (count == 0) {
                sel.options[0] = arrayname[x];
                break;
            }
        }
    }
    if (enabled) {
        var found = false;
        for (magic = 0; magic < sel.options.length; magic++) {
            if (sel.options[magic].value == choiceid) {
                found = true;
                break;
            }
        }
        if (!found) {
            sel.options[sel.options.length] = arrayname[choiceid];
        }
    }
    else {
        var temp;
        for (magic = 0; magic < sel.options.length; magic++) {
            if (sel.options[magic].value == choiceid) {
                temp = magic;
                break;
            }
        }
        if (temp > 0) {
            sel.options[temp] = null;
        }
    }
    if (sel.options.length == 1) {
        sel.options[0].selected = true;
        sel.disabled = true;
    }
}

function DrawResults(products, count) {
    if (resultsTable && resultsTable != null) {
        comparisonCounter = 0;
        var mainTBody;
        try {
            mainTBody = resultsTable.firstChild;
            var currRows = new Array();
            var len = mainTBody.rows.length;
            for (ii = 0; ii < mainTBody.rows.length; ii++) {
                currRows[ii] = mainTBody.rows[ii];
            }

            for (jj = 0; jj < currRows.length; jj++) {
                mainTBody.removeChild(currRows[jj]);
            }
        }
        catch (e) {
            resultsTable.innerHTML = "";
            mainTBody = document.createElement('TBODY');
            resultsTable.appendChild(mainTBody);
        }
        var rows = (count % 2 == 0) ? count / 2 : (count / 2) + 0.5;
        for (x = 0; x < rows; x++) {
            var tr = document.createElement('TR');
            mainTBody.appendChild(tr);

            var td1 = document.createElement('TD');
            tr.appendChild(td1);
            p1 = GetProductFromList(products, x, true, count);
            td1.innerHTML = DisplayProduct(p1, x);

            var td2 = document.createElement('TD');
            td2.className = 'w10_502';
            tr.appendChild(td2);

            var td3 = document.createElement('TD');
            tr.appendChild(td3);
            p1 = GetProductFromList(products, x, false, count);
            td3.innerHTML = DisplayProduct(p1, x);

            if (x != rows - 1) {
                var trspacer = document.createElement('TR');
                var tdspacer = document.createElement('TD');
                tdspacer.className = 'h10_502';
                tdspacer.colSpan = '3';
                tdspacer.innerHTML = "&nbsp;";
                trspacer.appendChild(tdspacer);
                mainTBody.appendChild(trspacer);
            }
        }
    }
}

function DisplayProduct(product, x) {
    if (product != null) {
        var result;
        //set x == 0 if the different top display is needed again
        if (x == -1) {
            var divtopprodHTML = document.getElementById('divtopprod').innerHTML;
            result = divtopprodHTML;
        }
        else {
            var divnormalprodHTML = document.getElementById('divnormalprod').innerHTML;
            result = divnormalprodHTML;
        }
        for (var h1 in product) {
            while (result.indexOf("[" + h1 + "]") != -1) {
                result = result.replace("[" + h1 + "]", product[h1]);
            }
        }
        return result;
    }
    return "&nbsp";
}

function GetProductFromList(products, row, left, count) {
    var pridx = 0;
    var pr;
    var ct = 0;
    if (left) {
        pridx = row * 2;
    }
    else {
        pridx = row * 2 + 1;
    }
    for (var hh in products) {
        if (ct == count) {
            return null;
        }
        if (ct == pridx) {
            return products[hh];
        }
        ct++;
    }
}
//************************** Component 501 Ends ***********************************

//************************** Component 607 Starts ************************************  

// start ajax

var thirdPartyProductXmlHttp = null;
var thirdPartyProductSelectId = null;
var tppPreselection = null;

function initManufacturers(serviceUrl, manuListId, tppSelectId, siteId, languageId) {
    var manuval = Cookies.value(manuListId);
    var manuList = document.getElementById(manuListId);

    if (manuval != "") {
        var prodval = Cookies.value(tppSelectId);

        // iterate over manufacturers to see if pre-selection is valid (it might
        // not be to a restriction to one manufacturer)
        for (var i = 0; i < manuList.options.length; i++) {
            if (manuList.options[i].value == manuval) {
                manuList.value = manuval;
                tppPreselection = prodval;
                break;
            }
        }
    }

    loadTpps(serviceUrl, manuList, tppSelectId, siteId, languageId);
}

function loadTpps(serviceUrl, sel, tppSelectId, siteId, languageId) {
    var manufacturerId = sel.value;

    thirdPartyProductSelectId = tppSelectId;
    var tppSelect = document.getElementById(tppSelectId);

    tppSelect.disabled = true;
    tppSelect.options[0].text = phoneModelsLoadingVal;

    try {
        //Opera, Firefox, IE7, ...
        thirdPartyProductXmlHttp = new XMLHttpRequest();
    }
    catch (error) {
        try {
            thirdPartyProductXmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE 6 and below
        }
        catch (error) {
            return false;
        }
    }

    if (thirdPartyProductXmlHttp) {
        thirdPartyProductXmlHttp.onreadystatechange = thirdpartyProductsAjaxCallback;

        thirdPartyProductXmlHttp.open('POST', '/GN.Public.Services/crmservice.asmx', true);
        thirdPartyProductXmlHttp.setRequestHeader("SOAPAction", "http://www.jabra.com/GN.Public.Services/GetThirdPartyProductsForManufacturer");
        thirdPartyProductXmlHttp.setRequestHeader('Content-Type', 'text/xml');

        thirdPartyProductXmlHttp.send('<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\n' +
            '  <soap:Body>\n' +
            '    <GetThirdPartyProductsForManufacturer xmlns="http://www.jabra.com/GN.Public.Services">\n' +
            '      <siteId>' + siteId + '</siteId>\n' +
            '      <languageId>' + languageId + '</languageId>\n' +
            '      <manufacturerId>' + manufacturerId + '</manufacturerId>\n' +
            '    </GetThirdPartyProductsForManufacturer>\n' +
            '  </soap:Body>\n' +
            '</soap:Envelope>\n');

    }
}

function thirdpartyProductsAjaxCallback() {
    if (thirdPartyProductXmlHttp.readyState == 4) {
        var nodes = thirdPartyProductXmlHttp.responseXML.getElementsByTagName("WsThirdPartyProduct");
        var tppSelect = document.getElementById(thirdPartyProductSelectId);

        while (tppSelect.options.length > 1) {
            tppSelect.options[tppSelect.options.length - 1] = null;
        }

        for (var i = 0; i < nodes.length; i++) {
            var tppNode = nodes[i];
            tppSelect.options[tppSelect.options.length] = new Option(tppNode.childNodes[1].firstChild.nodeValue, tppNode.childNodes[0].firstChild.nodeValue);
        }

        if (tppPreselection != null) {
            // don't assign value directly, first look if it is in the list. it might not, if it 
            // not attached to the stream / has been deleted / ...
            for (var i = 0; i < tppSelect.options.length; i++) {
                if (tppSelect.options[i].value == tppSelect.value) {
                    tppSelect.value = tppPreselection;
                    break;
                }
            }
            tppPreselection = null;
        }

        tppSelect.options[0].text = phoneModelVal;
        tppSelect.disabled = false;
    }
}

// end ajax

var phoneBrandVal = 'Phone brand';
var phoneModelVal = 'Model';
var phoneModelsLoadingVal = 'Loading...';
function PopulateManufactories(list, targetid) {

    var sel = document.getElementById(targetid);
    sel.options.length = list.length + 1;
    sel.options[0] = new Option(phoneBrandVal, '', true, false);

    for (var i = 0; i < list.length; i++) {
        var ix = i + 1;
        sel.options[ix] = new Option(list[i].name, list[i].id, false, false);
    }
}

function PopulateManufactoriesSelected(list, targetid, selected_value) {

    var sel = document.getElementById(targetid);
    sel.options.length = list.length + 1;
    sel.options[0] = new Option(phoneBrandVal, '', true, false);

    for (var i = 0; i < list.length; i++) {
        var ix = i + 1;
        var selected = selected_value == list[i].id;
        sel.options[ix] = new Option(list[i].name, list[i].id, false, selected);
    }
}


function PopulateProductsSelected(list, elm, targetid, selected_value) {
    if (elm.selectedIndex == 0) {
        var sel = document.getElementById(targetid);
        var optlen = sel.options.length;
        for (var jX = 0; jX < optlen; jX++) {
            sel.options[1] = null;
        }
    }
    if (elm.selectedIndex > 0) {
        var cmanu = list[elm.selectedIndex - 1];
        var sel = document.getElementById(targetid);
        sel.options.length = cmanu.Tpp.length + 1;

        sel.options[0] = new Option(phoneModelVal, '', true, false);
        for (var i = 0; i < cmanu.Tpp.length; i++) {
            var ix = i + 1;
            var selected = cmanu.Tpp[i].id == selected_value;
            sel.options[ix] = new Option(cmanu.Tpp[i].name, cmanu.Tpp[i].id, false, selected);
        }
    }
}

function PopulateProducts(list, elm, targetid) {
    if (elm.selectedIndex == 0) {
        var sel = document.getElementById(targetid);
        var optlen = sel.options.length;
        for (var jX = 0; jX < optlen; jX++) {
            sel.options[1] = null;
        }
    }
    if (elm.selectedIndex > 0) {
        var cmanu = list[elm.selectedIndex - 1];
        var sel = document.getElementById(targetid);
        sel.options.length = cmanu.Tpp.length + 1;
        sel.options[0] = new Option(phoneModelVal, '', true, false);
        for (var i = 0; i < cmanu.Tpp.length; i++) {
            var ix = i + 1;
            sel.options[ix] = new Option(cmanu.Tpp[i].name, cmanu.Tpp[i].id, false, false);
        }
    }
}
//************************** Component 607 Ends  ************************************  

//*************************** Search ***********************************************

function GNDoSearch(id, url) {
    var sf = document.getElementById(id);
    //var sf = document.getElementById('GNmasterdarchtextfield');
    var pam = '';

    if (sf && sf.value && sf.value != '') {
        pam = '?k=' + sf.value;
    }
    window.location = url + pam;
}

function GNInvokeSearch(e, url) {
    var charCode;
    if (e && e.which) {
        e = e;
        charCode = e.which;
    }
    else {
        e = event;
        charCode = e.keyCode;
    }

    if (charCode == 13) {
        if (e.srcElement) // Works for IE
        {
            GNDoSearch(e.srcElement.id, url);
        }
        else {
            GNDoSearch(e.target.id, url); // Works for Mozilla & family
        }
        return false;
    }
    return true;
}

//*************************** Search end *******************************************

//*************************** MOSS Administration scripts START

var CMAcurrentMenuElement = null;
var CMAdidOpen = false;

document.onclick = CMAMenuHandler;

function CMAMenuHandler(e) {
    if (!CMAdidOpen && CMAcurrentMenuElement) {
        var x = CMAcurrentMenuElement.childNodes[1];
        x.className = 'CMAeditMENUBODY';
    }
    CMAdidOpen = false;
}

function CMAShowHideAdminMenu() {
    var elm1 = document.getElementById('CMAnavigation');
    var elm2 = document.getElementById('CMAmossnavigation');
    if (elm1 && elm2) {
        var x = elm2.innerHTML;
        elm2.innerHTML = elm1.innerHTML;
        elm1.innerHTML = x;
    }
}

function CMASetFix() {
    var ff = document.getElementById('CMAadminevent');
    if (ff) {
        ff.value = 'toggleopen';
        document.forms[0].submit();
    }
}

function CMAToggleEditMode() {
    var ff = document.getElementById('CMAadminevent');
    if (ff) {
        ff.value = 'toggleedit';
        document.forms[0].submit();
    }
}

function CMASetContextDate() {
    var ff = document.getElementById('CMAadminevent');
    if (ff) {
        ff.value = 'setdate';
        document.forms[0].submit();
    }
}

function CMASetShopFakeUser() {
    var ff = document.getElementById('CMAadminevent');
    if (ff) {
        ff.value = 'setfakeshopuser';
        document.forms[0].submit();
    }
}

function CMAToggleMossMode() {
    var ff = document.getElementById('CMAadminevent');
    if (ff) {
        ff.value = 'togglemoss';
        document.forms[0].submit();
    }
}


function CMAShowMossMenu() {
    var d = document.getElementById('MOSSMENU');
    if (!d) {
        d = document.getElementById('ctl00_MOSSMENU');
    }
    if (d) {
        d.className = 'CMAMOSSMENUON';
    }
}


var wasdelete = false;

function CMAToggleEditComponent(elm) {
    if (!wasdelete) {
        if (CMAcurrentMenuElement && CMAcurrentMenuElement != elm) {
            var x = CMAcurrentMenuElement.childNodes[1];
            x.className = 'CMAeditMENUBODY';
        }
        var menu = elm.childNodes[1];
        if (menu.className == 'CMAeditMENUBODY') {
            menu.className = 'CMAeditMENUBODYOPEN';
            CMAcurrentMenuElement = elm;
            CMAdidOpen = true;
        } else {
            menu.className = 'CMAeditMENUBODY';
            CMAcurrentMenuElement = null;
        }
    }
    wasdelete = false;
}

function CMADeleteAdminLink(compid) {
    if (confirm('This will delete the datalink for this component.')) {
        var hid = document.getElementById('CMAdeletesmarturlid');
        if (hid) {
            hid.value = compid;
            document.forms[0].submit();
        }
    }
    wasdelete = true;
    return false;
}

function CMASmartURLDirectBind(compid, smartUrlType) {
    var componentHiddenField = document.getElementById('CMAdirectbindcompid');
    var smartUrlTypeHiddenField = document.getElementById('CMAdirectbindsmarturltype');

    if (componentHiddenField != null && smartUrlTypeHiddenField != null) {
        componentHiddenField.value = compid;
        smartUrlTypeHiddenField.value = smartUrlType;
        document.forms[0].submit();
    }
}

function CMASmartURLBindOther(value) {
    if (value.indexOf("|") > -1) {
        var parts = value.split("|");
        CMASmartURLDirectBind(parts[0], parts[1]);
    }
    else {
        CMASmartURL(value);
    }
}

function CMAmenuitemover(elm) {
    var icon = elm.childNodes[0].childNodes[0].childNodes[0];
    icon.className = 'CMAeditMEUNITEMICONOVER';
    var text = elm.childNodes[0].childNodes[0].childNodes[1];
    text.className = 'CMAeditMEUNITEMNAMEOVER';

}

function CMAmenuitemout(elm) {
    var icon = elm.childNodes[0].childNodes[0].childNodes[0];
    icon.className = 'CMAeditMEUNITEMICON';
    var text = elm.childNodes[0].childNodes[0].childNodes[1];
    text.className = 'CMAeditMEUNITEMNAME';
}

function CMAmenuitemclick(elm, url) {
    var winobj = window.open(url, '_blank', 'height=600,width=865,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
    winobj.moveTo(50, 50);
}

function CMARefresh() {
    location.reload(true);
}


function CMASmartURL(url) {
    var winobj = window.open(url, '_blank', 'height=600,width=865,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
    winobj.moveTo(50, 50);
}


function CMAApplyDictionaryMenu() {
    var target = document.getElementById('dictionarymenucell');
    var source = document.getElementById('dictionarymenucontent');
    if (target && source) {
        target.innerHTML = source.innerHTML;
        source.innerHTML = "&nbsp;";
    }
}

function CMASiteMapAdmin(url) {
    var winobj = window.open(url, '_blank', 'height=550,width=400,status=no,toolbar=no,menubar=no,location=no,resizable=0');
    winobj.moveTo(50, 50);
}

function CMAAdminOpenAdministration(url) {
    var winobj = window.open(url, '_blank', 'height=550,width=800,status=no,toolbar=no,menubar=no,location=no,resizable=1');
    winobj.moveTo(50, 50);
}


//*************************** MOSS Administration scripts END
//************************** Component 104 Starts  ************************************  

function rememberSelection(id, path) {
    var checkBox = document.getElementById(id)
    if (checkBox.checked) {

        Cookies.create('jabradefaultPath', path, 200);
    }
    else {
        Cookies.erase('jabradefaultPath');
    }
}

var Cookies = {
    init: function () {
        if (document.cookie) {
            var allCookies = document.cookie.split('; ');
            for (var i = 0; i < allCookies.length; i++) {
                var cookiePair = allCookies[i].split('=');
                this[cookiePair[0]] = cookiePair[1];
            }
        }
    },

    create: function (name, value, days) {
        var expires = "";
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        //		else 
        //		{
        //		    expires = "; expires=0";
        //		}
        document.cookie = name + "=" + value + expires + "; path=/;";
        this[name] = value;
    },

    erase: function (name) {
        this.create(name, '', -1);
        this[name] = undefined;
    },

    value: function (c_name) {
        //	    debugger;
        //	    alert('1');
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=");
            if (c_start != -1) {
                c_start = c_start + c_name.length + 1;
                c_end = document.cookie.indexOf(";", c_start);
                if (c_end == -1) {
                    c_end = document.cookie.length;
                }
                var val = unescape(document.cookie.substring(c_start, c_end));
                return val;
            }
        }
        return "";
    }
};
Cookies.init();

function SelectManuAndProductFromCookie(manuselid, manucookiename, prodlist, prodselid, prodcookiename) {
    var manuselelm = document.getElementById(manuselid);
    var prodselelm = document.getElementById(prodselid);
    var manuval = Cookies.value(manucookiename);
    if (manuval != "") {
        manuselelm.value = manuval;
        var prodval = Cookies.value(prodcookiename);
        PopulateProducts(prodlist, manuselelm, prodselelm.id);
        prodselelm.value = prodval;
        return true;
    }
    return false;
}


//************************** Component 104 Ends  ************************************  

// Hello


//************************** Component 602 Starts  ************************************  
//var comparisonCounter = 0;

function GetLength(checkBox) {
    var count = 0;
    for (x = 0; x < document.forms[0].elements[checkBox.name].length; x++) {
        if (document.forms[0].elements[checkBox.name][x].checked) {
            count++;
        }
    }
    return count;
}

function CMACompare() {
    document.forms[0].submit();
}

function CMACountCheck(checkBox, max) {
    //    debugger;
    comparisonCounter = GetLength(checkBox);
    if (checkBox.checked && comparisonCounter == (max + 1)) {
        checkBox.checked = false;
        return false;
    }
    else if (checkBox.checked) {
        comparisonCounter++;
    }
    else if (!checkBox.checked) {
        comparisonCounter--;
    }
    return true;
}
//************************** Component 602 Ends  ************************************  

//************************** 906 Webform component start ****************************


function GNWebformSelect(formid) {
    var action = document.getElementById(formid + "_action");
    if (action) {
        action.value = 'selectform';
        document.forms[0].submit();
    }
}

function GNWebformSubmit(formid) {
    if (GNIsValidForm(formid)) {
        var action = document.getElementById(formid + "_action");
        if (action) {
            action.value = 'submitform';

            var aelm = document.getElementById("SUBMIT" + formid);
            if (aelm) {
                aelm.innerHTML = "Sending...";
            }
            document.forms[0].submit();
        }
    } else {
    }
}

function GNWebformSubmitWithoutCheck(formid) {
    var action = document.getElementById(formid + "_action");
    if (action) {
        action.value = 'submitform';

        var aelm = document.getElementById("SUBMIT" + formid);
        if (aelm) {
            aelm.innerHTML = "Sending...";
        }

        document.forms[0].submit();
    }
}

function GNWebformNextPage(thisPage, nextPage) {
    document.getElementById('Page' + thisPage).style.display = 'none';
    document.getElementById('Page' + nextPage).style.display = 'block';
}

var FieldValidation = new Object();
var FieldValidationClone = new Object();
var RequiredValidationMessage = 'Please fill in all required fields.';
var GNEmailErrorMessage = 'Email format is wrong - please enter a correct email.';
var GNNumericErrorMessage = 'Only numbers can be used';
var GNAlphaNumericErrorMessage = 'Only alphanumeric characters can be used';
var GNPasswordErrorMessage = "The passwords don't mach.";
var GNEmailConfirmErrorMessage = 'Please confirm email address';
var GNDateErrorMessage = "Date is not valid - please use dd-mm-yyyy format";

function GNSetBlockFieldValidation(validation, errormessage, formblockid) {
    var identity = formblockid;

    if (!formblockid || formblockid == '') {
        identity = 'def';
    }
    eval("FieldValidation['" + identity + "']=" + validation);
    FieldValidation[identity].RequiredValidationMessage = errormessage;
    RequiredValidationMessage = errormessage;
}

function GNSetFieldValidation(validation, errormessage, formid) {
    var identity = formid;

    if (!formid || formid == '') {
        identity = 'def';
    }
    eval("FieldValidation['" + identity + "']=" + validation);
    FieldValidation[identity].RequiredValidationMessage = errormessage;
    RequiredValidationMessage = errormessage;
}

function GNIsValidFormBlock(formblockid) {
    if (document.getElementById(formblockid).style.display != 'none') {

        var identity = formblockid;
        if (!formblockid || formblockid == '') {
            identity = 'def';
        }

        if (FieldValidation[identity] != null) {
            RequiredValidationMessage = FieldValidation[identity].RequiredValidationMessage;

            for (var i = 0; i < FieldValidation[identity].length; i++) {
                if (!GNCheckValidation(FieldValidation[identity][i].Name, FieldValidation[identity][i].Value, FieldValidation[identity][i].Type, FieldValidation[identity][i].Required, "displayblock")) {
                    var elm = document.getElementById(FieldValidation[identity][i].Name);
                    if (elm) {
                        elm.focus();
                    }
                    return false;
                }
            }
        }
    }
    return true;
}

function GNIsValidForm(formid) {
    var identity = formid;
    if (!formid || formid == '') {
        identity = 'def';
    }

    if (FieldValidation[identity] != null) {
        RequiredValidationMessage = FieldValidation[identity].RequiredValidationMessage;

        for (var i = 0; i < FieldValidation[identity].length; i++) {
            if (!GNCheckValidation(FieldValidation[identity][i].Name, FieldValidation[identity][i].Value, FieldValidation[identity][i].Type, FieldValidation[identity][i].Required, "popup")) {
                var elm = document.getElementById(FieldValidation[identity][i].Name);
                if (elm) {
                    elm.focus();
                }
                return false;
            }
        }
    }
    return true;
}

function GNIsValidFormDisplayOption(formid, displayoption) {
    var identity = formid;
    if (!formid || formid == '') {
        identity = 'def';
    }

    RequiredValidationMessage = FieldValidation[identity].RequiredValidationMessage;

    if (FieldValidation[identity] != null) {
        for (var i = 0; i < FieldValidation[identity].length; i++) {
            if (!GNCheckValidation(FieldValidation[identity][i].Name, FieldValidation[identity][i].Value, FieldValidation[identity][i].Type, FieldValidation[identity][i].Required, displayoption)) {
                var elm = document.getElementById(FieldValidation[identity][i].Name);
                if (elm) {
                    elm.focus();
                }
                return false;
            }
        }
    }
    return true;
}

function GNCheckValidation(fieldName, valueR, vtype, required, alertmethod) {
    var value;
    var deelm = document.getElementById(fieldName);
    if (!(deelm) || deelm == null || (!deelm.value) || deelm.value == null) {
        value = valueR;
    } else {
        value = deelm.value;
    }

    if (required == "True") {
        if (!GNCheckRequired(fieldName, value, alertmethod)) {
            return false;
        }
    }

    if (value != '') {
        switch (vtype) {

            case "Email":
                if ((document.getElementById(fieldName + '_confirm') != null
                        && document.getElementById(fieldName).value != document.getElementById(fieldName + '_confirm').value)
                        || (!GNValidateEmailAddress(value))) {
                    if (alertmethod == "displayblock") {
                        GNValidateMessageOnOff(fieldName, 'block');
                    }
                    else {
                        alert(GNEmailErrorMessage);
                    }
                    return false;
                }
                if (alertmethod == "displayblock") {
                    GNValidateMessageOnOff(fieldName, 'none');
                }
                return true;
                break;

            case "Password":
                if ((document.getElementById(fieldName + '_confirm') != null && document.getElementById(fieldName).value !=
                        document.getElementById(fieldName + '_confirm').value) || document.getElementById(fieldName).value.length < 6) {
                    if (alertmethod == "displayblock") {
                        GNValidateMessageOnOff(fieldName, 'block');
                    }
                    else {
                        alert(GNPasswordErrorMessage);
                    }
                    return false;
                }

                if (alertmethod == "displayblock") {
                    GNRequiredMessageOnOff(fieldName, 'none');
                    GNValidateMessageOnOff(fieldName, 'none');
                }
                return true;
                break;

            case "Numeric":
                var pattern = /^([0-9]+)$/;
                if (!document.getElementById(fieldName).value.match(pattern)) {
                    if (alertmethod == "displayblock") {
                        GNValidateMessageOnOff(fieldName, 'block');
                    }
                    else {
                        alert(GNNumericErrorMessage);
                    }
                    return false;
                }

                if (alertmethod == "displayblock") {
                    GNValidateMessageOnOff(fieldName, 'none');
                }
                return true;
                break;

            case "AlphaNumeric":
                var pattern = /^([a-zA-Z0-9]+)$/;
                if (!document.getElementById(fieldName).value.match(pattern)) {
                    if (alertmethod == "displayblock") {
                        GNValidateMessageOnOff(fieldName, 'block');
                    }
                    else {
                        alert(GNAlphaNumericErrorMessage);
                    }
                    return false;
                }

                if (alertmethod == "displayblock") {
                    GNValidateMessageOnOff(fieldName, 'none');
                }
                return true;
                break;

            case "Date":
                var pattern = new RegExp("[0-3][0-9]-(0|1)[0-9]-(19|20)[0-9]{2}");

                if (document.getElementById(fieldName).value.match(pattern)) {
                    var date_array = document.getElementById(fieldName).value.split("-");
                    var day = date_array[0];
                    var month = date_array[1] - 1;
                    var year = date_array[2];

                    var refDate = new Date(year, month, day);

                    if (year != refDate.getFullYear() || month != refDate.getMonth() || day != refDate.getDate()) {
                        if (alertmethod == "displayblock") {
                            GNValidateMessageOnOff(fieldName, 'block');
                        }
                        else {
                            alert(GNDateErrorMessage);
                        }
                        return false;
                    }
                    else {
                        return true;
                    }
                }
                else {
                    if (alertmethod == "displayblock") {
                        GNValidateMessageOnOff(fieldName, 'block');
                    }
                    else {
                        alert(GNAlphaNumericErrorMessage);
                    }
                    return false;
                }
                break;
        }
    }

    if (alertmethod == "displayblock") {
        GNValidateMessageOnOff(fieldName, 'none');
    }
    return true;
}

function GNCheckRequired(fieldName, value, alertmethod) {
    var elm = document.getElementById(fieldName);


    if (elm == null) {
        // The field was not represented by is id, we look in the form on the name, and assume checkboxes or radio buttons.
        elm = document.forms[0].elements[fieldName];
        if (elm && elm.length && elm.length > 0) {
            for (var i = 0; i < elm.length; i++) {
                if (elm[i].checked) {
                    return true;
                }
            }
            elm[0].focus();
            alert(RequiredValidationMessage);
            return false;
        }
    }

    if (!elm) {
        return true; // We do not try to valid fields that are no longer on the form
    }

    if (elm.type == 'checkbox') {
        if (!elm.checked) {
            alert(RequiredValidationMessage);
        }
        return elm.checked; // required checkbox should always be true
    }

    if (elm.tagName.toLowerCase() == 'select') {
        if (elm.selectedIndex <= 0) {
            alert(RequiredValidationMessage);
        }
        return elm.selectedIndex > 0; // required dropdown should always have an index higher than 0
    }

    if (value == null || value == "") {
        if (alertmethod == "displayblock") {
            GNRequiredMessageOnOff(fieldName, 'block');
        }
        else {
            alert(RequiredValidationMessage);
        }
        return false;
    }

    if (alertmethod == "displayblock") {
        GNRequiredMessageOnOff(fieldName, 'none');
    }
    return true;
}

function GNRequiredMessageOnOff(field, disp) {
    var elm = document.getElementById(field + "_requiredalert");
    if (elm) {
        elm.style.display = disp;
    }
}

function GNValidateMessageOnOff(field, disp) {
    var elm = document.getElementById(field + "_validationalert");
    if (elm) {
        elm.style.display = disp;
    }
}


function GNValidateEmailAddress(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false
    }

    if (str.indexOf(" ") != -1) {
        return false
    }
    return true
}


function GNSetWebFormFieldValue(formid, fieldid, value) {
    var identity = formid;
    if (!formid || formid == '') {
        identity = 'def';
    }

    if (FieldValidation[identity] == null) {
        return;
    }
    for (var i = 0; i < FieldValidation[identity].length; i++) {
        if (fieldid == FieldValidation[identity][i].Name) {
            FieldValidation[identity][i].Value = value;
        }
    }
}

function GNSetWebFormCheckBoxValue(formid, checkBoxName) {

    var objCheckBox = document.forms[0].elements[checkBoxName];

    if (!objCheckBox) {
        return;
    }
    var countCheckBoxes = objCheckBox.length;
    if (!countCheckBoxes) {
        if (objCheckBox.Checked) {
            GNSetWebFormFieldValue(formid, focheckBoxName, '1');
        }
        else {
            GNSetWebFormFieldValue(formid, checkBoxName, '');
        }

    }
    else {
        for (var i = 0; i < countCheckBoxes; i++) {
            if (objCheckBox[i].checked) {
                GNSetWebFormFieldValue(formid, checkBoxName, '1');
                return;
            }
        }
        GNSetWebFormFieldValue(formid, checkBoxName, "");
    }
}


//************************** 906 Webform component end ****************************** 

//************************** Product Page IssuePopup start ****************************** 
var cX = -100; var cY = -100;
function UpdateCursorPosition(e) {
    cX = e.pageX;
    cY = e.pageY;
}

function UpdateCursorPositionDocAll(e) {
    cX = event.clientX;
    cY = event.clientY;
}

if (document.all) {
    document.onclick = UpdateCursorPositionDocAll;
}
else {
    document.onclick = UpdateCursorPosition;
}

function AssignPosition(d) {
    if (issueinfodivXpos.value == "0px" && issueinfodivYpos.value == "0px") {
        d.style.left = (cX + 0) + "px";
        d.style.top = (cY + 0) + "px";
    }
    else {
        d.style.left = issueinfodivXpos.value;
        d.style.top = issueinfodivYpos.value;
    }
    issueinfodivXpos.value = d.style.left;
    issueinfodivYpos.value = d.style.top;
}

function HideContent(d) {
    var div = document.getElementById(d);
    if (d.length < 1) {
        return;
    }
    if (div != null) {
        div.style.display = "none";
    }
}

function ShowContent(d) {
    if (d.length < 1) {
        return;
    }
    var div = document.getElementById(d);
    if (div != null) {
        AssignPosition(div);
        div.style.display = "block";
    }
}
//************************** Product Page IssuePopup end ****************************** 
//************************** Channel Selector ToggleDivs start ****************************** 
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if (document.layers)	   //NN4+
    {
        document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if (document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if (document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}
//************************** Channel Selector ToggleDivs end ****************************** 


function GNFormSelectProductValue(elm) {
    var target = document.getElementById(elm.id + '_name');

    if (target != null) {
        if (elm.selectedIndex && elm.selectedIndex > 0) {
            target.value = elm.options[elm.selectedIndex].text;
        } else {
            target.value = '';
        }
    }
}

//*********************************************** login box start *************************/

function logout() {
    var logoutHiddenField = document.getElementById('inputGenLogoff');
    logoutHiddenField.value = 'true';
    document.forms[0].submit();
}

//*********************************************** login box end *************************/


//*********************************************** Wizard handlers start *****************/

function GNWizardSubmit(wizardid, index) {
    var next = document.getElementById(wizardid + '_next');
    if (next) {
        next.value = index;
        document.forms[0].submit();
    }
}

function GNWizardOpenNext(wizardid) {
    var current = document.getElementById(wizardid + '_current');
    var next = parseInt(current.value) + 1;
    var td = document.getElementById(wizardid + '_step' + next);

    if (td) {
        td.className = 'Selectable_ProgressBox';
        td.onclick = function () { GNWizardSubmit(wizardid, 'next'); };
    }

    var img = document.getElementById(wizardid + '_next_image');
    img.src = nextimage.src;

    td = document.getElementById(wizardid + '_next_td');
    td.onclick = function () { GNWizardSubmit(wizardid, 'next'); };
}

//*********************************************** Wizard handlers end   *****************/

//*********************************************** Hedaset Guide start   *****************/

function toggleGuidance(boxid) {
    var box = document.getElementById(boxid);
    if (box.style.display == 'none' || box.style.display == '') {
        box.style.display = 'inline';
    }
    else {
        box.style.display = 'none';
    }
}

function Primary(name, id) {
    this.name = name;
    this.id = id;
    this.sub = new Array();
    this.index = 0;

    this.addChild = function (id, sname) {
        this.sub[this.index] = new Object();
        this.sub[this.index].id = id;
        this.sub[this.index].name = sname;
        this.index++;
    }

    this.addChildren = function (ids, snames) {
        for (var ix = 0; ix < ids.length; ix++) {
            this.sub[this.index] = new Object();
            this.sub[this.index].id = ids[ix];
            this.sub[this.index].name = snames[ix];
            this.index++;
        }
    }
}

function toggleTab(module, section) {
    var uls = document.getElementById(module).getElementsByTagName('ul');
    var tabs = new Array();
    for (i = 0; i < uls.length; i++)
        if (uls[i].className == 'tabs') tabs = uls[i].getElementsByTagName('li');
    var divs = document.getElementById(module).getElementsByTagName('div');
    var sections = new Array();
    for (i = 0; i < divs.length; i++)
        if (divs[i].className == 'section') sections[sections.length++] = divs[i];

    if (tabs.length != sections.length) {
        alert('warning: your number of tabs (' + tabs.length + ') differs from your number of sections (' + sections.length + ')');
        return;
    }
}
function hsgTechnicalSpecs(url, width, height) {
    var options = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1";
    window.open(url, 'name', options + ',width=' + width + ',height=' + height);
}

function hsgPrintView(url, width, height) {
    var options = "toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1";
    window.open(url, 'name', options + ',width=' + width + ',height=' + height);
}


function shopOrderReceipt(url, width, height) {
    var options = "toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1";
    window.open(url, 'name', options + ',width=' + width + ',height=' + height);
}

//*********************************************** Hedaset Guide end    *****************/

function shopOrderReceipt(url, width, height) {
    var options = "toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1";
    window.open(url, 'name', options + ',width=' + width + ',height=' + height);
}


function JabraToolClass() {
    this.ClientWidth = function () {
        return f_filterResults(
		            window.innerWidth ? window.innerWidth : 0,
		            document.documentElement ? document.documentElement.clientWidth : 0,
		            document.body ? document.body.clientWidth : 0
	            );
    };

    this.ClientHeight = function () {
        return f_filterResults(
		            window.innerHeight ? window.innerHeight : 0,
		            document.documentElement ? document.documentElement.clientHeight : 0,
		            document.body ? document.body.clientHeight : 0
	            );
    };

    this.ScrollLeft = function () {
        return f_filterResults(
		            window.pageXOffset ? window.pageXOffset : 0,
		            document.documentElement ? document.documentElement.scrollLeft : 0,
		            document.body ? document.body.scrollLeft : 0
	            );
    };

    this.ScrollTop = function () {
        return f_filterResults(
		            window.pageYOffset ? window.pageYOffset : 0,
		            document.documentElement ? document.documentElement.scrollTop : 0,
		            document.body ? document.body.scrollTop : 0
	            );
    };

    function f_filterResults(n_win, n_docel, n_body) {
        var n_result = n_win ? n_win : 0;
        if (n_docel && (!n_result || (n_result > n_docel)))
            n_result = n_docel;
        return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
    }


    this.ShowWait = function () {
        var elm = document.getElementById("pleasewait");
        if (elm != null) {
            elm.style.display = "block";
            elm.style.width = Number((this.ClientWidth() - 10)) + "px";
            elm.style.height = Number((Number(this.ClientHeight()) - 360)) + "px";
        }
        return true;
    }
}

var jabraTools = new JabraToolClass();


// ********************************************************************
// StringBuffer is a simple mechanism for effective handling of large
// javascript string concatanation.
// ********************************************************************
function StringBuffer() {
    this.buffer = [];
}

StringBuffer.prototype.append = function append(string) {
    this.buffer.push(string);
    return this;
};

StringBuffer.prototype.toString = function toString() {
    return this.buffer.join("");
};

var GNscript = new Object();
GNscript.fixedheader = 0;

GNscript.XmlBuilder = function (_root, _plain) {
    this.plain = _plain;
    if (arguments.length == 1) {
        this.plain = false;
    }

    this.root = _root;
    this.attributes = new Array();
    this.children = new Array();

    this.setAttr = function (name, value) {
        var obj = new Object();
        obj.name = name;
        obj.value = this.encodeString(value);
        this.attributes[this.attributes.length] = obj;
        return this;
    };

    this.addChild = function (name) {
        var child = new GNscript.XmlBuilder(name);
        this.children[this.children.length] = child;
        child.parent = this;
        return child;
    };

    this.body = function (content) {
        var child = new GNscript.XmlBuilder(this.encodeString(content), true);
        this.children[this.children.length] = child;
        child.parent = this;
        return child;
    };

    this.toString = function () {
        if (this.plain) {
            return this.root;
        }
        var sb = new StringBuffer();
        sb.append("<" + this.root);
        for (var i = 0; i < this.attributes.length; i++) {
            sb.append(" " + this.attributes[i].name + "='" + this.attributes[i].value + "'");
        }
        if (this.children.length > 0) {
            sb.append('>');
            for (var j = 0; j < this.children.length; j++) {
                sb.append(this.children[j].toString());
            }
            sb.append('</' + this.root + '>');
        } else {
            sb.append('/>');
        }
        return sb.toString();
    };

    this.encodeString = function (input) {
        try {
            return input.replace("&", "&amp;").replace("'", "&quot;").replace("<", "&lt;").replace(">", "&gt;");
        } catch (Error) {
            if (input) {
                return input;
            } else {
                return '';
            }
        }
    };
}

//************************************************************************************************************
// The GN root object provide comment generic platform facilities that can be used cross any other runction
//************************************************************************************************************

GNscript.ClientWidth = function () {
    return GNscript.f_filterResults(
	            window.innerWidth ? window.innerWidth : 0,
	            document.documentElement ? document.documentElement.clientWidth : 0,
	            document.body ? document.body.clientWidth : 0
            );
};

GNscript.ClientHeight = function () {
    return GNscript.f_filterResults(
	            window.innerHeight ? window.innerHeight : 0,
	            document.documentElement ? document.documentElement.clientHeight : 0,
	            document.body ? document.body.clientHeight : 0
            );
};

GNscript.ScrollLeft = function () {
    return GNscript.f_filterResults(
	            window.pageXOffset ? window.pageXOffset : 0,
	            document.documentElement ? document.documentElement.scrollLeft : 0,
	            document.body ? document.body.scrollLeft : 0
            );
};

GNscript.ScrollTop = function () {
    return GNscript.f_filterResults(
	            window.pageYOffset ? window.pageYOffset : 0,
	            document.documentElement ? document.documentElement.scrollTop : 0,
	            document.body ? document.body.scrollTop : 0
            );
};

GNscript.f_filterResults = function (n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
};

GNscript.SizeListener = new Array();

GNscript.AddSizeListener = function (elementid) {
    if (arguments.length <= 1) {
        return;
    }
    var pos = GNscript.SizeListener.length; ;
    for (var i = 0; i < GNscript.SizeListener.length; i++) {
        if (GNscript.SizeListener[i].Id == elementid) {
            pos = i;
            break;
        }
    }
    var obj = new Object();
    obj.Id = elementid;
    obj.Values = new Array();
    for (var x = 1; x < arguments.length; x++) {
        obj.Values[x - 1] = arguments[x];
    }
    GNscript.SizeListener[pos] = obj;
    GNscript.SizeWorkplace(GNscript.fixedheader);
};


GNscript.SizeWorkplace = function (headerheight) {
    GNscript.fixedheader = headerheight;
    var workplace = document.getElementById("workplace");
    if (workplace) {
        workplace.style.width = GNscript.ClientWidth() + "px";
        workplace.style.height = GNscript.ClientHeight() + "px";
        var bd = document.getElementById("workplacebody");
        if (bd) {
            bd.style.width = GNscript.ClientWidth() + "px";
            bd.style.height = Number(GNscript.ClientHeight() - headerheight) + "px";
            var dc = document.getElementById("workplacebodydynamiccontent");
            if (dc) {
                dc.style.height = Number(GNscript.ClientHeight() - (headerheight + 14)) + "px";
            }
        }
        for (var x = 0; x < GNscript.SizeListener.length; x++) {
            GNscript.SizeElementHeight(GNscript.SizeListener[x]);
        }
    }
};

GNscript.ChildOfType = function (root, type) {
    var ret = new Array();

    var all = root.children;

    for (var i = 0; i < all.length; i++) {
        if (all[i].tagName.toUpperCase() == type.toString().toUpperCase()) {
            ret[ret.length] = all[i];
        }
    }
    return ret;
}

GNscript.SizeElementHeight = function (defi) {
    var outerElement = document.getElementById(defi.Id);
    if (!outerElement) {
        return;
    }
    var total = outerElement.offsetHeight;
    var fixed = 0;
    for (var i = 0; i < defi.Values.length; i++) {
        if (defi.Values[i] > 0) {
            fixed += defi.Values[i];
        }
    }
    var variable = total - fixed;
    var target = GNscript.ChildOfType(outerElement, 'div');

    for (var x = 0; x < target.length; x++) {
        var h = defi.Values[x];
        if (h <= 0) {
            target[x].style.height = "" + variable + "px";
        } else {
            //target[x].style.height = "" + h + "px";
        }
    }
};

GNscript.AddClass = function (element, name) {
    var current = element.className;
    var newvalue = '';
    var blank = '';
    var list = current.split(' ');
    for (var i = 0; i < list.length; i++) {
        if (list[i] != name) {
            newvalue += blank + list[i];
            blank = ' ';
        }
    }
    element.className = newvalue + blank + name;
};

GNscript.RemoveClass = function (element, name) {
    var current = element.className;
    var newvalue = '';
    var blank = '';
    var list = current.split(' ');
    for (var i = 0; i < list.length; i++) {
        if (list[i] != name) {
            newvalue += blank + list[i];
            blank = ' ';
        }
    }
    element.className = newvalue;
};

GNscript.ReplaceClass = function (element, from, to) {
    this.RemoveClass(element, from);
    this.AddClass(element, to);
};


GNscript.ShowHidePopup = function (element) {
    if (element.parentNode) {
        if (element.parentNode.tagName.toUpperCase() == 'DIV') {
            var x = element.parentNode.getElementsByTagName('div')[0];
            if (x.style.display == 'block') {
                x.style.display = 'none';
            } else {
                x.style.display = 'block';
            }
        } else {
            GNscript.ShowHidePopup(element.parentNode);
        }
    }
};

GNscript.ShowInnerPopup = function (element) {
    element.getElementsByTagName('div')[0].style.display = 'block';
};

GNscript.HideInnerPopup = function (element) {
    element.getElementsByTagName('div')[0].style.display = 'none';
};

GNscript.OverElement = function (element) {
    this.ReplaceClass(element, 'out', 'over');
};

GNscript.OutElement = function (element) {
    this.ReplaceClass(element, 'over', 'out');
};


// ******************************************
// Gnax is a specific ajax webpart handler
// that allow webpart on a page to be updated
// on an event.
// ******************************************
GNscript.Gnax = function (command, param, _callback) {
    var xmlhttp;
    var callback = _callback;

    this.Run = function (furtherCallback) {
        var url = GNscript.Gnax.BuildRequestUrl();
        jQuery.ajax({
            type: "POST",
            url: url,
            data: param,
            dataType: "html",
            success: function (xml) {
                callback.Callback(xml, furtherCallback)
            },
            error: function (obj, text, error) {
                alert("An error occured. Please contact technical support");
            }
        });
    };
};

GNscript.Gnax.Listeners = new Array();

GNscript.Gnax.BuildRequestUrl = function () {
    var x = document.location.href;
    var qix = x.indexOf('?');
    if (qix >= 0) {
        x = x.substring(0, qix) + '.gnax' + x.substring(qix);
    } else {
        x = x + '.gnax';
    }

    return x;
}

GNscript.GnaxControls = new Array();

GNscript.GnaxControls.AddListener = function (element, id, classname, componentid, objectid, rootcomponentid, tabid) {

    var obj = new Object();
    obj.element = element;
    obj.id = id;
    obj.classname = classname;
    obj.componentid = componentid;
    obj.objectid = objectid;
    obj.rootcomponentid = rootcomponentid;
    obj.tabid = tabid;
    GNscript.Gnax.Listeners.push(obj);
};

GNscript.GnaxControls.Callback = function (result, furtherCallback) {

    var xmlDoc;

    if (window.DOMParser) {
        parser = new DOMParser();
        xmlDoc = parser.parseFromString(result, "text/xml");
    }
    else // Internet Explorer
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(result);
    }

    if (jQuery(xmlDoc).find('Error').text().toLowerCase() == 'true') {
        alert(jQuery(xmlDoc).find('Message').text());
    }
    else {
        var response = jQuery(xmlDoc).find('Response').text();
        if (!furtherCallback || !furtherCallback.Executer) {
            for (var i = 0; i < GNscript.Gnax.Listeners.length; i++) {
                var cid = "<!--ID:" + GNscript.Gnax.Listeners[i].id + "-->";
                var ix = response.indexOf(cid);
                if (ix > 0) {
                    var com = response.substring(0, ix);
                    if (GNscript.Gnax.Listeners[i].element) {
                        GNscript.Gnax.Listeners[i].element.innerHTML = com;
                    }
                    response = response.substring(ix + cid.length);
                }
            }
        }

        if (furtherCallback) {
            furtherCallback.Callback(response);
        }
    }
};


GNscript.Browser = new Object();
GNscript.Browser.IE_Less8 = function () {
    if (navigator.appName == "Microsoft Internet Explorer") {
        var ua = navigator.userAgent;
        var MSIEOffset = ua.indexOf("MSIE ");

        if (MSIEOffset == -1) {
            return false;
        } else {
            var ver = parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
            return ver < 8;
        }
    }
    return false;
};

// ***************************************************************
// Call Gnax method and update all Gnax registred webpart on page
// ***************************************************************
GNscript.GnaxControls.Run = function (command, param, callback, noeffect) {
    //GNscript.GnaxControls.NextCallback = callback;
    var doc = new GNscript.XmlBuilder("gnax");
    doc.addChild("command").setAttr('parameter', param).body(command);

    var listeners = GNscript.Gnax.Listeners;

    for (var i = 0; i < listeners.length; i++) {
        var listener = listeners[i];

        doc.addChild("webpart")
            .setAttr("classname", listener.classname)
            .setAttr("componentid", listener.componentid)
            .setAttr("id", listener.id)
            .setAttr("objectid", listener.objectid)
            .setAttr("rootcomponentid", listener.rootcomponentid)
            .setAttr("tabid", listener.tabid);

        if (listener.element && listener.element.offsetWidth && listener.element.offsetHeight) {
            var style = " style='width: " + listener.element.offsetWidth + "px;height: " + listener.element.offsetHeight + "px'";

            if (GNscript.Browser.IE_Less8()) {
                style = " style='left: -" + listener.element.offsetWidth + "px;width: " + listener.element.offsetWidth + "px;height: " + listener.element.offsetHeight + "px'";
            }

            if (!noeffect) {
                var demp = document.createElement("div");
                demp.className = "ajaxload";
                demp.innerHTML = "<div class='ajaxloadinner'" + style + "><div class='ajaxloadmessage'>&nbsp;</div></div>";
                listener.element.insertBefore(demp, listener.element.firstChild);
            }
        }

        //this[i].element.innerHTML = "<div class='ajaxload'><div class='ajaxloadinner'" + style + "><div class='ajaxloadmessage'>&nbsp;</div></div></div>" + this[i].element.innerHTML;
    }
    var ax = new GNscript.Gnax(command, doc.toString(), this);
    return ax.Run(callback);
};


// ***********************************************************
// Call Gnax method without updating webpart on page.
// ***********************************************************
GNscript.GnaxControls.Execute = function (command, param, callback) {
    //GNscript.GnaxControls.NextCallback = callback;
    callback.Executer = true;
    var doc = new GNscript.XmlBuilder("gnax");
    doc.addChild("command").setAttr('parameter', param).body(command);
    var ax = new GNscript.Gnax(command, doc.toString(), this);
    ax.Run(callback);
};

GNscript.GnaxControls.ExecuteSync = function (command, param, callback) {
    var doc = new GNscript.XmlBuilder("gnax");
    doc.addChild("command").setAttr('parameter', param).body(command);

    var url = GNscript.Gnax.BuildRequestUrl();
    var pageResponse;
    var successCallback = callback;

    jQuery.ajax(
        {
            async: false,
            data: doc.toString(),
            type: 'POST',
            url: url,
            success: function (response, status) {
                pageResponse = response;

                if (successCallback && successCallback.Callback)
                    successCallback.Callback(response);
            },
            error: function (response) { alert('error: Ajax call error: ' + response); }
        });

    return pageResponse;
};

GNscript.Keyboard = new Object();
GNscript.Keyboard.Backspace = 8;
GNscript.Keyboard.Tab = 9;
GNscript.Keyboard.Enter = 13;
GNscript.Keyboard.Shift = 16;
GNscript.Keyboard.Ctrl = 17;
GNscript.Keyboard.Alt = 18;
GNscript.Keyboard.Caps = 20;
GNscript.Keyboard.Esc = 27;
GNscript.Keyboard.PgUp = 33;
GNscript.Keyboard.PgUp = 34;
GNscript.Keyboard.End = 35;
GNscript.Keyboard.Home = 36;
GNscript.Keyboard.Left = 37;
GNscript.Keyboard.Up = 38;
GNscript.Keyboard.Right = 39;
GNscript.Keyboard.Down = 40;
GNscript.Keyboard.Insert = 45;
GNscript.Keyboard.Delete = 46;
GNscript.Keyboard.F1 = 123;


GNscript.AutocompleteControls = new Object();
GNscript.AutocompleteControls.Get = function (_id) {

    if (GNscript.AutocompleteControls[_id]) {
        return GNscript.AutocompleteControls[_id];
    }

    var nex = new GNscript.Autocomplete(_id);
    GNscript.AutocompleteControls[_id] = nex;
    return nex;
};

GNscript.Autocomplete = function (_id) {
    this.id = _id;
    this.currentSearch = '';
    this.match = new Array();
    this.data = new Array();
    this.Callback = null;

    this.Match = function (val) {
        if (this.Callback && this.currentSearch != val) {
            for (var i = 0; i < this.data.length; i++) {
                this.data[i].selected = false;
            }

            this.match = new Array();

            if (val != '') {
                for (var x = 0; x < this.data.length; x++) {
                    if (this.Callback.Compare(this.data[x], val)) {
                        this.match[this.match.length] = this.data[x];
                    }
                }
            }
            this.currentSearch = val;
        };
        if (this.match.length == 1) {
            this.match[0].selected = true;
        }
    };

    this.UnselectElement = function (ix) {
        var elm = document.getElementById(this.id + "result" + ix);
        if (elm) {
            GNscript.RemoveClass(elm, "sel");
        }
    };

    this.SelectElement = function (ix) {
        var elm = document.getElementById(this.id + "result" + ix);
        if (elm) {
            GNscript.AddClass(elm, "sel");
        }
    };

    this.Next = function () {
        for (var i = 0; i < this.match.length - 1; i++) {
            if (this.match[i].selected) {
                this.match[i].selected = false;
                this.UnselectElement(i);
                this.match[i + 1].selected = true;
                this.SelectElement(i + 1);
                return;
            }
        }
        if (this.match.length > 0) {
            this.match[0].selected = true;
            this.SelectElement(0);
            if (this.match.length > 1) {
                this.match[this.match.length - 1].selected = false;
                this.UnselectElement(this.match.length - 1);
            }
        }
    };

    this.Prev = function () {
        for (var i = this.match.length - 1; i > 0; i--) {
            if (this.match[i].selected) {
                this.match[i].selected = false;
                this.UnselectElement(i);
                this.match[i - 1].selected = true;
                this.SelectElement(i - 1);
                return;
            }
        }
        if (this.match.length > 0) {
            this.match[0].selected = false;
            this.UnselectElement(0);
            if (this.match.length > 1) {
                this.match[this.match.length - 1].selected = true;
                this.SelectElement(this.match.length - 1);
            }
        }
    };

    this.Over = function (ix) {
        for (var i = 0; i < this.match.length; i++) {
            if (this.match[i].selected) {
                this.match[i].selected = false;
                this.UnselectElement(i);
                break;
            }
        }
        this.match[ix].selected = true;
        this.SelectElement(ix);
    };

    this.OnKey = function (element, e) {
        var unicode = e.keyCode ? e.keyCode : e.charCode;

        setTimeout("GNscript.AutocompleteControls.Get('" + this.id + "').Perform(" + unicode + ")", 0);

        if (unicode == GNscript.Keyboard.Enter || unicode == GNscript.Keyboard.Tab) {
            return false;
        }

        return true;
    };

    this.Select = function (index) {
        var res = document.getElementById(this.id + 'result');
        res.style.display = 'none';

        this.Callback.OnEnter(this.match[index]);
    };

    this.Validate = function () {
        if (this.Callback && this.Callback.Validate) {
            var selected = null;
            for (var i = 0; i < this.match.length; i++) {
                if (this.match[i].selected) {
                    selected = this.match[i];
                }
            }
            return this.Callback.Validate(selected);
        }
        return true;
    };

    this.Perform = function (code) {
        var element = document.getElementById(this.id);
        this.Match(element.value);

        switch (code) {
            case GNscript.Keyboard.Enter:
            case GNscript.Keyboard.Tab:
                for (var i = 0; i < this.match.length; i++) {
                    if (this.match[i].selected) {
                        this.Select(i);
                        return;
                    }
                }
                return;
            case GNscript.Keyboard.Up:
                this.Prev();
                return;
            case GNscript.Keyboard.Down:
                this.Next();
                return;
        }

        var res = document.getElementById(this.id + 'result');
        var sb = new StringBuffer();
        sb.append("<div>");
        if (this.Callback && typeof this.Callback.Translate == 'function') {
            if (this.match.length > 0) {
                var t1 = this.Callback.Translate('found', this.match.length);
                sb.append("<div class='found'>" + t1 + "</div>");
            } else {
                var t2 = this.Callback.Translate('noresult');
                sb.append("<div class='found'>" + t2 + "</div>");
            }
        } else {
            sb.append("<div class='found'>Found: " + this.match.length + "</div>");
        }
        sb.append("</div>");
        for (var z = 0; z < this.match.length; z++) {
            sb.append("<div>");
            sb.append("<div id='" + this.id + "result" + z + "' class='lin" + (this.match[z].selected ? " sel" : "") + "' ");
            sb.append("onclick=\"GNscript.AutocompleteControls.Get('" + this.id + "').Select(" + z + ");\" ");
            sb.append("onmouseover=\"GNscript.AutocompleteControls.Get('" + this.id + "').Over(" + z + ");\"");
            sb.append(">");
            sb.append(this.Callback.MergeElement(this.match[z]));
            sb.append("</div>");
            sb.append("</div>");
        }


        if (this.match.length > 0) {
            res.style.display = 'block';
        } else {
            res.style.display = 'none';
        }
        res.innerHTML = sb.toString();
    };
};



// ****************************************
// Shop specific scripts
// ****************************************
GNscript.Shop = new Object();
GNscript.Shop.addFavoritText = 'Add to favorit';
GNscript.Shop.removeFavoritText = 'Remove from favorit';

GNscript.Shop.ToggleFavorite = function (me, productid) {
    var callback = new Object();
    callback.Callback = function (result) {
        if (result == 'added') {
            me.setAttribute('class', 'iconFavSelected');
            me.setAttribute('className', 'iconFavSelected');
            me.title = GNscript.Shop.removeFavoritText;
            me.innerHTML = GNscript.Shop.removeFavoritText;
        } else
            if (result == 'removed') {
                me.setAttribute('class', 'iconFav');
                me.setAttribute('className', 'iconFav');
                me.title = GNscript.Shop.addFavoritText;
                me.innerHTML = GNscript.Shop.addFavoritText;
            }
    }
    GNscript.GnaxControls.Execute("Shop.ToggleFavorit", productid, callback);
};

GNscript.Shop.Cart = new Object();

GNscript.Shop.Cart.SetProduct = function (quantityfield, product) {
    if (!this.products) {
        this.products = new Array();
    }
    var found = null;
    for (var i = 0; i < this.products.length; i++) {
        if (this.products[i].productid == product) {
            found = this.products[i];
            break;
        }
    }
    if (!found) {
        found = new Object();
        found.productid = product;
    }
    found.quantity = quantityfield.value;
    this.products.push(found);
};

GNscript.Shop.Cart.Submit = function () {
    if (this.products && this.products.length > 0) {
        var sb = new StringBuffer();
        var comma = "";
        for (var i = 0; i < this.products.length; i++) {
            sb.append(comma + this.products[i].productid + ":" + this.products[i].quantity);
            comma = ",";
        }
        GNscript.GnaxControls.Run("Shop.UpdateCart", sb.toString(), this);
    }
};

GNscript.Shop.Cart.Callback = function () {
    this.products = null;
};

GNscript.ToggleFormBlock = function (elm) {
    var block = document.getElementById(elm.id.substring(0, elm.id.length - 3));
    if (elm.childNodes[1].className == 'collapsed') {
        elm.childNodes[1].className = 'expanded';
        elm.childNodes[2].className = 'collapsed';
        block.style.display = 'block';
    } else {
        elm.childNodes[1].className = 'collapsed';
        elm.childNodes[2].className = 'expanded';
        block.style.display = 'none';
    }
};

/***********************************
* ServiceNet UserProfile Specific *
***********************************/

function UserProfileCheck(formid) {
    var identity = formid;
    if (!formid || formid == '') {
        identity = 'def';
    }

    if (FieldValidation[identity] != null) {
        for (var i = 0; i < FieldValidation[identity].length; i++) {
            GNSetWebFormFieldValue(identity, FieldValidation[identity][i].Name, document.getElementById(FieldValidation[identity][i].Name).value);
        }

        if (GNIsValidFormDisplayOption(formid, 'displayblock')) {
            document.forms[0].submit();
        }
    }
}

function CustomerInfoPOPCheck(formid) {
    var identity = formid;
    if (!formid || formid == '') {
        identity = 'def';
    }

    if (document.getElementById(identity + '_proofOfPurchase') != null) {
        if (document.getElementById(identity + '_proofOfPurchase').value == '' && !document.getElementById(identity + '_faxProofOfPurchase').checked) {
            document.getElementById('CustomerInfo_proofOfPurchase_validationalert').style.display = 'block';
        }
        else {
            UserProfileCheck(identity);
        }
    }
    else {
        UserProfileCheck(identity);
    }
}

/***********************************
* ServiceNet AddressBook Specific *
***********************************/

GNscript.ServiceNetDeleteAddress = function (guid) {
    var command = "!delete|" + guid.toString();
    GNscript.GnaxControls.Run("ServiceNet.AddressBook", command, null);
}

GNscript.ServiceNetUpdateAddress = function (guid, uid) {
    if (GNscript.ServiceNetCheckAddress(uid)) {
        var command = "!update|" + guid.toString() + "|";
        command = command + document.getElementById(uid + "_name").value + "|";
        command = command + document.getElementById(uid + "_name2").value + "|";
        command = command + document.getElementById(uid + "_address").value + "|";
        command = command + document.getElementById(uid + "_address2").value + "|";
        command = command + document.getElementById(uid + "_zip").value + "|";
        command = command + document.getElementById(uid + "_city").value + "|";
        command = command + document.getElementById(uid + "_contactName").value + "|";
        command = command + document.getElementById(uid + "_email").value + "|";
        command = command + document.getElementById(uid + "_phoneNumber").value;
        GNscript.GnaxControls.Run("ServiceNet.AddressBook", encodeURIComponent(command).replace('\'', '%27'), null);
    }
}

GNscript.ServiceNetCheckAddress = function (formid) {
    var identity = formid;
    if (!formid || formid == '') {
        identity = 'def';
    }
    if (FieldValidation[identity] != null) {
        for (var i = 0; i < FieldValidation[identity].length; i++) {
            GNSetWebFormFieldValue(identity, FieldValidation[identity][i].Name, document.getElementById(FieldValidation[identity][i].Name).value);
        }

        if (GNIsValidFormDisplayOption(formid, 'displayblock')) {
            return true;
        }
    }
}

GNscript.ServiceNetOrderAddresses = function (column) {
    command = "!orderby|" + column;
    GNscript.GnaxControls.Run("ServiceNet.AddressBook", command, null);
}

GNscript.ServiceNetSearchAddress = function (search) {
    command = "!search|" + search;
    GNscript.GnaxControls.Run("ServiceNet.AddressBook", command, null);
}

GNscript.ServiceNetSearchClear = function () {
    GNscript.GnaxControls.Run("ServiceNet.AddressBook", "!clearsearch", null);
}

// *************************************************
// * ServiceNet keypress functions
// *************************************************

function GNEnterInvokeOnChange(evnt, element) {
    var charCode;
    if (evnt.which) {
        charCode = evnt.which;
    }
    else {
        charCode = evnt.keyCode;
    }

    if (charCode == 13) {
        if (element.onchange) {
            element.onchange();
        }
        return false;
    }
    return true;
}

GNscript.CmsAdminMossTypeMenu = function (targetid, links) {
    this.targetid = targetid;
    this.links = links;

    this.render = function () {
        var sb = new StringBuffer();
        sb.append("<ul class='mossdropdownmenu'>");
        for (var i = 0; i < this.links.length; i++) {
            sb.append("<li onclick='CMAmenuitemclick(this, \"" + this.links[i].url + "\")' onmouseover='jQuery(this).addClass(\"over\")' onmouseout='jQuery(this).removeClass(\"over\")'>");
            sb.append("<div class='icon'>");
            if (this.links[i].icon && this.links[i].icon != '') {
                sb.append("<img src='" + this.links[i].icon + "' border='0' />");
            } else {
                sb.append("&nbsp;");
            }
            sb.append("</div>");
            sb.append("<div class='text'>");
            sb.append("<span class='title'>" + this.links[i].title + "</span>");
            sb.append("<br />");
            sb.append("<span>" + this.links[i].description + "</span>");
            sb.append("</div>");
            sb.append("</li>");
        }
        sb.append("</ul>");


        jQuery("#" + this.targetid).html(sb.toString());
    };
}

GNscript.renderAdminLinks = function (targetid, links) {
    var alm = new GNscript.CmsAdminMossTypeMenu(targetid, links);
    alm.render();
}



GNscript.togglePopup = function (element) {
    jQuery(element).children(".popup").each(function () {
        if (this.style.display != 'block') {
            jQuery(this).show();
        } else {
            jQuery(this).hide();
        }
    });
}

GNscript.applyBehavior = function () {
    jQuery("ul.mossdropdownmenu").each(function () {
        jQuery(this).children("li").each(function () {
            jQuery(this).mouseover(function () { jQuery(this).addClass("over"); });
            jQuery(this).mouseout(function () { jQuery(this).removeClass("over"); });
        });
    });
}

jQuery(document).ready(function () {
    GNscript.applyBehavior();
});

GNscript.DeleteSmarturl = function (compid, type) {
    if (confirm('this will remove the component from this page, are you sure')) {
        var obj = new Object;
        obj.Callback = function () {
            alert('comp was deleted: ' + compid);
            document.forms[0].submit();
        }
        GNscript.GnaxControls.Run("Administration.DeleteSmarturl", compid + "|" + type, obj);
    }
};

