/* (c) Jean Luc Biellmann - Groupe Ressources - 2009  */

Array.prototype.inArray = function (value)
{
	for (var i=0; i < this.length; i++)
		if (this[i] == value) // Matches identical (===), not just similar (==).
			return true;
	return false;
};

String.prototype.merge = function (hash) {
	var str = this;
	if (hash.length==undefined) // single hash
		for (var i in hash) {
			var regexp = new RegExp('\\$'+i,'g');
			str = str.replace(regexp,hash[i]);
		}
	else
		for (var i=0;i<hash.length;i++) // array of hashes
			for (var j in hash[i]) {
				//var regexp = new RegExp('\\['+j+'\\]','g');
				var regexp = new RegExp('\\$'+j,'g');
				str = str.replace(regexp,hash[i][j]);
			}
	return str;
};		
/* (c) 2009 - Jean Luc BIELLMANN */

function E (str,hash) {
	return new Element(str,hash);
}
function T (str) {
	return document.createTextNode(str);
}
function C (obj,hash) {
	var styles = new Array();
	styles.push(G(obj,'style'));
	for (var i in hash)
		styles.push(i+':'+hash[i]);
	S(obj,{'style':styles.join(';').replace(/(^;|;$)/,'')});
}
function S (obj,hash) {
	for (var i in hash)
		obj.setAttribute(i,hash[i]);
}
function G (obj,attr) {
	return obj.getAttribute(attr);
}
function A (obj,childs) {
	if (childs.constructor && childs.constructor.toString().indexOf('Array') != -1)
		while (childs.length)
			obj.appendChild(childs.shift());
	else
		obj.appendChild(childs)
	return obj;
}
function I (obj,html) {
	obj.update(html);
}
/* (c) Jean Luc Biellmann - Groupe Ressources - 2009  */

var JSON = Class.create({
	initialize : function () {
		this.reset();
	},
	reset : function () {
		this.url = 'index.php?json=true&';
		this.method = 'post';
		this.asynchronous = false; // if false, lock the script and wait the response
		this.formId = '';
		this.statusId = 'jsStatus'; // object which receive status
		this.onSuccess = function (json) {};
	},
	send : function () {
		//this.reset();
		var args = arguments[0];
		if (arguments.length>1)
			Object.extend(this,arguments[1]);
		try {
			var now = new Date();
			document.body.style.cursor = 'wait';
			new Ajax.Request(this.url+args+'&now='+now.getTime(), {
				method: this.method,
				asynchronous : this.asynchronous,
				parameters: (this.formId.length ? $(this.formId).serialize() : ''),
				onSuccess: (function(transport) {
					document.body.style.cursor = 'default';
					var json=transport.responseText.evalJSON();
//console.debug(json);
					if (json.now!=now.getTime())
						return false;
					if (json.status) {
						var _Status = new Status(this.statusId);
						_Status.init(json.status);
					}
					this.onSuccess(json);
				}).bind(this),
				onFailure: function(transport) {
					document.body.style.cursor = 'default';
					alert(transport.responseText);
				}
			}); // end Ajax.Request
		} catch (e) {
			document.body.style.cursor = 'default';
			alert(e);
		}
	}
});

var _JSON = new JSON();
/* (c) 2010 - Jean Luc BIELLMANN */

