
var submit_stamm = false;
var draft_delay = 60; // delai auto-enreg des brouillons, en secondes
//var GB_ROOT_DIR = "/js/greybox/";


var g_tooltip_elm=null;
var g_tooltip_inner_elm=null;
var g_tooltip_showing=0;
var g_tip_elm=null;





function none() { return; }

function getRef(id)
{   

var obj;
  if (document.getElementById&&!document.all) {
    obj = document.getElementById(id);
	} else if (document.all) { //IE 4 et +
		obj = eval('document.all.'+id);
	} else {
	}
  return obj;
/*
    if (is_ie4up) {
        return document.all.item(id);
    }
    else if(is_nav6up) {
        return document.getElementById(id);
    } else
    return null;
*/    
}


// Validation d'un message du chat
function submit_stammtisch2 (mode) {
	return true;
}

function submit_stammtisch (form, mode) {
	//if (submit_stamm) return false;
	var res = false;
	var limite    = 80;
  var msg = form.message_stammtisch;
	var check = check_stammtisch (msg,limite);
  if (check == "")
	  res = true;
  else {
  	alert (check);
		if (msg.value.length > limite)
			msg.value = msg.value.substr(0,limite);
		msg.focus();
		//submit_stamm = false;
	}
	//if (res) submit_stamm=true;
	return res;
}

// Teste la validité de ce qu'il y a de saisi sur le stamm
// Renvoie une erreur en clair ou chaine vide si OK
function check_stammtisch (obj, limite) {
	var err = "";
	if (!obj || obj=="undefined")	err += "Problème";
	obj.value=Trim(obj.value);
  if (obj.value.length < 2)    err += "Saisissez au-moins deux caractères !";
  else {
		// On ne compte pas les liens
		var msg;
		msg = obj.value;
		var lon = msg.length;
		//document.writeln (lon);
		var myRe = new RegExp(/(http[\S\.\/:]*)/gi);
		myArray = msg.match(myRe);
		//alert (myArray);
		if (myArray) {
			for (i=0;i<myArray.length;i++)
				lon -= myArray[i].length;
		}
		//document.writeln (lon);
		//document.writeln (myArray);
		if (lon > limite)    err += limite + " caractères maximum (hors lien) !";
	}
	return err;
}




// Shows the help messages in the helpline window
function helpline(help) {
	var helpbox = getRef("helpbox");
	if (helpbox && eval(help + "_help"))
		helpbox.innerHTML = eval(help + "_help");
}





function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}




// Photo
function viewPhoto (url, largeur, hauteur) {
    var url = home+page+"?page=viewPhoto&url=" + url;
    var name = "photo";
    var options = "height="+(hauteur+127)+",width="+(largeur+32)+",toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no";
    a = window.open (url, name, options);
    a.focus();
}


// Détail d'un message
//var arTopics = new Array();
function viewMessage (topicId, tab, filtre) {
    var url = home+page+"?page=viewMp&topic="+topicId+"&tab="+tab;
		if (filtre) url += "&filtre="+filtre;
		//window.open (url); return;
    var name = "topic" + topicId;
    var options = "height="+mp_height+",width="+mp_width+",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no";
		
		/*		
		if (arTopics[name] && arTopics[name].open && !arTopics[name].closed) {
			arTopics[name].focus();
		} else { 
			arTopics[name] = window.open (url, name, options);
			arTopics[name].focus();
		}
		*/
		//eval ("if ("+arTopics[name]+" && "+arTopics[name]+".open && !"+arTopics[name]+".closed) { "+arTopics[name]+".focus(); } else { arTopics[name] = window.open ('"+url+"', '"+name+"', '"+options+"'); }");
   	var a = window.open (url, name, options);
    a.focus();
}
function viewMessageRecherche (topicId) {
}

// Détail d'un message
// Cas d'un msg ouvert en popup par le site -> MP recu
function viewMessageMsgId (topicId, msgId) {
	var tab = 'recv';
	var url = home+page+"?page=viewMp&topic="+topicId+"&tab="+tab;
	var name = "topic"+topicId+"_"+msgId;
  var options = "height="+mp_height+",width="+mp_width+",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no";
	var a = window.open (url, name, options);
	a.focus();
}





// Envoi message
function writeMessage (userLogin, message) {
    var url = home+page+"?page=writeMp&to=" + userLogin;
    if (message) url += "&message="+message;
    var name = "writeMp";
    var options = "height="+mp_height_write+",width="+mp_width_write+",toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no";
    a = window.open (url, name, options);
    a.focus();
}

