
/**********************************************************************************************
	FONCTIONS GENERALES OUTILS
**********************************************************************************************/

function handleEnter (event) {var keyCode=event.keyCode?event.keyCode:event.which?event.which:event.charCode;if(keyCode == 13) {return false;}else{return true;}}
	
// Permet d'ajouter la fonction is_array en javascript
function is_array(input) {
	return typeof(input)=='object'&&(input instanceof Array);
}

/*	test du nagigateur*/
var msie = navigator.userAgent.indexOf('MSIE') != -1 ? true : false;

/* pour ie : on cache les selects qui ont un z-index supè±©eur ï¿½out les div existant */
function G_aff_select(visibl) {if(msie) {selects = document.getElementsByTagName("select");for (i = 0; i != selects.length; i++) {selects[i].style.visibility = visibl;}}}

/* renvoi les informations sur la page et le positionnement */
function G_getPageSize() {
	var xScroll, yScroll, vScroll, hScroll, windowWidth, windowHeight,pageWidth, pageHeight;
	if (window.innerHeight && window.scrollMaxY) {xScroll = document.body.scrollWidth;yScroll = window.innerHeight + window.scrollMaxY;}
	else if (document.body.scrollHeight > document.body.offsetHeight) {xScroll = document.body.scrollWidth;yScroll = document.body.scrollHeight;}
	else {xScroll = document.body.offsetWidth;yScroll = document.body.offsetHeight;}
	if (self.innerHeight) {windowWidth = self.innerWidth;windowHeight = self.innerHeight;}
	else if (document.documentElement && document.documentElement.clientHeight) {windowWidth = document.documentElement.clientWidth;windowHeight = document.documentElement.clientHeight;}
	else if (document.body) {windowWidth = document.body.clientWidth;windowHeight = document.body.clientHeight;}
	if(yScroll < windowHeight) {pageHeight = windowHeight;}else{pageHeight = yScroll;}
	if(xScroll < windowWidth) {pageWidth = windowWidth;}else{pageWidth = xScroll;}
	if (self.pageYOffset) {vScroll = self.pageYOffset; hScroll = self.pageXOffset;}
	else if (document.documentElement && document.documentElement.scrollTop) {vScroll = document.documentElement.scrollTop;hScroll = document.documentElement.scrollLeft;}
	else if (document.body) {vScroll = document.body.scrollTop;hScroll = document.body.scrollLeft;}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight, hScroll , vScroll);
	return arrayPageSize;
}

/* une petite pause s'impose pour ie */
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

/* crè ´ion en live de la BoxUp si n'existe pas.
	 <div id="overlay"></div>
	 <div id="MyBoxUp"><div id="MyBoxUpClose"><img src="../images/close.gif" onclick="" /></div>
		<div id="MyBoxUpFrame"></div>
	 </div>
*/

var BoxUpLeft="0";//left coordinate of boxup
var BoxUpTop="0";//top coordinate of buxup
var xpos=0; // mouse x position
var ypos=0; // mouse y position
var domStyle=null; // span DOM object with style

function initMyBoxUp() {
	if(!G_obj('MyBoxUp')) {
		var arrayPageSize = G_getPageSize();

		var objBody = document.getElementsByTagName("body").item(0);
		var objMyBoxUpOverlay = document.createElement("div");
		objMyBoxUpOverlay.setAttribute('id','overlay');
		objMyBoxUpOverlay.style.display = 'none';
		objMyBoxUpOverlay.style.position = 'absolute';
		objMyBoxUpOverlay.style.top = '0';
		objMyBoxUpOverlay.style.left = '0';
		objMyBoxUpOverlay.style.zIndex = '90';

		objBody.insertBefore(objMyBoxUpOverlay, objBody.firstChild);

		var objMyBoxUp = document.createElement("div");
		objMyBoxUp.setAttribute('id','MyBoxUp');
		objMyBoxUp.style.display = 'none';
		objMyBoxUp.style.position = 'absolute';
		objMyBoxUp.style.zIndex = '100';
		objBody.insertBefore(objMyBoxUp, objMyBoxUpOverlay.nextSibling);

		var objLink = document.createElement("div");
		objLink.setAttribute('id','MyBoxUpClose');
		objMyBoxUp.appendChild(objLink);

		var objLink1 = document.createElement("img");
		objLink1.setAttribute('id','MyBoxUpCloseImg');
		objLink1.setAttribute('alt','');
		objLink1.setAttribute('src','images/closeBtn.gif');
		objLink1.style.cursor = 'pointer';
		objLink1.onclick = function () {hideMyBoxUp(); return false;}
		objLink.appendChild(objLink1);

		var objFrame = document.createElement("iframe");
		objFrame.setAttribute('id','MyBoxUpFrame');
		objMyBoxUp.appendChild(objFrame);
	}
}

