/** Chat */
function getChatPopupSize()
{
    var h = window.screen.availHeight;
    var w = window.screen.availWidth;
    return w + "x" + h;
}

// Tailles possibles du popup de Chat
appletSizes = new Array();
appletSizes[0] = '752x615';
appletSizes[1] = '950x740';
appletSizes[2] = getChatPopupSize();

// Par défaut, taille adaptée
appletSize = appletSizes[2];

function popChat(channel, pseudo)
{
    if (!pseudo) pseudo = '';

    var time = new Date();
    var chatPopupPath = www_path+'chat/chat20080110/popup.php';
    var url = chatPopupPath+'?ts='+time.getTime();

    if (channel)
    {
      url += '&chan='+channel;
    }
    if (pseudo)
    {
      url += '&query='+pseudo;
    }
    if (typeof firstroom != 'undefined')
    {
        url += '&firstroom='+firstroom;
    }

    var size = appletSize.split('x');
    var wnd = window.open('','skyChatWindow', 'resizable=yes,location=no,height='+size[1]+',width='+size[0]+', menubar=no,status=no,scrollbars=no,menubar=no');

    /* WebKit fait trop bien son boulot, il ouvre le popup plus grand que la taille
     * qu'il peut vraiment occuper. Donc si on est en taille adaptée, on ajuste à
     * l'aide du resizeTo (credit: worf) */
    try {
        if (navigator.appVersion.indexOf('WebKit') != -1 && size[1] == window.screen.availHeight)
        {
            wnd.resizeTo(wnd.screen.availWidth, wnd.screen.availHeight);
        }
    } catch (e) {
        // Tant pis.
    }

    try {
        var handle = wnd.document.getElementById('skyrockChat');
    } catch (e) {
        var handle = false;
    }

    if (!handle)
    {
        wnd.location = url;
        wnd.focus();
        return true;
    }
    else
    {
        // Chat déjà ouvert, on passe les infos qu'on a précisé
        wnd.document.getElementById('skyrockChat').openTab(pseudo, unescape(channel));
        wnd.focus();
        return false;
    }
}
