/* Completion */
var currentLiCompletion=0;
var liMaxCompletion=0;
var _getKeyCompletion=new Array();
function getKeyCompletion(idInput){return _getKeyCompletion[idInput];}
function initCompletion(idInput,maxLi){
	var idPseudoSelect=idInput+"_NovaCompletion";
	liMaxCompletion=maxLi;
	currentLiCompletion=1;
	novUtils.$(idPseudoSelect).style.left=novUtils.getLeft(novUtils.$(idInput))+"px";
	novUtils.$(idPseudoSelect).style.top=novUtils.getTop(novUtils.$(idInput))+18+"px";
	$('#'+idPseudoSelect+" li").mouseover(function(){
		$(this).addClass('over');
	}).mouseout(function(){
		$(this).removeClass('over');
	}).click(function(){
		$('#'+idInput).val($(this).text());
		_getKeyCompletion[idInput]=$(this).attr('rel');
		novUtils.$(idPseudoSelect).parentNode.removeChild(novUtils.$(idPseudoSelect));
		currentLiCompletion=1;liMaxCompletion=0;
	});
}
function handlerInputCompletion(e){
	var touche=0;
	var targ=novUtils.getEvtTarget(e); 
	var idInput=targ.getAttribute('id');
	var idPseudoSelect=idInput+"_NovaCompletion";
	if (window.ActiveXObject) touche=window.event.keyCode;
	else touche=e.keyCode;
	switch(touche) {
		case 38: break;
		case 40: break;
		case 9:  break;
		case 13: validate(); break;
		case 37: break;
		case 16: break;
		case 27: deletePseudoSelect();break;
		case 39: break;
		default: xajax.call("getNovaCompletion",{parameters: new Array(idInput,targ.value)});break;
	}
	function deletePseudoSelect() {
		if (novUtils.$(idPseudoSelect)) {
			novUtils.$(idPseudoSelect).parentNode.removeChild(novUtils.$(idPseudoSelect));
			currentLiCompletion=1;liMaxCompletion=0;
		}
	}
	function validate() {
		if (novUtils.$(idPseudoSelect))	{
			novUtils.$(idInput).value=novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).firstChild.nodeValue;
			_getKeyCompletion[idInput]=novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).getAttribute('rel');
			novUtils.$(idPseudoSelect).parentNode.removeChild(novUtils.$(idPseudoSelect));
		}
		currentLiCompletion=1;liMaxCompletion=0;
		return false;
	}
}
function TabulateKeyDown(e){
	var touche=0;
	var targ=novUtils.getEvtTarget(e);
	var idInput=targ.getAttribute('id');
	var idPseudoSelect=idInput+"_NovaCompletion";
	if (window.ActiveXObject) touche=window.event.keyCode;
	else touche=e.keyCode;
	switch(touche) {
		case 9: tabu(); break;
		case 13: return false; break;
		case 38: haut();  break;
		case 40: bas();    break;
	}
	function tabu()	{
		if (novUtils.$(idPseudoSelect))	{
			novUtils.$(idInput).value=novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).firstChild.nodeValue;
			_getKeyCompletion[idInput]=novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).getAttribute('rel');
			novUtils.$(idPseudoSelect).parentNode.removeChild(novUtils.$(idPseudoSelect));
		}
		currentLiCompletion=1;liMaxCompletion=0;
	}
	function haut()	{
		if (currentLiCompletion>1) {
			novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).className="";
			currentLiCompletion-=1;
			novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).className="over";
			if (novUtils.getTop(novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion))< novUtils.getTop(novUtils.$(idPseudoSelect))+parseInt(novUtils.$(idPseudoSelect).scrollTop))
				novUtils.$(idPseudoSelect).scrollTop=parseInt(novUtils.$(idPseudoSelect).scrollTop)-parseInt(novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).offsetHeight);
		}else
			if (novUtils.$(idPseudoSelect)) 	novUtils.$(idPseudoSelect).scrollTop=0;
	}
	function bas() {
		if (currentLiCompletion<liMaxCompletion) {
			if (currentLiCompletion!=0)	novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).className="";
			currentLiCompletion+=1;
			novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).className="over";
			if (novUtils.getTop(novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion))+parseInt(novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).offsetHeight)> novUtils.getTop(novUtils.$(idPseudoSelect))+parseInt(novUtils.$(idPseudoSelect).offsetHeight)+parseInt(novUtils.$(idPseudoSelect).scrollTop))
				novUtils.$(idPseudoSelect).scrollTop=parseInt(novUtils.$(idPseudoSelect).scrollTop)+parseInt(novUtils.$(idPseudoSelect+'_li_'+currentLiCompletion).offsetHeight);
		}else
			if (novUtils.$(idPseudoSelect)) novUtils.$(idPseudoSelect).scrollTop=9999;
	}
}
function setCompletion(idInput) {
	novUtils.addEvent(novUtils.$(idInput),'keyup',handlerInputCompletion);
	novUtils.addEvent(novUtils.$(idInput),'keydown',TabulateKeyDown);
}
/* Fin - completion */


