//fonctions generales js utiles
var Prototype = {
	Version: '1.3.1',
	emptyFunction: function() {}
}

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
}



var Abstract = new Object();

Object.extend = function(destination, source) {
	for (property in source) {
		destination[property] = source[property];
	}
	return destination;
}


function InheritObj(destination, source){
	for (property in source) {
		if(destination[property]==undefined){
			destination[property] = source[property];
		}
	}
	return destination;

}
Object.prototype.extend = function(object) {
	return Object.extend.apply(this, [this, object]);
}

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		__method.apply(object, arguments);
	}
}
//class de Gestionnnaire Evt
var GestEvt=Class.create();
GestEvt.prototype= {
	initialize: function(){
		//sauvegarde les fonctions de rappel
		this.tabFonc=new Array();
		//sauvegarde les evenements ecoutes
		this.tabListen=new Array();
		//sauvegarde les objets ecoutes, pour les appler avec la fonction de rappel
		this.tabObjet=new Array();
		this.nomEvt="";

	},

	ajouteEcouteur : function(evt,fonction,objetRetour) {

		if (!objetRetour){
			objetRetour = this;
		}
		var nonok=false;

		for(i=0;i<this.tabFonc.length;i++){
			if (this.tabFonc[i]==evt){
				nonok=true;
			}
		}


		if(!nonok){
			this.ajouteEvenement(evt);
			this.ajouteEcouteur(evt,fonction,objetRetour);
			//	alert("impossible enregister evenement:fonction inconnue");
		}else{
			//fonctions
			var tabFonctemp=this.tabListen[evt];
			tabFonctemp[tabFonctemp.length]=fonction;
			this.tabListen[evt]=tabFonctemp;
			//objets
			var tabObjtemp=this.tabObjet[evt];
			tabObjtemp[tabObjtemp.length]=objetRetour;
			this.tabObjet[evt]=tabObjtemp;



		}

	},

	enleveEcouteur:function(nameEvent,fonction){
		var NewTab=new Array();
		var NewTabObj=new Array();
		var montableau=this.tabListen[nameEvent];
		var montableauObjet=this.tabObjet[nameEvent];
		for(i=0;i<montableau.length;i++){
			if(montableau[i]!=fonction){
				NewTab[NewTab.length]=montableau[i];
				NewTabObj[NewTabObj.length]=montableauObjet[i];
			}
		}
		this.tabListen[nameEvent]=NewTab;
		this.tabObjet[nameEvent]=NewTabObj;

	},

	ajouteEvenement:function(nameEven){

		this.tabFonc[this.tabFonc.length]=nameEven;
		this.tabListen[nameEven]= new Array();
		this.tabObjet[nameEven]=new Array();
	},

	lanceEvenement:function(nameEvent,Arretour){

		//alert(nameEvent+' lance '+	Arretour);
		if(!Arretour){
			Arretour=new Array();

		}

		var montableau=this.tabListen[nameEvent];
		//	alert(montableau.length);
		var montabObjet=this.tabObjet[nameEvent];
		if(typeof(Arretour)=='string'){
			var Arrtmp=[Arretour];
			Arretour=Arrtmp;

		}
		//alert(typeof(Arretour));

		this.nomEvt=nameEvent;
		try{
			if(montableau && montableau.length!=0){


				for(var i=0;i<montableau.length;i++){
					mafonction=montableau[i];
					monobjet=montabObjet[i];
					//alert('fonction appel sur '+this.nomEvt+' fonc'+mafonction);
					if(!(mafonction instanceof Function)&&0){
						alert("erreur:l'arguement passé au gestionnaire de fonctions n'est pas une fonction");
					}else{
						if(mafonction){
				

							try{
								//mafonction();

								mafonction.apply(monobjet,Arretour);
							}catch(e){

								try{
									var parameterStrings = new Array();
									var object=monobjet;

									for (var ia = 0; ia < Arretour.length; ia++){
										parameterStrings[ia] = 'Arretour[' + ia + ']';
									}
									object.__apply__ = mafonction;
									var result = eval('object.__apply__(' +parameterStrings.join(', ') + ')');
									object.__apply__ = null;

									return result;

								}catch(e){
									alert(e.name);
									alert(e.message);
									alert("la fonction de retour  ne peut etre atteinte"+mafonction);
								}
							}
						}
					}
				}
			}
		}catch(e){
		alert('probleme dans la gestion de l`evenement'+nameEvent)	;
			alert(e.name +" > "+e.message);
			
		}

	}
};

