﻿///
/// This function requests a navigation level from our JSON service.
/// Once the JSON object is received it builds an unordered list and
///     injects the styled list into the navigation list container.
///
function PopulateTree(parentID, cceid, toc, callback) {
    // Clear any current treeviews.
    $("#treecontainer").html('');
    // Readd the neeeded list container.
    //  This fixes a bug where not all new lists after the first
    //      would expand branches.
    var newTreeList = "<ul id=\"navigation\"></ul>";
    $("#treecontainer").html(newTreeList);    
    
    // Create treeview
    $("#navigation").treeview({
        url: "TreeParser.ashx",
        collapsed: true,
        animate: "slow",
        rootID: parentID,
        CCEID: cceid,
        lang: strCulturalCode,
        toc: toc
    },
        callback
    );
};

///
/// This function requests a list of the Types of Cancer that a public user can access.
///  Once the JSON object is received, we generate a selector based on the contents of
///     the JSON object.
///
function PopulateToCSelector(elID, attachEvent, includeBlank, callBack) {
    var options = [];
    if (includeBlank) {
        options.push('<option value="-1"></option>');
    }
    else {
        options.push('<option value="-1">' + strToCDefaultText + '</option>');
    }

    var url = GetToCServiceUrl();
    $.ajaxSetup({ cache: false });
    $.getJSON(url, {},
            function(result) {
                for (var i = 0; i < result.length; i++) {
                    options.push('<option value="',
                            result[i].ID, '">',
                            result[i].Description, '</option>');
                }
                $("#" + elID).html(options.join(''));
                if (undefined != callBack && null != callBack && typeof callBack == 'function') {
                    setTimeout(callBack, 500);
                }

                if (elID == "ToCSelector") {
                    PreLoadNavigation();
                }
            });         
};

//
// Handle the event for the toc selector change event.
//  We are using an explicit onchange event because IE was having problems
//      with jQuery's change event which fired a new document location.
//
function onToCSelectChange(option) {
    if ($("#ToCSelector").val() > -1) {
        changeToC($("#ToCSelector").val());
    }
    return false;
}

//
// Populate the list of topics
//
function PopulateTopicsSelector(callBack) {
    var topicsList = $("#tid");
    if (topicsList.get(0).options.length > 1) {
        return; // already populated
    }    
    
    var options = ['<option value="-1"></option>'];
    var url = GetTopicServiceUrl();
    $.ajaxSetup({ cache: false });
    $.getJSON(url, {},
            function(result) {
                for (var i = 0; i < result.length; i++) {
                    options.push('<option value="',
                            result[i].ID, '">',
                            result[i].Description, '</option>');
                }
                topicsList.html(options.join(''));
                
                if (undefined != callBack && null != callBack && typeof callBack == 'function') {
                    setTimeout(callBack, 500); 
                }
            });
}


///
/// This function uses jQuery to increase or decrease font size inside our content container.
///
function AdjustFontSize(action) {
    var ourText = $('#content');
    var currFontSize = ourText.css('fontSize');
    var finalNum = parseFloat(currFontSize, 10);    
    if (action == 'larger') {
        finalNum = finalNum + 2;
    }
    else if (action == 'smaller') {
        finalNum = finalNum - 2;
    }
    $('#content').css('fontSize', finalNum);
    return false;
}

///
/// Get the selected document by sending a JSON request to our serverice.
///      Once we have the JSON object, set the content to the requested document.
///
function GetContent(id, prevNodeID, preNodeTitle, nextNodeID, nextNodeTitle) {
    var strURL = window.location.pathname.toLowerCase();
    if (strURL.indexOf("default.aspx") < 0) {
        oQS["cceid"] = id.toString();
        oQS["sessionid"] = "";
        oQS["searchid"] = "";
        window.location = oQS.toQSString("default.aspx");
    }


    // if we don't clear then the bubble tip will attempt to attach to the 
    // old content since it could/will happen before the new content has loaded
    //$("#content").html("");

    var serviceURL = GetContentServiceUrl(id);
    $.ajaxSetup({ cache: false });
    $.getJSON(serviceURL, {},
            function(result) {
                // Inject the document into our container.
                //$("#content").html('');
                SetUpLinearNav(prevNodeID, unescape(preNodeTitle), nextNodeID, unescape(nextNodeTitle));

                $("#content").html(result.Document);

                InitReferencesLink(result.HasReferences);                                
                ContentChanged(result, id);
            });

    window.scrollTo(0, 0);            
}

