


var DynActionexportClient =Class.create();
DynActionexportClient.prototype={
	initialize:function(){
	},
	onAction:function(){
		mainCarte.exportVectors();
	
	}
}
var DynActionexportReport =Class.create();
DynActionexportReport.prototype={
	initialize:function(){
	},
	onAction:function(){
		this.params=this.getParam();
		this.p = "";
		this.presenter = "HTML";
		this.evt = "viewListeRapport";
		if(this.params)
		{
			this.params = this.params.split(",");
			if(this.params[0])
			{
				this.p = this.params[0];
				evt = "viewRapport";
			}
			if(this.params[1])this.presenter = "XLS"; 
		}	
		var 	tempParam = 'method=selectionToRecherche&limitationCouche=0';
		mainCarte.appelServeur(tempParam, this.a_server,this,mainCarte.recherche_url,'post');
	//	selectionToRecherche(coucheExport);
	},
	a_server:function(	res){
	
		var url  ="/dynmap/class/modules/mvccarte.php?cont=RAPPORT&event="+this.evt+"&etape=2&presenter="+this.presenter+"&idRapportEnCours="+this.p+"&path_application="+path_application;
		window.open(url,"test","","width="+(screen.width/1.5)+",scrollbars=yes,left="+(screen.width/6)+",height=500,top="+((screen.height-500)/2));
	
	}
}


var DynActionSpatialOperation = Class.create();

DynActionSpatialOperation.prototype = {
		initialize:function(){
	
		},
		onAction:function(){
			if(this.objParam.layer==undefined||this.objParam.layer==0){
				alert("Veuillez choisir une couche d'intersection");
			}else{
				var mode=this.getParam();
			//	alert(mode);
				mainCarte.inverseSelection(this.objParam.layer,mode);
			}

		}
		
}

var DynActiondeleteAllAnnotations =Class.create();
DynActiondeleteAllAnnotations.prototype={
	initialize:function(){
	},
	onAction:function(){
		deleteAllAnnotations();
	}
}


var DynActionparametreClient =Class.create();
DynActionparametreClient.prototype={
	initialize:function(){
	},
	onAction:function(){
	//	var tabelems=getViewBoxVars();
		mainCarte.editOptions();
	}
}

var DynActionchgStateAnnotations=Class.create();
DynActionchgStateAnnotations.prototype={
	initialize:function(){
	},
	onAction:function(){
		chgStateAnnotations();
	}
}

var DynActiontogglerImageStateMask=Class.create();

DynActiontogglerImageStateMask.prototype={
	initialize:function(){
		//this.state = false;
	
		  if ( typeof DynActiontogglerImageStateMask.state == 'undefined' ) {
		        // It has not... perform the initilization
			  DynActiontogglerImageStateMask.state=false;
		    }

		
		
		
	},
	_mH:function(){
	},
	stateModified:function(obj){
	
		if(	obj.state ){
			this.img.src = this.img_src_on;
		}else{
			this.img.src = this.img_src_off;
		}
		DynActiontogglerImageStateMask.state = ! obj.state;
	},
	onAction:function(){
		
		this.img= this.getParamSpec('eventLauncher');
		if(!this.img_src_on){
			this.img_src_on =this.img.getAttribute('src');
		}
		this.img_src_off=this.img.getAttribute('srcoff');
		this.img_src_over=this.img.getAttribute('srcover');
		this.img_src=this.img.getAttribute('src');
		GestEvtDyn.ajouteUniqueEcouteur( 'ON_STATE_MASK',this.stateModified,this);
		mainCarte.setStateMask(DynActiontogglerImageStateMask.state);
		
	}
}

var DynActionselectionToMask=Class.create();
DynActionselectionToMask.prototype={
	initialize:function(){
	
	},
	onAction:function(){
		selectionToMask();
	}
}

var DynActionzoomMap =Class.create();
DynActionzoomMap.prototype={
	initialize:function(){
	},
	onAction:function(){
		mapZoom(this.getParam());
	}
}
var DynActionpanMap =Class.create();
DynActionpanMap.prototype={
	initialize:function(){
	},
	onAction:function(){
		var strDep=this.getParam();
		var tabobj=strDep.split(',');
		panMap(tabobj[0],tabobj[1]);
		//mapZoom(this.objImg.getAttribute('DynmapParam'));
	}
}
var DynActiondefaultZoom=Class.create();
DynActiondefaultZoom.prototype={
	initialize:function(){
	},
	onAction:function(){
		initZoom();

	}
}

var DynActiontoolDraw =Class.create();
DynActiontoolDraw.prototype={
		initialize:function(){
				this.lay=0;	
		},
		_layerSel:function(lay,typeD){
	
			if(typeD=='draw'){
			
				this.layer=lay;
			}
		},
		
		onAction:function(){
			if(this.objParam.layer==undefined||this.objParam.layer==0){
				alert('Veuillez choisir une couche de dessin');
			}else{
				DynWatch.chgContextApi('drawSimple',{'dynmapparam':this.objParam.layer});
				
			}
		}

}
		
		


