/**************************

MERCI DE COMMENTER TOUTES CES FONCTIONS, ON N'Y COMPREND RIEN !!!
MERCI DE COMMENTER TOUTES CES FONCTIONS, ON N'Y COMPREND RIEN !!!
MERCI DE COMMENTER TOUTES CES FONCTIONS, ON N'Y COMPREND RIEN !!!
MERCI DE COMMENTER TOUTES CES FONCTIONS, ON N'Y COMPREND RIEN !!!
MERCI DE COMMENTER TOUTES CES FONCTIONS, ON N'Y COMPREND RIEN !!!
MERCI DE COMMENTER TOUTES CES FONCTIONS, ON N'Y COMPREND RIEN !!!
MERCI DE COMMENTER TOUTES CES FONCTIONS, ON N'Y COMPREND RIEN !!!

**************************/




function DynStopMeasure(){

	GestEvtDyn.enleveEcouteur('MODULEUNLOADED',DynStopMeasure);
	DynWatch.chgContextApi('Default');
}
var DynContextemeasureMap =Class.create();
DynContextemeasureMap.prototype={
	initialize:function(){
	},
	onStart:function(){
		mainCarte.loadModule('mesure',{'type':this.getParam()});
		GestEvtDyn.ajouteEcouteur('MODULEUNLOADED',DynStopMeasure);
	},
	onEnd:function(){
		//alert('test');
		GestEvtDyn.enleveEcouteur('MODULEUNLOADED',DynStopMeasure);
		mainCarte.unloadModule('mesure');
	}
}

/***********************************************/

var DynContexteselectMap=Class.create();
DynContexteselectMap.prototype={
	initialize:function(){
	 this.vars=['layer','mode'];
	},
	onStart:function(){
	
		if(!this.getParam()){
			SetevenementCl(1);
		}else{
			var para={'tool':this.getParam()};
			
			if(this.getParamSpec('layer')&&this.getParamSpec('layer')!='0'){
				para.layer=this.getParamSpec('layer');
			}
			mainCarte.loadModule('SelectionTools',para);
			if(this.getParamSpec('listener')){
				GestEvtDyn.ajouteEcouteur('LAYER_WORK_SELECTION',this._refresh,this);
			}
		}
		
	},
	_refresh:function(layer,param){
	
		if(param=='select'){
		//	this.setAttribute('layer',layer);
			GestEvtDyn.enleveEcouteur('LAYER_WORK_SELECTION',this._refresh,this);
			mainCarte.unloadModule('SelectionTools');
			this.objParam['layer']=layer;
			this.onStart();
				
		}
	},
	onEnd:function(){
		GestEvtDyn.enleveEcouteur('LAYER_WORK_SELECTION',this._refresh,this);
		if(!this.getParam()){
			SetevenementCl(0);
		}else{
			mainCarte.unloadModule('SelectionTools');
		}
	}
}


/***********************************************/


var DynContexteinformation =Class.create();
DynContexteinformation.prototype={
	initialize:function(){
	},
	onStart:function(){
		SetevenementCl(0);
	},
	onEnd:function(){
		SetevenementCl(0);
	}
}


/***********************************************/

var DynContexteannotation =Class.create();
DynContexteannotation.prototype={
	initialize:function(){
	},
	onStart:function(){
		GestEvtDyn.ajouteEcouteur('MODULEUNLOADED',this.stopAn,this);
		mainCarte.loadModule('Draw',{'idLayer':'annotation','showToolsBar':true});
	},
	stopAn:function(){

		DynWatch.chgContextApi('Default');
	},
	onEnd:function(){

		GestEvtDyn.enleveEcouteur('MODULEUNLOADED',this.stopAn);
		mainCarte.unloadModule('Draw');
	}
}


/***********************************************/

var DynContextecoordsXY =Class.create();
DynContextecoordsXY.prototype={
	initialize:function(){
	},
	onStart:function(){
		 MsgDynContexteNonImplement();
	},
	onEnd:function(){
		 

	}
}
var DynContextezoomRect =Class.create();
DynContextezoomRect.prototype={
	initialize:function(){
	},
	onStart:function(){

		var strDep=this.getParam(); 
		try{ 
			mainCarte.chgContexte(strDep);
		}catch(e){
			alert('Parametre de deplacement inconnu dans l\'objet DynContextezoomRect');
		}
	},
	onEnd:function(){
		mainCarte.chgContexte('DEFAULT');
		//alert ('fini contexte');

	}
}
var DynContextepanMap =Class.create();
DynContextepanMap.prototype={
	initialize:function(){
	},
	onStart:function(){
			mainCarte.chgContexte('PAN');
		//mapActionByButton('PAN');

	},
	onEnd:function(){
		mainCarte.chgContexte('DEFAULT');

	}
}

//appel de dynmap en interne