/* SortableList */
 var DragUtils = {
	swap : function(item1, item2) {
		var parent = item1.parentNode;
		parent.removeChild(item1);
		parent.insertBefore(item1, item2);
		item1.style["top"] = "0px";
		item1.style["left"] = "0px";
	},
	nextItem : function(item) {
		var sibling = item.nextSibling;
		while (sibling != null) {
			if (sibling.nodeName == item.nodeName) return sibling;
			sibling = sibling.nextSibling;
		}
		return null;
	},
	previousItem : function(item) {
		var sibling = item.previousSibling;
		while (sibling != null) {
			if (sibling.nodeName == item.nodeName) return sibling;
			sibling = sibling.previousSibling;
		}
		return null;
	}
};
function item(elmtHTML,infos) {
	var currentY = 0;
	var currentObject= false;
	var decalageTopElement=0;
	/**/
	elmtHTML.onmousedown=onMouseDown;
	elmtHTML.style["position"]="relative";
	elmtHTML.style["top"]="0px";
	/**/
	function onMouseDown(e) {
		var targ=novUtils.getEvtTarget(e); 
		if (targ!=elmtHTML) return false;
		currentObject=elmtHTML;
		currentY = (window.ActiveXObject) ? (window.event.clientY + document.body.scrollTop)  : e.pageY ;
		decalageTopElement=(window.ActiveXObject) ? (window.event.offsetY)  : e.layerY ;
		document.onmousemove=onMouseMove;
		document.onmouseup=onMouseUp;
		infos.ondown(currentObject);
		return false;
	}
	/**/
	function onMouseMove(e) {
			var difY = (window.ActiveXObject) ? (window.event.clientY+document.body.scrollTop - novUtils.getTop(currentObject)) : e.pageY-novUtils.getTop(currentObject) ;
			var newY1 = parseInt(currentObject.style["top"])+parseInt(difY)-decalageTopElement;
			currentY = (window.ActiveXObject) ? (window.event.clientY + document.body.scrollTop)  : e.pageY ;
			var item = currentObject;
			var next = DragUtils.nextItem(item);
			while (next != null && currentObject.offsetTop >= next.offsetTop - 2) {
				var item = next;
				var next = DragUtils.nextItem(item);
			}
			if (currentObject != item) {
				DragUtils.swap(currentObject, next);
				return;
			}
			var item = currentObject;
			var previous = DragUtils.previousItem(item);
			while (previous != null && currentObject.offsetTop <= previous.offsetTop + 2) {
				var item = previous;
				var previous = DragUtils.previousItem(item);
			}
			if (currentObject != item) {
				DragUtils.swap(currentObject, item);
				return;
			}
			currentObject.style["top"]=newY1+"px";
		return false;
	}
	/**/
	function onMouseUp(e) {
		infos.onup(currentObject);
		currentObject.style["top"] = "0px";
		currentObject.style["left"] = "0px";
		document.onmousemove=null;
		document.onmouseup=null;
		infos.send();
		return false;
	}
}
function ListeDragAndSort(divConteneur,classForFils,tagForFils,TableSQL,IDTableSQL,IDTriTableSQL,inputTriName,FormId,ajaxRegistryFunction,FnDown,FnUp)
{
	this.Items=new Array();
	this.infosAjax = {
		SqlTable    : TableSQL,
		IdSqlTable  : IDTableSQL,
		IdTriTable  : IDTriTableSQL,
		nameFormTri : inputTriName,
		IdForm : FormId,
		registry : ajaxRegistryFunction,
		ondown : FnDown,
		onup : FnUp,
		register : function() { xajax.call(ajaxRegistryFunction,{parameters: arguments}) },
		send :function() { this.register(this.SqlTable,this.IdSqlTable,this.IdTriTable,this.nameFormTri,xajax.getFormValues(this.IdForm));}
	}
	//var tab=novUtils.getElementsByClassName(classForFils,tagForFils,novUtils.$(divConteneur));
	//for(var i=0;i<tab.length;i++) this.Items.push(new item(tab[i],this.infosAjax));
	var tmpItems=this.Items;
	var tmpIA=this.infosAjax;
	$('#'+divConteneur+' '+tagForFils+'.'+classForFils).each(function(i) {
		tmpItems.push(new item(this,tmpIA));
	});
	this.Items=tmpItems;
	this.infosAjax=tmpIA;
}
/* Fin Sort list Ajax */
/* Anim Add Panier */
var move2panierStruct = {
	objDepart : false,
	objDestination : false,
	xajaxFunctionName : false,
	xajaxFunctionArgs :false,
	vitesse : 25,
	alpha : 50,
	move : function() {
		if (this.flyingDiv)	this.update();
		if ((this.objDepart)&&(this.objDestination))
			this.moveFunction();
		else
			return false;
	},
	moveFunction : function() { 
		if(!this.isMoving){
			this.flyingDiv = this.objDepart.cloneNode(true); 
			document.body.appendChild(this.flyingDiv);
			this.flyingDiv.style['position'] = 'absolute';
			if (window.ActiveXObject) this.flyingDiv.style['filter']="alpha(opacity="+(this.alpha)+")";
		else this.flyingDiv.style['opacity']=(this.alpha/100);
			this.flyingDiv.style.left =novUtils.getLeft(this.objDepart) + 'px';
			this.flyingDiv.style.top = novUtils.getTop(this.objDepart) + 'px';
			this.curX=novUtils.getLeft(this.objDepart);
			this.curY=novUtils.getTop(this.objDepart);
			this.flyingDiv.style.display='block';
			this.flyingDiv.style.width = this.objDepart.offsetWidth + 'px';
		}
		this.diffX=novUtils.getLeft(this.objDestination)-novUtils.getLeft(this.objDepart);
		this.diffY=novUtils.getTop(this.objDestination)-novUtils.getTop(this.objDepart);
		this.flyToBasket();
	},
	isMoving : false,
	flyingDiv : false,
	diffY : 0,
	diffX : 0,
	curX  : 0,
	curY  : 0,
	flyToBasket: function() {
		if (this.flyingDiv)
		{
			var maxDiff = Math.max(Math.abs(this.diffX),Math.abs(this.diffY));
			var moveX = (this.diffX / maxDiff) * this.vitesse;
			var moveY = (this.diffY / maxDiff) * this.vitesse;
			this.curX+=moveX;this.curY+=moveY;
			this.flyingDiv.style.left = Math.round(this.curX) + 'px';
			this.flyingDiv.style.top = Math.round(this.curY) + 'px';
			if(moveX>0 && this.curX > novUtils.getLeft(this.objDestination)) this.update();
			if(moveX<0 && this.curX < novUtils.getLeft(this.objDestination)) this.update();
			if((this.flyingDiv)&&(this.flyingDiv.style.display=='block')) setTimeout('move2panierStruct.flyToBasket()',10); 
		}
	},
	update : function() {
		this.clean();
		if (this.xajaxFunctionName) xajax.call(this.xajaxFunctionName,{parameters: this.xajaxFunctionArgs});
	},
	clean : function() {
		this.flyingDiv.style.display='none';
		this.isMoving=false;
		this.diffX=0;
		this.diffY=0;
		this.curY=0;
		this.curX=0;
		this.flyingDiv=false;
	}
}
/* Fin - Anim Add Panier */