/* 
    This file is part of MiraMon Map Browser.
    MiraMon Map Browser is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with MiraMon Map Browser.  If not, see "http://www.gnu.org/licenses/".

    Copyright 2001, 2011 Xavier Pons

    Aquest codi JavaScript ha estat realitzat per Joan Masó Pau 
    (joan maso at uab cat) i Nuria Julià (n julia at creaf uab cat)
    dins del grup de MiraMon. MiraMon és un projecte del Centre
    de recerca i aplicacions forestals (CREAF) que elabora programari de 
    Sistema d'Informació Geogràfica i de Teledetecció per a la 
    visualització, consulta, edició i anàlisi de mapes ràsters i 
    vectorials. Elabora programari d'escriptori i també servidors i clients 
    per Internet. No tots aquests productes són gratuïts o de codi obert. 
    En particular, el Navegador de Mapes del MiraMon (client per Internet) 
    es distribueix sota els termes de la llicència "GNU General Public 
    License". Es pot actualitzar des de www.creaf.uab.es/miramon/mmn
*/

/////////////////////////////////////////////

var VersioToolsMMN="5.3";

/////////////////////////////////////////////



/*Funcions d'utilitat general inspirades en codis trobats a la Internet*/

var layerList = new Array();
var layerFinestraList = new Array();
var JaAvisatSuportLayers=false;

function CreaPropietatsLayer(nom, ancora, contingut)
{
	this.nom=nom;
	this.ancora=ancora;
	this.contingut=contingut;
}

var moure_desactiu=0x01;
var moure_actiu=0x02;

function CreaPropietatsFinestraLayer(nom, titol, botons)
{
	this.nom=nom;
	this.titol=titol;  // Estructura Multidioma o una cadena
	this.botons=botons;	
	this.estat_click=moure_desactiu;
	this.coord_click=null;
	this.pos_ini_barra=new CreaPunt2D(0,0);
	this.pos_ini_finestra=new CreaPunt2D(0,0);
}

function showOrHideLayer(elem, show)
{
    if (show)
		showLayer(elem);
    else
		hideLayer(elem);
}

function removeLayer(elem) 
{
	var elem_pare=elem.parentNode;
	if (!elem_pare)
		return;
	elem_pare.removeChild(elem);
	if (NecessariLayerIFrame)
	{
		 var elem_iframe=elem_pare.getElementById("iframe_"+elem.id);
		 if (elem_iframe)  
			 elem_pare.removeChild(elem_iframe);
	}
  /*if (win.document.layers)    
  { 
	win.document.layers[name].removeNode(true);
  }
  else if (win.document.getElementById || win.document.all)
  {*/
}

function hideLayer(elem) 
{
	/*if (win.document.layers)    win.document.layers[name].visibility = "hide";
	  else if (win.document.getElementById || win.document.all)*/
	elem.style.visibility = "hidden";	
	if (NecessariLayerIFrame)
	{		 
		 var elem_iframe=elem.ownerDocument.getElementById("iframe_"+elem.id);
		 //var elem_iframe=elem.parentNode.getElementById("iframe_"+elem.id);  //Això no va amb IE6.
		 if (elem_iframe)  //Problema IE6
		     elem_iframe.style.visibility = "hidden";
	}
}

function showLayer(elem) 
{
  /*if (win.document.layers)   win.document.layers[name].visibility = "show";
  else if (win.document.getElementById || win.document.all)
  {*/
  	elem.style.visibility = "visible";
	
	if (NecessariLayerIFrame)
	{		 
		 var elem_iframe=elem.ownerDocument.getElementById("iframe_"+elem.id);
		 if (elem_iframe)  //Problema IE6
		     elem_iframe.style.visibility = "visible";
	}
}

function isLayerVisible(elem)
{
    /*if (win.document.layers)   
    {
	if (win.document.layers[name].visibility == "hide")
		return false;
	else
		return true;
    }
    else if (win.document.getElementById || win.document.all)
    {*/   
	if (elem.style.visibility == "hidden")
		return false;
	else
		return true;
}

// Extret de http://www.faqts.com/knowledge_base/view.phtml/aid/5756
// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// for Netscape 6/Mozilla by Thor Larholm me@jscript.dk
// Usage: include this code segment at the beginning of your document
// before any other Javascript contents.

if(typeof HTMLElement!="undefined" && !
HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
				this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else 
				this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}

function insertContentLayer(elem_pare, where, content)
{
	elem_pare.insertAdjacentHTML(where, content);
}

function contentLayer(elem, content) 
{
   //Segons: www.irt.org/articles/js106/index.htm
  /*if (win.document.layers)
  {
	    win.document.layers[name].document.open();
	    win.document.layers[name].document.write(content);
	    win.document.layers[name].document.close();
  }
  else if (win.document.getElementById)*/  
	elem.innerHTML = content;
  //else if (win.document.all)  win.document.getElementById(name).innerHTML = content;
}

function getContentLayer(elem)
{
  //if (win.document.getElementById)
	return elem.innerHTML;
  /*else if (win.document.all)  
	return win.document.getElementById(name).innerHTML;
  else
	return "";*/
}

function moveLayer(elem, x, y, w, h)
{
var elem
/*  if (win.document.layers)
  {
	win.document.layers[name].moveTo(x,y);
	win.document.layers[name].resizeTo(w,h);
  }
  else if (win.document.getElementById || win.document.all)
  {*/
	/*var s=elem.getAttribute("style");
	if (typeof s == 'object')  //IE fa això. Pels altres (Opera, NS, Saf) és directament una cadena
		s=s.cssText;*/
	//Ara ho manipulo i ho canvio.
	var estil=elem.style;
	estil.left = x;
	estil.top = y;
	estil.width = w;
	estil.height = h;
  //}
}

function changePosAndShowLayer(elem, x, y)
{
var elem
/*  if (win.document.layers)
  {
	win.document.layers[name].moveTo(x,y);
	win.document.layers[name].resizeTo(w,h);
  }
  else if (win.document.getElementById || win.document.all)
  {*/
	var estil=elem.style;
	estil.left = x;
	estil.top = y;
     	estil.visibility = "visible";
	if (NecessariLayerIFrame)
	{		 
		 var elem_iframe=elem.ownerDocument.getElementById("iframe_"+elem.id);
		 //var elem_iframe=(elem.parentNode).getElementById("iframe_"+elem.id);
		 if (elem_iframe)  //Problema IE6
		     elem_iframe.style.visibility = "visible";
	}
}


function moveLayer2(elem, x1, y1, x2, y2)
{
var x,y,w,h;
  if (x1<x2)
  {
	x=x1;
	w=x2-x1+1;
  }
  else
  {
	x=x2;
	w=x1-x2+1;
  }
  if (w<2)
	w=2;
  if (y1<y2)
  {
	y=y1;
	h=y2-y1+1;
  }
  else
  {
	y=y2;
	h=y1-y2+1;
  }
  if (h<2)
	h=2;
  moveLayer(elem, x, y, w, h);
}

function clipLayer2(elem,x1,y1,x2,y2)
{
	/*if (win.document.layers)
	{
		win.document.layers[name].clip.left=x1;
		win.document.layers[name].clip.top=y1;
		win.document.layers[name].clip.right=x2;
		win.document.layers[name].clip.bottom=y2;
	}
	else if (win.document.getElementById || win.document.all)
	{*/
	   	elem.style.clip="rect("+y1+" "+x2+" "+y2+" "+x1+")";
	//}
}

function clipLayer(elem,x,y,w,h)
{
	clipLayer2(elem,x,y,x+w,y+h);
}

function borderLayer(elem, s)
{
  /*if (win.document.layers)
  {
	;
  }
  else if (win.document.getElementById || win.document.all)
  {*/
	elem.style.border = s;
  //}
}

//s pot ser "transparent" o un color
function colorLayer(elem, s)
{
  /*if (win.document.layers)
  {
	;
  }
  else if (win.document.getElementById || win.document.all)
  {*/
	elem.style.backgroundColor = s;
  //}
}

function classLayer(elem, s)
{
  /*if (win.document.layers)
  {
	;
  }
  else if (win.document.getElementById || win.document.all)
  {*/
	elem.className = s;
  //}
}

function getzIndexLayer(elem) 
{
  /*if (win.document.layers)
  {
    return(win.document.layers[name].style.zIndex);
  }
  else if (win.document.getElementById  || win.document.all )
  {*/

	return elem.style.zIndex;
  /*}
  else
  {
    return(null);
  }*/
}

function setzIndexLayer(elem, z) 
{
  /*if (win.document.layers)
  {
    win.document.layers[name].zIndex=z;
    win.document.layers[name].style.zIndex=z;
  }
  else if (win.document.getElementById  || win.document.all )
  {*/
	elem.zIndex=z;
    	elem.style.zIndex=z;
  //}
}

function CreaRectangle(esq,sup,ample,alt)
{
	this.esq=esq;
	this.sup=sup;
	this.ample=ample;
	this.alt=alt;
}

var RectGetRectLayer=new CreaRectangle(0,0,0,0);

