// Effet de highlight sur une ligne d'un tableau
function highlight(mouseover, line, color)
{
	line.style.background = (mouseover ? "#BBBBFF" : "#" + color);
	line.style.cursor = "hand";
}

function afficheUrl(url)
{
	this.location.href = url;
}

function affichePersonne(idPersonne)
{
	this.location.href = "./fiche_personne.php?id=" + idPersonne;
}

function affichePartie(idPartie)
{
	this.location.href = "./fiche_partie.php?id=" + idPartie;
}

function affichePartieFoot7(idPartie)
{
	this.location.href = "./fiche_partie.php?type=foot7&id=" + idPartie;
}

function afficheDiaporama(repertoire)
{
	var nom_fenetre = repertoire.replace('-', '_');

	fiRef = window.open("./diaporama.php?rep=" + repertoire, "diaporama_" + nom_fenetre,
	"width=800,height=600,scrollbars=no,toolbar=no,location=no,directories=no,status=no,resizable=yes");
}

function affichePhoto(name, url, width, height)
{
	url = "./photo.php?photo=" + url;

	fiRef = window.open(url,name, "width=" + (width + 60) + ",height=" + (height + 70) +
		",scrollbars=yes,toolbar=no,location=no,directories=no,status=no,resizable=yes");
//	fiRef.focus();
}

function afficheFLV(videoName, width, height)
{
	var videoDiv = this.document.getElementById("videoDiv");
	var html = "<a href='./" + videoName + "'";

	html += "style='display:block;width:" + width + "px;height:" + (height + 30) + "px;border:solid 1px #000000;'";
	html += "id='video'>";
	html += "</a>";
	html += "<center><a class='bold_font' href=\"javascript:hideFLV('video1div');\">Fermer</a></center>";

	videoDiv.innerHTML = html;

	// http://flowplayer.org/documentation/configuration/

	flowplayer('video', "./flowplayer-3.1.2.swf", {
		clip:  {
			autoPlay: true,
			autoBuffering: true
		},
		plugins: {
			controls: {
				// display properties
				bottom:0,
				height:20,
				backgroundColor: '#2d3e46',
				backgroundGradient: 'low',

				// controlbar-specific configuration
				fontColor: '#ffffff',
				timeFontColor: '#333333',
				autoHide: 'never',

				// which buttons are visible and which are not?
				play:true,
				volume:true,
				mute:true,
				time:true,
				stop:true,
				playlist:false,
				fullscreen:true,

				// scrubber is a well-known nickname for the timeline/playhead combination
				scrubber: true

				// you can also use the "all" flag to disable/enable all controls
			}
		}
	});


	DisplayPopupDiv("videoDiv");
}

function hideFLV(divId)
{
	var videoDiv = this.document.getElementById("videoDiv");

	videoDiv.innerHTML = "";
	HidePopupDiv(divId);
}

function afficheAnniversaires()
{
	window.open("anniversaires.php","anniversaires", "width=450,height=550,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no");
}


var movingDiv = "";
var deltaHauteur = "";
var hauteurInitiale = "";
var ouverture;
var attente = 1;
var increment = 20;

function switchDivVisibility(divId, useSlide)
{
	if (useSlide)
		$('#' + divId).slideToggle(400);
	else
		$('#' + divId).toggle(400);
}

function isIE55Navigator()
{
	var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);

	if (navigator.userAgent.indexOf('Mac') >= 0)
		win_ie_ver = 0;
	if (navigator.userAgent.indexOf('Windows CE') >= 0)
		win_ie_ver = 0;
	if (navigator.userAgent.indexOf('Opera') >= 0)
		win_ie_ver = 0;

	if (win_ie_ver >= 5.5)
		return true;
	else
		return false;
}

