/** Generated by js.php */
// D�finition des constantes concernant les modules

var TAG_MODULE = 1
var BOOKMARK_MODULE = 2
var ACCOUNT_MODULE = 4
var NEWS_MODULE = 6
var HELP_MODULE = 7
var COMMUNAUTIES_MODULE = 10
var CATEGORIES_MODULE = 11
var TRIGGERED_ALERTS_MODULE = 12

/**
*	Adapte la taille du bandeau lors du redimensionnement de le fenêtre
*
**/

window.onresize = function() { 
	var width = document.body.clientWidth;

	if ($('contentHeader')) {
		$('contentHeader').style.width = "100%";
		
		if (width >=1210) {
			if($('coomcoomTitle')) $('coomcoomTitle').style.fontSize = "24px";
			if($("headerLinkLogin")) $("headerLinkLogin").style.fontSize = "12px"; 
			if($('headerLinkSubscribe')) $('headerLinkSubscribe').style.fontSize = "12px";
			if($('headerLinkPref')) $('headerLinkPref').style.fontSize = "12px";
			if($('headerLinkCGU')) $('headerLinkCGU').style.fontSize = "12px";
		}
		else if (width >=1115){
			if($('coomcoomTitle')) $('coomcoomTitle').style.fontSize = "20px";
			if($("headerLinkLogin")) $("headerLinkLogin").style.fontSize = "12px"; 
			if($('headerLinkSubscribe')) $('headerLinkSubscribe').style.fontSize = "12px";
			if($('headerLinkPref')) $('headerLinkPref').style.fontSize = "12px";
			if($('headerLinkCGU')) $('headerLinkCGU').style.fontSize = "12px";
		}
		else if (width >=1055) {
			if($('coomcoomTitle')) $('coomcoomTitle').style.fontSize = "18px";
			if($("headerLinkLogin")) $("headerLinkLogin").style.fontSize = "10px"; 
			if($('headerLinkSubscribe')) $('headerLinkSubscribe').style.fontSize = "10px";
			if($('headerLinkPref')) $('headerLinkPref').style.fontSize = "10px";
			if($('headerLinkCGU')) $('headerLinkCGU').style.fontSize = "10px";
		}
		else if (width >=1020) {
			if($('coomcoomTitle')) $('coomcoomTitle').style.fontSize = "17px";
			if($("headerLinkLogin")) $("headerLinkLogin").style.fontSize = "10px"; 
			if($('headerLinkSubscribe')) $('headerLinkSubscribe').style.fontSize = "10px";
			if($('headerLinkPref')) $('headerLinkPref').style.fontSize = "10px";
			if($('headerLinkCGU')) $('headerLinkCGU').style.fontSize = "10px";
			}
		else {
			if($('coomcoomTitle')) $('coomcoomTitle').style.fontSize = "15px";
			if($("headerLinkLogin")) $("headerLinkLogin").style.fontSize = "10px"; 
			if($('headerLinkSubscribe')) $('headerLinkSubscribe').style.fontSize = "10px";
			if($('headerLinkPref')) $('headerLinkPref').style.fontSize = "10px";
			if($('headerLinkCGU')) $('headerLinkCGU').style.fontSize = "10px";
			if($('contentHeader')) $('contentHeader').style.width = "470px";
		}
		
		// Adapte la taille des différentes iframes.
		$$('.panel .panelInner .content iframe.coomcoomIframe').each(function(f) {
			f.setStyle({height: (document.body.parentNode.clientHeight - 160) + 'px'});
		});	
	}
}

/**
*	Fonction qui change la langue de coomcoom
*
**/
changeLanguage = function(locale) {
	new Ajax.Request("/users/changeLanguage/"+locale,{onComplete:function(){
		document.location = "/";
	}});
}

/**
*	Fonction permettant de récupérer une chaine dans le fichier de ressource.
*	Retourne la valeur associée ou bien "value" si celle ci n'est pas trouvée.
*	Si le second paramètre est inexistant, on renvoit missing variable
*/

_mlt = function(key,value) {
	try {
		retour = eval("MLT_JS_"+key);
	}
	catch (e) {
		if (value) {
			retour = value;
		} else {
			retour = "[MISSING VARIABLE (MLT_JS_"+key+")]";
		}
	}
	return retour;
}