function getRectLayer(elem)
{
    /*if (win.document.layers)
    {
	RectGetRectLayer.esq=win.document.layers[name].left;
	RectGetRectLayer.sup=win.document.layers[name].top;
	RectGetRectLayer.ample=win.document.layers[name].width;
	RectGetRectLayer.alt=win.document.layers[name].height;
    }	
    else if (win.document.getElementById || win.document.all)
    {*/
	// ? és usat perquè FireFox no té pixelLeft i suposo que left està en píxels.
	var estil=elem.style;
	RectGetRectLayer.esq=estil.pixelLeft ? estil.pixelLeft : parseInt(estil.left,10);
	RectGetRectLayer.sup=estil.pixelTop ? estil.pixelTop : parseInt(estil.top,10);
	RectGetRectLayer.ample=estil.pixelWidth ? estil.pixelWidth : parseInt(estil.width,10);
	RectGetRectLayer.alt=estil.pixelHeight ? estil.pixelHeight : parseInt(estil.height,10);
    //}
}

var SpaceWidth=800;
var SpaceHeight=600;

function setSpaceForLayers(w,h)
{
	SpaceWidth=w;
	SpaceHeight=h;
}

function spaceForLayers(win)
{
	if (win.document.body.clientWidth)
		SpaceWidth=win.document.body.clientWidth;
	if (win.document.body.clientHeight)
		SpaceHeight=win.document.body.clientHeight;
}

function changeSizeLayers(win)
{
var w_previ,h_previ, delta_w, delta_h, delta, delta1;
var canvis=false;
var elem;

	w_previ=SpaceWidth;
	h_previ=SpaceHeight;

	spaceForLayers(win);

	delta_w=SpaceWidth-w_previ
	delta_h=SpaceHeight-h_previ;

	//alert(delta_w+" "+delta_h);
	for (var i=0; i<layerList.length; i++)
	{
		if (layerList[i].ancora)
		{
			if(-1!=layerList[i].nom.search("_barra"))
				continue;

			elem=getLayer(win, layerList[i].nom);
			getRectLayer(elem);
			if(-1!=layerList[i].nom.search("_finestra"))
			{
				RectGetRectLayer.alt+=19;
				RectGetRectLayer.sup-=19;
			}

			if (layerList[i].ancora.indexOf("e")!=-1)
			{
				delta=delta_w*(RectGetRectLayer.esq+RectGetRectLayer.ample)/w_previ;
				if (layerList[i].ancora.indexOf("w")!=-1)
				{
					delta1=delta_w*RectGetRectLayer.esq/w_previ;
					RectGetRectLayer.esq+=delta1;
					RectGetRectLayer.ample+=delta-delta1;
				}
				else if (layerList[i].ancora.indexOf("C")!=-1)
				{
					RectGetRectLayer.esq+=delta;
				}
				else //if (layerList[i].ancora.indexOf("W")!=-1)
				{
					RectGetRectLayer.ample+=delta;
				}
				canvis=true;
			}
			else if (layerList[i].ancora.indexOf("E")!=-1)
			{
				if (layerList[i].ancora.indexOf("w")!=-1)
				{
					delta=delta_w*RectGetRectLayer.esq/w_previ;
					RectGetRectLayer.esq+=delta;
					RectGetRectLayer.ample+=delta_w-delta;
				}
				else if (layerList[i].ancora.indexOf("C")!=-1)
				{
					RectGetRectLayer.esq+=delta_w;
				}
				else //if (layerList[i].ancora.indexOf("W")!=-1)
				{
					RectGetRectLayer.ample+=delta_w;
				}
				canvis=true;
			}
			else
			{
				if (layerList[i].ancora.indexOf("w")!=-1)
				{
					delta=delta_w*RectGetRectLayer.esq/w_previ;
					RectGetRectLayer.esq+=delta;
					if (layerList[i].ancora.indexOf("C")!=-1)
						;
					else
						RectGetRectLayer.ample-=delta;
					canvis=true;
				}
				//else if (layerList[i].ancora.indexOf("W")!=-1)
			}
			if (layerList[i].ancora.indexOf("s")!=-1)
			{
				delta=delta_h*(RectGetRectLayer.sup+RectGetRectLayer.alt)/h_previ;
				if (layerList[i].ancora.indexOf("n")!=-1)
				{
					delta1=delta_h*RectGetRectLayer.sup/h_previ;
					RectGetRectLayer.sup+=delta1;
					RectGetRectLayer.alt+=delta-delta1;
				}
				else if (layerList[i].ancora.indexOf("R")!=-1)
				{
					RectGetRectLayer.sup+=delta;
				}
				else //if (layerList[i].ancora.indexOf("N")!=-1)
				{
					RectGetRectLayer.alt+=delta;
				}
				canvis=true;
			}
			else if (layerList[i].ancora.indexOf("S")!=-1)
			{
				if (layerList[i].ancora.indexOf("n")!=-1)
				{
					delta=delta_h*RectGetRectLayer.sup/h_previ;
					RectGetRectLayer.sup+=delta;
					RectGetRectLayer.alt+=delta_h-delta;
				}
				else if (layerList[i].ancora.indexOf("R")!=-1)
				{
					RectGetRectLayer.sup+=delta_h;
				}
				else //if (layerList[i].ancora.indexOf("N")!=-1)
				{
					RectGetRectLayer.alt+=delta_h;
				}
				canvis=true;
			}
			else
			{
				if (layerList[i].ancora.indexOf("n")!=-1)
				{
					delta=delta_h*RectGetRectLayer.sup/h_previ;
					RectGetRectLayer.sup+=delta;
					if (layerList[i].ancora.indexOf("R")!=-1)
						;
					else
						RectGetRectLayer.alt-=delta;
					canvis=true;
				}
				//else if (layerList[i].ancora.indexOf("N")!=-1)
			}
			if (canvis==true)
			{
				//alert(layerList[i].nom+" "+RectGetRectLayer.esq+" "+RectGetRectLayer.sup+" "+RectGetRectLayer.ample+" "+RectGetRectLayer.alt);
				if (RectGetRectLayer.esq<0)
					RectGetRectLayer.esq=0;
				if (RectGetRectLayer.ample<5)  //Impedeixo que les layers desaparexin totalment
					RectGetRectLayer.ample=5;
				if (RectGetRectLayer.sup<0)
					RectGetRectLayer.sup=0;
				if (RectGetRectLayer.alt<5)    //Impedeiso que les layers desaparexin totalment
					RectGetRectLayer.alt=5;

				if(-1!=layerList[i].nom.search("_finestra"))
				{

					var barra;
					barra=layerList[i].nom.replace("_finestra", "_barra");

					moveLayer(getLayer(win, barra), RectGetRectLayer.esq, RectGetRectLayer.sup, RectGetRectLayer.ample, 19);
					//alert(layerList[i].nom +" RectBarra : " +(RectGetRectLayer.esq) +" , " + (RectGetRectLayer.sup)+" , " + (RectGetRectLayer.ample) + " , 19)");
					moveLayer(elem, RectGetRectLayer.esq, (RectGetRectLayer.sup+19), RectGetRectLayer.ample, (RectGetRectLayer.alt-19));
					//alert(layerList[i].nom + " RectBarra : " +RectGetRectLayer.esq +" , " + (RectGetRectLayer.sup+19)+" , " + RectGetRectLayer.ample+" , " +  (RectGetRectLayer.alt-19));
				}
				else					
					moveLayer(elem, RectGetRectLayer.esq, RectGetRectLayer.sup, RectGetRectLayer.ample, RectGetRectLayer.alt);
			}
		}
	}
	return canvis;
}

function vScrollLayer(elem, i, n)
{
    /*if (win.document.layers)
    {
        ;
    }
    else if (win.document.getElementById || win.document.all)
    {*/
	//elem.style.height, alert(elem.style.pixelHeight
	if (elem.scrollHeight && elem.scrollHeight>elem.offsetHeight)
	{
	    var i_scroll=i*elem.scrollHeight/n;
	    if (i_scroll<elem.scrollTop)
		elem.scrollTop=i_scroll;
	    if (i_scroll>elem.scrollTop+elem.offsetHeight-elem.scrollHeight/n)
	    	elem.scrollTop=i_scroll-elem.offsetHeight+elem.scrollHeight/n;
	}
    //}
}

var boto_tancar=0x01;
var boto_pop_up=0x02;
var boto_pop_down=0x04;

function isFinestraLayer(win, name)
{
	return isLayer(getLayer(win, name+"_finestra"));
}

function setzIndexFinestraLayer(win, name, z)
{
	setzIndexLayer(getLayer(win,name+"_finestra"),z);
	setzIndexLayer(getLayer(win,name+"_barra"),z);
}

function hideFinestraLayer(win, name) 
{
	hideLayer(getLayer(win,name+"_finestra"));
	hideLayer(getLayer(win,name+"_barra"));
}

function esborraFinestraLayer(win, name)
{
	esborraLayer(getLayer(win,name+"_finestra"));
}

function showFinestraLayer(win, name) 
{
	showLayer(getLayer(win,name+"_finestra"));
	showLayer(getLayer(win,name+"_barra"));
}

function isFinestraLayerVisible(win, name)
{
	var elem=getLayer(win,name+"_finestra");
	if(elem && isLayerVisible(elem))
		return true;
	else
		return false;
	
}

function getcontentFinestraLayer(win, name)
{
	return getContentLayer(getLayer(win, name+"_finestra"));
}

function contentFinestraLayer(win, name, content) 
{
	contentLayer(getLayer(win, name+"_finestra"), content);
}//Fi de contentFinestraLayer()