function InitReferencesLink(bDisplayLinks) {

    if (bDisplayLinks) {
        $(".referenceContent").show("fast");
    }
    else {
        $(".referenceContent").hide("fast");
    }

}

// Create the linear navigation links and their events
function SetUpLinearNav(prevNodeID, preNodeTitle, nextNodeID, nextNodeTitle) {

    var navContainers = $(".linearNavContainer");

    if (navContainers.length == 0) {
        return;
    }

    navContainers.each(function() {$(this).css("display", "block"); });           
           
    // Previous Node
    if (prevNodeID == -1) {
        $(".leftLinear").css("visibility", "hidden");
    }
    else {
        $(".prevLink").unbind();
        var strInnerText = $(".prevLink").html();
        if (null != strInnerText) {
            strInnerText = strInnerText.substring(0, strInnerText.indexOf(":") + 2);
            $(".prevLink").html(strInnerText + preNodeTitle);

            $(".prevLink").click(function() {
                var element = $("." + prevNodeID);
                if (element.length <= 0) {
                    var prevParentID = $("#" + oQS["cceid"]).prev().attr('id');
                    $("#" + prevParentID).children().first().trigger('click');
                    setTimeout("ClawToNode(" + prevNodeID + "," + prevParentID + "," + 1 + ")", 500);
                }
                else {
                    $("." + prevNodeID).trigger('click');
                }
                return false;
            });

            $(".leftLinear").css("visibility", "visible");
        }
    }

    // Next Node
    if (nextNodeID == -1) {
        $(".rightLinear").css("visibility", "hidden");
    }
    else {
        $(".nextLink").unbind();
        strInnerText = $(".nextLink").html();
        if (null != strInnerText) {
            strInnerText = strInnerText.substring(0, strInnerText.indexOf(":") + 2);
            $(".nextLink").html(strInnerText + nextNodeTitle);

            $(".nextLink").click(function() {
                $("." + nextNodeID).trigger('click');
                return false;
            });
            $(".rightLinear").css("visibility", "visible");
        }
    }   
}

// This function digs through our tree in reverse looking for the needed cell data.
function ClawToNode(targetNode, currentNode, iteration) {
// If we cannot find the cell after 6 tries, something very bad has happened so stop clawing back.
    if (iteration <= 5) {
        var node = $("." + targetNode);

        if (node.length <= 0) {
            var currentKids = $("#" + currentNode).children();
            if (null != currentKids) {
                var list = currentKids[currentKids.length - 1];
                if (null != list) {
                    $(list).children().last().children().first().trigger('click');
                    currentNode = $(list).children().first().attr('id');
                    if (!isNaN(currentNode)) {
                        setTimeout("ClawToNode(" + targetNode + "," + currentNode + "," + iteration++ + ")", 500);
                    }
                }
            }
        }
        else {
            $("." + targetNode).trigger('click');
        }
    }
}

function InternalCCE(lang, toc, cceid) {
    oQS['CCEID'] = "";
    oQS['cceid'] = "";
    oQS['searchid'] = "";
    oQS['sessionid'] = "";
    
    // if we get 0 or less then just look at the TOC portion of the code.
    if (cceid > 0) {
        oQS['cceid'] = cceid;
    }
    oQS['toc'] = toc;
    window.location = oQS.toQSString("default.aspx");
}