var currentMenuLabel = '';
function setMenuLabel (label) {
	var menuLabel;
	if (menuLabel = $("menuLabel")) {
		if (label) {
			currentMenuLabel = menuLabel.innerHTML;
			menuLabel.innerHTML = label;
		} else {
			menuLabel.innerHTML = currentMenuLabel;
		}
	}
}


// Popups
function selectPopupVal (fieldName, Id, Lib) {
	//alert ("fieldName="+fieldName+" / Id="+Id+" / Lib="+Lib);
	//var obj = window.opener.getRef (fieldName);
	var obj = getRef(fieldName);
	//alert ("obj="+obj);
  if (obj)		obj.value = Id;
  var objLib = getRef (fieldName+"Lib");
  if (objLib)	objLib.innerHTML = Lib;
	//self.close();
	//window.opener.focus();
}
function openerSelectPopupVal (fieldName, Id, Lib) {
	if (window.opener) {
		window.opener.selectPopupVal (fieldName, Id, Lib);
		self.close();
		window.opener.focus();
	} else
		alert ('Impossible de joindre la fenetre');

}

function selectPopupValVille (fieldVille, valueVille, fieldCp, valueCp, fieldPays, valuePays, Lib) {
  var objVille = getRef (fieldVille);
  objVille.value = valueVille;
  var objCp = getRef (fieldCp);
  objCp.value = (valueVille) ? valueCp : '';
  var objPays = getRef (fieldPays);
  objPays.value = (valueVille) ? valuePays : 0;
  var objLib = getRef (fieldVille+"Lib");
  objLib.innerHTML = (valueVille) ? Lib : '';
	//self.close();
	//window.opener.focus();
	}
function setPopupNo (fieldName) {
  var obj = $(fieldName);
  var objLib = getRef (fieldName+"Lib");
	if (obj) obj.value = "";
	if (objLib) objLib.innerHTML = "";
}
function popupMatches (fieldName, defineJsDomain) {
  var obj = $(fieldName);
	var url = home+page+"?page=listeMatches&field="+fieldName+"&defineJsDomain="+defineJsDomain+"&match="+obj.value;
	var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+(popup_width)+",height="+(popup_height);
	var name = "POPUP";
	var popWin = window.open(url, name, options);
	popWin.focus();
	}
function popupPersonnes (fieldName) {
  var obj = $(fieldName);
	var url = home+page+"?page=listePersonnes&field="+fieldName+"&personne="+obj.value;
	var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+(popup_width)+",height="+(popup_height);
	var name = "POPUP";
	var popWin = window.open(url, name, options);
	popWin.focus();
	}
function popupDirigeants (fieldName) {
  var obj = $(fieldName);
	var url = home+page+"?page=listeDirigeants&field="+fieldName+"&dirigeant="+obj.value;
	var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+(popup_width)+",height="+(popup_height);
	var name = "POPUP";
	var popWin = window.open(url, name, options);
	popWin.focus();
	}
function popupVilles (fieldVille, fieldCp, fieldPays, defineJsDomain) {
  var objVille = $(fieldVille);
  var objCp = $(fieldCp);
  var objPays = $(fieldPays);
	var url = home+page+"?page=listeVilles&fieldVille="+fieldVille+"&fieldCp="+fieldCp+"&fieldPays="+fieldPays+"&defineJsDomain="+defineJsDomain+"&ville="+objVille.value+"&cp="+objCp.value+"&pays="+objPays.value;
	var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+(popup_width)+",height="+(popup_height);
	var name = "POPUP";
	var popWin = window.open(url, name, options);
	popWin.focus();
	}
function popupClubs (fieldName) {
  var obj = $(fieldName);
	var url = home+page+"?page=listeClubs&field="+fieldName+"&club="+obj.value;
	var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+(popup_width)+",height="+(popup_height);
	var name = "POPUP";
	var popWin = window.open(url, name, options);
	popWin.focus();
	}    
    

// Encodage de l'URL
function urlencode (str) {
    var newstr;
    newstr = str.replace (/&/g, "%26");
    return newstr;
}

//http://www.albionresearch.com/misc/urlencode.php
function URLEncode2(str) {
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = str;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;

};