var Status = Class.create({
	initialize : function (id) {
		// HTML id element
		this.id = id;
	},
	chk : function () {
		if (!this.id.length || !$(this.id))
			this.id = 'status';
		if (!$('status')) {
			var div = E('div',{'id':'status'});
			div.addClassName('status');
			A(document.body,div);
		}
	},
	// reset status
	// efface le status courant
	reset : function () {
		this.chk();
		$(this.id).update('').hide();	
	},
	// init status with a hash of the form {'err':'','warn':'','info':''}
	// initialise le status au démarrage de l'application, à partir
	// de la table de hachage status
	init : function (hash) {
		this.chk();
		this.reset();
		if (hash)
			$A(['err','warn','info']).each(function (state) {
				if (hash[state] && hash[state].length) {
					if (hash[state].constructor === Array)
						$A(hash[state]).each(function (mess) {
							this.add(mess,state);
						}.bind(this));
					if (hash[state].constructor === String)
						this.add(mess,state);
				}
			}.bind(this));
		this.show();
	},
	// add a message to current status without reset
	// state should be 'err','warn' or 'info'
	// ajoute un message au status courant SANS effacer le contenu actuel
	add : function (mess,type) {
		this.chk();
		A($(this.id),E('p').update(String(mess).escapeHTML()).addClassName(type));
	},
	show : function () {
		this.chk();
		$(this.id).show();
	},
	// set a message to current status
	// state should be 'err','warn' or 'info'
	// efface le status courant et fixe le nouveau status
	set : function (mess,state) {
		this.chk();
		this.reset();
		this.add(mess,state);
		this.show();
	},
	err : function (mess) {
		this.set(mess,'err');
	},
	info : function (mess) {
		this.set(mess,'info');
	},
	warn : function (mess) {
		this.set(mess,'warn');
	}
});

/* (c) 2009 - Jean Luc BIELLMANN */

function blank (url) {
	window.open('http://'+url.replace('http://',''),'','');
}
/* (c) 2010 - Jean Luc BIELLMANN */

var mouseDragTimeOut = null;

function mouseEvent (e) {
	//$('debug').update(e.type+Date());
	//console.log(e.type+Date());
	var obj = (e && Event.element(e)) ? Event.element(e) : null;
	//if (e.preventDefault) // FFpreventDrag
		//e.preventDefault();
	switch(e.type) {
		case 'mousedown':
			if (obj && obj.hasClassName('signal') && !mouseDragTimeOut)
				_ShowRoom.drag(e);
				//mouseDragTimeOut = setTimeout(function () { _ShowRoom.drag(e); },200);
			break;
		case 'mouseup':
			//clearTimeout(mouseDragTimeOut);
			//mouseDragTimeOut = null;
			if (obj && _ShowRoom.draging && _ShowRoom.img)
				_ShowRoom.drop(e);
			break;
		case 'mousemove':
			if (_ShowRoom.draging) {
				_ShowRoom.move(e);
				Event.stop(e);
			}
			break;
		case 'mouseover':
			if (obj.hasClassName('signalover'))
				_ShowRoom.dynamic(e);
			break;
		case 'click':
			if (obj && obj.hasClassName('iconclose') && confirm('Effacer l\'objet de votre sélection ?'))
				_ShowRoom.del(obj);
			break;
		case 'dblclick':
			_ShowRoom.dblclick(e);
			break;
	}
	return true;
}

function setMouseEvents () {
	Event.observe(document.body,'mousedown',mouseEvent);
	Event.observe(document.body,'mousemove',mouseEvent);
	Event.observe(document.body,'mouseup',mouseEvent);
	Event.observe(document.body,'mouseover',mouseEvent);
	Event.observe(document.body,'click',mouseEvent);
	Event.observe(document.body,'dblclick',mouseEvent);

	// BLOODY IE HACKS, LIKE ALWAYS...
	// prevent text selection in IE
	//document.onselectstart = function () { return false; };
	// prevent IE from trying to drag an image
	document.ondragstart = function() { return false; };
}



/* (c) 2010 - Jean Luc BIELLMANN */

//function keyEvent (e) {
	//var obj = (e && Event.element(e)) ? Event.element(e) : null;
	//switch(e.type) {
		//case 'keyup':
			//_Form.setCookie(obj);
			//break;
	//}		
//}

function setKeyboardEvents () {
	// Desactivated because IE 8 is not fast enough to support it...
	//Event.observe(document.body,'keyup',keyEvent);
}
/* (c) Jean Luc Biellmann - Groupe Ressources - 2010  */

