// Activation du drag and drop
function selectMouse(e)
	{
		if (nn6) fobj = e.target;
		else		fobj = event.srcElement;

		while (fobj.tagName != "BODY" && fobj.className != "to_drag")
		{
			if (nn6) fobj = fobj.parentNode;
			else 		fobj = fobj.parentElement;
		}
	  
		if (fobj.className == "to_drag")
		{
			dobj = document.getElementById(fobj.id);
			isdrag = true;
			
			var targ = "top_"+Id2Element (fobj.id);
			tx = parseInt (param_top[targ+"_x"]*topScale); 
			ty = parseInt (param_top[targ+"_y"]*topScale); 
			
			x = nn6 ? e.clientX : event.clientX;
			y = nn6 ? e.clientY : event.clientY;
			
			document.onmouseup = mouseUp;
			document.onmousemove=moveMouse;
			return false;
		}
		else
			return true;
	}
// drag de l'élément
function moveMouse(e)
	{
	  if (isdrag)
		{
			if (nn6) 
			{ 
				valX = eval(tx + e.clientX - x);
				valY = eval(ty + e.clientY - y);
			}
			else 
			{
				valX = eval(tx + event.clientX - x);
				valY = eval(ty + event.clientY - y);
			}
			dobj.style.left = valX+"px";
			dobj.style.top = valY+"px";
			
			newPosX = parseInt(valX/topScale);
			newPosY = parseInt(valY/topScale);
			
			targ = Id2Element (dobj.id);
			document.getElementById("top_"+targ+"_set_x").value = newPosX;
			document.getElementById("top_"+targ+"_set_y").value = newPosY;
			
			onChangeX (newPosX, dobj.id);
			onChangeY (newPosY, dobj.id);
			
			return false;
		}
		else
			return true;
	}
// drop de l'élement
function mouseUp(e)
	{
		isdrag=false;
	}
// change la position horizontale de l'élément
function onChangeX (val, id)
	{
		var cuts = id.split("_");
		// Conversion en nombres
		val = parseInt(val);
		var imgWdt = parseInt(param_top['top_'+cuts[1]+'_width'])*parseInt(param_top['top_'+cuts[1]+'_z'])/100;
		// Cas extrêmes
		if ( val > siteWidth ) val = siteWidth;
		else if ( val < -imgWdt ) val = -imgWdt; 
		document.getElementById(id).value = val;
		// Prévisualisation	
		previewWidth = parseInt(topScale*val);
		var div = "top_"+cuts[1];
		param_top[div+"_x"] = val;	
		document.getElementById(div+'_view').style.left = previewWidth+"px";  
	}
// change la position verticale de l'élément
function onChangeY (val, id)
	{
		var cuts = id.split("_");
		// Conversion en nombres
		val = parseInt(val);
		var topHgt= parseInt(param_top['top_height']);
		var imgHgt = parseInt(param_top['top_'+cuts[1]+'_height'])*parseInt(param_top['top_'+cuts[1]+'_z'])/100;
		// Cas extrêmes
		if ( val > topHgt ) val = topHgt;
		else if ( val < -imgHgt ) val = -imgHgt; 
		document.getElementById(id).value = val;
		// Prévisualisation	
		previewHeight = parseInt(topScale*val);
		var div = "top_"+cuts[1];
		param_top[div+"_y"] = val;		
		document.getElementById(div+'_view').style.top = previewHeight+"px"; 
	}
// change l'échelle de l'élément
function onChangeZ (val, id)
	{
		var cuts = id.split("_");
		// cas extrêmes
		val = parseInt(val);
		if (val < 10) val = 10;
		else if (val > 100) val = 100;  
		// Initialisation des nouvelles valeurs
		var div = "top_"+cuts[1];
		param_top[div+"_z"] = val;		
		document.getElementById(id).value = val;
		// Prévisualisation	
		document.getElementById(div+'_img').width = parseInt(topScale*param_top['top_'+cuts[1]+'_width']*val/100);  
		document.getElementById(div+'_img').height = parseInt(topScale*param_top['top_'+cuts[1]+'_height']*val/100);  
	}