function BoxUpPickIt(evt) {
   // accesses the element that generates the event and retrieves its ID
   if (window.addEventListener) { // w3c
	  var objectID = evt.target.id;
      if (objectID.indexOf('MyBoxUpClose') != -1) {
         var dom = document.getElementById('MyBoxUp');
         BoxUpLeft=evt.pageX;
         BoxUpTop=evt.pageY;
				 G_obj('MyBoxUpFrame').style.display = 'none';

         if (dom.offsetLeft) {
           BoxUpLeft = (BoxUpLeft - dom.offsetLeft); BoxUpTop = (BoxUpTop - dom.offsetTop);
          }
       }
	  // get mouse position on click
	  xpos = (evt.pageX);
	  ypos = (evt.pageY);
	}
   else { // IE
	  var objectID = event.srcElement.id;
      BoxUpLeft=event.offsetX;
      BoxUpTop=(event.offsetY);
	  // get mouse position on click
	  var de = document.documentElement;
      var b = document.body;
      xpos = event.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
      ypos = event.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
   // verify if this is a valid element to pick
   if (objectID.indexOf('MyBoxUpClose') != -1) {
      domStyle = document.getElementById('MyBoxUp').style;
    }
   if (domStyle) {
      return false;
    }
   else {
      domStyle = null;
      return;
    }
 }

function BoxUpDragIt(evt) {
   if (domStyle) {
      if (window.Event) {
         domStyle.left = (evt.clientX-BoxUpLeft + document.body.scrollLeft)+'px';
         domStyle.top = (evt.clientY-BoxUpTop + document.body.scrollTop)+'px';
       }
      else {
         domStyle.left = (event.clientX-BoxUpLeft + document.body.scrollLeft)+'px';
         domStyle.top = (event.clientY-BoxUpTop + document.body.scrollTop)+'px';
       }
    pause(100);
    }
 }

function BoxUpDropIt() {
   if (domStyle) {
      domStyle = null;
			G_obj('MyBoxUpFrame').style.display = 'block';
    }
 }


/* Appel de la boxup. */

	function showMyBoxUp(MyBoxUpWidth, MyBoxUpHeight, MySrc) {
		initMyBoxUp();
		G_obj('MyBoxUpFrame').src = MySrc;
		pause(500);
		var arrayPageSize = G_getPageSize();
		if(MyBoxUpWidth == '') {MyBoxUpWidth = (arrayPageSize[0] > 100 ? arrayPageSize[0] - 100 : 50);}
		if(MyBoxUpHeight == '') {MyBoxUpHeight = (arrayPageSize[3] > 100 ? arrayPageSize[3] - 100 : 50);}

		G_obj('MyBoxUpFrame').style.height = (MyBoxUpHeight - 25) + 'px';

		G_obj('overlay').style.height = (arrayPageSize[1] + 'px');
		G_obj('overlay').style.width = arrayPageSize[0] + 'px';
		G_obj('overlay').style.display = 'block';
		var MyBoxUptop = arrayPageSize[5] + ((arrayPageSize[3] - MyBoxUpHeight) / 2);
		var MyBoxUpLeft = ((arrayPageSize[0] - MyBoxUpWidth) / 2);

		G_obj('MyBoxUp').style.top = (MyBoxUptop < 0) ? "0px" : MyBoxUptop + "px";
		G_obj('MyBoxUp').style.left = (MyBoxUpLeft < 0) ? "0px" : MyBoxUpLeft + "px";
    BoxUpLeft=(MyBoxUptop < 0) ? 0 : MyBoxUptop;
    BoxUpTop=(MyBoxUpLeft < 0) ? 0 : MyBoxUpLeft;

		G_obj('MyBoxUp').style.width = MyBoxUpWidth + (msie ? "":"px");
		G_obj('MyBoxUp').style.height = MyBoxUpHeight + (msie ? "":"px");
		if (msie) {pause(250);}
		G_aff_select('hidden');
		G_obj('MyBoxUp').style.display = 'block';
		document.onmousedown = BoxUpPickIt;
		document.onmousemove = BoxUpDragIt;
		document.onmouseup = BoxUpDropIt;
		}


/* appel box up local */

	function showMyBoxUpError(MyBoxUpWidth, MyBoxUpHeight, Mymess) {
		initMyBoxUp();
//		G_obj('MyBoxUpFrame').src = 'popup.php';
	  G_obj('MyBoxUpFrame').style.height = 'auto';
	  var testFrame = G_obj('MyBoxUpFrame');
    var doc = testFrame.contentDocument;
    if (doc == undefined || doc == null)
      doc = testFrame.contentWindow.document;

    doc.open();
    doc.innerHTML = '';
    doc.write('<?xml version="1.0" encoding="utf-8"?>');
    doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
    doc.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" dir="ltr" lang="fr">');
    doc.write('	<head>');
    doc.write('		<title></title>');
    doc.write('		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
    doc.write('		<link rel="stylesheet" href="style/default_popupalert.css" />');
    doc.write('	</head>');
    doc.write('	<body>');
    doc.write(stripslashes(Mymess));
    doc.write('	</body>');
    doc.write('	</html>');
    doc.close();
		var arrayPageSize = G_getPageSize();
		if(MyBoxUpWidth == '') {MyBoxUpWidth = (arrayPageSize[0] > 200 ? arrayPageSize[0] - 200 : 100);}
		if(MyBoxUpHeight == '') {MyBoxUpHeight = (arrayPageSize[3] > 200 ? arrayPageSize[3] - 200 : 100);}

		G_obj('overlay').style.height = (arrayPageSize[1] + 'px');
		G_obj('overlay').style.width = arrayPageSize[0] + 'px';
		G_obj('overlay').style.display = 'block';
		G_obj('overlay').onclick = function () {hideMyBoxUp(); return false;}

		var MyBoxUptop = arrayPageSize[5] + ((arrayPageSize[3] - MyBoxUpHeight) / 2);
		var MyBoxUpLeft = ((arrayPageSize[0] - MyBoxUpWidth) / 2);

		G_obj('MyBoxUp').style.top = (MyBoxUptop < 0) ? "0px" : MyBoxUptop + "px";
		G_obj('MyBoxUp').style.left = (MyBoxUpLeft < 0) ? "0px" : MyBoxUpLeft + "px";
		G_obj('MyBoxUp').style.width = MyBoxUpWidth + (msie ? "":"px");
		G_obj('MyBoxUp').style.height = MyBoxUpHeight + (msie ? "":"px");
		if (msie) {pause(250);}
		G_aff_select('hidden');
		G_obj('MyBoxUp').style.display = 'block';
		setTimeout("hideMyBoxUp();",5000);
		}



/* fermeture de la boxup. */

	function hideMyBoxUp() {
		G_obj('MyBoxUp').style.display = 'none';
		G_obj('MyBoxUpFrame').src = '';
		G_obj('overlay').style.display = 'none';
		G_obj('overlay').onclick = function () {};
		G_aff_select('visible');
		}

/* Selection des contacts. */

	function addContactList(uid, formulaire , champs) {
		var tmplistuid = document.forms[formulaire].elements[champs].value;
		var newlistuid = '';
		var nbnewuid = 0;
		if(tmplistuid == '') {
			newlistuid = uid;
			G_obj('member_'+uid).className = "Active";
			nbnewuid = 1;
			}
		else{
			listuid = tmplistuid.split(",");
			var nbuid = listuid.length;
			var present = false;
			for(i=0;i<nbuid;i++) {
				if(listuid[i] == uid) {
					// il est prè²¥nt : le supprimer
					present = true;
					G_obj('member_'+uid).className = "Inactive";
					}
				else{
					newlistuid = newlistuid+(newlistuid != '' ? ',':'')+listuid[i];
					nbnewuid++;
					}
				}
			if(present == false) {
				newlistuid = newlistuid+(newlistuid != '' ? ',':'')+uid;
				G_obj('member_'+uid).className = "Active";
				nbnewuid++;
				}
			}
		document.forms[formulaire].elements[champs].value = newlistuid;
		G_obj('nbReslut').innerHTML = nbnewuid;
		}

/* Ajout d'un selectform */

	function AddSelectId(champs , formulaire) {
		// recupè±¡tion du nombre de groupe total
		var TbIdGroup = document.forms[formulaire].elements['listid'].value.split('|');
		TbIdGroup.pop();
		var TbNomGroup = document.forms[formulaire].elements['listnom'].value.split('|');
		var nbtotalgroup = TbIdGroup.length;
		var usedgroup = new Array();
		var restgroup = new Array();
		restgroup = TbIdGroup;
		var restgroupname = new Array();
		var i;

		if(nbtotalgroup > 0) {
			restgroupname = new Array();
			for(i=0;i<nbtotalgroup;i++) {
				restgroupname[TbIdGroup[i]] = TbNomGroup[i];
				}
			}

		i=0;
		var k=0;
		while(G_obj('div_'+champs+i)) {
			var idtestgroup = document.forms[formulaire].elements[champs+''+i].options[document.forms[formulaire].elements[champs+''+i].selectedIndex].value;
			var addtmp = true;
			for(var j=0;j<usedgroup.length;j++) {if(usedgroup[j] == idtestgroup) {addtmp = false;}}
			if(addtmp == true) {
				usedgroup[k] = idtestgroup;
				k++;
				}
			i++;
			}

		var nbusedgroup = usedgroup.length;

		var objContent = G_obj('div_'+champs+'content');
		objContent.innerHTML = '';
		var k = 0;

		if(nbusedgroup > 0) {
			for(i=0;i<nbusedgroup;i++) {
				var nbrest = restgroup.length;
				if(usedgroup[i] != 'NULL' && nbrest > 0) {
					var objdiv = document.createElement("div");
					objdiv.setAttribute('id', 'div_'+champs+k);
					objdiv.className = 'divSelectContent';
					objContent.appendChild(objdiv);

					var objselect = document.createElement("select");
					objselect.setAttribute('name', champs+k);
					objselect.setAttribute('id', champs+k);
					objselect.style.width = '304px';
					objselect.onchange = function () {verifForm(document.forms[formulaire].elements[champs+k]);AddSelectId(champs , formulaire);}
					objdiv.appendChild(objselect);

					var objoption = document.createElement("option");
					objoption.setAttribute('value', 'NULL');
					objoption.innerHTML = 'Ajouter...';
					objselect.appendChild(objoption);

					for(j=0;j<nbrest;j++) {
						if(restgroup[j] != 'NULL') {
							var objoption = document.createElement("option");
							objoption.setAttribute('value', restgroup[j]);
							objoption.innerHTML = restgroupname[restgroup[j]];
							if(usedgroup[i] == restgroup[j]) {
								objoption.setAttribute('selected', 'selected');
								restgroup[j] = 'NULL';
								}
							objselect.appendChild(objoption);
							}
						}
					k++;
					}
				}
			}

		var affblank = 0;
		nbrest = restgroup.length;
		for(j=0;j<nbrest;j++) {if(restgroup[j] != 'NULL') {affblank = 1; break;}}

		if(affblank == 1) {
			var nbrest = restgroup.length;
			var objdiv = document.createElement("div");
			objdiv.setAttribute('id', 'div_'+champs+k);
			objdiv.className = 'divSelectContent';
			objContent.appendChild(objdiv);

			var objselect = document.createElement("select");
			objselect.setAttribute('name', champs+k);
					objselect.setAttribute('id', champs+k);
			objselect.style.width = '304px';
			objselect.onchange = function () {verifForm(document.forms[formulaire].elements[champs+k]);AddSelectId(champs , formulaire);}
			objdiv.appendChild(objselect);

			var objoption = document.createElement("option");
			objoption.setAttribute('value', 'NULL');
			objoption.innerHTML = 'Ajouter...';
			objoption.setAttribute('selected', 'selected');
			objselect.appendChild(objoption);

			for(j=0;j<nbrest;j++) {
				if(restgroup[j] != 'NULL') {
					var objoption = document.createElement("option");
					objoption.setAttribute('value', restgroup[j]);
					objoption.innerHTML = restgroupname[restgroup[j]];
					objselect.appendChild(objoption);
					}
				}
			}
		}

/* ouverture d'une page dans une nouvelle fené³²e */

	var NewWindow = '';
	function openWindow(MySrc) {
		if (!NewWindow.closed && NewWindow.location) {
			NewWindow.location.href = MySrc;
			NewWindow.focus();
			} else {
			NewWindow = this.open(MySrc,'_blank', '');
			}
		}

/* gestion des onglets */
	function ShowBoxFlip(noflip) {
		if(G_obj('BoxFlipContent')) {
			var Tabs = G_obj('BoxTabs').getElementsByTagName('li');
			var nbTabs = Tabs.length;
			for(var i=0;i<nbTabs;i++) {
				G_obj('BoxFlip_'+i).className = 'BoxFlip';
				Tabs[i].className = 'normal';
				}
			G_obj('BoxFlip_'+noflip).className = 'BoxFlipCurrent';
			Tabs[noflip].className = 'current';

			}
		}

	function UpdatePosition(champs, champsdest_name) {
		champs.form.elements[champsdest_name].options.length = 0;
			var choix=new Option('En premier', '');
		  champs.form.elements[champsdest_name].options[champs.form.elements[champsdest_name].options.length] = choix;

			if(champs.value != '') {
				if(TbCateg[champs.value]) {
					for(var i= 0;i <TbCateg[champs.value].length;i++) {
						if(TbCateg[champs.value][i] != undefined) {
							var choix=new Option('aprç± '+TbCateg[champs.value][i], i);
						  champs.form.elements[champsdest_name].options[champs.form.elements[champsdest_name].options.length] = choix;
						  }
						}
					}
				}
			}

	function OpenReply(mess) {
		if(G_obj('DivMessFils_'+mess)) {
			if(G_obj('DivMessFils_'+mess).style.display == 'block') {
				G_obj('DivMessFils_'+mess).style.display = 'none';
				}
			else{
				G_obj('DivMessFils_'+mess).style.display = 'block';
				}
			}
		}

	function CountAllMessage() {
		var tbParent = G_obj('messages').getElementsByTagName('ul');
		if(tbParent.length > 0) {
			for(i=0; i<tbParent.length;i++) {
				if(tbParent[i].id.substring(0,12) == 'DivMessFils_') {
					if(G_obj('DivMessNbFils_'+tbParent[i].id.substring(12))) {
						G_obj('DivMessNbFils_'+tbParent[i].id.substring(12)).innerHTML = CountMessage('DivMessFils_'+tbParent[i].id.substring(12));
						}
					}
				}
			}
//		G_obj('contentspecial').innerHTML = contentspecial;
		}

	function CountMessage(ide) {
		var numb = 0;
		var tab = G_obj(ide).getElementsByTagName('ul');
		if(tab.length > 0) {
			for(j=0; j<tab.length;j++) {
				if(tab[j].id.substring(0,14) == 'DivMessParent_') {numb++;}
				}
			}
		return numb;
		}

	function OpenMessageAdded() {
		if(MessAdded != '') {
			get_parent_mess(MessAdded , '');
			if(parent_found != '') {
				OpenAll(parent_found);
				OpenCorps(MessAdded , 1);
				}
			}
		}

	var parent_found = '';

	function get_parent_mess(id_mess , old_id) {
		var parent_mess = G_obj('DivMessParent_'+id_mess).parentNode;
		if(parent_mess.id != 'messages') {
			var new_id = parent_mess.id.split('_')[1];
			OpenCorps(new_id , 0);
			parent_found = new_id;
			get_parent_mess(new_id , id_mess);
			}
		}

	function OpenAll(mess) {
		if(mess == '') {
			var divsearch = 'messages';
			}
		else{
			var divsearch = 'DivMessFils_'+mess;
			G_obj('DivMessFils_'+mess).style.display = 'block';
//			G_obj('DivMessContent_'+mess).style.display = 'block';
			}

		var tbParent = G_obj(divsearch).getElementsByTagName('ul');

		if(tbParent.length > 0) {
			for(i=0; i<tbParent.length;i++) {
				if(tbParent[i].id.substring(0,12) == 'DivMessFils_') {
					tbParent[i].style.display = 'block';
//					G_obj('DivMessContent_'+tbParent[i].id.substring(12)).style.display = 'block';
					}
				else{
//					G_obj('DivMessContent_'+tbParent[i].id.substring(14)).style.display = 'block';
					}
				}
			}
		if(mess != '') {
//			window.location.href='#DivMess_'+mess;
			}
		G_obj('BtnOpenAll').style.display = 'none';
		G_obj('BtnCloseAll').style.display = 'block';
		}

	function CloseAll(mess) {
		var divsearch = 'messages';
		var tbParent = G_obj(divsearch).getElementsByTagName('ul');
		if(tbParent.length > 0) {
			for(i=0; i<tbParent.length;i++) {
				if(tbParent[i].id.substring(0,12) == 'DivMessFils_') {
					tbParent[i].style.display = 'none';
					}
				}
			}
		G_obj('BtnOpenAll').style.display = 'block';
		G_obj('BtnCloseAll').style.display = 'none';
		}

	function openDivMess(tbdiv) {
		}

	function OpenCorps(mess , act) {
		if(G_obj('DivMessContent_'+mess).style.display == 'block') {
			G_obj('DivMessContent_'+mess).style.display = 'none';
			G_obj('img_'+mess).src = 'images/right.gif';
			}
		else{
			if(G_obj('ImgRead_'+mess).src.substring(G_obj('ImgRead_'+mess).src.lastIndexOf('/')+1) == 'icn_favo_on.gif') {
				if(act == 1) {
					PostUpdateStatus(mess);
					}
				}
			G_obj('DivMessContent_'+mess).style.display = 'block';
			G_obj('img_'+mess).src = 'images/down.gif';
			}
		}

	function PostUpdateStatus(id_post) {
		if(id_post != '') {
			var xhr = getXhr();
			xhr.onreadystatechange = function() {
				if(xhr.readyState == 4 && xhr.status == 200) {
					if(xhr.responseText.trim() == 'false') {alert("erreur : "+xhr.responseText);}
					else{
						G_obj('ImgRead_'+id_post).src = 'images/icn_favo_'+(xhr.responseText.trim() == 1?'off':'on')+'.gif';
						}
					}
				}
			xhr.open("POST","?module=account&action=board_post",true);
			xhr.setRequestHeader( "Content-type" , "application/x-www-form-urlencoded" );
			xhr.send('update_post='+id_post);
			}
		}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
    	window.onload = func;
	} else {
		window.onload = function() {
		oldonload();
		func();
		}
	}
}

