/** InstantAtlas Server JavaScript Utils v6.4.4196.21430 */

var iasHomePath = '/';
var iasPopLinkExtra = ' (opens in new window)';
﻿var currentPopupDiv = null;
function showPopup(e, divId, xOff, yOff) {
    toggleOrStickPopup(e, divId, xOff, yOff, false, true);
}
function togglePopup(e, divId, xOff, yOff) {
    toggleOrStickPopup(e, divId, xOff, yOff, true, false);
}
function toggleOrStickPopup(e, divId, xOff, yOff, autoClose, forceOpen) {
    window.clearTimeout();
    var x = 0;
    var y = 0;
    // Standard sizes for the offset, but overridable
    var divXOff = (xOff == Number.MAX_VALUE ? xOff : (xOff || 106));
    var divYOff = (yOff == Number.MAX_VALUE ? yOff : (yOff || 136));
    var sp = getScrollXY();
    if (!e) {
        e = window.event;
        x = e.clientX - (divXOff != Number.MAX_VALUE ? divXOff : 0) + sp[0];
        y = e.clientY - (divYOff != Number.MAX_VALUE ? divYOff : 0) + sp[1];
    }
    else {
        x = e.clientX - (divXOff != Number.MAX_VALUE ? divXOff : 0) + sp[0];
        y = e.clientY - (divYOff != Number.MAX_VALUE ? divYOff : 0) + sp[1];
    }
    toggleOrStickPopupAt(x, y, divId, xOff, yOff, autoClose, forceOpen);
}
function showPopupAsChildOf(e, divId, xOff, yOff) {
    var xy = findPos(e); //document.getElementById(parentId));
    toggleOrStickPopupAt(xy[0], xy[1], divId, xOff, yOff, true, false);
}
function toggleOrStickPopupAt(x, y, divId, xOff, yOff, autoClose, forceOpen) {
    // Standard sizes for the offset, but overridable
    var divXOff = (xOff == Number.MAX_VALUE ? xOff : (xOff || 106));
    var divYOff = (yOff == Number.MAX_VALUE ? yOff : (yOff || 136));
    if (currentPopupDiv && (currentPopupDiv.id != divId) && currentPopupDiv.style && (currentPopupDiv.style.display != 'none') && !currentPopupDiv['sticky']) {
        currentPopupDiv.style.display = 'none';
    }
    else if (currentPopupDiv && (currentPopupDiv.id == divId) && !forceOpen && (currentPopupDiv.style.display != 'none')) {
        if (divXOff == Number.MAX_VALUE) {
            x = x - currentPopupDiv.offsetWidth - 2;
        }
        if (divYOff == Number.MAX_VALUE) {
            y = y - currentPopupDiv.offsetHeight - 2;
        }
        currentPopupDiv.style.left = x + 'px';
        currentPopupDiv.style.top = y + 'px';
        return;
    }
    var d = document.getElementById(divId);
    if (d && d.style && (d.style.display == 'none')) {
        d.style.display = 'block';
        if (divXOff == Number.MAX_VALUE) {
            x = x - d.offsetWidth - 2;
        }
        if (divYOff == Number.MAX_VALUE) {
            y = y - d.offsetHeight - 2;
        }
        d.parentNode.removeChild(d);
        document.body.appendChild(d);
        d.style.left = x + 'px';
        d.style.top = y + 'px';
        if (autoClose) {
            d.onmouseout = function() {
                closePopup(divId, false);
            };
            d.onclick = null;
            setTimeout('closePopup(\'' + divId + '\',false)', 4000);
        }
        else {
            d['sticky'] = true;
            d.onmouseout = null;
            d.onclick = function() {
                closePopup(divId, true);
            };
        }
        currentPopupDiv = d;
    }
}
function hidePopup(forceClose) {
    window.clearTimeout();
    if (currentPopupDiv && currentPopupDiv.style && (!currentPopupDiv['sticky'] || forceClose)) {
        currentPopupDiv.style.display = 'none';
        currentPopupDiv['sticky'] = false;
        currentPopupDiv = null;
    }
}
function closePopup(divId, forceClose) {
    window.clearTimeout();
    var d = document.getElementById(divId);
    if (d && d.style && (!d['sticky'] || forceClose)) {
        d['sticky'] = false;
        d.style.display = 'none';
    }
}
function findPos(element) {
  if (element) {
    var parentPos = findPos(element.offsetParent);
    return [
      parentPos[0] + element.offsetLeft,
      parentPos[1] + element.offsetTop
    ];
  } else {
    return [0,0];
  }
}