// Suppression 
function actionDelete (url) {
  from = ""+self.location+"";
  from = urlencode(from);
  if(confirm("Etes-vous sûr ?"))
    self.location = url + "&from=" + from;
}
  
	
// Imprimer
function vprint () {
  from = ""+self.location+"";
	motif = /\?/;
	if (from.search(motif)==-1)
		var url = from+"?print=1";
	else
		var url = from+"&print=1";
//  openMini2 (url,380,465);
	var options = "toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=650,height=500";
	var name = "POPUP";
	var popWin = window.open(url, name, options);
	popWin.focus();
}

// Envoi ami 
function send_friend () {
  from = ""+self.location+"";
  from = urlencode(from);
	var url = home+page+"?page=send_friend&url="+from;
  openMini2 (url,410,465);
/*	var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=330,height=400";
	var name = "POPUP";
	var popWin = window.open(url, name, options);
	popWin.focus();
  */
}
  
function confirmAction (action, id) {
  from = ""+self.location+"";
  from = urlencode(from);
  if(confirm("Etes-vous sûr ?"))
    self.location = home+page+"?page=action&action="+action+"&id="+id+"&from=" + from;
}  
function confirmAlert (action, id) {
  from = ""+self.location+"";
  from = urlencode(from);
  if(confirm("Avertir les modérateurs ?"))
    self.location = home+page+"?page=action&action="+action+"&id="+id+"&from=" + from;
}  
function confirmUnalert (action, id) {
  from = ""+self.location+"";
  from = urlencode(from);
  if(confirm("Supprimer l'alerte ?"))
    self.location = home+page+"?page=action&action="+action+"&id="+id+"&from=" + from;
}  

function alerteContenu (login, login_id, quoi, id) {
  //from = ""+top.location+"";
  //from = urlencode(from);
	var url = home+page+"?page=alerte_contenu&login="+login+"&login_id="+login_id;
	if (quoi)	url += "&quoi="+(quoi);
	if (id)	url += "&id="+(id);
	height = (quoi) ? 370 : 440;
	openMini2 (url,470,height);
}    
function desalerteContenu (login, quoi, id) {
	if (quoi == "commArticle")
		self.location = page_blog+"?page=action&action=UNALERT_ARTICLE_COMMENT&id="+id;
	else if (quoi == "commPhoto")
		self.location = page_blog+"?page=action&action=UNALERT_PHOTO_COMMENT&id="+id;
	else if (quoi == "commLo")
		self.location = page_blog+"?page=action&action=UNALERT_LO_COMMENT&id="+id;
}  
  
function submitonce(theform) {
 if (document.all || document.getElementById) {
  // hunt down "submit" and "reset"
  for (i=0;i<theform.length;i++) {
   var tempobj=theform.elements[i];
   if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") {
    tempobj.disabled=true;
   }
  }
 }
}



function askConfirm (libelle, url) {
  from = ""+top.location+"";
  from = urlencode(from);
  if(confirm(libelle))
//    top.location = url;
    top.location = url+"&from=" + from;
}  

/* Mini popup */
function openMini (url) {
    var name = "openmini";
    var options = "height="+(popup_height)+",width="+(popup_width)+",toolbar=yes,menubar=yes,scrollbars=yes,resizable=no,location=no,directories=no,status=no";
    a = window.open (url, name, options);
    a.focus();
}

/* Mini popup */
function openMini2 (url,width,height) {
    var name = "openmini2";
    var options = "height="+height+",width="+width+",toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=no,directories=no,status=no";
    a = window.open (url, name, options);
    a.focus();
}

/* PHOTOS ARTICLES */
// Ouverture de la fenêtre avec choix des photos
function browseArtImages () {
  var id = getRef ("photo_id");
	var url = home+page+"?page=listePhotos&selected_id="+id.value;
	var name = "";
	var options = "height=650,width=765,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no";
	a = window.open (url, name, options);
	a.focus();
	//window.open (url);
}
// Positionnement de l'image lors de l'édition d'un article
function setArtImage (photo_id, photo_folder, photo_file) {
  var id = getRef ("photo_id");
  var legende = getRef ("photo_legende");
  var preview = getRef ("preview");
  id.value = photo_id;
	if (!photo_id)  { imageSrc = static_url+"/img/alpha.gif"; legende.value=""; }
	else            imageSrc = "/photo.php?folder="+photo_folder+"&file="+photo_file+"&size=180";
	preview.src = imageSrc;
}


// Vérifie que la longueur d'un objet ne dépasse pas un certain nb de caractères
function checkLongueur (objet, max_limite) {
    if (objet.value.length>max_limite) {
        alert (""+max_limite+" caractères maximum !");
        objet.value = objet.value.substr(0,max_limite);
    }
}