GestEvtDyn=new GestEvt();
parent.GestEvtDyn=GestEvtDyn;
Function.prototype.lieEvenement = function(strevt) {

	GestEvtDyn.ajouteEcouteur(strevt,this);
	return 1;
};


ViewerGestDyn = function() {};
ViewerGestDyn.prototype = {
	ecoute:function(gest,evt,fonc){
		gest.ajouteEcouteur(evt,fonc,this);
	}
}

parent.legendeCharge=legendeCharge;
parent.legCharge=legCharge;
var legCharge=0;

function legendeCharge(){

	legCharge=1;

	dataInitLoad(sbdatTemp);

}

var LAYERCONTROL_LOADED = '0';

//pour afficher la legende dynamiquement
function lanceLegende(logok){
	//alert('totooo');
	var DivLeg=$("TheLayerID");

	if(DivLeg){

		if(logok=="1"){
			//alert('tresst');
			DivLeg.innerHTML=CheminLegende;
		}else{
			DivLeg.innerHTML="";
		}
	}else{
		LAYERCONTROL_LOADED = CheminLegende;
	}
	//alert('lanceLeg');
}

//chargeur de fonction
var Charge=Class.create();
Charge.prototype= {
	initialize: function(){
	},
	//charge un script dans svg
	BlockSvg:function(idBlock,fonction){
		svgdoc=document.svgmap.getSVGDocument();
		root=svgdoc.getDocumentElement();

		if(!svgdoc.getElementById(idBlock)){
			var svgns = "http://www.w3.org/2000/svg";

			var Myscript = svgdoc.createElementNS(svgns, "script");
			Myscript.defer = false;
			Myscript.setAttribute('type', "text/ecmascript");
			//var srcScript = '/dynmap/loaderJsBlock.php?idBlock='+idBlock;
			//Myscript.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",srcScript);
			Myscript.setAttribute('id' , idBlock);
			scriptCode = svgdoc.createTextElement("alert('ttiti');");
			Myscript.appendChild(scriptCode);

			root.appendChild(Myscript);
			var scriptLoaded=svgdoc.getElementById(idBlock);

			alert(scriptLoaded.getAttribute('readyState'));

		}

		//alert(scriptLoaded);
		//alert(scriptLoaded2);
		//alert(svgdoc);
		var scriptLoad=svgdoc.getElementById(idBlock);
		alert(scriptLoad.firstChild);
		alert(scriptLoad.firstChild);
		try{
			test46();
			eval(fonction+'()');
		}catch(e){
			alert(e.message);
		}


	}
}
document._currentObjectDrawable=0;
function WriteMainMap(mapUrlFin){
	document.write(mapUrlFin);
}
function setCurrentObjectDrawed(obj){
		document._currentObjectDrawable=obj;

}
function getCurrentObjectDrawed(){
	return document._currentObjectDrawable;
}
function unsetCurrentObjectDrawed(){
	document._currentObjectDrawable=0;
}
var C=new Charge();

/*
function openrechRes(onglet){

if(typeof onglet=='undefined'){
var url_recherche = '/dynmap/recherche/resultatrecherche.php?path_application='+path_application;
}else{
if(onglet=='rapport'){
var url_recherche = '/dynmap/class/modules/mvccarte.php?cont=RAPPORT&event=viewListeRapport&path_application='+path_application;
}
}
window.open(url_recherche,'','width='+(screen.width/1.5)+',scrollbars=yes,left='+(screen.width/6)+',height=500,top='+((screen.height-500)/2));
}
*/