function AddElement(formulaire , dest , uid) {
	var listuid = document.forms[formulaire].elements[dest].value;
	if(uid.checked == true) {document.forms[formulaire].elements[dest].value = listuid + (listuid != '' ? ',':'') + uid.value;}
	else{var tbuid = listuid.split(',');var nb = tbuid.length;listuid = '';
		if(nb>0) {for(i=0;i<nb;i++) {if(tbuid[i] != uid.value) {listuid = listuid + (listuid != '' ? ',':'') + tbuid[i];}}}
		document.forms[formulaire].elements[dest].value = listuid;
		}
	verifForm(document.forms[formulaire].elements[dest]);
	}

function AjaxUpdateInfo(table , champs , ide , confirmation , val ) {
	var goin = false;
	if(confirmation) {
		if(!confirm(_JAVA_INFO))
			return false;
		else
			goin = true;
		}
	else
		goin = true;

	if(goin) {
		// On met en place les paramÃ¨tres
		var params = 'action=update&table='+table+'&champs='+champs+'&id='+ide+(val != 'undefined' ? '&value='+val+'' : '');

		// Envoi des données en AJAX
		var rep = $.ajax({ url: "?module=action",
				type: "POST",
				data: params,
				async: false
		}).responseText;
		if(rep=='') {
			var myJsonObj = new Array();
			myJsonObj['result'] = 'ok';
		} else {
			var myJsonObj = jsonParse(rep);
		}
		if(myJsonObj['result'] != 'ok') {
			alert(html_entity_decode(_JAVA_WAITTIME_ERROR));
		}else{
			if(table == 'users_questionnaire' || table == 'users_have_rf_right'|| table == 'users_test') {
				window.location.reload();
			}
			else{
				var rep = myJsonObj['item'];
				switch(champs) {
					case 'delete':
						if(table == 'par_quest_question' || table == 'par_quest_section' || table == 'users_test' || table == 'indication'
						|| table == 'par_quest_group' || table == 'par_quest_bloc' 	 || table == 'users_societe'
						|| table == 'group' 					 || table == 'users_group' 			 || table == 'users_questionnaire') {
							window.location.reload();
						}
						else if(table == 'societe_docs') {
							var myUrlNew = remove_target(window.location.href);
							window.location.href = myUrlNew+'&target=4';
						}
						else if(table == 'group_questionnaire') {
							var myUrlNew = remove_target(window.location.href);
							window.location.href = myUrlNew+'&target=3';
							}
						else if(table == 'societe_other_contact') {
							var myUrlNew = remove_target(window.location.href);
							window.location.href = myUrlNew+'&target=1';
							}
						else if(table == 'cat_inscription') {
							$('node_'+ide).remove();
							// Mise à jour du nombre d'inscrit pour chaque niveau
							$(".intitule").each(function() {
								$(this).children(".nbInscrits").text($(this).next(".contenu").find(".one_user").length);
							});
						}
						else if(table == 'quest_evafor1' || table == 'quest_evafor2' || table == 'quest_evafor3') {
							// On ne fait rien, et surtout pas de suppression de ligne puisque traité avec quest_evafor
						}
						else{
							if(rep == '1') {
								if(table == 'menu')
									var tr = $('#nodeenfant_'+ide);
								else if(table == 'menu_bloc')
									var tr = $('#nodeparent1_'+ide);
								else
									var tr = $('#node_'+ide);
								// On supprime la ligne
								tr.remove();
			/* special menu bloc ... */
								$('#nodeparent0_'+ide).remove();
								$('#nodeparent2_'+ide).remove();
							}
						}
						break;
					case 'pcqid':
					case 'memtype':
						if(table == 'user_to_rf') {
							var myUrlNew = remove_target(window.location.href);
							window.location.href = myUrlNew+'&target=2';
						}
						else if(table == 'rf_to_user') {
							var myUrlNew = remove_target(window.location.href);
							window.location.href = myUrlNew+'&target=1';
						}
						else{
							window.location.reload();
						}
						break;

					case 'active':
						G_obj('img_'+table+'_'+champs+'_'+ide).src = 'images/'+champs+'_'+rep+'.gif';
						break;

					case 'in_formation':
						if(G_obj('img_'+table+'_'+champs+'_'+ide)) {
							G_obj('img_'+table+'_'+champs+'_'+ide).src = 'images/'+champs+'_'+rep+'.gif';
							}
						else{
							if(G_obj('parent')) {
								var tbimg = G_obj('parent').getElementsByTagName('IMG');
								var nbimg = tbimg.length;
								for(var i=0;i<nbimg;i++) {
									if(tbimg[i].id) {
										var tbgr = tbimg[i].id.split("_");
										if(tbgr.length > 6) {
											if(tbgr[0] == "img" && tbgr[1] =="users" && tbgr[2] == "in" && tbgr[3] == "formation" && tbgr[5] == "formation" && tbgr[6] == ide) {
												tbimg[i].src = 'images/'+champs+'_'+rep+'.gif';
												}
											}
										}
									}
								}
							}
						break;
					case 'uid':
					case 'statut':
						if(table == 'decompte') {
							window.location.reload();
						}else if(table=='quest_evafor' && val==4) { // Valider
							$('#node_'+ide+'_valide').html('<input type="button" value="'+_JAVA_ARCHIVE+'" class="Activate" onclick="AjaxUpdateInfo(\''+table+'\' , \'statut\' , \''+ide+'\' , true , \'5\');AjaxUpdateInfo(\''+table+'1\' , \'statut\' , \''+ide+'\' , false , \'5\');AjaxUpdateInfo(\''+table+'2\' , \'statut\' , \''+ide+'\' , false , \'5\');AjaxUpdateInfo(\''+table+'3\' , \'statut\' , \''+ide+'\' , false , \'5\');" />');
						}else if(table=='quest_evafor' && val==5) { // Archiver
							$('#node_'+ide+'_valide').empty();
						}else{
							//G_obj('img_'+table+'_'+champs+'_'+ide).src = 'images/'+champs+'-'+rep+'.gif';
							$('#img_'+table+'_'+champs+'_'+ide).attr('src','images/'+champs+'_'+rep+'.gif');
							if(val==4) {
								$('#node_'+ide+'_update_statut').html('<input type="button" value="'+_JAVA_ARCHIVE+'" class="Activate" onclick="AjaxUpdateInfo(\''+table+'\' , \'statut\' , '+ide+' , true , 5);" />');
							}else if(val==5) {
								$('#node_'+ide+'_update_statut').html('');
							}
						}
						break;

					default:
						//G_obj('img_'+table+'_'+champs+'_'+ide).src = 'images/'+champs+'_'+rep+'.gif';
						$('#img_'+table+'_'+champs+'_'+ide).attr('src','images/'+champs+'_'+rep+'.gif');
						break;
				}
			}
		}
	}
}

