var _loadfn;
var dd_active = "";
var dd_hasFocus = "";
function dd_over(dd_name)
{
    var dd = document.getElementById(dd_name);
    if (dd.to_close) {
        window.clearTimeout(dd.to_close);
        dd.to_close = 0
    }
    if (dd.to_open)
        return;
    var timer = 500;
    if (dd_active != "")
        timer = 100;
    dd.to_open = window.setTimeout("dd_open('"+dd_name+"')",timer);
}
function dd_open(dd_name)
{
    var dd = document.getElementById(dd_name);
    dd.style.display = "block";
    window.clearTimeout(dd.to_open);
    dd.to_open = 0;
    if (dd_active != "" && dd_active != dd_name)
        dd_close(dd_active);
    dd_active = dd_name;
    var a = document.getElementById("anc_" + dd_name);
    if (a)
    {
       a.onclick = null;
    }
}
function dd_out(dd_name)
{
    if (dd_hasFocus == dd_name)
        return;
    var dd = document.getElementById(dd_name);
    if (dd.to_open) {
        window.clearTimeout(dd.to_open);
        dd.to_open = 0;
    }
    if (dd.to_close)
        return;
    dd.to_close = window.setTimeout("dd_close('"+dd_name+"')",500);
}
function dd_close(dd_name)
{
    var dd = document.getElementById(dd_name);
    dd.style.display = "none";
    window.clearTimeout(dd.to_close);
    dd.to_close = 0;
    if (dd_active == dd_name)
        dd_active = "";
    var a = document.getElementById("anc_" + dd_name);
    if (a)
    {
        a.onclick = clickDisabled;
    }
}
function dd_toggle(dd_name)
{
    var dd = document.getElementById(dd_name);
    if (dd.style.display != "block")
    {
        dd_open(dd_name);
    }
    else
    {
        dd_close(dd_name);
    }
}
function dd_focus(evt)
{
   evt.target.focus();
   dd_over(evt.currentTarget.getElementsByTagName("div")[0].id);
   evt.stopPropagation();
}
function dd_blur(evt)
{
   evt.target.blur();
   dd_out(evt.currentTarget.getElementsByTagName("div")[0].id);
   evt.stopPropagation();
}
function clickDisabled()
{
    return false;
}
function addDDEvents(dd_name, dd_link)
{
    var dd = document.getElementById(dd_name);
    if (dd && dd.parentNode)
    {
        dd.parentNode.onmouseover = new Function("dd_over('" + dd_name + "')");
        dd.parentNode.onmouseout = new Function("dd_out('" + dd_name + "')");
        dd.parentNode.onfocusin = new Function("dd_over('" + dd_name + "');dd_hasFocus='" + dd_name + "';");
        dd.parentNode.onfocusout = new Function("if(dd_hasFocus=='" + dd_name + "')dd_hasFocus='';dd_out('" + dd_name + "')");
        if (dd.parentNode.addEventListener)
        {
            dd.parentNode.addEventListener("focus", new Function("dd_over('" + dd_name + "');dd_hasFocus='" + dd_name + "';"), true);
            dd.parentNode.addEventListener("blur", new Function("if(dd_hasFocus=='" + dd_name + "')dd_hasFocus='';dd_out('" + dd_name + "');"), true);
        } 
    }
    var a = document.getElementById("anc_"+dd_name);
    if (a)
    {
        a.onclick = clickDisabled;
        if (dd_link)
            a.href = dd_link;
        else
            a.href = "javascript://";
    }
}
function cc_click(obj)
{
    if (obj.parentNode.className == "plus")
    {
        obj.parentNode.className = "minus";
    }
    else
    {
        obj.parentNode.className = "plus";
    }
}
function open_events_block(blockId, moreId)
{
    var b = document.getElementById(blockId);
    var m = document.getElementById(moreId);
    
    if (b && m)
    {
        b.style.display = "block";
        b.parentNode.style.backgroundColor = "#F2F9FF";
        m.style.display = "none";
    }
}
function close_events_block(blockId, moreId)
{
    var b = document.getElementById(blockId);
    var m = document.getElementById(moreId);
    
    if (b && m)
    {
        b.style.display = "none";
        b.parentNode.style.backgroundColor = "";
        m.style.display = "block";
    }
}
function QuickLinksOver(evnt)
{
	var src = document.getElementById("quicklinks");
	src.className = "hover";
}

