$(document).ready(
		function() {
			//console.log("realtimeactivate ("+systemBV.realTimeActivate +")");
			if(systemBV.realTimeActivate == "true")
			{
			
				initRealTime2();
			}
			
		}
	);
	
var socket;
WEB_SOCKET_SWF_LOCATION = "WebSocketMain.swf";

function initRealTime2()
{

	WebPush.log = function(msg)
	     	    {
					var txt;
					if (msg) 
					{
						
						console.log('Data : ' + msg);
						try{
						
						eval('var data = ' + msg + ';');
						
						$('#realTimePanel').fadeOut('fast'); 
						$('#realTimePanel').fadeIn('fast'); 
						$('#realTimePanelDataUser').html('<a href="'+systemBV.lienProfile.replace("11111",data.lien)+'">' +data.userName + '</a>');
						if(systemBV.lang=='en')
						{
							txt = data.txtEn;
						}
						else
						{
							txt = data.txtFr;
						}
						
						$('#realTimePanelDataTxt').html(txt);
					
						}
						catch(e){console.log(e)}

					}
				}; 
	console.log(systemBV.fullServerPath);
    var server = new WebPush(systemBV.fullServerPath);
	//var server = new WebPush('ws://boursevirtuelle.net:80/echo');

    // WebPush events

    server.bind('open', function() 
						{
							$('#realTimePanel').show(); 
							console.log('Open');
						}
				);

    server.bind('connection_disconnected', function() {
        //$('#realTimePanel').hide(); 
		console.log('Disconnected');
    });

    server.bind('close', function() {
        //$('#realTimePanel').hide(); 
		console.log('Close');
    });

    server.bind('connection_failed', function() {
        //$('#realTimePanel').hide(); 
		console.log('Fail');
    });

    server.bind('message', function(data) {

        WebPush.log(data);
    });
}


function initRealTime() 
{

	//var host = "ws://boursevirtuelle.com:12345/serverWebSocket.php";
	//var host = "ws://localhost:12345/af2010/trunk/concours/serverWebSocket.php";
	var host = systemBV.fullServerPath;
	try 
	{
		socket = new WebSocket(host); 
		
		socket.onopen = function(msg)
		{
			$('#realTimePanel').show(); 
		};
		
		socket.onmessage = function(msg)
		{
			var txt;
			if (msg.data) 
			{
				eval('var data = ' + msg.data + ';');
				
				for (userId in data) 
				{
					if (data[userId].txtFr) 
					{
						$('#realTimePanel').fadeOut('fast'); 
						$('#realTimePanel').fadeIn('fast'); 
						$('#realTimePanelDataUser').html('<a href="'+systemBV.lienProfile.replace("11111",data[userId].lien)+'">' +data[userId].userName + '</a>');
						if(systemBV.lang=='en')
						{
							txt = data[userId].txtEn;
						}
						else
						{
							txt = data[userId].txtFr;
						}
						
						$('#realTimePanelDataTxt').html(txt);
					}
				}

			}
		};
		
		socket.onclose = function(msg)
		{
			$('#realTimePanel').show(); 
		};
	} 
	catch(ex)
	{
		$('#realTimePanel').hide(); 
	}

}



      
     