//appel de dynmap en interne
function DynStopDrawExterne(){
  //alert('toto');
	DynWatch.chgContextApi('Default');
	GestEvtDyn.enleveEcouteur('DESSINOFF',DynStopDrawExterne);

}



var DynContextedrawSimple =Class.create();
DynContextedrawSimple.prototype={
	initialize:function(){
	},
	onStart:function(){
		GestEvtDyn.ajouteEcouteur('MODULEUNLOADED',this.stopAn,this);
		mainCarte.loadModule('Draw',{'idLayer':this.getParam(),'showToolsBar':true});
	},
	stopAn:function(){
		
		DynWatch.chgContextApi('Default');
	},
	onEnd:function(){
	
		GestEvtDyn.enleveEcouteur('MODULEUNLOADED',this.stopAn);
		mainCarte.unloadModule('Draw');
	}
}




var DynContextedrawDef =Class.create();
DynContextedrawDef.prototype={
		initialize:function(){
			GestEvtDyn.ajouteEcouteur('LAYER_WORK_SELECTION',this._layerSel,this);
			this.lay=0;
		},
		_layerSel:function(lay,typeD){
			if(typeD=='draw'){
				this.lay=lay;
			}
		},
		onStart:function(){
			this.st=true;
			var tp=0;
			GestEvtDyn.ajouteEcouteur('DESSINOFF',DynStopDrawExterne);
			GestEvtDyn.ajouteEcouteur('MODULEUNLOADED',this.onEnd,this);
			if(this.getParam()){
				tp=this.getParam();
			}else{
				tp=this.lay;
			}
			rowid=0;
			if(typeof(this.objectEditable)!='undefined'){
				var rowidCurrent=getCurrentObjectDrawed();
				if(rowidCurrent!=0){
					rowid=rowidCurrent;
				}
			}
			if(tp=='0'){
				alert('Veuillez sélectionner une couche de dessin');
			}else{
			//	alert(this.tool);
				mainCarte.drawLayer(this.tool,tp,{},rowid);
			}
		},
		onEnd:function(){
			if(this.st){
				this.st=false;
		
				GestEvtDyn.enleveEcouteur('DESSINOFF',DynStopDrawExterne);
				GestEvtDyn.enleveEcouteur('MODULEUNLOADED',this.onEnd,this);
				switchDraw('close',1);
				DynWatch.chgContextApi('Default');
			}			
		}
	}
var DynContextedrawLine =Class.create();
DynContextedrawLine.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_polyline';
		
	}
	
});
var DynContextedrawPolygon =Class.create();
DynContextedrawPolygon.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_polygon';
	}
	
});
var DynContextedrawPoint =Class.create();
DynContextedrawPoint.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_point';
	}
	
});
var DynContextedrawMove =Class.create();
DynContextedrawMove.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_move';
	}
	
});


var DynContextedrawEditNode =Class.create();
DynContextedrawEditNode.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.objectEditable=true;
		this.tool='draw_edit_node';
	}
	
});
var DynContextedrawBuffer =Class.create();
DynContextedrawBuffer.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_buffer';
		this.pbuf='';
	},
	onStart:function(){
		this.st=true;
		var couche=0;
		GestEvtDyn.ajouteEcouteur('DESSINOFF',DynStopDrawExterne);
		GestEvtDyn.ajouteEcouteur('MODULEUNLOADED',this.onEnd,this);
		if(this.getParam()){
			couche=this.getParam();
		}else{
			couche=this.lay;
		}
		if(couche!=0){
			if (couche.indexOf(",") > -1)
			{
				var arrtemp = new Array ();
				arrtemp = couche.split(",");
				couche = arrtemp[0];
				this.pbuf = arrtemp[1];
			}
			
		}
		rowid=0;
		
		if(tp=='0'){
			alert('Veuillez sélectionner une couche de dessin');
		}else{
		//	alert(this.tool);
			mainCarte.drawLayer(this.tool,couche,{'buffer':this.pbuf},rowid);
		}
	}
	
});

var DynContextedrawFusion =Class.create();
DynContextedrawFusion.prototype==(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_fusion';
	}
});
//Suppression de l'intérieur de l'objet par rapport à la selection
var DynContextedrawSupInt =Class.create();
DynContextedrawSupInt.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.objectEditable=true;
		this.tool='draw_buffer';
		this.pbuf=0;
	}
});
//Suppression de l'exterieur de l'objet par rapport à la selection
var DynContextedrawSupExt =Class.create();
DynContextedrawSupExt.prototype=(new DynContextedrawDef()).extend({

	initialize:function(){
	this.objectEditable=true;
	this.tool='draw_delete_outside';
}
});


function MsgDynContexteNonImplement()
{
	alert("Cette fonctionnalité n'est pas encore disponible dans cette version");
}

