function swapImages(obj, url)
{
    obj.src = url;
}

function SetObjectTransparency(obj, value)
{
    if (!obj || !value)
        return false;

    value = parseInt(value);

    obj.style.opacity = parseFloat(value / 100);
    obj.style.filter = 'alpha(opacity=' + value + ');';

    return true;
}

function ToggleResolutionPane(obj, show)
{
    if (!obj)
        return false;

    if (!show)
        show = false;

    var target = document.getElementById(obj.id + '_cp');
    if (!target)
        return false;

    SetObjectTransparency(target, 80);

    target.style.display = (show) ? 'block' : 'none';

    return true;
}

function ToggleMovie(url)
{
    if(!url)
        return false;

    var player = document.getElementById('player');
    if (!player)
        return false;

    sourceHTML = '<object type="application/x-shockwave-flash" data="/template/default/flashes/videoplayer.swf" width="458" height="344" style="height: 344px;">';
    sourceHTML += '<param name="scale" value="200%" /><param name="allowFullScreen" value="true" />';
    sourceHTML += '<param name="movie" value="/template/default/flashes/videoplayer.swf" /><param name="quality" value="high" />';
    sourceHTML += '<param name="FlashVars" value="&src=http://diablo3bg.com' + url + '&autoStart=true" /></object>';

    player.style.display = 'block';
    player.innerHTML = sourceHTML;

    return false;
}

function ToggleHint(obj, defvalue, focusing)
{
    if (!obj || typeof(obj.value) == 'undefined' || !defvalue)
        return false;

    if (!focusing)
        focusing = false;

    if (focusing && obj.value == defvalue)
        obj.value = '';
    else if(!focusing && obj.value == '')
    obj.value = defvalue;

    return true;
}

function ShowMap(show)
{
    var world = document.getElementById('world');
    var map = document.getElementById('map');
    if (!world || !map)
        return;

    if (!show)
    {
        map.style.display = 'none';
        return;
    }

    map.style.position = "absolute";
    map.style.zIndex = 5;
    map.style.width = 200 + 'px';
    map.style.height = 200 + 'px';

    map.style.left = (world.offsetLeft + (world.offsetWidth / 2 - parseInt(map.style.width) / 2)) + 'px';
    map.style.top = ((world.offsetTop + (world.offsetHeight / 2 - parseInt(map.style.height) / 2)) - 48) + 'px';
    map.style.display = 'block';

    return;
}

function ReturnOnEnter(e, btn)
{
    if (parseInt(e.keyCode) == 13)
        btn.click();
}

function limitTextarea(obj, maxlength)
{
    var hCounter = document.getElementById('shout_counter');
    
    if (!obj || !hCounter)
        return;
    
    if (!maxlength)
        maxlength = 255;

    if (obj.value.length >= maxlength)
        obj.value = obj.value.substring(0, maxlength);

    hCounter.innerHTML = maxlength - obj.value.length;

    return;
}