function QuickLinksOut(evnt)
{
	var src = document.getElementById("quicklinks");
	src.className = "";
}
function setSearchOption(obj)
{
    var r = obj.getElementsByTagName("input");
    r[0].click();
    document.getElementById("q").focus();
}

function detectTabRadius()
{
    if (document.body.style.borderTopLeftRadius == undefined)
    {
        var Tabs = new Array( 
            "sitetab", 
            "psutab", 
            "ldaptab", 
            "depttab" 
            );
        for (var t in Tabs)
        {
            document.getElementById(Tabs[t]).className += " rounded";
        }
    }
}


function body_load()
{
    var __accs = document.getElementById("accs");
    if (__accs)
    {
        __accs.style.zIndex = "-1";
        __accs.style.visibility = "hidden";
        __accs.style.position = "absolute";
        __accs.innerHTML += "<a href=\"\" title=\"Hide this statement\" onclick=\"hide_accs();return false;\" class=\"accsClose\">close<\/a>";
    }
    var q = document.getElementById("q");
    qBlur(q);
    document.body.focus();
	if (_loadfn != undefined) _loadfn();
    show_next_alert();
}
function body_unload()
{
    var q = document.getElementById("q");
    qBlur(q);
}
function show_accs()
{
    var __accs = document.getElementById("accs");
    if (__accs)
    {
        __accs.style.zIndex = "100";
        __accs.style.visibility = "visible";
    }
}
function hide_accs()
{
    var __accs = document.getElementById("accs");
    if (__accs)
    {
        __accs.style.zIndex = "-1";
        __accs.style.visibility = "hidden";
    }
}
function qFocus(q)
{
    q.className = "";
}
function qBlur(q)
{
    if (q.value == "")
    {
        q.className = "qb";
    }
}
function AJAX_DOMGetFile(fileURI, htmlNodeId, fClean, fCache)
{
    this.request = null;
    this.requestURI = fileURI;
    this.displayNode = document.getElementById(htmlNodeId);
    this.doclean = fClean;
    this.docache = fCache;
    this.display = function (text)
    {
        if (this.displayNode)
        {
            this.displayNode.innerHTML = text;
            this.displayNode.style.visibility = "visible";
        }
    }
    this.readyhandler = function () 
    {
        if (this.request.readyState == 4)
        {
            if (this.request.status == 200)
            {
                if (this.request.responseText != null)
                {
                    if (this.doclean == true)
                    {
                        this.display(clean(this.request.responseText));
                    }
                    else
                    {
                        this.display(this.request.responseText);
                    }
                }
                else
                {
                    this.display("No data.");
                }
            }
            else
            {
                this.display("Error " + this.request.status + ": " + this.request.statusText);
            }
        }
    }
    this.getFile = function ()
    {
        if (this.request == null)
        {
            this.display("AJAX Request unsupported.");
        } 
        else 
        {
            try {
                var thisFile = this;
                this.request.open("GET", this.requestURI, true);
                if (this.docache == false)
                {
                    this.request.setRequestHeader("Cache-Control", "no-cache");
                    this.request.setRequestHeader("Pragma", "no-cache");
                }
                this.request.onreadystatechange = function() { thisFile.readyhandler(); };
                this.request.send(null);
            }
            catch (e) {
                this.display("AJAX Request error.");
            }
        }
    }
    this.refresh = function ()
    {
        this.getFile();
    }
    if (window.XMLHttpRequest)
    {
        this.request = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        try {
            this.request = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (e) {}
    }
    this.getFile();
}
function setStyle(elem, attr, value)
{
    var x = document.getElementById("center");
    var p = x.getElementsByTagName("p");
    var h1 = document.getElementsByTagName("h1");
    var h2 = document.getElementsByTagName("h2");
    var h3 = document.getElementsByTagName("h3");
    
    if (elem == "" || elem == "p") {
        for (var n = 0; n < p.length; n++) {
            eval("p[" + n + "].style." + attr + " = '" + value + "';");
        }
    } else if (elem == "h1") {
        for (var n = 0; n < h1.length; n++) {
            eval("h1[" + n + "].style." + attr + " = '" + value + "';");
        }
    } else if (elem == "h2") {
        for (var n = 0; n < h2.length; n++) {
            eval("h2[" + n + "].style." + attr + " = '" + value + "';");
        }
    } else if (elem == "h3") {
        for (var n = 0; n < h3.length; n++) {
            eval("h3[" + n + "].style." + attr + " = '" + value + "';");
        }
    } 
}
function swapFont()
{
    var x = document.getElementById("thefont");
    if (x.value == "Switch to Arial")
    {
        document.body.style.fontFamily = "Arial";
        x.value = "Switch to Gill Sans MT";
    }
    else
    {
        document.body.style.fontFamily = "Gill Sans MT";
        x.value = "Switch to Arial";
    }
    return false;
}

function RD_form_submit(anc, query)
{
	var f = document.getElementById("myForm1");
	if (f) {
		var pairs = query.split("&");
		for ( var i=0; i < pairs.length; i++ ) {
			var keyval = pairs[i].split("=");
			if (keyval.length == 2) {
				var elm = document.createElement("INPUT");
				if (elm) {
					elm.type = "hidden";
					elm.name = keyval[0];
					elm.value = keyval[1];
					f.appendChild(elm);
				}
			}
		}
		f.action = anc.href;
		f.submit();
	}
	return false;
}

function addChannelStyles(styles)
{
    var ss = document.createElement("STYLE");
    document.getElementsByTagName("HEAD")[0].appendChild(ss);
    if (ss.styleSheet == null) {
        ss.innerHTML = styles;
    } else {
        ss.styleSheet.cssText = styles;
    }
}

function clean(str)
{
    var re1 = /(?:<[^>]*?)?<(script|object|iframe|embed|link|form|input|xml|applet|bgsound|button|textarea|select|frameset|frame|base|body|head|html)[^>]*?>(?:[\s\S]*?<\/\1[^>]*?>)?/ig;
    var re2 = /(<[^>]*?\s)(?:on[^=>\s]*?=[^>]*?)+>/ig;
    var re3 = /(<[^>]*?\s)(?:(?:href|src)=["']?javascript:[^>]*?)+>/ig;
    str = str.replace(re1, "");
    str = str.replace(re2, "$1>");
    str = str.replace(re3, "$1>");
    return str;
}


function encodeHTML(s)
{
    var requot = new RegExp("\"","g");
    s = s.replace(requot,"&quot;");
    s = s.replace(/</g,"&lt;");
    s = s.replace(/>/g,"&gt;");
    s = s.replace(/&/g,"&amp;");
    return s;
}

function decodeHTML(s)
{
    s = s.replace(/&quot;/g,"\"");
    s = s.replace(/&lt;/g,"<");
    s = s.replace(/&gt;/g,">");
    s = s.replace(/&amp;/g,"&");
    return s;
}
function mailStory(subject, teaser, link)
{
    var url = "mailto:";
    url += "?subject=" + escape(decodeHTML(subject));
    url += "&body=" + escape(decodeHTML(teaser) + "\n\n" + location.protocol + "//" + location.host + link);
    location.href = url;
}
function submitStory(href, title, link)
{
    href = href.replace(/\{title\}/, encodeURIComponent(decodeHTML(title)));
    if (link.match(/^https?:\/{2}/) == null)
    {
        link = location.protocol + "//" + location.host + link;
    }
    href = href.replace(/\{link\}/, encodeURIComponent(decodeHTML(link)));
    
    window.open(href);
}

function flashPutHref(href) { location.href = href; }

var alert_queue = new Array();

function deactivate_alert(alertId)
{
    if (!alertId) return;
    var alertObj = document.getElementById(alertId);
    if (alertObj)
    {
        alertObj.className = "alert-viewed";
        var date = new Date();
        date.setDate(date.getDate() + 1);
        document.cookie = alertObj.id + "=y; expires=" + date.toGMTString();
    }
    show_next_alert();
}

function activate_alert(alertId)
{
    if (!alertId) return;
    var alertObj = document.getElementById(alertId);
    if (alertObj)
    {
        alertObj.className = "alert";
    }
}

function queue_alert(Id)
{
    var cookie = GetCookie(Id);
    if (!cookie)
    {
        alert_queue.push(Id);
    }
}

function show_next_alert()
{
    if (alert_queue.length > 0)
    {
        activate_alert(alert_queue.shift());
    }
}

function GetCookie(sName)
{
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }
  return null;
}