function showWaitPopup(e, txt) {
    var popupId = 'ias7F7427DB0B4840aeBAFF34A6C052FC11';
    var popup = document.getElementById(popupId);
    var x = 0;
    var y = 0;
    if (!popup) {
        var pd = document.createElement('div');
        pd.setAttribute('id', popupId);
        pd.setAttribute('style', 'position: absolute; z-index: 9999999;');
        pd.setAttribute('class', 'ajaxWaiting');
        pd.appendChild(document.createTextNode(txt));
        document.documentElement.appendChild(pd);
    }
    popup = document.getElementById(popupId);
    if (popup) {
        var sp = getScrollXY();
        if (!e) {
            e = window.event;
            if (!e) {
                return;
            }
            x = e.clientX - sp[0];
            y = e.clientY - sp[1];
        }
        else {
            x = e.clientX - sp[0];
            y = e.clientY - sp[1];
        }
        popup.style.display = 'block';
        popup.style.left = x + 'px';
        popup.style.top = y + 'px';
    }
}

function closeWaitPopup() {
    closePopup('ias7F7427DB0B4840aeBAFF34A6C052FC11');
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof(window.pageYOffset) != 'undefined' ) {
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } 
    else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } 
    else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}

function popLink(url, winName, wopts) {
    if (typeof(url.href) != 'undefined') {
        url = url.href;
    }
    var w = window.open(url, (winName != null ? winName : 'iasPopupWindow'), (wopts != null ? wopts : 'status=1,toolbar=1,location=1,menubar=1,resizable=1,scrollbars=1'), true);
    if (w && (typeof(w.focus) != 'undefined')) {
        w.focus();
    }
    return false;
}

function selectAll(selectObjectName) {
    doSelectUpdate(selectObjectName, true);
}

function selectNone(selectObjectName) {
    doSelectUpdate(selectObjectName, false);
}

function doSelectUpdate(selectObjectName, selStatus) {
    var s = (document.getElementById(selectObjectName) != null ? document.getElementById(selectObjectName) : document.forms[0].elements[selectObjectName]);
    if (s != null) {
        for (var i = 0; i < s.options.length; i++) {
            s.options[i].selected = selStatus;
        }
    }
}

function forceSelectsWide(skipThese) {
    var nodes = document.getElementsByTagName('select');
    for (var i = 0; i < nodes.length; i++) {
        if ((nodes.item(i).size != null) && 
             (parseInt(nodes.item(i).size) > 1) && 
             (nodes.item(i).offsetWidth < nodes.item(i).parentNode.offsetWidth) && 
             ((skipThese == null) || ((',' + skipThese + ',').indexOf(',' + nodes.item(i).attributes['id'] + ',') < 0))) {
            //nodes.item(i).style.width = '100%';
            nodes.item(i).style.width = (nodes.item(i).parentNode.offsetWidth - 19) + 'px';
        }
    }
}

// Uses a non-XHTML compliant property to try and trick the browser (Firefox in particular)
// to not show a scrollbar for select boxes
function forceSelectsNoScroll(skipThese) {
    var nodes = document.getElementsByTagName('select');
    for (var i = 0; i < nodes.length; i++) {
        if ((skipThese == null) || ((',' + skipThese + ',').indexOf(',' + nodes.item(i).attributes['id'] + ',') < 0)) {
            nodes.item(i).scrolling = 'no';
            nodes.item(i).scroll = 'no';
        }
    }
}