function winMousePos(e) 
{
	//get the position of the mouse
	if( !e ) 
		e = window.event; 
	if( !e || ( typeof( e.pageX ) != 'number' && typeof( e.clientX ) != 'number' ) ) 
		(new CreaPunt2D(0,0));
	
	if( typeof( e.pageX ) == 'number' ) 
	{ 
		var xcoord = e.pageX; 
		var ycoord = e.pageY; 
	} 
	else 
	{
		var xcoord = e.clientX; 
		var ycoord = e.clientY;
		if( !(( window.navigator.userAgent.indexOf( 'Opera' ) + 1) || 
			  (window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) || 
			  window.navigator.vendor == 'KDE' ) ) 
		{
			if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) ) 
			{
				xcoord += document.documentElement.scrollLeft; ycoord += document.documentElement.scrollTop;
			} 
			else if( document.body && ( document.body.scrollTop || document.body.scrollLeft ) ) 
			{
				xcoord += document.body.scrollLeft; ycoord += document.body.scrollTop; 
			} 
		} 
	}
	return (new CreaPunt2D(xcoord,ycoord));
}


function ActivaMovimentFinestraLayer(event, i_finestra)
{	
	layerFinestraList[i_finestra].estat_click=moure_actiu;
	var finestra=getLayer(this, layerFinestraList[i_finestra].nom+"_finestra");
	var barra=getLayer(this, layerFinestraList[i_finestra].nom+"_barra");
	
	layerFinestraList[i_finestra].coord_click=winMousePos(event);		
		
	layerFinestraList[i_finestra].pos_ini_barra.x=parseInt(barra.style.left,10);
	layerFinestraList[i_finestra].pos_ini_barra.y=parseInt(barra.style.top,10);
	layerFinestraList[i_finestra].pos_ini_finestra.x=parseInt(finestra.style.left,10);
	layerFinestraList[i_finestra].pos_ini_finestra.y=parseInt(finestra.style.top,10);	
	//evitaEventos(event);
}

function MouFinestraLayer(event, i_finestra)
{

	if(layerFinestraList[i_finestra].estat_click==moure_actiu)
	{
		var dx, dy;
		var coordActual;
		var finestra=getLayer(this, layerFinestraList[i_finestra].nom+"_finestra");
		var barra=getLayer(this, layerFinestraList[i_finestra].nom+"_barra");
				
		coordActual=winMousePos(event);
		
		dx=coordActual.x-layerFinestraList[i_finestra].coord_click.x;
		dy=coordActual.y-layerFinestraList[i_finestra].coord_click.y;
			
		barra.style.left=(layerFinestraList[i_finestra].pos_ini_barra.x+dx)+"px";
		barra.style.top=(layerFinestraList[i_finestra].pos_ini_barra.y+dy)+"px";
		finestra.style.left=(layerFinestraList[i_finestra].pos_ini_finestra.x+dx)+"px";
		finestra.style.top=(layerFinestraList[i_finestra].pos_ini_finestra.y+dy)+"px";
		//evitaEventos(event);
	}
}

function DesactivaMovimentFinestraLayer(event_on_click, i_finestra)
{
	layerFinestraList[i_finestra].estat_click=moure_desactiu;
	layerFinestraList[i_finestra].coord_click=null;
}

function evitaEventos(event)
{
	// Funcion que evita que se ejecuten eventos adicionales
	if(navigator.userAgent.indexOf("MSIE")>=0) 
	{
		window.event.cancelBubble=true;
		window.event.returnValue=false;
		if( window.event.stopPropagation ) 
			window.event.stopPropagation();
	}
	// Otros
	else 
	{
		event.preventDefault();
		event.cancelBubble=true;
		if( window.event.stopPropagation ) 
			window.event.stopPropagation();

	}
}

function createFinestraLayer(win, name, titol, botons, left, top, width, height, ancora, scroll, visible, ev, content) 
{
var alt_barra=19;
var s="";
var nom;
var z = layerFinestraList.length;

  	layerFinestraList[z]= new CreaPropietatsFinestraLayer(name, titol, botons);

	//Creo les dos layers que formaran la layer tipus finestra amb títol i botons

	//Creo la barra
	nom=name+"_barra";
	createLayer(win,nom, left, top, width, alt_barra, ancora, false, visible, ev, null);

	//Li assigno el seu estil de visualització
	classLayer(getLayer(win, nom), "barrafinestra");

	//No Omplo la layer barra amb els botons i el títol ho faré quan conegui l'dioma del navegador
	
	//Creo la finestra i li assigno el seu estil de visualització
	nom=name+"_finestra";
	createLayer(win, nom, left, (top+alt_barra), width, (height-alt_barra), ancora, scroll, visible, ev, content);
	classLayer(getLayer(win, nom), "finestra"); 
}//Fi de createFinestraLayer()

function createLayer(win, name, left, top, width, height, ancora, scroll, visible, ev, content) 
{
  var z = layerList.length;

  layerList[z]= new CreaPropietatsLayer(name, ancora, content);
  
  /*if (win.document.layers) 
  {  // Netscape
    win.document.writeln('<layer name="' + name + '" left=' + left + ' top=' + top + ' width=' + width + ' height=' + height + ' visibility=' + (visible ? '"show"' : '"hide"') + ' z-index=' + z +'>\n'
			 ((content) ? content : '')+
			 '</layer>');
    win.document.layers[name].width = width;
    win.document.layers[name].height = height;        
  }
  else if (win.document.all || win.document.getElementById) 
  {  	// Explorer*/
    win.document.writeln('<div id="' + name + '" style="position:absolute; overflow:'+((scroll==si) ? 'scroll' : (scroll? 'auto':'visible'))+'; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') + (ev ? ' background-image : url(1tran.gif);' : '') +' z-index:' + z +';" ' + (ev ? ev : '') + '>'+
			 ((content) ? ((typeof content == 'object')? '' : content) : '') +
    			'</div>');
  /*}
  else
  {
     if (JaAvisatSuportLayers==false)
     {
        alert("Aquest navegador no suporta les layers que requerim.\n" + 
	      "Este navegador no suporta las layers que requerimos.\n" +
	      "Sorry, this browser does not support layers as required.");
        JaAvisatSuportLayers==true;
     }
  }*/
}

function textHTMLLayer(name, left, top, width, height, ancora, scroll, visible, ev, content)
{
var z = layerList.length;
var s;

  /*Posem null a content per tal de que la funció de canvi d'idioma no la repinti.*/
  layerList[z]= new CreaPropietatsLayer(name, ancora, null);
  
  /*if (document.layers) 
  {  // Netscape
    s='<layer name="' + name + '" left=' + left + ' top=' + top + ' width=' + width + ' height=' + height + ' visibility=' + (visible ? '"show"' : '"hide"') + ' z-index=' + z +'>'+
	 ((content) ? content : '') +
    	'</layer>';
  }
  else if (document.all || document.getElementById) 
  {  	// Explorer  */
      s='<div id="' + name + '" style="position:absolute; overflow:'+(scroll? 'auto':'visible')+'; left:' + left + 'px; top:' + top + 'px; width:' + width + '; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') + (ev ? ' background-image : url(1tran.gif);' : '') +' z-index:' + z +';" ' + (ev ? ev : '') + '>' +
	 ((content) ? content : '') +
    	'</div>';
  /*}
  else
  {
     if (JaAvisatSuportLayers==false)
     {
        alert(DonaCadena3("Aquest navegador no suporta les layers que requerim.", 
		"Este navegador no suporta las layers que requerimos.",
		"Sorry, this browser does not support layers as required."));
        JaAvisatSuportLayers==true;
     }
     s="";
  }*/
  return s;
}

/*Aquesta funció afegeix un iframe per resoldre un problema del IE 6
i la transparància de selects (DIV over SELECT). Solució trobada a:
http://esdi.excelsystems.com/wsexmp/DIVDRP.pgm?task=showinst&wsnum=00110
http://weblogs.asp.net/bleroy/archive/2005/08/09/how-to-put-a-div-over-a-select-in-ie.aspx
S'ha de cridar ABANS de crear la DIV corresponent.
*/
function textHTMLiframeLayer(name, left, top, width, height, visible)
{
var s="";
  /*if (document.layers) 
  {  // Netscape
	return s;
  }
  if (document.all || document.getElementById) 
  {  	// Explorer  */
	if (NecessariLayerIFrame)
	{
	      s='<iframe src="blanc.htm" id="iframe_' + name + '" style="position:absolute; left:' + left + 'px; top:' + top + 'px; width:' + width + '; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') + '"></iframe>';
	}
  //}
  return s;
}

function getLayer(win, name)
{
	return win.document.getElementById(name);
}

function isLayer(elem)
{
    /*if (win.document.layers)    
    {
	if (win.document.layers[name])
		return true;
	else
		return false;
    }
    else if (win.document.getElementById || win.document.all)
    {*/
	if (elem)
		return true;
	else
		return false;
    //}
}

