function sendEmail( element )
{
    var spans = element.getElementsByTagName( 'span' )
    var address = false;

    for ( var i = 0; i < spans.length; i++ )
    {
        if ( spans[i].className == 'address' )
        {
            address = spans[i].innerHTML;
            break;
        }
    }

    if ( address )
    {
        address = 'mailto:' + address.replace( /<span class="?dot"?>[^<]*<\/span>/ig, '.' ).replace( /<span class="?at"?>[^<]*<\/span>/i, '@' );
        element.href = address;
        location.href = address;
    }

    return false;
}

function setCookie( name, value, expiresInDays )
{
    var expireDate = false;

    if ( expiresInDays )
    {
        expireDate = new Date();
        expireDate.setTime( expireDate.getTime() + ( expiresInDays * 24 * 3600 * 1000 ) );
    }

    document.cookie = name + "=" + escape( value )
        + ( ( expireDate )? "; expires=" + expireDate.toGMTString(): "" )
        + "; path=/";
}
                                    
function getCookie( name )
{
    var dc = document.cookie;
    var begin = dc.indexOf( name + "=" ); 
    if ( begin != -1 )
    {
        begin += name.length + 1; 
        var end = dc.indexOf( ";", begin );
        if ( end == -1 )
        {
            end = dc.length;
        }
        return unescape( dc.substring( begin, end ) );
    }
    return false;
}

function decreaseFontSize()
{
    var el = document.getElementById( 'content' );

    fontSize = el.style.fontSize;
    if ( !fontSize )
    {
        fontSize = 1;
    }
    else
    {
        fontSize = parseFloat( fontSize );
    }
    
    fontSize -= 0.1;
    
    if ( fontSize < 0.55 )
    {
        fontSize = 0.55;
    }
    
    el.style.fontSize = fontSize + 'em';
    setCookie( 'eaFS', fontSize, 3652 );

    fixFooterElement();
    return false;
}

function increaseFontSize()
{
    var el = document.getElementById( 'content' );

    fontSize = el.style.fontSize;
    if ( !fontSize )
    {
        fontSize = 1;
    }
    else
    {
        fontSize = parseFloat( fontSize );
    }
    
    fontSize += 0.1;
    
    if ( fontSize > 1.35 )
    {
        fontSize = 1.35;
    }

    el.style.fontSize = fontSize + 'em';
    setCookie( 'eaFS', fontSize, 3652 );

    fixFooterElement();
    return false;
}

function normalFontSize()
{
    var el = document.getElementById( 'content' );

    el.style.fontSize = '1em';
    setCookie( 'eaFS', '1', 3652 );

    fixFooterElement();
    return false;
}

function openNewWin( url, winName, width, height )
{
    var sx = screen.width / 2 - width / 2;
    var sy = screen.height / 2 - height / 2;
    var win = window.open( url, winName, 'width=' + width + ',height=' + height + ',location=0,menu=0,scrollbars=0,status=0,titlebar=0,title=0,toolbar=0,screenx='
        + sx +',left=' + sx + ',screeny=' + sy + ',top=' + sy );
    return ( win )? false: true;
}

function fixInnerSize( ww, wh )
{
    var iw;
    var ih;

    for ( var i = 0; i < 2; i++ ) // to fix a bug in Opera if the window is resized manually, sized are not updated
    {    
        if ( window.innerWidth )
        {
            iw = window.innerWidth;
            ih = window.innerHeight;
        }
        else if ( document.documentElement && document.documentElement.clientHeight )
        {
            iw = document.documentElement.clientWidth;
            ih = document.documentElement.clientHeight;
        }
        else
        {
            iw = document.body.clientWidth;
            ih = document.body.clientHeight;
        }
        if ( iw > 0 || ih > 0 )
        {
            window.resizeBy( ww - iw, wh - ih );
        }
    }
    window.focus();
}

function addDirAndFollow( aElement )
{
    if ( filterType )
    {
        location.href = aElement.href + '?filter=' + filterType;
        return false;
    }

    return true;
}

function fixFooterElement()
{
    var bodyElement = document.getElementById( 'body' );
    if ( bodyElement.offsetHeight < ( ( window.innerHeight )? window.innerHeight: bodyElement.clientHeight ) )
    {
        bodyElement.style.position = 'static';
    }
}

function init()
{
    fixFooterElement();
}

window.onload = init;
window.onresize = fixFooterElement;
