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

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 !!!

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




var DynActionexportClient =Class.create();
DynActionexportClient.prototype={
	initialize:function(){
	},
	onAction:function(){
		var tabelems=getViewBoxVars();
		var linkOpener="/dynmap/class/modules/mvccarte.php?cont=EXPORTCLIENT&event=getInterfaceExport&path_application="+path_application;
		linkOpener+='&bbox[Xmin]='+tabelems["Xmin"]+'&bbox[Ymin]='+tabelems["YminREEL"]+'&bbox[winDX]='+	tabelems["winDX"]+'&bbox[winDY]='+tabelems["winDY"]+'&bbox[yminCarto]='+tabelems['Ymin'];
		window.open(linkOpener,"","width="+(screen.width/1.5)+",scrollbars=yes,left="+(screen.width/6)+",height=500,top="+((screen.height-500)/2));
	}
}
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 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 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');
		//	alert(typeExport);
		if(typeExport!='RECHERCHE'){
			if(typeExport!='METIER'){
				//alert('22');
				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';
				pars='cont=APIDYNMAPTOMVC&event=selectionToListeColonne&coucheExport='+coucheExport+'&colExport='+colExport+'&path_application='+path_application;
				var myAjax = new Ajax.Request(
				dynUrl,
				{method: 'get', parameters: pars, onComplete: this.a_selectionToMetier,objetLie:this});
			}

		}else{
			if(coucheExport==undefined){
				coucheExport=0;
			}
			selectionToRecherche(coucheExport);
		}
	},
	a_selectionToMetier:function(res){

		try{
			eval('response = ' + res.responseText);
		}catch(e){
			alert(res.responseText);
			alert(e.name);
			alert(e.message);
		}

		typeEnvoi=this.getParamSpec('DynmapTypeCible');
		if(response.elems.length==0){
			alert('la selection 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.appendChild(divForm);
		dTest=$('divfSelMetier');
		document.fSelMetier.submit();
		document.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)
{
	 MsgDynActionNonImplement();
}

var DynActiondrawCopyGeom =Class.create();
DynActiondrawCopyGeom.prototype={
	initialize:function(){
	},
	onAction:function()
	{
		 MsgDynActionNonImplement();
	}
}

var DynActionmultiMajData =Class.create();
DynActionmultiMajData.prototype={
	initialize:function(){
	},
	onAction:function()
	{
		MsgDynActionNonImplement();		 
	}
}
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();
	}
}

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

