function InitActuBox(){
    $('#contentTopic').hide();
    $('#contentVideo').hide();
    $('#contentActu').hide();
    ActuBoxActu();
    $('#ongletActu').click(function(){
        ActuBoxActu();
    });
    $('#ongletTopic').click(function(){
        ActuBoxTopic();
    });
    $('#ongletVideo').click(function(){
        ActuBoxVideo();
    });
}

function ActuBoxActu(){
    $('#ongletActu').css('borderBottom', 'none');
    $('#ongletTopic').css('borderBottom', '1px dashed #e4dede');
    $('#ongletVideo').css('borderBottom', '1px dashed #e4dede');
    $('#contentTopic').hide();
    $('#contentVideo').hide();
    $('#contentActu').show("slow");
}

function ActuBoxTopic(){
    $('#ongletTopic').css('borderBottom', 'none');
    $('#ongletActu').css('borderBottom', '1px dashed #e4dede');
    $('#ongletVideo').css('borderBottom', '1px dashed #e4dede');
    $('#contentTopic').show("slow");
    $('#contentVideo').hide();
    $('#contentActu').hide();
}

function ActuBoxVideo(){
    $('#ongletVideo').css('borderBottom', 'none');
    $('#ongletActu').css('borderBottom', '1px dashed #e4dede');
    $('#ongletTopic').css('borderBottom', '1px dashed #e4dede');
    $('#contentTopic').hide();
    $('#contentVideo').show("slow");
    $('#contentActu').hide();
}


function SetMyStatusToWrite(id){
    $('#tchat_user_action_' + id).html('[*]');
    $.get("index.php", {
        page: "tchat",
        action: "statutTchat",
        statut: 1
    });
}

function SetMyStatusToWait(id, send){
    if ($('#tchat_user_action_' + id).html() != '[-]') {
        $('#tchat_user_action_' + id).html('[-]');
        if (send == 1) 
            $.get("index.php", {
                page: "tchat",
                action: "statutTchat",
                statut: 0
            });
    }
}

function SendMsg(){
    //Recuperation du message
    var messagetchat = '';
    $('#BoutonSubmitTchat').attr("disabled", true);
    messagetchat = $('#messageTchat').val();
    
    $.get('index.php', {
        page: 'tchat',
        action: 'PostTchat',
        messageTchat: messagetchat
    }, function(data){
        $('#BoutonSubmitTchat').attr("disabled", false);
        $('#messageTchat').val('');
        VerifTchat('non');
        $('#messageTchat').focus();
        var id = $('#user_id').html();
        SetMyStatusToWait(id, 0);
    });
}

function VerifTchat(param){
    if ($('#LastTchatId') != null) {
        lastid = parseInt($('#LastTchatId').html());
        $.get('index.php', {
            page: 'tchat',
            action: 'VerifTchat',
            last_id: lastid
        }, function(data){
            id = parseInt(data);
            if (id === 0) {
                $('#ShowMessages').load("index.php", {
                    page: 'tchat',
                    action: 'SeeTchat'
                }, function(data){
                    document.getElementById('ShowMessages').scrollTop = 1000000;
                });
                
            }
        });
        if (param != 'non') {
            setTimeout("VerifTchat()", 10000);
        }
    }
}

function GetUsers(){
    if ($('#LastTchatId') != null) {
        $('#tchat_memberlist').load("index.php", {
            page: 'tchat',
            action: 'getUsers'
        });
        //		new Ajax.Updater("tchat_memberlist", "v3.php",{parameters: { page: 'tchat',action: 'getUsers' }});
        setTimeout("GetUsers()", 10000);
    }
}

