function doTopicNav( selectElt )
{
    val = selectElt.options[ selectElt.selectedIndex ].value;
    window.location.href = '/content/topics/detail/'+val+'/';
}

function doAudienceNav( selectElt )
{
    val = selectElt.options[ selectElt.selectedIndex ].value;
    window.location.href = '/section/audience/'+val+'/';
}

function goTo( selectElt )
{
    val = selectElt.options[ selectElt.selectedIndex ].value;
    if (val == "") 
    {
        return false;
    }
    else
    {
        window.location.href = val;
        return true;
    }
}

function showHide(eltId)
{
    if (eltId)
    {
        $("span#" + eltId).toggle();
    }
    else
    {
        $("span").toggle();
    }
}

function setSelected( selectElt, valueToMatch )
{
    opts = selectElt.options;
    size = opts.length;
    for(i = 0; i < size; i++)
    {
        if (opts[i].value == valueToMatch)
        {
            selectElt.selectedIndex = i;
            return true;
        }
    }
    return false;
}

function checkSearch()
{
    return isEmptyField( 'siteSearch', 'search_query', 'Please enter the text to use in search.' );  
}

function isEmptyField( formname, fieldname, errormsg )
{    
    if ( document.forms[ formname ].elements[fieldname].value == "" )
    {
        alert( errormsg  );
        return false;
    }
    else 
    {
        return true;
    }
}

function validateEmail(formName, inputName)
{
    var input = document.forms[formName].elements[inputName];
    var emailRe = /^[a-z0-9_\-~\.]+@[a-z0-9_\-~\.]+\.[a-z]{2,4}$/i;
    if(emailRe.test(input.value))
    {
        return true;
    }
    else
    {
        alert('Please enter a valid email address.');
        return false;
    }
}

function newWindow(url, title, height, width)
{
    if (!height)
    {
        height = 640;
    }
    
    if (!width)
    {
        width = 480;
    }
    
    window.open(url, title, 'width=' + width + ',height=' + height + ',toolbar=0,statusbar=0,menubar=0');
}