/**
*	Return the good comment label in function to the number of comments
**/
getCommentsLabel = function(nb_comments)
{
	switch(nb_comments)
	{
		case '0':
		case 0:
		if(window.isUserLogged) comments_label = _mlt("ADD_COMMENT",'Ajouter un commentaire');
		else comments_label = _mlt("NO_COMMENT",'Aucun commentaire');
		break

		case '1':
		case 1:
		comments_label = '1 '+_mlt("COMMENT_LOWER","commentaire")
		break

		default:
		comments_label = nb_comments+' '+_mlt("COMMENTS","commentaires");
		break
	}

	return comments_label
}

// suppression de toutes les entrées courantes
clearMyList = function(ul)
{
	// suppression de toutes les entrées courantes
	ul.immediateDescendants("li").each(function(li){if(!li.id) li.remove()})
}

	// suppression de toutes les lignes d'un tableau
clearMyTable = function(table)
{
	try {
		// suppression de toutes les entrées courantes
		for (var i=table.rows.length; i > 0; i--)
		{
			table.deleteRow(i-1);
		}

	}
	catch(e) { if(console) console.debug(e) }
}

clearBookmarks = function(){
	$('bookmarksContainer').innerHTML = '';
}

unselectedAllTab = function(){
	$('switchToPublicTab').className = 'unselected_tab';
	$('switchToPrivateTab').className = 'unselected_tab';
	$('switchToGroupsTab').className = 'unselected_tab';
	$('switchToCoomunautyTab').className = 'unselected_tab';
}

/**
*	Incrémente le coomrank suite à un clic sur une Url
*/

hitUrl = function (url_id,origin)
{
	new Ajax.Request("/urls/hit/"+url_id+"/"+origin)
}


// étoiles pour le vote (commun avec les urls publiques)
starOff = document.createElement('IMG')
starOff.src = '/img/starGray.gif'

starOn = document.createElement('IMG')
starOn.src = '/img/starBlue.gif'

starOver = document.createElement('IMG')
starOver.src = '/img/starOrange.gif'




/**
* Réaffiche la note courante de l'utilisateur
*/
resetMark = function(event)
{
	starsContainer = Element.up(Event.element(event),'span')

	if(!starsContainer) starsContainer = Event.element(event)
		
	// actualisation des étoiles
	stars = starsContainer.immediateDescendants()

	for(i=0;i<stars.length;i++)
	{
		if((i+1) <= starsContainer.getAttribute('default')) stars[i].src = starOn.src
		else stars[i].src = starOff.src
	}
}


/**
* Enregistre une nouvelle note
*/
setMark = function(event)
{
	// étoile cliquée
	star = Event.element(event)

	// nouvelle note
	new_mark = star.getAttribute('value')
	
	//si l'etoile active
	if(Global.starCurrent){
		//quand on clique sur l'etoile numero 1
		if(new_mark == 1 && Global.starCurrent == 1) new_mark = 0;
		if(new_mark > 1 && Global.starCurrent == new_mark ) new_mark = new_mark - 1;
	}
	//else new_mark = new_mark - 1;
	//else Global.firstClickStar = 1;
	
	Global.starCurrent = new_mark;
	
	// mise à jour de l'attribut par défaut
	Element.up(star,'span').setAttribute('default',new_mark)

	// affichage la nouvelle note en bleu
	resetMark(event)

	// enregistrement effectif
	new Ajax.Request("/marks/add/"+Element.up(star,'li').getAttribute('urlId')+"/"+new_mark,{asynchronous:false})

	// recherche d'un commentaire affiché pour mettre sa note à jour
	try {
		$$('span.myPublicCommentMark')[0].innerHTML = new_mark
		Element.show('myPublicCommentMark')
	} catch(e) {}

}

/**
* Active la note en cours de survol
*/
overMark = function(event)
{
	// note survolée
	star = Event.element(event)	

	// valeur de la note
	overed_mark = star.getAttribute('value')

	// bloc complet des notes
	starsContainer = Element.up(star,'span')



	// actualisation des étoiles
	stars = starsContainer.immediateDescendants()

	for(i=0;i<stars.length;i++)
	{
		if((i+1) <= overed_mark) stars[i].src = starOver.src
		else stars[i].src = starOff.src
	}
}