var DynActionresizeMapWindow =Class.create();
DynActionresizeMapWindow.prototype={
	initialize:function(){
	},
	onAction:function(){

		var strDep=this.getParam();
		var tabobj=strDep.split(',');
		if(tabobj.length>1){
			mainCarte.resizeMap(tabobj[0],tabobj[1]);
		}else{
			mainCarte.resizeMap(widthPxInitial,heightPxInitial);
		}
	}
}
var DynActionexportSelectData =Class.create();
DynActionexportSelectData.prototype={
	initialize:function(){
	},
	onAction:function(){
	
		var typeExport=this.getParam();
		var coucheExport=this.getParamSpec('DynmapCouche');
		
		var objects=this.getParamSpec('DynmapObjects');
		
		if(typeExport!='RECHERCHE'){
			if(typeExport!='METIER'){
				
				export_selection(typeExport);
			}else{
				if(coucheExport==undefined){
					coucheExport=0;
				}
			
				var colExport=this.getParamSpec('DynmapColonneExport');
				if(colExport==undefined){
					colExport='ROWID';
				}

				dynUrl='/dynmap/class/modules/mvccarte.php';
				dynUrl+='?cont=APIDYNMAPTOMVC&event=selectionToListeColonne&coucheExport='+coucheExport+'&colExport='+colExport+'&path_application='+path_application;
			    var	pars='';
				if(objects!=undefined){
					pars+='objects='+objects;
				}
				
				var myAjax = new Ajax.Request(
				dynUrl,
				{method: 'post', parameters: pars, onComplete: this.a_selectionToMetier,objetLie:this});
			}

		}else{
			if(coucheExport==undefined){
				coucheExport=0;
			}
			if(objects==undefined){
				selectionToRecherche(coucheExport);
			}else{
				selectionToRecherche(coucheExport,objects);
			
			}
		}
	},
	a_selectionToMetier:function(res){
		var okSelect =true;
		try{
			eval('response = ' + res.responseText);
		}catch(e){
			okSelect=false;
		}

		typeEnvoi=this.getParamSpec('DynmapTypeCible');
		if(!okSelect||response.elems.length==0){
			alert('la sélection ne contient aucune donnée');
			return;
		}
		if(typeEnvoi==undefined){
			typeEnvoi='POST';
		}
		if(typeEnvoi=='POST'){
			this.action_POST(response.elems);
		}
		if(typeEnvoi=='AJAX_DIV'){
			this.action_AJAX(response.elems);
		}


	},
	action_POST:function(elems){
		targetMet=this.getParamSpec('DynmapCible');
		targetLink=this.getParamSpec('DynmapLink');
		if ( targetMet == "") //Si la cible n'est pas précisé ou egale à _blank
		{
			targetMet == "_blank"
		}
		divForm=document.createElement('div');
		divForm.id='divfSelMetier';
		tpHtml='<form name="fSelMetier" target="'+targetMet+'" action="'+targetLink+'" method="POST">';
		for(var i=0;i<elems.length;i++){
			tpHtml+='<input type ="hidden" name="elements[]" value="'+elems[i]+'">';
		}
		tpHtml+='</form>';
		divForm.innerHTML=tpHtml;

		document.body.appendChild(divForm);
		dTest=$('divfSelMetier');
		document.fSelMetier.submit();
		document.body.removeChild(divForm);

	},
	action_AJAX:function(elems){
		targetMet=this.getParamSpec('DynmapCible');
		targetLink=this.getParamSpec('DynmapLink');
		var elements = "";
		for(var i=0;i<elems.length;i++){
			elements+='elements[]='+elems[i]+'&';
		}

		var myAjax = new Ajax.Updater(targetMet,targetLink, {method: 'post', parameters: elements, evalScripts:true});
	}
}

var DynActionselectNone =Class.create();
DynActionselectNone.prototype={
	initialize:function(){
	},
	onAction:function(){
		init_selection();
	}
}

var DynActionprintMap =Class.create();
DynActionprintMap.prototype={
	initialize:function(){
	},
	onAction:function(){
		tp=false;
		if(this.getParam())
		{
			tp=this.getParam();
		}
		if(!tp){
			printFlash();
		}else{
			printFlash({'modele':tp});
		}
	}
}
var DynActionexportMap =Class.create();
DynActionexportMap.prototype={
	initialize:function(){
	},
	onAction:function(){
		mainCarte.exportToImg();
		
	}
}

