/**
		-------------------------------------------------------
		Classe acai_carto_infos
		-------------------------------------------------------
		Description : 
*/
function acai_carto_infos(pNom, pLeft, pTop, pWidth, pHeight) {
	var fMapWidth;
	var fMapHeight;
	var fMapXmin;
	var fMapXmax;
	var fMapYmin;
	var fMapYmax;
	var fGeoWidth;
	var fGeoHeight;
	var fDistance;
	var fDistanceTotale;
	var fProjection;
	var fGeoX;
	var fGeoY;
	var isShown = 0;
	var fScaleColor = document.body.text;

	this.setScaleColor = function(pColor) {
		fScaleColor = pColor;
	};

	this.setProjection = function(pProjection) {
		fProjection = acai_carto_utils.findProjectionText(pProjection);
	};

	this.setGeoPos = function(pGeoX,pGeoY) {
		if (pGeoX === 0 && pGeoY ===0) {
			fGeoX = '';
			fGeoY = '';
		} else {
			fGeoX = acai_carto_utils.decimalRound(fMapXmin + (fMapXmax-fMapXmin)*pGeoX / fMapWidth,2);
			fGeoY = acai_carto_utils.decimalRound(fMapYmax - (fMapYmax-fMapYmin)*pGeoY / fMapHeight,2);
		}
		if (isShown === 1) {
			this.refresh();
		}
	};

	this.setGeoDim = function(pMapWidth,pMapHeight,pMapXmin,pMapXmax,pMapYmin,pMapYmax) {
		fMapWidth = pMapWidth;
		fMapHeight = pMapHeight;
		fMapXmin = pMapXmin;
		fMapXmax = pMapXmax;
		fMapYmin = pMapYmin;
		fMapYmax = pMapYmax;
		fGeoWidth = acai_carto_utils.decimalRound(fMapXmax-fMapXmin,2);
		fGeoHeight = acai_carto_utils.decimalRound(fMapYmax-fMapYmin,2);
		if (isShown === 1) {
			this.refresh();
		}
	};

	this.setDistance = function(pDistance,pDistanceTotale) {
		if (pDistance === -1 ) {
			fDistance = '';
			fDistanceTotale = '';
		} else {
			fDistance = adaptDistance(pDistance);
			fDistanceTotale = adaptDistance(pDistanceTotale);
		}
		if (isShown === 1) {
			this.refresh();
		}
	};

	this.init = function(pMapWidth,pMapHeight,pMapXmin,pMapXmax,pMapYmin,pMapYmax) {
		this.setGeoDim(pMapWidth,pMapHeight,pMapXmin,pMapXmax,pMapYmin,pMapYmax);
		this.setGeoPos(0,0);
		this.setDistance(-1);
	};

	this.show = function() {
		this.refresh();
		isShown = 1;
	};
	

	this.refresh = function() {
		this.setContenu(getContenuHTML(this.getColor(),this.getBgColor()));
	};
	
	this.getScaleInfo = function(pColor,pBgColor) {
		return scaleInfo(pColor,pBgColor);
	};
	
	function getContenuHTML(pColor,pBgColor) {
		var pContenu = '<div style=\"font-size:65%;color:' + pColor + ';\"><table width=\"100%\" cellpadding=\"3\" cellspacing=\"0\" >'
			+ "<tr>"
			+ "<td><span style=\"font-family:Arial;font-size:8pt;\">" + scaleInfo(pColor,pBgColor) + "</span></td>"
			+ "<td><span style=\"font-family:Arial;font-size:8pt;\">" + boundsInfo() + "</span></td>"
			+ "<tr>"
		        + "</tr>"
			+ "<td><span style=\"font-family:Arial;font-size:8pt;\">" + coordinatesInfo() + "</span></td>"
		//	+ "<td><span style=\"font-family:Arial;font-size:8pt;\">" + distanceInfo() + "</span></td>"
			+ "</tr>"
			+ "</table></div>";
		return pContenu;
	}

	function scaleInfo(pColor,pBgColor) {
		var fColor = pColor || document.body.text;
		var fBgColor = pBgColor || document.body.bgColor;
		// longueur initiale de la barre
		var scale_width = Math.round(fMapWidth/SCALE_FACTOR);
		var geo_width = Math.round(fGeoWidth/SCALE_FACTOR);
		// recherche du premier chiffre
		var firstNumber = geo_width.toString().substr(0,1);
		// recherche du nombre de chiffres
		var totalNumbers = geo_width.toString().length;
		// generation d une longueur approximative
		var new_geo_width = firstNumber;
		for (var i=1 ; i<totalNumbers ; i++ ) {
			new_geo_width += '0';
		}
		var new_scale_width = (new_geo_width * fMapWidth / fGeoWidth)/SCALE_ZONES;

		var scale_infos = '';
		for (i=1 ; i<=SCALE_ZONES ; i++) {
			scale_infos += '<img src=\'' + VIEWER_LOCATION + 'px.gif\' '
				+ 'width=\'' + new_scale_width + '\' height=\'' + SCALE_HEIGHT + '\' '
				+ 'border=\'1\' '
				+ 'style=\'border-color:' + fColor;
			if (Math.round(i/2)*2 === i) {
				scale_infos += ';background:' + fColor;
			} else {
				scale_infos += ';background:' + fBgColor;
			}
			scale_infos += '\' '
				+ '>';
		}
		scale_infos += ' ' + adaptUnits(new_geo_width);

		return scale_infos;
	}

	function coordinatesInfo() {
		return "X : " + fGeoX + MAP_UNITS + " / Y : " + fGeoY + MAP_UNITS
			+ ( (fProjection != "?" ) ? " (" + fProjection + ")" : "");
	}

	function boundsInfo() {
		return INFO_ZONE_WIDTH + " : " + adaptUnits(fGeoWidth) + " / " + INFO_ZONE_HEIGHT + " : " + adaptUnits(fGeoHeight);
	}

	function distanceInfo() {
	// commenté BM 	var distance_info = INFO_ZONE_DISTANCE + " : " + fDistance; et remplacé par ligne suivante
		var distance_info = fDistance;
		if (fDistanceTotale !='') {
				distance_info += ' (' + INFO_ZONE_DISTANCE_TOTAL +' : ' + fDistanceTotale + ")";
		}
		return distance_info;
	}
/*
	function acai_carto_utils.decimalRound(myNumber,decimals) {
		var sNumber = myNumber.toString();
		var pos = sNumber.indexOf(".");
		if (pos != -1) {
			if ( (pos+decimals+1) < sNumber.length ) {
				sNumber = sNumber.substr(0,pos+decimals+1);
			}
		}
		return sNumber;
	}
*/
	function intMillier(myNumber) {
		var sNumber = myNumber.toString();
		var pos = sNumber.indexOf(".");
		if (pos != -1) {
			sNumber = sNumber.substr(0,pos);
		}
		var reste = sNumber.length%3;
		var div = (sNumber.length-reste)/3;
		var sMillier = sNumber.substr(0,reste);
		for (var i=1 ; i<=div ; i++) {
			if (reste == 0 && i==1 ) {
				sMillier = sMillier + sNumber.substr(reste + (i-1)*3 , 3);
			} else {
				sMillier = sMillier + "." + sNumber.substr(reste + (i-1)*3 , 3);
			}
		}
		return sMillier;
	}

	function adaptUnits(myNumber) {
		var units = MAP_UNITS;
		if (myNumber >= MAP_FACTOR_UNITS) {
			myNumber = myNumber/MAP_FACTOR_UNITS;
			units = MAP_SUPRA_UNITS;
		}
		var nbAvant;
		if (myNumber.toString().indexOf(".") == -1) {
			nbAvant = myNumber.toString().length;
		} else {
			nbAvant = myNumber.toString().indexOf(".");
		}
		var newNumber = "";
		if (nbAvant == 4) {
			newNumber = myNumber.toString().substring(0,3) + "0";
		}
		if (nbAvant == 3) {
			newNumber = myNumber.toString().substring(0,3);
		}
		if (nbAvant == 2) {
			newNumber = myNumber.toString().substring(0,4);
		}
		if (nbAvant == 1) {
			newNumber = myNumber.toString().substring(0,4);
		}
		
		return(newNumber + units);
/*
		if (myNumber >= MAP_FACTOR_UNITS) {
			return(intMillier(myNumber/MAP_FACTOR_UNITS) + MAP_SUPRA_UNITS);
		} else {
			return(intMillier(myNumber) + MAP_UNITS);
		}
*/
	}

	function adaptDistance(myNumber) {
		if (myNumber >= MAP_FACTOR_UNITS) {
			return(acai_carto_utils.decimalRound(myNumber/MAP_FACTOR_UNITS,2) + MAP_SUPRA_UNITS);
		} else {
			return(acai_carto_utils.decimalRound(myNumber,2) + MAP_UNITS);
		}
	}

	this.setNom(pNom);
	this.setPosition(pLeft,pTop,pWidth,pHeight);
}

acai_carto_infos.prototype = new acai_commons_genericCouche;