var _Form = {
	err : function (mess) {
		alert(mess);
		return false;
	},
	getLabelFor : function (id) {
		return $$('label[for="'+id+'"]') ? $$('label[for="'+id+'"]')[0].innerHTML : '';
	},
	getValue : function (id) {
		return $(id) ? $F(id) : ''; // $F ONLY for non multiple select !!!
	},
	setCheckedFields : function (formId,fieldsIds) {
		$A(fieldsIds).each(function (id) {
			if ($(id) && $(id).form && $(id).form.id==formId)
				Event.observe($(id),'change',_Form.chkField);	
		});			
	},
	setNotNull : function (formId,fieldsIds) {
		$A(fieldsIds).each(function (id) {
			if ($$('label[for="'+id+'"]')) {
				var td = $$('label[for="'+id+'"]')[0].parentNode;
				A(td,E('span').update(' *').addClassName('tahoma red'));
			}
		});
	},
	setTabIndex : function (formId,fieldsIds) {
		// IE bug (again) : need to force tabIndex instead of tabindex. Both syntax works on FireFox/Iceweasel..
		// http://o.dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-support/dojo-query-tabindex-not-working-me-ie
		var i=1;
		$A(fieldsIds).each(function (field) {
			if ($(field) && $(field).descendantOf(formId))
				S($(field),{'tabIndex':i++});
		});
	},
	setFields : function (formId,fieldsIds,datas,fromCookie) {
		var val, radioname;
		if (!$(formId))
			return false;
		// retrieve datas from cookie
		$(formId).select('textarea').each(function (obj) {
			val = null;
			if (datas[obj.id] && datas[obj.id].length)
				val = datas[obj.id];
			else
				if (fromCookie)
					val = _Cookie.get(obj.id);
			if (val!=null && val.length)
				obj.value = String(val).escapeHTML();
				//obj.update(String(val).escapeHTML());
				//obj.innerHTML = String(val).escapeHTML();
		});
//console.log(formHash);
//console.log($(formId).select('input'));
		$(formId).select('input').each(function (obj) {
			if (obj.id.length) {
				val = null;
				if (datas[obj.id] && datas[obj.id].length)
					val = datas[obj.id];
				else
					if (fromCookie)
						val = _Cookie.get(obj.id);
				if (obj.type=='text')
					if (val!=null && val.length)
						obj.value = String(val).escapeHTML();
				if (obj.type=='radio') {
					if (val!=null && val.length) {
						radioname = $(obj.id).name;
						if (radioname)
							$(formId).select('input[type="radio"][name="'+radioname+'"][value="'+String(val).escapeHTML()+'"]')[0].checked='checked';
					}
				}
			}
		});		
	},
	setCookie : function (obj) {
		if (obj)
			switch(obj.nodeName) {
				case 'INPUT':
					if (obj.type!='password')
						_Cookie.set(obj.id,obj.value);
					break;
				case 'TEXTAREA':
					_Cookie.set(obj.id,obj.value);
					break;
			}
	},
	chkFieldMatch : function (label,id,value,subset) {
//console.log(label);
//console.log(id);
//console.log(value);
//console.log(subset);
		var re1 = new RegExp('^['+subset+']+$');
		var re2 = new RegExp('[^'+subset+']+','gi');
		if (!value.match(re1)) {
			$(id).value = value.replace(re2,'');
			_Form.setCookie($(id));
			alert('Le champ "'+label+'" contenait des caractères interdits. Merci de vérifier les corrections et de revalider le formulaire.');
			return false;
		}
		return true;
	},
	chkFieldEmpty : function (label,id,value) {
		if (!value.length) {
			alert('Le champ "'+label+'" doit être renseigné !!!');
			return true;
		}
		return false;
	},
	chkFieldValid : function (label,id,value,regexp) {
		if (!value.match(regexp)) {
			alert('Le format du champ "'+label+'" n\'est pas valide. Merci de le corriger et de revalider le formulaire.');
			return false;
		}
		return true;
	},
	chkFieldLengthMin : function (label,id,value,mincars) {
		if (value.length<mincars) {
			alert('Le champ" '+label+'" est trop petit. Il doit être de '+mincars+' caractères minimum. Merci de le corriger et de revalider le formulaire');
			return true;
		}
		return false;
	},
	chkFieldLengthMax : function (label,id,value,maxcars) {
		if (value.length>maxcars) {
			$(id).value = value.substr(0,maxcars);
			alert('Le champ" '+label+'" était trop grand et a été tronqué à '+maxcars+' caractères. Merci de vérifier les corrections et de revalider le formulaire.');
			return true;
		}
		return false;
	},
	chkField : function (e) {
		var o  = Event.element(e);
		if (!o || !o.id)
			return false;
		_Form.chkFieldId(o.id);
	},
	chkFieldId : function (id) {
		var label = _Form.getLabelFor(id);
		var value = _Form.getValue(id);
//console.log(label+' : '+value);
		switch (id) {
			case 'fn':
				if (value.length) {
					if (_Form.chkFieldLengthMax(label,id,value,200))
						return false;
					if (!_Form.chkFieldMatch(label,id,value,ALPHABET_FR+'\\-\\ '))
						return false;
				}
				break;
			case 'ln':
				if (_Form.chkFieldEmpty(label,id,value))
					return false;
				if (_Form.chkFieldLengthMax(label,id,value,200))
					return false;
				if (!_Form.chkFieldMatch(label,id,value,ALPHABET_FR+'\\-\\ \\\''))
					return false;
				break;
			case 'tel':
			case 'handy':
			case 'fax':
				if (value.length) {
					if (_Form.chkFieldLengthMax(label,id,value,20))
						return false;
					if (!_Form.chkFieldMatch(label,id,value,'0-9\\+\\.\\ \\-\\(\\)'))
						return false;
				}
				break;
			case 'login':
			case 'email':
				if (_Form.chkFieldEmpty(label,id,value))
					return false;
				if (_Form.chkFieldLengthMax(label,id,value,200))
					return false;
				if (!_Form.chkFieldMatch(label,id,value,'a-zA-Z0-9\\.\\-\\_\\@'))
					return false;
				if (!_Form.chkFieldValid(label,id,value,/^[a-zA-Z0-9\.\-\_]+@[a-zA-Z0-9\.\-\_]+\.[a-zA-Z]{2,3}$/))
					return false;
				break;
			case 'pass':
				if (_Form.chkFieldEmpty(label,id,value))
					return false;
				if (_Form.chkFieldLengthMin(label,id,value,8))
					return false;
				if (_Form.chkFieldLengthMax(label,id,value,30))
					return false;
				if (!_Form.chkFieldMatch(label,id,value,ALPHABET_FR+'a-zA-Z0-9\\.\\-\\_\\@'))
					return false;
				break;
			case 'adr':
				if (value.length) {
					if (_Form.chkFieldLengthMax(label,id,value,200))
						return false;
					if (!_Form.chkFieldMatch(label,id,value,ALPHABET_FR+'0-9\\-\\ \\"\\\'\\,\\.\\r\\n'))
						return false;
				}
				break;
			case 'zip':
				if (value.length) {
					if (_Form.chkFieldLengthMax(label,id,value,10))
						return false;
					if (!_Form.chkFieldMatch(label,id,value,'A-Z\\-0-9'))
						return false;
				}
				break;
			case 'city':
				if (value.length) {
					if (_Form.chkFieldLengthMax(label,id,value,200))
						return false;
					if (!_Form.chkFieldMatch(label,id,value,ALPHABET_FR+'\\(\\)\\-\\ \\\''))
						return false;
				}
				break;
			case 'mess':
				if (_Form.chkFieldEmpty(label,id,value))
					return false;
				if (_Form.chkFieldLengthMax(label,id,value,2000))
					return false;
				if (!_Form.chkFieldMatch(label,id,value,ALPHABET_FR+'0-9\\!\\?\\/\\-\\ \\\'\\_\\,\\:\\;\\.\\t\\r\\n\\&\\~\\#\\{\\(\\[\\|\\`\\ç\\@\\)\\]\\=\\+\\$\\%\\µ\\*\\²\\<\\>'))
					return false;
				break;
		}
		_Form.setCookie($(id));
		return true;
	},
	chkAll : function (ids) {
		$A(ids).each(function (id) {
			if (!_Form.chkFieldId(id))
				return false;	
		});
		return true;
	},
	fillHash : function (formId,hash,fromCookie) {
		var val, radioname;
		// retrieve datas from cookie
		$(formId).select('textarea').each(function (obj) {
			val = null;
			if (hash[obj.id] && hash[obj.id].length)
				val = hash[obj.id];
			else
				if (fromCookie)
					val = _Cookie.get(obj.id);
			if (val!=null && val.length)
				obj.update(String(val).escapeHTML());
		});
//console.log(formHash);
//console.log($(formId).select('input'));
		$(formId).select('input').each(function (obj) {
			if (obj.id.length) {
				//alert(obj.id);
				val = null;
				if (hash[obj.id] && hash[obj.id].length)
					val = hash[obj.id];
				else
					if (fromCookie)
						val = _Cookie.get(obj.id);
				//if (obj.type=='text')
					//alert(val);
				if (obj.type=='text')
					if (val!=null && val.length)
						obj.value = String(val).escapeHTML();
				if (obj.type=='radio') {
					if (val!=null && val.length) {
						radioname = $(obj.id).name;
						if (radioname)
							$(formId).select('input[type="radio"][name="'+radioname+'"][value="'+String(val).escapeHTML()+'"]')[0].checked='checked';
					}
				}
			}
		});		
	}
};
/*
* Cookie is written by Carlos Reche. It is available on the Scripaculous wiki
* modified by Jean Luc BIELLMANN - 2010
*/