toolbarBookmark = function(event){
	
	var li = Event.element(event).up("LI");
	var id_current = li.getAttribute('bookmarkid');

	//si une boite commentaire est ouverte et qu'elle est different du bookmarks courant
	if(LAST_COMMENT_ID_DISPLAY != 0 && LAST_COMMENT_ID_DISPLAY != id_current)  $('bookmarkComment_'+LAST_COMMENT_ID_DISPLAY).style.display = 'none';
	
	//si le toolbar est deja creer
	if($('bookmarkToolbar'))
	{
		var id_back = $('bookmarkToolbar').getAttribute('bookmarkid');
		
		//si on click sur le meme bookmark
		if(id_current == id_back)
		{
			//on verifit si le toolbar est affiché
			if($('bookmarkToolbar').style.display == 'none')
			{
				li.className = 'selected_url';
				$('bookmarkToolbar').style.display = 'block';
				LAST_TOOLBAR_ID_DISPLAY = id_current;
			}
			else
			{
				li.className = 'unselected_url';
				$('bookmarkToolbar').style.display = 'none';
				LAST_TOOLBAR_ID_DISPLAY = 0;
			}
		}
		//si on click sur un autre bookmark
		else
		{
			
			var li_back = Element.up($('bookmarkToolbar'),'li');
			li_back.className = 'unselected_url';
			
			$('bookmarkToolbar').style.display = 'none';
			$('bookmarkToolbar').remove();
		}
	}
	
	//si le toolbar n'existe pas, on le creer
	if(!$('bookmarkToolbar'));
	{
		var comment_id = li.getAttribute('bookmarkid');
		
		LAST_TOOLBAR_ID_DISPLAY = comment_id;
		
		// création de la barre d'outils des dossiers
		var bookmarkToolbar = document.createElement("DIV");
		
		// paramètres
		bookmarkToolbar.setAttribute('bookmarkid',li.getAttribute('bookmarkid'));
		bookmarkToolbar.id = "bookmarkToolbar";
		bookmarkToolbar.style.display = 'none';
		
		// ajout des icones
		
		// ouvrir le lien
		var openBookmarkLink = document.createElement("A");
		openBookmarkLink.target = "_blank";
		openBookmarkLink.href = "javascript:;";
		openBookmarkLink.className = "bookmarkLink";
		
		
		var openBookmarkIcon = document.createElement("IMG");
		openBookmarkIcon.src = "/img/icons/crystal/16x16/actions/network.png";
		openBookmarkIcon.className = "imageGreyed";
		openBookmarkIcon.style.border = '0px';
		
		// actions
		Event.observe($(openBookmarkIcon),"mouseover",function(event) {showTooltip('bookmarkToolbarHelp','open_bookmark');Event.element(event).className = 'imageOver'});
		Event.observe($(openBookmarkIcon),"mouseout",function(event) {hideTooltip('bookmarkToolbarHelp');Event.element(event).className = 'imageGreyed'});
		
		openBookmarkLink.appendChild(openBookmarkIcon);
		bookmarkToolbar.appendChild(openBookmarkLink);
		
		/***************************************/
		
		// modifier le dossier
		var editBookmarkIcon = document.createElement("IMG");
		editBookmarkIcon.src = "/img/icons/crystal/16x16/actions/edit.png";
		editBookmarkIcon.className = "imageGreyed";
		
		// actions
		Event.observe($(editBookmarkIcon),"mouseover",function(event) {showTooltip('bookmarkToolbarHelp','edit_bookmark');Event.element(event).className = 'imageOver'});
		Event.observe($(editBookmarkIcon),"mouseout",function(event) {hideTooltip('bookmarkToolbarHelp');Event.element(event).className = 'imageGreyed'});
		
		bookmarkToolbar.appendChild(editBookmarkIcon);
		
		/***************************************/
		
		// supprimer le dossier
		var deleteBookmarkIcon = document.createElement("IMG");
		deleteBookmarkIcon.src = "/img/icons/crystal/16x16/actions/editdelete.png";
		deleteBookmarkIcon.className = "imageGreyed";
		
		// actions
		Event.observe($(deleteBookmarkIcon),"mouseover",function(event) {showTooltip('bookmarkToolbarHelp','delete_bookmark');Event.element(event).className = 'imageOver'});
		Event.observe($(deleteBookmarkIcon),"mouseout",function(event) {hideTooltip('bookmarkToolbarHelp');Event.element(event).className = 'imageGreyed'});
		
		bookmarkToolbar.appendChild(deleteBookmarkIcon);
		
		/***************************************/
		
		// déplacer le dossier
		var moveBookmarkIcon = document.createElement("IMG");
		moveBookmarkIcon.src = "/img/icons/crystal/16x16/actions/editmove.png";
		moveBookmarkIcon.className = "imageGreyed";
		
		// actions
		Event.observe($(moveBookmarkIcon),"mouseover",function(event) {showTooltip('bookmarkToolbarHelp','move_bookmark');Event.element(event).className = 'imageOver'});
		Event.observe($(moveBookmarkIcon),"mouseout",function(event) {hideTooltip('bookmarkToolbarHelp');Event.element(event).className = 'imageGreyed'});
		
		bookmarkToolbar.appendChild(moveBookmarkIcon);
		
		/***************************************/
		
		// partager le favoris
		var shareBookmarkIcon = document.createElement("IMG")
		shareBookmarkIcon.src = "/img/icons/crystal/16x16/actions/groupevent.png";
		shareBookmarkIcon.className = "imageGreyed";
		
		// actions
		Event.observe($(shareBookmarkIcon),"mouseover",function(event) {showTooltip('bookmarkToolbarHelp','publish_bookmark');Event.element(event).className = 'imageOver'})
		Event.observe($(shareBookmarkIcon),"mouseout",function(event) {hideTooltip('bookmarkToolbarHelp');Event.element(event).className = 'imageGreyed'})
		
		bookmarkToolbar.appendChild(shareBookmarkIcon)
		
		/***************************************/
		
		// calque pour l'aide contextuelle
		var bookmarkToolbarHelp = document.createElement("DIV");
		bookmarkToolbarHelp.id = "bookmarkToolbarHelp";
		bookmarkToolbarHelp.style.display = "inline";
		bookmarkToolbarHelp.style.position = "relative";
		bookmarkToolbarHelp.style.top = "-4px";
		bookmarkToolbarHelp.style.left = "10px";
		bookmarkToolbarHelp.style.border = "1px solid white";
		
		bookmarkToolbar.appendChild(bookmarkToolbarHelp)

		// désélection de l'élément de liste courant
		li.className = 'unselected_folder';
		
		// test s'il faut afficher ou cacher
		if(bookmarkToolbar.style.display == 'none')
		{
			// connexion des événements aux icones, en fonction du dossier cliqué

			Event.observe(openBookmarkIcon,'mousedown',function(event){openBookmarkLink.href = li.getAttribute('url');hitUrl(li.getAttribute('urlId'),'private');openBookmarkIcon.className = 'imageGreyed'});
			Event.observe(editBookmarkIcon,'click',function(event){dialog('editBookmark',{source:'/bookmarks/edit_form/'+li.getAttribute('bookmarkId'),size:'300,290'}).display();editBookmarkIcon.className = 'imageGreyed'});
			Event.observe(deleteBookmarkIcon,'click',function(event){dialog('deleteBookmark',{size:'300,160',source:'/bookmarks/confirmDelete/'+li.getAttribute('bookmarkId')}).display();deleteBookmarkIcon.className = 'imageGreyed'});
			Event.observe(moveBookmarkIcon,'click',function(event){dialog('moveBookmark',{size:'350,200',source:'/bookmarks/move/'+li.getAttribute('bookmarkId')}).display();moveBookmarkIcon.className = 'imageGreyed'});
			Event.observe(shareBookmarkIcon,'click',function(event){dialog('deleteBookmark',{size:'400,550',source:'/bookmarks/share_bookmark_form/'+li.getAttribute('bookmarkId')}).display();shareBookmarkIcon.className = 'imageGreyed'});

			// on rattache la barre d'outil au dossier courant, puis on l'affiche
			li.appendChild(bookmarkToolbar);
			bookmarkToolbar.style.display = 'block';
	
			// surbrillance de l'élément de liste concerné
			li.className = 'selected_folder';
		}
		else
		{
			li.className = 'unselected_folder';
			bookmarkToolbar.style.display = 'none';
		}
	}
	
}










