/**
		-------------------------------------------------------
		Classe acai_carto_dynamicMapURL
		-------------------------------------------------------
		Description : 
*/
function acai_carto_dynamicMapURL(pNom, pURLs, pLeft, pTop, pWidth, pHeight, pInfos, pMapTitle) {
	var fNom = pNom;
	var fURLs = pURLs;
	var fLeft = pLeft;
	var fTop = pTop;
	var fWidth = pWidth;
	var fHeight = pHeight;
	var fXmin;
	var fXmax;
	var fYmin;
	var fYmax;
	var fBackXmin;
	var fBackXmax;
	var fBackYmin;
	var fBackYmax;
	var fInitXmin;
	var fInitXmax;
	var fInitYmin;
	var fInitYmax;
	var fProjection;
	var fMapTitle = pMapTitle || '';

	var fInfos = pInfos;
	
	this.setWidth = function(pWidth) {		fWidth = pWidth;		};
	this.setHeight = function(pHeight) {	fHeight = pHeight;	};
	this.setXmin = function(pXmin) {		fBackXmin = fXmin; fXmin = pXmin;		};
	this.setXmax = function(pXmax) {		fBackXmax = fXmax; fXmax = pXmax;		};
	this.setYmin = function(pYmin) {		fBackYmin = fYmin; fYmin = pYmin;		};
	this.setYmax = function(pYmax) {		fBackYmax = fYmax; fYmax = pYmax;		};
	this.setProjection = function(pProjection) {		fProjection = pProjection;		};
	this.setURLs = function(pURLs) {		fURLs = pURLs;		};

	this.getWidth = function() {			return fWidth;		};
	this.getHeight = function() {			return fHeight;		};
	this.getXmin = function() {			return fXmin;		};
	this.getXmax = function() {			return fXmax;		};
	this.getYmin = function() {			return fYmin;		};
	this.getYmax = function() {			return fYmax;		};
	this.getBackXmin = function() {			return fBackXmin;		};
	this.getBackXmax = function() {			return fBackXmax;		};
	this.getBackYmin = function() {			return fBackYmin;		};
	this.getBackYmax = function() {			return fBackYmax;		};
	this.getProjection = function() {			return fProjection;		};
	this.getInitXmin = function() {		return fInitXmin;		};
	this.getInitXmax = function() {		return fInitXmax;		};
	this.getInitYmin = function() {		return fInitYmin;		};
	this.getInitYmax = function() {		return fInitYmax;		};
	this.getMapTitle = function() {		return fMapTitle;		};

	this.setInitBounds = function(pInitXmin, pInitXmax, pInitYmin, pInitYmax) {
		fInitXmin = pInitXmin;
		fInitXmax = pInitXmax;
		fInitYmin = pInitYmin;
		fInitYmax = pInitYmax;
		fXmin = pInitXmin;
		fXmax = pInitXmax;
		fYmin = pInitYmin;
		fYmax = pInitYmax;
		fBackXmin = pInitXmin;
		fBackXmax = pInitXmax;
		fBackYmin = pInitYmin;
		fBackYmax = pInitYmax;
	};

	this.getSrc = function() {
		var contenuHTML = "";
		var pSrc;
		for (var i=1 ; i<fURLs.length ; i++) {
			if ( (fURLs[i].getVisible() == true) && ( (fXmax-fXmin) < fURLs[i].getMinScale() ) && ( (fXmax-fXmin) > fURLs[i].getMaxScale() ) ) {
					pSrc = this.getWMSLayerURL(fURLs[i]);
			} else {
					pSrc = VIEWER_LOCATION + BLANK_IMG;
			}
			calque = new acai_commons_image(pSrc, this.getMapTitle(), fWidth, fHeight, fNom + '_WMS' + i);
			calque.setOpacity(fURLs[i].getOpacity());
			contenuHTML += '<div style=\'position:absolute;overflow:hidden;left:0px;top:0px;'
				+ 'width:' + this.getWidth() + 'px;height:' + this.getHeight() + 'px\'>'
				+  calque.toHTML()
				+ "</div>";
		}
		return contenuHTML;
	};

	this.refresh = function() {
		var pSrc;
		for (var i=1 ; i<fURLs.length ; i++) {
			var fImageWMS = document.getElementById(fNom + '_WMS' + i);
			pSrc = VIEWER_LOCATION + BLANK_IMG;
			fImageWMS.src = pSrc;
			if ( (fURLs[i].getVisible() == true) && ( (fXmax-fXmin) < fURLs[i].getMinScale() ) && ( (fXmax-fXmin) > fURLs[i].getMaxScale() ) ) {
					pSrc = this.getWMSLayerURL(fURLs[i]);
			} else {
					pSrc = VIEWER_LOCATION + BLANK_IMG;
			}
			fImageWMS.src = pSrc;
		}
	};
	
	this.refreshLayer = function(pNumLayer) {
			fImageWMS = document.getElementById(fNom + '_WMS' + pNumLayer);
			fImageWMS.src = this.getWMSLayerURL(fURLs[pNumLayer]);
	};
	
	this.getWMSLayerURL = function(pLayer) {
			var wmsLayerURL = pLayer.getServeur() + "SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&SRS=" + fProjection;
			if (pLayer.getImageFormat() == "image/jpeg" || pLayer.getImageFormat() == "image/jpg") {
				wmsLayerURL += "&TRANSPARENT=FALSE&BGCOLOR=0xffffff";
			} else {
				wmsLayerURL += "&TRANSPARENT=TRUE&BGCOLOR=0xffffff";
			}
			wmsLayerURL += "&LAYERS=" + pLayer.getLayerName()
				+ "&STYLES=" + pLayer.getStyleName()
				+ "&FORMAT=" + pLayer.getImageFormat()
				+ "&WIDTH=" + fWidth
				+ "&HEIGHT=" + fHeight
				+ "&BBOX=" + fXmin + "," + fYmin + "," + fXmax + "," + fYmax;
			return wmsLayerURL;
	};
}