// the URL to the glossary service
function GetGlossaryServiceUrl(id, word) {
    return Service_GlossaryContentService.replace("{0}", escape(strConsumerName)).replace("{1}", escape(strConsumerType)).replace("{2}", strCulturalCode).replace("{3}", id).replace("{4}", escape(word).replace("{5}", strLanguage.toLowerCase()));
}

function GetContentServiceUrl(id) {
    return Service_CCEContentService.replace("{0}", escape(strConsumerName)).replace("{1}", escape(strConsumerType)).replace("{2}", strCulturalCode).replace("{3}", id);
}

function GetToCServiceUrl() {
    return Service_TypeOfCancerService.replace("{0}", escape(strConsumerName)).replace("{1}", escape(strConsumerType)).replace("{2}", strCulturalCode);
}

function GetTopicServiceUrl() {
    return Service_TopicsService.replace("{0}", escape(strConsumerName)).replace("{1}", escape(strConsumerType)).replace("{2}", strCulturalCode);;
}

function GetTOCFromCCEID(iCCEID) {
    return Service_TypeOfCancerService_GetItem.replace("{0}", escape(strConsumerName)).replace("{1}", escape(strConsumerType)).replace("{2}", strCulturalCode).replace("{3}", iCCEID);
}

function ForceATOC() {
    if (oQS["cceid"] != null && oQS["cceid"] != undefined && (oQS["toc"] == null || oQS["toc"] == undefined)) {
        SetTOCFromCCEID(oQS["cceid"])
    }
}

function SetTOCFromCCEID(iCCEID) {
    $.ajaxSetup({ cache: false });
    $.getJSON(GetTOCFromCCEID(iCCEID), null, function(result) {
        oQS["toc"] = result.ID;
        setSelectValue("ToCSelector", result.ID);
    });
    
}

// build the link to a glossary word
function GetGlossaryLink(gid, word) {
    return Service_Glossary.replace("{0}", strLanguage).replace("{1}", gid) +
            "&alias=" + escape(word) + "&culture=" + escape(strCulturalCode);  
}


function IsIE6() {
    return !!(document.all && (/msie 6./i).test(navigator.appVersion) && window.ActiveXObject);
}

oRes.byLang = function(strLang) {
    return oRes[strLang.substr(0, 2)];
}

oRes.curLang = function() {
    return oRes.byLang(strCulturalCode);
}

function GetContentServiceUrl(id) {
    return Service_CCEContentService.replace("{0}", escape(strConsumerName)).replace("{1}", escape(strConsumerType)).replace("{2}", strCulturalCode).replace("{3}", id);
}

function GetToCServiceUrl() {
    return Service_TypeOfCancerService.replace("{0}", escape(strConsumerName)).replace("{1}", escape(strConsumerType)).replace("{2}", strCulturalCode);
}

function ToggleSearchOptions(arrowID, tocCallBack, topicsCallBack, callBack) {
    var arrowImg = document.getElementById(arrowID);
    var options = $("#extraOptions");
    
    
    if (options.is(":hidden")) {
        options.slideDown('slow');
        arrowImg.src = arrowImg.src.replace("down", "up");
        $("#OptionExpando").addClass("OpenOptions");

        // only populate when showing the items
        PopulateTopicsSelector(topicsCallBack);
        PopulateToCSelector('toc', false, true, tocCallBack);        
    }
    else {
        options.slideUp('slow');
        arrowImg.src = arrowImg.src.replace("up", "down");
        $("#OptionExpando").removeClass("OpenOptions");

        // clear these options out
        setSelectValue("toc", -1);
        setSelectValue("tid", -1);
    }
    
    arrowImg = $(arrowImg);
    
    var title = arrowImg.attr("title");
    var rel = arrowImg.attr("rel");
    arrowImg.attr("title", rel)
    arrowImg.attr("rel", title);

    if (undefined != callBack && null != callBack) {
        callBack();
    }
}