function remove_target(MyUrl) {
	var reg = new RegExp("(&target=)[0-9]?", "ig");
	return MyUrl.replace( reg, "" );
	}

function removeNL(s) {
  r = "";
  for (i=0; i < s.length; i++) {
    if (s.charAt(i) != '\n' &&
        s.charAt(i) != '\r' &&
        s.charCodeAt(i) != 65279 &&
        s.charAt(i) != '\t') {
      r += s.charAt(i);
      }
    }
  return r;
  }

function AffBoxContener(idcontent) {
	var tbcontener = G_obj('boxtitle').getElementsByTagName('TH');
	var nbcontener = tbcontener.length;
	for(var i = 0;i < nbcontener ; i++) {
		G_obj('boxtitle_'+i).className = 'BoxTitleInactive';
		G_obj('boxcontener_'+i).style.display = 'none';
		}
	G_obj('boxtitle_'+idcontent).className = 'BoxTitleActive';
	G_obj('boxcontener_'+idcontent).style.display = 'block';
	}

function OpenNewWindow(Mywidth , Myheight , Myurl , Myname) {
  var top=(screen.height-Myheight)/2;
  var left=(screen.width-Mywidth)/2;
	this.open (Myurl, Myname, config='top = '+top+' , left='+left+' , height='+Myheight+', width='+Mywidth+', toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, directories=no, status=no');
	}


