﻿// Shortcuts.
function el(element) {
    return typeof element == "string" ? document.getElementById(element) : element;
}
function tags(name) {
    return document.getElementsByTagName(name);
}
function tag(name,index) {
    return tags(name)[index==null?0:index];
}
// Using this function helps to avoid inspection warnings as well as crunching issues.
function evalGlobal(e) { return eval(e); }

var Debug = {
    enabled:false,
    message:function(text) {
        if(Debug.enabled) {
            var c = window["console"]; // For firebug.
            if( c && c.log != undefined)
                c.log(text);
            else
                alert(text);
        }
    }
};

// Utils
var StringUtil = {
    trim:function(source,pattern) {
        if(source) {
            if(pattern==null) source = source.replace(/^s+|s+$/g,"");
            else {
                var pl = pattern.length;
                while(source.indexOf(pattern)==0) source = source.substring(pl);
                while(source.length!=0 && source.lastIndexOf(pattern)==source.length-pl) source = source.substring(0,source.length-pl);
            }
        }
        return source;
    }
};

var ArrayUtil = {
    indexOf:function(array,item) {
        for(var i=0;i<array.length;++i)
            if(array[i]==item) return i;
        return -1;
    },
    contains:function(array,item) {
        return ArrayUtil.indexOf(array,item)!=-1;
    }
};

var FormUtil = {
    getValue:function(element) {
        element=el(element);
        return element?element.value:null;
    },
    setValue:function(element,value) {
        element=el(element);
        if(element) element.value = value;
    },
    applyDefaultText:function(element,text) {
        element=el(element);
        if(element) {
            var onblur = function(event) { if(element.value=="") { CSS.ClassName.add(element,"Empty");element.value = text; } };
            element.attachEvent("onfocus", function(event) { if(element.value==text) { element.value = ""; CSS.ClassName.remove(element,"Empty"); } } );
            element.attachEvent("onblur", onblur );
            setTimeout(onblur,1);
        }

    },
    applyTextAreaLimit:function(element,max,overflowMessage) {
        element=el(element);
        if(element) {
            var onchange = function(event) {
                var len = element.value.length;
                if(len>max) {
                    element.value = element.value.substring(0,max);
                    if(overflowMessage && len>max+1) alert(overflowMessage);
                }
            };
            var onkeypress = function(event) {
                if(element.value.length>=max && event.keyCode!=8) {
                    element.readOnly = true;
                    setTimeout(function(){element.readOnly = false;},0);
                    return false;
                }
                return true;
            };
            element.attachEvent("onchange", onchange );
            element.attachEvent("onkeyup", onchange );
            element.attachEvent("onkeypress", onkeypress );
        }
    },
    _focusElement:null,
    registerFocus:function(element) {
        element = el(element);
        if(FormUtil._focusElement) window.detachEvent("onload",FormUtil._focusElement.focus);
        FormUtil._focusElement = element;
        if(element) window.attachEvent("onload",element.focus);
    }
};

var CSS = {};
CSS.Display = {
    // If visible is undefined then
    toggle:function(element,visible) {
        element=el(element);
        var hidden = false;
        if (element) {
            var s = element.style, d = s.display;
            hidden = d=="none";
            if(typeof visible=="string") d = visible;
            else {
                if(visible==null) visible = hidden;
                if(!visible)
                    d = "none";
                else switch(element.tagName) {
                    case "DIV":
                        d = "block"; break;
                    case "SPAN":
                        d = "inline"; break;
                    default:
                        d = "";
                }
            }
            if(d!=s.display) s.display = d;
        }
        return hidden; // Returns previous status.  Returning hidden(true) represents: was visible.
    }
};
CSS.ClassName = {
    contains:function(element, className) {
        // Return true if the given element currently has the given class name.
        return element!=null && element.className!=null && ArrayUtil.contains(element.className.split(" "),className);
    },
    add:function(element, className) {
        if (element != null && element.className != null && !this.contains(element, className))
            element.className += ((element.className == null || element.className == "") ? "" : " ") + className;
    },
    remove:function(e, name) {
        if (!this.contains(e, name)) return false;

        // Remove the given class name from the element's className property.
        var newList = new Array(),
            curList = e.className.split(" ");
        for (var i = 0; i < curList.length; ++i) if (curList[i] != name)  newList.push(curList[i]);
        e.className = newList.join(" ");
        return newList.length != curList.length;
    },
    toggle:function(e, name, force) {
        if(force==null) force = !this.contains(e, name);
        if(force) this.add(e,name);
        else this.remove(e,name);
    }
};


