
var LastTime = "";

function TimeStamp()
{
    var d = new Date();
    var curr_hour = d.getHours();
    var curr_min = d.getMinutes();
    if ( curr_min < 10 ) curr_min = "0" + curr_min
    
    return curr_hour + ":" + curr_min;
}

function Print( str, r, g, b, a )
{
    if ( LastTime != TimeStamp() )
    {
        LastTime = TimeStamp();
        $('#console').append( "<div class=\"TimeStamp\">" + LastTime + "</div>" );
    }
    var str = str.replace( /\</g, "&lt;" )
    var str = str.replace( /\>/g, "&gt;" )
    $('#console').append( "<span style='color: rgba( "+r+", "+g+", "+b+", "+(a/255)+" );'>" + str + "</span>" );
}

function Command( str )
{  
    var str = str.replace( /\</g, "&lt;" )
    var str = str.replace( /\>/g, "&gt;" )
    $('#console').append( "<div class='command');'>" + str + "</div>" );
}

function Clear()
{
    $('#console').html( "" )
}


function LuaError(realm, errstr) 
{
    // Get the last error
    var lasterr = $('.error:last')
    if ( lasterr.attr( "original" ) == errstr+realm )
    {
        var tab = lasterr.find('.tab');
        var str = tab.html()
        if ( str == "" ) str = "1";
        
        var iNum = parseInt( str ) + 1
        if ( iNum > 9999 ) iNum = 9999;
        
        tab.html( iNum )
        
        // Move to the bottom of the stack..
        lasterr.appendTo( $('#console') );
        
        tab.fadeTo( 100, 0.8 ).fadeTo( 50, 1.0 );
        return;
    }
 
    var original = errstr

    var line = errstr.match(/\[(.+)\]/gi);
    line = line[0].replace(/\\/gi, "/")
    line = line.replace(/@|\[|\]/gi, "")
    
    errstr = errstr.replace(/\[(.*?)\]/gi, '');

    errstr = errstr.replace(/\n/g, "<br>")
    errstr = errstr.replace(" ", "&nbsp;")

    var err = $("<div class='error error_"+realm+"'><div class='tab realm_" + realm + "'></div>" + errstr + "<div class=location>" + $.trim(line) + "</div><div class='stack realm_" + realm + "'><table></table></div></div>");
    err.attr( "original", original+realm );

    $(err).click(function(e) { $(e.srcElement).find('.stack').toggle() });
    $(err).find('.stack').hide()
    
    $('#console').append( err );


}

function AddStack(id, line, func, file) 
{
    if (file == "[C]") file = "C++"
    if ( func == "") func = "Unknown"

    if (line > 0) line = "Line " + line
    else line = ""
    
    // Don't add to the stack if we're repeating..
    {
        var str = $('.error:last .tab').html();
        if ( str != "" ) return;
    }
    
    var err = $('.error:last .stack TABLE')
    err.append( "<tr><td><b>"+func+"</b></td><td>"+file+"</td><td>"+line+"</td></tr>" )
}


$( function() 
{


setTimeout( function() { Print( "Montage du code HTML.. OK\n", 255, 255, 255, 255 ) } ,2000)
setTimeout( function() { Print( "Montage du Javascript.. OK\n", 255, 255, 255, 255 ) } ,2100)
setTimeout( function() { Print( "Montage des léttres.. OK\n", 255, 255, 255, 255 ) } ,2200)
setTimeout( function() { Print( "Montage des éffets inutile.. OK\n", 255, 255, 255, 255 ) } ,2300)
setTimeout( function() { Print( "Montage de l'espace temps.. Non OK\n", 255, 255, 255, 255 ) } ,2400)
setTimeout( function() { Print( "Montage de rien.. OK\n", 255, 255, 255, 255 ) } ,2500)
setTimeout( function() { Print( "Erreur fatal\n",255,0,0,255) } ,3000)
setTimeout( function() { Print( "Erreur fatal\n",255,0,0,255) } ,3050)
setTimeout( function() { Print( "Erreur fatal\n",255,0,0,255) } ,3100)

for (i=1; i<=42; i++){ 
    setTimeout( function() {LuaError("client", "[@lua\\dans\\un\\dossier\\inconnue:42] Une erreur qui t'aide pas (avec un type) (mais cette erreur est dangereuse)")} ,3100+i*50)

 } 
setTimeout( function() {LuaError("server", "[@lua\\dans\\un\\dossier\\inaccessible:42] Une erreur bleu")} ,5300)
setTimeout( function() { TimeStamp(); Command( "Communautés participantes\n") } ,5400)
 function CommuFunc(i){
       setTimeout(function(){  Print( "\t " +Commu[i] + "\n") ;},100+i*100);  
    }
setTimeout(function(){
   
for (i=0; i<Commu.length; i++){ 
    CommuFunc(i);
   
} 

},5400)


})