function in_array (needle, haystack, argStrict) {
    var key = '', strict = !!argStrict;
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
            	return true;
            }
        }
    }
     return false;
}

function array_diff () {
	   var arr1 = arguments[0], retArr = new Array;;
    var k1 = '', i = 1, k = '', arr = {};
    arr1keys:
    for (k1 in arr1) {
    	for (i = 1; i < arguments.length; i++) {
 				arr = arguments[i];
        for (k in arr) {
        	if (arr[k] === arr1[k1]) {
           	continue arr1keys;
          	}
         	}
        retArr[k1] = arr1[k1];
        }
      }
    return retArr;
		}

	function array_unique (inputArr) {
		var key = '', tmp_arr2 = new Array(), val = '';
    var __array_search = function (needle, haystack) {
        var fkey = '';
        for (fkey in haystack) {
            if (haystack.hasOwnProperty) {
            	if ((haystack[fkey] + '') === (needle + '')) {
                return fkey;
                }
            }
        }
        return false;
    };

    for (key in inputArr) {
        if (inputArr.hasOwnProperty) {
        	val = inputArr[key];
          if (false === __array_search(val, tmp_arr2)) {
            tmp_arr2[key] = val;
            }
        }
  	  }
    return tmp_arr2;
		}


function html_entity_decode(str) {
	 try{
		var tarea=document.createElement('textarea');
		tarea.innerHTML = str; return tarea.value;
		tarea.parentNode.removeChild(tarea);
		}
	catch(e) {
	 //for IE add <div id="htmlconverter" style="display:none;"></div> to the page
	 document.getElementById("htmlconverter").innerHTML = '<textarea id="innerConverter">' + str + '</textarea>';
	 var content = document.getElementById("innerConverter").value;
	 document.getElementById("htmlconverter").innerHTML = "";
	 return content;
	 }
 }

function array_search (needle, haystack, argStrict) {
  var strict = !!argStrict;
  var key = '';
  for (key in haystack) {
  	if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
       return key;
       }
    }
  return false;
	}