// Funció inspirada en una de SitePoint Pty. Ltd, www.sitepoint.com
function Ajax() {
  this.req = null;
  this.url = null;
  this.status = null;
  this.statusText = '';
  this.method = 'GET';
  this.async = true;
  this.dataPayload = "";
  this.readyState = null;
  this.responseText = null;
  this.responseXML = null;
  this.handleResp = null;
  this.responseFormat = 'text/plain', // 'text/plain', 'text/xml', 'object'
  this.requestFormat = 'application/x-www-form-urlencoded'  //només per POST
  this.structResp=null;
  this.mimeType = null;
  this.headers = [];

  this.init = function() {
    var i = 0;
    var reqTry = [ 
      function() { return new XMLHttpRequest(); },
      function() { return new ActiveXObject('Msxml2.XMLHTTP') },
      function() { return new ActiveXObject('Microsoft.XMLHTTP' )} ];
      
    while (!this.req && (i < reqTry.length)) {
      try { 
        this.req = reqTry[i++]();
      } 
      catch(e) {}
    }
    return true;
  };
  this.doGet = function(url, hand, response_format, struct) {
    this.url = url;
    this.handleResp = hand;
    this.responseFormat = response_format || 'text/plain';
    this.structResp = struct;
    this.doReq();

  };

  this.doPost = function(url, request_format, dataPayload, hand, response_format, struct) {
    this.url = url;
	this.requestFormat = request_format || 'application/x-www-form-urlencoded';    
    this.dataPayload = dataPayload;
    this.handleResp = hand;
    this.responseFormat = response_format || 'text/plain';
	this.structResp = struct;
    this.method = 'POST';
    this.doReq();
  };

  this.doReq = function() {
    var self = null;
    var req = null;
    var headArr = [];
    
    if (!this.init()) {
      alert('Could not create XMLHttpRequest object.');
      return;
    }
    req = this.req;
    req.open(this.method, this.url, this.async);
    if (this.method == 'POST') 
        req.setRequestHeader('Content-Type', this.requestFormat);
    self = this;
	
    req.onreadystatechange = function() 
    {
      var resp = null;
      self.readyState = req.readyState;
      if (req.readyState == 4) {
        
		self.status = req.status;
        self.statusText = req.statusText;
        self.responseText = req.responseText;
        self.responseXML = req.responseXML;        
        
	switch(self.responseFormat) {
          case 'text/plain':
            resp = self.responseText;
            break;
          case 'text/xml':
            resp = self.responseXML;
            break;
          case 'object':
            resp = req;
            break;
        }
		
		if(self.structResp)
		   self.structResp.text=self.responseText;
        if (self.status > 199 && self.status < 300) {
          if (!self.handleResp) {
            alert('No response handler defined ' +
              'for this XMLHttpRequest object.');
            return;
          }
          else {
            if(self.structResp) 
            	self.handleResp(resp, self.structResp);
	    	else
		  		self.handleResp(resp);
          }
        }
        
        else {
          self.handleErr(resp);
        }
      }
    }
    req.send(this.dataPayload);
  };
  this.abort = function() {
    if (this.req) {
      this.req.onreadystatechange = function() { };
      this.req.abort();
      this.req = null;
    }
  };
  this.handleErr = function() {
    var errorWin;
    // Create new window and display error
    try {
      errorWin = window.open('', 'errorWin');
      errorWin.document.body.innerHTML = this.responseText;
    }
    // If pop-up gets blocked, inform user
    catch(e) {
      alert('An error occurred, but the error message cannot be' +
      ' displayed because of your browser\'s pop-up blocker.\n' +
      'Please allow pop-ups from this Web site.');
    }
  };
  this.setMimeType = function(mimeType) {
    this.mimeType = mimeType;
  };
  this.setHandlerResp = function(funcRef) {
    this.handleResp = funcRef;
  };
  this.setHandlerErr = function(funcRef) {
    this.handleErr = funcRef; 
  };
  this.setHandlerBoth = function(funcRef) {
    this.handleResp = funcRef;
    this.handleErr = funcRef;
  };
  this.setRequestHeader = function(headerName, headerValue) {
    this.headers.push(headerName + ': ' + headerValue);
  };
}


//Arrodonir X a N decimals amb suport a positius i negatius i notació exponencial.
//Extret de http://www.merlyn.demon.co.uk/js-round.htm
//Modificada perque si es demanen 0 decimals no es vegi el punt.
function OKStrOfNe(X, N) 
{ 
	if (N==0)
		return Math.round(X);
	var Q = ''+Math.round(X*Number("1e"+N))
	while (Q.length<=N) Q='0'+Q
	with (new String(Q)) 
	{
		if (search(/e/)!=-1) { return X-0 }
		return substring(0,length-N)+'.'+substring(length-N,length) 
	} 
}

//Aquesta funció no és a la llibrerira matemàtica.
function sinh(z)
{
    with (Math)
	return (exp(z)-exp(-z))/2;
}

function ArrodoneixSiSoroll(n)
{ 
var e, d;

    with(Math)
    {
	e=floor(log(n)/LN10);    //dona l'exponent en base 10
	d=n/pow(10,e);
	if (parseFloat(OKStrOfNe(d, 4))==parseFloat(OKStrOfNe(d, 12)))
		return OKStrOfNe(d, 4)*pow(10,e);
	else
		return n;
    }
}

/*Aquesta funció retorna un número positiu arrodonit per sota a una
sola xifra significativa que només pot ser 1, 2 o 5. Joan Masó*/
function DonaNumeroArrodonit125(a)
{
    with(Math)
    {
	if (a<1e-20)
		return a;
	var e=floor(log(a)/LN10);    //dona l'exponent en base 10
	var n=abs(a/pow(10,e));
	
	//Ara cal arrodinir a l'enter més proper:
	if (n<2)
		n=1;
	else if (n<5)
		n=2;
	else
		n=5;
	return n*pow(10,e);
    }
}

function DonaDenominadorDeLEscalaArrodonit(a)
{
    with(Math)
    {
	if (a<1e-20)
		return a;
	var e=floor(log(a)/LN10);    //dona l'exponent en base 10
        if (e<2)
		return a;
	e-=2;
	var n=abs(a/pow(10,e));
	
	//Ara cal arrodinir a l'enter més proper:
	if (n<112)
		n=100;
	else if (n<137)
		n=125;
	else if (n<165)
		n=150;
	else if (n<187)
		n=175;
	else if (n<212)
		n=200;
	else if (n<275)
		n=250;
	else if (n<325)
		n=300;
	else if (n<375)
		n=350;
	else if (n<450)
		n=400;
	else if (n<550)
		n=500;
	else if (n<675)
		n=600;
	else if (n<775)
		n=750;
	else if (n<900)
		n=800;
	else
		n=1000;
	return n*pow(10,e);
    }
}


function RGB(r,g,b)
{
    if (r<0 || r>255 || g<0 || g>255 || b<0 || b>255)
	alert(DonaCadena3(("Índex de color incorrecte: " + r + "," + g + "," + b +". Els índexs de color han d\'anar de 0 a 255."),
		("Índice de color incorrecto: " + r + "," + g + "," + b +". Los índices de color deberian ir entre 0 i 255."),
		("Wrong color index: " + r + "," + g + "," + b +". Color indices has to be between 0 and 255.")));
   
    return "#" + (r.toString(16).length==1 ? "0"+r.toString(16) : r.toString(16))
		+ (g.toString(16).length==1 ? "0"+g.toString(16) : g.toString(16))
		+ (b.toString(16).length==1 ? "0"+b.toString(16) : b.toString(16));
}

function DonaCaracterHexaMultiple3(s)
{
	if (s=='1')
		return '0';
	if (s=='2' || s=='4')
		return '3';
	if (s=='5' || s=='7')
		return '6';
	if (s=='8' || s=='a' || s=='A')
		return '9';
	if (s=='b' || s=='B' || s=='C' || s=='d' || s=='D')
		return 'c';
	if (s=='e' || s=='E' || s=='F')
		return 'f';
	return s;
}

function DonaFitxerColor(c)
{
	//Arrodoneix el valor del color
	s=new String(c)	
	if (s.toLowerCase()=="#e6f2ff")
		s="colors/c"+s.substring(1,7)+".gif";	
	else
	{
		if (s.charAt(0)=='#')
			s="colors/c"+DonaCaracterHexaMultiple3(s.substring(1,2))+DonaCaracterHexaMultiple3(s.charAt(1))+DonaCaracterHexaMultiple3(s.substring(3,4))+DonaCaracterHexaMultiple3(s.charAt(3))+DonaCaracterHexaMultiple3(s.substring(5,6))+DonaCaracterHexaMultiple3(s.charAt(5))+".gif";
	}
	return s;
}

function DonaCadenaAmbCometesBarra(cadena)
{
	s=new String(cadena);
	for (var i=0; i<s.length; i++)
	{
		if (s.charAt(i)=='\'')
		{
			s=s.substring(0,i)+"\\\'"+s.substring(i+1,s.length);
			i++;
		}
		if (s.charAt(i)=='\"')
		{
			s=s.substring(0,i)+"\\\""+s.substring(i+1,s.length);
			i++;
		}
	}
	return s;
}

//Després de intentar fer servir l'objecte link() sense exit he hagut de fer això.
function DonaHost(s)
{
	if (-1!=s.indexOf("//"))
	{
		s2=s.substring(s.indexOf("//")+2,s.length);
		if (-1!=s2.indexOf("/"))
			return s2.substring(0,s2.indexOf("/"));
		else
			return s2;
	}
	else
	{
		if (-1!=s.indexOf("/"))
			return s.substring(0,s.indexOf("/"));
		else
			return s;
	}
}

//Extret de: http://www.xs4all.nl/~ppk/js/detect.html

function checkIt(detect, string)
{
	var place = detect.indexOf(string) + 1;
	//thestring = string;
	return place;
}

var NecessariLayerIFrame=false;

