
var aCom = new Array(1);
var aReg = new Array(1);
var aDept = new Array(1);
var nbCom = 0;

// *******************************************************************
// Parametrage des services
// *******************************************************************
var FEATUREINFO_SERVER = "";
var FEATURE_SERVER = "";
var EXPORT_PDF_SERVER = "";
var EXPORT_PNG_SERVER = "";
var VUE_LEGEND = 1;
var VUE_LAYERS = 2;
var VUE_GAZEETTER = 3;


/**
		-------------------------------------------------------
		Classe acai_carto_viewer
		-------------------------------------------------------
		Description : Objet "conteneur" englobant les zones :
		- carte
		- barre d'outils
		- informations
		- legende
		- gazeetter de localisation administrative
*/
function acai_carto_viewerWMS(pId,pLeft,pTop,pWidth,pHeight,pMapTitle,pMapAtRight,pEditTools) {
	var fId = pId;
	var isShown = 0;
	var fBorderStyle = "solid";
	var fBorderColor = document.body.text;
	var fBorderWidth = 2;
	var fLeft = pLeft;
	var fTop = pTop;
	var fWidth = pWidth;
	var fHeight = pHeight;
	var fMapTitle = pMapTitle || '';
	var fMapAtRight = false || (pMapAtRight ? true : false);
	var fEditTools = false || (pEditTools ? true : false);

	var fMapURLs = new Array(1);
	var fNbMaps = 0;
//	var fMapWidth;
//	var fMapHeight;
	var fMapInitXmin = -1;
	var fMapInitXmax = -1;
	var fMapInitYmin = -1;
	var fMapInitYmax = -1;
	var fMapLimitXmin = -1;
	var fMapLimitXmax = -1;
	var fMapLimitYmin = -1;
	var fMapLimitYmax = -1;
	var fMapAreaXmin = -1;
	var fMapAreaXmax = -1;
	var fMapAreaYmin = -1;
	var fMapAreaYmax = -1;
	var fMiniMapHeight = -1;
	var fAreaBoundsOK = false;
	var fLimitBoundsOK = false;
	var fInitBoundsOK = false;
	var fBoundsOK = false;
	var fProjectionOK = false;
	var fZoomMax = -1;
	var fInitialView = VUE_LEGEND;

	// elements-zones composant le viewer
	var fDynamicMap;
	var fToolBar;
	var fLegend;
	var fGazeetter;
	var fInfos;
	var fLayerControl;
	var fMiniMap;
	var fControlPanel;
	
	// marqueurs des fonctionnalites optionnelles
	var fPackInfos = false;
	var fPackDatas = false;
	var fPackPrint = false;
	var fPackExplore = false;
	var fPackGazetter = false;
	
	// positions et dimensions des zones
	var pToolBarLeft;
	var	pToolBarTop;
	var	pToolBarWidth;
	var	pToolBarHeight;
	var	pInfosLeft;
	var	pInfosTop;
	var	pInfosWidth;
	var	pInfosHeight;
	var	pMinimapLeft;
	var	pMinimapTop;
	var	pMinimapWidth;
	var pMinimapHeight;
	var pControlsLeft;
	var pControlsTop;
	var pControlsWidth;
	var pControlsHeight;
	var	pTabPanelLeft;
	var	pTabPanelTop;
	var	pTabPanelWidth;
	var pTabPanelHeight;

	// accesseurs des elements-zones composant le viewer
	this.getDynamicMap = function() {	return fDynamicMap; 	};
	this.getToolBar = function() {		return fToolBar;		};
	this.getLegend = function() {		return fLegend;			};
	this.getGazeetter = function() {	return fGazeetter;		};
	this.getInfos = function() {		return fInfos;			};
	this.getLayerControl = function() {	return fLayerControl;	};
	this.getMiniMap = function() {		return fMiniMap;		};
	this.getControlPanel = function() {	return fControlPanel;	};

	// mutateurs pour les informations complémentaires (pour impression)
	this.setAuteur = function(pAuteur) {				fDynamicMap.setAuteur(pAuteur);					};
	this.setDateValidite = function(pDateValidite) {	fDynamicMap.setDateValidite(pDateValidite);		};
	this.setDescription = function(pDescription) {		fDynamicMap.setDescription(pDescription);		};
	this.setCopyright = function(pCopyright) {			fDynamicMap.setCopyright(pCopyright);			};
	this.setAppInfos = function(pAppInfos) {			fDynamicMap.setAppInfos(pAppInfos);				};
	this.setCreator = function(pCreator) {				fDynamicMap.setCreator(pCreator);				};
	this.addPrintLogoFile = function(pPrintLogoFile) {	fDynamicMap.addPrintLogoFile(pPrintLogoFile);	};
	this.addPrintLogoURL = function(pPrintLogoURL) {	fDynamicMap.addPrintLogoURL(pPrintLogoURL);		};
	
	// mutateurs pour les parametres "fonctionnels" du viewer
	this.setMinimalGeoWidth = function(pZoomMax) {
		fZoomMax = pZoomMax;
	};
	
	this.setInitialView = function(pZone) {
		fInitialView = pZone || VUE_LEGEND;
	};
	
	this.setGazeetterInitialLevel = function(pInitLevel,pInitValue) {
		fGazeetter.setInitialLevel(pInitLevel,pInitValue);
	};

	this.setMapProjection = function(pMapProjection) {
		fDynamicMap.setProjection(pMapProjection);
		fInfos.setProjection(pMapProjection);
		fProjectionOK = true;
		aProjection = pMapProjection.split(':');
		fGazeetter.setProjection(aProjection[1]);
		
	};

	this.setConfig = function(pQueryable, pAllQueryable, pPrintable, pGazetter) {
		fPackInfos = pQueryable;
		fPackDatas = pAllQueryable;
		fPackPrint = pPrintable;
		fPackGazetter = pGazetter;
		fPackExplore = false;
		setToolBar();
	};
	
	this.setServices = function(pFeatureInfoService, pFeatureService, pExportPdfService, pExportPngService) {
		FEATUREINFO_SERVER = pFeatureInfoService;
		FEATURE_SERVER = pFeatureService;
		EXPORT_PDF_SERVER = pExportPdfService;
		EXPORT_PNG_SERVER = pExportPngService;
	};
	
	this.setInsertService = function(pInsertService,pFeatureFieldName,pGeometryTypeFieldName,pGeometryFieldName,pSrsFieldName) {
		fDynamicMap.setInsertService(pInsertService,pFeatureFieldName,pGeometryTypeFieldName,pGeometryFieldName,pSrsFieldName);
	};
	
/*
	this.setMapSizes = function(pMapWidth, pMapHeight) {
		fMapWidth = pMapWidth;
		fMapHeight = pMapHeight;
	};
*/

	// accesseurs pour les parametres "fonctionnels" du viewer
	this.getZoomMax = function() {
		return fZoomMax;
	};
	
	this.getConfig = function(pConfigOption) {
		var pConfig = false;
		if (pConfigOption == "INFOS" && fPackInfos) {		pConfig = true;	}
		if (pConfigOption == "DATAS" && fPackDatas) {		pConfig = true;	}
		if (pConfigOption == "PRINT" && fPackPrint) {		pConfig = true;	}
		if (pConfigOption == "EXPLORE" && fPackExplore) {	pConfig = true;	}
		return pConfig;
	};
	
	// mutateurs pour les parametres "ergonomiques" du viewer
	this.setAllForeColor = function(pColor) {
		this.setBorderColor(pColor);
		this.setAllTextColor(pColor);
	};
	
	this.setBorderStyle = function(pStyle) {
		fBorderStyle = pStyle;
		if (isShown === 1) {
			displayBorders();
		}
	};

	this.setBorderColor = function(pColor) {
		fBorderColor = pColor;
		if (isShown === 1) {
			displayBorders();
		}
	};

	this.setBorderWidth = function(pWidth) {
		fBorderWidth = pWidth;
		setNewSizes();
		if (isShown === 1) {
			displayBorders();
		}
	};

	this.setAllTextColor = function(pColor) {
		this.setLayerControlTextColor(pColor);
		this.setInfosTextColor(pColor);
		this.setControlPanelTextColor(pColor);
		this.setToolBarHightlightColor(pColor);
		this.setGazeetterTextColor(pColor);
	};
	
	this.setLayerControlTextColor = function(pColor) {
		fLayerControl.setColor(pColor);
		fLayerControl.refresh();
	};
	
	this.setInfosTextColor = function(pColor) {
		fInfos.setColor(pColor);
		fInfos.refresh();
	};
	
	this.setControlPanelTextColor = function(pColor) {
		fControlPanel.setColor(pColor);
		fControlPanel.show();
	};
	
	this.setToolBarHightlightColor = function(pColor) {
		fToolBar.setColor(pColor);
		fToolBar.show();
	};
	
	this.setGazeetterTextColor = function(pColor) {
		fGazeetter.setColor(pColor);
		fGazeetter.configure();
	};
	
	this.setAllBackgroundColor = function(pColor) {
		this.setInfosBackgroundColor(pColor);
		this.setControlPanelBackgroundColor(pColor);
		this.setToolBarBackgroundColor(pColor);
		this.setLayerControlBackgroundColor(pColor);
		this.setGazeetterBackgroundColor(pColor);
		this.setMapBackgroundColor(pColor);
	};
	
	this.setInfosBackgroundColor = function(pColor) {
		fInfos.setBgColor(pColor);
		fInfos.refresh();
	};
	
	this.setControlPanelBackgroundColor = function(pColor) {
		fControlPanel.setBgColor(pColor);
		fControlPanel.show();
	};
	
	this.setToolBarBackgroundColor = function(pColor) {
		fToolBar.setBgColor(pColor);
		fToolBar.show();
	};

	this.setLayerControlBackgroundColor = function(pColor) {
		fLayerControl.setBgColor(pColor);
		fLayerControl.refresh();
	};
	
	this.setGazeetterBackgroundColor = function(pColor) {
		fGazeetter.setBgColor(pColor);
	};
	
	this.setMapBackgroundColor = function(pColor) {
		fDynamicMap.setBgColor(pColor);
	};

	// methodes pour la gestion des couches
	this.addMapURL = function(pTitle, pServeur, pLayerName, pStyleName, pImageFormat, pVisible, pAllwaysVisible, pQueryable, pSheetable, pMinScale, pMaxScale, pLegend,pOpacity) {
		var pMapLegend;
		fNbMaps++;
		pMapLegend = pLegend || 'NONE';
		fMapURLs[fNbMaps] = new acai_carto_layerURL(pTitle, pServeur, pLayerName, pStyleName, pImageFormat, pVisible, pAllwaysVisible, pQueryable, pSheetable, pMinScale, pMaxScale,pOpacity);
		if (pMapLegend !='AUTO') {
			fMapURLs[fNbMaps].setLegendURL(pMapLegend);
		}
		fDynamicMap.setURLs(fMapURLs);
	};

	this.getLayerByNum = function(pNum) {
			return fMapURLs[pNum];
	};
	
/*
	this.getLayer = function(pServeur,pLayerName,pStyleName) {
		for (i=0 ; i<fMapURLs.length ; i++) {
				if ( (fMapURLs[i].getServeur() == pServeur) && (fMapURLs[i].getLayerName() == pLayerName) && (fMapURLs[i].getStyleName() == pStyleName) ) {
						return fMapURLs[i];
				} else {
						return null;
				}
		}
	};
*/

	this.showLayerByNum = function(pNum) {
		if ( ( (fDynamicMap.getMapImage().getXmax()-fDynamicMap.getMapImage().getXmin()) < fMapURLs[pNum].getMinScale() )
			&& ( (fDynamicMap.getMapImage().getXmax()-fDynamicMap.getMapImage().getXmin()) > fMapURLs[pNum].getMaxScale() ) ) {
				fMapURLs[pNum].setVisible(true);
				fDynamicMap.getMapImage().refreshLayer(pNum);
				fLayerControl.refresh();
				fLegend.setDeprecated(true);
				document.getElementById("theMap"+"_WMS"+pNum).style.display='';
		}
	};
	
	this.hideLayerByNum = function(pNum) {
		fMapURLs[pNum].setVisible(false);
		fLayerControl.refresh();
		fLegend.setDeprecated(true);
		document.getElementById("theMap"+"_WMS"+pNum).style.display='none';
	};
	
	this.alterLayerOpacity = function(pNum, pDecalage) {
		op = parseFloat(document.getElementById("theMap"+"_WMS"+pNum).style.opacity);
		if (op == null) {
			op=1;
		}
		if (op == 1 && pDecalage == 1) {
		} else {
			if (op== 0.1 && pDecalage == -1) {
			} else {
				if (pDecalage == 1 || pDecalage == -1) {
					newOp = op + pDecalage/10;
					newFilter = parseInt(100*newOp);
					document.getElementById("theMap"+"_WMS"+pNum).style.opacity = newOp;
					if (navigator.userAgent.indexOf("MSIE") != -1) {
						document.getElementById("theMap"+"_WMS"+pNum).style.filter = "alpha(opacity=" + newFilter + ")";
					}
				}
			}
		}
	};
	
	// methodes pour la gestion des etendues geographiques de la carte
	this.setMiniMap = function(pImageURL, pImageWidth, pImageHeight, pMapAreaXmin, pMapAreaXmax, pMapAreaYmin, pMapAreaYmax) {
		var pNewImageHeight;
		var pNewImageWidth;
		if (fLimitBoundsOK || fInitBoundsOK) {
			throwGlobalException(SET_MINIMAP_EXCEPTION);
		} else {
			storeMiniMapBounds(pMapAreaXmin, pMapAreaXmax, pMapAreaYmin, pMapAreaYmax);
			fAreaBoundsOK = true;
			storeMapLimitBounds(pMapAreaXmin,pMapAreaXmax,pMapAreaYmin,pMapAreaYmax);
			storeMapInitBounds(fMapAreaXmin,fMapAreaXmax,fMapAreaYmin,fMapAreaYmax);
			fDynamicMap.setMiniMapBounds(fMapAreaXmin, fMapAreaXmax, fMapAreaYmin, fMapAreaYmax);
			fMiniMap.setURL(pImageURL);
			// ajustement des dimensions de l'image aux dimensions de la zone minimap
			if ( (pImageWidth/pImageHeight) / (fMiniMap.getWidth()/fMiniMap.getHeight()) < 1 ) {
				pNewImageHeight = fMiniMap.getHeight();
				pNewImageWidth =  pImageWidth/pImageHeight * pNewImageHeight;
			} else {
				pNewImageWidth = fMiniMap.getHeight();
				pNewImageHeight =  pImageHeight/pImageWidth * pNewImageWidth;
			}
			pNewImageWidth = MINIMAP_WIDTH;
			pNewImageHeight = MINIMAP_WIDTH * this.getDynamicMap().getHeight() / this.getDynamicMap().getWidth();
			fMiniMap.setImageDimensions(pNewImageWidth,pNewImageHeight);
			fMiniMapHeight = pNewImageHeight;
			setNewSizes();
		}
	};

	this.setMapLimitBounds = function(pMapLimitXmin, pMapLimitXmax, pMapLimitYmin, pMapLimitYmax) {
		if (fInitBoundsOK) {
			throwGlobalException(SET_LIMIT_BOUNDS_EXCEPTION);
		} else {
			storeMapLimitBounds(pMapLimitXmin,pMapLimitXmax,pMapLimitYmin,pMapLimitYmax);
			fLimitBoundsOK = true;
			storeMapInitBounds(fMapLimitXmin,fMapLimitXmax,fMapLimitYmin,fMapLimitYmax);
		}
	};
	
	this.setMapInitBounds = function(pMapInitXmin, pMapInitXmax, pMapInitYmin, pMapInitYmax) {
		storeMapInitBounds(pMapInitXmin, pMapInitXmax, pMapInitYmin, pMapInitYmax);
		fInitBoundsOK = true;
	};

	function storeMiniMapBounds(pMapAreaXmin, pMapAreaXmax, pMapAreaYmin, pMapAreaYmax) {
		// adaptation du rectangle de la minimap au rectangle de la carte (memes proportions...)
		var aNewBounds = acai_carto_utils.adaptRectangleToMap(fWidth, fHeight, pMapAreaXmin, pMapAreaXmax, pMapAreaYmin, pMapAreaYmax);
		fMapAreaXmin = aNewBounds[0] - MINIMAP_BOUNDS_TOLERANCE * (aNewBounds[1] - aNewBounds[0]);
		fMapAreaXmax = aNewBounds[1] + MINIMAP_BOUNDS_TOLERANCE * (aNewBounds[1] - aNewBounds[0]);
		fMapAreaYmin = aNewBounds[2] - MINIMAP_BOUNDS_TOLERANCE * (aNewBounds[3] - aNewBounds[2]);
		fMapAreaYmax = aNewBounds[3] + MINIMAP_BOUNDS_TOLERANCE * (aNewBounds[3] - aNewBounds[2]);
		fBoundsOK = true;
	}
	
	function storeMapLimitBounds(pMapLimitXmin,pMapLimitXmax,pMapLimitYmin,pMapLimitYmax) {
		// restriction a l'inclusion dans les bounds de la minimap
		if (fAreaBoundsOK) {
			pMapLimitXmin = (pMapLimitXmin < fMapAreaXmin) ? fMapAreaXmin : pMapLimitXmin;
			pMapLimitXmax = (pMapLimitXmax > fMapAreaXmax) ? fMapAreaXmax : pMapLimitXmax;
			pMapLimitYmin = (pMapLimitYmin < fMapAreaYmin) ? fMapAreaYmin : pMapLimitYmin;
			pMapLimitYmax = (pMapLimitYmax > fMapAreaYmax) ? fMapAreaYmax : pMapLimitYmax;
			if ( (fMapLimitXmin >fMapLimitXmax) || (fMapLimitYmin > fMapLimitYmax) ) {
				pMapLimitXmin = fMapAreaXmin;
				pMapLimitXmax = fMapAreaXmax;
				pMapLimitYmin = fMapAreaYmin;
				pMapLimitYmax = fMapAreaYmax;
			}
		}
		var aNewBounds = acai_carto_utils.adaptRectangleToMap(fWidth, fHeight, pMapLimitXmin, pMapLimitXmax, pMapLimitYmin, pMapLimitYmax);
		fMapLimitXmin = aNewBounds[0];
		fMapLimitXmax = aNewBounds[1];
		fMapLimitYmin = aNewBounds[2];
		fMapLimitYmax = aNewBounds[3];
		fDynamicMap.setMapLimitBounds(fMapLimitXmin, fMapLimitXmax, fMapLimitYmin, fMapLimitYmax);
		fBoundsOK = true;
	}
	
	function storeMapInitBounds(pMapInitXmin, pMapInitXmax, pMapInitYmin, pMapInitYmax) {
		// restriction a l'inclusion dans les bounds de l'etendue maximale
		var aNewBounds;
		if (fAreaBoundsOK) {
			pMapInitXmin = (pMapInitXmin < fMapAreaXmin) ? fMapAreaXmin : pMapInitXmin;
			pMapInitXmax = (pMapInitXmax > fMapAreaXmax) ? fMapAreaXmax : pMapInitXmax;
			pMapInitYmin = (pMapInitYmin < fMapAreaYmin) ? fMapAreaYmin : pMapInitYmin;
			pMapInitYmax = (pMapInitYmax > fMapAreaYmax) ? fMapAreaYmax : pMapInitYmax;
			if ( (pMapInitXmin >pMapInitXmax) || (pMapInitYmin > pMapInitYmax) ) {
				fMapInitXmin = fMapAreaXmin;
				fMapInitXmax = fMapAreaXmax;
				fMapInitYmin = fMapAreaYmin;
				fMapInitYmax = fMapAreaYmax;
			} else {
				aNewBounds = acai_carto_utils.adaptRectangleToMap(fWidth, fHeight, pMapInitXmin, pMapInitXmax, pMapInitYmin, pMapInitYmax);
				fMapInitXmin = aNewBounds[0];
				fMapInitXmax = aNewBounds[1];
				fMapInitYmin = aNewBounds[2];
				fMapInitYmax = aNewBounds[3];
			}
		}
		if (fLimitBoundsOK) {
			pMapInitXmin = (pMapInitXmin < fMapLimitXmin) ? fMapLimitXmin : pMapInitXmin;
			pMapInitXmax = (pMapInitXmax > fMapLimitXmax) ? fMapLimitXmax : pMapInitXmax;
			pMapInitYmin = (pMapInitYmin < fMapLimitYmin) ? fMapLimitYmin : pMapInitYmin;
			pMapInitYmax = (pMapInitYmax > fMapLimitYmax) ? fMapLimitYmax : pMapInitYmax;
			if ( (pMapInitXmin >pMapInitXmax) || (pMapInitYmin > pMapInitYmax) ) {
				fMapInitXmin = fMapLimitXmin;
				fMapInitXmax = fMapLimitXmax;
				fMapInitYmin = fMapLimitYmin;
				fMapInitYmax = fMapLimitYmax;
			} else {
				aNewBounds = acai_carto_utils.adaptRectangleToMap(fWidth, fHeight, pMapInitXmin, pMapInitXmax, pMapInitYmin, pMapInitYmax);
				fMapInitXmin = aNewBounds[0];
				fMapInitXmax = aNewBounds[1];
				fMapInitYmin = aNewBounds[2];
				fMapInitYmax = aNewBounds[3];
			}
		}
		if (!fAreaBoundsOK && !fLimitBoundsOK) {
			aNewBounds = acai_carto_utils.adaptRectangleToMap(fWidth, fHeight, pMapInitXmin, pMapInitXmax, pMapInitYmin, pMapInitYmax);
			fMapInitXmin = aNewBounds[0];
			fMapInitXmax = aNewBounds[1];
			fMapInitYmin = aNewBounds[2];
			fMapInitYmax = aNewBounds[3];
		}
		fDynamicMap.getMapImage().setInitBounds(fMapInitXmin, fMapInitXmax, fMapInitYmin, fMapInitYmax);
		fInfos.init(fWidth, fHeight, fMapInitXmin, fMapInitXmax, fMapInitYmin, fMapInitYmax);
		fBoundsOK = true;
	}

	// methodes pour le basculement des onglets
	this.showLegend = function() {
		fLegend.setVisible(true);
		if (fLegend.getDeprecated() == true) {
			fLegend.show();
			fLegend.setDeprecated(false);
		}
		fLayerControl.setVisible(false);
		fGazeetter.setVisible(false);
	};
	
	this.showLayerControl = function() {
		fLegend.setVisible(false);
		fLayerControl.setVisible(true);
		fGazeetter.setVisible(false);
	};
	
	this.showGazeetter = function() {
		if (fPackGazetter == true && fGazeetter.isPopulated()) {
			fLegend.setVisible(false);
			fLayerControl.setVisible(false);
			fGazeetter.setVisible(true);
		}
	};

//Ajouté par BM 29 08 2007

    this.showGazeetterCartorisque = function() {
		if (fPackGazetter == true && fGazeetter.isPopulated()) {
			fLegend.setVisible(false);
			fLayerControl.setVisible(false);
			fGazeetter.setVisible(true);
            fControlPanel.activeTab(VUE_GAZEETTER);
            }
	};
    
	// initialisation du composant
	this.init = function() {
		if (fMapAtRight) {
			fLeft += CONTROLS_WIDTH;
		}
		setDefaultSizes();
		// Creation de la zone controle des couches
		fLayerControl = new acai_carto_layerControl("fLayerControl", fMapURLs, fId, pControlsLeft,pControlsTop,pControlsWidth,pControlsHeight);
		// Creation de la zone legende
		fLegend = new acai_carto_legend("theLegend",fMapURLs, pControlsLeft,pControlsTop,pControlsWidth,pControlsHeight,fId+".getDynamicMap()");
		// Creation de la zone localisation administrative
		fGazeetter = new acai_carto_gazeetter("fGazeetter", pControlsLeft,pControlsTop,pControlsWidth,pControlsHeight);
		// Creation de la zone informations
		fInfos = new acai_carto_infos("theInfos",pInfosLeft, pInfosTop, pInfosWidth, pInfosHeight);
		// Creation de la zone minimap
		fMiniMap = new acai_carto_miniMap("fMiniMap",pMinimapLeft,pMinimapTop,pMinimapWidth,pMinimapHeight,fId+".getDynamicMap()", fId);
		// Creation de la zone carte
		fDynamicMap = new acai_carto_dynamicMap("theMap", fMapURLs, fLeft, fTop, fWidth, fHeight, fId, fMapTitle);
		// Creation du panneau de controle
		fControlPanel = new acai_commons_tabPanel(fId+".getControlPanel()","theControlPanel",pTabPanelLeft,pTabPanelTop,pTabPanelWidth,pTabPanelHeight);
	};

	// activation du composant
	this.show = function() {
		if (fNbMaps == 0) {
			throwGlobalException(NO_LAYER_EXCEPTION);
		}
		if (!fBoundsOK) {
			throwGlobalException(NO_BOUNDS_EXCEPTION);
		}
		if (!fProjectionOK) {
			throwGlobalException(NO_PROJECTION_EXCEPTION);
		}
		if (fNbMaps != 0 && fBoundsOK && fProjectionOK) {
			fControlPanel.addTab(TAB_TEXT_LEGEND,TOOL_LABEL_LEGEND,fId+".showLegend();");
			fControlPanel.addTab(TAB_TEXT_LAYER_CONTROL,TOOL_LABEL_LAYER_CONTROL,fId+".showLayerControl();");
			if (fPackGazetter == true) {
				fControlPanel.addTab(TAB_TEXT_GAZEETTER,TOOL_LABEL_GAZEETTER,fId+".showGazeetter();");
				fGazeetter.init(fId+'.getGazeetter()', fId+'.getDynamicMap()');
				fGazeetter.setInitialLevel(GAZEETTER_LEVEL_ALL,'');
				fPackGazetter = fGazeetter.isPopulated();
			} else {
				if (fInitialView == VUE_GAZEETTER) {
					fInitialView = VUE_LEGEND;
				}
			}
			// Creation de la zone barre d'outils
			setToolBar();
			fToolBar.show();
			fLegend.show();
			fLayerControl.refresh();
			fInfos.show();
			fControlPanel.show();
			if (fPackGazetter == true) {
				fGazeetter.show();
			}
			fMiniMap.init();
			if (fAreaBoundsOK) {
					fMiniMap.show();
			} else {
					fMiniMap.setVisible(false);
			}
			fDynamicMap.init();
			fDynamicMap.desactiveTools();
			fDynamicMap.restoreBounds();
			isShown = 1;
			displayBorders();
			fLegend.setVisible(false);
			fControlPanel.setVisible(true);
			fControlPanel.activeTab(fInitialView);
		}
	};

	// fonctions internes de gestion des elements (positionnement, couleurs, bordures...)
	function setDefaultSizes() {
		if (fEditTools) {
			pToolBarLeft = fLeft;
			pToolBarTop = fTop - 2*PICTOS_HEIGHT - 2*fBorderWidth;
			pToolBarWidth = fWidth;
			pToolBarHeight = 2*PICTOS_HEIGHT + fBorderWidth;
	
			pInfosLeft = fLeft;
			pInfosTop = fTop + fHeight + fBorderWidth;
			pInfosWidth = fWidth;
			pInfosHeight = INFOS_HEIGHT;
	
			pMinimapLeft = fLeft + fWidth - MINIMAP_WIDTH;
			pMinimapTop = fTop;
			pMinimapWidth = MINIMAP_WIDTH;
			if (fMiniMapHeight == -1) {
				pMinimapHeight = Math.floor(fHeight/fWidth*MINIMAP_WIDTH) ;
			} else {
				pMinimapHeight = fMiniMapHeight;
			}
	
			pTabPanelLeft = fLeft + fWidth + fBorderWidth;
			pTabPanelTop = fTop - 2*PICTOS_HEIGHT - 2*fBorderWidth;
			pTabPanelWidth = CONTROLS_WIDTH;
			pTabPanelHeight = PICTOS_HEIGHT;
			
			pControlsLeft = fLeft + fWidth + fBorderWidth;
			pControlsWidth = CONTROLS_WIDTH;
			pControlsTop = fTop - PICTOS_HEIGHT - fBorderWidth;
			pControlsHeight = fHeight + pInfosHeight + 2*fBorderWidth + PICTOS_HEIGHT;
			
			if (fMapAtRight) {
				pControlsLeft = fLeft - CONTROLS_WIDTH;
				pTabPanelLeft = fLeft - CONTROLS_WIDTH;
			}
		} else {
			pToolBarLeft = fLeft;
			pToolBarTop = fTop - PICTOS_HEIGHT - fBorderWidth;
			pToolBarWidth = fWidth;
			pToolBarHeight = PICTOS_HEIGHT;
	
			pInfosLeft = fLeft;
			pInfosTop = fTop + fHeight + fBorderWidth;
			pInfosWidth = fWidth;
			pInfosHeight = INFOS_HEIGHT;
	
			pMinimapLeft = fLeft + fWidth - MINIMAP_WIDTH;
			pMinimapTop = fTop;
			pMinimapWidth = MINIMAP_WIDTH;
			if (fMiniMapHeight == -1) {
				pMinimapHeight = Math.floor(fHeight/fWidth*MINIMAP_WIDTH) ;
			} else {
				pMinimapHeight = fMiniMapHeight;
			}
	
			pTabPanelLeft = fLeft + fWidth + fBorderWidth;
			pTabPanelTop = fTop - PICTOS_HEIGHT - fBorderWidth;
			pTabPanelWidth = CONTROLS_WIDTH;
			pTabPanelHeight = PICTOS_HEIGHT;
			
			pControlsLeft = fLeft + fWidth + fBorderWidth;
			pControlsWidth = CONTROLS_WIDTH;
			pControlsTop = fTop;
			pControlsHeight = fHeight + pInfosHeight + fBorderWidth;
			
			if (fMapAtRight) {
				pControlsLeft = fLeft - CONTROLS_WIDTH;
				pTabPanelLeft = fLeft - CONTROLS_WIDTH;
			}
		}
	}
	
	function setToolBar() {
		fToolBar = new acai_commons_toolBar(fId+".getToolBar()","theToolBar",pToolBarLeft,pToolBarTop,pToolBarWidth,pToolBarHeight);
		fToolBar.addPicto(VIEWER_LOCATION + PICTO_ZOOM_PLUS,TOOL_LABEL_ZOOM_PLUS,fId+".getDynamicMap().activeZoomIn();");
		fToolBar.addPicto(VIEWER_LOCATION + PICTO_ZOOM_PLUS_RECT,TOOL_LABEL_ZOOM_PLUS_RECT,fId+".getDynamicMap().activeZoomInRect();");
		fToolBar.addPicto(VIEWER_LOCATION + PICTO_ZOOM_MINUS,TOOL_LABEL_ZOOM_MINUS,fId+".getDynamicMap().activeZoomOut();");
		fToolBar.addPicto(VIEWER_LOCATION + PICTO_ZOOM_BACK,TOOL_LABEL_ZOOM_BACK,fId+".getDynamicMap().cancelBounds();");
		
		//fToolBar.addPicto(VIEWER_LOCATION + PICTO_ZOOM_MINUS_RECT,TOOL_LABEL_ZOOM_MINUS_RECT,fId+".getDynamicMap().activeZoomOutRect();");
		//fToolBar.addPicto(VIEWER_LOCATION + PICTO_RECENTER,TOOL_LABEL_RECENTER,fId+".getDynamicMap().activeRecenter();");
		fToolBar.addPicto(VIEWER_LOCATION + PICTO_PAN,TOOL_LABEL_PAN,fId+".getDynamicMap().activePan();");
		fToolBar.addPicto(VIEWER_LOCATION + PICTO_EXTEND,TOOL_LABEL_EXTEND,fId+".getDynamicMap().restoreBounds();");
		//fToolBar.addPicto(VIEWER_LOCATION + PICTO_DISTANCE,TOOL_LABEL_DISTANCE,fId+".getDynamicMap().activeDistance();");
		if (fPackInfos == true) {
				fToolBar.addPicto(VIEWER_LOCATION + PICTO_INFO_CARD,TOOL_LABEL_INFO_CARD,fId+".getDynamicMap().activeMapQuery();");
		}
		if (fPackDatas == true) {
				fToolBar.addPicto(VIEWER_LOCATION + PICTO_DATA_SHEET,TOOL_LABEL_DATA_SHEET,fId+".getDynamicMap().executeDataSheet(" + fId + ");");
		}
		if (fPackExplore == true) {
				/* Desactive en version 1.2
				fToolBar.addPicto(VIEWER_LOCATION + PICTO_EXPLORE,TOOL_LABEL_EXPLORE,fId+".getDynamicMap().restoreBounds();");
				*/
		}
		if (fPackPrint == true) {
//				fToolBar.addPicto(VIEWER_LOCATION + PICTO_PRINT,TOOL_LABEL_PRINT,fId+".getDynamicMap().printMap();");
				fToolBar.addPicto(VIEWER_LOCATION + PICTO_PDF,TOOL_LABEL_PDF,fId+".getDynamicMap().exportPDF();");
				fToolBar.addPicto(VIEWER_LOCATION + PICTO_PNG,TOOL_LABEL_PNG,fId+".getDynamicMap().exportPNG();");
		}
		fToolBar.addPicto(VIEWER_LOCATION + PICTO_HELP,TOOL_LABEL_HELP,fId+".showHelp();");
// ajouté par BM le 29 08 2007
		fToolBar.addPicto(VIEWER_LOCATION + PICTO_ESPACEMENT);
		if (fPackGazetter == true) {
		                fToolBar.addPicto(VIEWER_LOCATION + PICTO_GAZEETTER,TOOL_LABEL_GAZEETTER,fId+".showGazeetterCartorisque();");
				 }
								
		
		if (fEditTools) {
			fToolBar.addSeparator();
			fToolBar.addPicto(VIEWER_LOCATION + PICTO_POINT,"",fId+".getDynamicMap().activeCreatePoint();");
			fToolBar.addPicto(VIEWER_LOCATION + PICTO_POLYLIGNE,"",fId+".getDynamicMap().activeCreatePolyline();");
			fToolBar.addPicto(VIEWER_LOCATION + PICTO_POLYGONE,"",fId+".getDynamicMap().activeCreatePolygon();");
			fToolBar.addPicto(VIEWER_LOCATION + PICTO_POLYGONE_TROU,"",fId+".getDynamicMap().activeCreatePolygonWithHole();");
			fToolBar.addPicto(VIEWER_LOCATION + PICTO_XY,"",fId+".getDynamicMap().activeCreateXY();");
			fToolBar.addPicto(VIEWER_LOCATION + PICTO_UNDO,"",fId+".getDynamicMap().validGeometry();");
			fToolBar.addPicto(VIEWER_LOCATION + PICTO_VALIDE_SAISIE,"",fId+".getDynamicMap().validGeometry();");
		}
	}

	function displayBorders() {
		fToolBar.setBorderStyle(fBorderStyle);
		fToolBar.setBorderColor(fBorderColor);
		fToolBar.setBorderWidth(fBorderWidth);
		fDynamicMap.setBorderStyle(fBorderStyle);
		fDynamicMap.setBorderColor(fBorderColor);
		fDynamicMap.setBorderWidth(fBorderWidth);
		fLegend.setBorderStyle(fBorderStyle);
		fLegend.setBorderColor(fBorderColor);
		fLegend.setBorderWidth(fBorderWidth);
		fLayerControl.setBorderStyle(fBorderStyle);
		fLayerControl.setBorderColor(fBorderColor);
		fLayerControl.setBorderWidth(fBorderWidth);
		fGazeetter.setBorderStyle(fBorderStyle);
		fGazeetter.setBorderColor(fBorderColor);
		fGazeetter.setBorderWidth(fBorderWidth);
		fInfos.setBorderStyle(fBorderStyle);
		fInfos.setBorderColor(fBorderColor);
		fInfos.setBorderWidth(fBorderWidth);
		fInfos.setScaleColor(fBorderColor);
		fMiniMap.setBorderStyle(fBorderStyle);
		fMiniMap.setBorderColor(fBorderColor);
		fMiniMap.setBorderWidth(fBorderWidth);
		fControlPanel.setBorderStyle(fBorderStyle);
		fControlPanel.setBorderColor(fBorderColor);
		fControlPanel.setBorderWidth(fBorderWidth);
	}
	
	function setNewSizes() {
		setDefaultSizes();
		fToolBar.setPosition(pToolBarLeft,pToolBarTop,pToolBarWidth,pToolBarHeight);
		fLayerControl.setPosition(pControlsLeft,pControlsTop,pControlsWidth,pControlsHeight);
		fLegend.setPosition(pControlsLeft,pControlsTop,pControlsWidth,pControlsHeight);
		fGazeetter.setPosition(pControlsLeft,pControlsTop,pControlsWidth,pControlsHeight);
		fInfos.setPosition(pInfosLeft, pInfosTop, pInfosWidth, pInfosHeight);
		fMiniMap.setPosition(pMinimapLeft,pMinimapTop,pMinimapWidth,pMinimapHeight);
		fDynamicMap.setPosition(fLeft,fTop,fWidth,fHeight);
	}
	
	// methodes "accessoires"
	this.showHelp = function() {
		acai_carto_help.show(fPackInfos, fPackDatas, fPackPrint, fPackGazetter, fGazeetter.getLevel());
	};

	function throwGlobalException(myException) {
		alert(GLOBAL_EXCEPTION + myException);
	}

	this.init();
	
}