function array_multisort (arr) {
    var flags = {'SORT_REGULAR': 16, 'SORT_NUMERIC': 17, 'SORT_STRING': 18, 'SORT_ASC': 32, 'SORT_DESC': 40},    sortArrs = [[]], sortFlag = [0], sortKeys = [[]], g = 0, i = 0, j = 0, k = '', l = 0, thingsToSort = [], vkey = 0, zlast = null,
    args = arguments, nLastSort = [], lastSort = [], lastSorts = [], tmpArray = [], elIndex = 0, sortDuplicator = function (a, b) {
	     return nLastSort.shift();
    };
    var sortFunctions = [[function (a, b) {        lastSort.push(a > b ? 1 : (a < b ? -1 : 0));
        return a > b ? 1 : (a < b ? -1 : 0);
    }, function (a, b) {
        lastSort.push(b > a ? 1 : (b < a ? -1 : 0));
        return b > a ? 1 : (b < a ? -1 : 0);    }], [function (a, b) {
        lastSort.push(a - b);
        return a - b;
    }, function (a, b) {
        lastSort.push(b - a);        return b - a;
    }], [function (a, b) {
        lastSort.push((a + '') > (b + '') ? 1 : ((a + '') < (b + '') ? -1 : 0));
        return (a + '') > (b + '') ? 1 : ((a + '') < (b + '') ? -1 : 0);
    }, function (a, b) {        lastSort.push((b + '') > (a + '') ? 1 : ((b + '') < (a + '') ? -1 : 0));
        return (b + '') > (a + '') ? 1 : ((b + '') < (a + '') ? -1 : 0);
    }]];

    // Store first argument into sortArrs and sortKeys if an Object.    // First Argument should be either a Javascript Array or an Object, otherwise function would return FALSE like in PHP
    if (arr instanceof Array) {
        sortArrs[0] = arr;
    }
    else if (arr instanceof Object) {        for (i in arr) {
            if (arr.hasOwnProperty(i)) {
                sortKeys[0].push(i);
                sortArrs[0].push(arr[i]);
            }        }
    }
    else {
        return false;
    }



    var arrMainLength = sortArrs[0].length, sortComponents = [0, arrMainLength];
    for (j = 1; j < arguments.length; j++) {
        if (arguments[j] instanceof Array) {            sortArrs[j] = arguments[j];
            sortFlag[j] = 0;
            if (arguments[j].length !== arrMainLength) {
                return false;
            }        } else if (arguments[j] instanceof Object) {
            sortKeys[j] = [];
            sortArrs[j] = [];
            sortFlag[j] = 0;
            for (i in arguments[j]) {                if (arguments[j].hasOwnProperty(i)) {
                    sortKeys[j].push(i);
                    sortArrs[j].push(arguments[j][i]);
                }
            }            if (sortArrs[j].length !== arrMainLength) {
                return false;
            }
        } else if (typeof arguments[j] === 'string') {
            var lFlag = sortFlag.pop();            if (typeof flags[arguments[j]] === 'undefined' || ((((flags[arguments[j]]) >>> 4) & (lFlag >>> 4)) > 0)) {
                return false;
            }
            sortFlag.push(lFlag + flags[arguments[j]]);
        } else {            return false;
        }
    }

     for (i = 0; i !== arrMainLength; i++) {
        thingsToSort.push(true);
    }

    // Sort all the arrays....
    for (i in sortArrs) {
        if (sortArrs.hasOwnProperty(i)) {
            lastSorts = [];
            tmpArray = [];
            elIndex = 0;            nLastSort = [];
            lastSort = [];


            if (sortComponents.length === 0) {                if (arguments[i] instanceof Array) {
                    args[i] = sortArrs[i];
                }
                else {
                    for (k in arguments[i]) {                        if (arguments[i].hasOwnProperty(k)) {
                            delete arguments[i][k];
                        }
                    }
                    for (j = 0, vkey = 0; j < sortArrs[i].length; j++) {                        vkey = sortKeys[i][j];
                        args[i][vkey] = sortArrs[i][j];
                    }
                }
                delete sortArrs[i];                delete sortKeys[i];
                continue;
            }

            var sFunction = sortFunctions[(sortFlag[i] & 3)][((sortFlag[i] & 8) > 0) ? 1 : 0];

            // Sort current array.
            for (l = 0; l !== sortComponents.length; l += 2) {
                tmpArray = sortArrs[i].slice(sortComponents[l], sortComponents[l + 1] + 1);
                tmpArray.sort(sFunction);
                lastSorts[l] = [].concat(lastSort); // Is there a better way to copy an array in Javascript?
                elIndex = sortComponents[l];
                for (g in tmpArray) {
                    if (tmpArray.hasOwnProperty(g)) {                        sortArrs[i][elIndex] = tmpArray[g];
                        elIndex++;
                    }
                }
            }
            // Duplicate the sorting of the current array on future arrays.
            sFunction = sortDuplicator;
            for (j in sortArrs) {
                if (sortArrs.hasOwnProperty(j)) {                    if (sortArrs[j] === sortArrs[i]) {
                        continue;
                    }
                    for (l = 0; l !== sortComponents.length; l += 2) {
                        tmpArray = sortArrs[j].slice(sortComponents[l], sortComponents[l + 1] + 1);                        nLastSort = [].concat(lastSorts[l]); // alert(l + ':' + nLastSort);
                        tmpArray.sort(sFunction);
                        elIndex = sortComponents[l];
                        for (g in tmpArray) {
                            if (tmpArray.hasOwnProperty(g)) {                                sortArrs[j][elIndex] = tmpArray[g];
                                elIndex++;
                            }
                        }
                    }                }
            }

            // Duplicate the sorting of the current array on array keys
            for (j in sortKeys) {                if (sortKeys.hasOwnProperty(j)) {
                    for (l = 0; l !== sortComponents.length; l += 2) {
                        tmpArray = sortKeys[j].slice(sortComponents[l], sortComponents[l + 1] + 1);
                        nLastSort = [].concat(lastSorts[l]);
                        tmpArray.sort(sFunction);                        elIndex = sortComponents[l];
                        for (g in tmpArray) {
                            if (tmpArray.hasOwnProperty(g)) {
                                sortKeys[j][elIndex] = tmpArray[g];
                                elIndex++;                            }
                        }
                    }
                }
            }
            // Generate the next sortComponents
            zlast = null;
            sortComponents = [];
            for (j in sortArrs[i]) {                if (sortArrs[i].hasOwnProperty(j)) {
                    if (!thingsToSort[j]) {
                        if ((sortComponents.length & 1)) {
                            sortComponents.push(j - 1);
                        }                        zlast = null;
                        continue;
                    }
                    if (!(sortComponents.length & 1)) {
                        if (zlast !== null) {                            if (sortArrs[i][j] === zlast) {
                                sortComponents.push(j - 1);
                            }
                            else {
                                thingsToSort[j] = false;                            }
                        }
                        zlast = sortArrs[i][j];
                    } else {
                        if (sortArrs[i][j] !== zlast) {                            sortComponents.push(j - 1);
                            zlast = sortArrs[i][j];
                        }
                    }
                }            }

            if (sortComponents.length & 1) {
                sortComponents.push(j);
            }            if (arguments[i] instanceof Array) {
                args[i] = sortArrs[i];
            }
            else {
                for (j in arguments[i]) {                    if (arguments[i].hasOwnProperty(j)) {
                        delete arguments[i][j];
                    }
                }
                for (j = 0, vkey = 0; j < sortArrs[i].length; j++) {                    vkey = sortKeys[i][j];
                    args[i][vkey] = sortArrs[i][j];
                }

            }            delete sortArrs[i];
            delete sortKeys[i];
        }
    }
    return true;
    }

 function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}