function searchOnEnter(e) {
    var characterCode;
    if(e && e.which){ 
        e = e
        characterCode = e.which
    } else {
        e = event
        characterCode = e.keyCode
    }

    if(characterCode == 13){
        doSearch();
        return false
    } else {
        return true
    }
}

function selectValue(elID)
{
    var oSel = document.getElementById(elID);
    if (oSel.selectedIndex > 0) {
        return oSel.options[oSel.selectedIndex].value
    }
    return "";
}
function setSelectValue(elID, val) {
    var oSel = document.getElementById(elID);
    for (var i = 0; i < oSel.options.length; i++) {
        if (oSel.options[i].value == val) {
            try {
                oSel.options[i].selected = true;
            } catch (e) { }
            break;
        }
    }

    if ($("#ToCSelector").val() > 0) {
        $("#treeRootIcon").attr("src", "images/treeroot_open.gif");
        $(".treeRootSpacer").css("display", "block");
    }
    else {
        $("#treeRootIcon").attr("src", "images/treeroot.gif");
        $(".treeRootSpacer").css("display", "none");
    }
}

oQS.toQSString = function(strBaseUrl) {
    var newWS = "";
    for (var key in this) {
        if (typeof this[key] != 'function') {
            if (this[key].length > 0) {
                if (newWS.length > 0) {
                    newWS += "&";
                }
                newWS += key + "=" + escape(this[key])
            }
        }
    }

    // we have a base URL to append to
    if (undefined != strBaseUrl & null != strBaseUrl) {
        if (newWS.length > 0) {
            if (strBaseUrl.indexOf("?") < 0) {
                return strBaseUrl + "?" + newWS;
            } else {
                return strBaseUrl + "&" + newWS;
            }
        } else {
            return strBaseUrl
        }
    }

    // no base just give back the new QS
    return newWS;
}

function doDidYouMeanSearch(el) {
    document.getElementById("lf").value = $(el).text();
    doSearch();
}

function doSearch() {
    // remove stuff that shouldn't be added to the search
    oQS["cceid"] = "";
    oQS["CCEID"] = "";
    oQS["sessionid"] = "";
    oQS["searchid"] = "";
    oQS["page"] = "";
    // add in the search criteria
    oQS["toc"] = selectValue("toc");
    oQS["tid"] = selectValue("tid");
    oQS["lf"] = escape(document.getElementById("lf").value);
    // go do a search
    document.location = oQS.toQSString("SearchResults.aspx");
}

function setSearchOptions() {
    if (
            (oQS["tid"] != "-1" && oQS["tid"] != null && oQS["tid"] != undefined) ||
            (oQS["toc"] != "-1" && oQS["toc"] != null && oQS["toc"] != undefined)
        ) {        
        ToggleSearchOptions($(".toggleOptionsArrow").attr("id"),
            function() { setSelectValue("toc", oQS["toc"]); },
            function() { setSelectValue("tid", oQS["tid"]); },
            function() { if (null != oQS["lf"] && undefined != oQS["lf"]) { document.getElementById("lf").value = unescape(oQS["lf"]); } }
        );
    } else if (null != oQS["lf"] && undefined != oQS["lf"]) {
        document.getElementById("lf").value = unescape(oQS["lf"]);
    }
}//setSearchOptions


// Set the selected ToC if we have a query string TOC parameter
function PreLoadNavigation() {
    var tocid = oQS["toc"];
    var cceid = oQS["cceid"];

    if ((null == tocid || undefined == tocid) && (null != cceid && undefined != cceid)) {
        SetTOCFromCCEID(cceid)
    }    

    if (cceid != "" && cceid != "-1" && cceid != null) {
        PopulateTree(-1, cceid, -1, function() {
            if (tocid != "" && tocid != "-1" && tocid != null) {
                setSelectValue("ToCSelector", tocid);
            }
            // Wait for the tree to build.
            setTimeout("CollectLinearNavData(" + cceid + ")", 500);            
        });                
   }
    else {
        if (tocid != "" && tocid != "-1" && tocid != null) {
            var strURL = window.location.pathname.toLowerCase();
            // Issue #176 - Do not load the tree on the Search Results Page.
            if (strURL.indexOf("searchresult") <= 0) {
                PopulateTree(-1, -1, tocid, function() {
                    setSelectValue("ToCSelector", tocid);

                    if (strURL.indexOf("default.aspx") >= 0) {
                        var id = $("ul.treeview li:first-child").attr('id');
                        if (null != id) {
                            HighlightTreeNode(-1, id);
                            CollectLinearNavData(id);
                            $("#" + id).children().first().trigger('click');
                            oQS['cceid'] = id.toString();
                        }
                    }

                });
            }                    
        }
    }
}