/**
* OnComplete basique
*
**/
requestURL = function(url,method,f)
{	
	//si on passe par un formulaire
	new Ajax.Request(url,{
			method: method,
			postBody: Form.serialize(f),
			onComplete: valideOnComplete
	});
	
	return false
}


valideOnComplete = function(xhr,json){
	try {
		// si une redirection est définie, on la traite en priorité
		if(json.redirect){
			document.location = json.redirect;
			return
		}
		//si une fonction est definie
		if(json.fonction){
			//execute la fonction
			eval(json.fonction);
		}
		
		//s'il n'y a pas d'erreur
		if(json.error == 0){
			//on ferme la boite de dialogue
			closeDialog();
			return
		}

		//cas ou il y aurai des erreurs
		
		if(json.infos.title) var title = json.infos.title;
		else title = '';
		
		if(title)
		{
			var content = json.infos.text;				
	
			content = "<br><br><center><input id='closeDialogButton' type='button' value='"+_mlt("CLOSE")+"' onclick='closeDialog()'>";
			dialog('confirmation',{
				title:title,
				content:content,
				size:'350,250'
			}).display(json.hidedialogs);
		}
	}
	catch(e) { if (console) console.debug(e); }
}

//-- mot de passe oublié --//
lostPassword = function(token){
	dialog('lostPassword',{
		source:'/users/lostPassword/'+token,
		size:'220,230'}).display();
}