function drawCopyGeomComplete(evt)
{
	var layerRetour = evt.responseText;


	init_selection();

	GestEvtDyn.enleveEcouteur('DESSINOFF',DynStopDrawExterne);

	switchDraw('close',1);

	if(document.all['SPAN_DRAWLAYERS']){
		document.all['SPAN_DRAWLAYERS'].innerHTML='';
	}

	mainCarte.refreshMapData(layerRetour);
}

var DynActionNewObjectByDataType=Class.create();
DynActionNewObjectByDataType.prototype={
		initialize:function(){
		},
		onAction:function(){
			var tp=0;
			if(this.getParam()){
				tp=this.getParam();
			}else{
				tp=getDrawLayer();
			}

			if (tp==0){
				alert('Vous devez sélectionner une couche de dessin');
			}else{
				mainCarte.setNewObject(tp);
			}
		}
}

var DynActiondrawCopyGeom =Class.create();
DynActiondrawCopyGeom.prototype={
	initialize:function(){
	},
	onAction:function()
	{
		GestEvtDyn.ajouteEcouteur('DESSINOFF',DynStopDrawExterne);
		var tp=0;
		if(this.getParam())
		{
			tp=this.getParam();
		}
		else
		{
			tp=getDrawLayer();
		}

		if (tp==0)
		{
			alert('Vous devez sélectionner une couche de dessin');
		}
		else
		{
			var separator="-";
		
			ArraySelection = getCurrentSelection();
			var strSelection="";
			if(ArraySelection){
				for(var i=0;i<ArraySelection.length;i++){
					if(ArraySelection[i]!=""){
						var identifiant=ArraySelection[i];
						strSelection+=identifiant+separator;
					}
				}
			}
			if (strSelection != "")
			{
				var dynmap_urlpars	="path_application="+path_application+"&";
				dynmap_urlpars      +='method=DRAWSERVER&args=drawCopyGeom,layerIdDessin|'+tp+'|ObjSelection|'+strSelection+'|separator|-,common';
				var myAjax2 = new Ajax.Request (dynmap_url , {method: 'post', parameters: dynmap_urlpars, onComplete: drawCopyGeomComplete} );
			}
			else
			{
				alert('Veuillez sélectionner dans la carte les objets à copier');
			}
		}

		if(document.all['SPAN_DRAWLAYERS']){
			document.all['SPAN_DRAWLAYERS'].innerHTML='';
		}
	}
}

var DynActionmultiMajData =Class.create();
DynActionmultiMajData.prototype={
	initialize:function(){
	},
	onAction:function()
	{
		var separator="-";
		
		ArraySelection = getCurrentSelection();
		var strSelection="";
		if(ArraySelection){
			for(var i=0;i<ArraySelection.length;i++){
				if(ArraySelection[i]!=""){
					var identifiant=ArraySelection[i];
					strSelection+=identifiant+separator;
				}
			}
		}
	    var viewType = "popup";
		if (strSelection != "")
		{
			if (viewType == "div")
			{
				// ------------------ viewType DIV to do
				var dynmap_urlpars = "/dynmap/class/modules/mvccarte.php?cont=MAJDATAMULTIPLE&event=affichePopup&path_application="+path_application;
				var myAjax = new Ajax.Updater('monformulaire ...', url, {method: 'post', parameters: pars, evalScripts:true});
			}
			if (viewType == "popup")
			{
				window.open("/dynmap/class/modules/mvccarte.php?cont=MAJDATAMULTIPLE&event=affichePopup&path_application="+path_application,"test","top=200,left=200,width=280,height=170,resizable=yes,scrollbars=yes");
			}
		}
		else
		{
			alert('Veuillez sélectionner dans la carte les objets à modifier');
		}

	}
}

var DynActionStyleAnalysePicker=Class.create();
DynActionStyleAnalysePicker.prototype={
	initialize:function(){
	},
	onAction:function()
	{ 
		MsgDynActionNonImplement();
	}
}

var DynActionzoomPreced =Class.create();
DynActionzoomPreced.prototype={
	initialize:function(){
	},
	onAction:function(){
		 zoomPreced();
	}
}

var DynActionvuePrecedente =Class.create();
DynActionvuePrecedente.prototype={
	initialize:function(){
	},
	onAction:function(){
		 MsgDynActionNonImplement();
	}
}
var DynActionvuePrecedente =Class.create();
DynActionvuePrecedente.prototype={
	initialize:function(){
	},
	onAction:function(){
		zoomPreced();
	}
}
var DynActionuserMaps =Class.create();
DynActionuserMaps.prototype={
	initialize:function(){
	},
	onAction:function(){
		tp=false;
		if(this.getParam())
		{
			tp=this.getParam();
		}
		if(!tp){			
			userMaps('liste');
		}else{
			userMaps(tp);
		}
	}
}

function MsgDynActionNonImplement()
{
	alert("Cette fonctionnalité n'est pas encore disponible dans cette version");
}