function addslashes(str) {
str = str.replace(/\\/g,"\\\\")
str = str.replace(/\'/g,"\\'")
str = str.replace(/\"/g,"\\\"")
return str
}

function addslashes_doublequotes(str) {
str = str.replace(/\"/g,"\\\"")
return str
}


$(function() {
	$("#TheEditor input[type='text']").css('border' , '1px solid #1F96C0');
});

/**
 * Recherche un utilisateur via le filtre de la fenêtre AddUser
 */
userList_id = new Array();
userList_title = new Array();
userList_select = new Array();
function SearchUsers(colonne_name, user_type, select, parameter) {

	var value = $('#AddUserForm #search_'+colonne_name).val();

	if(value=='') { // Le champs filtre est vide
		$('#AddUserForm #select_'+colonne_name).empty();
	}
	else {
		// Ouverture de la fenetre d'attente
		if($('#SpecialWaitingTime').length == 0) {
			$('body').append('<div id="SpecialWaitingTime" title="'+_JAVA_WAITTIME_TITLE+'"><p>'+_JAVA_WAITTIME+'</p></div>');
			$("#SpecialWaitingTime").dialog({ autoOpen: false, draggable: false, resizable: false, modal: true, width: 400, zIndex: 2000 });
		}
		$('#SpecialWaitingTime').html('<p><img src="images/wait.gif" style="float: left; display: inline-block; margin-right: 10px;">'+_JAVA_WAITTIME+'</p>');
		$('#SpecialWaitingTime').dialog('open');

		var langue_id = $('#AddUserForm [name="langue"]').val(); // On récupÃ¨re la langue du select si elle éxiste

		if(langue_id=='' && $('#AddUserForm [name="langue"]').hasClass('required')) {
			$('#SpecialWaitingTime').html('<p>'+_JAVA_CHOISE_LANGUAGE+'</p>');
		}
		else {

			var params = 'action=getusers&search='+value+'&user_type='+user_type;

			if(langue_id!='undefined') {
				params += '&langue_id='+langue_id;
			}

			if(select) {
				params += '&select='+select+'&parameter='+parameter;
			}

			// Envoi des données en AJAX
			var rep = $.ajax({ url: "index.php?module=action",
					type: "POST",
					data: params,
					async: false
			}).responseText;
			var myJsonObj = jsonParse(rep);
			if(myJsonObj['result'] != 'ok') {
				$('#SpecialWaitingTime').html("<p>" + _JAVA_WAITTIME_ERROR + "</p>");
			}else{
				var item = myJsonObj['item'];

				// On vide le select
				$('#AddUserForm #select_'+colonne_name).empty();

				if(item.length == 0) { // Aucun résultat à afficher
					$('#SpecialWaitingTime').html('<p>'+_JAVA_NO_SELECTION+'</p>');
				}
				else { // Traitement des résultats
					var output = [];
					for(var i = 0 in item) {
						// Préparation du select
						output.push('<option value="'+ item[i].id +'">'+ item[i].nom +' '+ item[i].prenom+(item[i].societe ? ' ('+item[i].societe+')':'')+'</option>');

						// Sauvegarde les informations dans des tableaux
						if(!in_array(item[i].id, userList_id)) {
							userList_id.push(item[i].id);
							userList_title[(item[i].id)] = item[i].nom+' '+item[i].prenom;
							if(item[i].societe) {
								userList_title[(item[i].id)] += ' ('+item[i].societe+')';
							}
							if(item[i].select) {
								userList_select[(item[i].id)] = item[i].select;
							}
						}
					}
					// Mise en place du select
					$('#AddUserForm #select_'+colonne_name).html(output.join(''));

					// Fermeture de la fenetre d'attente
					$('#SpecialWaitingTime').dialog('close');
				}
			}
		}
	}
}

/**
 * Permet d'ajouter un utilisateur dans une fenetre AddUsers
 * \param column_name (string) Nom de la colonne. Ce nom permet de retrouver les champs liés
 * \param required (bool) Indique si le select (si il existe) est requis ou non
 */
column_verif = new Array();
column_select = new Array();
function AddUsers(column_name, required) {
	var id_list = $('#'+column_name).val();
	if(id_list != '') {
		id_list = id_list.split(',');
	}else{
		id_list = new Array();
	}
	$('#select_'+column_name+' option:selected').each(function() {
		var id = $(this).val();
		if(!in_array(id, id_list)) {
			id_list[id_list.length] = id;
			if(userList_select[id]) {
				var options = '';
				var selected = false;
				for(var i in userList_select[id]['options']) {
					options += '<option'+(i==userList_select[id]['default'] ? ' selected="selected"' : '')+' value="'+i+'">'+userList_select[id]['options'][i]+'</option>';
					if(i==userList_select[id]['default']) {
						selected = true;
					}
				}
				var class_name = '';
				if(selected) {
					class_name = 'answer';
				}
				if(required) {
					if(selected) {
						class_name = 'required answer';
					}else{
						class_name = 'required noanswer';
					}
				}
				// Mise en place du onchange sur le select si renseigné
				if(column_select[column_name] && typeof(column_select[column_name])!='undefined') {
					var onchange = ' onchange="'+column_select[column_name]+'"';
				}else{
					var onchange = '';
				}
				var select = '<select id="select_'+column_name+'_'+id+'" name="select_'+column_name+'_'+id+'" style="width:150px;"'+(class_name!='' ? 'class="'+class_name+'"' : '')+onchange+'><option value=""></option>'+options+'</select>';
				if(userList_select[id]['error'] && userList_select[id]['error']!='') {
					if($('#WaitingTime').length == 0) {
						$('body').append('<div id="WaitingTime" title="'+_JAVA_ATTENTION+'"></div>');
						$('#WaitingTime').dialog({ autoOpen: false, draggable: false, resizable: false, modal:true, width: 400 });
					}
					$('#WaitingTime').html('<p id="WaitingTimeContent">'+userList_select[id]['error']+'</p>');
					$('#WaitingTime').dialog('open');
				}
			}
			$('#table_'+column_name).append(
				'<tr id="'+column_name+'_'+id+'">'+
					'<td style="text-align:left; padding-left:4px; border-right:0px;">'+userList_title[id]+'</td>'+
					'<td style="text-align:right; border-left:0px; padding-right:4px;">'+(select ? select : '')+'</td>'+
					'<td style="text-align:center; width:30px;"><img src="images/icn_delete.gif" onclick="RemoveUser(\''+column_name+'\','+id+');" class="BtnAct" /></td>'+
				'</tr>');
		}
	});

	// Modification du champs hidden qui contient les ids des utilisateurs à ajouter
	$('#'+column_name).val(id_list.join(','));

	// Vérification du formulaire
	if(column_verif[column_name] && typeof(column_verif[column_name])!='undefined') {
		eval(column_verif[column_name]);
	}
}

/**
 * Permet de retirer un utilisateur dans une fenetre AddUsers
 * \param string column_name Nom de la colonne. Ce nom permet de retrouver les champs liés
 * \param int uid Id du membre que l'on désire retirer
 */
function RemoveUser(column_name,uid) {
	// On supprime la ligne du membre
	$('#table_'+column_name+' #'+column_name+'_'+uid).remove();

	// On enlève son id dans l'input
	var uid_list = $('#'+column_name).val().split(','); // On cré un tableau à partir du contenu de l'input
	var uid_index = 0; // index de l'uid recherché dans le tableau
	for (var i=0; i<uid_list.length; i++) {
	  	if (uid_list[i]== uid) {
	  		uidindex = i;
	  		break;
		}
	}
	uid_list.splice(uid_index, 1); // On supprime la ligne du tableau qui contient l'uid recherché
	$('#'+column_name).val(uid_list.join(','));

	// Vérification du formulaire
	if(column_verif[column_name] && typeof(column_verif[column_name])!='undefined') {
		eval(column_verif[column_name]);
	}
}

/**
 * Fonction standard pour vérifier le formulaire de la fenetre AddUsers
 * \param field_id (string|object) Objet ou id du champs à vérifier (optionnel)
 */
function AddUsersVerif(submit_action,field_id) {
	if(verifRequired('AddUserForm',field_id)) {
		$('#AddUserForm_BtnSubmit')
		.removeClass('InActivate')
		.addClass('Activate')
		.unbind('click')
		.click(function() {
			eval(stripslashes(submit_action));
		});
	}
	else{
		$('#AddUserForm_BtnSubmit')
		.removeClass('Activate')
		.addClass('InActivate')
		.unbind('click')
	}
}

/**
 * Réinitialise la fenêtre AddUsers
 */
function ResetAddUsers() {
	$('#AddUserForm')[0].reset(); // Réinitialisation du formulaire
	$('#AddUserForm table table').empty(); // On vide la table contenant la liste des membres sur lesquels on a déjà cliqué
	$('#AddUserForm table input:hidden').val(''); // On vide les champs cachés qui sauvegardaient les membres sur lesquels on a déjà cliqué
	$('#AddUserForm table select').empty(); // On vide la liste des membres obtenue par la recherche

}

/**
 * Appelé lorsqu'on clique sur "Afficher" dans le filtre de la class show_list
 * N'envoi en POST que les champs ayant une valeur
 */
function Filter() {
	var url=$('form[name=SearchEngine]').attr('action');
	$('.filter').each(function() {
		if($(this).attr('type')=='radio') {
			if($("#"+form_id+" [name="+$(this).attr('name')+"]").is(':checked')) { // On regarde si le champ est coché à partir du nom
				url += '&'+$(this).attr('name')+'='+$(this).val();
			}
		}
		else {
			if($(this).val()!='') {
				url += '&'+$(this).attr('name')+'='+$(this).val();
			}
		}
	});
	window.location.href = url;
}

function openBoxAjax(MyUrl , Mytitle , MyW , MyH, MyId) {
	if(MyW) {}else{
		var MyW = parseInt($(window).width())-200;
		if(MyW < 200) { MyW = 200;}
	}
	if(MyH) {}else{
		var MyH = parseInt($(window).height()) -50;
		if(MyH < 200) { MyH = 200;}
	}
	if(!MyId) {
		MyId = 'OpenBoxAjax';
	}
	if($('#'+MyId).length != 0) {
		$('#'+MyId).html('<p>Chargement en cours...</p>');
		//$(''+MyId).attr('title' , Mytitle);
	}else{
		$('body').append('<div id="'+MyId+'"><p>Chargement en cours...</p></div>');
	}
	$('#'+MyId).dialog({
		title: Mytitle,
		autoOpen: false,
		draggable: false,
		resizable: false,
		modal:true,
		width: MyW,
		minHeight: MyH,
		close: function () { $(this).dialog('destroy'); $(this).empty(); },
		open: function() { $(this).load(MyUrl, function() { $('body').css('cursor','auto'); }); } });
	$('#'+MyId).dialog('open'); // Ouverture de la fenÃªtre avant la fin du chargement de la page
}

function openBox(MyText , Mytitle , MyW , MyH, MyId) {
	if(MyW) {}else{
		var MyW = parseInt($(window).width())-200;
		if(MyW < 200) { MyW = 200;}
	}
	if(MyH) {}else{
		var MyH = parseInt($(window).height()) -50;
		if(MyH < 200) { MyH = 200;}
	}
	if(!MyId) {
		MyId = 'OpenBox';
	}
	if($('#'+MyId).length != 0) {
		$('#'+MyId).remove();
	}
	$("body").append('<div id="'+MyId+'"'+(Mytitle!='' ? ' title="'+Mytitle+'"' : '')+'></div>');
	$('#'+MyId).dialog({ autoOpen: false, draggable: false, resizable: false, modal:true, width: MyW, minHeight: MyH, open: function() { $('#'+MyId).html(MyText); } });
	$('#'+MyId).dialog('open');
}

/**
 * RécupÃ¨re un paramÃ¨tre dans l'url de la page
 * \param name (string) Nom du paramÃ¨tre à rechercher
 * \return (?) Retourne la valeur du paramÃ¨tre
 */
function getURLParameter(name) {
    return unescape(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}

function show_list_searchinfo(fieldName,fieldObject) {
	$('#searchrunning').html('<img src="images/wait.gif" />');
	var champs = $('#search_'+fieldName);

	if(champs.val().length > 1) {

		var params = 'action=show_list_searchinfo&type='+fieldObject+'&search='+champs.val();

		// Envoi des données en AJAX
		var rep = $.ajax({
			url: "index.php?module=action",
			type: "POST",
			data: params,
			async: false
		}).responseText;
		var myJsonObj = jsonParse(rep);
		if(myJsonObj.result != 'ok') {
			$('#searchrunning').html('');
			alert(html_entity_decode(_JAVA_WAITTIME_ERROR));
		}else{
			if(myJsonObj.item=='') {
				$('#'+fieldName).html('<option value="">'+_JAVA_NO_RESULT+'</option>');
			}
			else {
				$('#'+fieldName).html('<option value="">'+_JAVA_CHOOSE_IN+' '+myJsonObj.item.length+' '+_JAVA_RESULT+'</option>');

				for(var i in myJsonObj.item) {
					$('#'+fieldName).append('<option value="'+myJsonObj.item[i].value+'">'+myJsonObj.item[i].title+'</option>');
				}
			}
		}
	}
	else{
		// On indique qu'il faut taper au moins 2 caractÃ¨res
		$('#'+fieldName).html('<option value="">'+_JAVA_WAIT1+'</option>');
	}
	// On enlÃ¨ve le gif d'attente
	$('#searchrunning').html('');
}

/**
 * Permet l'affichage des zones de la carte Altran au survol de la carte
 */
function SelectArea(a) {$('#zone_'+a).css('visibility','visible')}
function UnselectArea(a) {$('#zone_'+a).css('visibility','hidden')}

/**
 * Permet de changer de page
 * A utiliser pour remplacer des liens (<a href=""></a>) par des boutons (<input type="button" onclick="" value="" />)
 */
function windowslocation(url) {
	window.location.href = url;
}

