﻿function ChangeTextSizeClass(clsName)
{
	document.getElementById("contentarea").className = clsName;
	document.cookie = "textsize=" + clsName;
	switch(clsName)
	{
	    case "small":
	    document.getElementById("small").setAttribute("className", "active");
	    document.getElementById("large").setAttribute("className", "inactive");
	    document.getElementById("larger").setAttribute("className", "inactive");
	    document.getElementById("small").setAttribute("class", "active");
	    document.getElementById("large").setAttribute("class", "inactive");
	    document.getElementById("larger").setAttribute("class", "inactive");
	    break;
	    case "large":
	    document.getElementById("small").setAttribute("className", "inactive");
	    document.getElementById("large").setAttribute("className", "active");
	    document.getElementById("larger").setAttribute("className", "inactive");
	    document.getElementById("small").setAttribute("class", "inactive");
	    document.getElementById("large").setAttribute("class", "active");
	    document.getElementById("larger").setAttribute("class", "inactive");
	    break;
	    case "larger":
	    document.getElementById("small").setAttribute("className", "inactive");
	    document.getElementById("large").setAttribute("className", "inactive");
	    document.getElementById("larger").setAttribute("className", "active");
	    document.getElementById("small").setAttribute("class", "inactive");
	    document.getElementById("large").setAttribute("class", "inactive");
	    document.getElementById("larger").setAttribute("class", "active");
	    break;
	}
}
function getCookie(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{ 
			c_start = c_start + c_name.length + 1; 
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) 
				c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function openOutsideLink(url)
{
	var oWin = window.open('960-leaving-dexcom.aspx?Link=' + url, 'leavingwin', 'width=480,height=400');
	oWin.focus();
}

function openInternationalLink(url)
{
	var oWin = window.open('965-International-Interstitial.aspx?Link=' + url, 'leavingwin', 'width=480,height=400');
	oWin.focus();
}

function openStorePopup(url)
{
	var oWin = window.open('990-seven-store-popup.aspx?Link=' + url, 'leavingwin', 'width=480,height=450');
	oWin.focus();
}

function openSharePopup()
{
	var oWin = window.open('1000-share-your-story.aspx', 'sharestory', 'width=543,height=722,resizable=0');
	oWin.focus();
}

function openTempStorePopup()
{
	var oWin = window.open('290-seven-catalog.aspx', '_blank', 'width=750,height=800,scrollbars=1');
	oWin.focus();
}

function openRegisterPopup()
{
	var oWin = window.open('950-register-for-updates.aspx', '_blank', 'width=800,height=800,resizable=0,scrollbars=1');
	oWin.focus();
}

function openTellFriendPopup(url)
{
	var oWin = window.open('980-tell-a-friend.aspx?url=' + url, '_blank', 'width=800,height=800,resizable=0,scrollbars=1');
	oWin.focus();
}

function changeBio(dispID)
{
	var oDivContainer = document.getElementById('thenames');
	for (var i = 0; i < oDivContainer.childNodes.length; i++)
	{
		if (oDivContainer.childNodes[i].style != null)
			oDivContainer.childNodes[i].style.display = 'none';
	}
	
	document.getElementById(dispID).style.display = 'block';
}


//GLOSSARY
var offsetfrommouse=[20,-10]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 0;	// maximum image size.

function gettrailobj()
{
	if (document.getElementById)
		return document.getElementById("trailimageid").style
	else if (document.all)
		return document.all.trailimageid.style
}

function gettrailobjnostyle()
{
	if (document.getElementById)
		return document.getElementById("trailimageid")
	else if (document.all)
		return document.all.trailimageid
}

function gettrailobj2()
{
	if (document.getElementById)
		return document.getElementById("trailimageid2").style
	else if (document.all)
		return document.all.trailimageid2.style
}

function gettrailobjnostyle2()
{
	if (document.getElementById)
		return document.getElementById("trailimageid2")
	else if (document.all)
		return document.all.trailimageid2
}


function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showGlossPop()
{
	document.onmousemove=followmouse;
	followmouse();
	gettrailobj().display = "block";
}
function hideGlossPop(){
	gettrailobj().display = "none";
	document.onmousemove = "";
	gettrailobj().left = "-500px";

}

function showGlossPop2()
{
	document.onmousemove=followmouse2;
	followmouse2();
	gettrailobj2().display = "block";
}
function hideGlossPop2(){
	gettrailobj2().display = "none";
	document.onmousemove = "";
	gettrailobj2().left = "-500px";

}
function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 300; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 400){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 380; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

}

function followmouse2(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 380){
			xcoord = e.pageX - xcoord - 300; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 400){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 380; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj2().left=xcoord+"px"
	gettrailobj2().top=ycoord+"px"

}
//END GLOSSARY