/**
    Move an item UP in a select box.
    @param lbId - The ID of the select box.
    @param hfId - The ID of the hidden input where the new order (values only) should be stored.
*/
function moveItemUp(lbId, hfId, delimiter) {
    var lb = document.getElementById(lbId);
    var si = lb.selectedIndex;
    if (si > -1) {
        var sval = lb.options[si].value;
        var stxt = lb.options[si].text;
        if (si > 0) {
            lb.remove(si);
            lb.options.add(new Option(stxt, sval), si - 1);
            lb.selectedIndex = si - 1;
        }
    }
    if ((hfId != null) && (document.getElementById(hfId) != null)) {
        var hf = document.getElementById(hfId);
        serializeOrder(lb, hf, (delimiter != null ? delimiter : '|'));
    }
}
/**
    Move an item DOWN in a select box.
    @param lbId - The ID of the select box.
    @param hfId - The ID of the hidden input where the new order (values only) should be stored.
*/
function moveItemDown(lbId, hfId, delimiter) {
    var lb = document.getElementById(lbId);
    var si = lb.selectedIndex;
    if (si > -1) {
        var sval = lb.options[si].value;
        var stxt = lb.options[si].text;
        if (si < (lb.options.length - 1)) {
            lb.remove(si);
            lb.options.add(new Option(stxt, sval), si + 1);
            lb.selectedIndex = si + 1;
        }
    }
    if ((hfId != null) && (document.getElementById(hfId) != null)) {
        var hf = document.getElementById(hfId);
        serializeOrder(lb, hf, (delimiter != null ? delimiter : '|'));
    }
}
/**
    Serialize the order of items in a select box to a hidden field.
    @param lb - The select box.
    @param hf - The hidden input where the new order (values only) should be stored.
    @param delimiter - Th echaracter to split the values - defaults to |.
*/
function serializeOrder(lb, hf, delimiter) {
    var dl = delimiter || '|';
    var tval = '';
    for (var i = 0; i < lb.options.length; i++) {
        tval += dl + lb.options[i].value;
    }
    hf.value = (tval.length > dl.length ? tval.substring(dl.length) : '');
}
function forceSelectedToTop(s) {
    if ((s != null) && (s.options != null)) {
        for (var i = 0; i < s.options.length; i++) {
            if (s.options[i].selected) {
                s.options[i].scrollIntoView(true);
                break;
            }
        }
    }
}
function copyHrefToClipboard(href, linkTag) {
    var copied = false;
    if ((href || linkTag) && window.clipboardData) {
        if (href) {
            clipboardData.setData('Text', href);
        }
        else {
            var ahref = (linkTag.href ? linkTag.href : linkTag.getAttribute('href'));
            clipboardData.setData('Text', ahref);
        }
    }
    else if ((href || linkTag) && (typeof(Components.classes) != 'undefined')) {
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
        gClipboardHelper.copyString(href); 
    }
}

function forcePopLinks(skipThese) {
    var tags = new Array('a', 'input', 'button');
    for (var i = 0; i < tags.length; i++) {
        doForcePopLinks(skipThese, tags[i]);
    }
}

function doForcePopLinks(skipThese, tagName) {
    var nodes = document.getElementsByTagName(tagName);
    var plx = eval('iasPopLinkExtra');
    doForcePopLinksTimed(nodes, skipThese, 0, plx);
}

function doForcePopLinksTimed(nodes, skipThese, i, plx) {
    try {
        if (i < nodes.length) {
            if ((nodes.item(i).href != null) && 
                 (nodes.item(i).getAttribute('onclick') != null) && 
                 (nodes.item(i).getAttribute('onclick').indexOf('popLink') >= 0) && 
                 ((skipThese == null) || ((',' + skipThese + ',').indexOf(',' + nodes.item(i).attributes['id'] + ',') < 0))) {
                var bt = nodes.item(i).getAttribute('title');
                nodes.item(i).setAttribute('title', (bt != null ? bt : '') + plx);
                window.setTimeout(function() { doForcePopLinksTimed(nodes, skipThese, i + 1, plx); }, 20);
            }
        }
    }
    catch (ex) {
        // Silent - this is a nice-to-have only...
    }
}

function launchPopLinksFix(allowDelay) {
    if (allowDelay && (typeof(window.addEventListener) != 'undefined')) {
        window.addEventListener('load', forcePopLinks, false);
    } 
    else if (allowDelay && (typeof(window.attachEvent) != 'undefined')) {
        window.attachEvent('onload', forcePopLinks);
    } 
    else {
        window.setTimeout(forcePopLinks, 500);
    }
}

function launchAnchorsFix(allowDelay) {
    if (allowDelay && (typeof(window.addEventListener) != 'undefined')) {
        window.addEventListener('load', forceAnchorIds, false);
    } 
    else if (allowDelay && (typeof(window.attachEvent) != 'undefined')) {
        window.attachEvent('onload', forceAnchorIds);
    } 
    else {
        window.setTimeout(forceAnchorIds, 50);
    }
}

function forceAnchorIds() {
    var nodes = document.getElementsByTagName('a');
    doForceAnchorIdsTimed(nodes, 0);
}
    
function doForceAnchorIdsTimed(nodes, i) {
    try {
        if (i < nodes.length) {
            if ((nodes.item(i).id != null) && (nodes.item(i).name == null) && (nodes.item(i).href == null)) {
                var bt = nodes.item(i).getAttribute('id');
                nodes.item(i).setAttribute('name', (bt != null ? bt : ''));
                window.setTimeout(function() { doForceAnchorIdsTimed(nodes, i + 1); }, 20); 
            }
        }
    }
    catch (ex) {
        // Silent - this is a nice-to-have only...
    }
}