/**
*	Fonction qui met ˆ jour l'attribut 'viewed' des triggered_alert, lorsque l'on click sur une url
*
**/
markAsViewed = function(triggeredAlert)
{
	new Ajax.Request('/triggered_alerts/markAsViewed/'+triggeredAlert,
						{
							onComplete: function(xhr){
								$("triggeredAlert"+xhr.responseText).style.fontWeight = 'normal';
							}
						}
	)
}

toggleComment = function(event)
{
	li = Event.findElement(event,'LI')
	commentContainer = Element.down(li,'div.commentContainer')
	if (commentContainer.style.display == 'none')
	{
		commentContainer.style.display = 'block'
		if (opened_private_comment)
		{
			Element.down(opened_private_comment,'div.commentContainer').style.display = 'none'
		}
		opened_private_comment = li;
	}
	else{
		commentContainer.style.display = 'none'
		opened_private_comment = 0;
	}
}

deleteAlert = function(triggeredAlert)
{
	new Ajax.Request('/triggered_alerts/delete/'+triggeredAlert,
						{
							onComplete: function(xhr,json){
								var data = eval('('+xhr.responseText+')');
								var li = $("li_triggeredAlert"+data.id);
								if (data.none)
								{
									li.innerHTML = data.none
								}
								else
								{
									Element.remove(li);									
								}
							}
						}
	)
}

/**
*	Fonction qui affiche les prŽfŽrences de l'utilisateur concernant les alertes.
*
**/
displayAlertSettings = function()
{
	new Ajax.Updater("myAlerts","/configured_alerts/update_settings");
}

/**
*	Fonction qui affiche les alertes
*
**/
displayAlerts = function()
{
	new Ajax.Updater("myAlerts","/triggered_alerts/get");
}

/**
*	Fonction qui affiche les diffŽrents liens RSS
*
**/
displayAlertsRss = function()
{
	new Ajax.Updater("myAlerts","/configured_alerts/rss");
}

/**
*	Mise ˆ jour des param?tres des alertes
*
**/
updateAlertSettings = function()
{
	var requestParameters = Form.serialize('updateSettingsForm')
	new Ajax.Request("/configured_alerts/update_settings",{onComplete:displayAlerts,method:'post', postBody:requestParameters});
}

/**
*	Fonction qui permet de voir plus d'alertes
*
**/

seeMoreOrLess = function(communautyId,mltMore,mltLess)
{
	var div = $("moreAlerts"+communautyId);
	var a = $("a_moreAlerts"+communautyId);
	if ( div.style.display == 'block')
	{
		div.style.display = "none";
		a.innerHTML = '['+mltMore+']';	
	}
	else
	{
		div.style.display = "block";
		a.innerHTML = '['+mltLess+']';
	}
}