var AJAX = {
    _newXMLHttpRequest:function() {
        return typeof window.ActiveXObject != 'undefined' ?
           (new ActiveXObject("Microsoft.XMLHTTP")) :
           (new XMLHttpRequest());
    },
    _requests:new Array(),
    registerRequest:function(request) {
        if(!ArrayUtil.contains(AJAX._requests,request))
            AJAX._requests.push(request);
        setTimeout(AJAX.updateLoading,1000);
    },
    unregisterRequest:function(request) {
        var i = ArrayUtil.indexOf(AJAX._requests,request);
        if(i!=-1)
            AJAX._requests.splice(i,1);
        AJAX.updateLoading();

    },
    updateLoading:function() {
        CSS.ClassName.toggle(tag("body"),"Updating", AJAX._requests.length!=0);
    },
    XMLHttpRequest:function(href,completeCB,errorCB) {
        var me = this;
        me.href = href;
        me.oncomplete = completeCB;
        me.onerror = errorCB;

        me.call = function(method) {
            if(method==null) method = "GET";
            var client = AJAX._newXMLHttpRequest();
            client.onreadystatechange = function() {
                if(client.readyState==4) {
                    if(client.status==200 && client.responseXML)
                    {
                        if(me.oncomplete) me.oncomplete(client.responseXML.documentElement);
                    } else {
                        if(me.onerror) {
                            Debug.message(client.responseText);
                            me.onerror(client.responseText);
                        }
                    }
                    AJAX.unregisterRequest(me);
                }
            };
            client.open(method, me.href);
            client.send(null);
            AJAX.registerRequest(me);
            return client;
        };
    },
    // Shortcut.
    getXML:function(href,completeCB,errorCB) {
        var client = new AJAX.XMLHttpRequest(href,completeCB,errorCB);
        client.call("GET");
        return client;
    },
    postXML:function(href,completeCB,errorCB) {
        var client = new AJAX.XMLHttpRequest(href,completeCB,errorCB);
        client.call("POST");
        return client;
    },
    getValueByNodeName:function(xml,nodeName,defaultValue) {
        var n = xml.getElementsByTagName(nodeName);
        if (n) {
            var i = n.item(0);
            if(i && i.firstChild)
                return (i.textContent) ? i.textContent : i.firstChild.data;
        }
        return defaultValue;
    }
};


// Browser compatibility...
var BrowserInfo = function() {
    var me = this;
    me.Name = null;
    me.Version = null;

    function checkBrowser(name) {
        var ua=navigator.userAgent,i = ua.indexOf("Version");
        if(i==-1) i = ua.indexOf(name);
        var version = i!=-1?parseFloat(ua.substr(i + name.length).replace(/^[^0-9.]+/,"")):null;
        name = name.replace(/[^a-z0-9]/gi,""); //Normalize name.
        // When called in order, the first browser detected is the current one.
        if(me.Name==null && version!=null) {
            me.Name = name;
            me.Version = version;
        }
        return version!=null;
    }

    me.isOpera        = checkBrowser("Opera") || window["opera"]; // Opera goes first because it likes to spoof IE.
    me.isFirefox      = checkBrowser("Firefox");
    me.isSafari       = checkBrowser("Safari");
    me.isNetscape6    = checkBrowser("Netscape6/");
    me.isNetscape     = checkBrowser("Netscape");
    me.isMSIE         = checkBrowser("MSIE");

    me.isWindows      = navigator.platform.indexOf("Win")==0;
    me.isMac          = navigator.platform.indexOf("Mac")==0;
    me.isTrueIE       = me.Name=="MSIE" && !(!document.all); // document.all negates spoofing.
    me.isTrueWinIE    = me.isWindows && me.isTrueIE;
    me.isMozilla      = checkBrowser("Mozilla") && !me.isTrueIE && !me.isOpera && !me.isSafari;
    me.isIE           = function(version) { return me.isTrueIE && me.Version >= version; };
    me.isWinIE        = function(version) { return me.isTrueWinIE && me.Version >= version; };
};