function checkNoteNews (form) {
	var msg="", obj=form.note, trouve=false;
	for (var i=0 ; i<obj.length && trouve==false ; i++)
		if (obj[i].checked) trouve=true;
	if (!trouve) msg += "Choisissez une note !\n";
	if (msg != "")	alert (msg);
	else			form.submit();
	return false;
}


function checkFormSondage (form) {
	var msg="", obj=form.id_choix, trouve=false;
	for (var i=0 ; i<obj.length && trouve==false ; i++)
		if (obj[i].checked) trouve=obj[i].value;
	if (!trouve) msg += "Choisissez une réponse !\n";
	if (msg != "")	alert (msg);
	else {
		//form.submit();
		var url = page;
		var pars = 'page=vote&id_sondage='+form.id_sondage.value+'&id_choix='+trouve;
	  var myAjax = new Ajax.Updater(
			'formSondage',
	    url,
	    {
				method: 'get',
				parameters: pars,
				onFailure: ajaxError
			}
	 	);
	}
	return false;
}
function sondageViewForm (id) {
	var url = page;
	var pars = 'page=action&action=AJAX_SONDAGE_FORM&id='+id;
  var myAjax = new Ajax.Updater(
		'formSondage',
    url,
    {
			method: 'get',
			parameters: pars,
			onFailure: ajaxError
		}
 	);
}
function sondageViewResult (id) {
	var url = page;
	var pars = 'page=action&action=AJAX_SONDAGE_RESULT&id='+id;
  var myAjax = new Ajax.Updater(
		'formSondage',
    url,
    {
			method: 'get',
			parameters: pars,
			onFailure: ajaxError
		}
 	);
}


/* Photo de la table photos_files */
function popupPhoto (folder, file, size, width, height) {
    var url = home+page+"?page=photo&folder="+folder+"&file="+file+"&size="+size;
    var name = "openmini";
    var options = "height="+(height+107)+",width="+(width+12)+",toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,directories=no,status=no";
    a = window.open (url, name, options);
    a.focus();
}
/* Photo de la table photos_files */
function popupPhotoId (id, size, width, height, folder) {
    var url = home+page+"?page=photo&id="+id+"&size="+size;
		if (folder)
			url += '&folder='+folder;
    var name = "openmini";
    var options = "height="+(height+107)+",width="+(width+12)+",toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,directories=no,status=no";
    a = window.open (url, name, options);
    a.focus();
}

/* Stammtisch */
function stammtisch (width) {
    var url = home+page+"?page=stammtisch_read";
    var name = "stammtisch";
    var options = "height=550,width="+width+",toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,directories=no,status=no";
    a = window.open (url, name, options);
    a.focus();
}

function disp_addr (addr, domain, attribs, libelle) {
	document.write ("<A HREF=\"javascript:add_link('"+addr+"', '"+domain+"');\" "+attribs+">");
	if (libelle)	document.write (libelle);
	else					document.write (addr + "&#64;" + domain);
	document.write ("</A>");
}

function add_link (addr, domain) {
	var l = "mai"+"lto:"+addr+"@"+domain;
	self.location = l;
}

function search_focus (sens,obj,defaut) {
	if (sens=="on" && obj.value==defaut)
		obj.value="";
	else if (sens=="off" && obj.value=="")
		obj.value=defaut;
}

function bb_load_image (img, maxi) {

	//if (img.width) {
		if (img.width > maxi || img.height > maxi) {
			if ((img.width / img.height) > (maxi/maxi))
				img.width=maxi;
			else
				img.height=maxi;
		}
	//} else {
		//alert ("-");
	//}
}


// Source : http://pompage.net/pompe/pieds/
function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') { //Non-IE
        windowHeight=window.innerHeight;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientHeight) { //IE 6+ in 'standards compliant mode'
         windowHeight = document.documentElement.clientHeight;
    }
    else { //IE 4 compatible
     if (document.body&&document.body.clientHeight) {
         windowHeight=document.body.clientHeight;
      }
     }
    }
    return windowHeight;
}

// Source : http://pompage.net/pompe/pieds/
function getWindowWidth() {
    var windowWidth=0;
    if (typeof(window.innerWidth)=='number') {
        windowWidth=window.innerWidth;
    }
    else {
     if (document.documentElement&&
       document.documentElement.clientWidth) {
         windowWidth = document.documentElement.clientWidth;
    }
    else {
     if (document.body&&document.body.clientWidth) {
         windowWidth=document.body.clientWidth;
      }
     }
    }
    return windowWidth;
}

