//*************************************************************
//Function to display the XML when debug = true;
//*************************************************************

function doDebug(axl,message) {
	
	if(debug)
	{
		if(axl != null)  alert(axl); 
		if(message != null) alert(message); 
	}
}





//*************************************************************
// Add commas to any number.
// source: http://www.mredkj.com/javascript/numberFormat.html
//*************************************************************
function addCommasAndRound(myNumb,decimales) {

	totalDecimales = Math.pow(10, decimales);
	nStr = Math.round(myNumb * totalDecimales) / totalDecimales;
	nStr += '';
	xx = nStr.split('.');
	xx1 = xx[0];
	xx2 = xx.length > 1 ? '.' +xx[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(xx1)) {
		xx1 = xx1.replace(rgx, '$1' + ',' + '$2');
	}
	
	var results =xx1 + xx2;
	return results;
}



//*******************************************************************************
// Add code below to happen when the users mouse is moving over the main map
// THIS FUNCTION CAN NOT BE DELETED! (the contents can, but not the definition)
//*******************************************************************************
function mapMoveMouseOperations() {

	var  showCoords = true;

	if (panning) {
		xx = IMouse.x-panX  ;
		yy = IMouse.y-panY  ;
	
		document.getElementById("mapImage").style.top = yy + "px";
		document.getElementById("mapImage").style.left = xx + "px"
		document.getElementById("mapLayer").style.top = yy + "px";
		document.getElementById("mapLayer").style.left = xx + "px"
		document.getElementById("mapLayer").onmouseup = stopPan;
		document.getElementById("mapLayer").onmouseout = stopPan
	}
	
	//calulate the distance when measureing.
	if(measuring) {
		calcDistance(IMouse.coordX,IMouse.coordY)
	}
		
	//if zomming in....
	if (zoombox==true && currentToolName=="zoominbox") {
		showCoords = false;
		moveRubberBands();
	}
	
	//if zomming OUT....
	if (zoombox==true && currentToolName=="zoomoutbox") {
		showCoords = false;
		moveRubberBands()
	}
	
	//if select ....
	if (zoombox==true && currentToolName=="select") {
		showCoords = false;
		moveRubberBands()
	}
	


	if (showCoords)
	{
		//Add the X and Y coordinates on the screen.
		exx = addCommasAndRound(IMouse.coordX,3);
		whyy = addCommasAndRound(IMouse.coordY,3);	
		document.getElementById("ex").innerHTML = exx;
		document.getElementById("why").innerHTML = whyy;
	}


}



//*******************************************************************************
// Add code below to happen when a new map is generated.
// THIS FUNCTION CAN NOT BE DELETED! (the contents can, but not the definition)
//*******************************************************************************
function onMapLoad() {
		
		//Update Scale
		document.getElementById("scale").innerHTML = myMap.scaleFraction;	
		//toggelLayerNameColor(myMap.scaleFactor)
		
		//alert(myMap.scaleFactor)
		//redraw the legend
		//createLegend();
		
		
		//calulate marker coords etc..
		//addMarker()
		
		
}





