﻿
/* '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);
    }
}


// can pass in image name and image to swap
// ie changeImages('mc', '/images/template/mostcommented.jpg')
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 ChangeBGColor(item, itemColor) {
    //if the browser supports this...
    if (document.getElementById) {
        document.getElementById(item).style.backgroundColor = itemColor;
    }
}


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 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 SetHomePage(obj) {
    //This script fails in anything but IE, so the "return false" never happens.
    // Therefore, homepage is set automagically in IE, and others get manual instructions.
    obj.style.behavior = 'url(#default#homepage)';
    obj.setHomePage('http://www.tulsaworld.com');
    return false;
}