info = function(action,contenu,e){

	var voir;
	var display;
	var mouseX, mouseY;
	
	if(t) clearTimeout(t);
	
	if (action == "cache"){
		voir = "hidden";
		display = "none";
		tempo();
	}
	else {
		voir = "visible";
		display = "block";
		
		if(document.all) getMouseXY(document.event);
		else getMouseXY(e);
		
		$('bulle').className = 'relsample';
		
		document.getElementById("bulle").style.top = mouseY+15+"px";
		document.getElementById("bulle").style.left = mouseX+5+"px";
		document.getElementById("bulle").style.visibility = voir;
		document.getElementById("bulle").style.display = display;
		
		$("sub_content").innerHTML = contenu;
	}
	
	function getMouseXY(e){
		if (!e) e = window.event;
		
		if (e){
			if (e.pageX || e.pageY){
				mouseX = e.pageX;
				mouseY = e.pageY;
			}
			else if (e.clientX || e.clientY){
				mouseX = e.clientX + document.body.scrollLeft;
				mouseY = e.clientY + document.body.scrollTop;
			}
		}
	}
}


function cache(){
	$("bulle").className = 'hide';
	$("sub_content").innerHTML = '';
}

function tempo(){
	t = setTimeout(cache,200);
}


/**
*	Forme un select avec les dossiers d'une communauté
*
**/
getFolder = function(sel,mlt){
	//l indice du choix dans le select
	var indice = sel.selectedIndex;
	
	//si on a choisit quelques choses
	if(indice){
		var communauty_id = $F(sel);
		new Ajax.Request('/communauties/getCategories/'+communauty_id,{
			method:'get',
			onComplete: function(xhr,json){
				$('categoryCommunauty').innerHTML = xhr.responseText;
			}
		});
	}
}


/**
*	Requ�te AJAX permettant d'incr�menter le module dont l'id est pass� en param�tre
*
*/
incrementModuleCounter = function(moduleId) {
		new Ajax.Request("/modules/incrementCounter/"+moduleId);
}

/**
 * Standard onSuccess handler for Ajax requests,
 * if the JSON fragment defines an error attribute,
 * display its content in a modal dialog, else, close
 * the current dialog.
 * @return {Boolean} true if all was OK, false if an error
 * 		occured
 */
ajaxErrorOrClose = function(xhr) {
	try {
		var result = eval('(' + xhr.responseText + ')');
		if(result.error) {
			errorDialog(result.error);
			return false;
		} else {
			closeDialog();
			return true	;
		}
	} catch(e) {
		if(console) console.info(e);
		return false;
	}
}

errorDialog = function(msg) {
	dialog('CommonErrorDlg',
	{
		title: _mlt('ERROR', 'Erreur'),
		content: msg,
		size: '200,80',
		type: 'info'
	}).display();
}

// affiche l'aide contextuelle
showTooltip = function(div,button) {

	div = $(div)
	if(!div) return

	switch(button)
	{

		case 'open_bookmark':
		Element.update(div,_mlt('OPEN_BOOKMARK_HELP','Ouvrir ce favori'));
		break;

		case 'delete_bookmark':
		Element.update(div,_mlt('DELETE_BOOKMARK_HELP','Supprimer ce favori'));
		break;

		case 'move_bookmark':
		Element.update(div,_mlt('MOVE_BOOKMARK_HELP','D&eacute;placer ce favori'));
		break;

		case 'publish_bookmark':
		Element.update(div,_mlt('PUBLISH_BOOKMARK_GROUP_HELP','Partager ce favori dans <b>Mes Groupes</b>'));
		break;

		case 'edit_bookmark':
		Element.update(div,_mlt('EDIT_BOOKMARK_HELP','Editer ce favori'));
		break;

		case 'add_bookmark':
		Element.update(div,_mlt('ADD_BOOKMARK_HELP','Ajouter un favori'));
		break;

		case 'open_folder':
		Element.update(div,_mlt('OPEN_FOLDER_HELP','Ouvrir ce dossier'));
		break;

		case 'edit_folder':
		Element.update(div,_mlt('EDIT_FOLDER_HELP','Editer ce dossier'));
		break;

		case 'move_folder':
		Element.update(div,_mlt('MOVE_FOLDER_HELP','D&eacute;placer ce dossier'));
		break;

		case 'delete_folder':
		Element.update(div,_mlt('DELETE_FOLDER_HELP','Supprimer ce dossier'));
		break;
		
		case 'publish_bookmark_communauty':
		Element.update(div,_mlt('PUBLISH_BOOKMARK_COMMUNAUTY_HELP',"Partager ce favori à la")+" <b>"+_mlt("COMMUNAUTY")+"</b>");
		break;
	}
}

