
var ANEOL = {

	validation: {//{{{
		validate: function(){//{{{
			var ok=true;
  			var i=0;			
			while(ok && i < arguments.length){
				ok = arguments[i](arguments[i+1]);
				i = i+2;
			}
			return ok;
		},//}}}
		execOnReturn: function(e, func){//{{{
			//var key = (e.keyPress) ? e.keyPress : e.which;
			var key = e.keyPress || e.which || e.keyCode;
			if(key == 13){
				func();		
				return false;
			}else{
				return true;
			}
		},//}}}
		required: function(o){//{{{
			if(o.field.value === ""){
				if(o.msg === undefined){
					if(o.label === undefined){
						o.label = o.field.name;
					}
					o.msg = "Le champs "+o.label+" est obligatoire !";
				}
				ANEOL.visualisation.displayMsg('Erreur !', o.msg, YAHOO.widget.SimpleDialog.ICON_WARN);
				o.field.focus();
				return false;
			}
			return true;
		},//}}}
		email: function(o){//{{{
			if(o.field.value !==""){
				var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;
				if(reg.exec(o.field.value)===null){
					if(o.msg === undefined){
						if(o.label === undefined){
							o.label = o.field.name;
						}
						o.msg = "Le champs "+o.label+" n'est pas valide !";
					}
					ANEOL.visualisation.displayMsg('Erreur !', o.msg, YAHOO.widget.SimpleDialog.ICON_WARN);
					o.field.focus();
					return false;
				}
			}		
			return true;
		},//}}}
		max: function(o){//{{{
			if(o.field.value !==""){
				if(o.field.value.length > o.size){
					if(o.msg === undefined){
						if(o.label === undefined){
							o.label = o.field.name;
						}
						o.msg = "Le champs "+o.label+" ne doit pas dépasser "+o.size+" caractères !";
					}
					ANEOL.visualisation.displayMsg('Erreur !', o.msg, YAHOO.widget.SimpleDialog.ICON_WARN);
					o.field.focus();
					return false;
				}
			}		
			return true;
		},//}}}
		range: function(o){//{{{
			if(o.field.value !==""){
				if(!o.field.value.NaN && o.field.value >= o.min && o.field.value <= o.max){
					return true;
				}else{
					if(o.msg === undefined){
						if(o.label === undefined){
							o.label = o.field.name;
						}
						o.msg = "Le champs "+o.label+" doit être un nombre compris entre "+o.min+" et "+o.max+" !";
					}
					ANEOL.visualisation.displayMsg('Erreur !', o.msg, YAHOO.widget.SimpleDialog.ICON_WARN);
					o.field.focus();
					return false;
				}
			}
		}//}}}
	},//}}} 
	visualisation:{//{{{
		showElement: function (id){//{{{
			try{
				var elt = document.getElementById(id);
				elt.style.display = "block";
				elt.style.visibility = "visible";
			}catch(e){ }
		},//}}}
		hideElement: function (id){//{{{
			try{
				var elt = document.getElementById(id);
				elt.style.display = "none";
				elt.style.visibility = "hidden";
			}catch(e){ }
		},//}}}
		showHide: function (id){//{{{
				var elt = document.getElementById(id);
				if(elt.style.display == "none"){
					ANEOL.visualisation.showElement(id);			
				}else{
					ANEOL.visualisation.hideElement(id);			
				}
		},//}}}
		displayMsg: function (titre, text, icon){//{{{
			var handleClose = function(){
				this.hide();
			};
			var msg = document.getElementById('msg');
			msg.innerHTML = "";
			var dialog = new YAHOO.widget.SimpleDialog('msg',  {
				width: "300px", 
				fixedcenter: true, 
				visible: false, 
				draggable: true, 
				close: false, 
				modal: YAHOO.env.ua.ie === 0, 
				'text': text, 
				'icon': icon, 
				constraintoviewport: true, 
				buttons: [ { text:"Fermer", handler:handleClose, isDefault:true } ] 
			}); 
			dialog.setHeader(titre); 
			dialog.render(document.body); 
			dialog.show();
		}//}}}
	},//}}}
	lang:{//{{{
		extend:function(son, father, args){
			son.superclass = father;
			son.prototype = new son.superclass();
			son.superclass.apply(son, args);
			delete son.superclass;
		}
	},//}}}
	internationalisation:{//{{{
		FrenchCalendar:{
			"title":"Sélectionnez une date:",
			"close":true,
			"LOCALE_WEEKDAYS": "short",
			"START_WEEKDAY": 1, 
			"MULTI_SELECT": false,
			"DATE_FIELD_DELIMITER": "/",
			"MDY_DAY_POSITION": 1, 
			"MDY_MONTH_POSITION": 2, 
			"MDY_YEAR_POSITION": 3, 
			"MD_DAY_POSITION": 1, 
			"MD_MONTH_POSITION": 2, 
			"MONTHS_SHORT":   ["Janv", "Févr", "Mars", "Avr", "Mai", "Juin", "Juil", "Août", "Sept", "Oct", "Nov", "Déc"],
			"MONTHS_LONG":    ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
			"WEEKDAYS_1CHAR": ["D", "L", "M", "M", "J", "V", "S"],
			"WEEKDAYS_SHORT": ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
			"WEEKDAYS_MEDIUM":["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"],
			"WEEKDAYS_LONG":  ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"]
		}
	},//}}}
	DataTable:function(o){//{{{
		if(o === undefined){
			o = {};	
		}
		this.first = o.first || 0;
		this.action = o.action || '';
		this.tableElt = o.tableElt || '';
		this.listeNbpp = o.listeNbpp || [10,20,30];
		this.nbpp = o.nbpp || this.listeNbpp[0];
		this.name = o.name || '';
		this.url = o.url || '/index.php';
		this.params = o.params || {};

		this.get = function(first){//{{{
			var that = this; 
			if(first !== undefined){
				that.first = first;
			}
			var handler = {
				success: function(o) {
					var te = document.getElementById(that.tableElt);				 
					te.innerHTML = o.responseText;					 
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			ANEOL.ajax('POST', this.url, handler, "action="+this.action+"&DataTableParams="+YAHOO.lang.JSON.stringify(that));
		};//}}}
		this.setNbpp = function(nb){//{{{
			this.nbpp = nb;
			this.get(Math.floor(this.first / this.nbpp) * this.nbpp); 
		};//}}}
		this.unselectLAll = function(){//{{{
			var table = document.getElementById(this.name+'_table');
			var lignes = table.getElementsByTagName('tr');
			for(var i=0;i<lignes.length;i++){
				var tr = lignes[i];
				if(tr.className != 'th'){
					tr.className = (i%2) ? 'regular' : 'alternate';
				}
			}
		};//}}}
		this.selectLine = function(elt){//{{{
			this.unselectLAll(elt);
			while(elt !== undefined && elt.nodeName != 'TR'){
				elt = elt.parentNode;
			}
			if(elt !== undefined){
				elt.className='selected';
			}
		};//}}}
		this.orderBy = function(field){//{{{
			if(this.params.orderField == field){
				if(this.params.orderDirection == 'asc'){
					this.params.orderDirection = 'desc';
				}else{
					this.params.orderDirection = 'asc';
				}
			}else{
				this.params.orderField = field;
				this.params.orderDirection = 'asc';
			}
		};//}}}

	},//}}}
	Dialog:function(o){//{{{

		if(o === undefined){
			o = {};	
		}
		this.template = o.template || undefined;
		this.params = o.params || {};
		this.url = o.url || '/index.php';

		this.container = undefined;
		this.panel = undefined;
		var that = this;

		this.show = function(){//{{{
			var handler = {
				success: function(o){
					that.container = document.createElement('div');
					document.body.appendChild(that.container);
					that.container.innerHTML = o.responseText;
					that.init();
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			ANEOL.ajax('POST', that.url, handler, "action="+that.template+"&params="+YAHOO.lang.JSON.stringify(that.params));
		};//}}}
		this.init = function(){//{{{
			that.panel = new YAHOO.widget.Dialog(that.container, { 
				width : "700px",
				
				visible : false, 
				modal: YAHOO.env.ua.ie === 0,
				constraintoviewport : true,
				buttons : [ { text:"Fermer", handler:that.hide, isDefault:true } ]
			});
			that.panel.render();
			that.panel.show();
		};//}}}
		this.hide = function(){//{{{
			that.panel.destroy();
		};//}}}
	
		this.help = function(){//{{{
			window.open('/index/help/topic.html');
		};//}}}

	},//}}}
	Tooltip:function(o){//{{{

		this.c = document.createElement('span');
		this.c.id = i+'_div';
		document.body.appendChild(this.c);

		this.t = new YAHOO.widget.Tooltip(this.c, {
			context:o.id, 
			text:o.content,
			hidedelay:1000,
			effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25} 
		});

		var that = this;

		YAHOO.util.Event.addListener(this.c, 'mouseover', function(e){
		});

		YAHOO.util.Event.addListener(this.c, 'mouseout', function(e){
			that.t.hide();
		});

	},//}}}
	ajax:function(method, url, handler, params){//{{{
		ANEOL.visualisation.showElement('loading');
		if(params !== undefined){
			var trans = YAHOO.util.Connect.asyncRequest(method, url, handler, params);
		}else{
			var trans = YAHOO.util.Connect.asyncRequest(method, url, handler);
		}
		return trans;
	 },//}}}
	global:{}

};

	DndBox = function(id, sGroup, config) {//{{{
		DndBox.superclass.constructor.apply(this, arguments);
		this.initBox(id, sGroup, config);
	};//}}}
	YAHOO.extend(DndBox, YAHOO.util.DDProxy, {//{{{
		initBox: function(id, sGroup, config) {//{{{
			if (!id) { 
				return; 
			}
			this.setOuterHandleElId(id+'_handler');
			this.isTarget = false;
			var el = this.getDragEl();

			YAHOO.util.Dom.setStyle(el, "opacity", 0.8);
			// specify that this is not currently a drop target
			this.originalStyles = [];
			this.startPos = YAHOO.util.Dom.getXY( this.getEl() );
		},//}}}
		startDrag: function(x, y) {//{{{
			var Dom = YAHOO.util.Dom;
			// Copie de l'élément dans le proxy
			var proxy = this.getDragEl();
			var source = this.getEl();
			this.startContainer = source.parentNode.id;

			proxy.innerHTML = ""; 
			proxy.className = 'box-proxy';

		},//}}}
		onDragDrop: function(e, id) {//{{{
			var dest = document.getElementById(id);
			var source = this.getEl();
			var prev = YAHOO.util.Dom.getLastChild(id);
			var boxes = YAHOO.util.Dom.getElementsByClassName('box-over');

			for(i=0;i<boxes.length;i++){
				YAHOO.util.Dom.removeClass(boxes[i], 'box-over'); 
			}
			while(prev){
				var region = YAHOO.util.Region.getRegion(prev);
				if(region.intersect(YAHOO.util.DragDropMgr.interactionInfo.point)){
					dest.insertBefore(source, prev);
					return;
				}
				prev = YAHOO.util.Dom.getPreviousSibling(prev);
			}
			dest.appendChild(source);
		},//}}}
		endDrag: function(e) {//{{{
			YAHOO.util.Dom.setStyle(this.getEl(), "opacity", 1);
			if(this.startContainer == this.getEl().parentNode.id){
				updateContainer(this.startContainer);
			}else{
				updateContainer(this.startContainer);
				updateContainer(this.getEl().parentNode.id);
			}
		},//}}}
		onDragOver: function(e, id) {//{{{
			/*YAHOO.util.Dom.removeClass(id, 'container'); */
			/*YAHOO.util.Dom.addClass(id, 'container-over'); */

			var prev = YAHOO.util.Dom.getLastChild(id);
			while(prev){
				var region = YAHOO.util.Region.getRegion(prev);
				if(region.intersect(YAHOO.util.DragDropMgr.interactionInfo.point)){
					YAHOO.util.Dom.addClass(prev, 'box-over'); 
				}else{
					YAHOO.util.Dom.removeClass(prev, 'box-over'); 
				}
				prev = YAHOO.util.Dom.getPreviousSibling(prev);
			}
		},//}}}
		onDragOut: function(e, id) {//{{{
			YAHOO.util.Dom.removeClass(id, 'container-over'); 
			YAHOO.util.Dom.addClass(id, 'container'); 

			var prev = YAHOO.util.Dom.getLastChild(id);
			while(prev){
				YAHOO.util.Dom.removeClass(prev, 'box-over'); 
				prev = YAHOO.util.Dom.getPreviousSibling(prev);
			}
		}//}}}
	});//}}}

	DndPanelBox = function(id, sGroup, config) {//{{{
		DndPanelBox.superclass.constructor.apply(this, arguments);
		this.initBox(id, sGroup, config);
	};//}}}
	YAHOO.extend(DndPanelBox, YAHOO.util.DDProxy, {//{{{
		initBox: function(id, sGroup, config) {//{{{
			if (!id) { 
				return; 
			}
			this.isTarget = false;
			var el = this.getDragEl();
			YAHOO.util.Dom.setStyle(el, "opacity", 0.8);
			// specify that this is not currently a drop target
			this.originalStyles = [];
			this.startPos = YAHOO.util.Dom.getXY( this.getEl() );
		},//}}}
		startDrag: function(x, y) {//{{{
			var Dom = YAHOO.util.Dom;
			// Copie de l'élément dans le proxy
			var proxy = this.getDragEl();
			var source = this.getEl();

			proxy.innerHTML = source.innerHTML; 
			var imgs = proxy.getElementsByTagName('img');
			for(var i=0;i<imgs.length;i++){
				proxy.removeChild(imgs[i]);
			}
			YAHOO.util.Dom.addClass(proxy, 'box-proxy'); 

			// La boite est elle deja presente ?
			this.allowed = true;
			id_box = "box_"+source.id.substring(10, source.id.length);
			var boxes = YAHOO.util.Dom.getElementsByClassName('box');
			for(i=0;i<boxes.length;i++){
				if(boxes[i].id == id_box){
					YAHOO.util.Dom.addClass(boxes[i].id, 'box-forbidden'); 
					this.allowed = false;
					Dom.setStyle(proxy, "cursor",  'not-allowed');
				}
			}

		},//}}}
		onDragDrop: function(e, id) {//{{{
			if(this.allowed){
				var boxes = YAHOO.util.Dom.getElementsByClassName('box');
				for(i=0;i<boxes.length;i++){
					YAHOO.util.Dom.removeClass(boxes[i].id, 'box-over'); 
				}
				var dest = document.getElementById(id);
				var source = this.getEl();
				var prev = YAHOO.util.Dom.getLastChild(id);
				while(prev){
					var region = YAHOO.util.Region.getRegion(prev);
					if(region.intersect(YAHOO.util.DragDropMgr.interactionInfo.point)){
						// creation de la boite
						var callback = {
							success:function(o){
								ANEOL.visualisation.hideElement('loading');
								if(o.responseText !== ''){
									var newBox = document.createElement('div');
									newBox.id = 'box_'+source.id.substring(10, source.id.length);
									newBox.innerHTML = o.responseText;
									YAHOO.util.Dom.addClass(newBox, "box");
									dest.insertBefore(newBox, prev);
									var dndb = new DndBox(newBox.id, "dnd");
									updateContainer(dest.id);
								}
							},
							failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
						};
						ANEOL.ajax('POST', '/index.php?action=addBox', callback, "id_box="+source.id.substring(10, source.id.length));
						return;
					}
					prev = YAHOO.util.Dom.getPreviousSibling(prev);
				}
			}

		},//}}}
		endDrag: function(e) {//{{{
			YAHOO.util.Dom.setStyle(this.getEl(), "opacity", 1);

			if(!this.allowed){
				var boxes = YAHOO.util.Dom.getElementsByClassName('box');
				for(i=0;i<boxes.length;i++){
					YAHOO.util.Dom.removeClass(boxes[i].id, 'box-forbidden'); 
				}
			}
		},//}}}
		onDragOver: function(e, id) {//{{{
			if(this.allowed){
				var prev = YAHOO.util.Dom.getLastChild(id);
				while(prev){
					var region = YAHOO.util.Region.getRegion(prev);
					if(region.intersect(YAHOO.util.DragDropMgr.interactionInfo.point)){
						YAHOO.util.Dom.addClass(prev, 'box-over'); 
					}else{
						YAHOO.util.Dom.removeClass(prev, 'box-over'); 
					}
					prev = YAHOO.util.Dom.getPreviousSibling(prev);
				}
			}
		},//}}}
		onDragOut: function(e, id) {//{{{
			if(this.allowed){
				var prev = YAHOO.util.Dom.getLastChild(id);
				while(prev){
					YAHOO.util.Dom.removeClass(prev, 'box-over'); 
					prev = YAHOO.util.Dom.getPreviousSibling(prev);
				}
			}
		}//}}}
	});//}}}

	ANEOL.reloadListingsByTopic = function(id_topic){//{{{
		var handler = {
			success: function(o){
				var boxes = YAHOO.lang.JSON.parse(o.responseText);
				for(var i=0;i<boxes.length;i++){
					if(document.getElementById('box_'+boxes[i]) !== undefined){
						ANEOL.reloadListingBox(boxes[i]);
					}
				}
				ANEOL.visualisation.hideElement('loading');
			},
			failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
		};
		ANEOL.ajax('POST', "/topic.php", handler, "action=getBoxes&id_topic="+id_topic);
	};//}}}
	ANEOL.reloadListingBox = function(id_box){//{{{
		var handler = {
			success: function(o){
				var box = document.getElementById('box_'+id_box);
				box.innerHTML = o.responseText;
				ANEOL.visualisation.hideElement('loading');
			},
			failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
		};
		ANEOL.ajax('POST', "/listing.php", handler, "action=boxGetListing&id_box="+id_box);
	};//}}}

// Gestion des pages
		var PlanSite = function(){//{{{
			ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
			this.url = '/page.php';
			this.template = 'getPlanSite';
			this.plan = undefined;
			var that = this;

			this.init = function(){//{{{
				that.panel = new YAHOO.widget.Dialog(that.container, { 
					width : "500px",
					fixedcenter:false,
					visible : false, 
					close:false,
					modal: YAHOO.env.ua.ie === 0,
					constraintoviewport : true,
					buttons : [ { text:"Valider", handler:that.validte },{ text:"Annuler", handler:that.hide, isDefault:true } ]
				});
				that.panel.render();

				var callback = {
					success:function(o){
						ANEOL.visualisation.hideElement('loading');
						that.plan = document.getElementById('plan');
						that.plan.innerHTML = o.responseText;

						var pages = YAHOO.util.Dom.getElementsByClassName('page');
						for(var p=0;p<pages.length;p++){
							var dd = new DndPage(pages[p].id);
							dd.setHandleElId(pages[p].id.replace('p', 'h'));
						}

						YAHOO.util.Event.addListener(document.getElementById('btAddPage'), "click", that.addPage); 

						that.panel.center();
						that.panel.show();
					},
					failure:function(o){ console.warn("failure"); }
				};
				ANEOL.ajax('POST', that.url, callback, "action=getPlan");

			};//}}}
			this.hide = function(){//{{{
				that.panel.destroy();
				/*window.location = window.location;*/
			};//}}}
			this.validte = function(){//{{{
				var pages = YAHOO.util.Dom.getElementsByClassName('page');
				var index = YAHOO.util.Dom.getElementsByClassName('aneol-tree-index');
				var fathers = [];
				fathers[0] = {'id_page':index[0].id.substr(1, index[0].id.length), 'order':0};
				var nodes = [];
				var prevLvl = -1;
				for(var p=0;p<pages.length;p++){
					var id = parseInt(pages[p].id.substr(1, pages[p].id.length));
					var lvl = parseInt(pages[p].className.substr(10, pages[p].className.length));
					fathers[lvl+1] = {'id_page':id, 'order':0 };
					nodes[nodes.length] = { 'id_page':id, 'parent':fathers[lvl].id_page, 'order':fathers[lvl].order++ };
					prevLvl = lvl;
				}

				var callback = {
					success:function(o){
						ANEOL.visualisation.hideElement('loading'); 
						that.hide();
						window.location.reload();
					},
					failure:function(o){ console.warn("failure"); }
				};
				ANEOL.ajax('POST', '/page.php?action=updatePagesTree', callback, "nodes="+YAHOO.lang.JSON.stringify(nodes));

			};//}}}
			this.addPage = function(){//{{{
				var index = YAHOO.util.Dom.getElementsByClassName('aneol-tree-index');
				pageFrm = new PageFrm({'id_parent':index[0].id.substr(1, index[0].id.length)});
				pageFrm.show();
			};//}}}
			this.deletePage = function(id){//{{{
				var handleYes = function(){
					var callback = {
						success:function(o){
							ANEOL.visualisation.hideElement('loading');
							document.getElementById('plan').removeChild(document.getElementById('p'+id));
							ANEOL.planSite.redrawTree(document.getElementById('p'+o.responseText));
							confirmDialog.hide();
						},
						failure:function(o){ console.warn("failure"); }
					};
					ANEOL.ajax('POST', '/page.php?action=delete', callback, "id_page="+id);
				};
				var handleNo = function(){
					this.hide();
				};

				var text = "Voulez-vous vraiment supprimer cette page ?";

				var confirmDialog = new YAHOO.widget.SimpleDialog("Confirmation",  {
					width: "300px", 
					fixedcenter: true, 
					visible: false, 
					draggable: true, 
					close: false, 
					modal: true, 
					text: text, 
					icon: YAHOO.widget.SimpleDialog.ICON_WARN, 
					constraintoviewport: true, 
					buttons: [ { text:"Oui", handler:handleYes, isDefault:true }, { text:"Non",  handler:handleNo } ] 
				}); 
				confirmDialog.render(document.body); 
				confirmDialog.show();

			};//}}}
			this.redrawTree = function(srcEl){//{{{
				if(srcEl === null){
					var first =  YAHOO.util.Dom.getFirstChild(document.getElementById('plan'));
					if(first !== null){
						var className = first.className.substr(5, first.className.length);
						YAHOO.util.Dom.replaceClass(first, className, 'level0');
						this.redrawTree(first);
					}
				}else{
					var child = YAHOO.util.Dom.getNextSibling(srcEl);
					if(child !== null){
						var className = srcEl.className.substr(5, srcEl.className.length);
						var curLvl = parseInt(className.substr(5, className.length));
						var childLvl = parseInt(child.className.substr(10, child.className.length));

						if(childLvl - curLvl > 1){
							YAHOO.util.Dom.replaceClass(child, child.className.substr(5, child.className.length), 'level'+(curLvl+1));
							this.redrawTree(child);
						}
					}
				}
			};//}}}

		};//}}}
 		PageFrm = function(o){//{{{

			ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
			this.url = '/page.php';
			this.params = o;
			this.template = "getFrm";
			this.panel = undefined;
			var that = this;

			this.submit = function(){//{{{
				var frm = document.getElementById('page_frm');
				var ok = ANEOL.validation.validate(
					ANEOL.validation.required, {'field': frm.title}
				);
				if(ok){
					var handler = {
						success: function(o){
							ANEOL.visualisation.hideElement('loading');
							if(that.params.id_page !== undefined){ // cas props page
								that.hide();
								window.location.reload();
							}else{ // cas arbo site
								if(o.responseText !== ''){
									var plan = document.getElementById('plan');
									plan.innerHTML += o.responseText;

									var pages = YAHOO.util.Dom.getElementsByClassName('page');
									for(var p=0;p<pages.length;p++){
										var dd = new DndPage(pages[p].id);
										dd.setHandleElId(pages[p].id.replace('p', 'h'));
									}
									that.hide();
								}
							}
						},
						failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
					};
					YAHOO.util.Connect.setForm(frm);
					ANEOL.ajax('POST', that.url, handler);
				}
			};//}}}
			this.init = function(){//{{{
				this.panel = new YAHOO.widget.Dialog("page_dialog", { 
					width : "450px",
					visible : false, 
					modal: YAHOO.env.ua.ie === 0,
					constraintoviewport : true,
					buttons : [ { text:"Valider", handler:that.submit, isDefault:true }, { text:"Annuler", handler:that.hide } ]
				});

				this.panel.render(); 

				var lstTemplate = document.getElementById('id_template');
				YAHOO.util.Event.addListener(lstTemplate, "change", this.getTemplatePic);
				this.getTemplatePic();

				this.panel.center();
				this.panel.show();
			};//}}}
			this.getTemplatePic = function(e){//{{{
				var lstTemplate = document.getElementById('id_template');
				var handler = {
					success: function(o){
						ANEOL.visualisation.hideElement('loading');
						if(o.responseText !== ''){
							var pic = document.getElementById('template_pic');
							pic.src = o.responseText;
						}
					},
					failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
				};
				ANEOL.ajax('POST', that.url, handler, "action=getTemplatePic&id_template="+lstTemplate.value);
			};//}}}

		};//}}}
DndPage = function(id, sGroup, config) { //{{{
 
    DndPage.superclass.constructor.call(this, id, sGroup, config); 
 
    this.logger = this.logger || YAHOO; 
    var el = this.getDragEl(); 
    YAHOO.util.Dom.setStyle(el, "opacity", 0.67); // The proxy is slightly transparent 
 
    this.goingUp = false; 
    this.lastY = 0; 
}; //}}}
YAHOO.extend(DndPage, YAHOO.util.DDProxy, { //{{{

		startParent:undefined,
 
    startDrag: function(x, y) { //{{{
        this.logger.log(this.id + " startDrag"); 
 
        // make the proxy look like the source element 
        var dragEl = this.getDragEl(); 
        var clickEl = this.getEl(); 
				this.startParent = YAHOO.util.Dom.getPreviousSibling(clickEl);

				/*YAHOO.util.Dom.setStyle(clickEl, "visibility", "hidden"); */
        dragEl.innerHTML = clickEl.innerHTML; 
				clickEl.innerHTML = "";
				YAHOO.util.Dom.setStyle(clickEl, "border", "dashed 2px gray"); 
 
        YAHOO.util.Dom.setStyle(dragEl, "color", YAHOO.util.Dom.getStyle(clickEl, "color")); 
        YAHOO.util.Dom.setStyle(dragEl, "backgroundColor", YAHOO.util.Dom.getStyle(clickEl, "backgroundColor")); 
        YAHOO.util.Dom.setStyle(dragEl, "border", "2px solid gray"); 
    }, //}}}
    endDrag: function(e) { //{{{
 
        var srcEl = this.getEl(); 
        var proxy = this.getDragEl(); 

				srcEl.innerHTML = proxy.innerHTML;
				YAHOO.util.Dom.setStyle(srcEl, "border", "solid 1px gray"); 
 
        // Show the proxy element and animate it to the src element's location 
        YAHOO.util.Dom.setStyle(proxy, "visibility", ""); 
        var a = new YAHOO.util.Motion(  
            proxy, {  
							points: {  
								to: YAHOO.util.Dom.getXY(srcEl) 
							} 
            },  
            0.2,  
            YAHOO.util.Easing.easeOut  
        ) 
        var proxyid = proxy.id; 
        var thisid = this.id; 
 
        // Hide the proxy and show the source element when finished with the animation 
        a.onComplete.subscribe(function() { 
					YAHOO.util.Dom.setStyle(proxyid, "visibility", "hidden"); 
					YAHOO.util.Dom.setStyle(thisid, "visibility", ""); 
        }); 
        a.animate(); 

				// repositionnement
				var srcEl = this.getEl(); 
				ANEOL.planSite.redrawTree(srcEl);
				var parent = YAHOO.util.Dom.getPreviousSibling(srcEl);
				if(parent !== null){
					ANEOL.planSite.redrawTree(parent);
				}
				ANEOL.planSite.redrawTree(this.startParent);
    }, //}}}
    onDragDrop: function(e, id) { //{{{
 
    }, //}}}
    onDrag: function(e) { //{{{
 
        // Keep track of the direction of the drag for use during onDragOver 
        var y = YAHOO.util.Event.getPageY(e); 

				var srcEl = this.getEl(); 
				var x1 = YAHOO.util.Dom.getX(srcEl);
				var proxy = this.getDragEl(); 
				var x2 = YAHOO.util.Dom.getX(proxy);


				if(YAHOO.util.Dom.getPreviousSibling(srcEl) === null){
					var className = srcEl.className.substr(5, srcEl.className.length);
					YAHOO.util.Dom.replaceClass(srcEl, className, 'level0');
				}else{
					var decal = (x2-x1)/20;
					if(Math.abs(decal)>1){

						var parentLvl = YAHOO.util.Dom.getPreviousSibling(srcEl).className;
						parentLvl = parseInt(parentLvl.substr(10, parentLvl.length));
						var className = srcEl.className.substr(5, srcEl.className.length);
						var curLvl = parseInt(className.substr(5, className.length));

						if(decal > 0){
							if(curLvl < parentLvl+1){
								YAHOO.util.Dom.replaceClass(srcEl, className, 'level'+(curLvl+1));
							}
						}else{
							if(curLvl>0){
								YAHOO.util.Dom.replaceClass(srcEl, className, 'level'+(curLvl-1));
							}
						}
					}
				}

 
        if (y < this.lastY) { 
            this.goingUp = true; 
        } else if (y > this.lastY) { 
            this.goingUp = false; 
        } 
 
        this.lastY = y; 
    }, //}}}
    onDragOver: function(e, id) { //{{{
     
			var srcEl = this.getEl(); 
			var destEl = YAHOO.util.Dom.get(id); 




			// We are only concerned with list items, we ignore the dragover 
			// notifications for the list. 
			/*if (destEl.nodeName.toLowerCase() == "li") { */
					var orig_p = srcEl.parentNode; 
					var p = destEl.parentNode; 

					if (this.goingUp) { 
							p.insertBefore(srcEl, destEl); // insert above 
					} else { 
							p.insertBefore(srcEl, destEl.nextSibling); // insert below 
					} 

					YAHOO.util.DragDropMgr.refreshCache(); 
					/*}*/

    } //}}}

}); //}}}

// Gestion des éléments et des listings
	ElementFrm = function(o){//{{{
		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/element.php';
		this.template = 'getFrm';
		var that = this;

		this.submit = function(){//{{{

			var handler = {
				success: function(o){
					
					if(o.responseText !== ''){ // Cas ajout

						var ret = YAHOO.lang.JSON.parse(o.responseText); 
						newBox = document.createElement('div');
						newBox.id = 'box_'+ret.id_box;
						newBox.innerHTML = ret.content;
						YAHOO.util.Dom.addClass(newBox, "box");
						var b = new DndBox(newBox.id, "dnd");

						var before = document.getElementById(that.params.before);
						YAHOO.util.Dom.insertBefore(newBox, that.params.before);

						var container = before.parentNode;
						updateContainer(container.id);

					}else{ // Cas update
						that.reloadBox();
					}
					that.hide();
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};

			var frm = document.getElementById('frm_element');
			var ok = ANEOL.validation.validate(
				ANEOL.validation.required, {'field': frm.title, 'msg':"Veuillez saisir un titre."}
			);
			if(ok){
				frm.content.value = FCKeditorAPI.GetInstance('editor_area').GetHTML();
				YAHOO.util.Connect.setForm(frm);
				ANEOL.ajax('POST', that.url, handler);
			}
		};//}}}
		this.init = function(){//{{{
			that.panel = new YAHOO.widget.Dialog(that.container, { 
				width : "700px",
				visible : false, 
				modal: YAHOO.env.ua.ie === 0,
				close:false,
				constraintoviewport : true,
				buttons : [ /*{text:'Aide', handler:that.help},*/ { text:"Enregistrer", handler:that.submit, isDefault:true }, { text:"Annuler", handler:that.hide } ]
			});
			that.panel.render();

			var editor = new FCKeditor( 'editor_area' ) ;
			editor.Height = 420 ;
			editor.ReplaceTextarea() ;

			that.panel.center();
			that.panel.show();

		};//}}}
		this.reloadBox = function(){//{{{
			var handler = {
				success: function(o){
					var box = document.getElementById('box_'+that.params.id_box);
					box.innerHTML = o.responseText;
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			ANEOL.ajax('POST', that.url, handler, "action=boxGetElement&id_box="+that.params.id_box);
		};//}}}

	};//}}}
	ListingFrm = function(o){//{{{
		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/listing.php';
		this.template = 'getFrm';
		var that = this;

		this.submit = function(){//{{{
			var frm = document.getElementById('frm_listing');
			var ok = ANEOL.validation.validate(
				ANEOL.validation.required, {'field': frm.title},
				ANEOL.validation.required, {'field': frm.nb_items},
				ANEOL.validation.range, {'field': frm.nb_items, 'min':1, 'max':100},
				ANEOL.validation.required, {'field': frm.preview_length},
				ANEOL.validation.range, {'field': frm.preview_length, 'min':100, 'max':1000}
			);
			if(ok){
				var handler = {
					success: function(o){
						// Cas ajout
						if(o.responseText !== ''){
							var ret = YAHOO.lang.JSON.parse(o.responseText); 
							newBox = document.createElement('div');
							newBox.id = 'box_'+ret.id_box;
							newBox.innerHTML = ret.content;
							YAHOO.util.Dom.addClass(newBox, "box");
							var b = new DndBox(newBox.id, "dnd");

							var before = document.getElementById(that.params.before);
							YAHOO.util.Dom.insertBefore(newBox, before);
							updateContainer(before.parentNode.id);

							that.hide();
						// Cas update
						}else{
							that.reloadBox();
							that.hide();
						}
						ANEOL.visualisation.hideElement('loading');
					},
					failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
				};
				YAHOO.util.Connect.setForm(frm);
				ANEOL.ajax('POST', that.url, handler);
			}
		};//}}}
		this.init = function(){//{{{
			that.panel = new YAHOO.widget.Dialog(that.container, { 
				width : "480px",
				visible : false, 
				modal: YAHOO.env.ua.ie === 0,
				close:false,
				constraintoviewport : true,
				buttons : [ { text:"Valider", handler:that.submit, isDefault:true }, { text:"Annuler", handler:that.hide } ]
			});
			that.panel.render();
			that.panel.center();
			that.panel.show();
		};//}}}
		this.reloadBox = function(){//{{{
			var handler = {
				success: function(o){
					var box = document.getElementById('box_'+that.params.id_box);
					box.innerHTML = o.responseText;
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			ANEOL.ajax('POST', that.url, handler, "action=boxGetListing&id_box="+that.params.id_box);
		};//}}}

	};//}}}

// Gestion des articles + topics
	ArticlesDialog = function(o){//{{{
		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/article.php';
		this.template = 'getListDialog';
		this.dt = new ANEOL.DataTable({action:'getListDatagrid', tableElt:'dt_articles', name:'ANEOL.articlesDialog.dt', url:this.url, 'params':this.params});
		var that = this;

		that.dt.get = function(first){//{{{
			if(first !== undefined){
				that.dt.first = first;
			}
			var handler = {
				success: function(o) {
					var te = document.getElementById(that.dt.tableElt);				 
					te.innerHTML = o.responseText;					 
					that.panel.center();
					that.panel.show();
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			ANEOL.ajax('POST', this.url, handler, "action="+this.action+"&DataTableParams="+YAHOO.lang.JSON.stringify(that.dt));
		};//}}}
		this.init = function(){//{{{
			var that = this;
			this.panel = new YAHOO.widget.Dialog(this.container, { 
				width : "700px",
				fixedcenter:false,
				visible : false, 
				close : false, 
				modal: YAHOO.env.ua.ie === 0,
				constraintoviewport : true,
				buttons : [ { text:"Fermer", handler:that.hide } ]
			});
			this.panel.render();
			that.dt.get();

		};//}}}
		this.deleteArticle = function(id_article){//{{{
			var that = this;
			var handleNo = function(){
				this.hide();
			};
			var handleYes = function(){
				var handler = {
					success: function(o){
						that.dt.get();
						confirmDialog.hide();
						ANEOL.reloadListingsByTopic(that.params.id_topic);
						ANEOL.visualisation.hideElement('loading');
					},
					failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
				};
				ANEOL.ajax('POST', that.url, handler, "action=delete&id_article="+id_article);
			};
			var confirmDialog = new YAHOO.widget.SimpleDialog("Confirmation",  {
				width: "300px", 
				fixedcenter: true, 
				visible: false, 
				draggable: true, 
				close: false, 
				modal: YAHOO.env.ua.ie === 0, 
				text: "Voulez vous vraiment supprimer cette actualité ?", 
					icon: YAHOO.widget.SimpleDialog.ICON_WARN, 
					constraintoviewport: true, 
					buttons: [ { text:"Oui", handler:handleYes, isDefault:true }, 
										 { text:"Non",  handler:handleNo } ] 
			}); 
			confirmDialog.render(document.body); 
			confirmDialog.show();
		 };//}}}
	};//}}}
	ArticleFrm = function(o){//{{{
		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/article.php';
		this.template = 'getFrm';
		var that = this;

		this.init = function(){//{{{
			that.panel = new YAHOO.widget.Dialog(that.container, { 
				width : "700px",
				visible : false, 
				modal: YAHOO.env.ua.ie === 0,
				close:false,
				constraintoviewport : true,
				buttons : [ { text:"Valider", handler:that.submit, isDefault:true }, { text:"Fermer", handler:that.hide } ]
			});
			that.panel.render();
			var editor = new FCKeditor( 'editor_area' ) ;
			editor.Height = 420 ;
			editor.ReplaceTextarea() ;
			that.panel.center();
			that.panel.show();
		};//}}}
		this.submit = function(){//{{{
			var handler = {
				success: function(o){
					if(ANEOL.articlesDialog !== undefined){
						ANEOL.articlesDialog.dt.get();
					}
					ANEOL.reloadListingsByTopic(that.params.id_topic);
					that.hide();
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			var frm = document.getElementById('frm_article');
			frm.content.value = FCKeditorAPI.GetInstance('editor_area').GetHTML();
			YAHOO.util.Connect.setForm(frm);
			ANEOL.ajax('POST', that.url, handler);
		};//}}}

	};//}}}
	TopicsDialog = function(o){//{{{
		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/topic.php';
		this.template = 'getListDialog';
		this.dt = new ANEOL.DataTable({action:'getListDatagrid', tableElt:'dt_topics', name:'ANEOL.topicsDialog.dt', url:this.url, 'params':this.params});
		var that = this;

		that.dt.get = function(first){//{{{
			if(first !== undefined){
				that.dt.first = first;
			}
			var handler = {
				success: function(o) {
					var te = document.getElementById(that.dt.tableElt);				 
					te.innerHTML = o.responseText;					 
					that.panel.center();
					that.panel.show();
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			ANEOL.ajax('POST', this.url, handler, "action="+this.action+"&DataTableParams="+YAHOO.lang.JSON.stringify(that.dt));
		};//}}}
		this.init = function(){//{{{
			var that = this;
			this.panel = new YAHOO.widget.Dialog(this.container, { 
				width : "500px",
				fixedcenter:false,
				visible : false, 
				close : false, 
				modal: YAHOO.env.ua.ie === 0,
				constraintoviewport : true,
				buttons : [ { text:"Fermer", handler:that.hide } ]
			});
			this.panel.render();
			that.dt.get();

			/*that.panel.beforeHideEvent.subscribe(that.hide, that.panel, true);*/

		};//}}}
		this.deleteTopic = function(id_topic){//{{{
			var that = this;
			var handleNo = function(){
				this.hide();
			};
			var handleYes = function(){
				var handler = {
					success: function(o){
					 /*that.dt.get();*/
					 /*confirmDialog.hide();*/
						window.location.reload();
						ANEOL.visualisation.hideElement('loading');
					},
					failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
				};
				ANEOL.ajax('POST', that.url, handler, "action=delete&id_topic="+id_topic);
			};
			var confirmDialog = new YAHOO.widget.SimpleDialog("Confirmation",  {
				width: "300px", 
				fixedcenter: true, 
				visible: false, 
				draggable: true, 
				close:false, 
				modal: YAHOO.env.ua.ie === 0, 
				text: "Voulez vous vraiment supprimer ce thème et ses actualités ?", 
					icon: YAHOO.widget.SimpleDialog.ICON_WARN, 
					constraintoviewport: true, 
					buttons: [ { text:"Oui", handler:handleYes, isDefault:true }, 
										 { text:"Non",  handler:handleNo } ] 
			}); 
			confirmDialog.render(document.body); 
			confirmDialog.show();
		 };//}}}
		this.reloadBox = function(){//{{{
			var handler = {
				success: function(o){
					var box = document.getElementById('box_'+that.params.id_box);
					box.innerHTML = o.responseText;
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			ANEOL.ajax('POST', "/listing.php", handler, "action=getBox&id_box="+that.params.id_box);
		};//}}}

	};//}}}
	TopicFrm = function(o){//{{{
		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/topic.php';
		this.template = 'getFrm';
		var that = this;

		this.init = function(){//{{{
			that.panel = new YAHOO.widget.Dialog(that.container, { 
				width : "400px",
				visible : false, 
				modal: YAHOO.env.ua.ie === 0,
				constraintoviewport : true,
				buttons : [ { text:"Valider", handler:that.submit, isDefault:true }, { text:"Fermer", handler:that.hide } ]
			});
			that.panel.render();
			that.panel.center();
			that.panel.show();
		};//}}}
		this.submit = function(){//{{{
			var handler = {
				success: function(o){
					if(ANEOL.topicsDialog !== undefined){
						ANEOL.topicsDialog.dt.get();
					}
					that.hide();
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			var frm = document.getElementById('frm_topic');
			YAHOO.util.Connect.setForm(frm);
			ANEOL.ajax('POST', that.url, handler);
		};//}}}
		this.reloadBox = function(){//{{{
			var handler = {
				success: function(o){
					var box = document.getElementById('box_'+that.params.id_box);
					box.innerHTML = o.responseText;
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			//ANEOL.ajax('POST', '/listing.php', handler, "action=getBox&id_box="+that.params.id_box);
		};//}}}

	};//}}}

// Configuration + Redacteurs + pages privees + Contact
	ConfigFrm = function() {//{{{
		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/index.php';
		this.template = 'configFrm';
		var that = this;

		this.init = function(){//{{{
			that.panel = new YAHOO.widget.Dialog(that.container, { 
				width : "300px",
				visible : false, 
				close:false,
				modal: YAHOO.env.ua.ie === 0,
				constraintoviewport : true,
				buttons : [ { text:"Fermer", handler:that.hide } ]
			});
			this.panel.render();
			this.panel.center();
			this.panel.show();

		};//}}}
	};//}}}
	RedactorsDialog = function(){//{{{

		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/redactor.php';
		this.template = 'getListDialog';
		this.dt = new ANEOL.DataTable({action:'getListDatagrid', tableElt:'dt', name:'ANEOL.redactorsDialog.dt', url:this.url});
		var that = this;

		that.dt.get = function(first){//{{{
			if(first !== undefined){
				that.dt.first = first;
			}
			var handler = {
				success: function(o) {
					var te = document.getElementById(that.dt.tableElt);				 
					te.innerHTML = o.responseText;					 
					that.panel.center();
					that.panel.show();
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			ANEOL.ajax('POST', this.url, handler, "action="+this.action+"&DataTableParams="+YAHOO.lang.JSON.stringify(that.dt));
		};//}}}
		this.init = function(){//{{{
			var that = this;
			this.panel = new YAHOO.widget.Dialog(this.container, { 
				width : "500px",
				visible : false, 
				modal: YAHOO.env.ua.ie === 0,
				close:false,
				constraintoviewport : true,
				buttons : [ { text:"Fermer", handler:that.hide } ]
			});
			this.panel.render();
			that.dt.get();
		};//}}}
		this.deleteRedactor = function(id_redactor){//{{{
			var that = this;
			var handleNo = function(){
				this.hide();
			};
			var handleYes = function(){
				var handler = {
					success: function(o){
						that.dt.get();
						confirmDialog.hide();
						ANEOL.visualisation.hideElement('loading');
					},
					failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
				};
				ANEOL.ajax('POST', that.url, handler, "action=delete&id_redactor="+id_redactor);
			};
			var confirmDialog = new YAHOO.widget.SimpleDialog("Confirmation",  {
				width: "300px", 
				fixedcenter: true, 
				visible: false, 
				draggable: true, 
				close: false, 
				modal: YAHOO.env.ua.ie === 0, 
				text: "Voulez-vous vraiment supprimer ce rédacteur ?", 
					icon: YAHOO.widget.SimpleDialog.ICON_WARN, 
					constraintoviewport: true, 
					buttons: [ { text:"Oui", handler:handleYes, isDefault:true }, 
										 { text:"Non",  handler:handleNo } ] 
			}); 
			confirmDialog.render(document.body); 
			confirmDialog.show();
		 };//}}}

	};//}}}
	RedactorFrm = function(o){//{{{
		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/redactor.php';
		this.template = 'getFrm';
		var that = this;

		this.init = function(){//{{{
			that.panel = new YAHOO.widget.Dialog(that.container, { 
				width : "400px",
				visible : false, 
				modal: YAHOO.env.ua.ie === 0,
				close:false,
				constraintoviewport : true,
				buttons : [ { text:"Valider", handler:that.submit, isDefault:true }, { text:"Fermer", handler:that.hide } ]
			});
			that.panel.render();
			that.panel.center();
			that.panel.show();
		};//}}}
		this.submit = function(){//{{{
			var handler = {
				success: function(o){
					if(ANEOL.redactorsDialog !== undefined){
						ANEOL.redactorsDialog.dt.get();
					}
					that.hide();
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			var frm = document.getElementById('frm_redactor');
			var ok = ANEOL.validation.validate(
				ANEOL.validation.required, {'field': frm.name},
				ANEOL.validation.required, {'field': frm.surname},
				ANEOL.validation.required, {'field': frm.login},
				ANEOL.validation.email, {'field': frm.login},
				ANEOL.validation.required, {'field': frm.password},
				ANEOL.validation.required, {'field': frm.confirmation}
			);
			if(ok){
				if(frm.password.value != frm.confirmation.value){
					ANEOL.visualisation.displayMsg('Erreur !', "Le mot de passe n'est pas valide.", YAHOO.widget.SimpleDialog.ICON_WARN);
					frm.password.focus();
				}
				YAHOO.util.Connect.setForm(frm);
				ANEOL.ajax('POST', that.url, handler);
			}
		};//}}}

	};//}}}
		PrivPage = function(){//{{{

			ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
			this.url = '/redactor.php';
			this.template = 'getPrivateFrm';
			var that = this;

			this.submit = function(){//{{{
				var handler = {
					success: function(o){
						if(o.responseText != ""){
							ANEOL.visualisation.displayMsg('Erreur !', o.responseText, YAHOO.widget.SimpleDialog.ICON_WARN);
						}else{
							that.hide();
						}
						ANEOL.visualisation.hideElement('loading');
					},
					failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
				};
				var frm = document.getElementById('private_frm');
				var ok = ANEOL.validation.validate(
					ANEOL.validation.required, {'field': frm.ancien, 'msg':"Veuillez saisir l'ancien mot de passe."},
					ANEOL.validation.required, {'field': frm.password},
					ANEOL.validation.required, {'field': frm.confirmation}
				);
				if(ok){
					if(frm.password.value != frm.confirmation.value){
						ANEOL.visualisation.displayMsg('Erreur !', "Le mot de passe n'est pas valide.", YAHOO.widget.SimpleDialog.ICON_WARN);
						frm.password.focus();
						return false;
					}
					YAHOO.util.Connect.setForm(frm);
					ANEOL.ajax('POST', that.url, handler);
				}
			};//}}}
			this.init = function(){//{{{
				that.panel = new YAHOO.widget.Dialog("private", { 
					width : "500px",
					visible : false, 
					modal: YAHOO.env.ua.ie === 0,
					close:false,
					constraintoviewport : true,
					buttons : [ { text:"Valider", handler:that.submit, isDefault:true }, { text:"Fermer", handler:that.hide, isDefault:true } ]
				});
				that.panel.render();
				that.panel.center();
				that.panel.show();
			};//}}}

		};//}}}
	ContactFrm = function() {//{{{
		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/index.php';
		this.template = 'contactFrm';
		var that = this;

		this.submit = function(){//{{{
			var formu = document.getElementById('contact_form');
			var ok = ANEOL.validation.validate(
				ANEOL.validation.required, {'field': formu.contact_recipient, 'msg':"Le champ destinataire n'est pas valide."},
				ANEOL.validation.email, {'field': formu.contact_recipient, 'msg':"Le champ destinataire n'est pas valide."}
			);
			if(ok){
				var handler = {
					success: function(o){
						that.hide();
						window.location = window.location;
						ANEOL.visualisation.hideElement('loading');
					},
					failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
				};
				formu.contact_message.value = FCKeditorAPI.GetInstance('editor_area').GetHTML();
				YAHOO.util.Connect.setForm(formu);
				ANEOL.ajax('POST', "/index.php", handler);
			}
		};//}}}
		this.init = function(){//{{{
			that.panel = new YAHOO.widget.Dialog(that.container, { 
				width : "700px",
				visible : false, 
				modal: YAHOO.env.ua.ie === 0,
				close:false,
				constraintoviewport : true,
				buttons : [ { text:"Valider", handler:that.submit, isDefault:true }, { text:"Annuler", handler:that.hide } ]
			});
			this.panel.render();
			var editor = new FCKeditor( 'editor_area' ) ;
			editor.Height = 250 ;
			editor.ReplaceTextarea() ;
			this.panel.center();
			this.panel.show();
		};//}}}
	};//}}}

// Edition CSS / HTML et gestion themes
	StyleFrm = function(){//{{{

		ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
		this.url = '/theme.php';
		this.template = 'styleFrm';
		var that = this;

		this.submit = function(){//{{{
			var handler = {
				success: function(o){
					 window.open(window.location);
					ANEOL.visualisation.hideElement('loading');
				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			var frm = document.getElementById('frm_css');
			frm.file_content.value = editAreaLoader.getValue("file_content");
			YAHOO.util.Connect.setForm(frm);
			ANEOL.ajax('POST', '/theme.php', handler, "action=styleUpdateFile");
		}//}}}
		this.init = function(){//{{{
			that.panel = new YAHOO.widget.Dialog("dialog", { 
				width : "800px",
				visible : false, 
				modal: YAHOO.env.ua.ie === 0,
				close:false,
				constraintoviewport : true,
				buttons : [{ text:"Enregistrer et visualiser", handler:that.submit, isDefault:true }, { text:"Fermer", handler:that.hide } ]
			});
			that.panel.render();
			that.panel.center();
			that.panel.show();

			editAreaLoader.init({ 
				id : "file_content",
				syntax: "css",
				start_highlight: true,
				language: 'fr',
				allow_toggle: false,
				font_size: 8,
				toolbar:''
			});

		};//}}}
		this.getStyle = function(file){//{{{
			var handler = {
				success: function(o){
					var fn = document.getElementById('filename');
					fn.value = file;
					var txt = document.getElementById('file_content');
					txt.value = o.responseText;

					editAreaLoader.setValue("file_content", o.responseText);
					editAreaLoader.execCommand("file_content", "change_syntax", file.split('.')[1]);
					ANEOL.visualisation.hideElement('loading');

				},
				failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
			};
			ANEOL.ajax('POST', '/theme.php', handler, "action=styleGetFile&filename="+file);
		};//}}}

	};//}}}
		ThemeSelector = function(){//{{{
			ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
			this.url = '/theme.php';
			this.template = 'themeSelector';
			var that = this;

			this.init = function(){//{{{
				that.panel = new YAHOO.widget.Dialog(that.container, { 
					width : "700px",
					visible : false, 
					modal: YAHOO.env.ua.ie === 0,
					close:false,
					constraintoviewport : true,
					buttons : [{ text:"Appliquer", handler:that.applyTheme, isDefault:true }, { text:"Fermer", handler:that.hide } ]
				});
				
				var themes = YAHOO.util.Dom.getElementsByClassName('theme');
				for(i=0;i<themes.length;i++){
					YAHOO.util.Event.addListener(themes[i].id, "click", that.selectTheme); 
				}

				that.panel.render();
				that.panel.center();
				that.panel.show();
				that.panel.cfg.config.buttons.value[0].htmlButton.disabled = true;

			};//}}}
			this.selectTheme = function(e){//{{{
				var themes = YAHOO.util.Dom.getElementsByClassName('theme');
				for(i=0;i<themes.length;i++){
					YAHOO.util.Dom.removeClass(themes[i], 'selected'); 
				}
				document.getElementById('theme').value = this.id;
				YAHOO.util.Dom.addClass(this, "selected");
				that.panel.cfg.config.buttons.value[0].htmlButton.disabled = false;
			};//}}}
			this.applyTheme = function(){//{{{
				var handler = {
					success: function(o){
						that.hide();
						window.location.reload(true);
						ANEOL.visualisation.hideElement('loading');
					},
					failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
				};
				ANEOL.ajax('POST', '/theme.php', handler, "action=applyTheme&theme="+document.getElementById('theme').value);
			};//}}}

		};//}}}

// Edition Header / Footer
		BannerFrm = function(o) {//{{{
			ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
			this.url = '/index.php';
			this.template = 'bannerFrm';
			var that = this;

			this.init = function(){//{{{
				this.panel = new YAHOO.widget.Dialog(that.container, { 
					width : "500px",
					visible : false, 
					modal: YAHOO.env.ua.ie === 0,
					close:false,
					constraintoviewport : true,
					buttons : [ { text:"Valider", handler:that.submit, isDefault:true }, { text:"Annuler", handler:that.hide }]
				});
				this.panel.render();
				that.panel.center();
				this.panel.show();

				var btSelectBackground = document.getElementById("btSelectBackground"); 
				YAHOO.util.Event.addListener(btSelectBackground, "click", that.selectBackground); 
				var btResetBackground = document.getElementById("btResetBackground"); 
				YAHOO.util.Event.addListener(btResetBackground, "click", that.resetBackground); 

				var btSelectBackground = document.getElementById("btSelectLogo"); 
				YAHOO.util.Event.addListener(btSelectBackground, "click", that.selectLogo); 
				var btResetBackground = document.getElementById("btResetLogo"); 
				YAHOO.util.Event.addListener(btResetBackground, "click", that.resetLogo); 

				hb = document.getElementById('hidden_block');
				hb.style.display = 'none';
			};//}}}
			this.submit = function(){//{{{
				var handler = {
					success: function(o){
						that.hide();
						window.location = window.location;
						ANEOL.visualisation.hideElement('loading');
					},
					failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
				};
				var frm = document.getElementById('frm_banner');
				YAHOO.util.Connect.setForm(frm);
				ANEOL.ajax('POST', "/index.php", handler);
			};//}}}

			this.selectBackground = function(){//{{{
				BrowseServer('header_bg_image');
			};//}}}
			this.resetBackground = function(){//{{{ 
				var img = document.getElementById('bg');
				img.src = "/images/fond_banner.jpg";
				document.getElementById('header_bg_image').value = "";
			};//}}}
			this.selectLogo = function(){//{{{
				BrowseServer('header_logo');
			};//}}}
			this.resetLogo = function(){//{{{
				var img = document.getElementById('logo_img');
				img.src = "/images/fond_banner.jpg";
				document.getElementById('header_logo').value = "";
			};//}}}

		};//}}}
		FooterFrm = function() {//{{{
			ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
			this.url = '/index.php';
			this.template = 'footerFrm';
			var that = this;

			this.init = function(){//{{{
				that.panel = new YAHOO.widget.Dialog(that.container, { 
					width : "700px",
					visible : false, 
					modal: YAHOO.env.ua.ie === 0,
					close:false,
					constraintoviewport : true,
					buttons : [ { text:"Valider", handler:that.submit, isDefault:true }, { text:"Fermer", handler:that.hide } ]
				});
				that.panel.render();
				var editor = new FCKeditor( 'editor_area' ) ;
				editor.Height = 420 ;
				editor.ReplaceTextarea() ;
				that.panel.center();
				that.panel.show();

			};//}}}
			this.submit = function(){//{{{
				var handler = {
					success: function(o){
						that.hide();
						window.location = window.location;
						ANEOL.visualisation.hideElement('loading');
					},
					failure: function(o){ ANEOL.visualisation.displayMsg('Erreur !', o.statusText, YAHOO.widget.SimpleDialog.ICON_WARN); }
				};
				var frm = document.getElementById('frm_footer');
				frm.content.value = FCKeditorAPI.GetInstance('editor_area').GetHTML();
				YAHOO.util.Connect.setForm(frm);
				ANEOL.ajax('POST', '/index.php', handler);
			};//}}}

		};//}}}

// Periode selector
		CalendarSelector = function(){//{{{
			ANEOL.lang.extend(this, ANEOL.Dialog, arguments);
			this.url = '/index.php';
			this.template = 'calendarSelector';
			this.calendar = undefined;
			this.deb = this.fin = undefined;
			var that = this;

			this.init = function(){//{{{
				that.panel = new YAHOO.widget.Dialog(that.container, { 
					width : "430px",
					height : "300px",
					visible : false, 
					modal: YAHOO.env.ua.ie === 0,
					close:false,
					constraintoviewport : true,
					buttons : [ { text:"Valider", handler:that.submit, isDefault:true }, { text:"Fermer", handler:that.hide } ]
				});
				that.panel.render();

				that.calendar = new YAHOO.example.calendar.IntervalCalendar("calInterval");

				that.calendar.selectEvent.subscribe(function() {
					var interval = this.getInterval();
					that.deb = interval[0];
					that.fin = interval[1];
					/*
					*/
				}, that.calendar, true);
				that.calendar.render();

				that.panel.show();
				that.panel.center();

			};//}}}
			this.submit = function(){//{{{
				var duree = ((that.fin - that.deb)/86400000);
				if(duree > 62){
					ANEOL.visualisation.displayMsg('Erreur !', "La période maximale est de deux mois.", YAHOO.widget.SimpleDialog.ICON_WARN);
				}else{
					that.hide();
					window.location = '/index/analytics/'+that.deb.getFullYear() +'-'+ (that.deb.getMonth() + 1) +'-'+ that.deb.getDate()+'/'+that.fin.getFullYear() +'-'+ (that.fin.getMonth() + 1) +'-'+ that.fin.getDate()+'.html';
				}
			};//}}}

		}//}}}