var Browser = new BrowserInfo();

// Path discovering and importing scripts.
Browser.getScriptPath = function(path,refjsname){
    if(refjsname==null) refjsname = "";
    var base, src = new RegExp("[^\\/]+"+refjsname+"\\.js.*"), scripts = document.getElementsByTagName("script");
    for (var i=0; i<scripts.length; ++i) {
        var s = scripts[i].src;
        if (s.match(src)) { base = s.replace(src, ""); break; }
    }
    return base + path;
};
//Browser.importScript = function(path,refjs){ document.write('<' + 'script type="text/javascript" src="' + Browser.getScriptPath(path,refjs) + '"><'+'/script>'); };

// Suppliment compatibility.
Browser.compatibility = function() {

    // Add document.getElementById if needed (mobile IE < 5)
    if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; };}

    for(var b in Browser) if(b.indexOf("is")==0 && Browser[b] && typeof Browser[b] != "function") CSS.ClassName.add(tag("body"), b);

    // Unsupported specific css styles.
    document.write('<style type="text/css">\n');
    document.write("a.Button,a.ButtonSecondary,.InlineBlock{display:"+((Browser.isMozilla && (!Browser.isFirefox || Browser.Version<3))?"-moz-":"")+"inline-block}\n");

    if (Browser.isTrueWinIE) {
      if(window["serverDomain"] && location.href.indexOf("http://localhost")!=0) {
        document.domain = window["serverDomain"];
        if(Browser.Version>=5.5 && Browser.Version<7)
            document.write("img{behavior:url("+Browser.getScriptPath("png.htc?version=2")+")}\n");
      }
      // Add word-wrap class through script to avoid Firefox warning.
      document.write(".WordWrap{word-wrap:break-word}\n");
      // Add PNG behavior.
    }
    document.write('<'+'/style>\n');

    // Cross Browser Emulation

    // Safari HTML Prototyping.
    if (Browser.isSafari && Browser.Version<3) { // WebCore/KHTML
        (function(c) {
            for (var i in c)
                window["HTML" + i + "Element"] = document.createElement(c[ i ]).constructor;
        })({
            Html: "html", Head: "head", Link: "link", Title: "title", Meta: "meta",
            Base: "base", IsIndex: "isindex", Style: "style", Body: "body", Form: "form",
            Select: "select", OptGroup: "optgroup", Option: "option", Input: "input",
            TextArea: "textarea", Button: "button", Label: "label", FieldSet: "fieldset",
            Legend: "legend", UList: "ul", OList: "ol", DList: "dl", Directory: "dir",
            Menu: "menu", LI: "li", Div: "div", Paragraph: "p", Heading: "h1", Quote: "q",
            Pre: "pre", BR: "br", BaseFont: "basefont", Font: "font", HR: "hr", Mod: "ins",
            Anchor: "a", Image: "img", Object: "object", Param: "param", Applet: "applet",
            Map: "map", Area: "area", Script: "script", Table: "table", TableCaption: "caption",
            TableCol: "col", TableSection: "tbody", TableRow: "tr", TableCell: "td",
            FrameSet: "frameset", Frame: "frame", IFrame: "iframe"
        });

        evalGlobal("function HTMLElement() {}");
        HTMLElement.prototype     = evalGlobal("HTMLHtmlElement.__proto__.__proto__");
    }

    function isFunction(obj) { return typeof obj == "function"; }

    if (window.addEventListener) window.attachEvent = function(eventname, handler){
        if(!isFunction(handler._ieEmuEventHandler)) {
            handler._ieEmuEventHandler = function (e) {
                window.event = e;
                return handler(e);
            };
        }
        this.addEventListener(eventname.toLowerCase().replace(/^on/, ""), handler._ieEmuEventHandler, false);
    };

    if (window.removeEventListener) window.detachEvent = function(eventname, handler){
        var f = !isFunction(handler._ieEmuEventHandler);
        this.removeEventListener(eventname.toLowerCase().replace(/^on/, ""), f?handler:handler._ieEmuEventHandler, f);
    };

    if (typeof HTMLElement != "undefined") {
        if (HTMLElement.prototype.attachEvent==undefined) HTMLElement.prototype.attachEvent = window.attachEvent;
        if (HTMLElement.prototype.detachEvent==undefined) HTMLElement.prototype.detachEvent = window.detachEvent;
    }


    window.popup = function(url, name, params)
    {
        try {
            var win = window.open(url, name, params);
            win.focus();
            return true; // True if successful
        }
        // False if fails.
        catch (ex) { return false; }
    };

};

