
function magDemRel(rel){
	i = 0;
	if($$('tr[rel='+rel+']')[1] && $$('tr[rel='+rel+']')[1].getStyle('display') == "none"){
		($$('tr[rel='+rel+']')).each(function(item2){
			if(Prototype.Browser.IE) item2.setStyle({display:'block'});
			else					 item2.setStyle({display:'table-row'});

			new Effect.Morph(item2,{style:{backgroundColor:'#ffffcc'},duration:2, afterFinish:function(){

			}});
			/*item2.select('td').each(function(td){
				new Effect.Morph(td,{style:{backgroundColor:'#ffffcc'},duration:2, afterFinish:function(){
					new Effect.Morph(td,{style:{backgroundColor:'#fff'},duration:2});
				}});
			});
			*/

		});
	} else {
		($$('tr[rel='+rel+']')).each(function(item2){
			if(i == 0){
				oldStyle = item2.getStyle('backgroundColor');
				new Effect.Morph(item2,{style:{backgroundColor:'#ffffff'},duration:2, afterFinish:function(){

				}});
				/*
				item2.select('td').each(function(td){
					new Effect.Morph(td,{style:{backgroundColor:'#ccccff'},duration:2, afterFinish:function(){
						new Effect.Morph(td,{style:{backgroundColor:'#fff'},duration:2});
					}});
				});*/
			}
			if(i++ > 0)	{
				item2.setStyle({display:'none'});
			}
		});
	}
}
function videEns(){
	$('idens').value='';
	$('libens').value='';
}
function videMag(){
	$('idmag').value='';
	$('libmag').value='';
}
function selectEmailDemande(dem){
	$('dem').value = dem;
	$('lstDemandeMail').setStyle({ display: 'none'});
	$('email_dem_view').onclick=function(){
		modDemande(dem, "");
		return false;
	};
}
function showLstDemande(ens, mag){
	$('lstDemandeMail').setStyle({ display: 'block'});
	document.body.style.cursor = 'wait';
	new Ajax.Updater(	'lstDemandeMail',
							'ajax.autocomplete.demandes.php?ens='+ens+'&mag='+mag,
							{	method:'post',
								asynchronous:true,
								onComplete: function(){	document.body.style.cursor = 'default';	},
								onError:function(){$('relogin_user').innerHTML = "<h1>Erreur 404</h1><h2>Please contact the administrator</h2>";},
								evalScripts:true
							}
						);
}
function showModMagDem(idMag){
	document.body.style.cursor = 'wait';
	$('showModMagDem').update('<div align="center"><img src="img/loading2.gif" /></div>');
	new Ajax.Updater(	'showModMagDem',
							'ajax.show.mod.mag.dem.php?id='+idMag,
							{	method:'post',
								asynchronous:true,
								onComplete: function(){	document.body.style.cursor = 'default';	},
								onError:function(){$('showModMagDem').innerHTML = "<h1>Erreur 404</h1><h2>Please contact the administrator</h2>";},
								evalScripts:true
							}
						);
}
function showModDemMag(idDem, idLst){
	document.body.style.cursor = 'wait';
	$('showModDemMag').update('<div align="center"><img src="img/loading2.gif" /></div>');
	new Ajax.Updater(	'showModDemMag',
							'ajax.show.mod.dem.mag.php?id='+idDem+'&lst='+idLst,
							{	method:'post',
								asynchronous:true,
								onComplete: function(){	document.body.style.cursor = 'default';	},
								onError:function(){$('showModDemMag').innerHTML = "<h1>Erreur 404</h1><h2>Please contact the administrator</h2>";},
								evalScripts:true
							}
						);
}
//initialise la googlemap
function initialize(id) {
      if (GBrowserIsCompatible()) {
        map = new GMap2($(id+"_map_google"));
        map.setCenter(new GLatLng(47.15984, 2.988281), 5);
        geocoder = new GClientGeocoder();
        //map.setMapType(G_PHYSICAL_MAP);			// Vue relief
		map.addMapType(G_PHYSICAL_MAP);
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.enableDoubleClickZoom();
		map.enableContinuousZoom();
		new GKeyboardHandler(map);
      }
}
function showPuceItem(id, iLat, iLng){
	var  icon = new GIcon();
		 icon.image = "img/lightblue.png";
       	 icon.shadow= "img/mm_20_shadow.png";
		 icon.iconSize = new GSize(12, 20);
		 icon.shadowSize = new GSize(22, 20);
		 icon.iconAnchor = new GPoint(6, 20);
		 icon.infoWindowAnchor = new GPoint(5, 1);

	$(id+'_map_googleContent').style.display='block';
	map.clearOverlays();
	if(iLng.value != "" && iLat.value != ""){
		var point = new GLatLng(iLng.value, iLat.value)
	    if (!point) {
	        alert("L'adresse " + address + " est introuvable");
	    } else {
	       	map.setCenter(point, 16);
	       	var marker = new GMarker(point,{draggable: true, icon:icon, dragCrossMove:true});
	    	map.addOverlay(marker);
	        GEvent.addListener(marker, "drag", function() {
	  			var pointAdd=marker.getLatLng();
				iLat.value=pointAdd.x;
		        iLng.value=pointAdd.y;
			});
		}
	}
}
function searchAddress(id, address, iLat, iLng){
	var  icon = new GIcon();
		 icon.image = "img/lightblue.png";
       	 icon.shadow= "img/mm_20_shadow.png";
		 icon.iconSize = new GSize(12, 20);
		 icon.shadowSize = new GSize(22, 20);
		 icon.iconAnchor = new GPoint(6, 20);
		 icon.infoWindowAnchor = new GPoint(5, 1);

	$(id+'_map_googleContent').style.display='block';
	geocoder.getLatLng(address,
	function(point) {
		map.clearOverlays();
	    if (!point) {
	        alert("L'adresse " + address + " est introuvable");
	    } else {
	       	map.setCenter(point, 16);
	       	var marker = new GMarker(point,{draggable: true, icon:icon, dragCrossMove:true});
	    	map.addOverlay(marker);
	    	iLat.value=point.x;
	        iLng.value=point.y;
	        GEvent.addListener(marker, "drag", function() {
  				pointAdd=marker.getLatLng();
				iLat.value=pointAdd.x;
		        iLng.value=pointAdd.y;
  			});
		}
    });
}
	function ping(){
		var res;
		new Ajax.Request('ajax.ping.php?u='+(new Date()).getTime(), 	{
			asynchronous:false,
			onComplete: function(t) { res = (t.responseText == "true");	},
			onError: function() { alert("Connexion au serveur interrompue, veuillez rafraichir la page");	}
		});
		return res;
	}
	function ajaxReloadContentGlobal(){
	//	Windows.closeAll();
		var arrayPageSize = getPageSize();
		$('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1]+10 + 'px', top:'-10px' });
		new Effect.Appear('overlay', { duration: 1.0, from: 0.0, to: 0.8 });
		$('relogin').setStyle({
			display:'block',
			zIndex:'1000'});
		new Effect.Move($('relogin'), { x: 0, y: 0, mode: 'absolute' });
		document.body.style.cursor = 'wait';

		new Ajax.Updater(	'relogin_content',
							'ajax.login.php',
							{	method:'post',
								asynchronous:true,
								onComplete: function(){	document.body.style.cursor = 'default';	},
								onError:function(){$('relogin_content').innerHTML = "<h1>Erreur 404</h1><h2>Please contact the administrator</h2>";},
								evalScripts:true
							}
						);
	}
	function ajaxLoginSubmit(F){
		new Ajax.Request('ajax.login.submit.php', 	{
			method:'post',
			asynchronous:true,
			parameters:Form.serialize(F),
			onSuccess: function(t) {
				if(t.responseText != ""){
					alert(t.responseText);
				} else {
				/*
					document.body.style.cursor = 'wait';
					window.setTimeout(function(){
						new Effect.Fade('overlay', { duration: 1.0, from: 0.8, to: 0.0 });
						new Effect.Move($('relogin'), { x: 0, y: -600, mode: 'absolute', afterFinish:function(){
							$('relogin_content').innerHTML = '';
							$('relogin').style.display="none";
							document.body.style.cursor = 'default';
						} });
					},500);
				*/

					$('overlay').setOpacity(0).hide();
					new Effect.Move($('relogin'), { x: 0, y: -600, mode: 'absolute', afterFinish:function(){
						$('relogin_user').update('');
						$('relogin').hide();
					} });


				}
			},
			evalScripts:true
		});
		return false;
	}
	function switchEmailStatut(img, econt){
		new Ajax.Request("ajax.mod.email_statut.php?econt="+econt, 	{
				method:'post',
				asynchronous:true,
				onSuccess: function(t) {
					$$("img[id="+img.id+"]").each(function(item){
						item.src="img/"+(t.responseText);
					});

				},
				onComplete: function(){},
				evalScripts:true
			}
		);
	}
	function switchEmailStatut2(img, econt){
		new Ajax.Request("ajax.mod.email_statut2.php?econt="+econt, 	{
				method:'post',
				asynchronous:true,
				onSuccess: function(t) {
					$$("img[id="+img.id+"]").each(function(item){
						item.src="img/"+(t.responseText);
					});

				},
				onComplete: function(){},
				evalScripts:true
			}
		);
	}
	function switchEnsFicheMag(img, mag, ens){
		new Ajax.Request("ajax.mod.ens_fiche_mag.php?ens="+ens+"&mag="+mag, 	{
				method:'post',
				asynchronous:true,
				onSuccess: function(t) {
					$$("img[id="+img.id+"]").each(function(item){
						item.src="img/"+(t.responseText);
					});
					if(t.responseText == "off.gif"){
						$$("img[id="+img.id+"_statut]").each(function(item){
							item.style.display="none";
							item.src="img/comment.png";
						});
						$$("img[id="+img.id+"_statut2]").each(function(item){
							item.style.display="none";
							item.src="img/comments.png";
						});
						$$("img[id="+img.id+"_statut3]").each(function(item){
							item.style.display="none";
							item.src="img/thumb_up.png";
						});
					}
					else {
						$$("img[id="+img.id+"_statut]").each(function(item){
							item.style.display="block";
						});
						$$("img[id="+img.id+"_statut2]").each(function(item){
							item.style.display="block";
						});
						$$("img[id="+img.id+"_statut3]").each(function(item){
							item.style.display="block";
						});
					}
				},
				onComplete: function(){},
				evalScripts:true
			}
		);
	}
	function switchEnsFicheMagStatut(img, mag, ens){
		new Ajax.Request("ajax.mod.ens_fiche_mag_statut.php?ens="+ens+"&mag="+mag, 	{
				method:'post',
				asynchronous:true,
				onSuccess: function(t) {
					$$("img[id="+img.id+"]").each(function(item){
						item.src="img/"+(t.responseText);
					});

				},
				onComplete: function(){},
				evalScripts:true
			}
		);
	}
	function switchEnsFicheMagStatut2(img, mag, ens){
		new Ajax.Request("ajax.mod.ens_fiche_mag_statut2.php?ens="+ens+"&mag="+mag, 	{
				method:'post',
				asynchronous:true,
				onSuccess: function(t) {
					$$("img[id="+img.id+"]").each(function(item){
						item.src="img/"+(t.responseText);
					});

				},
				onComplete: function(){},
				evalScripts:true
			}
		);
	}
	function switchEnsFicheMagStatut3(img, mag, ens){
		new Ajax.Request("ajax.mod.ens_fiche_mag_statut3.php?ens="+ens+"&mag="+mag, 	{
				method:'post',
				asynchronous:true,
				onSuccess: function(t) {
					$$("img[id="+img.id+"]").each(function(item){
						item.src="img/"+(t.responseText);
					});

				},
				onComplete: function(){},
				evalScripts:true
			}
		);
	}
	function linkCont(id){
		newPopup( {
			'url':'ajax.mod.cont.app.php?id='+id,
			'title': 'Lier le contact',
			'showCenter':true,
			'width':500,
			'height':485,
			'id':'modContApp'+id
		});
	}
	function affSimpleDev(popup){
		$(popup+"_content").select('.affDeb').each(function(item){ if(item.style.display!="block") new Effect.Pulsate(item); item.style.display=(item.style.display=="block" ? "none" : "block");});
	}
	function affSimpleDev2(popup){
		$(popup+"_content").select('.affDeb').each(function(item){ item.style.display=(item.style.display=="block" ? "none" : "block");});
	}
	function getSurfPonderee(id){
		if(id != undefined){
			var surf_rdc 				= $('magasins_'+id+'_surf_rdc').innerHTML == "" 		? 0 : parseInt($('magasins_'+id+'_surf_rdc').innerHTML);
			var surf_premier 			= $('magasins_'+id+'_surf_premier').innerHTML == "" 	? 0 : parseInt($('magasins_'+id+'_surf_premier').innerHTML);
			var surf_ss 				= $('magasins_'+id+'_surf_ss').innerHTML == "" 			? 0 : parseInt($('magasins_'+id+'_surf_ss').innerHTML);
			var surf_reserve 			= $('magasins_'+id+'_surf_reserve').innerHTML == "" 	? 0 : parseInt($('magasins_'+id+'_surf_reserve').innerHTML);
			var surf_autres 			= 0;
			//var surf_autres 			= $('magasins_'+id+'_surf_autres').innerHTML == "" 		? 0 : parseInt($('magasins_'+id+'_surf_autres').innerHTML);
			$('magasins_'+id+'_surf_totale').innerHTML 	= eval(Math.round((surf_rdc + surf_premier*0.4 + surf_ss*0.3 + surf_reserve*0.1+ surf_autres*0.1)*100)/100);
		} else {
			var surf_rdc 				= $('surf_rdc').value == "" 		? 0 : parseInt($('surf_rdc').value);
			var surf_premier 			= $('surf_premier').value == "" 	? 0 : parseInt($('surf_premier').value);
			var surf_ss 				= $('surf_ss').value == "" 			? 0 : parseInt($('surf_ss').value);
			var surf_reserve 			= $('surf_reserve').value == "" 	? 0 : parseInt($('surf_reserve').value);
			//var surf_autres 			= $('surf_autres').value == "" 		? 0 : parseInt($('surf_autres').value);
			var surf_autres 			= 0;
			$('surf_totale').value	 	= eval(Math.round((surf_rdc + surf_premier*0.4 + surf_ss*0.3 + surf_reserve*0.1+ surf_autres*0.1)*100)/100);
		}
	}
	function getValeurLocative(id){
		if(id != undefined){
			var loyer_actuel 			= $('magasins_'+id+'_loyer_actuel').innerHTML == "" 		? 0 : parseInt($('magasins_'+id+'_loyer_actuel').innerHTML);
			var prix_cession 			= $('magasins_'+id+'_cession').innerHTML == "" 				? 0 : parseInt($('magasins_'+id+'_cession').innerHTML);
			var surf_totale 			= $('magasins_'+id+'_surf_totale').innerHTML == "" 			? 0 : parseInt($('magasins_'+id+'_surf_totale').innerHTML);
			$('magasins_'+id+'_val_loc_m2').innerHTML	 	= eval(Math.round(((loyer_actuel + prix_cession*0.1) / surf_totale)));
		} else {
			var loyer_actuel 			= $('loyer_actuel').value == "" 		? 0 : parseInt($('loyer_actuel').value);
			var prix_cession 			= $('cession').value == "" 				? 0 : parseInt($('cession').value);
			var surf_totale 			= $('surf_totale').value == "" 			? 0 : parseInt($('surf_totale').value);
			$('val_loc_m2').value	 	= eval(Math.round(((loyer_actuel + prix_cession*0.1) / surf_totale)));
		}
		getValeurLocativeInd(id);
	}
	function getValeurLocativeInd(id){
		if(id != undefined){
			var loyer_actuel 			= $('magasins_'+id+'_loyer_actuel').innerHTML == "" 		? 0 : parseInt($('magasins_'+id+'_loyer_actuel').innerHTML);
			var despec 					= $('magasins_'+id+'_despec').innerHTML == "" 				? 0 : parseInt($('magasins_'+id+'_despec').innerHTML);
			var surf_totale 			= $('magasins_'+id+'_surf_totale').innerHTML == "" 			? 0 : parseInt($('magasins_'+id+'_surf_totale').innerHTML);
			$('magasins_'+id+'_val_loc_ind').innerHTML	 	= eval(Math.round(((loyer_actuel + despec*0.1) / surf_totale)));
		} else {
			var loyer_actuel 			= $('loyer_actuel').value == "" 		? 0 : parseInt($('loyer_actuel').value);
			var despec 					= $('despec').value == "" 				? 0 : parseInt($('despec').value);
			var surf_totale 			= $('surf_totale').value == "" 			? 0 : parseInt($('surf_totale').value);
			$('val_loc_ind').value	 	= eval(Math.round(((loyer_actuel + despec*0.1) / surf_totale)));
		}
	}

/* TinyMCE */
	function prepareContenuForTinyMCEEdit(id){
		try{
			if(mcImageManager) mcImageManager.settings.iframe = null;
			if(mcFileManager) mcFileManager.settings.iframe = null;
			if(tinyMCE.getInstanceById(id))
				tinyMCE.remove(tinyMCE.getInstanceById(id));
		} catch (e){alert(e);}
		var tm = setTimeout(	function(){
			try {
				tinyMCE.idCounter=0; // prevent this.geDoc() error with ajax
				tinyMCE.execCommand("mceAddControl", false, id);
				tinyMCE.execCommand('mceFocus', true, id );
				window.clearTimeout(tm);
			} catch(e) {alert(e);}
		},	200);
	}
	function removeContenuForTinyMCEEdit(id){
		try{
			tinyMCE.execCommand("mceRemoveControl", false, id);
		} catch (e){}
	}
	function getContenuForTinyMCEEdit(id){
	//alert(tinyMCE.getInstanceById(id).getContent());
	var temp = tinyMCE.getInstanceById(id).getContent().replace(/\n/g,'');
		try{
			if($(id) && tinyMCE && tinyMCE.getInstanceById(id))
				$(id).value = temp;
		} catch (e) {}
	}
	function setContenuForTinyMCEEdit(id, contenu){
		try{
			if($(id) && tinyMCE && tinyMCE.getInstanceById(id))
				$(id).value = tinyMCE.getInstanceById(id).setContent(contenu);
		} catch (e) {}
	}
	function showMask(id){
		if($(id).style.display == "none")
			new Effect.Appear(id);
		else
			new Effect.Fade(id);
	}
	function getContenu(elem){
		if(getElem('id', elem) && tinyMCE)
			getElem('id', elem).value = tinyMCE.getContent();
		//alert(tinyMCE.getContent(elem));
	}
	function showEmail(id){
		newPopup( {
						'url':'show.email.php?id='+id,
						'title': 'Apercu de l\'e-mail',
						'showCenter':true,
						'iframe':true,
						'width':850,
						'height':700,
						'id':'showEmail'+id
					}
				);
	}
	function emailContact(id){
		newPopup( {
						'url':'ajax.email.cont.php?id='+id,
						'title': 'Envoyer un e-mail',
						'showCenter':true,
						'width':850,
						'height':650,
						'top':5,
						'id':'sendemail'
					}
				);
	}
	function emailReContact(id){
		newPopup( {
						'url':'ajax.email.cont.php?mid='+id,
						'title': 'Renvoyer un e-mail',
						'showCenter':true,
						'width':850,
						'height':650,
						'top':5,
						'id':'sendemail'
					}
				);
	}
	function emailEnseigne(id){
		newPopup(	{
						'url':'ajax.email.ens.php?id='+id,
						'title': 'Envoyer un e-mail',
						'showCenter':true,
						'width':685,
						'height':650,
						'id':'sendemail'
					}
				);
	}
	function emailGroupe(id){
		newPopup(	{
						'url':'ajax.email.groupe.php?id='+id,
						'title': 'Envoyer un e-mail',
						'showCenter':true,
						'width':685,
						'height':650,
						'id':'sendemail'
					}
				);
	}
	function emailMagasin(id){
		newPopup(	{
						'url':'ajax.email.mag.php?id='+id,
						'title': 'Envoyer un e-mail',
						'showCenter':true,
						'width':685,
						'height':650,
						'id':'sendemail'
					}
				);
	}
	function emailSuccursale(id){
		newPopup(	{
						'url':'ajax.email.succ.php?id='+id,
						'title': 'Envoyer un e-mail',
						'showCenter':true,
						'width':685,
						'height':650,
						'id':'sendemail'
					}
				);
	}
	function emailUser(id){
		newPopup(	{
						'url':'ajax.email.user.php?id='+id,
						'title': 'Envoyer un e-mail',
						'showCenter':true,
						'width':685,
						'height':650,
						'id':'sendemail'
					}
				);
	}
	function emailUpdateFichier(id){
		new Ajax.Updater(
				'lstFichierMag',
				'ajax.lst.comm.email.php?id='+id,
				{	method:'get',
					onSuccess: function(t) {},
					asynchronous:true,
					evalScripts:true
				}
			);
	}
/* Popup d'envoi d'e-mail (fin) */
/* Requete de suppression */
	function rmEven(_id){
		if(confirm("Etes-vous sur de vouloir supprimer cet evenement ?")){
			new Ajax.Request(	'ajax.rm.even.php?id='+_id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else window.location.reload();
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function rmContact(_id){
		if(confirm("Etes-vous sur de vouloir supprimer cette fiche ?")){
			new Ajax.Request(	'ajax.rm.cont.php?id='+_id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else window.location.reload();
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function rmDemande(_id){
		if(confirm("Etes-vous sur de vouloir supprimer cette fiche ?")){
			new Ajax.Request(	'ajax.rm.dem.php?id='+_id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else window.location.reload();
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function cpDemande(_id){
		if(confirm("Etes-vous sur de vouloir dupliquer cette demande ?")){
			new Ajax.Request(	'ajax.cp.dem.submit.php?id='+_id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else window.location.reload();
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function rmEnseigne(_id){
		if(confirm("Etes-vous sur de vouloir supprimer cette fiche ?")){
			new Ajax.Request(	'ajax.rm.ens.php?id='+_id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else window.location.reload();
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function rmGroupe(_id){
		if(confirm("Etes-vous sur de vouloir supprimer cette fiche ?")){
			new Ajax.Request(	'ajax.rm.groupe.php?id='+_id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else window.location.reload();
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function rmMagasin(_id){
		if(confirm("Etes-vous sur de vouloir supprimer cette fiche ?")){
			new Ajax.Request(	'ajax.rm.mag.php?id='+_id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else window.location.reload();
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function rmSuccursale(_id){
		if(confirm("Etes-vous sur de vouloir supprimer cette fiche ?")){
			new Ajax.Request(	'ajax.rm.succ.php?id='+_id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else window.location.reload();
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function rmUser(_id){
		if(confirm("Etes-vous sur de vouloir supprimer cette fiche ?")){
			new Ajax.Request(	'ajax.rm.user.php?id='+_id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else window.location.reload();
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
/* Requete de suppression (fin) */
/* Popup de modifications */
	function modEven(_id, _title){
		newPopupModInst(	_id,{
								'url':'ajax.mod.even.php?id=',
								'title': "Voir la fiche de l'actualit&eacute; "+_title,
								'showCenter':true,
								'width':500,
								'height':400,
								'maximize':false,
								'table':'even'
							}
						);
	}
	function modContact(_id, _title){
		newPopupModInst(	_id,{
								'url':'ajax.mod.cont.php?id=',
								'title': "Voir la fiche du contact "+_title,
								'showCenter':true,
								'width':500,
								'height':300,
								'table':'contacts'
							}
						);
	}
	function modDemande(_id, _title){
		newPopupModInst(	_id,{
								'url':'ajax.mod.dem.php?id=',
								'title': "Voir la fiche de la demande du "+_title,
								'showCenter':true,
								'width':950,
								'height':485,
								'table':'demandes'
							}
						);
	}
	function modEnseigne(_id, _title){
		newPopupModInst(	_id,{
								'url':'ajax.mod.ens.php?id=',
								'title': "Voir la fiche de l'enseigne "+_title,
								'showCenter':true,
								'width':950,
								'height':485,
								'table':'enseignes'
							}
						);
	}
	function modGroupe(_id, _title){
		newPopupModInst(	_id,{
								'url':'ajax.mod.groupe.php?id=',
								'title': "Voir la fiche du groupe "+_title,
								'showCenter':true,
								'width':500,
								'height':300,
								'table':'groupes'
							}
						);
	}
	function modMagasin(_id, _title){
		newPopupModInst(	_id,{
								'url':'ajax.mod.mag.php?id=',
								'title': "Voir la fiche du magasin "+_title,
								'showCenter':true,
								'width':950,
								'height':485,
								'table':'magasins'
							}
						);
	}
	function modSuccursale(_id, _title){
		newPopupModInst(	_id,{
								'url':'ajax.mod.succ.php?id=',
								'title': "Voir la fiche de la succursale "+_title,
								'showCenter':true,
								'width':500,
								'height':300,
								'table':'succursales'
							}
						);
	}
	function modUser(_id, _title){
		newPopupModInst(	_id,{
								'url':'ajax.mod.user.php?id=',
								'title': "Voir la fiche de l'utilisateur "+_title,
								'showCenter':true,
								'width':500,
								'height':300,
								'table':'users'
							}
						);
	}
/* Popup d'ajouts */
	function addEven(){
		newPopupAddInst({
			'url':'ajax.add.even.php',
			'title': 'Ajouter un &eacute;v&egrave;nement',
			'showCenter':true,
			'width':500,
			'height':400,
			'maximize':false,
			'table':'even'
		});
	}
	function addContact(_args){
		var _close_callback = _args != undefined && _args['close_callback'] != undefined	? _args['close_callback'] 	: null;
		var _nolink = _args != undefined && _args['nolink'] != undefined	? _args['nolink'] 	: 'false';

		newPopupAddInst({
			'url':'ajax.add.cont.php?nolink='+_nolink,
			'title': 'Ajouter un contact',
			'close_callback':_close_callback,
			'showCenter':true,
			'width':500,
			'height':485,
			'table':'contacts'
		});
	}
	function addDemande(_args){
		var _close_callback = _args != undefined && _args['close_callback'] != undefined	? _args['close_callback'] 	: null;
		var _id = _args != undefined && _args['id'] != undefined	? _args['id'] 	: "";

		newPopupAddInst({
			'url':'ajax.add.dem.php?id='+_id,
			'title': 'Ajouter une demande',
			'close_callback':_close_callback,
			'showCenter':true,
			'width':500,
			'height':485,
			'table':'demandes'
		});
	}
	function addEnseigne(_args){
		var _close_callback = _args != undefined && _args['close_callback'] != undefined	? _args['close_callback'] 	: null;

		newPopupAddInst({
			'url':'ajax.add.ens.php',
			'title': 'Ajouter une enseigne',
			'close_callback':_close_callback,
			'showCenter':true,
			'width':500,
			'height':485,
			'table':'enseignes'
		});
	}
	function addGroupe(){
		newPopupAddInst({
			'url':'ajax.add.groupe.php',
			'title': 'Ajouter un groupe',
			'showCenter':true,
			'width':500,
			'height':485,
			'table':'groupes'
		});
	}
	function addMagasin(_args){
		var _close_callback = _args != undefined && _args['close_callback'] != undefined	? _args['close_callback'] 	: null;
		var _id = _args != undefined && _args['id'] != undefined	? _args['id'] 	: "";


		newPopupAddInst({
			'url':'ajax.add.mag.php?id='+_id,
			'title': 'Ajouter un magasin',
			'close_callback':_close_callback,
			'showCenter':true,
			'width':500,
			'height':485,
			'table':'magasins'
		});
	}
	function addSuccursale(){
		newPopupAddInst({
			'url':'ajax.add.succ.php',
			'title': 'Ajouter une succursale',
			'showCenter':true,
			'width':500,
			'height':485,
			'table':'succursales'
		});
	}
	function addUser(){
		newPopupAddInst({
			'url':'ajax.add.user.php',
			'title': 'Ajouter un utilisateur',
			'showCenter':true,
			'width':500,
			'height':485,
			'table':'users'
		});
	}
	function addMemos_general(){
		newPopupAddInst({
			'url':'ajax.add.memos_general.php',
			'title': 'Ajouter un memo',
			'showCenter':true,
			'width':500,
			'height':485,
			'table':'memos_general'
		});
	}
	function modMemo_general(id){
		newPopupAddInst({
			'url':'ajax.mod.memos_general.php?id='+id,
			'title': 'Modifier le memo '+id,
			'showCenter':true,
			'width':500,
			'height':485,
			'table':'memos_general'
		});
	}
	function rmMemo_general(id){
		if(confirm("Etes-vous sur de vouloir supprimer ce memo ?")){
			new Ajax.Request(	'ajax.rm.memos_general.php?id='+id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else window.location.reload();
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function addTelForm(F){
		var id = F.teladdmag_id.value;
		var lib = F.teladdmag_lib.value;
		var value = F.teladdmag_input.value;

		var elem = 'lstTel_'+id;

		if(id == "") alert('Identifiant incorrect');
		else if(lib == "") alert('Veuillez taper un libelle');
		else if(value == "") alert('Veuillez taper le numero de telephone');
		else {
			var nbInput = ($(elem).select('input').length);
			if(nbInput > 0){
				$(elem).innerHTML += '<div style="clear:both; float:left; width:180px; height:25px"><input tyle="text" name="telLib[]" value="'+lib+'" readonly="readonly" /></div><div style="float:left; width:240px; height:25px"><input tyle="text" name="telValue[]" value="'+value+'" style="float:left; " /></div>';
			} else {
				$(elem).innerHTML = '<div style="clear:both; float:left; width:180px; height:25px"><input tyle="text" name="telLib[]" value="'+lib+'" readonly="readonly" /></div><div style="float:left; width:240px; height:25px"><input tyle="text" name="telValue[]" value="'+value+'" style="float:left; " /></div>';
			}
			F.reset();
		}
		return false;
	}
	function addContForm(F){
		var id = F.contaddmag_id.value;
		var lib = F.contaddmag_lib.value;
		var value = F.contaddmag_input.value;

		var elem = 'lstContacts_'+id;

		if(id == "") alert('Identifiant incorrect');
		else if(lib == "") alert('Veuillez taper un libelle');
		else if(value == "") alert('Veuillez taper l\'identifiant d\'un contact');
		else {
			var nbInput = ($(elem).select('input').length);
			if(nbInput > 0){
				$(elem).innerHTML += '<div style="clear:both; float:left; width:180px; height:25px"><input tyle="text" name="contLib[]" value="'+lib+'" readonly="readonly" /></div><div style="float:left; width:240px; height:25px"><input tyle="text" name="contValue[]" value="'+value+'" readonly="readonly" style="float:left; " /><a href="#" onClick="modContact(\''+value+'\', \'Identifiant '+value+'\');"><img src="img/application_form_magnify.png" /></a></div>';
			} else {
				$(elem).innerHTML = '<div style="clear:both; float:left; width:180px; height:25px"><input tyle="text" name="contLib[]" value="'+lib+'" readonly="readonly" /></div><div style="float:left; width:240px; height:25px"><input tyle="text" name="contValue[]" value="'+value+'" readonly="readonly" style="float:left; " /><a href="#" onClick="modContact(\''+value+'\', \'Identifiant '+value+'\');" style="float:left; "><img src="img/application_form_magnify.png" /></a></div>';
			}
			F.reset();
		}
		return false;
	}
/* Gestion des fichiers des commentaires */
	function commAddFichier(id){
		getElem('id', 'lstFileLoad'+id).innerHTML= '<div style="width:320px"><a href="javascript:commUpdateFichier('+id+')" style="float:right" title="Annuler"><img src="img/delete.png" align="absmiddle" /></a><img src="img/loading3.gif" align="absmiddle"  />&nbsp;T&eacute;l&eacute;chargement...</div>';
		return true;
	}
	function commUpdateFichier(id, reset){
		var _reset 			= reset != undefined ? reset : 1;
		if(_reset && getElem('id', 'addComm'+id)) getElem('id', 'addComm'+id).reset();
		getElem('id', 'iframe').src="_blank.html";

		if(id == undefined) id = 0;
//		new Effect.BlindUp('lstFiles'+id, {afterFinish:	function(){
			new Ajax.Updater(	'lstFiles'+id,
								'ajax.lst.comm.php?id='+id,
								{	method:'get',
									onComplete:function(){
//										new Effect.BlindDown('lstFiles'+id);
										new Effect.Pulsate('lstFiles'+id);
										//new Effect.Highlight('lstFiles'+id);
										setupAllTabs();
										getElem('id', 'lstFileLoad'+id).innerHTML = "";
									},
									asynchronous:true,
									evalScripts:true
								}
			);
//		}});
	}
	function commRmFichier(cid, id){
		if(confirm("Etes-vous sur de vouloir supprimer ce fichier ?")){
			new Ajax.Request(	'ajax.rm.comm.php?id='+id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else commUpdateFichier(cid);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
/* Gestion des memos */
	function memosAddItem(id){
		$('lstMemosLoad'+id).innerHTML= '<div style="width:320px"><a href="javascript:memosUpdateItem('+id+')" style="float:right" title="Annuler"><img src="img/delete.png" align="absmiddle" /></a><img src="img/loading3.gif" align="absmiddle"  />&nbsp;T&eacute;l&eacute;chargement...</div>';
		return true;
	}
	function memosUpdateItem(id, reset){
		var _reset 			= reset != undefined ? reset : 1;
		if(_reset && $('addMemos'+id)) $('addMemos'+id).reset();
		$('iframe').src="_blank.html";

		if(id == undefined) id = 0;
//		new Effect.BlindUp('lstFiles'+id, {afterFinish:	function(){
			new Ajax.Updater(	'lstItems'+id,
								'ajax.lst.memos.php?id='+id,
								{	method:'get',
									onComplete:function(){
//										new Effect.BlindDown('lstItems'+id);
										new Effect.Pulsate('lstItems'+id);
										//new Effect.Highlight('lstItems'+id);
										setupAllTabs();
										$('lstMemosLoad'+id).innerHTML = "";
									},
									asynchronous:true,
									evalScripts:true
								}
			);
//		}});
	}
	function memosRmItem(mid, id){
		if(confirm("Etes-vous sur de vouloir supprimer ce memo ?")){
			new Ajax.Request(	'ajax.rm.memos.php?id='+id,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else memosUpdateItem(mid);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function groupeUpdateEns(id){
//		new Effect.BlindUp('groupes_'+id+'_lstEns', {afterFinish:	function(){
		if(id == undefined) id = 0;
			new Ajax.Updater(	'groupes_'+id+'_lstEns',
								'ajax.lst.ens.php?id='+id,
								{	method:'get',
//									onComplete:function(){new Effect.BlindDown('groupes_'+id+'_lstEns');},
									asynchronous:true,
									evalScripts:true
								}
			);
//		}});
	}
	function ensUpdateDem(id){
//		new Effect.BlindUp('enseignes_'+id+'_lstDem', {afterFinish:	function(){
		if(id == undefined) id = 0;
			new Ajax.Updater(	'enseignes_'+id+'_lstDem',
								'ajax.lst.dem.php?id='+id,
								{	method:'get',
//									onComplete:function(){new Effect.BlindDown('enseignes_'+id+'_lstDem');},
									asynchronous:true,
									evalScripts:true
								}
			);
//		}});
	}
	function ensUpdateMag(id){
//		new Effect.BlindUp('enseignes_'+id+'_lstMag', {afterFinish:	function(){
		if(id == undefined) id = 0;
			new Ajax.Updater(	'enseignes_'+id+'_lstMag',
								'ajax.lst.mag.php?id='+id,
								{	method:'get',
//									onComplete:function(){new Effect.BlindDown('enseignes_'+id+'_lstMag');},
									asynchronous:true,
									evalScripts:true
								}
			);
//		}});
	}
	function ensUpdateCont(id, _effect){
		if(id == undefined) id = 0;
			new Ajax.Updater(	'lstContEns'+id,
								'ajax.lst.cont.ens.php?id='+id,
								{	method:'get',
									onComplete:function(){
										if(_effect == undefined || _effect)
											new Effect.Pulsate('lstContEns'+id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);

	}
	function ensRmCont(cid, id){
		if(confirm("Etes-vous sur de vouloir supprimer ce contact ?")){
			new Ajax.Request(	'ajax.rm.cont.ens.php?id='+id+'&cid='+cid,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != ""){
											if(confirm(t.responseText)){
												new Ajax.Request('ajax.rm.cont.ens.php?rm=true&id='+id+'&cid='+cid,
																{	method:'get',
																	asynchronous:true,
																	onSuccess: function(t) {
																		if(t.responseText == ""){
																			ensUpdateCont(id);
																		}
																	},
																	evalScripts:true
																});
											}
										}else{
											ensUpdateCont(id);
										}
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function addContAppEnsForm(F, id){
		new Ajax.Request(	'ajax.add.cont.ens.php?id='+id,
							{	method:'post',
								parameters:Form.serialize(F),
								onSuccess: function(t) {
									if(t.responseText != ""){alert(t.responseText);}
									else{
										contUpdateAppEns(id);
										F.reset();
									}
								},
								asynchronous:true,
								evalScripts:true
							}
		);
		return false;
	}
	function contUpdateAppEns(id, _effect){
		if(id == undefined) id = 0;
			new Ajax.Updater(	'lstContAppEns'+id,
								'ajax.lst.cont.app.ens.php?id='+id,
								{	method:'get',
									onComplete:function(){
										if(_effect == undefined || _effect)
											new Effect.Pulsate('lstContAppEns'+id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);

	}
	function contRmAppEns(contId, ensId){
		if(confirm("Etes-vous sur de vouloir supprimer cette liaison ?")){
			new Ajax.Request(	'ajax.rm.cont.app.ens.php?id='+contId+'&ens='+ensId,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else contUpdateAppEns(contId);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function addContAppMagForm(F, id){
		new Ajax.Request(	'ajax.add.cont.mag.php?id='+id,
							{	method:'post',
								parameters:Form.serialize(F),
								onSuccess: function(t) {
									if(t.responseText != ""){alert(t.responseText);}
									else{
										contUpdateAppMag(id);
										F.reset();
									}
								},
								asynchronous:true,
								evalScripts:true
							}
		);
		return false;
	}
	function contUpdateAppMag(id, _effect){
		if(id == undefined) id = 0;
			new Ajax.Updater(	'lstContAppMag'+id,
								'ajax.lst.cont.app.mag.php?id='+id,
								{	method:'get',
									onComplete:function(){
										if(_effect == undefined || _effect)
											new Effect.Pulsate('lstContAppMag'+id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);

	}
	function contRmAppMag(contId, magId){
		if(confirm("Etes-vous sur de vouloir supprimer cette liaison ?")){
			new Ajax.Request(	'ajax.rm.cont.app.mag.php?id='+contId+'&mag='+magId,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else contUpdateAppMag(contId);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function magUpdateCont(id, _effect){
		if(id == undefined) id = 0;
			new Ajax.Updater(	'lstContMag'+id,
								'ajax.lst.cont.mag.php?id='+id,
								{	method:'get',
									onComplete:function(){
										if(_effect == undefined || _effect)
											new Effect.Pulsate('lstContMag'+id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);

	}
	function magRmCont(cid, id){
		if(confirm("Etes-vous sur de vouloir supprimer ce contact ?")){
			new Ajax.Request(	'ajax.rm.cont.mag.php?id='+id+'&cid='+cid,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else magUpdateCont(id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function magUpdateTel(id){
		if(id == undefined) id = 0;
		new Effect.BlindUp('lstTelMag'+id, {afterFinish:	function(){
			new Ajax.Updater(	'lstTelMag'+id,
								'ajax.lst.tel.mag.php?id='+id,
								{	method:'get',
									onComplete:function(){
										new Effect.BlindDown('lstTelMag'+id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}});
	}
	function magRmTel(cid, id){
		if(confirm("Etes-vous sur de vouloir supprimer ce numero ?")){
			new Ajax.Request(	'ajax.rm.tel.mag.php?id='+id+'&cid='+cid,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else magUpdateTel(id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function contUpdateTel(id){
		if(id == undefined) id = 0;
		new Effect.BlindUp('lstTelCont'+id, {afterFinish:	function(){
			new Ajax.Updater(	'lstTelCont'+id,
								'ajax.lst.tel.cont.php?id='+id,
								{	method:'get',
									onComplete:function(){
										new Effect.BlindDown('lstTelCont'+id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}});
	}
	function contRmTel(cid, id){
		if(confirm("Etes-vous sur de vouloir supprimer ce numero ?")){
			new Ajax.Request(	'ajax.rm.tel.cont.php?id='+id+'&cid='+cid,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else contUpdateTel(id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function ensUpdateTel(id){
		if(id == undefined) id = 0;
		new Effect.BlindUp('lstTelEns'+id, {afterFinish:	function(){
			new Ajax.Updater(	'lstTelEns'+id,
								'ajax.lst.tel.ens.php?id='+id,
								{	method:'get',
									onComplete:function(){
										new Effect.BlindDown('lstTelEns'+id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}});
	}
	function ensRmTel(cid, id){
		if(confirm("Etes-vous sur de vouloir supprimer ce numero ?")){
			new Ajax.Request(	'ajax.rm.tel.ens.php?id='+id+'&cid='+cid,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else ensUpdateTel(id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
	function groupeUpdateTel(id){
		if(id == undefined) id = 0;
		new Effect.BlindUp('lstTelGroupe'+id, {afterFinish:	function(){
			new Ajax.Updater(	'lstTelGroupe'+id,
								'ajax.lst.tel.groupe.php?id='+id,
								{	method:'get',
									onComplete:function(){
										new Effect.BlindDown('lstTelGroupe'+id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}});
	}
	function groupeRmTel(cid, id){
		if(confirm("Etes-vous sur de vouloir supprimer ce numero ?")){
			new Ajax.Request(	'ajax.rm.tel.groupe.php?id='+id+'&cid='+cid,
								{	method:'get',
									onSuccess: function(t) {
										if(t.responseText != "") alert(t.responseText);
										else groupeUpdateTel(id);
									},
									asynchronous:true,
									evalScripts:true
								}
			);
		}
	}
/* Gestion des Hints */
	function prepareInputsForHints() {
		var inputs = document.getElementsByTagName("input");
		for (var i=0; i<inputs.length; i++){
			// test to see if the hint span exists first
			if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
				// the span exists!  on focus, show the hint
				inputs[i].observe('click', function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
				});
				// when the cursor moves away from the field, hide the hint
				inputs[i].onkeypress = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "none";
				}
				// when the cursor moves away from the field, hide the hint
				inputs[i].onblur = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "none";
				}
			}
		}
		var inputs = document.getElementsByTagName("textarea");
		for (var i=0; i<inputs.length; i++){
			// test to see if the hint span exists first
			if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
				// the span exists!  on focus, show the hint
				inputs[i].observe('click', function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
				});
				// when the cursor moves away from the field, hide the hint
				inputs[i].onkeypress = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "none";
				}
				// when the cursor moves away from the field, hide the hint
				inputs[i].onblur = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "none";
				}
			}
		}

		// repeat the same tests as above for selects
		var selects = document.getElementsByTagName("select");
		for (var k=0; k<selects.length; k++){
			if (selects[k].parentNode.getElementsByTagName("span")[0]) {
				selects[k].onfocus = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
				}
				selects[k].onblur = function () {
					this.parentNode.getElementsByTagName("span")[0].style.display = "none";
				}
			}
		}
	}
/* MouseMove */
	function mouseX(evt) {
		if (evt.pageX) return evt.pageX;
		else if (evt.clientX)
		   return evt.clientX + (document.documentElement.scrollLeft ?
		   document.documentElement.scrollLeft :
		   document.body.scrollLeft);
		else return null;
	}
	function mouseY(evt) {
		if (evt.pageY) return evt.pageY;
		else if (evt.clientY)
		   return evt.clientY + (document.documentElement.scrollTop ?
		   document.documentElement.scrollTop :
		   document.body.scrollTop);
		else return null;
	}
	function checkth(id){
		if($(id).checked == false){
			$(id).checked = true;
		}else{
			$(id).checked = false;
		}
	}
	function changeEtatMemoGeneral(id){
		var etat = $('memo_etat_'+id).value;
		new Ajax.Request('ajax.update.memos_general.php?id='+id+'&etat='+etat,
							{	method:'get',
								onComplete:function(){
									if(etat == '1'){
										$('img_memo_'+id).src = "img/thumb_down.png";
										$('memo_etat_'+id).value = 0;
									}else{
										$('img_memo_'+id).src = "img/thumb_up.png";
										$('memo_etat_'+id).value = 1;
									}
								},
								asynchronous:true,
								evalScripts:true
							});
	}