﻿// Utility Function
function $(id) { return document.getElementById(id); }
// END:Utility Function

// Extending js //
Array.prototype.max = function() { return Math.max.apply({}, this) };
// END:Extending js //

function StandardizeHostName(hn) {
    var hnpatterns = new RegExp("healthvault.com|microsofthealth.com", "i");
    var standardizedhn = "www.healthvault.com";
    if (typeof (hn) == "string") {
        if (hn.match(hnpatterns)) {
            hn = standardizedhn;
        }
    }
    return hn;
}


var BrowserDetect = {
    init: function() {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function(data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function(dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [
		{
		    string: navigator.userAgent,
		    subString: "Chrome",
		    identity: "Chrome"
		},
		{ string: navigator.userAgent,
		    subString: "OmniWeb",
		    versionSearch: "OmniWeb/",
		    identity: "OmniWeb"
		},
		{
		    string: navigator.vendor,
		    subString: "Apple",
		    identity: "Safari",
		    versionSearch: "Version"
		},
		{
		    prop: window.opera,
		    identity: "Opera"
		},
		{
		    string: navigator.vendor,
		    subString: "iCab",
		    identity: "iCab"
		},
		{
		    string: navigator.vendor,
		    subString: "KDE",
		    identity: "Konqueror"
		},
		{
		    string: navigator.userAgent,
		    subString: "Firefox",
		    identity: "Firefox"
		},
		{
		    string: navigator.vendor,
		    subString: "Camino",
		    identity: "Camino"
		},
		{		// for newer Netscapes (6+)
		    string: navigator.userAgent,
		    subString: "Netscape",
		    identity: "Netscape"
		},
		{
		    string: navigator.userAgent,
		    subString: "MSIE",
		    identity: "Explorer",
		    versionSearch: "MSIE"
		},
		{
		    string: navigator.userAgent,
		    subString: "Gecko",
		    identity: "Mozilla",
		    versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
		    string: navigator.userAgent,
		    subString: "Mozilla",
		    identity: "Netscape",
		    versionSearch: "Mozilla"
		}
	],
    dataOS: [
		{
		    string: navigator.platform,
		    subString: "Win",
		    identity: "Windows"
		},
		{
		    string: navigator.platform,
		    subString: "Mac",
		    identity: "Mac"
		},
		{
		    string: navigator.userAgent,
		    subString: "iPhone",
		    identity: "iPhone/iPod"
		},
		{
		    string: navigator.platform,
		    subString: "Linux",
		    identity: "Linux"
		}
	]

};
BrowserDetect.init();




function HasWindowsMediaPlayerPlugin() {
    //Windows Media Player
    var agt = navigator.userAgent.toLowerCase();
    var ie = (agt.indexOf("msie") != -1);
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var win = ((agt.indexOf("win") != -1) || (agt.indexOf("32bit") != -1));
    var mac = (agt.indexOf("mac") != -1);
    var returnValue = false;

    if (ie && win) {
        try {
            var testObject = CreateObject("MediaPlayer.MediaPlayer.1");
            returnValue = IsObject(testObject);
        }
        catch (Err) {
            returnValue = false;
        }
    }
    if (ns || !win) {
        if (navigator.mimeTypes["application/x-mplayer2"]) {
            if (navigator.mimeTypes["application/x-mplayer2"].enabledPlugin != null) {
                returnValue = true;
            }
        }
        if (navigator.mimeTypes["application/x-ms-wmp"]) {
            if (navigator.mimeTypes["application/x-ms-wmp"].enabledPlugin != null) {
                returnValue = true;
            }
        }
    }
    return returnValue;
}


function heightEqualizer(elementArray) {
    var heights = [];
    for (var i = 0; i < elementArray.length; i++) {
        heights.push(elementArray[i].offsetHeight);
    }
    applyChange("height", elementArray, heights.max());
}

function randomize(max, elementArray) {
    var newArray = new Array();

    for (var i = 0; i < elementArray.length; i++)
        newArray[i] = i;

    for (var i = 0; i < max; i++) {
        var ri = -1;
        do {
            var n = Math.floor(Math.random() * newArray.length);
            ri = newArray[n];

            if (ri != -1)
                newArray[n] = -1;
        }
        while (ri == -1);

        elementArray[ri].style.display = "block";
    }
}

function applyChange(type, elementArray, value) {
    var param = "";
    var unit = "";
    switch (type) {
        case "height":
            param = "height";
            unit = "em";
            break;
    }
    for (var i = 0; i < elementArray.length; i++) {
        elementArray[i].style[param] = value / 10 + unit;
    }
}

function getChildrenInParentByClassName(pID, cClass) {
    var array = $(pID).getElementsByTagName("div");
    var newArray = [];
    for (var i = 0; i < array.length; i++) {
        if (array[i].className == cClass) {
            newArray.push(array[i]);
        }
    }
    return (newArray);
}

function addToMyFavorite(url, title) {
    if (document.all) {
        window.external.AddFavorite(url, title);
    }
    else if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
}


// Redesign JS //


function audienceDirectory() {
    if (readCookie("HealthVault")) {
        if (readCookie("HealthVault") == "organization") {
            document.getElementById("lnkPersonal").style.display = "none";
            document.getElementById("lnkIndustry").style.display = "block";
        } else {
            document.getElementById("lnkPersonal").style.display = "block";
            document.getElementById("lnkIndustry").style.display = "none";
        }
    }
}

function audienceDir() {
    if (readCookie("HealthVault")) {
        if (readCookie("HealthVault") == "organization") {
            document.getElementById("channel").className = "indDir";
        }
    }
}

function audienceHelp() {
    if (readCookie("HealthVault")) {
        if (readCookie("HealthVault") == "organization") {
            document.getElementById("industry-help").style.display = "block";
        }
    }
}


function lnkDevices() {
    if (readCookie("HealthVault")) {
        if (readCookie("HealthVault") == "organization") {
            document.getElementById("lnkLD1Ind").style.display = "block";
            document.getElementById("lnkLD1Per").style.display = "none";
        }
    }
}

function selectHome() {
    if (readCookie("HealthVault")) {
        if (readCookie("HealthVault") == "organization") {
            window.location = "/industry/index.aspx";
            return;
        }

    }
    window.location = "/personal/index.aspx";
}


function setSubnav() {

    if (document.getElementById("nav-ind")) {
        var nind = document.getElementById("nav-ind");
        var norg = document.getElementById("nav-org");


        if (readCookie("HealthVault")) {
            if (readCookie("HealthVault") == "individual") {
                nind.style.display = "block";
                norg.style.display = "none";
            }
            else if (readCookie("HealthVault") == "organization") {
                norg.style.display = "block";
                nind.style.display = "none";
            }
        }
        else {
            norg.style.display = "none";
        }
    }
}


function setWTAudience() {

    if (readCookie("HealthVault")) {
        if (readCookie("HealthVault") == "individual") {
            document.write("<meta name=\"DCSext.www_rt\" content=\"" + "personal" + "\" />");
        }
        else if (readCookie("HealthVault") == "organization") {
            document.write("<meta name=\"DCSext.www_rt\" content=\"" + "industry" + "\" />");
        }
    }
    else {
        document.write("<meta name=\"DCSext.www_rt\" content=\"" + "none" + "\" />");
    }
}



function startList() {
    if (document.all && document.getElementById) {
        if (document.getElementById("nav")) {
            subnavRoot = document.getElementById("nav").getElementsByTagName("ul");
            for (i = 0; i < subnavRoot.length; i++) {
                for (j = 0; j < subnavRoot[i].childNodes.length; j++) {
                    node = subnavRoot[i].childNodes[j];
                    if (node.nodeName == "LI") {
                        node.onmouseover = function() {
                            this.className += " over";
                        }
                        node.onmouseout = function() {
                            this.className = this.className.replace(" over", "");
                        }
                    }
                }
            }
        }
    }
}


function setCookie(name, value, expiration) {
    var cookie = name + "=" + encodeURIComponent(value);
    var expires = new Date();
    expires.setFullYear(expires.getFullYear() + 1);

    if (expiration != null) {
        if (expiration != 0)
            cookie += "; expires=" + expiration + "; path=/";
        else
            cookie += "; path=/";
    }
    else {
        cookie += "; expires=" + expires + "; path=/";
    }
    document.cookie = cookie;

}


function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}


function deleteCookie(name) {
    setCookie(name, "", new Date(0));
}

function detect() {
    if (readCookie("HealthVault")) {
        if (readCookie("HealthVault") == "individual") {
            document.location = "Personal/index.aspx";
        }
        else if (readCookie("HealthVault") == "organization") {
            document.location = "Industry/index.aspx";
        }
    }
}


function setTabState() {

    if (readCookie("HVFocus")) {
        if (readCookie("HVFocus") == "walking") {
            HRTabSelect("tab1");
        }
        else if (readCookie("HVFocus") == "diet") {
            HRTabSelect("tab2");
        }
        else if (readCookie("HVFocus") == "comprehensive") {
            HRTabSelect("tab3");
        }
    }
}

function getElementsByClassName(oElm, strTagName, strClassName) {
    var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for (var i = 0; i < arrElements.length; i++) {
        oElement = arrElements[i];
        if (oRegExp.test(oElement.className)) {
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

function isPage(pageUrl) {
    var currentUrl = document.URL;
    var re = new RegExp(pageUrl, "i");
    return (re.test(currentUrl));
}

function getPosition(element) {
    var left = 0;
    var top = 0;

    while (element.offsetParent) {
        left += element.offsetLeft;
        top += element.offsetTop;
        element = element.offsetParent;
    }

    left += element.offsetLeft;
    top += element.offsetTop;

    return { x: left, y: top };
}

function personalHomePageEqualizeHeights() {
    var elemA = document.getElementById("PersonalHomeBoxLeft");
    var elemB = document.getElementById("PersonalHomeBoxRight");
    if ((elemA) && (elemB)) {
        // Equalize the heights
        var rightElemDelta = 81;
        var heightA = elemA.offsetHeight;
        var heightB = elemB.offsetHeight + rightElemDelta;
        var NewHeight = Math.max(heightA, heightB);
        elemA.style.height = NewHeight + "px";
        NewHeight -= rightElemDelta;
        elemB.style.height = NewHeight + "px";
    }
}
function personalHomePageOnFontResize(e, args) {
    personalHomePageEqualizeHeights();
}
function personalHomePageInit() {
    var iBase = TextResizeDetector.addEventListener(personalHomePageOnFontResize, null);
}

function correctNavigation() {
    var navObj = document.getElementById("nav");
    if (navObj) {
        var navlistitemObjs = navObj.getElementsByTagName("LI");
        if (navlistitemObjs) {
            var lastsubsubnavObj;
            var i = 0;
            var lastsubsubnavFound = false;
            while ((i < navlistitemObjs.length) && (!lastsubsubnavFound)) {
                lastsubsubnavObj = navlistitemObjs[i];
                if ((lastsubsubnavObj) && (lastsubsubnavObj.className)) {
                    lastsubsubnavFound = (lastsubsubnavObj.className == "heightfix first");
                }
                if (!lastsubsubnavFound) {
                    i++;
                }
            }
            if (lastsubsubnavFound) {
                if (BrowserDetect.browser == "Safari") {
                    // get the submenu
                    var submenuobjs = lastsubsubnavObj.getElementsByTagName("UL");
                    if (submenuobjs) {
                        var submenuobj = submenuobjs[0];
                        if (submenuobj) {
                            // add a little to the left margin
                            submenuobj.style.marginLeft = "20px";
                        }
                    }
                }
            }
        }
    }
}
function init() {
    appendFlip4MacText();
    startList();
    if (isPage("/ICE/HiMSS/index.html") || isPage("/ICE/HiMSS/index.aspx") || isPage("/ICE/HiMSS/")) {
        // Equalize the heights
        var elementA = document.getElementById("Metavante");
        var elementB = document.getElementById("MyVitalData");
        var heightA = elementA.offsetHeight;
        var heightB = elementB.offsetHeight;
        var NewHeight = Math.max(heightA, heightB);
        var deltaA = NewHeight - heightA;
        var deltaB = NewHeight - heightB;
        elementA.style.height = NewHeight + "px";
        elementB.style.height = NewHeight + "px";

        // Align the two offer blocks
        elementA = document.getElementById("MetavanteOffer");
        elementB = document.getElementById("MyVitalDataOffer");
        elementA.style.position = "relative";
        elementB.style.position = "relative";
        elementA.style.top = deltaA + "px";
        elementB.style.top = deltaB + "px";

        reTargetAllLinksOnPage("_target");
    }
    if (isPage("/Personal/devices-overview.") || isPage("/Personal/devicelogoprogram.")) {
        var HVCCInstallLink = document.getElementById("HVCCInstallLink");
        if (HVCCInstallLink) {
            if (navigator.userAgent.toLowerCase().indexOf("windows nt 5.1") == -1) {
                HVCCInstallLink.href = "http://go.microsoft.com/fwlink/?LinkID=127972";
            }
        }
    }

    var elemA = document.getElementById("PersonalHomeBoxLeft");
    var elemB = document.getElementById("PersonalHomeBoxRight");
    if ((elemA) && (elemB)) {
        personalHomePageEqualizeHeights();
    }
    correctNavigation();
}

function OSDetect() {
    var platformOS;

    if (navigator.userAgent.indexOf("Windows NT 6.0") > -1) {
        document.getElementById("selectOS").style.display = "none";
        document.getElementById("vista").style.display = "block";
    }
    else if (navigator.userAgent.indexOf("Windows NT 5.1") > -1) {
        document.getElementById("selectOS").style.display = "none";
        document.getElementById("xp").style.display = "block";
    }
}



function HRTabSelect(tab) {
    for (var i = 1; i < 4; i++) {
        document.getElementById("tab" + i + "Left").className = "tabLeftOff";
        document.getElementById("tab" + i + "Middle").className = "tabMiddleOff";
        document.getElementById("tab" + i + "Right").className = "tabRightOff";
        document.getElementById("tab" + i + "Content").style.display = "none";
        document.getElementById("tab" + i).className = "tabNormal";
    }
    if (tab == "tab1") {
        document.getElementById("tab1Left").className = "tabLeftOn";
        document.getElementById("tab1Middle").className = "tabMiddleOn";
        document.getElementById("tab1Right").className = "tabRightOn";
        document.getElementById("tab2").className = "tabLeft";
        document.getElementById("tab1Content").style.display = "block";
    }
    else if (tab == "tab2") {
        document.getElementById("tab2Left").className = "tabLeftOn2";
        document.getElementById("tab2Middle").className = "tabMiddleOn";
        document.getElementById("tab2Right").className = "tabRightOn";
        document.getElementById("tab3").className = "tabLeft";
        document.getElementById("tab2Content").style.display = "block";
    }
    else if (tab == "tab3") {
        document.getElementById("tab3Left").className = "tabLeftOn2";
        document.getElementById("tab3Middle").className = "tabMiddleOn";
        document.getElementById("tab3Right").className = "tabRightOn";
        document.getElementById("tab3Content").style.display = "block";
    }
}

function SmartBreadcrumb(name, section) {
    url = window.location.search.substring(1);

    if (url.length < 400) {
        param = url.split("&");
        for (i = 0; i < param.length; i++) {
            value = param[i].split("=");
            if (value[0] == name) {
                switch (value[1]) {
                    case "1":
                        document.write("<a href='/hrweb/lose-weight.aspx'>Back to Lose or maintain weight</a>");
                        break;
                    case "2":
                        document.write("<a href='/hrweb/stay-fit.aspx'>Back to Get fit, stay fit</a>");
                        break;
                    case "3":
                        document.write("<a href='/hrweb/high-blood-pressure.aspx'>Back to Manage high blood pressure</a>");
                        break;
                    case "4":
                        document.write("<a href='/hrweb/get-organized.aspx'>Back to Organize family health information</a>");
                        break;
                    case "5":
                        document.write("<a href='/hrweb/in-case-of-emergency.aspx'>Back to Prepare for emergency</a>");
                        break;
                    case "6":
                        document.write("<a href='/personal/scenario/lose-weight.aspx'>Back to Lose or maintain weight</a>");
                        break;
                    case "7":
                        document.write("<a href='/personal/scenario/stay-fit.aspx'>Back to Get fit, stay fit</a>");
                        break;
                    case "8":
                        document.write("<a href='/personal/scenario/high-blood-pressure.aspx'>Back to Manage high blood pressure</a>");
                        break;
                    case "9":
                        document.write("<a href='/personal/scenario/get-organized.aspx'>Back to Organize family health information</a>");
                        break;
                    case "10":
                        document.write("<a href='/personal/scenario/in-case-of-emergency.aspx'>Back to Prepare for emergency</a>");
                        break;
                    default:
                        document.write("<a href='/personal/scenario/index.aspx'>Back to HealthVault on HRWeb</a>");
                }
                return;
            }
            else if (value[0] == "type") {            
                switch (value[1]) {
                    case "application":
                        if (readCookie("HealthVault")) {
                            if (readCookie("HealthVault") == "organization") {
                                document.write("<a href='/industry/websites.aspx?type=application'>See all applications</a>");
                            } else {
                            document.write("<a href='/personal/websites.aspx?type=application'>See all applications</a>");
                            }
                        }

                        return;
                    case "device":
                        if (readCookie("HealthVault")) {
                            if (readCookie("HealthVault") == "organization") {
                                document.write("<a href='/industry/devices.aspx?type=device'>See all devices</a>");
                            } else {
                            document.write("<a href='/personal/devices.aspx?type=device'>See all devices</a>");
                            }
                        }

                        return;
                }
            }
        }
    }

    if (section == "hrweb")
        document.write("<a href='/hrweb/websites.aspx'>Back to all featured applications</a>");
}

function getViewportHeight() {
    var returnValue = -1;
    if (window.innerHeight != window.undefined) {
        returnValue = window.innerHeight;
    }
    else {
        if (document.compatMode == 'CSS1Compat') {
            returnValue = document.documentElement.clientHeight;
        }
        else {
            if (document.body) {
                returnValue = document.body.clientHeight;
            }
        }
    }
    return returnValue;
}

function getViewportWidth() {
    var returnValue = -1;
    if (window.innerWidth != window.undefined) {
        returnValue = window.innerWidth;
    }
    else {
        if (document.compatMode == 'CSS1Compat') {
            returnValue = document.documentElement.clientWidth;
        }
        else {
            if (document.body) {
                returnValue = document.body.clientWidth;
            }
        }
    }
    return returnValue;
}

function setFadeSize() {
    var body = document.getElementsByTagName("BODY")[0];
    var fade = document.getElementById("fade");
    var fullHeight = getViewportHeight();
    var fullWidth = getViewportWidth();

    // Determine what's bigger, scrollHeight or fullHeight / width
    if (fullHeight > body.scrollHeight) {
        popHeight = fullHeight;
    }
    else {
        popHeight = body.scrollHeight;
    }

    if (fullWidth > body.scrollWidth) {
        popWidth = fullWidth;
    }
    else {
        popWidth = body.scrollWidth;
    }

    fade.style.height = popHeight + "px";
    fade.style.width = popWidth + "px";
}


function HRWebFirstVisit() {
    if (!readCookie("HRWebHV")) {
        document.getElementById('light').style.display = 'block';
        document.getElementById('fade').style.display = 'block';
        setFadeSize();
        setCookie('WT.mc_id', 'hrweb', 0);
    }
}

function captureTab(e) {
    var keynum;
    if (!readCookie("HRWebHV")) {
        if (window.event) // IE
        {
            keynum = e.keyCode;
        }
        else if (e.which) // Netscape/Firefox/Opera
        {
            keynum = e.which;
        }
        if (keynum == 9)
            return false;
    }
}

function popUp(url, title, width, height) {
    xPos = (screen.width) ? (screen.width - width) / 2 : 0;
    yPos = (screen.height) ? (screen.height - height) / 2 : 0;
    window.open(url, title, 'width=' + width + ',height=' + height + ',scrollbars=no,top=' + yPos + ',left=' + xPos, +',location=no,resize=no');
}

function popUpWMPlayer(url, title, width, height) {
    var onClickReturnValue = true;
    if (HasWindowsMediaPlayerPlugin()) {
        if (url) {
            if (!title) {
                title = "HealthVault Media";
            }
            if ((!width) || (!height)) {
                height = 480;
                width = 640;
            }
            url = "/player.html?v=" + url + "&h=" + height + "&w=" + width + "&t=" + title;
            var xPos = (screen.width) ? (screen.width - width) / 2 : 0;
            var yPos = (screen.height) ? (screen.height - height) / 2 : 0;
            var win = window.open(url, "popUpWMPlayer", 'width=' + width + ',height=' + height + ',scrollbars=no,top=' + yPos + ',left=' + xPos, +',location=no,resize=no');
            if (win) {
                onClickReturnValue = false;
            }
        }
    }
    return onClickReturnValue;
}


function continueHRWeb() {
    document.getElementById('light').style.display = 'none';
    document.getElementById('fade').style.display = 'none';
    setCookie('HRWebHV', 'true', 0);
    setCookie('WT.mc_id', 'hrweb', 0);
}

function setRefHRWeb() {
    if (!readCookie("WT.mc_id")) {
        setCookie('WT.mc_id', 'hrweb', 0);
    }
    document.write("<meta name=\"WT.mc_id\" content=\"" + readCookie("WT.mc_id") + "\" />");
}

function setHRCampaignId(mcid, ad) {
    if (document.referrer == '' && location.href.indexOf('WT.mc_id') < 0) {
        document.write("<meta name=\"WT.mc_id\" content=\"" + mcid + "\" />");
        document.write("<meta name=\"WT.ad\" content=\"" + ad + "\" />");
    }
}

function setReferralSite() {
    var RefererFound = false;
    var url = window.location.search.substring(1);

    if (url.length < 1000) {
        if (!readCookie("WT.mc_id")) {
            param = url.split("&");
            var i = 0;
            while ((i < param.length) && (!RefererFound)) ///  While
            {
                value = param[i].split("=");
                if ((value[0] == "WT.mc_id")) {
                    var oRegExp = new RegExp("^[a-zA-Z0-9]+$");
                    if (value[1].match(oRegExp)) {
                        setCookie('WT.mc_id', value[1], 0);
                        document.write("<meta name=\"WT.mc_id\" content=\"" + value[1] + "\" />");
                        RefererFound = true;
                    }
                    RefererFound = true;
                }
                i++;
            }    // While loop
        }    // if(!readCookie("WT.mc_id"))
    }   // Length test
}

function disableImage(e) {
    if (document.all) {
        if (event.button == 2 || event.button == 3) {
            if (event.srcElement.tagName == "IMG") {
                alert(msg);
                return false;
            }
        }
    }
    else if (document.layers) {
        if (e.which == 3) {
            alert(msg);
            return false;
        }
    }
    else if (document.getElementById) {
        if (e.which == 3 && e.target.tagName == "IMG") {
            alert(msg)
            return false;
        }
    }
}

function associateImages() {
    for (i = 0; i < document.images.length; i++)
        document.images[i].onmousedown = disableImage;
}

function isMac() {
    // returns True if client platform is a Mac
    return (navigator.appVersion.toLowerCase().indexOf("mac") != -1);
}

function appendFlip4MacText() {
    if (isMac()) {
        var FlipForMacElement = document.getElementById("FlipForMac");
        if (FlipForMacElement) {
            FlipForMacElement.style.display = "block";
            FlipForMacElement.style.visibility = "visible";
        }
        FlipForMacElement = document.getElementById("FlipForMac2");
        if (FlipForMacElement) {
            FlipForMacElement.style.display = "block";
            FlipForMacElement.style.visibility = "visible";
        }
    }
}

function appendRef(objAnchor) {
    if (readCookie("WT.mc_id")) {
        var href = objAnchor.href;
        if (href.indexOf("?") < 1) {
            href = href + "?";
        }
        else {
            href = href + "&";
        }
        href = href + "WT.mc_id=" + readCookie("WT.mc_id");
        objAnchor.href = href;
    }
}

function getRef() {
    return readCookie("WT.mc_id");
}

function reTargetAllLinksOnPage(newTarget) {
    var anchorsCollection = document.getElementsByTagName('A');
    var anchorElement;
    var scratch = "";
    for (var i = 0; i < anchorsCollection.length; i++) {
        anchorElement = anchorsCollection[i];
        scratch = anchorElement.href;
        scratch = scratch.substring(0, 10);
        scratch = scratch.toLowerCase();
        if (scratch != "javascript") {
            anchorElement.setAttribute("target", newTarget);
        }
    }
}


/*****************************************************************************
Text Resize Detector
*****************************************************************************/
TextResizeDetector = function() {
    var el = null;
    var iIntervalDelay = 200;
    var iInterval = null;
    var iCurrSize = -1;
    var iBase = -1;
    var aListeners = [];
    var createControlElement = function() {
        el = document.createElement('span');
        el.id = 'textResizeControl';
        el.innerHTML = '&nbsp;';
        el.style.position = "absolute";
        el.style.left = "-9999px";
        var elC = document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID);
        // insert before firstChild
        if (elC)
            elC.insertBefore(el, elC.firstChild);
        iBase = iCurrSize = TextResizeDetector.getSize();
    };

    function _stopDetector() {
        window.clearInterval(iInterval);
        iInterval = null;
    };
    function _startDetector() {
        if (!iInterval) {
            iInterval = window.setInterval('TextResizeDetector.detect()', iIntervalDelay);
        }
    };

    function _detect() {
        var iNewSize = TextResizeDetector.getSize();
        if (iNewSize !== iCurrSize) {
            for (var i = 0; i < aListeners.length; i++) {
                aListnr = aListeners[i];
                var oArgs = { iBase: iBase, iDelta: ((iCurrSize != -1) ? iNewSize - iCurrSize + 'px' : "0px"), iSize: iCurrSize = iNewSize };
                if (!aListnr.obj) {
                    aListnr.fn('textSizeChanged', [oArgs]);
                }
                else {
                    aListnr.fn.apply(aListnr.obj, ['textSizeChanged', [oArgs]]);
                }
            }

        }
        return iCurrSize;
    };
    var onAvailable = function() {
        if (!TextResizeDetector.onAvailableCount_i) {
            TextResizeDetector.onAvailableCount_i = 0;
        }

        if (document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID)) {
            TextResizeDetector.init();
            if (TextResizeDetector.USER_INIT_FUNC) {
                TextResizeDetector.USER_INIT_FUNC();
            }
            TextResizeDetector.onAvailableCount_i = null;
        }
        else {
            if (TextResizeDetector.onAvailableCount_i < 600) {
                TextResizeDetector.onAvailableCount_i++;
                setTimeout(onAvailable, 200)
            }
        }
    };
    setTimeout(onAvailable, 500);

    return {
        // Initialize the detector
        //   @param {String} sId The id of the element in which to create the control element
        init: function() {
            createControlElement();
            _startDetector();
        },
        // Adds listeners to the ontextsizechange event. 
        // Returns the base font size
        addEventListener: function(fn, obj, bScope) {
            aListeners[aListeners.length] = {
                fn: fn,
                obj: obj
            }
            return iBase;
        },
        // performs the detection and fires textSizeChanged event
        //   @return the current font size
        //   @type {integer}
        detect: function() {
            return _detect();
        },
        // Returns the height of the control element
        //   @return the current height of control element
        //   @type {integer}
        getSize: function() {
            var iSize;
            return el.offsetHeight;


        },
        // Stops the detector
        stopDetector: function() {
            return _stopDetector();
        },
        // Starts the detector
        startDetector: function() {
            return _startDetector();
        }
    }
} ();

TextResizeDetector.TARGET_ELEMENT_ID = 'doc';
TextResizeDetector.USER_INIT_FUNC = null;