/**
		-------------------------------------------------------
		Classe acai_carto_layerURL
		-------------------------------------------------------
*/
function acai_carto_layerURL(pTitle, pServeur, pLayerName, pStyleName, pImageFormat, pVisible, pAllwaysVisible, pQueryable, pSheetable, pMinScale, pMaxScale, pOpacity) {
	var fTitle = pTitle;
	var fServeur = pServeur;
	var fLayerName = pLayerName;
	var fStyleName = pStyleName;
	var fImageFormat = pImageFormat;
	var fVisible = pVisible || pAllwaysVisible;
	var fAllwaysVisible = pAllwaysVisible;
	var fQueryable = pQueryable;
	var fSheetable = pSheetable;
	var fMinScale = pMinScale == "" ? 9999999 : pMinScale ;
	var fMaxScale = pMaxScale == "" ? 0 : pMaxScale ;
	var fOpacity = pOpacity || 100;
	var fLegendURL = pServeur + "SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&FORMAT=image/png&layer=" + pLayerName;
	var fInfoCard = true;
	var fDataSheet = false;

	this.getTitle = function() {			return fTitle;};
	this.getServeur = function() {		return fServeur;};
	this.getLayerName = function() {	return fLayerName;};
	this.getStyleName = function() {	return fStyleName;};
	this.getImageFormat = function() {return fImageFormat;};
	this.getVisible = function() {		return fVisible;};
	this.getAllwaysVisible = function() {		return fAllwaysVisible;};
	this.getQueryable = function() {	return fQueryable;};
	this.getSheetable = function() {	return fSheetable;};
	this.getMinScale = function() {		return fMinScale;};
	this.getMaxScale = function() {		return fMaxScale;};
	this.getOpacity = function() {	return fOpacity;};
	this.getLegendURL = function() {	return fLegendURL;};
	this.getInfoCard = function() {		return fInfoCard;};
	this.getDataSheet = function() {	return fDataSheet;};
	
	this.setVisible = function(pVisible) {			fVisible = pVisible;};
	this.setAllwaysVisible = function(pAllwaysVisible) {			fAllwaysVisible = pAllwaysVisible;};
	this.setOpacity = function(pOpacity) {	fOpacity = pOpacity;	};
//	this.setLegendURL = function(pLegendURL) {	fLegendURL = pLegendURL;	};	
	this.setLegendURL = function(pLegendURL) {
		var legend = "";
		var legendUrlList = pLegendURL.split(',');
		var layerNameList = pLayerName.split(',');
		for (var item = 0 ; item<legendUrlList.length ; item++) {
			if (item != 0) {
				legend += ",";
			}
			if (legendUrlList[item] == "AUTO") {
				legend += pServeur + "SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&FORMAT=image/png&layer=" + layerNameList[item];
			} else {
				legend += legendUrlList[item];
			}
		}
		fLegendURL = legend;
	};
	this.setInfoCard = function(pInfoCard) {		fInfoCard = pInfoCard;};
	this.setDataSheet = function(pDataSheet) {	fDataSheet = pDataSheet;};
}