// Issu de http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function viewAllConnectes() {
  var url = page;
  var parametres = 'page=connectes';
  var myAjax = new Ajax.Updater(
  	'allConnectes',
  	url,
  	{
  	method: 'get',
  	parameters: parametres,
  	onFailure: viewAllConnectesError,
    onComplete: viewAllConnectesOk
  	}
  );
}
function viewAllConnectesError(requete) {
		alert('Erreur / viewAllConnectesError');
}
function viewAllConnectesOk (requete) {
    //document.getElementById('allConnectes').style.display ="block";
    new Effect.Appear('allConnectes', 1);
}
function closeAllConnectes () {
    //document.getElementById('allConnectes').style.display ="none";
    new Effect.Fade('allConnectes', 1);
}

function stammSubmit (form) {
  //form.style.display = "none";
  
  var stammWait = getRef ('stammWait');
  stammWait.className = 'SHOW';
  var stammForm = getRef ('stammForm');
  stammForm.className = 'HIDDEN';
  var url = page;
  var pars = 'page=action&action=MINICHAT_WRITE&message='+stammUrlEncode(form.message_stammtisch.value);
	
  var myAjax = new Ajax.Request(
  url,
  {
  	method: 'post',
	  parameters: pars,
		onComplete: stammSubmitOk,
 		onFailure: stammSubmitError
  }
 	);
  
  return false;
}


/* Résultat */
function stammSubmitOk (originalRequest) {
	tab = originalRequest.responseText.split('|');
	is_kicked = tab[0];
	text = tab[1];
	if (is_kicked==1) {
		top.location = home+page+'?page=accountLogout&mode=kick';
	}
	
	$('divStamm').innerHTML = text;
  var stammWait = $('stammWait');
	stammWait.className = 'HIDDEN';
	var stammForm = $('stammForm');
	stammForm.className = 'SHOW';
  var formStamm = $('formStamm');
	//alert (originalRequest.responseText);
	if (text.substr(0,10) != '<div style')
		formStamm.message_stammtisch.value = '';
  //formPost.style.display = "";
	formStamm.message_stammtisch.focus();
}

/* En cas d'erreur */
function stammSubmitError (request) {
	alert('Erreur (stammSubmitError)');
}

/* Actualisation du stammtisch */
function stammRefresh () {
  var divStamm = $('divStamm');
  var stammWait = $('stammWait');
  divStamm.innerHTML = stammWait.innerHTML;
  var url = page;
  var pars = 'page=action&action=MINICHAT_REFRESH';
  var myAjax = new Ajax.Updater(
  'divStamm',
  url,
  {
  	method: 'get',
	  parameters: pars,
		onComplete: stammRefreshOk,
 		onFailure: stammRefreshError
  }
 	);
}
/* Résultat */
function stammRefreshOk (originalRequest) {
}
/* En cas d'erreur */
function stammRefreshError (request) {
	alert('Erreur (stammRefreshError)');
}

function stammUrlEncode (str) {
  str = str.replace ("€", "&#8364;");
  str = str.replace ("’", "'"); // Ou &#8217;
  /*
  str = str.replace (/&/g, "%26");
  str = str.replace (/\+/g, "%2B");
  */
  str = encodeURIComponent (str);
	return str;
}

function popupMP () {
	var E = $("divMP");
  E.style.display = "block";
  E.innerHTML = '<div style="margin:2px; text-align:center;">'+loading_txt+'<br /><img src="'+static_url+'/img/loading1.gif" width="16" height="16" alt="Chargement" vspace="4" /></div>';
	var url = page;
	var pars = 'page=accountMessagesPopup';
	var myAjax = new Ajax.Updater(
		'divMP',
    url,
    {
			method: 'get',
			parameters: pars,
			onFailure: clickPhotoError
		}
 	);
}
function closePopupMP () {
	var E = getRef("divMP");
  E.style.display = "none";
}


function toggleObject (name) {
  Element.toggle(name);
}


var draft_timer;

function draft_timer (field, value) {
   draft_timer = window.setInterval ("save_draft('"+field+"', '"+value+"')",1000*draft_delay);
}