internalErrorDialog = function() {
	errorDialog(_mlt('INTERNAL_ERROR', 'Une erreur inatendue est survenue, veuillez r&eacute;&eacute;ssayer plus tard'));
}


/**
 * Enrichit le prototype Ajax de base pour avoir
 * un contrôle d'authentification générique. 
 */
Ajax.Request.prototype._respondToReadyState = Ajax.Request.prototype.respondToReadyState;

Ajax.Request.ErrorDialogTemplate = new Template('<h1>#{ERROR}</h1><p>#{ERROR_MSG}</p><p class="button"><input type="button" value="#{CLOSE}" onclick="javascript:closeDialog()"/></p>');

Ajax.Request.prototype.respondToReadyState = function(readyState) {
	var state = Ajax.Request.Events[readyState];
	if(state == 'Complete' && 
		this.getHeader('X-Authentication-Required') == 'true') {
		// L'utilisateur tente d'accéder à une page nécessitant une authentification
		if(this.getRequestHeader('X-Request-Type') == 'dialog') {
			this.transport.onreadystatechange = Prototype.emptyFunction;
			this.transport = {
				responseText: Ajax.Request.ErrorDialogTemplate.evaluate({
					ERROR: _mlt('ERROR'),
					ERROR_MSG: _mlt('AUTHENTICATION_NEEDED', 'Vous devez &ecirc;tre identifi&eacute; pour acc&eacute;der &agrave; cette ressource'),
					CLOSE: _mlt('BACK')
					})
			};
		
		} else {
			errorDialog(_mlt('AUTHENTICATION_NEEDED'));
		}
		return;
	}
	
	this._respondToReadyState(readyState);
}


/**
*   Gestion du petit popup pub
*/

var tabId = new Array()

var id
var t = 0

displayAdvertise = function(event)
{
    //ie
    if(document.all){
        //alert(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)
        curX = event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
        curY = event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    }
    
    //netscape 4 ou mozilla
    else{
        curX = event.pageX;
        curY = event.pageY;
    }
    
    element = Event.element(event)
    id = element.id

    
    $('calque_'+id).style.left = (curX + 20) + 'px'
    $('calque_'+id).style.top = (curY + 10) + 'px'
    
    
    //on hide tous les autres DIV pub
    for(i=0;i<tabId.length;i++)
    {
        //si l'id courant se trouve dans le tableau, on l 'affiche
        if(id != tabId[i])
        {
            $('calque_'+tabId[i]).style.display = 'none'
        }
    }
    
    $('calque_'+id).style.display = 'block'
    
    //on ajout l'id
    setId(id)
                
    //on arrte le tempo
    clearTimeout(t)
}

hideAdvertise = function(event)
{
    //on rend invisible de la div courant
    $('calque_'+id).style.display = 'none'  
}


//quand on est sur le SPAN ('publicite')
activeTimer = function(event)
{
    //on demarre le tempo a laquelle la DIV pub sera rendu invisible
    t = setTimeout(hideAdvertise,500)
}

resetTimer = function(event)
{   
    //on arret le tempo
    clearTimeout(t)
}


//on met tout les ID ds un tableau pour pouvoir les afficher ou non
setId = function(id)
{
    var already = 0
    var n
    if(tabId.length < 1) n = 0
    else n = tabId.length

    //on verifit l'id n'est pas deja enregistrer
    for(var i=0;i<n;i++)
    {
        //on verifit si l'id courant existe
        if(tabId[i] == id){ already = 1;}
    }
    
    //si l'id n'existe pas dans le tableau, on rajoute
    if(!already){ tabId[n] = id }
}


/**
* Fonction qui détecte si l'utilisateur utilise un navigateur compatible
*
* Return true si oui, false dans le cas contraire
*/
isBrowserCompatible = function()
{
	var bool = false;
	var browser = navigator.userAgent.toLowerCase();

	if ( (browser.indexOf("msie 7.0") != -1) || (browser.indexOf("msie 6.0") != -1) ||
	(browser.indexOf("firefox/2") != -1) || (browser.indexOf("firefox/1.5") != -1) ||
	(browser.indexOf("safari/4") != -1)  || (browser.indexOf("opera/9") != -1) || (browser.indexOf("mozilla/5.0") != -1))
	{
		bool = true;
	}
	return bool;
}