function SwitchChat()
{
	var mainChatFrame = this.parent;
	var chatDiv = document.getElementById("open_chat_div");
	var iframeChat = mainChatFrame.document.getElementById("chat_frame");

	if (iframeChat.src == "about:blank")
	{
		alert("Le chargement du chat est en cours. Veuillez patienter...");
		return;
	}

	chatOpen = !chatOpen;

	if (chatOpen)
	{
		chatDiv.innerHTML = "<font color='#FFFFFF' class='petit'>Fermer le t'chat</font>";
		mainChatFrame.ResizeFrames(mainChatFrame.last_opened_chat_height, mainChatFrame.last_opened_chat_height);
	}
	else
	{
		chatDiv.innerHTML = "<font color='#FFFFFF' class='petit'>Ouvrir le t'chat</font>";
		mainChatFrame.ResizeFrames(0, 0);
	}

	SendPing(false);
}

function ReplaceString(text, search, replace)
{
	if (text == null)
		return null;

	if (search == null)
		return text;

	var	result = "";
	var	i, j;
	var	length = text.length;
	var	sl = search.length;
	var	rl = 0;

	if (replace != null)
		rl = replace.length;

	for (i = 0, j = 0; (i < length) && ((j = text.indexOf(search, i)) >= 0); i = j + sl)
	{
		result = result + text.substring(i, j);

		if (rl > 0)
			result = result + replace;
	}

	if (i < length)
		result = result + text.substring(i, length);

	return result;
}

// Send an Ajax request to the server
function SendPing(recurse)
{
	var ajaxRequest;

	if (window.XMLHttpRequest)
		ajaxRequest = new XMLHttpRequest();
	else if (window.ActiveXObject)
		ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

	var url = "./ping.php";
	var mainChatFrame = this.parent;
	var nom = "";
	var nom_encode = "";
	var sendMessage = true;

	try
	{
		if ((mainChatFrame != null) && ((typeof mainChatFrame) != "undefined"))
		{
			var chatFrame = mainChatFrame.frames["chat_frame"];

			if ((chatFrame != null) && ((typeof chatFrame) != "undefined")
					&& (chatFrame.document.forms[0] != null) && ((typeof chatFrame.document.forms[0]) != "undefined"))
			{
				var nomInput = chatFrame.document.forms[0].elements["chat_nom"];

				nom = nomInput.value;

				if (chatFrame.messageSent)
					sendMessage = false;
			}
		}
	}
	catch (ex)
	{
	}

	nom = ReplaceString(escape(nom), "+", "%2B");

	if (sendMessage)
	{
		// déclaration dynamique d une fonction locale : une instance de la fonction par instance Ajax !
		var ajaxCallback = function()
		{
			ProcessChatAjaxRequest(ajaxRequest);
		}

		ajaxRequest.open("POST", url, true);
		ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
		ajaxRequest.onreadystatechange = ajaxCallback;
		ajaxRequest.send("chat_height=" + mainChatFrame.chat_height + "&chat_nom=" + nom);
	}

	if (recurse)
		setTimeout("SendPing(true)", 10000);
}

// This function implements the process of an ajax request
function ProcessChatAjaxRequest(ajaxRequest)
{
	if (ajaxRequest.readyState == 4)
	{
		if (ajaxRequest.status == 200)
		{
			var text = ajaxRequest.responseText;

			SetPingInfo(text);
		}
	}
}

