﻿function loadAnalysis(iType, iEdition, sContainer) 
{
	document.getElementById('mostPopLink').className="missOff";
	document.getElementById('mostRecent').className="missOff";
	if ( document.getElementById('espanolLink'))
		document.getElementById('espanolLink').className="missOff";

	switch(iType)
	{
		case 0:   
			document.getElementById('mostRecent').className="missOn";
			break;
		case 1:   
			document.getElementById('mostPopLink').className="missOn";
			break;
		case 2:
			document.getElementById('espanolLink').className="missOn";
			break;
		default:
			document.getElementById('mostRecent').className="missOn";
	}

	getContent(iType, iEdition, sContainer);
}
function openViewer(cid)
{
	var strURL = "/dismal/pro/multimedia/captivate.asp?cid=" + cid
	var strFeatures = "width=675,height=540,top=150,left=150,scrollbars";
	var newWindow = window.open(strURL, "Presentation",strFeatures );
	newWindow.focus();

}
function setTextSize( size )
{
    document.body.style.fontSize = size + "pt";
}
function changeGraph( dir, type )
{
    var cur, all, show;
    switch( type )
    {
        case "recession_graphs":
            all = $(".recession_graphs");
            cur = $(".recession_graphs:visible");
            break;
        case "top_charts":
            all = $(".top_charts");
            cur = $(".top_charts:visible");
    }
    switch( dir )
    {
        case "up":
            if( $(cur).next().is("*") == true )
                show = $(cur).next();
            else
                show = $(all)[0];
            break;
        case "down":
            if( $(cur).prev().is("*") == true )
                show = $(cur).prev();
            else
                show = $(all)[($(all).length) - 1];
            break;
    }
    $(cur).hide();
    $(show).show();
}
function goScroll( div, dir )
{
    var theDiv = null, upArrow = null, downArrow = null, upArrow2 = null, downArrow2 = null;
    var upEnabled = "/dismal/images/interface/up-enabled.gif";
    var downEnabled = "/dismal/images/interface/down-enabled.gif";
    var upDisabled = "/dismal/images/interface/up-disabled.gif";
    var downDisabled = "/dismal/images/interface/down-disabled.gif";
    var upString = "", downString = "";
    switch( div )
    {
        case "indicators":
            theDiv = $("#indicators");
            upArrow = $("#indicatorScroll").children().not(".down");
            upArrow2 = $("#indicatorScrollUpper").children().not(".down");
            downArrow = $("#indicatorScroll").children().not(".up");
            downArrow2 = $("#indicatorScrollUpper").children().not(".up");
            break;
        case "blogs":
            theDiv = $("#blogs");
            upArrow = $("#blogScroll").children().not(".down");
            downArrow = $("#blogScroll").children().not(".up");
            break;
    }
    var scrollSpeed = 700;
    var elem = document.getElementById( div );
    var curTop = elem.scrollTop;
    //var scrollSize = elem.offsetHeight - 10;
    var scrollSize = 250;
    var newTop = 0;
    
    //Do the scroll
    switch( dir )
    {
        case "up":
            if( curTop == 0 )
                return;
            newTop = curTop - scrollSize;
            //$(theDiv).animate({scrollTop: curTop - scrollSize}, scrollSpeed);
            break;
        case "down":
            if( elem.scrollHeight - curTop - elem.offsetHeight <= 0 )
                return;
            newTop = curTop + scrollSize;
            //$(theDiv).animate({scrollTop: curTop + scrollSize}, scrollSpeed);
            break;
    }
    $(theDiv).animate({scrollTop: newTop}, scrollSpeed);
    
    //update arrow imgs
    if( newTop <= 0 )
    {
        upString = upDisabled;
        downString = downEnabled;
    }
    else if( elem.scrollHeight - newTop - elem.offsetHeight <= 0 )
    {
        upString = upEnabled;
        downString = downDisabled;
    }
    else
    {
        upString = upEnabled;
        downString = downEnabled;
    }
    $(upArrow).attr( "src", upString );
    if( upArrow2 != null )
        $(upArrow2).attr( "src", upString );
    $(downArrow).attr( "src", downString );
    if( downArrow2 != null )
        $(downArrow2).attr( "src", downString );
}
function checkIndicatorHeight( )
{
    var ind = $("#indicators");
    var indScroll = $("#indicatorScroll");
    var indScrollUpper = $("#indicatorScrollUpper");
    var todaysEconomyContainer = $("#todaysEconomyContainer");
    var containerStartHeight = 0;
    var indStartHeight = ind.height();
    var indStretchHeight = 0;
    var indScrollHeight = 0;
    var tempHeight = 0;
    
    $(indScroll).hide();
    $(indScrollUpper).hide();
    
    //start at a dummy height
    $(ind).height( 400 );
    
    //get container height (this will be set based on height of blog column
    containerStartHeight = $(todaysEconomyContainer).height();
    tempHeight = containerStartHeight;
    
    //get the overall height of the indicators
    indScrollHeight = ind[0].scrollHeight;
        
    //increase height of indicators until whole container grows in size
    while( tempHeight == containerStartHeight )
    {
        $(ind).height( $(ind).height() + 50 );
        tempHeight = $(todaysEconomyContainer).height();
    }
    indStretchHeight = $(ind).height() - $(indScroll).height() - $(indScrollUpper).height() - (tempHeight - containerStartHeight);
    
    if( indScrollHeight > indStretchHeight )
    {
        $("#indicatorScroll").show();
        $("#indicatorScrollUpper").show();
    } 
    else 
    {
        $("#indicatorScroll").hide();
        $("#indicatorScrollUpper").hide();
    }
    $(ind).height(Math.min(indStartHeight, indStretchHeight));
}
function checkIndicatorHeight_old( )
{
    $("#indicatorScroll").hide();
    $("#indicatorScrollUpper").hide();
    //return;
    //var wh = window.innerHeight || document.documentElement.clientHeight;
    //var iMaxHeight = wh * 0.4; // 40% of screen height
    var iMaxHeight = 900;
    var ind = $("#indicators");
    var indHeight = ind.height();
    var scrHeight = ind[0].scrollHeight;
    if( scrHeight > iMaxHeight )
    {
        $("#indicatorScroll").show();
        $("#indicatorScrollUpper").show();
    } 
    else 
    {
        $("#indicatorScroll").hide();
        $("#indicatorScrollUpper").hide();
    }
    ind.height(Math.min(iMaxHeight, indHeight));
}
function checkBlogHeight( )
{
    $("#blogScroll").hide();
    //return;
    //var wh = window.innerHeight || document.documentElement.clientHeight;
    //var iMaxHeight = wh * 0.4; // 40% of screen height
    var iMaxHeight = 895;
    var blog = $("#blogs");
    var blogHeight = blog.height();
    var scrHeight = blog[0].scrollHeight;
    if( scrHeight > iMaxHeight ){
        $("#blogScroll").show();
    } else {
        $("#blogScroll").hide();
    }
    blog.height(Math.min(iMaxHeight, blogHeight));
}
function goOver( o )
{
    if( typeof( $(o).attr( "class" ) ) != "undefined" )
    {
        $(o).css( "text-decoration", "underline" );
    }
}
function goOut( o )
{
    if( typeof( $(o).attr( "class" ) ) != "undefined" )
    {
        $(o).css( "text-decoration", "none" );
    }
}
function toggleWatch( )
{
    var temp = $(".naTab");
    if( $(temp).is( ".smallTab1" ) == true )
        toggleView( 1 );
    else
        toggleView( 2 );
    setTimeout( toggleWatch, 15000 );
}
function toggleView( val )
{
    if( val == 2 )
    {
        $(".smallTab1").addClass("naTab");
        $("#smallTabDiv1").hide();
        $(".smallTab2").removeClass("naTab").css( "text-decoration", "none" );
        $("#smallTabDiv2").show();
    }
    else
    {
        $(".smallTab2").addClass("naTab");
        $("#smallTabDiv2").hide();
        $(".smallTab1").removeClass("naTab").css( "text-decoration", "none" );
        $("#smallTabDiv1").show();
    }
}
function toggleEditorReaderTab( which )
{
    switch( which )
    {
        case 0:
            //hide tab1, show tab0
            $("#dsEditorReaderTab1").addClass("inactiveTab");
            $("#dsEditorReaderTab0").removeClass("inactiveTab").css( "text-decoration", "none" );
            $("#dsEditorReaderDiv1:visible").hide();
            $("#dsEditorReaderDiv0:hidden").show();
            break;
        case 1:
            //hide tab0, show tab1
            $("#dsEditorReaderTab0").addClass("inactiveTab");
            $("#dsEditorReaderTab1").removeClass("inactiveTab").css( "text-decoration", "none" );
            $("#dsEditorReaderDiv0:visible").hide();
            $("#dsEditorReaderDiv1:hidden").show();
            break;
    }
}
function setEditorReaderTabHeight( )
{
    var div0, div1, h0, h1, newHeight;
    
    //get divs
    div0 = $("#dsEditorReaderDiv0");
    div1 = $("#dsEditorReaderDiv1");
    
    //get heights
    h0 = $(div0).height();
    h1 = $(div1).height();
    
    //switch tab (causes heights to change)
    $(div0).toggle();
    $(div1).toggle();
    
    //get larger height
    h0 = Math.max( $(div0).height(), h0 );
    h1 = Math.max( $(div1).height(), h1 );
    
    //switch tabs back
    $(div0).toggle();
    $(div1).toggle();
    
    //get larger height, set heights of both
    newHeight = Math.max( h0, h1 );
    //Commented out 3/11/09
    //$(div0).height( newHeight );
    //$(div1).height( newHeight );
}
function goChart( sMnemonic ) 
{
	//var sArg = document.frmMain.target.value + "?" + document.frmMain.querystring.value;
	var sArg = "/freelunch/default.asp?";
	window.open( "/freelunch/protected/fl_check_reg.asp?sURL=" + adv_escape(sArg) + "&type=chart&m=" + adv_escape(sMnemonic), "Free Lunch" );
	//location.href="/freelunch/protected/fl_check_reg.asp?sURL=" + adv_escape(sArg) + "&type=chart&m=" + adv_escape(sMnemonic);
}
function adv_escape( strUrl ) 
{
	var sRet = escape(strUrl);
	sRet = sRet.replace(/\+/g,"%2b");
	sRet = sRet.replace(/\-/g, "%2d");
	sRet = sRet.replace(/\*/g, "%2a");
	sRet = sRet.replace(/\//g, "%2f");
	return sRet;
}