function LaunchPlayer(youtube_code){
    $('#playerTchat').html('<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/' + youtube_code + '&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + youtube_code + '&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>');
}

function InitTchat(){
    VerifTchat('oui');
    GetUsers();
    $('#messageTchat').focus();
    document.getElementById('ShowMessages').scrollTop = 1000000;
    $('#messageTchat').bind('keyup', function() {
        var id = $('#user_id').html();
        if ($('#messageTchat').val() == '') 
            SetMyStatusToWait(id, 1);
        else 
            if ($('#messageTchat').val().length == 1) 
                SetMyStatusToWrite(id);
    } );
}


function DisconnectUser(user_id){
        $('#connectStatus').load("index.php", {
            page: 'Moderation',
	    action: 'disconnect',
	    member_id:user_id
        });
}

function BanUser(user_id){
    if (confirm("Attention, si vous etes Admin, le membre sera banni immediatement.... \n Si vous etes moderateur, vous soumettez/retirez une demande de ban.")) {
        $('#connectStatus').load("index.php", {
            page: 'Moderation',
	    action: 'BanUser',
	    member_id:user_id
        });
    }
}

function FetchDoublons(user_id){
    if (confirm("Attention, la commande peut prendre quelques minutes... \n")) {
        $('listDoublons').html('<span style="color:red;">Recherche en cours, veuillez patienter...</span>');
        $('#listDoublons').load("index.php", {
            page: 'Moderation',
	    action: 'FetchDoublons',
	    member_id:user_id
        });
    }
}

function HidePost(postid, topicid){

   $.get('index.php', {
        page: 'viewtopic',
        hidePost: '1',
        post_id: postid,
        topic_id: topicid
    }, function(data){
        $('#TopicMessageN' + postid).hide();            
    });
}


function MoveTopic(idtopic)
{

// $.get('index.php', {
         // page: 'moveTopic',
	    // topic_id: idtopic
    // }, function(data){
       // $('#MoveTopic').html(date.trim());
    // });

		
}

function EditSubject(topic_id)
{
	var txtbody = '<table><tr><th>Nouvel intitule du topic :</th><td><input name="subject" type="text" id="subject" value="'+$('#topicname').html()+'"><input type="hidden" name="topic_id" id="topic_id" value="'+topic_id+'"></td></tr><tr><th>Valider le nouvel intitule</th><td><input type="button" onclick="SubmitEditSubject();" value="Envoyer"></td></tr></table>';
	$('a:has(#topicname)').bind('click',function() {return false;});
	$('#topicname').html(txtbody);
}

function SubmitEditSubject() 
{	
	var valModif = $('#subject').val();
     if ($('#subject').val()=='') {alert('Merci de mettre un titre sur le topic !');return false;}
    
	$.get('index.php', {
         page: 'viewtopic',
	    topic_id: $('#topic_id').val(),
	    editTopic:'rename',
	    subject: valModif
    }, function(data){
       if (data.trim() != 'OK')
			alert('une erreur est survenue...');
	$('#topicname').html(valModif);
	$('a:has(#topicname)').unbind('click',function() {return false;});
    });
}



function InitSearchAll() 
{
    $('#layerSearchAll').css('display','none');
    $('#inputSearchAll').focus( function() {
	    if ($('#inputSearchAll').val() == 'Rechercher...') {
		$('#inputSearchAll').val('');
	    }
	});
    $('#inputSearchAll').blur( function() {
	    if ($('#inputSearchAll').val()=='') {
		$('#inputSearchAll').val('Rechercher...');
	    }
	});
    $('#inputSearchAll').keyup( function() {
	    var search=$('#inputSearchAll').val();
	    if (search.length<4) {
		$('#layerSearchAll').css('display','none');                    
	    }
	    else {
		$('#layerSearchAll').html('Chargement en cours...');
		var tosearch=search;
		$('#layerSearchAll').load("index.php", {
			page: 'search',
			    search: tosearch,
			    where:'All'
			    });
		$('#layerSearchAll').css('display','block');                    
	    }
	});
}

function SendMP(id)
{
    var MP=$('#messagePrive').val();
    var SUJET=$('#sujet').val();
    if (SUJET=='') {alert('Merci de renseigner le sujet du message'); return false;}
    if (MP=='') {alert('Merci de renseigner le corps du message'); return false;}

    $('#sendMP').load("index.php", {
            page: 'messagerie',
	    user_id: id,
	    message:MP,
	    sujet:SUJET
		}, function(data){
	    $('#sendMP').html('<p>Message envoye !</p>');
                });
}


