var DynContextePointToAction=Class.create();
DynContextePointToAction.prototype={
	initialize:function(){
	},
	onStart:function(){ 
		
		GestEvtDyn.ajouteEcouteur('MOUSECLICK',this._doAct2,this);
		mainCarte.chgContexte('PROXY'); 
	
		 
	},
	_doAct2:function(X,Y,objId,p){
		
		var foncSpec=this.getParam();
		


		foncSpec(X,Y,objId,p);
		//this.onEnd();
	},
	onEnd:function(){

	GestEvtDyn.enleveEcouteur('MOUSECLICK',this._doAct2,this);
		mainCarte.chgContexte('DEFAULT'); 
		
	}
}








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

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

	}
}

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;
				}else{
					if(this.getParamSpec('dynmapROWID')){
						rowid = this.getParamSpec('dynmapROWID');
					}
				}
			}
			if(tp=='0'){
				alert('Veuillez sélectionner une couche de dessin');
			}else{
				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 DynContextedrawEllipse =Class.create();
DynContextedrawEllipse.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_ellipse';
	}
	
});
var DynContextedrawPoint =Class.create();
DynContextedrawPoint.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_point';
	}
	
});
var DynContextedrawRectangle =Class.create();
DynContextedrawRectangle.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_rectangle';
	}
	
});
var DynContextedrawMove =Class.create();
DynContextedrawMove.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_move';
	}
	
});
var DynContextedrawMoveSelection =Class.create();
DynContextedrawMoveSelection.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.tool='draw_move_selection';
	}
	
});

var DynContextedrawEditNode =Class.create();
DynContextedrawEditNode.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		this.objectEditable=true;
		this.tool='draw_edit_node';
	}
	
});


var DynContextedrawDelete =Class.create();
DynContextedrawDelete.prototype=(new DynContextedrawDef()).extend({
	initialize:function(){
		
		this.tool='draw_delete';
	}
	
});
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(typeof(this.objectEditable)!='undefined'){
			var rowidCurrent=getCurrentObjectDrawed();
			if(rowidCurrent!=0){
				rowid=rowidCurrent;
			}else{
				if(this.getParamSpec('dynmapROWID')){
					rowid = this.getParamSpec('dynmapROWID');
				}
			}
		}
		if(this.pbuf==''){
			this.pbuf='0.000001';
		}
		if(couche=='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_delete_inside';
		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");
}

