
/* 'FindControl' can be used to find element names in JavaScript, since .NET mangles the ID tag. */
function FindControl(ControlName, ReturnType)
{
    var theForm = document.forms[0];
    var iMax = theForm.elements.length;
    var ElementName = '';
    
    for (i=0; i<iMax; i++)
    {
        if (theForm.elements[i].name.indexOf(ControlName) > 0)
        {
            ElementName = theForm.elements[i].name;
            break;
        }
    }
    
    if (ReturnType == 'string')
    {
        return ElementName;
    } else {
        return eval('theForm.' + ElementName);
    }
}

function ActiveItem(NamePattern, ActiveDivIndex)
{
    var LoopInt = 1;
    
    do //first, clear all HTML elements matching the NamePattern.
    {
        if ( eval("document.getElementById('" + NamePattern + LoopInt + "')") )
            eval("document.getElementById('" + NamePattern + LoopInt + "').style.display = 'none'");
        LoopInt++;
    }
    while
        (eval("document.getElementById('" + NamePattern + LoopInt + "')") || (LoopInt<100));
    
    //Now, show the one specified by "ActiveDivIndex"
    eval("document.getElementById('" + NamePattern + ActiveDivIndex + "').style.display = 'inline'");
}

var LastNewsFeature = 'NewsFeature1';
var LastNewsImg = 'NewsTab1';

var DefaultItem = 1;
var TimerIdArray = new Array();
var TimerIdCount = 0;

function ShowDefaultSubNav()
{   //show the default subnav, in one second (sets a timer)
    TimerIdArray[TimerIdCount++] = self.setTimeout("ShowSubNav(DefaultItem)", 1000);
}

function ClearTimeOuts()
{   //because of the <a> tags in the subnav div's, there are multiple "onmouseout" events that fire, and 
    //therefore, multiple timers are set. This keeps track of the potentially multiple "showdefaultsubnav"
    //functions that are waiting to fire off.
    for (var i=0; i < TimerIdCount; i++)
    {
        clearTimeout(TimerIdArray[i]);
    }
}

function ShowSubNav(item)
{   
    if (document.getElementById)
    {
        //first, get rid of any pending "showdefaultsubnav" functions that may be waiting to fire off.
        ClearTimeOuts();
        //now, grab all the <li> tags that are in the twnav div
        var NavLIs = document.getElementById('twnav').getElementsByTagName('ul')[0].getElementsByTagName('li');
        //now, loop through them.
        for (var i=0; i<NavLIs.length; i++)
        {   //if this is the item that was actually moused over...
            if (i == (item - 1)) 
            {   //then give it the highlighted style, and show its subnav div.
                NavLIs[i].className = 'on'; 
                eval("document.getElementById('SubNav" + item + "').style.display = 'inline';");
            } else {
                //check to see if the "off" style is silver or not.
                if (NavLIs[i].dir != 'ltr')
                {
                    NavLIs[i].className = '';
                } else {
                    NavLIs[i].className = 'slvr';
                }
                //and hide the associated subnav
                eval("document.getElementById('SubNav" + (i+1) + "').style.display = 'none';");
            }
        }
    }
}


//ChangeToNewsFeature('NewsFeature1','NewsTab1')

function ChangeToNewsFeature(TargetObject, TargetNewsTab)
{
    if (document.getElementById)
    {
		//alert(LastNewsFeature);
        if ( (document.getElementById(TargetObject)) && (document.getElementById(LastNewsFeature)) )
        {
            //hide the previous
            document.getElementById(LastNewsFeature).style.display = 'none';
            changeImages(LastNewsImg,GetNewsFeatureImage(LastNewsFeature) + '_norm.gif');
            //show the one
            document.getElementById(TargetObject).style.display = 'inline';
            changeImages(TargetNewsTab,GetNewsFeatureImage(TargetObject) + '_on.gif');
            //update "last" variables
            LastNewsFeature = TargetObject
            LastNewsImg = TargetNewsTab
        }
    }
}

function GetNewsFeatureImage(theObject)
{
    switch(theObject)
    {
        case 'NewsFeature1': return '/images/topPgArticles/front-page';
        case 'NewsFeature2': return '/images/topPgArticles/local';
        case 'NewsFeature3': return '/images/topPgArticles/sports';
        case 'NewsFeature4': return '/images/topPgArticles/business';
        case 'NewsFeature5': return '/images/topPgArticles/spot';
        case 'NewsFeature6': return '/images/topPgArticles/scene';
    }
}

function changeImages()
{
    if (document.images)
    {
        for (var i=0; i<changeImages.arguments.length; i+=2) 
        {
            document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
        }
    }
}

function OpenWindow(url)
{
    var params;
    
    if (arguments.length > 1)
        params = arguments[1];
    else
        params = 'scrollbars=yes,resizable=yes,width=640,height=480'
    
    var win = window.open(url,'NewWin',params);
}

function BlankOutSearchBox(objSearchText, strTextToClear)
{
    if (objSearchText.value == strTextToClear)
    {
        objSearchText.value = '';
    }
}

function ShowHide(item)
{
    //if the browser supports this...
    if (document.getElementById)
    {
        //if the user specifically passed in a state to use for the item in question (inline, none)
        if (arguments.length > 1)
        {
            document.getElementById(item).style.display = arguments[1];
        } else {
            //otherwise, we want to take the current state of this item, and flip it.
            if (document.getElementById(item).style.display == 'none')
            {
                document.getElementById(item).style.display = 'inline';
            } else {
                document.getElementById(item).style.display = 'none';
            }
        }
    }
}

function ChangeBGColor(item, itemColor)
{
    //if the browser supports this...
    if (document.getElementById)
    {
        document.getElementById(item).style.backgroundColor = itemColor;
    }
}

// used by site header/footer, allows for pressing ENTER on search text box
function PressedEnter(e)
{
    if (e.keyCode == 13)
    {
        document.forms[0].submit();
    }
}