function FesTestDeNavegador()
{
    if (!document.getElementById)
    {
		alert("Aquest navegador és massa antic i no suporta la funció javascript document.getElementById() pel que no funcionarà correctament. Actualitzeu-vos.\n" +
			"Este navegador es demassiado antiguo y no suporta la función javascript document.getElementById() por lo que no funcionará correctamente. Actualicese.\n" + 
			"This browser is too old and do not supports the javascript function document.getElementById(). It will not work properly. Please upgrade it.\n");
    }

    var detect = navigator.userAgent.toLowerCase();
    var OS,browser,thestring;
    var version = 0;

	//NJ a JM: Caldria comprovar alguna cosa del Google Chrome?
	if (checkIt(detect, 'konqueror'))
    {
		browser = "Konqueror";
		OS = "Linux";
		thestring='konqueror';
    }
    else if (checkIt(detect, 'safari'))
    {
		browser = "Safari"; 
		thestring='safari';
    }
    else if (checkIt(detect, 'omniweb')) 
    {
		browser = "OmniWeb";
		thestring='omniweb';
    }
    else if (checkIt(detect, 'opera')) 
    {
		browser = "Opera";
		thestring='opera';
    }
    else if (checkIt(detect, 'webtv'))
    {
		browser = "WebTV";
		thestring='webtv';
    }
    else if (checkIt(detect, 'icab'))
    {
		browser = "iCab"
		thestring='icab';
    }
    else if (checkIt(detect, 'msie'))
    {
		browser = "Internet Explorer"
		thestring='msie';
    }
    else if (!checkIt(detect, 'compatible'))
    {
		browser = "Netscape Navigator"
		version = detect.charAt(8);
		thestring='compatible';
    }
    else
    { 
		browser = "An unknown browser";
    }

    if (!version) 
		version = detect.charAt(detect.indexOf(thestring) + 1 + thestring.length);

    if (!OS)
    {
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
    }

    //Diverses precaucions sobre la versió dels navegadors:
    if (browser=="Internet Explorer")
    {
		if (version<5)
		{
			alert("S'ha detectat una versió " + version + " de " + browser + ". Aquest navegador de mapes necessita una versió 5 o posterior per a funcionar correctament.\n" +
				"Se ha detectado una versión " + version + " de " + browser + ". Este navegador de mapas necesita una versión 5 o posterior para funcionar correctamente.\n" + 
				"A version " + version + " of " + browser + " has been detected. This map browser need a version 5 o greater to work properly.");
				parent.history.back();
		}
		var appVer = navigator.appVersion.toLowerCase(); 
		var iePos = appVer.indexOf('msie'); 
		if (iePos !=-1) 
		{
			var is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos))); 
			var is_major = parseInt(is_minor,10); 
		} 
		if (navigator.appName.substring(0,9) == "Microsoft" && is_major <= 6)
			NecessariLayerIFrame=true;
    }
    else if (browser=="Netscape Navigator")
    {
		if (version<5)
		{
			alert("S'ha detectat una versió " + version + " de " + browser + ". Aquest navegador de mapes necessita una versió 5 o posterior per a funcionar correctament (es recomana la versió 7).\n" +
				"Se ha detectado una versión " + version + " de " + browser + ". Este navegador de mapas necesita una versión 5 o posterior para funcionar correctamente (se recomienda la versión 7).\n" + 
				"A version " + version + " of " + browser + " has been detected. This map browser need a version 5 o greater to work properly (version 7 is recomended).");
				parent.history.go(-2);
		}
    }
    else if (browser=="Opera")
    {
		if (version<7)
		{
			alert("S'ha detectat una versió " + version + " de " + browser + ". Actualment, no hi ha cap versió de Opera que funcioni correctament amb aquest navegador de mapes, malgrat que la versió 7 gairebé resulta compatible.\n" +
				"Se ha detectado una versión " + version + " de " + browser + ". Actualmente, no existe ninguna versión de Opera que funcione correctamente con este navegador de mapas, aunque la versión 7 casi resulta compatible.\n" +
				"A version " + version + " of " + browser + " has been detected. Today, there is not any version of Opera that works properly with this map browser. Versió 7 is almost compatible.");
				parent.history.back();
		}
		else if (version==7)
		{
			alert("S'ha detectat una versió " + version + " de " + browser + ". El funcionament d'aquest navegador de mapes és pobre en aquesta versió. Es deixa continuar amb finalitats experimentals.\n" +
				"Se ha detectado una versión " + version + " de " + browser + ". El funcionamiento de esta navegador de mapas es pobre en esta versión. Se deja continuar con finalidades experimentales.\n" +
				"A version " + version + " of " + browser + " has been detected. El performance of this map browser is poor on this version. It is allowed to continue with experimental proposes.");
		}
    }
    else if (version<5)
    {
		alert("S'ha detectat la versió " + version + " del navegador " + browser + ". Aquest navegador no ha estat testat i la versió indicada és inferior a la 5. Es deixa continuar però no garantim el funcionament correcte d'aquest navegador de mapes.\n" +
			"Se ha detectado la versión " + version + " del navegador " + browser + ". Este navegador no ha sido testeado y la versión indicada es inferior a la 5. Es deja continuar pero no se garantiza el funcionamento correcto de este navegador de mapas.\n" +
			"Version " + version + " of the browser " + browser + " has been detected. This browser has not been tested and the indicated version is lower than 5. It is allowed to continue but we cannot guaranty a correct performance of this map browser.");
    }
}

FesTestDeNavegador();

/////////////////////////////////////////////
/*Definició de les clases propies del Navegador de Mapes de MiraMon*/

function CadenaMultiIdioma(cat,spa,eng)
{
    this.cat=cat;
    this.spa=spa;
    this.eng=eng;
}

var PrepMesDeLAny=new Array(new CadenaMultiIdioma("de gener", "de enero", "January"), 
			new CadenaMultiIdioma("de febrer", "de febrero", "February"), 
			new CadenaMultiIdioma("de març", "de marzo", "March"), 
			new CadenaMultiIdioma("d\'abril", "de abril", "April"), 
			new CadenaMultiIdioma("de maig", "de mayo", "May"), 
			new CadenaMultiIdioma("de juny", "de junio", "June"), 
			new CadenaMultiIdioma("de juliol", "de julio", "July"), 
			new CadenaMultiIdioma("d\'agost", "de agosto", "August"), 
			new CadenaMultiIdioma("de setembre", "de setiembre", "September"),
			new CadenaMultiIdioma("d\'octubre", "de octubre", "Octuber"),
			new CadenaMultiIdioma("de novembre", "de noviembre", "November"), 
			new CadenaMultiIdioma("de desembre", "de diciembre", "Desember"));

var MesDeLAny=new Array(new CadenaMultiIdioma("Gener", "Enero", "January"), 
			new CadenaMultiIdioma("Febrer", "Febrero", "February"), 
			new CadenaMultiIdioma("Març", "Marzo", "March"), 
			new CadenaMultiIdioma("Abril", "Abril", "April"), 
			new CadenaMultiIdioma("Maig", "Mayo", "May"), 
			new CadenaMultiIdioma("Juny", "Junio", "June"), 
			new CadenaMultiIdioma("Juliol", "Julio", "July"), 
			new CadenaMultiIdioma("Agost", "Agosto", "August"), 
			new CadenaMultiIdioma("Setembre", "Setiembre", "September"),
			new CadenaMultiIdioma("Octubre", "Octubre", "Octuber"),
			new CadenaMultiIdioma("Novembre", "Noviembre", "November"), 
			new CadenaMultiIdioma("Desembre", "Diciembre", "Desember"));

function takeYear(theDate) 
{
	//tret de http://www.quirksmode.org/js/introdate.html
	var x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}
function CreaExtent(minx, maxx, miny, maxy)
{
	this.MinX=minx;
	this.MaxX=maxx;
	this.MinY=miny;
	this.MaxY=maxy;
}

function CreaExtentCRS(env_crs, crs)
{
	this.EnvCRS=env_crs;
	this.CRS=crs;
}

function CreaPunt2D(x,y)
{
	this.x=x;
	this.y=y;
}

function CreaZoomPrevi(costat, punt_ori, i_situa)
{
	this.costat=costat;
	this.PuntOri=punt_ori;
	this.ISituacio=i_situa;
}

//Valors per a CoordExtermes i CoordActual
var proj=0x01;
var longlat_g=0x02;
var longlat_gms=0x04;

//Valors de TipusBarraBotons
var boto_mes=0x02;
var boto_menys=0x04;
var boto_back=0x08;
var boto_vgeneral=0x10;
var botons_alternatius=0x100;
var boto_moumig=0x200;
var boto_caixa_param=0x1000;
var boto_print=0x2000;
var boto_plana_principal=0x4000;
var boto_ajuda=0x8000;
var boto_installar_mmz=0x10000;
var boto_idiomes=0x20000;
var boto_anar_coord=0x40000;
var boto_consola=0x80000;
var boto_enllac=0x100000;
var boto_inserta=0x200000;  //Si botó posso el botó encara que no hi hagi capa ObjDigi editable --> vol dir que en vull un de volàtil
var boto_enllacWMS=0x400000;
var boto_altres_links=0x800000;  //Si volem possar un botó que enllaci cap alguna altre web o faci alguna funcionalitat personalitzada
var boto_afegeixCapa=0x1000000;  //Si volem possar un botó que permeti obrir una finestra per solicitar les capacitats i afegir una capa d'un altre servidor
var boto_ctipica=0x2000000;

//La barra completa no conté el botó consola, boto_enllac, boto_inserta, boto_enllacWMS, boto_altres_links, boto_afegeixCapa, boto_ctipica;
var completa=boto_mes|boto_menys|boto_back|boto_vgeneral|botons_alternatius|boto_moumig|boto_caixa_param|boto_print|boto_plana_principal|boto_installar_mmz|boto_ajuda|boto_idiomes|boto_anar_coord;
var nomes_descarrega=0x01;  //Usar sol.