function displayPDF(Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18,
 Q19, Q20, Q21, Q22, Q23, Q24, Q25, Q26, Q27, Q28)
 {
    var s = "&Q1=" + Q1 + "&Q2=" + Q2 +"&Q3=" + Q3 +"&Q4=" + Q4 +"&Q5=" + Q5 +"&Q6=" + Q6 +"&Q7=" + Q7 +
    "&Q8=" + Q8 +"&Q9=" + Q9 +"&Q10=" + Q10 +"&Q11=" + Q11 +"&Q12=" + Q12 +"&Q13=" + Q13 +"&Q14=" + Q14 +"&Q15=" + Q15 +
    "&Q16=" + Q16 +"&Q17=" + Q17 +"&Q18=" + Q18 +"&Q19=" + Q19 +"&Q20=" + Q20 +"&Q21=" + Q21 +"&Q22=" + Q22 +"&Q23=" + Q23 + 
    "&Q24=" + Q24 +"&Q25=" + Q25 +"&Q26=" + Q26 +"&Q27=" + Q27 +"&Q28=" + Q28;
    window.location = "showdoc.aspx?" + s.toString();
}

//Navigation

$(document).ready(function()
{
    //Initialize main nav
    $(".navigation ul li").hover(
        function()
        {
            $(".dropdown").hide();

            var el = $(".dropdown", this);

            el.show();

            el.data("active", true);
        },

        function()
        {
            var el = $(".dropdown", this);

            el.data("active", false);

            setTimeout(function()
            {
                if (!el.data("active"))
                {
                    el.hide();
                }
            }, 500);
        }
    );

    //Initialize sub nav
    $(".subnavigation ul li a").hover(
        function()
        {
            $(this).addClass("hover");
        },

        function()
        {
            $(this).removeClass("hover");
        }
    );
               
});

function trackLink() {
    if (arguments.length < 3) {
        alert("Error: Not enough arguments to TrackLink()");
        return false;
    }

    var linkTest = arguments[0];

    var link;

    if (linkTest.href == undefined) {
        link = document.createElement('a');
        link.href = linkTest;
        document.body.appendChild(link);
    }

    else {
        link = linkTest;
    }

    var name = arguments[1];

    var linkType = arguments[2];

    var options;

    if (arguments.length > 3) {
        options = arguments[3];
    }

    var linkTrackVars = 'channel'; //override to always track the channel
    var linkTrackEvents = '';

    var suppressTracking = false;

    if (options != undefined) {

        if (options.props != undefined) {
            for (var i in options.props) {
                var prop = options.props[i];

                if (linkTrackVars.length > 0) {
                    linkTrackVars += ",";
                }

                linkTrackVars += prop.name;

                s[prop.name] = prop.value;
            }
        }

        if (options.event != undefined) {
            if (linkTrackVars.length > 0) {
                linkTrackVars += ",";
            }

            linkTrackVars += "events";

            linkTrackEvents += options.event;

            s.events = options.event;
        }

        if (options.evars != undefined) {
            for (var i in options.evars) {
                var evar = options.evars[i];

                if (linkTrackVars.length > 0) {
                    linkTrackVars += ",";
                }

                linkTrackVars += evar.name;

                s[evar.name] = evar.value;
            }
        }

        if (options.supress != undefined) {
            suppressTracking = options.supress;
        }
    }

    s.linkTrackVars = linkTrackVars;
    s.linkTrackEvents = linkTrackEvents;

    if (!suppressTracking) {
        s.tl(link, linkType, name);
    }

    return false;
}

function trackPage()
{
    if (arguments.length < 1)
    {
        alert("Error: Not enough arguments to trackPage()");
        return;
    }

    s.pageName = arguments[0];

    var options;
    
    if (arguments.length > 1)
    {
        options = arguments[1];
    }

    var linkTrackVars = 'channel'; //override to always track the channel
    var linkTrackEvents = '';

    var suppressTracking = false;

    if (options != undefined)
    {
        if (options.prop != undefined)
        {
            if (linkTrackVars.length > 0)
            {
                linkTrackVars += ",";
            }

            linkTrackVars += options.prop;

            s[options.prop] = options.prop;
        }

        if (options.event != undefined)
        {
            if (linkTrackVars.length > 0)
            {
                linkTrackVars += ",";
            }

            linkTrackVars += "events";

            linkTrackEvents += options.event;

            s.events = options.event;
        }
        
        if (options.evar != undefined)
        {
            if (linkTrackVars.length > 0)
            {
                linkTrackVars += ",";
            }
            
            linkTrackVars += options.evar.name;
            
            s[options.evar.name] = options.evar.value;
        }

        if (options.supress != undefined)
        {
            suppressTracking = options.supress;
        }
    }

    s.linkTrackVars = linkTrackVars;
    s.linkTrackEvents = linkTrackEvents;

    if (!suppressTracking)
    {
        s.t();
    }
}

function closePopup() {
    $(".jqmWindow").jqmHide();
}