function acceptChat( id )
{
    $( 'chatDiv' ).hide();

    window.open( '/sglivechat/f.php/chat/acceptInvite?id=' + id ,'chat_' + id, 'width=680,height=520,location=0,toolbar=0,resizable=1');    
}

function rejectChat( id )
{
    $( 'chatDiv' ).remove();
    
    new Ajax.Request('/sglivechat/f.php/chat/rejectInvite', {asynchronous:true, evalScripts:false, parameters:'id=' + id});
}

function scrollInvite()
{
    if ( $('chatDiv') ) $('chatDiv').setStyle({ top: 8 + document.viewport.getScrollOffsets().top + 'px' });
}


function openInvite()
{
        $('chatDiv').show();
        scrollInvite();
}

if ( typeof( skipChat ) == "undefined" )
{
    document.write( '<div id="chatDiv" style="position: absolute; left: 100px;border: 2px solid #666; border-top: 0; background: url(/sglivechat/images/header_bgr.jpg) repeat-x top;background-color: #fff; width: 330px;"></div>' );
    
    Event.observe(document, "dom:loaded", function() {
       $('chatDiv').hide();
       
       Event.observe(window,'scroll', function(evt){
                scrollInvite();
            });
       
    });
}

function getTimeZone()
{
    var dt = new Date();   
    return (dt.getTimezoneOffset()/60)*(-1);
}
function processResponse(ajax)
{
  json = ajax.responseJSON;
  
 // if ( true || json ) Alert( json );
}
new Ajax.Request('/sglivechat/f.php/tracker/update', {asynchronous:true, evalScripts:false, parameters:'lt=' + escape(new Date()) + '&tz='+getTimeZone()+'&r='+encodeURIComponent( document.referrer ) });
var sglcu = new PeriodicalExecuter(function() {new Ajax.Request('/sglivechat/f.php/tracker/update', {asynchronous:true, evalScripts:false, method:'get', onComplete:function(request, json){processResponse(ajax)}, parameters:'lt=' + escape(new Date())  });}, 5);
var sglcs = new PeriodicalExecuter(function() { sglcu.stop(); sglcs.stop(); }, 7200);


