function mapLib(){}


mapLib.drawPrintFrame = function(scale,width,height,framing)
{
	var marginFactor = 105/100;
	var printWorldWidth = marginFactor * scale * width;
	var printWorldHeight = marginFactor * scale * height;
	
	var fx1 = framing["x1"];
	var fy1 = framing["y1"];
	var fx2 = framing["x2"];
	var fy2 = framing["y2"];
	
	// Mantis 5134 - impression PDF : 
	// Suite aux arrondis, il est possible que la condition ci-dessous soit remplie alors qu'elle ne devrait pas l'être.
	// La conséquence est dans tous les cas une requete de mise à jour de la boite englobante sans cesse appellée et un écran 
	// qui flashe (surtout sous Firefox) 
	// Pour éviter cela, la tolérance est appliquée ici aussi
	if (printWorldWidth > ((fx2-fx1)*marginFactor) || printWorldHeight > ((fy2-fy1)*marginFactor) )
	{
		// on doit recadrer l'image de façon à avoir l'entièreté du cadre (de visualisation de ce qui sera imprimé) dans la carte
		var mapCenterX = (fx2+fx1)/2;
		var mapCenterY = (fy2+fy1)/2;
		var newMapLeft = mapCenterX - printWorldWidth/2;
		var newMapTop = mapCenterY - printWorldHeight/2;
		setPrintFraming(newMapLeft, newMapTop, newMapLeft+printWorldWidth, newMapTop+printWorldHeight);
	}					
	drawFrame(scale,width,height);
};



/* ====================================================================================
/ a teste alert
/ ==================================================================================== */

mapLib.echo = function()
{
	window.alert("teste in mapLib.js");
};

/* ====================================================================================
/ Recupere la position x,y d'un objet.
/ oElement : l'objet dont la position est a determiner
/ ==================================================================================== */
mapLib.getXY = function(oElement,errorLeft,errorTop)
{
	var resultArray = [];
	resultArray[0]=mapLib.findPosX(oElement)+errorLeft;
	resultArray[1]=mapLib.findPosY(oElement)+errorTop;
	return resultArray;
};
	
/* ========================================================
/ Calcule la position en X d'un objet
/ ======================================================== */
mapLib.findPosX = function(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}
	return curleft;
};

/* ========================================================
/ Calcule la position en Y d'un objet
/ ======================================================== */
mapLib.findPosY = function(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
};