var _Cookie = {
	set: function(name, value, daysToExpire) {
		var expire = '';
//console.log('cookie set to '+name+', value='+value);
		if (daysToExpire != undefined) {
			var d = new Date();
			d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
			expire = '; expires=' + d.toGMTString();
		}
		return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
	},
	get: function(name) {
		var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
//console.log(unescape(cookie.join(',')));
		return (cookie ? unescape(cookie[2]) : null);
	},
	erase: function(name) {
		var cookie = _Cookie.get(name) || true;
		_Cookie.set(name, '', -1);
		return cookie;
	},
	accept: function() {
		if (typeof navigator.cookieEnabled == 'boolean') 
			return navigator.cookieEnabled;
		_Cookie.set('_test', '1');
		return (_Cookie.erase('_test') === '1');
	}
};
/* (c) Jean Luc Biellmann - Groupe Ressources - 2009  */

var _Tab = {
	effect : null,
	show : function (id) {
		$$('.tab').invoke('hide');
		//Effect.toggle(id,'appear');
		if (this.effect)
			this.effect.cancel();
		this.effect = new Effect.Appear(id, {duration:1, fps:25, from:0.0, to:1.0});
	}
};
/* (c) Jean Luc Biellmann - Groupe Ressources - 2009  */

var Loader = Class.create({
	initialize : function(obj) {
		this.obj = $(obj);
		this.div = E('div').hide();
		this.zIndex = '1000';
		C(this.div,{'position':'absolute','zIndex':this.zIndex});
		A(this.obj.parentNode,this.div);
		this.img = E('img',{'src':'/img/loader.gif','alt':'Chargement en cours...','title':'Chargement en cours...'});
		A(this.div,this.img);
		A(this.obj.parentNode,this.div);		
	},
	on : function () {
		C(this.div,{'left':0,'top':0,'width':this.obj.offsetWidth+'px','height':this.obj.offsetHeight+'px'});
		this.div.show();
		C(this.img,{'position':'absolute','left':parseInt((this.div.offsetWidth-this.img.offsetWidth)/2)+'px','top':parseInt((this.div.offsetHeight-this.img.offsetHeight)/2)+'px'});
	},
	off : function () {
		this.div.hide();
	}
});
/* (c) Jean Luc Biellmann - Groupe Ressources - 2009  */