// Initiate a post back when the TOC changes
function changeToC(id) {    
    // CCEID is removed during a TOC change
    oQS["cceid"] = "";
    oQS["sessionid"] = "";
    oQS["searchid"] = "";
    oQS["lf"] = "";
    oQS["tid"] = "";        
    oQS["toc"] = id;
    var url = "default.aspx"; //document.location.href.substring(0, document.location.href.lastIndexOf("?"));
    document.location = oQS.toQSString(url);

    return false;
}

function openReferencesWindow(link) {
    var win = window.open($(link).attr("href"), "references", "width=500,height=500,resizable=1,scrollbars=1", false);
    win.focus();
    return false;
}

// Reset the form in the container.  Works best passed a div with an id.
function resetForm(container) {
    $(":input", container).each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form')
            return $(':input', this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea')
            this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
    });
}

// Add custom highlighting to textareas and textboxes located inside the provided container.
function TextBoxHighlighting(elID) {
    $(':input', elID).each(function(){
        var type = this.type, tag = this.tagName.toLowerCase();
        if (type == 'text' || type == 'password' || tag == 'textarea') {
            $("#" + this.id).focus(function() {
                $(this).toggleClass("focusTextBox", true);
                
                $(this).blur(function(){
                    $(this).toggleClass("focusTextBox", false);
                });
            });
        }
    });
}

// Dynamically trims the length of input.
function LimitTextLength(elID, limit) {
    $('textarea[id$=' + elID + ']').keyup(function() {
        var len = $(this).val().length;
        if (len > limit) {
            this.value = $.trim(this.value).substring(0, limit);
        }
    });
}

function clone(object)
{
    var ClonedObject = function() { };
    ClonedObject.prototype = object;
    return new ClonedObject;
}

function showPageLink(popLink) {
    var poppedLink = $(popLink);
    var pl = $("#permaLink");
    pl.css({ top: poppedLink.position().top + 25, left: poppedLink.position().left - 270 });

    var oNewQs = clone(oQS);
    var url = document.location.protocol + "//" + document.location.host + document.location.pathname;    
    oNewQs["searchid"] = "";
    oNewQs["sessionid"] = "";
    oNewQs["Lang"] = strLanguage;

    var boxToPopulate = document.getElementById("pageLinkToCopy");
    if(null != boxToPopulate)
    {
        boxToPopulate.value = oNewQs.toQSString(url);    
    }

    pl.toggle();

    if (null != boxToPopulate && pl.is(":visible")) {
        boxToPopulate.focus();
        boxToPopulate.select();
    }
}
function closer() {
    $("#permaLink").hide();
}

function emailThisPage() {
    var url = getBaseUrl() + webui_EmailAFriend;
    var oNewQs = clone(oQS);
    oNewQs["searchid"]="";
    oNewQs["sessionid"]="";
    url = url.replace("{0}",
        escape((oNewQs.toQSString(document.location.protocol + "//" + document.location.host + document.location.pathname))).replace("&", "%26")
        );
    oNewQs["Lang"] = strLanguage;
    var win = window.open(oNewQs.toQSString(url), "emailFriend", "height=650,width=490,location=no,menubar=no,scrollbars=auto", false);
    win.focus();
}