Browser.compatibility();

Browser.Event = {
    getSourceElement:function(event){
        if (event == null) event = window.event;
        if (event == null) return null;
        if (event.srcElement) return event.srcElement;

        var node = event.target;
        while (node.nodeType != 1) node = node.parentNode;
    return node;
    },
    isMouseLeaveOrEnter:function(event, element) {
        if (event.type != 'mouseout' && event.type != 'mouseover') return false;
        var reltg = event.relatedTarget ? event.relatedTarget : event.type == 'mouseout' ? event.toElement : event.fromElement;
        while (reltg && reltg != element) reltg = reltg.parentNode;
        return (reltg != element); // && typeof reltg != 'undefined'
    }
};

// Suppliment copy paste handling.
Browser.onCopy = function(event) {
  var data = window["clipboardData"];
  if(data) setTimeout(function(){
      try{
          var result = data["getData"]("Text");
          result = result.replace(/\xAD/g,""); // Strip shy hyphens.
          data["setData"]("Text",result);
      } catch(ex){} // Just in case of a security exception.
  },0);
};
Browser.onDocumentChanged = function() {
    if(Browser.isTrueWinIE) {
        setTimeout(function(){
            // Override oncopy to allow for stripping shy hyphens.
            var elements = tags("*");
            for(var i=0;i<elements.length;++i) {
                var e=elements[i];
                e.detachEvent("oncopy",Browser.onCopy);
                e.attachEvent("oncopy",Browser.onCopy);
                e.detachEvent("oncut",Browser.onCopy);
                e.attachEvent("oncut",Browser.onCopy);
            }
        },1);
    }
    else if(Browser.isFirefox) {
        var spans = tags("span");
        for(var i=0;i<spans.length;++i) {
            var e=spans[i];
            if(CSS.ClassName.contains(e,"WordBreak"))
                e.innerHTML = e.innerHTML.replace(/\xAD/g,"");
        }
    }
};

// Find player by scrolling up the page TODO: ~~~ add smooth-scrolling
Browser.scrollToPlayer = function() {
  window.scrollTo(0, 0); 
};

var ImageObject = {
    loadImage:function(path,onload) {
        var img = evalGlobal("new Image()");
        img.onload = onload?onload:(function(element){});
        // use this to ensure image loads...
        img.src = path;
        return img;
    }
};