var ALPHABET_FR = 'a-zA-ZÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ';

var _FormUsr = {
	ids : [],
	chkAll : function () {
		$A(_FormUsr.ids).each(function (id) {
			if (!_Form.chkFieldId(id))
				return false;
		});
		return true;
	},
	reset : function () {
		$A(_FormUsr.ids).each(function (id) {
			if ($(id).nodeName=='TEXTAREA' || ($(id).nodeName=='INPUT' && $(id).type.toUpperCase().match(/(TEXT|PASSWORD)/)))
				$(id).value = '';
		});
	},
	init : function () {
		if ($('FormUsr')) {
			_FormUsr.ids = $('FormUsr').select('label').pluck('htmlFor');
			$A(_FormUsr.ids).each(function (id) {
				Event.observe($(id),'change',_Form.chkField);
			});
		}
	}
};

Event.observe(window,'load',_FormUsr.init);
/* (c) 2010 - Jean Luc BIELLMANN */

var TableLs = Class.create({
	table : null,
	hover : null,
	container : null,
	
	// slots
	slotAdd : function (e) {},
	slotEdit : function (e) {},
	slotCopy : function (e) {},
	slotCopyLast : function (e) {},
	slotDel : function (e) {},

	initialize : function (tbl,rows,container) {
		this.table = this.buildArray(tbl,rows);
		this.container = $(container);
		this.fill(this.table);
		$(this.container).update(this.table);
		Event.observe(window,'resize',this.resize.bind(this));
	},
	addEvents : function () {
		Event.observe(this.table,'mousemove',this.mouseMove.bind(this));
		Event.observe(this.table,'click',this.mouseClick.bind(this));
		Event.observe(this.table,'keydown',this.keyDown.bind(this));
		Event.observe(this.table,'keyup',this.keyUp.bind(this));
	},
	getHover : function (e) {
		var obj = Event.element(e);
		while (obj && obj.parentNode && (obj.nodeName!='TR' || !obj.id || !obj.id.match(/row[0-9]+/)))
			obj = obj.parentNode;
		return obj;
	},
	setHover : function (tr) {
		this.table.select('tr.hover').invoke('removeClassName','hover');
		this.hover = (tr && tr.nodeName=='TR') ? tr.addClassName('hover') : null;
	},
	keyDown : function (e) {
console.log('TableLs::keyPress : keyCode='+e.keyCode);		
		if (!this.hover)
			this.hover = this.table.select('tbody')[0].down('tr');
		if (this.hover!=null)
			switch (e.keyCode) {		
				case Event.KEY_UP:
					var prev = e.shiftKey ? this.hover.previous('tr',5) : this.hover.previous('tr');
					if (prev && prev.id && prev.id.match(/row[0-9]+/)) {
						this.setHover(prev);
						e.stopPropagation();
						return false;
					}
					break;
				case Event.KEY_DOWN:
					var next = e.shiftKey ? this.hover.next('tr',5) : this.hover.next('tr');
					if (next && next.id && next.id.match(/row[0-9]+/)) {
						this.setHover(next);
						e.stopPropagation();
						return false;
					}
					break;
			}
		return true;
	},
	keyUp : function (e) {
console.log('TableLs::keyDown : keyCode='+e.keyCode);		
		if (!this.hover)
			this.hover = this.table.select('tbody')[0].down('tr');
		if (this.hover!=null)
			switch (e.keyCode) {
				//case Event.KEY_RETURN:
				// case Event.KEY_RIGHT:
				case 32: // SPACE
					this.slotEdit(e);
					e.stopPropagation();
					return false;
					break;
			}
		return true;
	},
	mouseMove : function (e) {
		this.setHover(this.getHover(e));
		return true;
	},
	mouseClick : function (e) {
		if (this.hover!=null)
			this.slotEdit(e);
		return true;
	},
	setLastRowId : function (lastRowId) {
		if (lastRowId) {
			var row = this.table.select('tr[id="row'+lastRowId+'"]');
			if (row.length)
				this.setHover(row[0]);
		}
	},
	resize : function () { // needed to resize tbody... CSS2 alone don't work
		if (this.table!=null && this.table.up('div')!=undefined) {
			var h = this.table.up('div').offsetHeight;
			var thead = this.table.select('thead')[0];
			var tfoot = this.table.select('tfoot')[0];
			var tbody = this.table.select('tbody')[0];
			if (thead)
				h -= thead.offsetHeight;
			if (tfoot)
				h -= tfoot.offsetHeight;
			if (tbody && h>150)
				tbody.style.height = parseInt(h)+'px';
		}
	},
	buildArray : function (tbl,rows) {
		var div,table,thead,tbody,tfoot,th,td,txt,i,j,key;
		var cols = $A(tbl.cols.split(','));
		var hidden = $A(tbl.hidden.split(','));
		var thead_align = $A(tbl.thead_align.split(','));
		var tbody_align = $A(tbl.tbody_align.split(','));
		table = E('table',{'id':'ls','tabIndex':'1'}).addClassName('ls');
		// thead
		thead = E('thead');
		tr = E('tr');
		j=0;
		cols.each(function (col) {
			th = E('th').update(col).addClassName(thead_align[j++]);
			tr.appendChild(th);
		});
		thead.appendChild(tr);
		table.appendChild(thead)
		// tfoot
		tfoot = E('tfoot');
		tr = E('tr');
		td = E('td',{'colspan':cols.length}).update('Sélection ligne : flèches haut/bas - Édition : flèche droite.');
		tr.appendChild(td);
		tfoot.appendChild(tr);
		table.appendChild(tfoot);
		// tbody			        
		tbody = E('tbody');
		i=1;
		$A(rows).each(function (row) {
			tr = E('tr',{'id':'row'+row['id']});
			tr.addClassName(i++%2 ? 'odd' : 'even');
			j = 0;
			for (key in row) {
				if (hidden.inArray(key))
					continue;
					console.debug(row[key]);
				div = E('div').update(row[key]);
					console.debug(div.innerHTML);
				td = E('td');
				td.appendChild(div).addClassName(tbody_align[j++]);
				tr.appendChild(td);
			}
			tbody.appendChild(tr);
		});
		table.appendChild(tbody);
		return table;
	},
	fill : function (DOMObject) {
		//this.container.appendChild(E('p'));
		this.container.appendChild(DOMObject);
	}
});
/* (c) 2010 - Jean Luc BIELLMANN */