function ShowCMSContent(contentID) {
    oQS["cceid"] = contentID;
    oQS["sessionid"] = "";
    oQS["searchid"] = "";
    // clear out the search result or things wil get wonky.
    oQS["lf"] = "";
    oQS["toc"] = ""; 
    oQS["tid"] = "";    
    var url = getBaseUrl() + "default.aspx";
    window.location = oQS.toQSString(url);
}

function ShowSearchTips() {
    ShowCMSContent(webui_SearchTipsID);
}

function GotoContactForm() {
    if (null != oQS["cceid"] && "" != oQS["cceid"]) {
        oQS["cu_cceid"] = oQS["cceid"];
    }
    oQS["cceid"] = "";
    oQS["sessionid"] = "";
    oQS["searchid"] = "";
    // clear out the search result or things wil get wonky.
    oQS["lf"] = "";
    oQS["toc"] = "";
    oQS["tid"] = "";           
    var url = getBaseUrl() + webui_ContactFormURL;
    window.location = oQS.toQSString(url);

    return false;
}

function GotoReferences() {
    oQS["sessionid"] = "";
    oQS["searchid"] = "";
    // clear out the search result or things wil get wonky.
    oQS["lf"] = "";
    oQS["toc"] = "";
    oQS["tid"] = "";        
    var url = getBaseUrl() + webui_ReferencesURL;
    var win = window.open(oQS.toQSString(url), "References", "width=750,height=500,resizable=1,scrollbars=1", false);
    win.focus();
    
    return false;    
}

function getBaseUrl() {
    return document.location.href.substring(0, document.location.href.lastIndexOf("/") + 1);
}

function GotoTalkToUs() {
    GotoContactForm();

    return false;
}

function goToWelcome() {
    oQS["cceid"] = "";
    oQS["CCEID"] = "";
    oQS["lf"] = "";
    oQS["sessionid"] = "";
    oQS["searchid"] = "";
    oQS["toc"] = "";
    oQS["rk"] = "";
    oQS["fp"] = "";
    oQS["alp"] = "";
    oQS["sqg"] = "";    
    var url = "default.aspx"; 
    document.location = oQS.toQSString(url);
    return false;
}

function GotoMedicalDisclaimer() {
    if (intLanguage != 1) {
        oQS["sc_lang"] = strCulturalCode.toLowerCase();
    }
    else {
        oQS["sc_lang"] = "en";
    }
    window.open(oQS.toQSString(External_MedicalDisclaimer));

    return false;
}

function GotoCancerCA() {
    window.open("http://www.cancer.ca");
    return false;
}

function GotoContactUs() {
    ShowCMSContent(webui_ContactUsPageID);
}

function GotoGlossary() {
    var strURL = External_Glossary.replace("{0}", strLanguage.toLowerCase());
    window.open(strURL);
}

// Update the AddThis share object to the current querystring.
function UpdateAddThisLink() {
    var strcurrentURL = document.location.href.substring(0, document.location.href.lastIndexOf("?"));
    var objShareLnk = document.getElementById("shareLink")
    if (null != objShareLnk && undefined != objShareLnk) {
        if (null != objShareLnk.share && undefined != objShareLnk.share) {
            objShareLnk.share.url = oQS.toQSString(strcurrentURL);
        }
    }
}

// Track async content changes in Google Analytics
function UpdateAnalytics() {
    var intFirstPosition = document.location.href.lastIndexOf("/")+1;
    var intLastPosition = document.location.href.lastIndexOf("?");
    var strCurrentPage = document.location.href.substring(intFirstPosition, intLastPosition);
           
    pageTracker._trackPageview(oQS.toQSString(strCurrentPage).toLowerCase());    
}

// Handle the events that need to fire after content has changed.
function ContentChanged(result, newID) {
    // Set the highlight on currently selected cell
    var oldID = oQS["cceid"];
    HighlightTreeNode(oldID, newID);

    oQS["cceid"] = newID.toString();
    $(".documentPath").each(function() { $(this).html(result.Path); });
    document.title = result.Path;
    
    UpdateAddThisLink();
    UpdateAnalytics();
    AttachGlossaryTips();
}

