// (c) Jean Luc Biellmann - Groupe Ressources - 2004/2010

var _FormViewData = {
	lastRowId : {}, // last row positions
	tpl : {}, // templates for edition
	reset : function () {
		$('divViewDataBody').update('');
	},
	lsRowEdit : function (element) {
		if (element && element.nodeName=='TR') {
			var id = element.id.replace(/row/,'');
			if (id>0) 
				_FormViewCtrl.edit('id='+id);
		}
	},
	// but : sélectionner la ligne courante en la marquant d'une class CSS "hover"
	// et en controlant l'ascenseur cote droit
	lsRowSelect : function (tr) {
		if (tr.nodeName!='TR')
			return false;
		var tbody = $$('#ls tbody')[0];
		// scrollTo
		var y = tr.offsetTop-$$('#ls thead')[0].offsetHeight;
		// NO px for scrollTop ???? - Firefox bug ?
		var scrollY = parseInt(Math.floor(y/tbody.offsetHeight)*tbody.offsetHeight);
////console.log('lsRowSelect : y='+y+', scrollY='+scrollY+', tbody.scrollTop='+tbody.scrollTop+', tbody.scrollHeight='+tbody.scrollHeight);
		if (y<tbody.scrollTop)
			tbody.scrollTop = y; 
		if (y+tr.offsetHeight>tbody.scrollTop+tbody.offsetHeight)
			tbody.scrollTop = (tbody.scrollTop+tbody.offsetHeight-tr.offsetHeight); 
		$$('tr.hover').invoke('removeClassName','hover');
		tr.addClassName('hover');		
	},
	getLastRowId : function () {
		// retrieve last position 
		var trs = $('ls').select('tr');
		return _FormViewData.lastRowId[_FormViewCtrl.cn];
	}
};

	//resize : function () { // needed to resize tbody... CSS2 alone don't work
		//if ($('divViewDataBody') && _FormViewCtrl.mode=='ls') {
			//var thead = $('divViewDataBody').select('thead')[0];
			//var tbody = $('divViewDataBody').select('tbody')[0];
			//var tfoot = $('divViewDataBody').select('tfoot')[0];
			//if (tbody)
				//tbody.style.height = parseInt($('divViewDataBody').offsetHeight-thead.offsetHeight-tfoot.offsetHeight)+'px';
		//}
	//},
	//fill : function (DOMObject) {
		//var p = E('p');
		//$('divViewDataBody').appendChild(p);
		//$('divViewDataBody').appendChild(DOMObject);
	//},
	//eventMouseMove : function (e) {
		//var element = Event.element(e);
		//// we look for the TR at the beginning of the line 
		//if (element && element.nodeName) {
			//while (element && element.nodeName!='TR')
				//element = element.parentNode;
			//if (element && element.nodeName=='TR' && element.id.match(/row\d+/)) {
				//_FormViewData.lsRowSelect(element);
				//e.stopPropagation();
			//}
		//}
	//},
	//eventMouseClick : function (e) {
		//var element = Event.element(e);
		//if (element) {
			//_FormViewData.lsRowEdit(element);
			//e.stopPropagation();
		//}
	//},

//Event.observe(window,'resize',function () {_FormViewData.resize();});