ImageObject.HoverSwap = {
    onMouseOver:function(event){
        var e = Browser.Event.getSourceElement(event);
        e.src = e.getAttribute("mouseoversrc");
    },
    onMouseOut:function(event){
        var e = Browser.Event.getSourceElement(event);
        e.src = e.getAttribute("originalsrc");
    },
    apply:function(img) {
        var mosrc = img.getAttribute("mouseoversrc");
        if (mosrc != null)
        {
            ImageObject.loadImage(mosrc, function(event){ //Only adds behavior on successful preload of mouseover image.
                if(img.getAttribute("originalsrc")==null) img.setAttribute("originalsrc", img.src);
                img.attachEvent("onmouseover", ImageObject.HoverSwap.onMouseOver);
                img.attachEvent("onmouseout", ImageObject.HoverSwap.onMouseOut);
            });
        }
    }
};

var RollOver = {
    over:function(e,inOut)
    {
        if(inOut==null) inOut = true;
        while (e != null && !CSS.ClassName.contains(e,"HoverTarget")) e = e.parentNode;
        CSS.ClassName.toggle(e,"Hover",inOut);
    },
    out:function(e) {
        RollOver.over(e,false);
    },

    onOver:function(event) { RollOver.over(Browser.Event.getSourceElement(event)); },
    onOut:function(event) { RollOver.out(Browser.Event.getSourceElement(event)); },

    apply:function(element) {
        element = el(element);
        if(element) { // this represents the target element.
            element.detachEvent("onmouseover",RollOver.onOver);
            element.attachEvent("onmouseover",RollOver.onOver);
            element.detachEvent("onmouseout",RollOver.onOut);
            element.attachEvent("onmouseout",RollOver.onOut);
        }
    }
};