function HighlightTreeNode(prevNodeID, nextNodeID) {        
    $("." + prevNodeID).removeAttr('style');
    $("." + nextNodeID).css('color', '#FF9101');
    $("." + nextNodeID).css('text-decoration', 'underline');
}

function GotoPrinterFriendly() {
    //var strURL = window.location.pathname.toLowerCase();
    //if (strURL.match("default") != null) {
    // We have a CCE cell, so go to the printer friendly page
    //    var url = document.location.href.substring(0, document.location.href.lastIndexOf("/") + 1) + webui_PrinterFriendlyURL;
    //    window.location = oQS.toQSString(url);
    //}else {
    // We do not have a CCE cell, so change to printer friendly styling

    $(".masterLayout").css("visibility", "hidden");
    $("html").css("background-color", "#FFFFFF");
    $("body").addClass("printerMode");
    $("body").css("background-color", "#FFFFFF");
    $("#printerHeader").css("display", "block");
    $("#printerFooter").css("display", "block");
    $("#contentWrapper").toggleClass("printerFriendlyContent");
    $("#content").css("padding-top", "0px");
    $("#SwitcherandPath").css('margin-top', '0px');
    $(".switcher").css('display', 'none');
    $(".referenceContainer").fadeOut("fast");
    $(".linearNavContainer").fadeOut("slow");
    $(".resultNavigation").fadeOut("slow");
    $(".copyright").css("margin-bottom", "36px");   
}

// Remove the printer friendly styling
function ClosePrinter() {
    $("#printerHeader").css("display", "none");
    $("#printerFooter").css("display", "none");
    
    $("#contentWrapper").toggleClass("printerFriendlyContent");
    $("body").css("background-color", "");
    $("html").css("background-color", "#0066cb");
    $("body").removeClass("printerMode");
    $("#content").removeAttr('style');
    $("#SwitcherandPath").removeAttr('style');
    $(".switcher").css('display', 'block');
    $(".referenceContainer").fadeIn("fast");
    $(".resultNavigation").fadeIn("slow");
    $(".copyright").css("margin-bottom", "");
    $(".masterLayout").css("visibility", "visible");
    
    if(null != oQS['cceid'] || !isNaN(oQS['cceid'])) {
        $(".linearNavContainer").fadeIn("slow");
    }
}

function CollectLinearNavData(cceid) {
    if ($("#" + cceid).length > 0) {
        var spansArray = $("#" + cceid).find("span");
        var prevNodeID = $(spansArray[0]).attr("previd");
        var prevNodeTitle = $(spansArray[0]).attr("prevtitle");
        var nextNodeID = $(spansArray[0]).attr("nextid");
        var nextNodeTitle = $(spansArray[0]).attr("nexttitle");

        SetUpLinearNav(prevNodeID, unescape(prevNodeTitle), nextNodeID, unescape(nextNodeTitle));
    }
}

function SwitchToLanguage(strPrefix) {
    oQS["Lang"] = strPrefix;
    oQS["sessionid"] = "";
    // don't need to pass it along if it is blank
    if (oQS["searchid"] == "00000000-0000-0000-0000-000000000000") {
        oQS["searchid"] = "";
    }

    // get the base url
    var strCurrentURL = "";
    if (document.location.href.indexOf(".aspx") < 0) {
        strCurrentURL = "default.aspx";
    } else {
        strCurrentURL = document.location.href.substring(0, document.location.href.lastIndexOf("?"));
    }
    window.location = oQS.toQSString(strCurrentURL);    
}


function doPagePrint() {
    if (document.execCommand) {
        try {
            document.execCommand('print', false, null);
        }
        catch (e) {
            window.print();
        }
    }
    else {
        window.print();
    }
    return false;
}

