//-----------------------------------------------------
//-----------------------------------------------------
function comboHideAll()
{
    if (!document.all)
        return;

    var comboArr = document.body.getElementsByTagName('SELECT');
    if (!comboArr)
        return;
    for (var i=0; i<comboArr.length; i++)
    {
        comboArr[i].style.visibility = 'hidden';
    }
}
function comboShowAll()
{
    if (!document.all)
        return;

    var comboArr = document.body.getElementsByTagName('SELECT');
    if (!comboArr)
        return;
    for (var i=0; i<comboArr.length; i++)
    {
        comboArr[i].style.visibility = 'visible';
    }
}
//-----------------------------------------------------
//-----------------------------------------------------
function flashHideAll()
{
    var objectsArr = document.body.getElementsByTagName('OBJECT');
    if (!objectsArr)
        return;
    for (var i=0; i<objectsArr.length; i++)
    {
        objectsArr[i].style.visibility = 'hidden';
    }
}
function flashShowAll()
{
    var objectsArr = document.body.getElementsByTagName('OBJECT');
    if (!objectsArr)
        return;
    for (var i=0; i<objectsArr.length; i++)
    {
        objectsArr[i].style.visibility = 'visible';
    }
}
    
//-----------------------------------------------------
//-----------------------------------------------------
function grayoutEnable()
{
    var divDisableAll = document.getElementById('divDisableAll');
    if (!divDisableAll)
        return;
    
    var w = document.body.scrollWidth;
    var h = document.body.scrollHeight;
    if (w < document.body.clientWidth)
        w = document.body.clientWidth;
    if (h < document.body.clientHeight)
        h = document.body.clientHeight;
    
    divDisableAll.style.left    = '0px';
    divDisableAll.style.top     = '0px';
    divDisableAll.style.width   = w.toString()+'px';
    divDisableAll.style.height  = h.toString()+'px';
    divDisableAll.style.zIndex  = 40000;
    divDisableAll.style.display = 'block';

    comboHideAll();
    flashHideAll();
}
function grayoutDisable()
{
    var divDisableAll = document.getElementById('divDisableAll');
    if (!divDisableAll)
        return;

    divDisableAll.style.zIndex  = -1000;
    divDisableAll.style.display = 'none';

    comboShowAll();
    flashShowAll();
}
//-----------------------------
// display announcement
//-----------------------------
var announcementWasDisplayed = 0;

function showAnnouncement()
{
    if (announcementWasDisplayed)
        return;

    var tabAnnouncement = document.getElementById('tabAnnouncement');
    if (!tabAnnouncement)
        return;

    if (tabAnnouncement.style.visibility != 'visible')
    {
        grayoutEnable();
        tabAnnouncement.style.visibility = 'visible';
    }

    tabAnnouncement.style.left = ((document.body.clientWidth  - tabAnnouncement.offsetWidth ) / 2).toString() + 'px';
    tabAnnouncement.style.top  = (document.body.scrollTop + (document.body.clientHeight  - tabAnnouncement.offsetHeight ) / 2).toString() + 'px';
}

function hideAnnouncement(anId, dontShowAgain)
{
    grayoutDisable();
    announcementWasDisplayed = 1;
    var tabAnnouncement = document.getElementById('tabAnnouncement');
    tabAnnouncement.style.visibility = 'hidden';
    
    // set cookie
    var now = new Date();
    var expDate = new Date(now.getTime() +  (dontShowAgain ? 1000 : 1) * 3600000);
    document.cookie = 'anHid'+anId+'=1;expires=' + expDate.toUTCString()+';path=/';
}
//-----------------------------
// position menu
//-----------------------------
function positionMenu()
{
    showAnnouncement();

    var outer = document.getElementById('outer');
    var footer = document.getElementById('footer');
    if (! (outer && footer) )
        return;
        
    var marginTop = document.body.clientHeight - (outer.offsetHeight + footer.offsetHeight + 1);
    if (marginTop < 0)
        marginTop = 0;

    footer.style.marginTop= marginTop.toString() + 'px';
}

//-----------------------------
// open lobby or solo game
//-----------------------------
function openLobby(lid,lang)
{
    window.open ('/lobby.php?lang='+lang+'&lid='+lid, 
                 'win_lobby_'+lid,
                 'dependent=no,toolbar=no,scrollbars=no,status=no,menubar=no,location=no,resizable=yes,width=950,height=685');
}

function openSolo(solo_id)
{
    window.open ('/solo.php?solo_id='+solo_id, 
                 '',
                 'dependent=no,toolbar=no,scrollbars=yes,status=no,menubar=no,location=no,resizable=no,width=950,height=685');
}

//-----------------------------
// main page tab handling
//-----------------------------
function mainTabOver (tabEl)
{
    if (tabEl.className != 'contentMenuBtnActive')
        tabEl.className='contentMenuBtn_hover';
}
function mainTabOut (tabEl)
{
    if (tabEl.className != 'contentMenuBtnActive')
        tabEl.className='contentMenuBtn';
}
function mainTabClick (tabEl)
{
    if (tabEl.className == 'contentMenuBtnActive')
        return;
    
    var divTabMultiGames = document.getElementById('divTabMultiGames');
    var divTabSoloGames  = document.getElementById('divTabSoloGames');
    var divMultiGames    = document.getElementById('divMultiGames');
    var divSoloGames     = document.getElementById('divSoloGames');
    var divOuter         = document.getElementById('outer');
    if (! (divTabMultiGames && divTabSoloGames && divMultiGames && divSoloGames && divOuter) )
        return;
    
    if (tabEl.id == 'divTabMultiGames')
    {
        divTabMultiGames.className  = 'contentMenuBtnActive';
        divTabSoloGames.className   = 'contentMenuBtn'; 
        divSoloGames.style.display  = 'none';   
        divMultiGames.style.display = 'block';   
    }
    else
    {
        divTabMultiGames.className  = 'contentMenuBtn';
        divTabSoloGames.className   = 'contentMenuBtnActive'; 
        divMultiGames.style.display = 'none';   
        divSoloGames.style.display  = 'block';   
    }                                
}                                              


//-----------------------------
// changing the page language
//-----------------------------
function pageLangChange (lang_id)
{
    var href     = document.location.href;
    var lang_ind = href.indexOf('lang=');
    if (lang_ind >= 0)
    {
        var amp_ind = href.indexOf('&',lang_ind);
        if (amp_ind>=0)
             href = href.substr(0,lang_ind) + 'lang=' + lang_id + href.substr(amp_ind);
        else href = href.substr(0,lang_ind) + 'lang=' + lang_id;
    }
    else
    {
        var quest_ind = href.indexOf('?');
        if (quest_ind>=0)
             href  = href.substr(0,quest_ind) + '?lang=' + lang_id + '&' + href.substr(quest_ind+1);
        else href += '?lang=' + lang_id;
    }
    document.location = href;
}