//Valors de TipusLlistatNivellZoom
var z_no_llista=0x00;
var z_fraccio=0x01;
var z_mida_pixel=0x02;
var z_escala_aprox=0x04;

//Valors de FlagsLlegenda
var amaga_segons_escala=0x01;
var gris_segons_escala=0x02;
var icones_inactives_grises=0x04;
var grups_com_a_radials=0x08;
var lliga_visible_amb_ctipica=0x10;
var amaga_separa_no_capa=0x20;
var amaga_si_fora_ambit=0x40;
var gris_si_fora_ambit=0x80;
var lliga_visible_amb_descarregable=0x100;

//Valors de FlagsData
var mostra_tot=mostra_any|mostra_mes|mostra_dia|mostra_hora|mostra_minut|mostra_segon;
var mostra_any=0x01; 
var mostra_mes=0x02;
var mostra_dia=0x04;
var mostra_hora=0x08;
var mostra_minut=0x10;
var mostra_segon=0x20;
var mostra_desc_llegenda=0x100;

//Valors de flags generals
var zoom_continu=0x01;
var consultable_segons_escala=0x02;
var desplegable_proj=0x04;
var canvi_proj_auto=0x08;
var zoom_un_sol_clic=0x10;
var usa_sempre_meu_servidor=0x20;
var amaga_barra_escala=0x40;
var relaxa_ambit_visualitzacio=0x80;  //Relaxo les limitacions d'àmbit de navegació per poder-me sortir del mapa de situació

//Valors de FlagsConsultaLoc
var consul_finestra_seguent_capa=0x01;
var consul_finestra_de_cop=0x02;
var consul_incrus_de_cop=0x04;
//var consulta_de_cop=0x10;  No usat. S'usa ParamCtrl.PlantillaConsulta en el seu lloc. 
//També recordeu que si hi ha un frame de nom consulta_info, la consulta es mostra directament a la plana del portal.


//Valors de EstatClickSobreVista
var estat_click_conloc=0; //consulta per localització
var estat_click_moumig=1; //centra la vista
var estat_click_zrec_1=2; //primer clic de zoom de rectangle
var estat_click_zrec_2=3; //segon clic de zoom de rectangle. Intern No useu
var estat_click_pan_1=4;  //primer clic de pan
var estat_click_pan_2=5;  //segon clic de pan. Intern No useu
var estat_click_editar_punts=6;  //mode edició de punts

function CreaImatgeDeSituacio(env_total, nom, ample, alt, marge_esq, marge_sup)
{   
	this.EnvTotal=env_total;
	this.nom=nom;
	this.Ample=ample;
	this.Alt=alt;
	this.MargeEsq=marge_esq;
	this.MargeSup=marge_sup;
}

function CreaAspecteLlegenda(capcalera_llegenda, peu_llegenda, previ_separa, post_separa, previ_desc_llegenda, post_desc_llegenda, previ_desc_llegenda_gris, post_desc_llegenda_gris, previ_desc_estil, post_desc_estil, previ_desc_items, post_desc_items, previ_desc_color, post_desc_color)
{
	this.CapcaleraLlegenda=capcalera_llegenda;
	this.PeuLlegenda=peu_llegenda;
	this.PreviSepara=previ_separa;
	this.PostSepara=post_separa;
	this.PreviDescLlegenda=previ_desc_llegenda;
	this.PostDescLlegenda=post_desc_llegenda;
	this.PreviDescLlegendaGris=previ_desc_llegenda_gris;
	this.PostDescLlegendaGris=post_desc_llegenda_gris;
	this.PreviDescEstil=previ_desc_estil;
	this.PostDescEstil=post_desc_estil;
	this.PreviDescItems=previ_desc_items;
	this.PostDescItems=post_desc_items;
	this.PreviDescColor=previ_desc_color;
	this.PostDescColor=post_desc_color;
}

//Valors de TipusConsultaTipica. De moment els valos són excloents.
var ctipica_completa=0x01;  
var ctipica_desplegables=0x02;  //Abans nomes_sobre_capa
var ctipica_inicials=0x04;
var ctipica_cercador=0x08;

function CreaParamFinestraConsultaTipica(nom, tipus_consulta_tipica,nom_capa)
{
	this.nom=nom;  //Nom de la finestra
	this.TipusConsultaTipica=tipus_consulta_tipica;     //Estats: ctipica_desplegables, ctipica_inicials, ctipica_cercador, ctipica_completa
	this.NomCapa=nom_capa;  //Array de noms de capa de consulta típica implicats en aquesta finestra o null per totes
}

function CreaDocumentPlantilla(nom, desc, src, ample, alt)
{   
	this.nom = nom;
	this.desc = desc;
	this.src = src;
	this.ample = ample;
	this.alt = alt;
}

function CreaIcona(icona, ncol, nfil, i, j)
{
	this.icona=icona;    //nom del fitxer que fa d'icona (Generalment un GIF o PNG).
	this.ncol = ncol;    //nombre de columnes de la icona
	this.nfil = nfil;    //nombre de filess de la icona
	this.i=i;            //punt calent en l'eix de columnes
	this.j=j;            //punt calent en l'eix de files
}

function CreaAltresLinks(boto, text_boto, funcio)
{
	this.boto=boto;
	this.text_boto=text_boto;
	this.funcio=funcio;
}

function CreaTitolNavegador(nom_layer, text_titol)
{
	this.layer=nom_layer;
	this.text=text_titol;  //multidiomàtic
}

function CreaParametresDeControl(idiomes, idioma, plana_principal, titol_navegador, titol, titol_caixa, ncol, nfil, ncolnfil_auto, psalt, marge_esq_vista, marge_sup_vista, color_fons_vista, color_quadrat_situacio, color_fons_plana, titol_coord, n_decimals_coord_xy, coord_extremes, coord_actual, nivell_zoom_costat, flags, imatge_situacio, ample_alt_situacio_auto, i_situacio_ori, punt_ori, aspecte_llegenda, aspecte_llegenda_impressio, flags_llegenda, ctipica, tipus_barra_botons, altres_links, titol_llnivell_zoom, tipus_llnivell_zoom, estat_click_sobre_vista, tipus_consulta, icona_consulta, plantilla_consulta, icona_anar_coord, icona_edicio, funcio_edicio, funcio_canvi_prj, temps_refresc, descarreges_certificades)
{   
	this.idiomes=idiomes;                   //Idiomes dels textos i l'ordre. És un array amb els valors "cat", "spa" ,"eng".
	this.idioma=idioma;                     //Idioma per defecte del textos "cat", "spa" ,"eng"
	this.PlanaPrincipal = plana_principal;   //Plana de que crida a aquesta per tal de poder tornar
	this.TitolNavegador= titol_navegador;   // new CreaTitolNavegador(nom_finestra, text_multidiomatic)
	this.titol = titol;                 //Titol de les caixes filles
	this.TitolCaixa = titol_caixa;  //Titol de les caixes filles
	this.ncol = ncol;
	this.nfil = nfil;
	this.NColNFilAuto = ncolnfil_auto;
	this.psalt= psalt;
	this.MargeEsqVista=marge_esq_vista;
	this.MargeSupVista=marge_sup_vista;
	this.ColorFonsVista=color_fons_vista;
	this.ColorQuadratSituacio=color_quadrat_situacio;
	this.ColorFonsPlana=color_fons_plana;
	this.TitolCoord=titol_coord;
	this.NDecimalsCoordXY=n_decimals_coord_xy;
	this.CoordExtermes=coord_extremes;  //Estats: no|proj|longlat_g, proj|longlat_gms
	this.CoordActual=coord_actual;      //Estats: proj|longlat_g|longlat_gms		
	this.NivellZoomCostat=nivell_zoom_costat;
	this.flags=flags; 
	this.ImatgeSituacio=imatge_situacio;
	this.AmpleAltSituacioAuto = ample_alt_situacio_auto;
	this.ISituacioOri = i_situacio_ori;
	this.PuntOri = punt_ori;        //Punt central d'on s'inicia la vista
	this.AspecteLlegenda = aspecte_llegenda; 
	this.AspecteLlegendaImpressio = aspecte_llegenda_impressio;
	this.FlagsLlegenda=flags_llegenda;
	this.ConsultaTipica=ctipica;                        //Array de new CreaParamFinestraConsultaTipica()
	this.TipusBarraBotons=tipus_barra_botons;
	this.AltresLinks=altres_links;  // és un objecte de tipus new CreaAltresLinks(boto, text_boto, funcio)
	this.TitolLlistatNivellZoom=titol_llnivell_zoom;
	this.TipusLlistatNivellZoom=tipus_llnivell_zoom;
	this.EstatClickSobreVista=estat_click_sobre_vista;
	this.TipusConsulta=tipus_consulta;
	this.IconaConsulta=icona_consulta;
	this.PlantillaConsulta=plantilla_consulta;          //new CreaDocumentPlantilla();
	this.IconaAnarCoord=icona_anar_coord;
	this.IconaEdicio=icona_edicio;
	this.FuncioIconaEdicio=funcio_edicio;  //Que s'ha de fer quan l'usuari prem el botó d'edició per editar un punt volàtil
	this.FuncioCanviProjeccio=funcio_canvi_prj;
	this.TempsRefresc=temps_refresc;
	this.DescarregesCertificades=descarreges_certificades;
}