function save_draft (field, value) {
	var valueTxt = getRef(value);
	var url = page;
	var pars = 'page=action&action=AJAX_SAVE_DRAFT&field='+field+'&value='+stammUrlEncode(valueTxt.value);
	var myAjax = new Ajax.Updater(
		'draft_status',
    url,
    {
			method: 'post',
			parameters: pars
		}
 	);
}
function delete_draft (field, next_url) {
	window.clearInterval(draft_timer);
	var url = page;
	var pars = 'page=action&action=AJAX_DELETE_DRAFT&field='+field;
	var myAjax = new Ajax.Request(
		url,
    {
			asynchronous: true,
			method: 'post',
			parameters: pars,
			onSuccess: delete_draft_next(next_url)
		}
 	);
}

function delete_draft_next (next_url) {
	self.location = next_url;
}


function showUsersMatch() {
	if (is_ie) {
		hisScroll = getScrollXY();
		$('cachePage').style.top = hisScroll[1]+"px";
		$('cachePage').style.height = getWindowHeight()+"px";
	}
	$('usersViewMatch').style.display ="block";
	$('cachePage').style.display ="block";
}

function hideUsersMatch(zone) {
	$(zone).style.display ="none";
	$('cachePage').style.display ="none";
}

function isNumeric (sText, withZero){
	if (withZero)	var ValidChars = "0123456789";
	else					var ValidChars = "123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}


function in_array (tab, val) {
//	alert ("tab="+tab+" / val="+val);
	for (j=0 ; j<tab.length ; j++) {
  	if (tab[j] == val)
			return true;
	}
	return false;
}


function trim(string) {
	return string.replace(/(^\s*)|(\s*$)/g,'');
}

function ajaxError () {
	alert ('ajaxError');
}


function ajaxUpdateNbMps () {
	var url = page;
	var pars = 'page=action&action=AJAX_CALCUL_NB_MPS';
  var myAjax = new Ajax.Updater(
		'nbMps',
    url,
    {
			method: 'get',
			parameters: pars,
			onFailure: ajaxError
		}
 	);
}

function ieFooter () {
	//if (!is_ie) return;
	var obj = $('footer1');
	if (obj) {
		obj.style.position = 'absolute';
		obj.style.bottom = '77px';
	}
	var obj = $('footer2');
	if (obj) {
		obj.style.position = 'absolute';
		obj.style.bottom = '0';
	}
}

function ieFooterPopup () {
	//if (!is_ie) return;
	var obj = $('footerPopup');
	if (obj) {
		obj.style.position = 'absolute';
		obj.style.bottom = '0px';
	}
}

// Repris de http://blog.bigsmoke.us/2007/02/18/automatic-html-textarea-resizing
function resizeTextarea(t) {
  if ( !t.initialRows ) t.initialRows = t.rows;
  a = t.value.split('\n');
  b=0;
  for (x=0; x < a.length; x++) {
    if (a[x].length >= t.cols) b+= Math.floor(a[x].length / t.cols);
  }
  b += a.length;
	if (agt.indexOf('opera') != -1) b += 2;
	else if (is_ie) b += 1;

  if (b > t.rows || b < t.rows)
    t.rows = (b < t.initialRows ? t.initialRows : b);
}

function fbs_click() { u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false; }

function delicious_click() { u=location.href;t=document.title;window.open('http://del.icio.us/post?url='+encodeURIComponent(u)+'&title='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false; }

function twitter_click() { u=location.href;t=document.title; window.open('http://www.twitter.com/home?status='+URLEncode2(t+' ')+urlencode(u),'sharer','toolbar=0,status=0,width=800,height=500'); return false; }

// TOOLTIP

// Source : http://www.flickr.com/photos/upload/
function init_tooltip() {
	g_tooltip_inner_elm = document.createElement("DIV");
	g_tooltip_elm = document.createElement("DIV");
	g_tooltip_elm.className = "blog_tooltip";
	g_tooltip_elm.style.display = "none";
	document.body.appendChild (g_tooltip_elm);
	g_tooltip_elm.appendChild (g_tooltip_inner_elm);
}
	
function show_tooltip (obj, name, width) {
	if (!g_tooltip_elm)
		init_tooltip();
	if (g_tooltip_showing)
		hide_tooltip();
	
	w = width;
	x=lastMouseX;
	y=lastMouseY;
	g_tooltip_inner_elm.style.width=w+"px";
	var windowWidth = getWindowWidth()-40;
	if(x+w>windowWidth) x = windowWidth-w;
	g_tooltip_elm.style.left=x+"px";
	g_tooltip_elm.style.top=(y+16)+"px";
	g_tip_elm=document.getElementById(name);
	g_tooltip_inner_elm.innerHTML=g_tip_elm.innerHTML;
	g_tooltip_elm.style.display="block";

}


function hide_tooltip () {
	//document.onmousedown=function() {};
	if(!g_tooltip_elm)
		return false;
	g_tooltip_showing=0;
	g_tooltip_elm.style.display="none";
	return false;
}

function show_tooltip2 (obj, name, width) {
	if (obj = $(name)) {
		obj.style.display = 'block';
	}

}
function hide_tooltip2 (name) {
	if (obj = $(name)) {
		obj.style.display = 'none';
	}
}

function implode (glue, array) {
	var res = '';
	for (i=0 ; i<array.length ; i++) {
		if (i) res += glue;
		res += array[i];
	}
	return res;
}


function alertFiche (type,id) {
	if (type != 'personne' && type != 'match' && type != 'club' && type != 'article')
		return;
	$('cachePage').style.display ="block";
	div = 'formFicheAlert';
	if (type == 'match') {
		showUsersMatch();
		div = 'usersViewMatch';
	} else {
		$('formFicheAlert').style.display ="block";
		$('formFicheAlert').style.top = ""+(document.documentElement.scrollTop+300) + "px";
	}

	//alert (document.documentElement.scrollTop);
	//$('formFicheAlert').style.top = "600px;";


	var url = page;
	var pars = 'page=action&action=AJAX_ALERT_FICHE&type='+type+'&id='+id;
	var myAjax = new Ajax.Updater(
		div,
    url,
    {
			method: 'get',
			parameters: pars,
			onComplete: alertFicheOnComplete
		}
 	);
}
function alertFicheOnComplete () {
	if (form = ($('formFicheAlert_form'))) {
		if (!form.auteur_nom.value)
			form.auteur_nom.focus();
		else if (!form.message.value)
			form.message.focus();
	}
}


function alertFicheClose (type) {
	if (type=='match')
		hideUsersMatch('usersViewMatch');
	else {
		$('formFicheAlert').style.display ="none";
		$('cachePage').style.display ="none";
	}
}


function alertFicheSubmit (type,id,form) {
	if (type != 'personne' && type != 'match' && type != 'club' && type != 'article')
		return false;
	var url = page;
	div = 'formFicheAlert';
	if (type == 'match') {
		div = 'usersViewMatch';
	}
	var pars = 'page=action&action=AJAX_ALERT_FICHE&type='+type+'&id='+id;
	//pars += '&message='+urlencode(form.message.value);
	pars += '&message='+stammUrlEncode(form.message.value);
	pars += '&auteur_nom='+urlencode(form.auteur_nom.value);
	pars += '&auteur_email='+urlencode(form.auteur_email.value);
	//pars += '&site1='+urlencode(form.site1.value);
	pars += '&site2='+urlencode(form.site2.value);
	pars += '&from='+urlencode(escape(window.location.href));
	var myAjax = new Ajax.Updater(
		div,
    url,
    {
			method: 'post',
			parameters: pars
		}
 	);
	return false;
}



function html_entity_decode (string, quote_style) {
	
    // http://kevin.vanzonneveld.net
    // +   original by: john (http://www.jd-tech.net)
    // +      input by: ger
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: marc andreu
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Ratheous
    // -    depends on: get_html_translation_table
    // *     example 1: html_entity_decode('Kevin &amp; van Zonneveld');
    // *     returns 1: 'Kevin & van Zonneveld'
    // *     example 2: html_entity_decode('&amp;lt;');
    // *     returns 2: '&lt;'
 
    var hash_map = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
 
    for (symbol in hash_map) {
        entity = hash_map[symbol];
        tmp_str = tmp_str.split(entity).join(symbol);
    }
    tmp_str = tmp_str.split('&#039;').join("'");
    
    return tmp_str;
}


function get_html_translation_table (table, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco
    // +   bugfixed by: madipta
    // +   improved by: KELAN
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Frank Forte
    // +   bugfixed by: T.Wild
    // +      input by: Ratheous
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js, meaning the constants are not
    // %          note: real constants, but strings instead. Integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, hash_map = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';
 
    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
 
    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
        throw new Error("Table: "+useTable+' not supported');
        // return false;
    }
 
    entities['38'] = '&amp;';
    if (useTable === 'HTML_ENTITIES') {
        entities['160'] = '&nbsp;';
        entities['161'] = '&iexcl;';
        entities['162'] = '&cent;';
        entities['163'] = '&pound;';
        entities['164'] = '&curren;';
        entities['165'] = '&yen;';
        entities['166'] = '&brvbar;';
        entities['167'] = '&sect;';
        entities['168'] = '&uml;';
        entities['169'] = '&copy;';
        entities['170'] = '&ordf;';
        entities['171'] = '&laquo;';
        entities['172'] = '&not;';
        entities['173'] = '&shy;';
        entities['174'] = '&reg;';
        entities['175'] = '&macr;';
        entities['176'] = '&deg;';
        entities['177'] = '&plusmn;';
        entities['178'] = '&sup2;';
        entities['179'] = '&sup3;';
        entities['180'] = '&acute;';
        entities['181'] = '&micro;';
        entities['182'] = '&para;';
        entities['183'] = '&middot;';
        entities['184'] = '&cedil;';
        entities['185'] = '&sup1;';
        entities['186'] = '&ordm;';
        entities['187'] = '&raquo;';
        entities['188'] = '&frac14;';
        entities['189'] = '&frac12;';
        entities['190'] = '&frac34;';
        entities['191'] = '&iquest;';
        entities['192'] = '&Agrave;';
        entities['193'] = '&Aacute;';
        entities['194'] = '&Acirc;';
        entities['195'] = '&Atilde;';
        entities['196'] = '&Auml;';
        entities['197'] = '&Aring;';
        entities['198'] = '&AElig;';
        entities['199'] = '&Ccedil;';
        entities['200'] = '&Egrave;';
        entities['201'] = '&Eacute;';
        entities['202'] = '&Ecirc;';
        entities['203'] = '&Euml;';
        entities['204'] = '&Igrave;';
        entities['205'] = '&Iacute;';
        entities['206'] = '&Icirc;';
        entities['207'] = '&Iuml;';
        entities['208'] = '&ETH;';
        entities['209'] = '&Ntilde;';
        entities['210'] = '&Ograve;';
        entities['211'] = '&Oacute;';
        entities['212'] = '&Ocirc;';
        entities['213'] = '&Otilde;';
        entities['214'] = '&Ouml;';
        entities['215'] = '&times;';
        entities['216'] = '&Oslash;';
        entities['217'] = '&Ugrave;';
        entities['218'] = '&Uacute;';
        entities['219'] = '&Ucirc;';
        entities['220'] = '&Uuml;';
        entities['221'] = '&Yacute;';
        entities['222'] = '&THORN;';
        entities['223'] = '&szlig;';
        entities['224'] = '&agrave;';
        entities['225'] = '&aacute;';
        entities['226'] = '&acirc;';
        entities['227'] = '&atilde;';
        entities['228'] = '&auml;';
        entities['229'] = '&aring;';
        entities['230'] = '&aelig;';
        entities['231'] = '&ccedil;';
        entities['232'] = '&egrave;';
        entities['233'] = '&eacute;';
        entities['234'] = '&ecirc;';
        entities['235'] = '&euml;';
        entities['236'] = '&igrave;';
        entities['237'] = '&iacute;';
        entities['238'] = '&icirc;';
        entities['239'] = '&iuml;';
        entities['240'] = '&eth;';
        entities['241'] = '&ntilde;';
        entities['242'] = '&ograve;';
        entities['243'] = '&oacute;';
        entities['244'] = '&ocirc;';
        entities['245'] = '&otilde;';
        entities['246'] = '&ouml;';
        entities['247'] = '&divide;';
        entities['248'] = '&oslash;';
        entities['249'] = '&ugrave;';
        entities['250'] = '&uacute;';
        entities['251'] = '&ucirc;';
        entities['252'] = '&uuml;';
        entities['253'] = '&yacute;';
        entities['254'] = '&thorn;';
        entities['255'] = '&yuml;';
    }
 
    if (useQuoteStyle !== 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
    if (useQuoteStyle === 'ENT_QUOTES') {
        entities['39'] = '&#39;';
    }
    entities['60'] = '&lt;';
    entities['62'] = '&gt;';
 
 
    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        hash_map[symbol] = entities[decimal];
    }
    
    return hash_map;
}

function effectToggle (div) {
	new Effect.toggle($(div),'appear', { duration: 0, delay: 0 });
}

function setValue (id, value) {
	if (obj=$(id))
		obj.value = value;
}



