var order = '0';

/*function afficheTabJeuHome()
{
    with (atsm = new tabStripMenu("mytabs",600,300))	   			 	
        {
            resp = file('catalog-action.php?check=1&offset=0&limit=5'+(order?'&order='+order:''));
          //  resp2 = file('verif.php?check=9&offset=0&limit=5');
            resp2 = file('catalog-action.php?check=2');
            resp3 = file('catalog-action.php?check=4&home=1');
            
            addTab('more recent', resp);
            addTab('best ranked', resp2);
            addTab('most played', resp3);
            build(0);
        }
}
*/
function afficheTabJeuCatalog()
{
    if (order == 0)
        check = 3;
    else if (order == 1)
        check = 2;
    else if (order == 2)
        check = 4;
    
    with (atsm = new tabStripMenu("mytabs",600,300))
    {
        tablehead = '<table width="100%" height="100" border="2" rules="none"><tr><td height="5%" align="right" style="border-bottom: 1px solid;">order by:&nbsp;<a href="?order=0">date</a>&nbsp;|&nbsp;<a href="?order=1">rank</a>&nbsp;|&nbsp;<a href="?order=2">plays</a></td></tr><tr><td height="95%" valign="top">';
        tablefoot = '</td></tr></table>';
        addTab('all',tablehead+file('catalog-action.php?check='+check+(order?'&order='+order:''))+tablefoot);
        addTab('action',tablehead+file('catalog-action.php?check='+check+'&cat=1'+(order?'&order='+order:''))+tablefoot);
        addTab('adventure',tablehead+file('catalog-action.php?check='+check+'&cat=2'+(order?'&order='+order:''))+tablefoot);
        addTab('discovery',tablehead+file('catalog-action.php?check='+check+'&cat=3'+(order?'&order='+order:''))+tablefoot);
        addTab('sport',tablehead+file('catalog-action.php?check='+check+'&cat=4'+(order?'&order='+order:''))+tablefoot);
        addTab('simulation',tablehead+file('catalog-action.php?check='+check+'&cat=5'+(order?'&order='+order:''))+tablefoot);
        addTab('strategy',tablehead+file('catalog-action.php?check='+check+'&cat=6'+(order?'&order='+order:''))+tablefoot);
        addTab('puzzle',tablehead+file('catalog-action.php?check='+check+'&cat=7'+(order?'&order='+order:''))+tablefoot);
        addTab('more',tablehead+file('catalog-action.php?check='+check+'&cat=8'+(order?'&order='+order:''))+tablefoot);
        
        build(0);
        
    }
}

function setOrder (string)
{
    if (order != '') {
        window.location.search = window.location.search.replace('order='+order,'order='+string);
    } else {
        if (window.location.search != '') {
            window.location.search += '&order='+string;
        } else {
            window.location.search += '?order='+string;
        }
    }
}

function beginModifyGame(id)
{
    window.location.href = 'editgame.php?game='+encodeURIComponent(id);
}

function changeGameState(id)
{
    resp = file('manage-game.php?manage=2&gid='+encodeURIComponent(id));
    if (resp == -3)
    {
        file('manage-game.php?manage=3&gid='+encodeURIComponent(id)+'&st=1');
        document.getElementById('changestate'+id).innerHTML = 'remove';
        document.getElementById('state'+id).style.color = 'green';
        document.getElementById('state'+id).innerHTML = 'Online';
    }
    else if (resp == 1)
    {
        file('manage-game.php?manage=3&gid='+encodeURIComponent(id)+'&st=-3');
        document.getElementById('changestate'+id).innerHTML = 'publish';
        document.getElementById('state'+id).style.color = 'red';
        document.getElementById('state'+id).innerHTML = 'plays this month';
    }
    else 
    {
        document.getElementById('box'+id).style.display = '';
        document.getElementById('msg'+id).innerHTML = 'Error: cannot remove a game that has not been moderated or that is denied by moderation';
    }
}

function removeGame(id,title)
{
    if (window.confirm('Are you sure you want to remove game: '+title))    
    {
        file('manage-game.php?manage=3&gid='+encodeURIComponent(id)+'&st=-3');
        document.getElementById('game'+id).style.display = 'none';
        return true;
    }
    else 
    {
        return false;
    }
}
/*
function headSwitch(i)
{
    document.getElementById('tabselected').innerHTML = document.getElementById('mytab'+i).innerHTML;
}*/

function getMyGames()
{
    document.getElementById('mygames').innerHTML = file('manage-game.php?manage=1');
}

function getMyFavs()
{
    document.getElementById('mygames').innerHTML = file('manage-game.php?manage=4');
    createTable();
}

function removeFav(uid,gid)
{
    resp = file('game-action.php?check=3&gid='+encodeURIComponent(gid)+'&uid='+encodeURIComponent(uid));
    if (resp == 1)
        document.getElementById('mygames_'+gid).style.display = 'none';

}

function createTable()
{
    Sortable.create("mygames",{dropOnEmpty:true,containment:["mygames"],constraint:["vertical"],onUpdate:orderList});
    
}
function orderList()
{
    var serial = Sortable.serialize('mygames');
    file('game-action.php?check=6&'+serial);
}

function moveTop(gameId)
{
   file('game-action.php?check=7&gid='+gameId);
   location.href = 'manage-favourite.php';
}

function moveBottom(gameId)
{
    resp = file('game-action.php?check=8&gid='+gameId);
    location.href = 'manage-favourite.php';
}

function showArchive(newsId, totalnews)
{
    document.getElementById('n0').style.display = 'none';
    for (var i = 1; i <= totalnews; i++)
    {
        document.getElementById('n'+i).style.display = 'none';
    }
    document.getElementById('n'+newsId).style.display = '';
}