function SetPingInfo(text)
{
	text = ReplaceString(text, "&eacute;", "é");
	text = ReplaceString(text, "&egrave;", "è");
	text = ReplaceString(text, "&euml;", "ë");
	text = ReplaceString(text, "&ecirc;", "ê");
	text = ReplaceString(text, "&iuml;", "ï");
	text = ReplaceString(text, "&ouml;", "ö");
	text = ReplaceString(text, "&agrave;", "à");
	text = ReplaceString(text, "&ntilde;", "ñ");
	text = ReplaceString(text, "&ccedil;", "ç");

	var pos = text.indexOf("*");
	var pings = text.substring(0, pos);
	var pos2 = text.indexOf("*", pos + "*".length);
	var nouveau = text.substring(pos2 + "*".length, text.length);

	text = text.substring(pos + "*".length, pos2);

	var divLabel = document.getElementById("ping_div_label");
	var divImg = $("#ping_div_img");
	var nouveauMessageImg = $("#new_chat_message_image");
	var divText;

	if (pings == 0)
		divText = "Personne n'est connecté";
	else if (pings == 1)
		divText = "1 personne connectée";
	else
		divText = pings + " personnes connectées";

	divLabel.innerHTML = "<font color='#FFFFFF' class='petit'>" + divText + "</font>";
	divImg.attr("tooltiptipsy", text);
	divImg.tipsy({html: true, gravity: 'ne', title: 'tooltiptipsy', opacity: 0.8, fade: true});

	if (!chatOpen && (nouveau == "nouveau_message"))
	{
		nouveauMessageImg.attr('src', './images/divers/girophare.gif');
		nouveauMessageImg.attr("tooltiptipsy", "Nouveau message dans le chat");
		nouveauMessageImg.tipsy({html: true, gravity: 'ne', title: 'tooltiptipsy', opacity: 0.8, fade: true});
	}
	else
	{
		nouveauMessageImg.src = './images/divers/vide_petit.gif';
		nouveauMessageImg.attr("tooltiptipsy", "");
	}
}

var displayedPopupDiv = null;

function DisplayPopupDiv(divId)
{
	var popup_div = document.getElementById("popup_div");

	displayedPopupDiv = document.getElementById(divId);

	popup_div.style.display = "block";

	if (displayedPopupDiv != null)
		displayedPopupDiv.style.display = "block";

	ReplacePopupDiv();
}

function HidePopupDiv(divId)
{
	var popup_div = document.getElementById("popup_div");

	popup_div.style.display = "none";

	if (displayedPopupDiv != null)
		displayedPopupDiv.style.display = "none";
}

function ReplacePopupDiv()
{
	var popup_div = document.getElementById("popup_div");

	if (popup_div != null)
	{
		popup_div.style.width = 10;
		popup_div.style.height = 10;

		if (displayedPopupDiv != null)
		{
			displayedPopupDiv.style.left = 0;
			displayedPopupDiv.style.top = 0;
		}

		var width = this.document.body.scrollWidth;
		var height = this.document.body.scrollHeight;
		var totalWidth = this.document.body.clientWidth;
		var totalHeight = this.document.body.clientHeight;

		if (width < totalWidth)
			width = totalWidth;

		if (height < totalHeight)
			height = totalHeight;

		popup_div.style.width = width;
		popup_div.style.height = height;
	}

	if (displayedPopupDiv != null)
	{
		var parentHScroll = this.document.body.scrollLeft;
		var parentVScroll = this.document.body.scrollTop;

		displayedPopupDiv.style.left = (totalWidth - displayedPopupDiv.offsetWidth) / 2 + parentHScroll;
		displayedPopupDiv.style.top = (totalHeight - displayedPopupDiv.offsetHeight) / 2 + parentVScroll;
	}
}

// Send an Ajax request to the server
function AjaxReplaceDivContent(url, params, divId)
{
	var ajaxRequest;

	if (window.XMLHttpRequest)
		ajaxRequest = new XMLHttpRequest();
	else if (window.ActiveXObject)
		ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

	// déclaration dynamique d'une fonction locale : une instance de la fonction par instance Ajax !
	var ajaxCallback = function()
	{
		ProcessAjaxReplaceDivContent(ajaxRequest, divId);
	}

	ajaxRequest.open("POST", url, true);
	ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
	ajaxRequest.onreadystatechange = ajaxCallback;
	ajaxRequest.send(params);
}

// This function implements the process of an ajax request
function ProcessAjaxReplaceDivContent(ajaxRequest, divId)
{
	if (ajaxRequest.readyState == 4)
	{
		if (ajaxRequest.status == 200)
		{
			var text = ajaxRequest.responseText;
			var div = document.getElementById(divId);

			if (div != null)
			{
				div.innerHTML = text;
				ReplacePopupDiv();
				setTimeout("ReplacePopupDiv()", 200);
			}
		}
	}
}