var ara_canvi_proj_auto=0x01;

var OrigenEsqSituacio=0;
var OrigenSupSituacio=0;

var MidaDePixelPantalla=0.28;  //Mida del píxel de pantalla en metres. Això es podria tenir com un paràmetre igual que en MiraMon

function CreaParametresVistaCapaTiled(tile_matrix, i_tileMin, i_tileMax, j_tileMin, j_tileMax, dx, dy)
{
	this.TileMatrix=tile_matrix;
	this.ITileMin=i_tileMin;
	this.ITileMax=i_tileMax;
	this.JTileMin=j_tileMin;
	this.JTileMax=j_tileMax;
	this.dx=dx; 
	this.dy=dy;
}

function CreaParametresInternsDeControl(env_actual, env_capa, env_ll_situacio, ample_situacio, alt_situacio, marge_esq_situacio, marge_sup_situacio, i_situacio, costat_zoom_actual, zoom_previ, n_zoom_previ_usat, punt_ori, vista, flags)
{
	this.EnvActual=env_actual;
	this.EnvLLCapa=env_capa; 
	this.EnvLLSituacio=env_ll_situacio;
	this.AmpleSituacio=ample_situacio;
	this.AltSituacio=alt_situacio;
	this.MargeEsqSituacio=marge_esq_situacio;
	this.MargeSupSituacio=marge_sup_situacio;
	this.ISituacio=i_situacio;
	this.CostatZoomActual = costat_zoom_actual;
	this.ZoomPrevi = zoom_previ;
	this.NZoomPreviUsat = n_zoom_previ_usat;
	this.PuntOri=punt_ori;   //Punt del angle inferior esquerra on està actualment la vista
	this.Vista=vista;  //De moment només útil pel cas tiled
	this.flags=flags;
}

//Es podria eliminar CreaItemLleg i usar CreaNomIDescripcio que és més genèrica.
function CreaItemLleg(color, desc_color)
{
	this.color = color;    //Color amb notació HTML o nom de fitxer simbol
	this.DescColor = desc_color;
}
function CreaItemVis(i_camp, icona)
{
	this.i_camp = i_camp;
	this.icona = icona;
}


function CreaEstil(nom, desc, desc_items, tipus_obj, metadades, item_lleg, ncol)
{
	this.nom=nom;
	this.desc=desc;
	this.DescItems=desc_items;
	this.TipusObj=tipus_obj;
	this.metadades=metadades;
	this.ItemLleg=item_lleg;
	this.ncol=ncol;	
}

function CreaEstilCapaDigi(nom, desc, desc_items, simbol, simbol_sel, item_lleg, ncol, camp_index)
{
	this.nom=nom;
	this.desc=desc;
	this.DescItems=desc_items;
	this.simbol=simbol;   //new Array(new CreaItemVis(i_camp, new CreaIcona()))
	this.simbol_sel=simbol_sel;  //new Array(new CreaItemVis(i_camp, new CreaIcona()))
	this.ItemLleg=item_lleg;  //Array de new CreaItemLleg()
	this.ncol=ncol;
	this.NomCamp=camp_index;
}

function CreaNomILlista(nom, ll)
{
	this.nom=nom;
	this.ll=ll;
}

function CreaNomURLTemplateILlista(nom, crs, url_template, ll)
{
	this.nom=nom;
	this.CRS=crs;
	this.URLTemplate=url_template;  //Només si TipusWMTS_REST
	this.ll=ll;
}

function CreaNomIDescripcio(nom, desc)
{
    this.nom=nom;
    this.desc=desc;
}

function CreaNomIDescripcioSel(nom, desc, sel)
{
    this.nom=nom;
    this.desc=desc;
    this.sel=sel;
}

function CreaIntervalValorsDescripciosSel(v1, desc1, v2, desc2, sel)
{
	this.v1=v1;
	this.desc1=desc1;
	this.v2=v2;
	this.desc2=desc2;
	this.sel=sel;
}

function CreaParGetCoverage(nom, cardin, valors)
{ 
    this.nom=nom; 
    this.cardin=cardin; 
    this.valors=valors;
}

//Valors de flags_valor de CreaParProces
var valor_editable=0x01; //vol dir que l'usuari pot indicar un valor per al paràmetre 
var valor_predefinit=0x02;  //és una llista de valors predefinits en l'estructura CreaParProces que no es poden editar
var valor_editable_i_predefinit=valor_editable|valor_predefinit;  
var valor_capa_wps=0x04; //vol dir que és un valor predefinit que prove del membre capa_wps de l'estructura capa

//Valors de flags_tipus de CreaParProces
//alguns tipus necessiten un tractament especial
var tipus_referencia=0x01;  //El valor es passa per referència
var tipus_referencia_fitxer=0x02;  //És un fitxer que es passa per referència però que previament s'enviarà al servidor
//més endavant hi podria haver tipus_dada_fitxer que s'enviaria directament al fer la petició en gml
var tipus_dada=0x04;  //Es un valor que s'envia directament


function CreaParProces(nom, valors, flags_valor, flags_tipus,format)
{ 
    this.nom=nom; //new CreaNomIDescripcio
    this.valors=valors;  //new Array de CreaNomIDescripcioSel() si hi ha valors predefinits o null si no n'hi ha
	this.flags_valor=flags_valor;
	this.flags_tipus=flags_tipus;
	this.formats=format; //new Array("mmz","gml")  Array de les extensions del fitxers sense el punt permesos si el paràmetre és de tipus fitxer. Si
	//és de tipus fitxer i format és null vol dir que admet qualsevol extensió
}

function CreaOperacio(url, versio, id_i_desc, param_input, param_output)
{
	this.servidor=url;  //url del servei de processos
	this.versio=versio;  //new CreaVersio	
	this.id_operacio=id_i_desc; //new CreaNomIDescripcio
	this.par_input=param_input;  //new Array de CreaParProces
	this.par_output=param_output;  //new Array de CreaParProces
}

function CreaProces(operacio, capa_wps)
{
	this.operacio=operacio;  //new CreaOperacio(), només un no pot ser un array
	this.capa_wps=capa_wps;  //fitxer o url de la capa que s'està visualitzant accessible pel servidor de processos que executarà la operació
}

function CreaVersio(vers, sub_vers, variant_vers)
{ 
    this.Vers=vers;
    this.SubVers=sub_vers;
    this.VariantVers=variant_vers;
}

function CreaTileMatrix(identifier, costat, topLeftPoint, tileWidth, tileHeight, matrixWidth, matrixHeight)
{
    this.Identifier=identifier;
    this.costat=costat;
    this.TopLeftPoint=topLeftPoint;
    this.TileWidth=tileWidth;
    this.TileHeight=tileHeight;
    this.MatrixWidth=matrixWidth;
    this.MatrixHeight=matrixHeight;
}

var no=0x00;
var ara_no=0x01;
var si=0x02;
var semitransparent=0x04;
var multitime=0x08;

var transparent=1;
var opac=3;

//Tipus de capa. Fer uns flags em permet fer-ho servir en altres contextos en una sola variable.
var TipusWMS=       0x0001;
var TipusWMS_C=     0x0002;
var TipusWMTS_REST= 0x0004;
var TipusWMTS_KVP=  0x0008;
var TipusWMTS_SOAP= 0x0010;  //GetTile només funciona amb FireFox, Opera etc però no amb IE 7 o inferiors.
//var TipusGoogle_KVP=0x0020;  //Només funciona si el sistema de referencia és EPSG:3785 (Web Mercator).
var TipusWFS=       0x0100;

function CreaCapa(servidor, versio, tipus, nom, desc, crs, env_total, format_imatge, transparencia, costat_minim, costat_maxim, tileMatrixSet, format_consulta, grup, separa, desc_llegenda, estil, i_estil, ncol_estil, lleg_desplegada, visible_a_la_llegenda, visible, consultable, descarregable, param_coverage, format_coverage, res_coverage, metadades, nom_video, desc_video, flags_data, data, i_data, animable, proces)
{   
	this.ordre=0;
	this.servidor = servidor;
	this.versio = versio;
	this.tipus = tipus;         //Valors possibles TipusWMS, TipusWMS-C,TipusWMTS-REST,TipusWMTS-KVP
	this.nom = nom;
	this.desc = desc;
	this.CRS = crs;             //Array de CRS's disponibles
	this.EnvTotal = env_total;  //Serveix per poder apagar la capa si està fora d'àmbit. Es un únic CreaExtentCRS. Pot ser NULL.

//Visualització
	this.FormatImatge = format_imatge;    //format MIME excepte per wmts-rest que és l'extensió del fitxer sense punt.
	this.transparencia = transparencia;
	this.CostatMinim = costat_minim;
	this.CostatMaxim = costat_maxim;
	this.TileMatrixSet = tileMatrixSet;   //NULL per a wms i és new Array (new CreaNomURLTemplateILlista(nom_tile_matrix_set, CRS, plantilla, new Array(new CreaTileMatrix()))) per a WMTS
//Consulta
	this.FormatConsulta = format_consulta;
//Llegenda
	this.grup = grup;
	this.separa = separa;
	this.DescLlegenda = desc_llegenda;
	this.estil = estil;
	this.i_estil = i_estil;
	this.NColEstil = ncol_estil; 
	this.LlegDesplegada = lleg_desplegada;  //Estats: si, no
	this.VisibleALaLlegenda=visible_a_la_llegenda;
	
	this.visible = visible;           //Estats: si, ara_no, no, semitransparent
	this.consultable = consultable;   //Estats: si, ara_no, no
	this.descarregable = descarregable;   //Estats: si, ara_no, no
	
	this.ParamCoverage=param_coverage;
	this.FormatCoverage=format_coverage;
	this.ResCoverage=res_coverage;

	this.metadades=metadades;

	this.NomVideo=nom_video;
	this.DescVideo=desc_video;
	this.FlagsData=flags_data;   //Estats: mostra_dia, mostra_mes, mostra_any, mostra_desc_llegenda
	this.data=data;                //Array de Date
	this.i_data=i_data;          //Index inicial del array en la visualització.
	this.animable=animable;  //Estats: si, ara_no, sobrecarregat o no amb multitime
	this.proces=proces; //Punter a un array de creaProces
}
//usat per consultes per localització en ajax
function CreaAtribut(nom, descripcio, valor, unitats, esNODATA, separador, esLink, esImatge)
{
	this.nom=nom;
	this.descripcio=descripcio;
	this.valor=valor;
	this.unitats=unitats;
	this.esNODATA=esNODATA;
	this.separador=separador;
	this.esLink=esLink;
	this.esImatge=esImatge;
}//Fi de CreaAtribut()