var HTMLUtil = {
    setInnerHTML:function(elment,value,delay) {
        if(delay)
            setTimeout( function() { setInnerHTML(elment,value); }  , delay);
        else {
            if(typeof elment == "string") elment = el(elment);
            elment.innerHTML = value;
            if(Browser.isSafari)
                elment.innerHTML += "";
            Browser.onDocumentChanged();
        }
    }
};
HTMLUtil.CheckBox = {
    check:function(within,value) {
        var element = el(within);
        var c = element.getElementsByTagName("input");
        for(var i=0;i<c.length;++i) {
            var cb = c[i];
            if(cb.getAttribute("type")=="checkbox")
                cb.checked = value;

        }
    },
    count:function(form,checked) {
        var n = 0, fe = form.elements;
        for(var i=0;i<fe.length;++i) if(checked==null || fe[i].checked==checked) n++;
        return n;
    },
    toggleContained:function(event,element) {
        var target = Browser.Event.getSourceElement(event), cb, clickedOnCB = false;
        if(target.tagName=="INPUT") {
            if(target.type=="checkbox") {
                cb = target;
                clickedOnCB = true;
            }
        }
        else
            cb = element.getElementsByTagName('INPUT')[0];

        if(cb) {
            var cbl = window["checkBoxLimit"];
            if(cb.checked==clickedOnCB && typeof cbl == "number" && HTMLUtil.CheckBox.count(cb.form,true)>=cbl) {
                cb.checked = false;
                alert("Please select no more than "+cbl+".");
                return;
            }

            if(!clickedOnCB)
              cb.checked = !cb.checked;
        }

    }

};
HTMLUtil.Copy = {
    from:function(inElement) {
        inElement.select();
        var v = inElement.value?inElement.value:inElement.innerHTML,
        data = window["clipboardData"];

        if (data) data["setData"]("Text",v);
        else {
            var flashcopier = 'flashcopier', fc = document.getElementById(flashcopier);;
            if(!fc) {
              fc = document.createElement('div');
              fc.id = flashcopier;
              tag("body").appendChild(fc);
            }
        fc.innerHTML = ''; // Clear the contents first.
        HTMLUtil.setInnerHTML(fc,'<embed src="/images/flash/util/_clipboard.swf" FlashVars="clipboard='+escape(v)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>');
        }
        setTimeout(function(){inElement.focus();},0);
    },
    renderButton:function(id,text) {
        if(text==null) text = "Copy";
        document.write('<input style="width:auto;" type="button" value="'+text+'" class="Button" onclick="HTMLUtil.Copy.from(el(\''+id+'\'));"/>');
    }

};


// QueryString parsing.

function QueryStringParser(href) {
    if(href==undefined) href = location.href;
    if(href==null) href = "";
    this.href = href; // So that the original value is accessible.

    var hi = href.indexOf("#"); // Trim off the hash first.
    if(hi!=-1) href = href.substring(0,hi);

    var a = new Array(), qs, qmi = href.indexOf("?");
    if(qmi!=-1) qs = href.substring(qmi+1);
    if(qs!=null) {
        this.value = qs;
        var q = qs.split("&");
        for(var i=0;i<q.length;++i) {
            var d = q[i].split("=");
            d.key = d[0];
            d.value = unescape(d[1]);
            a[i] = d;
            a[d.key] = d.value;
        }
    }
    this.items = a;
};
var QueryString = new QueryStringParser();


var HashUtil = {
    ENTRY_SEPARATOR:",",
    KEYVALUE_SEPARATOR:"=",
    TRACKING_INTERVAL:1000,
    LastTitle:document.title,
    LatestHash:"",
    createHashColleciton:function(hash) { // Hash can be a Uri with hash.
        if(hash==null) hash = this.LatestHash; // Get from LatestHash so to be sure it's the most up to date.
        hash = hash.substring(hash.indexOf("#")+1);
		var entries = hash.split(this.ENTRY_SEPARATOR);
        var hc = new Object();
		if(Browser.isSafari) {
			var removeProps = ["attachEvent","detachEvent"];
			for(var i=0;i<removeProps.length;++i) hc[removeProps[i]] = undefined;
		}
        for(var i=0;i<entries.length;++i) {
            var entry = entries[i], sIndex = entry.indexOf(this.KEYVALUE_SEPARATOR);
            if(sIndex==-1) hc[entry] = null;
            else hc[entry.substring(0,sIndex)] = entry.substring(sIndex+1);
        }
        return hc;
    },

    hashFromCollection:function(collection) {
        var result = new Array();
        for(var k in collection) {
            var v = collection[k];
            if(v) result.push(k + this.KEYVALUE_SEPARATOR + v);
        }
        result.sort(); // Sort to maintain the order of values in the URL.
        return result.join(this.ENTRY_SEPARATOR);
    },

    getValue:function(key, hash) {
        var hc = this.createHashColleciton(hash);
        return hc[key];
    },

    setValue:function(key, value, hash) {
        var hc = this.createHashColleciton(hash);
        if(hc[key]==value) return null; // Null means no change.
        hc[key] = value;
        var result = this.hashFromCollection(hc);
        if(hash==null) this.updateCurrent(result);
        return result;
    },

    // Tracking Hash Changes
    _pollingID:0,
    _updateThreadId:0,
    onHashChanged:function() {},
    stopTrackingChanges:function() {
        if(this._pollingID!=0) clearInterval(this._pollingID);
    },
    startTrackingChanges:function(hashChangedCallback) {
        if(hashChangedCallback) this.onHashChanged = hashChangedCallback;
        this.stopTrackingChanges();
        this._pollingID = setInterval(this.queryChanges,this.TRACKING_INTERVAL);
    },
    updateLatest:function() { // Thread Safe
        try {
            HashUtil.LatestHash = window.location.hash; // Update to actual value.
            HashUtil._updateThreadId = 0;
            HashUtil.startTrackingChanges();
        } catch(ex) {}
    },
    updateCurrent:function(hash) {
        this.stopTrackingChanges();
        HashUtil.updateTitle(); // Cache title, since in some cases the title changes when setting the hash value.
        if(hash=="" && Browser.isFirefox) hash = "#"; // Bug in Firefox will refresh the page and misreport the URL.
        window.location.hash = this.LatestHash = hash; // This insures that correct values are retrieved from here on.
        HashUtil.updateTitle();
        // Using a timeout allows for indiscriminate setting of values without doubling the update.
        if(this._updateThreadId!=0) clearTimeout(this._updateThreadId);
        this._updateThreadId = setTimeout(this.updateLatest,1);
    },
    queryChanges:function() { // Thread Safe
        if (window.location.hash != HashUtil.LatestHash)
        {
            HashUtil.LatestHash = window.location.hash;
            HashUtil.onHashChanged();
        }
        HashUtil.updateTitle();
    },
    updateTitle:function(value) {
        if(value!=document.title) {
            if (value==null) {
                if (document.title != HashUtil.LastTitle)
                    document.title = HashUtil.LastTitle;
            }
            else document.title = HashUtil.LastTitle = value;
        }
        else HashUtil.LastTitle = value;

        return HashUtil.LastTitle;
    },
    updateLink:function(a) {
        var ref = a.href.split("#"), h = StringUtil.trim(this.LatestHash,"#");
        if(h=="") ref.length = 1;
        else ref[1] = h;
        a.href = ref.join("#");
    }
};
HashUtil.updateLatest();

/* SIGN IN
---------------------------------------------------------------- */

var SignIn = {};
SignIn.Form = {
    show:function() {
        var t = CSS.Display.toggle;
        t("SignIn_Links",false);
        t("SignIn_Form",true);
        t("Cobrand",false);
        setTimeout(SignIn.Form.focus, 200);
    },
    focus:function() {
        var lfe = el("loginForm").elements;
        if(!lfe) return;
        var un = lfe["username"], pw = lfe["password"];
        var e = (un && un.value.length == 0) ? un : pw;
        if(e) e.focus();
    }
};

window.attachEvent("onload", function(event) {
    if(window.onpreload) window.onpreload();

    // Setup mouse-overs.
    var images = tags("img");
    for (var i = 0; i < images.length; ++i) {
        var x = images[i], osrc = x.getAttribute("originalsrc"), src = osrc?osrc:x.src;

        if (src.indexOf("_off.gif") != -1) {
            x.setAttribute("mouseoversrc", src.replace(/_off\.gif/i, "_hover.gif"));
            ImageObject.HoverSwap.apply(x);
        }
    }

    var LanguageSelector = el("LanguageSelector");
    window.LanguageSelectorTimeout = 0;
    if(LanguageSelector) {
        function resetTimeout() {
            if(window.LanguageSelectorTimeout!=0) {
                clearTimeout(window.LanguageSelectorTimeout);
                window.LanguageSelectorTimeout = 0;
            }
        }
        with(el("LanguageSelectorTarget")) {
            attachEvent("onmouseout",resetTimeout);
            attachEvent("onmouseover",function(event){
                resetTimeout();
                window.LanguageSelectorTimeout = setTimeout( function(){ window.LanguageSelectorTimeout = 0; LanguageSelector.style.display='block'; }, 300 );
            });
        }
        LanguageSelector.attachEvent("onmouseover",resetTimeout);
        LanguageSelector.attachEvent("onmouseout",function(event){
            resetTimeout();
            if(Browser.Event.isMouseLeaveOrEnter(event,LanguageSelector))
                window.LanguageSelectorTimeout = setTimeout( function(){ window.LanguageSelectorTimeout = 0; LanguageSelector.style.display='none'; }, 300 );
        });
    }

    // Autoselect read-only text fields.
    function AutoSelect() { this.select(); };
    var fields = document.getElementsByTagName("input");
    for(var i=0;i<fields.length;++i) {
      var f = fields[i];
      if(f.type=="text" && f.readOnly)
        f.oncontextmenu = f.onclick = AutoSelect;
    }

    Browser.onDocumentChanged();

});