var TableEdit = Class.create({
	// slots
	slotLs : function (e) {},
	slotRec : function (e) {},
	slotDel : function (e) {},

	initialize : function () {
	},
	keyDown : function (e) {
console.log('keyDown : keyCode='+e.keyCode);		
		switch (e.keyCode) {
			case Event.KEY_RETURN:
				if (e.shiftKey) {
					this.slotRec();
					e.stopPropagation();
				}
				break;
			case Event.KEY_DELETE:		
				if (e.shiftKey) {
					if (confirm('Effacer la fiche ?'))
						this.slotDel();
					e.stopPropagation();
				}
				break;
			case Event.KEY_ESC:
				this.slotLs();
				e.stopPropagation();
				break;
		}
		return true;
	}
});
/* (c) Jean Luc Biellmann - Groupe Ressources - 2010  */

var _Window = {
	center : function (element) {
		var x=0, y=0;
		if($(element) != null) {
			if(typeof window.innerHeight != 'undefined') {
				x = Math.round(document.viewport.getScrollOffsets().left + ((window.innerWidth - $(element).getWidth()))/2);
				y = Math.round(document.viewport.getScrollOffsets().top + ((window.innerHeight - $(element).getHeight()))/2);
			} else {
				x = Math.round(document.body.scrollLeft + (($$('body')[0].clientWidth - $(element).getWidth()))/2);
				y = 	Math.round(document.body.scrollTop + (($$('body')[0].clientHeight - $(element).getHeight()))/2);
			}
			$(element).style.left = x+'px';
			$(element).style.top = y+'px';		
		}
	}
};