function CreaAtributObjecteDigi(nom, descripcio, valor, unitats, separador, esLink, esImatge, mostrar)
{
	this.nom=nom;
	this.descripcio=descripcio;
	this.valor=valor;
	this.unitats=unitats;
	this.separador=separador;
	this.esLink=esLink;
	this.esImatge=esImatge;
	this.mostrar=mostrar;
}//Fi de CreaAtributObjecteDigi()

function CreaFeature(id, data, i_simbol, punt, atributs, seleccionat)
{
	this.identificador=id;
	this.data=data;
	this.i_simbol=i_simbol;
	this.punt=punt; //Array de CreaPunt2D, si els objectes són de tipus punt només n'hi haurà 1
	this.puntCRSactual=null; //Array de CreaPunt2D igual que punt però en el CRS actual de navegació. si CRS capa i crsnavegació són iguals aquests contingut no és vàlid
	this.atributs=atributs; //Array de CreaAtributObjecteDigi()
	this.seleccionat=seleccionat; //si 0 o false: no_seleccionat; 1 o true: seleccionat 
}
var tile_no_solicitat=0;
var tile_solicitat=1;
var tile_rebut=2;

function CreaObjecteDigitalitzat(servidor,versio,nom,desc,crs,i_situacio,tipus_obj,n_cols,n_files,objecte,estil,i_estil, ncol_estil, costat_minim,costat_maxim,separa,desc_llegenda,lleg_desplegada, visible_a_la_llegenda,visible,consultable,editable, funcio_edicio, metadades)
{
	this.namespace=null;
	this.servidor = servidor;  //Si servidor és null, és un objecte digitalitzat i sinó wfs/gml
	this.versio = versio;
	this.nom = nom;
	this.desc = desc; //Descripció de la capa. És el títol que s'usa per les consutles per localització
	this.CRS = crs;   //CRS en el que estan els objectes de la capa
	
	//divisió de tiles (només si hi ha servidor)
	this.i_situacio=i_situacio;
	//Això no forma part de la divisió de talls
	this.TipusObj=tipus_obj;  //Només diponible per 'S'(simbols-punts) però en un futur es suportaran 'L'(línies) o 'P'(polígons).
	this.n_cols_tiles=n_cols;
	this.n_files_tiles=n_files;
	this.tiles_solicitats=null;  //array de boolens, n'hi haurà tants com n_colsxn_files
//Objectes
	this.objecte=objecte;    //Array de CreaFeature() de la CapaDigitalitzada
//Visualització
	this.estil = estil;      //Array de new CreaEstilCapaDigi()
	this.i_estil = i_estil;
	this.NColEstil = ncol_estil; 
	
	this.CostatMinim = costat_minim;  //Costats mínim i màxim als que és visible.
	this.CostatMaxim = costat_maxim;
//Llegenda
	this.separa = separa;   //Text de separa anterior al punt
	this.DescLlegenda = desc_llegenda;  //Text descriptiu a la llegenda.
	this.LlegDesplegada = lleg_desplegada;  //Estats: si, no
	this.VisibleALaLlegenda=visible_a_la_llegenda;  //true o false
	
	this.visible = visible;           //Estats: si, ara_no, no (encara que no no te massa sentit)
	this.consultable = consultable;   //Estats: si, ara_no, no (per consultar el punt)
	this.editable = editable;   //Estats: si, ara_no, no
	this.FuncioEdicio=funcio_edicio; //Que s'ha de fer si la capa és la seleccionada per la edició
	this.metadades=metadades;
}


function CreaZoom(costat)
{
	this.costat=costat;
}

function CreaItemIdentificadorConsultaTipica(index,valor_id)
{
	this.index=index;
	this.id=valor_id;
}

function CreaItemProjeccioConsultaTipica(valor,env)
{
	this.valor=valor;
	this.env=env;
}

/*function CreaCapaConsulta(nom, desc, camp, proj_camp)
{
        this.nom=nom;
	this.desc=desc;
	this.camp=camp;
	this.proj_camp=proj_camp;
}
capa_consulta=new Array();
*/

function CreaCampConsultaTipica(previ, nom, desc, post)
{
    this.previ=previ;
    this.nom=nom;
    this.desc=desc;
    this.post=post;
}

function CreaCapaPreguntaServidorConsultaTipica(servidor, nom, camps, crs)
{   
	this.servidor=servidor;
	this.nom=nom;
	this.camps=camps;  //Array de CreaCampConsultaTipica: noms,descripcions de camps i textos anteriors i posterios, ordenats en funció de com estan continguts  1er Municipis - 2on Provincies
	this.CRS=crs;
}

function CreaConsultaTipicaIntern(servidor, nom, camps, crs, proj_camp, id_camp)
{
	this.servidor=servidor;
	this.nom=nom;
	this.camps=camps;  //Array de CreaCampConsultaTipica:noms, descripcions de camps i textos anteriors i posterios, ordenats en funció de com estan continguts  1er Municipis - 2on Provincies
	this.CRS=crs;
	this.proj_camp=proj_camp;  //Array de les projeccions de cada camp
	this.id_camp=id_camp; //Array de les taules de identificadors que relacionen els diferents camps
}

var IPlantillaDImpressio=0;

var CalImprimirTitol=0x0001;
var CalImprimirVista=0x0002;
var CalImprimirSituacio=0x0004;
var CalImprimirLlegenda=0x0008;
var CalImprimirEscala=0x0010;
var RespectarResolucioVistaImprimir=0x0020;  //Per contraposició a respectar àmbit.
//var CalImprimirCoordProj=0x0040;
//var CalImprimirCoordLongLatG=0x0080;
//var CalImprimirCoordLongLatGMS=0x0100;

function CreaPlantillaDImpressioLayerPropiaIntern(visible, rect, contingut, i_layer)
{
	this.visible = visible;
	this.rect = rect;
	this.contingut = contingut;
	this.ILayer = i_layer;
}

function IniciaLayerPropiaPlantillaDImpressio(i_plantilla, i_layer_propia,
						visible,
						rect_esq, rect_sup, rect_ample, rect_alt,
						contingut,
						i_layer)
{
	plantilla_dimpressio_intern[i_plantilla].LayersPropies[i_layer_propia] = 
					new CreaPlantillaDImpressioLayerPropiaIntern(visible,
						new CreaRectangle(rect_esq,rect_sup,rect_ample,rect_alt),
						contingut,
						i_layer);
}

function CreaPlantillaDImpressioIntern(cal_imprimir, rect_titol, rect_vista, rect_situacio, rect_llegenda, rect_escala, layers_propies)
{
	this.CalImprimir = cal_imprimir;
	this.RectTitol = rect_titol;
	this.RectVista = rect_vista;
	this.RectEscala = rect_escala;
	this.RectLlegenda = rect_llegenda;
	this.RectSituacio = rect_situacio;
	this.LayersPropies = layers_propies;
}

var accio_anar_coord=0x0001;
var accio_conloc=0x0002;
var accio_validacio=0x0004;


function CreaAccio(accio,servidor, coord, buffer, capes, camps, valors, id_trans, feta)
{
	this.accio=accio;
	this.servidor=servidor;
	this.coord=coord; //Punt que es vol validar
	this.buffer=buffer;
	this.capes=capes; //Array de capes que es volen validar
	this.camps=camps; //Array de camps de les capes (1 per cada capa en el mateix ordre)
	this.valors=valors; //Array de valors dels camps (1 per cada camp en el mateix ordre)
	this.id_trans=id_trans; //Identificador de la transacció
	this.feta=feta; //feta:true--> acció despatxada, feta:false --> acció cancel·lada
}

var estat_pendent=0x0001;
var estat_fi_exit=0x0002;
var estat_fi_error=0x0004;

var tipus_insert=0x0001;

function CreaTransaccio(i_capa, tipus, estat, win)
{
	this.i_capa=i_capa;
	this.tipus=tipus;
	this.estat=estat;
	this.text="";
	this.win=win;
}


LlistaServOWS=new Array();
function CreaLListaServidorsOWS(url, nom, tipus, categoria)
{
	this.url=url;
	this.nom=nom;
	this.tipus=tipus;
	this.categoria=categoria; 
}//Fi de CreaLListaServidorsOWS()

