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(o.msg);
				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(o.msg);
					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(o.msg);
					o.field.focus();
					return false;
				}
			}		
			return true;
		}//}}}
	},//}}}
	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 (text, className){//{{{
			var msg = document.getElementById('msg');
			if(msg != undefined){			
				msg.style.display = 'block';
				msg.style.visibility = 'visible';
				msg.innerHTML = text;
				if(className != undefined){
					msg.className = className;
				}else{
					msg.className = 'error';
				}
			}else{
				msg.style.display = 'none';
				msg.style.visibility = 'hidden';
				msg.innerHTML = "";
			}
		}//}}}
	},//}}}
	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"]
		}
	},//}}}
	editor:{//{{{
		edit: function(id){//{{{
			window.open('/element/edit/'+id+".html", 'edit_elt', 'menubar=no, status=no, scrollbars=auto, menubar=no, width=700, height=780');
		}//}}}
	},//}}}
	map:{//{{{
		getMapFromAdress: function (adr_comp, adr_ville){//{{{
			var trouve = false;
			var nbRech = 0;
			var geoCallback = function(point){
				if(nbRech < 2){
					if(point != null){
						var map = new GMap2(document.getElementById("map"));
						map.enableScrollWheelZoom();
						map.addControl(new GSmallMapControl());
						if(nbRech == 0){
							map.setCenter(point, 13);
						}else{
							map.setCenter(point, 16);
						}
						var marker = new GMarker(point);
						map.addOverlay(marker);
						nbRech++;
					}else{
						geo.getLatLng(adr_ville, geoCallback);
					}
				}
			};
			var geo = new GClientGeocoder();
			geo.getLatLng(adr_comp, geoCallback);
		},//}}}
		convertSexatoDeg: function (chaine){//{{{
			var stripped = chaine.substr(1,chaine.length-3);
			var vals = stripped.split('Â°');
			var degs = parseInt(vals[0]);
			var vals2 = vals[1].split("'");
			var mins = parseInt(vals2[0]);
			var secs = parseFloat(vals2[1].replace(',','.'));
			return degs + (mins/60) + (secs/3600);
		},//}}}
		getMapFromLL: function (latitude, longitude){//{{{
			var map = new GMap2(document.getElementById("map"));
			map.enableScrollWheelZoom();
			map.addControl(new GSmallMapControl());
			var point = new GLatLng(convertSexatoDeg(latitude), convertSexatoDeg(longitude));
			map.setCenter(point, 13);
			var marker = new GMarker(point);
			map.addOverlay(marker);
		}//}}}
	},//}}}
	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;					 
				},
				failure: function(o){
					ANEOL.visualisation.displayMsg(o.statusText);
				}
			};
			var trans = YAHOO.util.Connect.asyncRequest('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'){
					(i%2) ? tr.className='regular' : tr.className='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';
			}
		};//}}}

	},//}}}
	DataPickerPanel: function(o){//{{{
		if(o == undefined){
			o = {};	
		}
		// parametres
		this.panelAction = o.panelAction || '';
		this.dataTableAction = o.dataTableAction || '';				
		this.autoCompAction = o.autoCompAction || '';
		this.container = o.container || '';
		this.name = o.name || '';
		this.title = o.title || '';
		this.params = o.params || '';
		this.url = o.url || '';

		// variables d'instance
		this.panel = undefined;
		this.dt = undefined;
		this.autoComp = undefined;
		this.caller = o.caller || undefined;

		this.init = function(){//{{{
			this.getPanel();
			this.getHtml();
		};//}}}
		this.getPanel = function(){//{{{
			this.panel = new YAHOO.widget.Panel(this.container, { 
				fixedcenter: true,  
				constraintoviewport: true,  
				close:true,  
				visible:true,  
				draggable:true} ); 
			this.panel.setHeader(this.title); 
		};//}}}
		this.getHtml = function(){//{{{
			var that = this; 
			var handler = {
				success: function(o){
					that.panel.setBody(o.responseText); 
					that.panel.render(); 
					that.getDataTable();
					that.getAutoComplete();
				},
				failure: function(o){ ANEOL.visualisation.displayMsg(o.statusText); }
			};
			var trans = YAHOO.util.Connect.asyncRequest('POST', this.url, handler, "action="+this.panelAction+"&name="+this.name);
		}; //}}}
		this.getDataTable = function(){//{{{
			this.dt = new ANEOL.DataTable({action:this.dataTableAction, tableElt:'dpp_dt_cts', name:this.name+'.dt', url:this.url, params:{lettre:'%'} });
			this.dt.selectId = function(id, elt){
				var autoCompField = document.getElementById("auto_comp_field");
				autoCompField.value = elt;
				var autoCompHidden = document.getElementById("auto_comp_hidden");
				autoCompHidden.value = id;
			};
			this.dt.get();
		};//}}}
		this.getAutoComplete = function(){//{{{
			var ds = new YAHOO.util.XHRDataSource(this.url+"?action="+this.autoCompAction+"&");
			ds.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
			ds.responseSchema = {resultsList:'results', fields:['nom', 'id', 'prenom'] };

			this.autoComp = new YAHOO.widget.AutoComplete("auto_comp_field","auto_comp_container", ds);
			this.autoComp.queryQuestionMark = false;
			this.autoComp.itemSelectEvent.subscribe(this.autoCompItemSelectHandler);

			this.autoComp.resultTypeList = false;
			this.autoComp.formatResult = function(oResultItem, sQuery, sResultMatch) { 
				return oResultItem.nom+' '+oResultItem.prenom;
			}; 

			var autoComp = document.getElementById('auto_comp_field');
			autoComp.focus();
		}//}}}
		this.autoCompItemSelectHandler = function(sType, aArgs){//{{{
			var autoCompHidden = document.getElementById('auto_comp_hidden');
			autoCompHidden.value = aArgs[2].id;
		}//}}}
		this.validateSelection = function(){//{{{
			var autoCompField = document.getElementById("auto_comp_field");
			var autoCompHidden = document.getElementById("auto_comp_hidden");
			if(autoCompHidden.value != '' && autoCompField.value != ''){
				this.callback(autoCompHidden.value);
				this.panel.hide();
			}
		};//}}}
		this.callback = function(id){//{{{
		};//}}}

	}//}}}
	
};

