//<![CDATA[
var INFO_LEGAL = msg_legal;               
var DELTAMAP = 150;
//12 juliol 2007
var RESOLUTION = window.screen.width;
var MONITOR_WIDTH = 11.5;
var PIXELPERINCH = RESOLUTION / MONITOR_WIDTH;
var ESCALACTUAL = 0;
var ZOOMLEVELS = 20;
var editor = false; 
// fin 12 juliol 2007
//var  zFactor=300;                   
function event_false() {
         window.event.returnValue = false
}

//document.onselectstart = event_false;   
document.onmousedown = nrc;               
 
function nrc(e) {
	if(document.all){
		if(event.button >1){
			//alert('ideLocal');return false;
			}
	}else{
		if(e.which >1){
			//alert('ideLocal');return false;
			}
	}
}

window.status="IDEC";

asdf=0;
var pass="1";
//var coordIniciR= new Array(258000,4485000,539600,4752000);
var coordIniciR = new Array(258000,4485000,539600,4752000);
var coordTemp= new Array(0,0,0,0);
var estatInicial="inici";
var pasZoom="punter";
var avisCarrerer=avisCar;
var codiEmail="";
var winInfo=null;

function ogcmap_convertGeom(type,pts) {
  geom = "";
  switch(type) {
    case "point":
      geom += "POINT:";
      geom += "(";
      geom += pts[0][0] + " " + pts[0][1];
      geom += ")";
      break;
    case "line":
      geom += "LINESTRING:";
      geom += "(";
        for(i=0;i<pts.length;i++) {
          geom += pts[i][0] + " " + pts[i][1];
          if(i<pts.length-1) {
            geom += ",";
          }
        }
      geom += ")";
      break;
    case "polygon":
      geom += "POLYGON:";
      geom += "(";
      geom += "(";
      for(i=0;i<pts.length;i++) {
        geom += pts[i][0] + " " + pts[i][1];
        if(i<pts.length-1) {
          geom += ",";
        }
      }
      geom += ")";
      geom += ")";
      break;
  }
  return geom;
}


var g_ogcMaps = new Array();

function ogcmap_findImage(name, doc) {
  var i, img;
  for (i = 0; i < doc.images.length; i++) {
  if (doc.images[i].name == name)
    return doc.images[i];
  }
  for (i = 0; i < doc.layers.length; i++) {
    if ((img = ogcmap_findImage(name, doc.layers[i].document)) != null) {
      img.container = doc.layers[i];
      return img;
    }
  }
  return null;
}

function ogcmap_getElt () {
  if(document.getElementById && document.getElementsByName) { 
    var name = ogcmap_getElt.arguments[ogcmap_getElt.arguments.length-1];
    if(document.getElementById(name))
      return document.getElementById(name);
    else if (document.getElementsByName(name))
      return document.getElementsByName(name)[0];
  }
  else if (document.layers){
    var currentLayer = document.layers[ogcmap_getElt.arguments[0]];
    for (var i=1; i<ogcmap_getElt.arguments.length && currentLayer; i++) {
      currentLayer = currentLayer.document.layers[ogcmap_getElt.arguments[i]];
    }
    return currentLayer;
  }
  else if (document.all) {
    var elt = eval('document.all.' + ogcmap_getElt.arguments[ogcmap_getElt.arguments.length-1]);
    return(elt);
  }
}

//objects
function ogcmap_Tool(opcode,name,title,description,targetFunction,enabled) {
  this.opcode = opcode;
  this.name = name;
  this.description = description;
  this.targetFunction = targetFunction;
  this.enabled = enabled;
}

function ogcmap_Label(pt,str) {
  this.pt = pt;
  this.str = str;
}

function ogcmap_transferPoints(type, pts) {

}

function ogcmap_setZoomBox(pt1,pt2) {
  layer = this.zoomBox.style;	
  if (pt1[0]>pt2[0]){
    layer.left=pt2[0] + "px";layer.width=pt1[0]-pt2[0] + "px";
  }
  else {
    layer.left=pt1[0] + "px";layer.width=pt2[0]-pt1[0] + "px";
  }
  if (pt1[1]>pt2[1]){
    layer.top=pt2[1] + "px";layer.height=pt1[1]-pt2[1] + "px";
  }
  else {
    layer.top=pt1[1] + "px";layer.height=pt2[1]-pt1[1] + "px";
  }
}

function ogcmap_capabilities_url(aLayer) {
  var sURL = aLayer.url;
  sURL += "&REQUEST=GetCapabilities";
  return sURL;
}

function ogcmap_queryLayerURL(i,aLayer,x,y) {

	var capaQ="";
	var sURL = aLayer.url;
  	if (sURL.indexOf("&") == -1){
  		sURL += "&REQUEST=GetFeatureInfo";
  	}else{
  		sURL += "REQUEST=GetFeatureInfo";
  	}
  	sURL += "&VERSION=" + aLayer.version;
 	for (k=0; k< this.servidores.length; k++) {
  		if (this.servidores[k][0] == i) {
			if ((this.servidores[k][3] == true) && (this.servidores[k][7] == true)) {
  				capaQ +=this.servidores[k][1]+",";
  			}
   		}
   	}
   	var gfh=(capaQ.length-1);
	if (gfh == -1){
   		sURL = "";
   	}else{
   	capaQ=capaQ.substring(0,gfh);
	capaQ=capaQ.replace(/ /g,"%20");
   	sURL += "&QUERY_LAYERS="+capaQ;
   	sURL += "&LAYERS="+capaQ;
  	sURL += "&SRS="+aLayer.epsg;
  	sURL += "&X=" + x;
  	sURL += "&Y=" + y;
  	sURL += "&FORMAT=PNG&STYLES=&SERVICE=WMS";
  	sURL += "&WIDTH="+this.mapWidthPX;
  	sURL += "&HEIGHT="+this.mapHeightPX;
    
  	if(sURL.indexOf("map=/opt/idec/dades/idelocal/")!=-1){
  		sURL += "&FEATURE_COUNT=50";
  	}else{
  		sURL += "&FEATURE_COUNT=10";
  	}
  	sURL += "&BBOX=" + this.cBounds[0] + "," + this.cBounds[1] + "," + this.cBounds[2] + "," + this.cBounds[3];
  	//sURL += "&INFO_FORMAT=application/vnd.ogc.gml";
 	if(sURL.indexOf('umn')==-1){
 		sURL += "&INFO_FORMAT="+aLayer.infoFormat;
 	}else{
 		sURL += "&INFO_FORMAT="+aLayer.infoFormat;
 	}
	}
    
  	return sURL;
}

//Nova funcio per fer Ajax
function ogcmap_queryLayerURLAjax(aLayer,x,y) {
	var servidor=aLayer.url;
	servidor=servidor.replace('?','&');
  	var sURL ="SERVIDOR="+servidor;
 	sURL += "&LAYERS="+document.getElementById('Escull').value;
  	sURL += "&X=" + x;
  	sURL += "&Y=" + y;
  	sURL += "&WIDTH="+this.mapWidthPX;
  	sURL += "&HEIGHT="+this.mapHeightPX;
  	sURL += "&Xmin=" + this.cBounds[0];
  	sURL += "&Ymin=" + this.cBounds[1];
  	sURL += "&Xmax=" + this.cBounds[2];
  	sURL += "&Ymax=" + this.cBounds[3];
 	return sURL;
}


function ogcmap_pixelToProj(xp,yp) {
  var aPt = new Array(0,0);
  var dx = this.cBounds[2] - this.cBounds[0];
  var dy = this.cBounds[3] - this.cBounds[1];
  aPt[0] = this.cBounds[0] + (dx*xp)/this.mapWidthPX;
  aPt[1] = this.cBounds[3] - (dy*yp)/this.mapHeightPX;
  return aPt;
}


function ogcmap_projToPixel(xp,yp) {
  var aPt = new Array(0,0);
  var dx = this.cBounds[2] - this.cBounds[0];
  var dy = this.cBounds[3] - this.cBounds[1];
  aPt[0]=(this.mapWidthPX/dx)*(xp-this.cBounds[0]);
  aPt[1] = this.mapHeightPX-((this.mapHeightPX/dy)*(yp - this.cBounds[1]));
  return aPt;
}

//adds a tool to the map
function ogcmap_addTool(opcode,name,title,description,targetFunction,enabled) {
  this.tools[this.tools.length] = new ogcmap_Tool(opcode,name,title,description,targetFunction,enabled);
}

function ogcmap_addLabel(pt,str) {
  this.labels[this.labels.length] = new ogcmap_Label(pt,str);
  this.writeLabels();
}

//28 nov 2006
function getInfo(index,template,format){

var inf="info_"+index;


	document.getElementById("ifrFeatureInfo").src = document.getElementById(inf).value;
}
var winInfo;
function ogcmap_queryUI(x,y) {
	var sURL
	var wInfo="<html><head><title>GetfeatureInfo</title></head>";
	wInfo +='<link rel="stylesheet" href="css/'+key+'.css">';
	wInfo +='<script>';
	wInfo +='function getInfo(index,template,format){document.getElementById("ifrFeatureInfo").src=document.getElementById(index).value;}';
	wInfo +='</script>';
	wInfo +='<form name="frmInfo">';
	wInfo +='<div style="height:100px;overflow:auto"><table border="1" cellspacing="0" cellpadding="0" bgcolor="#F4F5F7" bordercolor="#FFFFFF" width="95%">';
	var control = 0;
	var ultimSel = 0;
	for (i=0;i < this.layers.length;i++){
		if (this.layers[i].queryable){
				var visib = this.serVisible(i);
				if (visib){
					control = 1;
					
			 		var rutaServ=this.queryLayerURL(i,this.layers[i],x,y);
			 		if (rutaServ != ""){
					wInfo +="<tr><td class=\"menu\">"+this.layers[i].srvname+" <img OnClick=\"getInfo("+i+",'si','text/html')\" alt=\"Informació objecte seleccionat\" style=\" cursor:pointer;cursor:hand\" src=\"images/misc/info.gif\" width=\"17\" height=\"17\"></td></tr>";
					if (i == this.layers.length){
			 			//rutarServ = rutaServ.replace('text/html','mime');
			 		}
			   		wInfo +='<input type="hidden" id="info_'+i+'" value="'+rutaServ+'" > ';
			   		ultimSel = i;
			 	}
				}
		}
	}
	if (tipusAplicacio=="Urbanisme"){
		if (ultimSel > 5){
			if (this.serVisible(5)){
				ultimSel = 5;
			}
		}
	}
	if (control == 0){wInfo +='No hi ha cap capa activada';}
	wInfo +='</table></div><IFRAME frameborder="0" id="ifrFeatureInfo" width="95%" height="80%">';
	wInfo +="</iframe></form>"
	if (control == 1){
		wInfo +="<script>";
		wInfo +="getInfo("+ultimSel+",'si','text/html');";
		wInfo +="</script>";
	}
	wInfo +="</html>";
	
	
	
	winInfo=dhtmlwindow.open("winInfo", "inline", wInfo, "Info", "width=400px,height=530px,left=350px,top=95px,resize=1,scrolling=1");
	
	
	
	
}
//28 nov 2007 fin

//Nova funcio per industria
function ogcmap_queryAjax(x,y) {
  	if (!this.query)
    	return;
  	if (this.queryLayer < 0)
    	return;
  	if (this.queryLayer >= this.layers.length)
    	return;
  	var sURL = this.queryLayerURLAjax(this.layers[this.queryLayer],x,y);
 	getFeatureAjax(sURL);
}

function ogcmap_setTool(idx) {
  	if(this.toolbar == true) {
  		if(this.opcode > -1) {
      		prevCell = ogcmap_getElt(this.gid + "_toolcell_"+this.tools[this.opcode].opcode);
      		//13 Octubre
     		prevCell.className="boto_normal"
    	}
  	}
  	this.opcode = idx;
  	if(this.toolbar == true) {
  		var toolCell = ogcmap_getElt(this.gid + "_toolcell_"+this.tools[this.opcode].opcode);
    	toolCell.className="boto_sobre"
  	}
}

//10 NOV
function ogcmap_serVisible(idx) {
  	if (idx < 0)
    	return;
  	if (idx >= this.layers.length)
   		return;
   	var ver = false;
   	for (l=0; l < this.servidores.length; l++){
   		if (this.servidores[l][0] == idx){
   			if (this.servidores[l][3] == true){
   				ver = true;
   			}	
   		}
   	} 
   	return ver;
}

function ogcmap_setDefault(type,idx) {
  switch(type) {
    case "tool":
      if(idx) {
        this.setTool(idx);
      }
      else {
        var ntools = this.tools.length;
        for (var i=0; i < ntools-1; i++) {
          if(this.tools[i].enabled == true) {
            this.setTool(i);
            break;
          }
        }
      }
      break;
    case "queryLayer":
      if(idx) {
         this.setQueryLayer(idx);
      }
      else {
        var nlayers = this.layers.length;
        for (var i=0; i < nlayers-1; i++) {
          if(this.layers[i].queryable == true) {
            this.setQueryLayer(i);
            break;
          }
        }
      }
      break;
  }
}

function ogcmap_setQueryLayer(idx) {
  this.queryLayer = idx;
}

function ogcmap_writeLabels() {
  if(!this.labelsDiv) {
    return;
  }
  s = "";
  for(i=0;i<this.labels.length;i++){
    pt = this.projToPixel(this.labels[i].pt[0],this.labels[i].pt[1]);
  	s += "<div style=\"color:white;position:absolute;left:" + (pt[0]+1) + "px;top:" + (pt[1]) + "px;\">" + this.labels[i].str + "</div>\n";
	s += "<div style=\"color:white;position:absolute;left:" + (pt[0]) + "px;top:" + (pt[1]+1) + "px;\">" + this.labels[i].str + "</div>\n";
	s += "<div style=\"color:white;position:absolute;left:" + (pt[0]-1) + "px;top:" + (pt[1]) + "px;\">" + this.labels[i].str + "</div>\n";
	s += "<div style=\"color:white;position:absolute;left:" + (pt[0]) + "px;top:" + (pt[1]-1) + "px;\">" + this.labels[i].str + "</div>\n";
	s += "<div style=\"color:red;position:absolute;left:" + pt[0]+ "px;top:" + pt[1] + "px;\">" + this.labels[i].str + "</div>\n";
  }
  this.labelsDiv.innerHTML = s;
}

//14 NOV
//redondea numero
function redondear(cantidad, decimales) {
	var cantidad = parseFloat(cantidad);
	var decimales = parseFloat(decimales);
	decimales = (!decimales ? 2 : decimales);
	return Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);
}   

function ogcmap_limpiar(){
	this.inputPts.splice(0,this.inputPts.length);
	this.jg.clear();
	this.drawPts();
	escriuValorInfo("");
	this.labelsDiv.innerHTML="";
	this.labels.splice(0,this.labels.length);
	this.labels.length = 0;
	document.getElementById('puntInci').style.visibility='hidden';
}

function ogcmap_drawPts() {

  	if(!this.jg) {
    	return;
  	}
  	s = "";
  	// convert all geographic coords into image space and draw
  	var imgxs = new Array();
  	var imgys = new Array();
  	var linewidth = 2;
  	var markerdiam = linewidth * 2;
  	var markerrad = markerdiam * 2;
  	var raiz = 0;
  	var total = 0;
  	//20Gener
   	if(document.getElementById('fooWSXY').style.visibility=='visible'){
	   	tmpWS= new Array();
	  	tmpWS=this.projToPixel(parseFloat(document.getElementById('cX').value),parseFloat(document.getElementById('cY').value));
		var sWS=idec_getSeleccioPunt(0,tmpWS,document.getElementById('adreca').value);
		
		document.getElementById('efecte').innerHTML=sWS;
		document.getElementById('efecte').style.visibility = 'visible';
		writePunt();
  	}
  	if(document.getElementById('puntInci').style.visibility=='visible'){
		tmpInci = new Array();
		tmpInci=this.projToPixel(parseFloat(document.getElementById('inciX').value),parseFloat(document.getElementById('inciY').value));
		idec_puntIncidencia(tmpInci[0],tmpInci[1]);
	}
	
  	for (i=0; i<this.inputPts.length; i++) {
    	tmp = new Array();
    	tmp = this.projToPixel(this.inputPts[i][0],this.inputPts[i][1]);
    	//14 NOV
  		if (i != 0) {
    		var xmin = this.inputPts[i-1][0];
    		var ymin = this.inputPts[i-1][1];
    		var xmax = this.inputPts[i][0];
    		var ymax = this.inputPts[i][1];
    		var filtre=xmin+'p';
    		filtre=filtre.indexOf('.');
    		if(filtre < 4){ 
    			//estem parlant de coord no metrica
    			var xy = new Array(2);
				var xy1 = new Array(2);  
    			var lon = parseFloat (xmin);
    			var lat = parseFloat (ymin);
 				zone = Math.floor ((lon + 180.0) / 6) + 1;
 				zone = LatLonToUTMXY (DegToRad (lat), DegToRad (lon), zone, xy);
				xmin=xy[0];
       			ymin=xy[1];
        		lon1 = parseFloat (xmax);
        		lat1 = parseFloat (ymax); 
		        zone = Math.floor ((lon + 180.0) / 6) + 1;   
		        zone = LatLonToUTMXY (DegToRad (lat1), DegToRad (lon1), zone, xy1);
				xmax=xy1[0];
         		ymax=xy1[1];
    		}
		    var x = xmax - xmin;
		    var y = ymax - ymin;
		    x = x*x;
		    y = y*y;
		    var suma = x + y
		    var raiz = Math.sqrt(suma)
		    total = total + raiz;
		    total = redondear(total,2);
		    raiz = redondear(raiz,2);
		    if (i == (this.inputPts.length - 1)){
		    	var stotal = "Últim tram: "+raiz+" metres. Total: " + total + " metres.";
		    	escriuValorInfo(stotal);
		    }
   		}
    	//14 NOV fin
    	imgxs[imgxs.length] = parseInt(tmp[0]);
	    imgys[imgys.length] = parseInt(tmp[1]);
	   
	    s += this.getSelectionPoint(i,tmp,total);
	}
  	if(imgxs.length > 1) {
  		//borra el tramo se elimina un punto
    	this.jg.clear();
    	//crea la linea
    	this.jg.drawPolyline( imgxs, imgys );
  	}
  	//dibuja la linea
  	this.jg.paint();
  	//escribe el punto
  	
  	this.selectionDiv.innerHTML = s;
}

function ogcmap_getSelectionPoint(idx,pt,dist) {
	//11 NOV
	var sj = "<div id=\"" + this.gid + "_selection_" + idx + "\" style=\"padding:1px;cursor:move;border:0px solid white;position:absolute;width:5px;height:5px;left:" + ((pt[0]) - 0) + "px;top:" + ((pt[1]) - 1) + "px;\"><p STYLE=\"color: white\">" + dist + "</p></div>";
	var sj1 = "<div id=\"" + this.gid + "_selection_" + idx + "1\" style=\"padding:1px;cursor:move;border:0px solid white;position:absolute;width:5px;height:5px;left:" + ((pt[0]) - 1) + "px;top:" + ((pt[1]) - 0) + "px;\"><p STYLE=\"color: white\">" + dist + "</p></div>";
	var sj2 = "<div id=\"" + this.gid + "_selection_" + idx + "2\" style=\"padding:1px;cursor:move;border:0px solid white;position:absolute;width:5px;height:5px;left:" + ((pt[0]) - 0) + "px;top:" + ((pt[1]) + 1) + "px;\"><p STYLE=\"color: white\">" + dist + "</p></div>";
	var sj3 = "<div id=\"" + this.gid + "_selection_" + idx + "3\" style=\"padding:1px;cursor:move;border:0px solid white;position:absolute;width:5px;height:5px;left:" + ((pt[0]) + 1) + "px;top:" + ((pt[1]) - 0) + "px;\"><p STYLE=\"color: white\">" + dist + "</p></div>";
	var sj4 = "<div id=\"" + this.gid + "_selection_" + idx + "4\" style=\"padding:1px;cursor:move;border:0px solid white;position:absolute;width:5px;height:5px;left:" + ((pt[0]) - 0) + "px;top:" + ((pt[1]) - 0) + "px;\"><p STYLE=\"color: blue\">" + dist + "</p></div>";
	var sj = sj + sj1 + sj2 + sj3 + sj4;
	return sj;
}

var sj0="";

//20Gener
function idec_getSeleccioPunt(idx,pt,dist) {
	sj0="";
  	var sj="<div  id=\"punt\" Onclick='veureInfoPuntAdreca(\""+dist+"\",event,1)' style=\"z-index:50;padding:1px;cursor:pointer;cursor:hand;border:0px none black;position:absolute;width:38px;height:32px;left:" + ((pt[0]) - 8) + "px;top:" + ((pt[1]) - 40) + "px;\"><img  src=\"images/point.gif\" width='38px' height='32px' ></img></div>";
 	if((dist == "null")||(dist == "")){}
 	else{
 	
//winPoint.overlayHideEffectOptions(null);
 	
  		//var sj0 = "<div id=\"label\" class=\"label\"  style=\"z-index:100;width:150px;height:50px;left:" + ((pt[0]) + 15) + "px;top:" + ((pt[1]) - 15) + "px;\">" + dist + " ";
  //sj0 +="<img class=\"img\" onClick=\"map.botoGML()\" onmouseover=\"Tip('"+bt_gml_des+"')\" src=\"/idecwebservices/mapawms/images/gml.gif\">";
  	//sj0 +="</div>";
  	
  	
  	
  	}
  	return sj;
}

function veureInfoPuntAdreca(dist,pt,tipo){
	if (tipo == 1){
		if(document.all){
			Leftpt = pt.clientX;
			Toppt = pt.clientY;
		}
		else{
			Leftpt = pt.pageX;
			Toppt = pt.pageY;
		}
	}
	else{
		//alert(pt);
		pt = pt.split("@");
		Leftpt =  parseInt(pt[0])+260;
		Toppt = parseInt(pt[1])+40;
	}
	//winPoint= new Window('Infop', {className: "alphacube",opacity:1,zIndex:150,top:0, left:0 , width:150, height:50,minimizable:false,maximizable:false});
	//alert(Leftpt + "  " + Toppt);
	Leftpt=(Leftpt + 20);
	Toppt=(Toppt - 20);
	//winPoint.setLocation(Toppt,Leftpt);
	if (dist.indexOf("null") != -1){
		dist = document.getElementById("txtcodiMunH").value;	
	}
	var sj0 = "<table width=\"99%\" class=\"menu\" style=\"text-align:left;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  	sj0 +="<tr><td><b>" + dist + "</b></td></tr>";
  	//sj0 +="<tr><td onClick=\"map.botoGML()\" style=\"cursor:pointer;cursor:hand\"><u>"+bt_gml_des+"</u></td></tr>";
  	//sj0 +="<tr><td onClick=\"idec_metadades('','')\" style=\"cursor:pointer;cursor:hand\"><u>"+gui_Met+"</u></td></tr>";
   	sj0 +="</table>";
	/*
   winPoint.getContent().innerHTML=sj0;
	winPoint.toFront();
	winPoint.setDestroyOnClose(true);
	winPoint.show();
	*/	
	var winPoint=dhtmlwindow.open("winPoint", "inline", sj0, "Info", "width=150px,height=50px,left="+Leftpt+"px,top="+Toppt+"px,resize=1,scrolling=1");	

}


function ogcmap_toggleRefresh() {
  this.autoRefresh = !this.autoRefresh;
}

//Gestor capes
function ogcmap_gestorCapes(id) {
	var sURL = "";
  	for (var i=0; i < this.layers.length; i++) {
 		if(i==id){
 			img = ogcmap_findImage(this.prefix+i,document);
    		sURL = this.layer_url(this.layers[i]);
    		var img = 0;
    		if (document.all) {
      			img = document.images[this.prefix+i];
    		}
    		else {
      			img = ogcmap_findImage(this.prefix+i,document);
    		}
    		if (this.layers[i].visible == false) {
      			img.src = sURL;
    		}
    		else {
      			img.src = this.baseDir + "blank.gif";
    		}
 		}
 	}
  	this.container.style.visibility = "hidden";
  	this.drawPts();
  	this.writeLabels();
}

function ogcmap_setLoaded(idx) {
	if(this.loadDiv) {
  		this.layers[idx].loaded = true;
    	this.testLoaded();
  	}
}

function ogcmap_showLoading() {
	//this.loadDiv.style.visibility = "visible";
	var nom=this.loadDiv.id;
	ogcmap_hideLoading();
	//setTimeout('ogcmap_hideLoading()',500);
}

function ogcmap_hideLoading() {
	if(this.loadDiv) {
    	this.loadDiv.style.visibility = "hidden";
     	this.container.style.left = "0px";
  		this.container.style.top = "0px";
  	}else{
 		document.getElementById('0_loadDiv').style.visibility = "hidden";
 		document.getElementById('0_container').style.left = "0px";
   		document.getElementById('0_container').style.top = "0px";
	}
}


function ogcmap_fullExtent() {
  this.cBounds[0] = this.mapBounds[0];
  this.cBounds[1] = this.mapBounds[1];
  this.cBounds[2] = this.mapBounds[2];
  this.cBounds[3] = this.mapBounds[3];
  this.redraw();
}


function ogcmap_previousExtent() {
  this.cBounds[0] = this.prevBounds[0];
  this.cBounds[1] = this.prevBounds[1];
  this.cBounds[2] = this.prevBounds[2];
  this.cBounds[3] = this.prevBounds[3];
  if ((this.cBounds[0] == 0) && (this.cBounds[1] == 0) && (this.cBounds[2] == 0) && (this.cBounds[3] == 0)){
  	this.fullExtent();
  }else {
  	this.redraw();
  }
}
var winWMS;
function ogcmap_afegirServidor() {
	
var url = "/idecwebservices/mapawms/addwms.jsp?key=" + key + "&language=" + language + "&server=" + serverUrl + "&layers=" + layersUrl;

winWMS=dhtmlwindow.open("WMS", "iframe", url, "WMS", "width=380px,height=600px,left=350px,top=95px,resize=1,scrolling=1");
	
}

function afegirServidorD(servidor) {


	
var url = "/idecwebservices/mapawms/addwms.jsp?key=" + key + "&language=" + language + "&server=" + servidor + "&layers=";

winWMS=dhtmlwindow.open("WMS", "iframe", url, "WMS", "width=380px,height=600px,left=350px,top=95px,resize=1,scrolling=1");
	
}


function ogcmap_zoomCentre(accio){

var xp=parseInt(this.mapWidthPX/2);
var yp=parseInt(this.mapHeightPX/2);
if(accio=="mes"){
this.zoom(xp,yp);
}else{
this.zoomOut(xp,yp);
}

}

function ogcmap_pan(factor,direction) {

  this.prevBounds[0] = this.cBounds[0];
  this.prevBounds[1] = this.cBounds[1];
  this.prevBounds[2] = this.cBounds[2];
  this.prevBounds[3] = this.cBounds[3];
 
 value=20;
 
 bcdf21 = this.cBounds[2] - this.cBounds[0]; 
bcdf15 = this.cBounds[3] - this.cBounds[1];
bcdf17 = 0;
if (direction == "N") { 
bcdf17 = bcdf15 / (100.0 / value);
this.cBounds[1] = this.cBounds[1] - bcdf17;
this.cBounds[3] = this.cBounds[3] - bcdf17; 
}

 
else if (direction == "S") { 
bcdf17 = bcdf15 / (100.0 / value); 
this.cBounds[1] = this.cBounds[1] + bcdf17;
this.cBounds[3] = this.cBounds[3] + bcdf17;
} 

else if (direction == "W") { 
bcdf17 = bcdf21 / (100.0 / value); 
this.cBounds[0] = this.cBounds[0] + bcdf17;
this.cBounds[2] = this.cBounds[2] + bcdf17;
 } 


else if (direction == "E") { 
bcdf17 = bcdf21 / (100.0 / value); 
this.cBounds[0] = this.cBounds[0] - bcdf17;
this.cBounds[2] = this.cBounds[2] - bcdf17; 
} 
 
 
 this.redraw();
  
 
  

}


function ogcmap_zoom(xp,yp) {
  this.prevBounds[0] = this.cBounds[0];
  this.prevBounds[1] = this.cBounds[1];
  this.prevBounds[2] = this.cBounds[2];
  this.prevBounds[3] = this.cBounds[3];
  var dx = this.cBounds[2] - this.cBounds[0];
  dx = dx / this.zoomFactor;
  var dy = this.cBounds[3] - this.cBounds[1];
  dy = dy / this.zoomFactor;
  var pt = this.pixelToProj(xp,yp);
  this.cBounds[0] = pt[0]-(dx/2.0);
  this.cBounds[2] = pt[0]+(dx/2.0);
  this.cBounds[1] = pt[1]-(dy/2.0);
  this.cBounds[3] = pt[1]+(dy/2.0);
  this.redraw();
}

function ogcmap_zoomToBox() {
  pt1 = new Array();
  pt2 = new Array();
  if(this.pt1[0]<this.pt2[0]){
    pt1[0]=this.pt1[0];
    pt2[0]=this.pt2[0];
  }
  else{
    pt1[0]=this.pt2[0];
    pt2[0]=this.pt1[0];
  }
  if(this.pt1[1]<this.pt2[1]){
    pt1[1]=this.pt1[1];
    pt2[1]=this.pt2[1];
  }
  else{
    pt1[1]=this.pt2[1];
    pt2[1]=this.pt1[1];
  }
  pt1=this.pixelToProj(pt1[0],pt1[1]);
  pt2=this.pixelToProj(pt2[0],pt2[1]);
  bbox = new Array();
  bbox[0]=pt1[0];
  bbox[2]=pt2[0];
  bbox[1]=pt2[1];
  bbox[3]=pt1[1];
  bbox = this.adjustExtent(bbox);
  this.prevBounds[0] = this.cBounds[0];
  this.prevBounds[1] = this.cBounds[1];
  this.prevBounds[2] = this.cBounds[2];
  this.prevBounds[3] = this.cBounds[3];
  this.cBounds[0] = bbox[0];
  this.cBounds[2] = bbox[2];
  this.cBounds[1] = bbox[1];
  this.cBounds[3] = bbox[3];
  this.redraw();
}

function ogcmap_zoomFinestra(minX,minY,maxX,maxY){
  bbox = new Array();
  

  bbox[0]=parseFloat(minX);
  bbox[2]=parseFloat(maxX);
  bbox[1]=parseFloat(minY);
  bbox[3]=parseFloat(maxY);
  
  
  
    
  bbox = this.adjustExtent(bbox);
  this.prevBounds[0] = this.cBounds[0];
  this.prevBounds[1] = this.cBounds[1];
  this.prevBounds[2] = this.cBounds[2];
  this.prevBounds[3] = this.cBounds[3];
  
  this.cBounds[0] = bbox[0];
  this.cBounds[2] = bbox[2];
  this.cBounds[1] = bbox[1];
  this.cBounds[3] = bbox[3];
  
  
  
  this.redraw();
}


function ogcmap_zoomOut(xp,yp) {
  this.prevBounds[0] = this.cBounds[0];
  this.prevBounds[1] = this.cBounds[1];
  this.prevBounds[2] = this.cBounds[2];
  this.prevBounds[3] = this.cBounds[3];
  var dx = this.cBounds[2] - this.cBounds[0];
  dx = dx * this.zoomFactor;
  var dy = this.cBounds[3] - this.cBounds[1];
  dy = dy * this.zoomFactor;
  var pt = this.pixelToProj(xp,yp);
  this.cBounds[0] = pt[0]-(dx/2.0);
  this.cBounds[2] = pt[0]+(dx/2.0);
  this.cBounds[1] = pt[1]-(dy/2.0);
  this.cBounds[3] = pt[1]+(dy/2.0);
  this.redraw();
}

function ogcmap_zoomescala(valor){
	valor = parseFloat(valor);
	ESCALACTUAL = valor;
	
	var res =  1 / ((1/valor) *  72 * 39.3701);
	var w_deg = parseInt(this.mapWidthPX) * res;
    var h_deg = parseInt(this.mapHeightPX) * res;
    var cenX = (this.cBounds[0] + this.cBounds[2])/2; 
    var cenY = (this.cBounds[1] + this.cBounds[3])/2; 
    var xmin = cenX - (w_deg / 2);
    var ymin = cenY - (h_deg / 2); 
	var xmax = cenX + (w_deg / 2); 
	var ymax = cenY + (h_deg / 2);
    this.zoomFinestra(xmin,ymin,xmax,ymax);
}



function ogcmap_zoomPt(x,y,zF) {
	if(zF==null){zF=300;}
	zF=parseInt(zF);
	var x1 = 0;
	var x2 = 0;
	var y1 = 0;
	var y2 = 0;
	x=parseFloat(x);
	y=parseFloat(y);
	x1=eval(x - zF);
	y1=eval(y - zF);
	x2=eval(x + zF);
	y2=eval(y + zF);
	x1 = parseInt(x1);
	x2 = parseInt(x2);
	y1 = parseInt(y1);
	y2 = parseInt(y2);
	this.zoomFinestra(x1,y1,x2,y2);
	
}

function ogcmap_recenter(xp,yp) {
  this.prevBounds[0] = this.cBounds[0];
  this.prevBounds[1] = this.cBounds[1];
  this.prevBounds[2] = this.cBounds[2];
  this.prevBounds[3] = this.cBounds[3];
  var dx = this.cBounds[2] - this.cBounds[0];
  var dy = this.cBounds[3] - this.cBounds[1];
  var pt = this.pixelToProj(xp,yp);
  this.cBounds[0] = pt[0]-(dx/2.0);
  this.cBounds[2] = pt[0]+(dx/2.0);
  this.cBounds[1] = pt[1]-(dy/2.0);
  this.cBounds[3] = pt[1]+(dy/2.0);
  this.redraw();
}



function ogcmap_position(e) {
  if(!e)
    e=window.event;
  var mX=null;
  var mY=null;
  var op=navigator.userAgent.toLowerCase().indexOf('opera')!=-1;
  var ie = document.all;
  if (ie || op) {
    mX = e.offsetX;
    mY = e.offsetY;
  }
  else {
    mX = e.layerX;
    mY = e.layerY;
  }
  return new Array(mX,mY);
}
//ratoli
function ogcmap_onmouseWheel(e) {
wheel(e);
}
//
function ogcmap_onResize(){

}


function ogcmap_mouseDown(e) {
  position = this.position(e);
  switch(this.opcode) {
    case 0:
      this.pt1 = position;
      this.zoomBox.style.visibility="visible";
      this.zooming = true;
      //document.getElementById('efecte').style.zIndex=0;
      break;
    case 1:
      this.zoomOut(position[0],position[1]);
      break;
    case 2:
      this.pt1 = position;
      this.panning = true;
      break;
    case 3:
      this.queryUI(position[0],position[1]);
      break;
    case 7:
      this.pt1 = position;
      xmin=position[0]-7;
      xmax=position[0]+7;
      ymin=position[1]-7;
      ymax=position[1]+7;
      for(i=this.inputPts.length-1;i>-1;i--) {
        pt = this.projToPixel(this.inputPts[i][0],this.inputPts[i][1]);
        if((pt[0]>xmin) && (pt[0]<xmax) && (pt[1]>ymin) && (pt[1]<ymax)) {
          this.selecting=true;
          this.selectionPoint=i;
          break;
        }
      }
      break;
    case 8:
      var pt = this.pixelToProj(position[0],position[1]);
      var str = prompt("Escriure text:","");
      if(str != null) {
        this.addLabel(pt,str);
      }
      break;
    case 11:
    	coord = this.pixelToProj(position[0],position[1]);
    	var str = prompt("Escriure text(opcional):","");
      	this.crearVincle(coord[0],coord[1],str);
      	break;
    case 12:
    	idec_puntIncidencia(position[0],position[1]);
		coord = this.pixelToProj(position[0],position[1]);
    	this.mailing(coord[0],coord[1]);
  }
  return false;
}

function ogcmap_mouseMove(e) {
  position = this.position(e);
  proj = this.pixelToProj(position[0],position[1]);
  
  //26 marzo
  escriuValorInfo("x: " + Math.round((Math.round(proj[0]*1000)/1000)* Math.pow(10, 2)) / Math.pow(10, 2) + "<br> y: " + Math.round((Math.round(proj[1]*1000)/1000)* Math.pow(10, 2)) / Math.pow(10, 2));
  if(this.zooming) {
    this.pt2 = position;
    this.setZoomBox(this.pt1,this.pt2);
  }
  else if(this.panning) {
    this.pt2 = position;
    this.container.style.left = (this.pt2[0] - this.pt1[0]) + "px";
    this.container.style.top = (this.pt2[1] - this.pt1[1]) + "px";
  }
  else if(this.selecting) {
    this.pt2 = position;
    div = ogcmap_getElt(this.gid + "_selection_" + this.selectionPoint);
    div.style.left = ((position[0]) - 3) + "px";
    div.style.top = ((position[1]) -3) + "px";
  }
  return false;
}

function ogcmap_mouseUp(e) {
//document.getElementById('efecte').style.zIndex=101;
  if(this.zooming) {
    this.zooming = false;
    this.zoomBox.style.width="0px";
    this.zoomBox.style.height="0px";
    this.zoomBox.style.visibility="hidden";
    position = this.position(e);
    if((this.pt1[0] == position[0]) && (this.pt1[1] == position[1])) {
      this.zoom(position[0],position[1]);
    }
    else {
      this.zoomToBox();
    }
  }
   else if (this.panning) {
  position = this.position(e);
    this.panning = false;
    this.prevBounds[0] = this.cBounds[0];
    this.prevBounds[1] = this.cBounds[1];
    this.prevBounds[2] = this.cBounds[2];
    this.prevBounds[3] = this.cBounds[3];
    if(isNaN(this.pt2[0]) || this.pt2[0] == "undefined"){
    	this.recenter(position[0],position[1]);
    }
    else if (this.pt1[0] == position[0] && this.pt1[1] == position[1]){
    	this.recenter(position[0],position[1]);
    }
    else{
	    down = this.pixelToProj(this.pt1[0],this.pt1[1]);
	    up = this.pixelToProj(this.pt2[0],this.pt2[1]);
	    
	    this.cBounds[0] -= (up[0]-down[0]);
	    this.cBounds[2] -= (up[0]-down[0]);
	    this.cBounds[1] += (down[1]-up[1]);
	    this.cBounds[3] += (down[1]-up[1]);
	    this.redraw();
    }
  }
  else if(this.selecting) {
    this.selecting = false;
    if((this.pt1[0] == this.position(e)[0]) && (this.pt1[1] == this.position(e)[1])) {
      if(confirm("Delete this point?")) {
        this.inputPts.splice(i,1);
        this.drawPts();
      }
      else {
        if(confirm("Clone (duplicate) this point?")) {
          this.inputPts.splice(((i) + 1),0,this.inputPts[i]);
          this.drawPts();
        }
      }
    }
    else {
      this.inputPts[this.selectionPoint] = this.pixelToProj(this.pt2[0],this.pt2[1]);
      this.drawPts();
      this.selectionPoint = null;
    }
  }
  else if(this.opcode == 7) {
    var pt = this.pixelToProj(position[0],position[1]);
    this.inputPts[this.inputPts.length] = pt;
    this.drawPts();
  }
  return false;
}

function ogcmap_mouseOver(e) {

}

function ogcmap_mouseOut(e) {
  window.status = "";
}

function ogcmap_escriuCapa(){
	//var sdiv = "<div style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; margin:0; padding:0; position:absolute;\">";
	var swh = "width=\"" + this.mapWidthPX + "px\" height=\"" +this.mapHeightPX + "px\"";
	var contenedor = "0_container";
	var gid=0;
	var nlayers = this.layers.length;
	var nou = "";
	
	var MapActu=document.getElementById(contenedor).innerHTML;
	
	for (var i=0; i < nlayers; i++) {
		nou = "<div id=\"div_" + this.prefix+i+ "\" name=\"div_" + this.prefix+i+ "\" style=\"margin: 0pt; padding: 0pt; width:" + this.mapWidthPX + "px; height: " + this.mapHeightPX + "px; position: absolute; filter:alpha(opacity=100); opacity:1;\" ><img style=\"filter:alpha(opacity=100);opacity:1;\" id=\"" + this.prefix+i+ "\" name=\"" + this.prefix+i+ "\" onload=\"g_ogcMaps["+gid+"].setLoaded(" + i + ")\" src=\"" + this.baseDir + "blank.gif\" " + swh + "/></div>\n";
	    //nou = "<div id=\"div_" + this.prefix+i+ "\" name=\"div_" + this.prefix+i+ "\" style=\"margin: 0pt; padding: 0pt; width:" + this.mapWidthPX + "px; height: " + this.mapHeightPX + "px; position: absolute; filter:alpha(opacity=100); opacity:1;\" ><img style=\"filter:alpha(opacity=100);opacity:1;\" id=\"" + this.prefix+i+ "\" name=\"" + this.prefix+i+ "\" onload=\"g_ogcMaps["+gid+"].setLoaded(" + i + ")\" src=\"" + this.baseDir + "blank.gif\" " + swh + "/></div>\n";
	}
	MapActu = MapActu + nou; 
	
	
	
	document.getElementById(contenedor).innerHTML=MapActu;
	
	this.postWrite();
	
	
	
}

function ogcmap_imprimir(){
	window.open("/ideLocal/visual/imprimir.htm", "Imprimir", 'width=650,height=600,left=150,top=150,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes');
}

// Resize a spatial extent to have the same aspect ratio as an image size.
function ogcmap_adjustExtent(ext) {




  var dx = parseFloat(ext[2] - ext[0]);
  var dy = parseFloat(ext[3] - ext[1]);
  
  // var resolution = Math.max( dx  / this.mapWidthPX,dy / this.mapHeightPX );
  
  
  if(dx/this.mapWidthPX>dy/this.mapHeightPX){
    ext[1]=parseFloat(ext[1])-(((dx/this.mapWidthPX*this.mapHeightPX)-dy)/2);
    ext[3]=parseFloat(ext[3])+(((dx/this.mapWidthPX*this.mapHeightPX)-dy)/2);
    
  }
  else{
    ext[0]=parseFloat(ext[0])-(((dy/this.mapHeightPX*this.mapWidthPX)-dx)/2);
    ext[2]=parseFloat(ext[2])+(((dy/this.mapHeightPX*this.mapWidthPX)-dx)/2);
     
  }
  
  
  
 
  
  return ext;
}

function ogcmap_testLoaded() {
  this.container.style.visibility = "hidden";
  for(i=0;i<this.layers.length;i++) {
    if(this.layers[i].loaded == false) {
      return;
    }
  }
  this.container.style.visibility = "visible";
}

function ogcmap_postWrite(inicial) {
  this.setDefault("tool");
  this.setDefault("queryLayer");
  if(editEnabled) {
    this.jg = new jsGraphics(this.gid + "mapCanvas");
    this.jg.setStroke(2);
    this.jg.setColor("yellow");
  }
  this.labelsDiv = ogcmap_getElt(this.gid + "_labelsDiv");
  this.selectionDiv = ogcmap_getElt(this.gid + "_selectionDiv");
  //20Gener
  this.selectionDiv1 = ogcmap_getElt(this.gid + "_selectionDiv1");
  this.zoomBox = ogcmap_getElt(this.gid+"_zoomBox");
  this.container = ogcmap_getElt(this.gid + "_container");
  this.loadDiv = ogcmap_getElt(this.gid + "_loadDiv");
  this.glassPane = ogcmap_getElt(this.gid + "_glassPane");
 if (inicial == 1){
  	this.zoomInicial();
  }else{
  	this.redraw();
  }
}

function ogcmap_calculaEscala(){
	var escala2;
   	escalaN=(this.cBounds[2]-this.cBounds[0])/2;
 	escalaN=escalaN/2
   	return escalaN;
}

function ogcmap_init() {


 //this.mapBounds = this.adjustExtent(this.mapBounds);
  this.cBounds[0] = this.mapBounds[0];
  this.cBounds[1] = this.mapBounds[1];
  this.cBounds[2] = this.mapBounds[2];
  this.cBounds[3] = this.mapBounds[3];
  if((this.editType == "none") || (this.editType == "undefined")) {
    editEnabled = false;
  }
  else {
    editEnabled = true;
  }
  this.addTool(0,"zoom","zoom in",bt_zoomin,"setTool(0)",true);
  this.addTool(1,"zoomout","zoom out",bt_zoomout,"setTool(1)",true);
  this.addTool(2,"centrar","recenter map",bt_pan,"setTool(2)",true);
  this.addTool(3,"identificar","add point",bt_info,"setTool(3)",this.query);
  this.addTool(4,"inici","home",bt_extent,"fullExtent()",true);
  this.addTool(5,"tornar","Vista anterior",bt_back,"previousExtent()",true);
  this.addTool(6,"zoomescala","zoom escala",bt_zoomesc,"muestraZoomEscala()",true);
  this.addTool(7,"mesurar","digitize feature",bt_mesura,"setTool(7)",editEnabled);
  this.addTool(8,"etiquetar","label",bt_text,"setTool(8)",true);
  this.addTool(6,"esborrar","esborrar",bt_esborra,"limpiar()",true);
  this.addTool(10,"imprimir","Afegir Servidor",bt_print,"imprimir()",true);
  this.addTool(11,"link1","Vincle",bt_link,"setTool(11)",true);
  this.addTool(12,"download","GML",bt_gml,"botoGML()",true);
  this.addTool(13,"incidencia_cat","Enviar Incidència",bt_incidencia,"setTool(12)",true);
  
}

function ogcMap(gid,prefix,width,height,srs,xmin,ymin,xmax,ymax,baseDir,skin,toolbar,editType,query,leyenda) {
  //properties
  this.gid = gid;
  this.prefix = prefix;
  this.mapWidthPX = width;
  this.mapHeightPX = height;
  this.srs = srs;
  this.mapBounds = new Array(xmin,ymin,xmax,ymax);
  this.baseDir = baseDir;
  this.skin = skin;
  this.toolbar = toolbar;
  this.editType = editType;
  this.query = query;
  this.layers = new Array();
  this.tools = new Array();
  this.labels = new Array();
  this.bgColor = "0xFFFFFF";
  this.cBounds = new Array(0,0,0,0);
  this.prevBounds = new Array(0,0,0,0);
  this.zoomFactor = 2;
  this.autoRefresh = false;
  this.queryLayer = 0;
  this.opcode = -1;
  this.inputPts = new Array();
  this.zooming = false;
  this.panning = false;
  this.selecting = false;
  this.selectionPoint = null;
  this.pt1 = new Array();
  this.pt2 = new Array();
  this.zoomBox = null;
  this.container = null;
  this.loadDiv = null;
  this.labelsDiv = null;
  this.selectionDiv = null;
  this.glassPane = null;
  //nuevo
  this.servidores = new Array();
  this.leyenda = leyenda;
  this.WidthDivPer='100%'
  this.HeightDivPer='100%'
  this.percent=0;
  this.topM=null;
  this.leftM=null;
  
    
  //methods
  this.mailing = ogcmap_mailing;
  this.imprimir=ogcmap_imprimir;
  this.botoGML=ogcmap_botoGML;
  this.limpiar=ogcmap_limpiar;
  this.zoomescala=ogcmap_zoomescala;
  this.zoomFinestra=ogcmap_zoomFinestra;
  this.calculaEscala=ogcmap_calculaEscala;
  this.rebre=ogcmap_rebre;
  this.moureSlide=ogcmap_moureSlide;
  this.layer_url = ogcmap_layer_url;
  this.pixelToProj = ogcmap_pixelToProj;
  this.projToPixel = ogcmap_projToPixel;
  this.writeInline = ogcmap_writeInline;
  this.escriuCapa =ogcmap_escriuCapa;
  this.addLayer = ogcmap_addLayer;
  this.addTool = ogcmap_addTool;
  this.addLabel = ogcmap_addLabel;
  this.redraw = ogcmap_redraw;
  this.gestorCapes =ogcmap_gestorCapes;
  this.fullExtent = ogcmap_fullExtent;
  this.previousExtent = ogcmap_previousExtent;
  this.afegirServidor=ogcmap_afegirServidor;
  this.zoom = ogcmap_zoom;
  this.zoomToBox = ogcmap_zoomToBox;
  this.zoomOut = ogcmap_zoomOut;
  this.setZoomBox = ogcmap_setZoomBox;
  this.recenter = ogcmap_recenter;
  this.pan = ogcmap_pan;
  this.mouseDown = ogcmap_mouseDown;
  this.mouseMove = ogcmap_mouseMove;
  this.mouseUp = ogcmap_mouseUp;
  this.mouseOver = ogcmap_mouseOver;
  this.mouseOut = ogcmap_mouseOut;
  //ratoli
  this.mouseWheel = ogcmap_onmouseWheel;
  this.onResizeWindow=ogcmap_onResize;
  this.position = ogcmap_position;
  this.zoomPt = ogcmap_zoomPt;
  this.layerUI = ogcmap_layerUI;
  this.toggleLayer = ogcmap_toggleLayer;
  this.setLoaded = ogcmap_setLoaded;
  this.toggleRefresh = ogcmap_toggleRefresh;
  this.setTool = ogcmap_setTool;
  this.setDefault = ogcmap_setDefault;
  this.setQueryLayer = ogcmap_setQueryLayer;
  this.queryLayerURL = ogcmap_queryLayerURL;
  this.queryLayerURLAjax = ogcmap_queryLayerURLAjax;
  this.queryUI = ogcmap_queryUI;
  this.queryAjax=ogcmap_queryAjax;
  this.showLoading = ogcmap_showLoading;
  this.hideLoading = ogcmap_hideLoading;
  this.testLoaded = ogcmap_testLoaded;
  this.drawPts = ogcmap_drawPts;
  this.getSelectionPoint = ogcmap_getSelectionPoint;
  this.transferPoints = ogcmap_transferPoints;
  this.adjustExtent = ogcmap_adjustExtent;
  this.postWrite = ogcmap_postWrite;
  this.writeLabels = ogcmap_writeLabels;
  this.capabilitiesURL = ogcmap_capabilities_url;
  this.init = ogcmap_init;
  this.serVisible = ogcmap_serVisible;
  this.crearVincle = ogcmap_crearVincle;
  this.muestraZoomEscala = ogcmap_muestraZoomEscala;
  //10 NOV
  this.serVisible = ogcmap_serVisible;
  //13 dic
  //this.cargarC=ogcmap_cargarC;
  //this.guardarC=ogcmap_guardarC; 
  //5 maig
  this.eliminarServidor = ogcmap_eliminarServidor;
  this.agregarCapa = ogcmap_agregarCapa;
  this.eliminarCapa = ogcmap_eliminarCapa;
  //28 nov 2007
  this.zoomLevel = ogcmap_zoomLevel;
  //23 gen 2008 
  this.posaOffset=idec_posaOffset;
  // initialization
  
  this.zoomInicial=ogcmap_zoomInicial;
  
  this.init();
  
  this.zoomCentre=ogcmap_zoomCentre;
  
}

//creates a new ogcmap, inserts it into the global map array, and returns the map object created
function addOGCMap(prefix,width,height,srs,xmin,ymin,xmax,ymax,baseDir,skin,toolbar,editType,query,leyenda) {
  var n = g_ogcMaps.length;
  prefix = prefix + "_g"+n+"_";
  var map = new ogcMap(n,prefix,width,height,srs,xmin,ymin,xmax,ymax,baseDir,skin,toolbar,editType,query,leyenda);
  g_ogcMaps[n] = map;
  return map;
}

var xmlImg = makeObject();

function idec_escriuMapa(x0,y0,x1,y1){
	var caixa=new Array();
	caixa[0]=x0;
	caixa[1]=y0;
	caixa[2]=x1;
	caixa[3]=y1;
	caixa=map.adjustExtent(caixa);
	coordInici[0]=caixa[0];
	coordInici[1]=caixa[1];
	coordInici[2]=caixa[2];
	coordInici[3]=caixa[3];
	var caixaBB=caixa[0]+","+caixa[1]+","+caixa[2]+","+caixa[3];
	var tipp=tipusAplicacio;
	if(appIntern==1){
		tipp="Intern";
	}
	var parametres="mapaRefe.jsp?caixaBB="+caixaBB+"&codiMun="+codiEmail+"&tipus="+tipp+"&host="+document.location.host;
	xmlImg.open('GET',parametres,true);
	xmlImg.setRequestHeader("Content-Type", "text/html"); 
	xmlImg.onreadystatechange = parseImg2; 
	xmlImg.send('');
}

function  interaccio(app,tipus){
var parametres="interaccio.jsp?app="+app+"&tipus="+tipus+"&";
	xmlImg.open('GET',parametres,true);
	xmlImg.setRequestHeader("Content-Type", "text/html"); 
	xmlImg.onreadystatechange = function res(){}; 
	xmlImg.send('');
}



function parseImg2(){
	if(xmlImg.readyState == 1){}
	if(xmlImg.readyState == 4){ 
		if(xmlImg.status == 200){
			document.getElementById('mapaSituacio').innerHTML=xmlImg.responseText;
		}
	}
}   

function idec_escriuCerques(tipus,posLeft){
	a='<table width="100%" border="0" cellspacing="0" cellpadding="0" >';
	if(tipus !="Urbanisme"){
	a +='<tr><td class=\"menu\" colspan="2">Cercar adre&ccedil;a</td>'; 
	a +=' <td colspan="2" height="7">'; 
	a +='<div align="left">';
	a +='</div>';
 	a +='</td></tr>';}
	a +='<tr>';
	if((codiMun.length < 4)&&(tipusAplicacio=="Carrerer")){
		a +='</tr><td> ';
		a +='<select class="text" style="width:150px" onchange="codiMun=this.value" >';
		codiMun=comarca[0][0];
		for(i=0;i < comarca.length;i++){
			a +='<option  value="'+comarca[i][0]+'">'+comarca[i][1]+'</option>';
		}
		a +='</select>';
		a +='</td><tr> ';
	}
	a +='<td class="text" >Tipus:';
	a +='<br>'; 
	a +='<select class="text" id="tipusCarrer" name="tipusCarrer">';
		a +='<option value="C">Altres...</option>';
	    a +='<option value="Avinguda">Avinguda</option>';
	    a +='<option value="Carrer" selected>Carrer</option>';
	    a +='<option value="Camí">Camí</option>';
	    a +='<option value="Parc">Parc</option>';
	    a +='<option value="Passeig">Passeig</option>';
	    a +='<option value="Plaça">Plaça</option>';
	    a +='<option value="Passatge">Passatge</option>';
	    a +='<option value="Rambla">Rambla</option>';
	    a +='<option value="Ronda">Ronda</option>';
	    a +='<option value="Travessera">Travessera</option>';
	    a +='<option value="Via">Via</option>';
	    a +='<option value="Vial">Vial</option>';
    a +='</select>';
    a +='</td></tr><tr>'; 
    a +='<td class="text">Carrer:';
    a +='<br>'; 
    a +='<input class="text" id="nomCarrer" size="20" onkeyDown="idec_capturaTecla(event);" name="nomCarrer">';
    a +='</td></tr><tr>'; 
    a +='<td class="text" >N&uacute;mero:';
    a +='<br>'; 
    a +='<input class="text" id="numCarrer" size="5" onkeyDown="idec_capturaTecla(event);" name="numCarrer">';
    a +='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class="botoMarcGroc" onMouseOver="this.className = \'botoGroc\'" onClick="idec_cercaCarrer()" onMouseOut="this.className = \'botoMarcGroc\'" type="button" value="Cercar" name="cerca">';
	a +="</td></tr></table>";
	return a;
}


//18 sep 2007
function escriuInterseccio(valor,origen){
if(origen==0){ //carrerer normal
var a='Carrer:<br><input class="text" id="nomCarrer" size="20" onkeyDown="idec_capturaTecla(event);" name="nomCarrer">';

var b='Carrer1:<input style="height:18px" class="text" id="nomCarrer" size="20" onkeyDown="idec_capturaTecla(event);" name="nomCarrer">';
b +='Carrer2:<input style="height:18px" class="text"  id="nomCarrer2" size="20" onkeyDown="idec_capturaTecla(event);" name="nomCarrer2">';

var c='N&uacute;mero:';
    c +='<br><input class="text" id="numCarrer" size="5" onkeyDown="idec_capturaTecla(event);" name="numCarrer">';
    c +='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class="botoMarcGroc" onMouseOver="this.className = \'botoGroc\'" onClick="idec_cercaCarrer()" onMouseOut="this.className = \'botoMarcGroc\'" type="button" value="Cercar" name="cerca">';

var d='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class="botoMarcGroc" onMouseOver="this.className = \'botoGroc\'" onClick="idec_cercaCarrer()" onMouseOut="this.className = \'botoMarcGroc\'" type="button" value="Cercar" name="cerca">';

if(valor){
document.getElementById('2car').innerHTML=d;
document.getElementById('1car').innerHTML=b;
}else{
document.getElementById('2car').innerHTML=c;
document.getElementById('1car').innerHTML=a;
}

}else{

var a='N&uacute;mero:';
var b='Carrer2:';

var c ='<input class="text1" id="numCarrer" size="4" onkeyDown="idec_capturaTecla(event);" name="numCarrer">';
var d='<input class="text1" id="nomCarrer2" size="18" onkeyDown="idec_capturaTecla(event);" name="nomCarrer2">';

}

if(valor){
document.getElementById('numCarrer').id="nomCarrer2";
//document.getElementById('numCarrer').name="nomCarrer2";
document.getElementById('1car').innerHTML=b;
}else{

document.getElementById('1car').innerHTML=a;
document.getElementById('nomCarrer2').id="numCarrer";
//document.getElementById('nomCarrer2').name="numCarrer";
}



}

//Funcions de cerques
function capturaTecla(e,valor) {
	if(document.all){
    	tecla=event.keyCode;
    }else{
    	tecla=e.which; 
    }
    if(tecla==13){
    	while (tecla==13){
			if(capes="txtMetaNom"){idec_metadades(valor,'gestor');}
        	else{cercarDades(valor);}
          	break;
		}
    }
}
 
 function capturaTeclaCadastre(e,valor) {
	if(document.all){tecla=event.keyCode;}else{tecla=e.which; }
    if(tecla==13){
    	while (tecla==13){
			idec_cercaCadastre(valor,0);
          	break;
		}
    }
}
 
    
function idec_capturaTecla(e) {
	if(document.all){
    	tecla=event.keyCode;
    }else{
    	tecla=e.which; 
    }
    if(tecla==13){
      	while (tecla==13){
         	idec_cercaCarrer();
          	break;
        }
    }
}  
      
function canviValor(valor){
	valor=valor.toUpperCase();
	accent=new Array('À','È','É','Í','Ì','Ò','Ó','Ú','Ù','Ï','Ü');
	noaccent=new Array('A','E','E','I','I','O','O','U','U','I','U');
	for(i=0;i<accent.length;i++){
		if (valor.indexOf(0,accent[i])){
			valor=valor.replace(accent[i],noaccent[i]);
		}
	}
	return valor;
}
   
//prova ajax
function makeObject(){
	var naveg; 
	var browser = navigator.appName; 
	if(browser == "Microsoft Internet Explorer"){
		naveg = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		naveg = new XMLHttpRequest();	
	}
	return naveg;
}

//AJAX for coordinates
var htmlCoord=makeObject();
function ajaxCoord(sURL){

htmlCoord.open('GET', sURL, true);
htmlCoord.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1"); 
htmlCoord.onreadystatechange = parseInfoCoord; 
htmlCoord.send('');
//htmlCoord.send(null);
}

function parseBBOX(xurro){
	var p0=new Array();
	var p1=new Array();
	var bbox=new Object();
	
	xurro=trim(xurro);
	
	xurro=xurro.split(",");
	
	bbox.x0=trim(xurro[0]);
	bbox.y0=xurro[1];
	bbox.x1=xurro[2];
	bbox.y1=xurro[3];
	//alert("1"+xurro[1]);
	return bbox;
	

}

function parseInfoCoord(){


if(htmlCoord.readyState == 1){}
if(htmlCoord.readyState == 4){ 

		if(htmlCoord.status == 200){
			
//escriuValorInfo(htmlCoord.responseText);
//var coordTemp

var cof=parseBBOX(htmlCoord.responseText);
coordTemp[0]=cof.x0;
coordTemp[1]=cof.y0;
coordTemp[2]=cof.x1;
coordTemp[3]=cof.y1;

//return cof;
}
}
//escriuValorInfo('')
}   
//end Ajax for coordinates
//Funcions per trim strings


function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}


function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}


function trim( value ) {
	
	return LTrim(RTrim(value));
	
}


var xmlDoc = makeObject();
var tpPet=false;
function ajax(sURL){
	xmlDoc.open('GET', sURL, true);
	
if(sURL.indexOf("peticio=getMapaWMS")!=-1){tpPet=true;}
	xmlDoc.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1");
	xmlDoc.onreadystatechange = parseInfo; 
	xmlDoc.send('');
}


var winGInfo;
function parseInfo(){
	document.getElementById('posFitxes').innerHTML="";
	tipus="estacions";
	//alert(tpPet);
	if(xmlDoc.readyState == 1){
		if(tpPet){
		document.getElementById('avis').style.display="none";
		document.getElementById('fooWS').style.display="none";
		}else{
		document.getElementById('avis').style.display="block";
		}
		}
	if(xmlDoc.readyState == 4){ 
		escriuValorInfo('');
		if(xmlDoc.status == 200){
			document.getElementById('avis').style.display="none";
			var resposta=xmlDoc.responseText;
			if(resposta.indexOf('fondotaula.gif')!=-1){
			//document.getElementById('posFitxes').style.display='block';
			document.getElementById('posFitxes').innerHTML=xmlDoc.responseText;
			if(tpPet){
		document.getElementById('fooWS').style.display="block";}tpPet=false;
			}else{
/*			
winInfo= new Window('Info', {className: "alphacube",opacity:1,zIndex:150,top:100, left:300, width:265, height:275,minimizable:false,maximizable:false, showEffect:Element.show, hideEffect: Effect.SwitchOff});			
	winInfo.getContent().innerHTML=xmlDoc.responseText;
	winInfo.toFront();
	winInfo.setDestroyOnClose(true);
	winInfo.show();
*/

winGInfo=dhtmlwindow.open("winGInfo", "inline", xmlDoc.responseText, "Info", "width=265px,height=275px,left=350px,top=95px,resize=1,scrolling=1");
	

	
	


	}
	
		}
	}
}

var xmlDoc2 = makeObject();
function idec_ajax2(sURL){
	xmlDoc2.open('GET', sURL,true);
	xmlDoc2.setRequestHeader("Content-Type", "text/html"); 
	xmlDoc2.onreadystatechange = parseInfo2; 
	xmlDoc2.send('');
}

function parseInfo2(){
	document.getElementById('posFitxes2').innerHTML="";
	if(xmlDoc2.readyState == 1){}
	if(xmlDoc2.readyState == 4){ 
		if(xmlDoc2.status == 200){
			document.getElementById('posFitxes2').innerHTML=xmlDoc2.responseText;
		}
	}
}   

//28 marzo
var xmlDoc4 = makeObject();
function getFeatureAjax(sURL){
	xmlDoc4.open('GET','infoAjax.jsp?'+sURL,true);
	xmlDoc4.setRequestHeader("Content-Type", "text/html"); 
	xmlDoc4.onreadystatechange = parseInfoAjax; 
	xmlDoc4.send('');
}

function parseInfoAjax(){
	tipus="estacions";
	if(xmlDoc4.readyState == 1){escriuValorInfo('...');}
	if(xmlDoc4.readyState == 4){ 
		if(xmlDoc4.status == 200){
			escriuValorInfo(xmlDoc4.responseText);
		}
	}
}   

var idObjecte="";
var capaEqui="";
var capaM="capa";
var capaC="capaC";
var tipusAmbit="CODMUN"; 
 
function cercarDades(valor){
	idObjecte="";
	var tipu="";
	var topotext1="";
	var topotext="";
	
	if(valor=="txtMuniCom"){
	tipu=document.getElementById('Escull').value;
	
	}else if(valor=="txtToponims"){
	tipu="Toponims"	
	}
	
	
	var topotext1=document.getElementById(valor).value;
	var topotext=canviValor(topotext1);	
	ajax("cercaAjax.jsp?capa="+tipu+"&valor="+topotext+"&cerca=0");
}

function escriuValorInfo(valor){
	var capaEscriu=document.getElementById('posInfo');
    
	capaEscriu.visibility='visible';
	capaEscriu.innerHTML=valor;
}

function capturaID(id,valor){
	if (idObjecte ==""){
		idObjecte=id;
	}else{
	 	document.getElementById(idObjecte).className='boto_normal';
	 	idObjecte=id;
	}
	escriuValorInfo(valor);
}
 
function capturaIDEqui(id,equipament){
	if (idObjecte ==""){
 		idObjecte=id;
 		capaEqui=equipament;
 	}else{
 		document.getElementById(idObjecte).className='boto_normal';
 		idObjecte=id;
   		capaEqui=equipament;
 	}
}
var tipusCarrerCadastre="CL";
var nomCarrerCadastre="";
var provinciaCarrerCadastre="";
var nunicipiCarrerCadastre="";

function parseCarrerCadastre(tipus,carrer){
		
tipusCarrerCadastre=tipus;
nomCarrerCadastre=carrer;	

e('nomCarrerCadastre').value=nomCarrerCadastre;	
}


function e(id){
	
	return document.getElementById(id);
}

function tancaFR(){
	
winGInfo.close();
	
//winInfo.setDestroyOnClose(true);	
//winInfo.close();		
}


function resultats(estat,capaAct){
	//winInfo.close();
	winGInfo.close();
	var cercaT="";
 	if (capaAct=="Municipis"){cercaT="1"}
 	if (capaAct=="Toponims"){cercaT="2"}
  	if (capaAct=="Comarques"){cercaT="3"}
  	if (capaAct=="localrettext"){cercaT="4"}
  	if (capaAct=="industria"){cercaT="5"}
 	if(idObjecte==""){alert("Has de seleccionar un resultat")}
 	else{
	 	if (estat=='no'){
			document.getElementById('posFitxes').style.visibility='hidden'; 	
		}else{
	 		ajax("cercaAjax.jsp?cerca="+cercaT+"&capa="+capaAct+"&valor="+idObjecte);
		}
	}
} 

//activa las capas de por el menu de propiedades
//20 jul
function activaCapesURL(capes){
	var cap=new Array(capes);
	cap=capes.split(",");
	if (tipusAplicacio == "Visual"){
		for (var i=0; i < map.servidores.length; i++) {
			var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
			//alert(nombrechk);
			document.getElementById(nombrechk).checked = false;
			map.servidores[i][3] = false;
		}
		for (var i=0; i < map.servidores.length; i++) {
			for (var j=0; j< cap.length; j++) {
		
			
				if(map.servidores[i][2] == cap[j]){
			  	//if(map.servidores[i][2].indexOf(cap[j])!=-1){
			  		var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
			  		document.getElementById(nombrechk).checked = true;
			  		map.servidores[i][3] = true;
			  	}	
			}
			map.redraw(1);
		}
	}else{
		for (var i=5; i < map.servidores.length; i++) {
			var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
			document.getElementById(nombrechk).checked = false;
			map.servidores[i][3] = false;
		}
		for (var i=5; i < map.servidores.length; i++) {
			for (var j=0; j< cap.length; j++) {
				if(map.servidores[i][2] == cap[j]){	
			  	//if(map.servidores[i][2].indexOf(cap[j])!=-1){
			  		var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
					document.getElementById(nombrechk).checked = true;
					map.servidores[i][3] = true;
			  	}
			}
			map.redraw(1);
		}
	}
}

//20 jul fin
//16 Jul 2007

function ensenyaMSG(){
if (language=="cat"){alert("Cartografia de la metadada no disponible.\nEs mostrarà la zona geogràfica corresponent a la seva caixa de coordenades");}
if (language=="ca"){alert("Cartografia de la metadada no disponible.\nEs mostrarà la zona geogràfica corresponent a la seva caixa de coordenades");}
if (language=="cas"){alert("Cartografía del metadato no disponible.\nSe mostrará la zona geográfica correspondiente a su caja de coordenadas");}
if (language=="eng"){alert("Metadata cartography not available.\nYou will see metadata bounding box");}

}

function activaCapesNom(capes){
//alert(capes);
if(capes=="orto5mMD"){capes="orto5m"; ensenyaMSG();}

//alert(capes);
	var cap=new Array(capes);
	cap=capes.split(",");
	if (tipusAplicacio == "Visual"){
		for (var i=0; i < map.servidores.length; i++) {
			var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
			//alert(nombrechk);
			document.getElementById(nombrechk).checked = false;
			map.servidores[i][3] = false;
		}
		for (var i=0; i < map.servidores.length; i++) {
			for (var j=0; j< cap.length; j++) {
					
				if(map.servidores[i][1] == cap[j]){
			  	//if(map.servidores[i][2].indexOf(cap[j])!=-1){
			  		var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
			  		document.getElementById(nombrechk).checked = true;
			  		map.servidores[i][3] = true;                  
                      cambiar(getPosition(map.layers,map.layers[map.servidores[i][0]].srvname));
			  		
			  	}	
			}
			map.redraw(1);
		}
	}else{
		for (var i=5; i < map.servidores.length; i++) {
			var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
			document.getElementById(nombrechk).checked = false;
			map.servidores[i][3] = false;
		}
		for (var i=5; i < map.servidores.length; i++) {
			for (var j=0; j< cap.length; j++) {
				if(map.servidores[i][1] == cap[j]){	
			  	//if(map.servidores[i][2].indexOf(cap[j])!=-1){
			  		var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
					document.getElementById(nombrechk).checked = true;
					map.servidores[i][3] = true;
			  	}
			}
			map.redraw(1);
		}
	}
}


function activaCapaxServidor1(capes,url){

var esta=0;
var cap=new Array(capes);
	cap=capes.split(";");
	for (k=0; k<map.layers.length; k++){
		if(map.layers[k].url==url){
			for (var j=0; j< cap.length; j++) {
				esta = 0;
				for (var i=0; i < map.servidores.length; i++) {
					if (map.servidores[i][0] == k){
						if(map.servidores[i][2].indexOf(cap[j])!=-1){
							var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
							document.getElementById(nombrechk).checked = true;
							map.servidores[i][3] = true;
							esta=1;
						}	
					}	
				}
				if (esta == 0){
					map.agregarCapa(k,cap[j],cap[j]);
				}
			}
			
		}
			map.redraw(1);
	}
}
/*
Validate if server exists
*/
function existURL(url){
	var sUrl = "";
	var esta = -1;
	for (i=0; i<map.layers.length; i++){
		sUrl = map.layers[i].url;
		if (sUrl == url){
			esta = i;
			break;
		}
	}
	return esta;
}

//Afegirr i treure capes
//15 may
function ogcmap_eliminarServidor(index){
	
	desactiveServ(index);
	var tempLayer = new Array();
	tempLayer = this.layers;
	var ntempLayer = tempLayer.eliminarElemento(index);
	var tempServ = this.servidores;
	var ntempServ = tempServ.modificar(index, null);
	this.layers = ntempLayer;
	this.servidores = ntempServ;
	
	//alert(this.layers.length);
	//alert(this.servidores.length);
	this.layerUI();
}

Array.prototype.eliminarElemento = function (num){
	var	pos = parseInt(num);
	var finalA;
	if (pos >= this.length){
		alert("fuera del vector");
	}else{
		var inicio = this.slice(0,pos);
		finalA = this.slice((pos+1), this.length);
		//alert("inicio: " + inicio + " final: " + final);
		var nuevoA = inicio.concat(finalA);
		//alert("nuevo: " + nuevo + " largo: " + nuevo.length);
		return nuevoA;
	}
}

Array.prototype.insertarElemento = function (num, elemento){
	var	pos = parseInt(num);
	var nuevoA = new Array();
	if (pos > this.length){
		alert("fuera del vector");
	}
	else if (pos == this.length){
		nuevoA = this.concat(elemento);
		return nuevoA;
	}
	else{
		var inicio = this.slice(0,pos);
		inicio.concat(elemento);
		var finalA = this.slice(pos, this.length);
		//alert("inicio: " + inicio + " final: " + final);
		nuevoA = inicio.concat(finalA);
		//alert("nuevo: " + nuevoA + " largo: " + nuevo.length);
		return nuevoA;
	}
}

Array.prototype.modificar = function (pos, valores){
	var aparece = null;
    var sin, modif;
	var temp = new Array;
	for (var i = 0; i < this.length; i++){
		//alert(this[i][0]);
		if (this[i][0] == pos){
			if (aparece == null){
				aparece = i;
				//alert(aparece);
			}
		}else{
			temp[temp.length] = this[i];
		}
	}
	//alert(temp);
	if (valores == null){
		modif = temp;
	}else{
		//alert(aparece);
		if (aparece != null){
			modif = temp.insertarElemento(aparece, valores);
		}else{
			alert("no se puede modificar ningun registro");
			modif = this;
		}
	}
	//alert(modif);
	return modif;
}

function desactiveServ(numServ){
	for (var i=0; i < map.servidores.length; i++) {
		if(map.servidores[i][0] == numServ){
		  	var nombrechk = map.servidores[i][0] + map.servidores[i][1];
		  	//document.getElementById(nombrechk).checked = false;
		  	map.servidores[i][3] = false;
		}
	  	map.redraw(1);
	}
}
//edicio
function ogcmap_agregarCapa(index, nomCap, titolCap){
	//alert("agregarCapa " + nomCap);
	if (this.layers[index].name == ""){
		this.layers[index].name = nomCap;
		this.layers[index].title = titolCap;
	}else{
		this.layers[index].name = this.layers[index].name + "," + nomCap;
		this.layers[index].title = this.layers[index].title + "," + titolCap;
	}
	var nuevoServ = new Array(); 
	for (i = 0; i < this.servidores.length; i++){
		if (this.servidores[i][0] == index){
			nuevoServ[nuevoServ.length] = this.servidores[i];
		}
	}
	//alert(nuevoServ.length);
	if (nuevoServ.length == 0){
		var elemento = new Array(index, nomCap, titolCap, true,  nuevoServ[0][4], nuevoServ[0][5], nuevoServ[0][6]);	
	}else{
		var elemento = new Array(index, nomCap, titolCap, true,  this.layers[index].srvname, nuevoServ[0][5], nuevoServ[0][6]);
	}
	nuevoServ[nuevoServ.length] = elemento;
	var modif = this.servidores.modificar(index, nuevoServ);
	this.servidores = modif;
	this.layerUI();
	cambiar(index);
}

function ogcmap_eliminarCapa(index, nomCap){
	//alert("eliminar " + nomCap);
	var nuevoServ = new Array();
	var numCap = 0;
	for (k = 0; k < this.servidores.length; k++){
		if (this.servidores[k][0] == index){
			numCap = numCap + 1;
		}
	}
	//alert("Capas: " + numCap);
	for (k = 0; k < this.servidores.length; k++){
		if ((this.servidores[k][0] == index) && (this.servidores[k][1] == nomCap)){
			var nombrechk = map.servidores[k][0] + map.servidores[k][1];
			//alert("desactivo " + k);
			desactivaCapa(nombrechk,nomCap);
			//alert("desactivo " + k);
			if (numCap > 1){
				nuevoServ = this.servidores.eliminarElemento(k);
			}else{
				this.servidores[k][1] = "";
				this.servidores[k][2] = "";
				this.servidores[k][3] = false;
				nuevoServ = this.servidores;
			}
			k = this.servidores.length;
		}
	}
	this.servidores = nuevoServ;
	this.layerUI();
	cambiar(index);
}

//fi 16 jul 2007

//16 gener
function ogcmap_crearVincle(x,y,adreca){
	var cap = new Array();
	var retalla = new Array();
	var BBOX = redondear(map.cBounds[0],4)+","+redondear(map.cBounds[1],4)+","+redondear(map.cBounds[2],4)+","+redondear(map.cBounds[3],4);
	var factor=parseInt((map.cBounds[2]- map.cBounds[0])/2);	
	var str = servlet + "index.jsp?";	
	for (var i=0; i < map.servidores.length; i++) {
		var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
		if(document.getElementById(nombrechk).checked){
       
			retalla = map.servidores[i][2];
            
			if(retalla.indexOf(">")!=-1){
            fora=retalla.substring(retalla.indexOf("<"),retalla.indexOf(">")+1);
            
				cap += retalla.replace(fora,"")+",";
			}else{
				cap += map.servidores[i][2]+",";
			}


            }
	}
	cap = cap.substring(0,cap.length-1)
	str += "&capes=" + cap;
	var strVista = str + "&bbox=" + BBOX + "&";
	x = redondear(x,4);
	Y = redondear(x,4);
	str += "&x="+ x +"&y="+ y +"&zfactor="+ factor;
	if(adreca != null){
		if(adreca != ""){
			str += "&text=" + adreca;
		}
	}else{
		adreca="incidència";
	}
	var wInfo = "<html><head><title>"+adreca+"</title></head>";
	wInfo +='<link rel="stylesheet" href="css/'+key+'.css">';
	//var wInfo = "";
	wInfo +='<form name="frmVincle">';
	wInfo += "<div style=\"font-family: Verdada;font-size: 9px;color: #0000CC;position:absolute;width:450px;overflow:hidden\">";
	wInfo += "<table width=\"450px\" class=\"text\">"
	wInfo += "<tr><td><b>"+vin_punt+": </b></td><td><input class=\"text\" type=\"text\" value=\""+str+"\" size='50' ></td></tr>";
	wInfo += "<tr><td width=\"30%\"><b>"+vin_no_punt+": </b></td><td><input class=\"text\" type=\"text\" value=\""+strVista+"\" size='50' ></td></tr>";
	wInfo += "<tr><td width=\"30%\"><b>"+vin_coord+" X:</b></td><td><input class=\"text\" type=\"text\" value=\""+x+"\" size='50' ></td></tr>";
	wInfo += "<tr><td width=\"30%\"><b>"+vin_coord+" Y:</b></td><td><input class=\"text\" type=\"text\" value=\""+y+"\" size='50' ></td></tr>";
	wInfo += "<tr><td width=\"30%\"><b>"+vin_caixa_coord+":</b></td><td><input class=\"text\" type=\"text\" value=\""+BBOX+"\" size='50' ></td></tr>";
	wInfo += "</div>";
	wInfo += "</form>";
	wInfo += "</html>";
	/*
	winInfo = new Window('Info', {className: "alphacube",opacity:1,zIndex:1500,top:100, left:350, width:450, height:250,minimizable:false,maximizable:false, showEffect:Element.show, hideEffect: Effect.SwitchOff});
	winInfo.getContent().innerHTML = wInfo;
	winInfo.toFront();
	winInfo.setDestroyOnClose();
	winInfo.show();
	*/
	var winLInfo=dhtmlwindow.open("winLInfo", "inline", wInfo, "Info", "width=480px,height=250px,left=350px,top=95px,resize=1,scrolling=1");
	
	
	
}

function activaCapaxServidor(capes,url){
//alert(map.servidores.length);
//alert(map.layers.length);
var esta=0;
var cap=new Array(capes);
	cap=capes.split(";");
	for (k=0; k<map.layers.length; k++){
		if(map.layers[k].url==url){
			for (var j=0; j< cap.length; j++) {
				esta = 0;
				for (var i=0; i < map.servidores.length; i++) {
					if (map.servidores[i][0] == k){
						if(map.servidores[i][2].indexOf(cap[j])!=-1){
							var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
							document.getElementById(nombrechk).checked = true;
							map.servidores[i][3] = true;
							esta=1;
						}	
					}	
				}
				
			}
			
		}
			map.redraw(1);
	}
}


function activaCapes(id, nom){
  document.getElementById(id).checked = true;
  //10 jul
  var num = id.indexOf("_");
  var idcap = id.substring(0,num);
  var idcap = parseInt(idcap);
  var nom = "";
  nom = id.substring(num+1,id.length);
  //10 jul fin
  for (var i=0; i<map.servidores.length; i++) {
	if (map.servidores[i][0] == idcap) {
		if (map.servidores[i][1] == nom){
	  		map.servidores[i][3] = true;
	  	}	
	}
  }
  map.redraw(1);
}

//cambia la imagen de las carpetas del arbol de la leyenda
function cambiar(item) {
   obj=document.getElementById(item);
   visible=(obj.style.display!="none");
   var t="chk_"+item;
   if (visible) {
     
     if(document.getElementById(t).checked){
     obj.style.display="block";
     }else{
     obj.style.display="none";
     }     
    // keyr.innerHTML="<img src='" + map.baseDir + "skin/" + map.skin + "/images/folderb.gif' width='30' height='16' hspace='0' vspace='0' border='0'>";
   }
   else {
      obj.style.display="block";
     // keyr.innerHTML=" <img src='" + map.baseDir + "skin/" + map.skin + "/images/textfolderb.gif' width='30' height='16' hspace='0' vspace='0' border='0'>";
   }
}

function cambiarG(item,text) {
   obj=document.getElementById('novetats');
   visible=(obj.style.display!="none")
  // keyr=document.getElementById("g" + item);
   if (visible) {
     obj.style.display="none";
    // keyr.innerHTML="<img src='" + map.baseDir + "skin/" + map.skin + "/images/folder.gif' width='30' height='16' hspace='0' vspace='0' border='0'><font color=\"red\"><b>&nbsp;"+text+"</b></font>";
   }
   else {
      obj.style.display="block";
    //  keyr.innerHTML="<img src='" + map.baseDir + "skin/" + map.skin + "/images/textfolder.gif' width='30' height='16' hspace='0' vspace='0' border='0'><font color=\"red\"><b>&nbsp;"+text+"</b></font>";
   }
}

//desactiva la capa por medio del menu de propiedades
function desactivaCapa(id, nom){
  document.getElementById(id).checked = false;
  //10 jul
  var num = id.indexOf("_");
  var idcap = id.substring(0,num);
  var idcap = parseInt(idcap);
  var nom = "";
  nom = id.substring(num+1,id.length);
  //10 jul fin
  for (var i=0; i<map.servidores.length; i++) {
	if (map.servidores[i][0] == idcap) {
		if (map.servidores[i][1] == nom){
	  		map.servidores[i][3] = false;
	  	}	
	}
  }
  map.redraw(1);
}

var capetrans = "";

function idec_retoca(id){



	var rut=document.getElementById(id).src;
  
    
    
    
	//var cc="Problemes amb el servidor <br><a href='"+rut+"' target='_blank'>Veure petició GetMap</a>";	
	//document.getElementById('posInfo').innerHTML=cc;
	if (document.getElementById(id).src.indexOf("gis.localret.cat") != -1){
		var src = document.getElementById(id).src;
		src = src.replace("http://gis.localret.cat/wmsequipdemo/request.aspx?","http://delta.icc.es/cgi-bin/mapserv?map=/opt/idec/dades/umn/localret_equip.map&");
		document.getElementById(id).src = src;
	}else{
		document.getElementById(id).src="images/blank.gif";
	}
}

function idec_retocaGLG(id){
alert("No es pot obtenir la llegenda de la capa");
//var rut=document.getElementById(id).src;
var im="div"+id;

document.getElementById(im).innerHTML="";
//document.getElementById(id).src="images/blank.gif";



}


function menuPropietats(capes,nom,titulo,organ,e){
	var texte= ""
	var pro=document.getElementById('propietats');
	var trt=nom.length;
	var tr1=nom.indexOf('>');
	capes.replace(' ','&nbsp;');
	if(nom.indexOf('>')!=-1){
		nom=nom.substring(parseInt(tr1+1),trt);
	}
	capetrans = capes;
	pro.style.visibility='visible';
	if (document.all){
		x = e.clientX - 10;
		y = e.clientY - 10;
	}else{
		x = e.pageX - 10;
		y = e.pageY - 10;
	}
	pro.style.left=x+"px";
	pro.style.top=y+"px";
	texte+='<table class="text" cellpadding="1" cellspacing="1" border="0" width="90" >';
	texte+='<tr><td class="normal1" style="font-size:9px;" onclick="activaCapes(\'' + capes + '\',\'' + nom + '\');" onmouseover="if (this.className==\'normal1\'){this.className=\'sobre1\'}" onmouseout="if (this.className==\'sobre1\'){this.className=\'normal1\'}">'+mn_lyAc+'</td></tr>';
	texte+='<tr><td class="normal1" style="font-size:9px;" onclick="desactivaCapa(\''+ capes + '\',\'' + nom + '\');" onmouseover="if (this.className==\'normal1\'){this.className=\'sobre1\'}" onmouseout="if (this.className==\'sobre1\'){this.className=\'normal1\'}">'+mn_lyDe+'</td></tr>';
	texte+='<tr><td class="normal1" style="font-size:9px;" onclick="transparencia(\''+ capes + '\',event);" onmouseover="if (this.className==\'normal1\'){this.className=\'sobre1\'}" onmouseout="if (this.className==\'sobre1\'){this.className=\'normal1\'}">'+mn_lyTr+'</td></tr>';
	if(titulo.indexOf('undefined') == 0 || titulo == ""){
	texte+='<tr><td class="normal1" style="font-size:9px;"  onclick="idec_metadades(\'NO\',\'' + organ + '\');" onmouseover="if (this.className==\'normal1\'){this.className=\'sobre1\'}" onmouseout="if (this.className==\'sobre1\'){this.className=\'normal1\'}">'+mn_lyMd+'</td></tr>';
	}else{
		texte+='<tr><td class="normal1" style="font-size:9px;"  onclick="idec_metadades(\'' + titulo + '\',\'' + organ + '\');" onmouseover="if (this.className==\'normal1\'){this.className=\'sobre1\'}" onmouseout="if (this.className==\'sobre1\'){this.className=\'normal1\'}">'+mn_lyMd+'</td></tr>';
	}
	texte+='</table>';
	pro.innerHTML=texte;
}

function transCoordUTMxGEO(){
latlon = new Array(2);
    var x, y, zone, southhemi;
    xmin =map.cBounds[0];
    ymin =map.cBounds[1];
    xmax =map.cBounds[2];
    ymax =map.cBounds[3];
    x = parseFloat (xmin);
    y = parseFloat (ymin);
    zone = parseFloat (31);
	southhemi = false;
	UTMXYToLatLon (x, y, zone, southhemi, latlon);
    xmin = RadToDeg (latlon[1]);
    ymin = RadToDeg (latlon[0]);
	var xn=redondear(xmin,4);
	var yn=redondear(ymin,4);
	x = parseFloat (xmax);
    y = parseFloat (ymax);
    zone = parseFloat (31);
    southhemi = false;
	UTMXYToLatLon (x, y, zone, southhemi, latlon);
    xmax = RadToDeg (latlon[1]);
    ymax = RadToDeg (latlon[0]);
	var xx=redondear(xmax,4);
	var yx=redondear(ymax,4);
	var mdBoox=new Object();
	mdBoox.x0=xn;
	mdBoox.y0=yn;
	mdBoox.x1=xx;
	mdBoox.y1=yx;
	return mdBoox;
}

function idec_resoldreIdioma(idioma){
if(idioma=="cat"){idioma="ca";}
return idioma;
	
}

function srcFrame(valor,frameid){
document.getElementById(frameid).src=valor;
}


function idec_metadades_servei(organisme,url){
var nomIdiomaCurt=idec_resoldreIdioma(language);


var id = "&orgServei="+organisme;
var	peticio='clau=cidec&idioma='+nomIdiomaCurt+'&do=cercaServeis&'+id+'&';
        


var urlPet="http://delta.icc.cat/wefex/client?"+peticio;
	//tra
	var org=organisme.replace(/\+/g,' ');
    
    var infoMeta='<div id="sd1" style="position:absolute; width:100%; height:410px; z-index:1">';
        infoMeta +='<table width="99%" height="400" border="0" cellpadding="1" cellspacing="1">';
        infoMeta +='<tr><td class="text" colspan="2" style="font-size: 10pt" height="25">'+gui_Orga+':<b>'+org+'</b></td></tr>';
        infoMeta +='<tr><td class="text" colspan="2" style="font-size: 10pt" height="25">Url:<b>'+url+'</b></td></tr>';
        infoMeta +='<tr><td height="25" align="center"><input Onclick="srcFrame(\''+urlPet+'\',\'frMDS\');$(\'d01\').style.display=\'block\'" type="button" class="boto" name="Submit" value="'+xmd_cerca+'"></td>';
        infoMeta +='<td><div id="d01" style="display:none"><img src="images/load_layer.gif"</div></td></tr>';
        infoMeta +='<tr><td colspan="2"height="330" bordercolor="#FFCC00"><iframe FRAMEBORDER="0" id="frMDS" name="frMDS"width="100%" height="100%" src="" ></iframe></td></tr>';
        infoMeta +='</table>';
        infoMeta +='</div>';
    
    
    
    
    
    
    
    
    
//var infoMeta='<iframe width=98% height=98%   frameborder=\"0\" src="'+urlPet+'">Searching...</iframe>'; 


    
var winMD=dhtmlwindow.open("winMD", "inline", infoMeta, "OGC-WMS", "width=510px,height=425px,left=350px,top=95px,resize=1,scrolling=1");	
	
//document.getElementById('avis').style.display="none";










}


function idec_metadades(capes,nom){
	var mbBoox=transCoordUTMxGEO();
	var addNSb=0;
	var nomIdiomaCurt=idec_resoldreIdioma(language);
	//var caixaBBOXMD='bbox='+(mbBoox.x0)+','+(mbBoox.y0)+','+(mbBoox.x1)+','+mbBoox.y1;
    
    var caixaBBOXMD='bbox='+(mbBoox.y0)+' '+(mbBoox.x0)+','+(mbBoox.y1)+' '+mbBoox.x1;
    
	var peticio="";
	var id = "";
if(capes=="txtMetaNom"){
	nom=document.getElementById('comboOrg').value;
	nom=nom.replace('(Totes les organitzacions)','');
	capes=document.getElementById('txtMetaNom').value;
	var clau=document.getElementById('txtMetaKey').value;
	id = "cercaRapida=*"+capes+"*,*"+capes+"*&org="+nom+"&keyword="+clau;	
		if(document.getElementById('caixaMD').checked){
		peticio='idioma='+nomIdiomaCurt+'&do=cercaDatasetsClient&'+id+'&'+caixaBBOXMD+'&';
		}else{
		peticio='idioma='+nomIdiomaCurt+'&do=cercaDatasetsClient&'+id+'&';
		}

}else if(capes=="NO"){
 id = "&org="+nom;
	 peticio='idioma='+nomIdiomaCurt+'&do=cercaDatasetsClient&'+id+'&'+caixaBBOXMD+'&';
        
}else{
	//if(nom.indexOf('Institut')==-1){capes="";}
	
    if(capes.indexOf('#')!=-1){capes=capes.replace('#','');caixaBBOXMD="";}
    
	 id = "cercaRapida=*"+capes+"*,*"+capes+"*&org="+nom;
	 peticio='idioma='+nomIdiomaCurt+'&do=cercaDatasetsClient&'+id+'&'+caixaBBOXMD+'&';
	 //alert(peticio);
}	

var urlPet="http://delta.icc.cat/wefex/client?"+peticio;
	//tra
	
    var infoMeta='<div id="sd1" style="position:absolute; width:100%; height:410px; z-index:1">';
        infoMeta +='<table width="99%" height="400" border="0" cellpadding="1" cellspacing="1">';
        infoMeta +='<tr><td height="10" align="center"><div id="d02" style="display:block"><img src="images/load_layer.gif"</div></td></tr>';
        infoMeta +='<tr><td height="400" bordercolor="#FFCC00"><iframe FRAMEBORDER="0" id="frMDD" name="frMDD" width="100%" height="100%" src="'+urlPet+'" ></iframe></td></tr>';
        infoMeta +='</table>';
        infoMeta +='</div>';
    
    
    
//var infoMeta='<iframe width=98% height=98%   frameborder=\"0\" src="'+urlPet+'">Searching...</iframe>'; 
	
	
	
    //document.getElementById('avis').style.display="block";
    
var winMD=dhtmlwindow.open("winMD", "inline", infoMeta, "MD-D", "width=530px,height=410px,left=350px,top=95px,resize=1,scrolling=1");	
	
//document.getElementById('avis').style.display="none";

}
var validaDIV=true;
function validaDIV1(){
document.getElementById('d02').style.display='none';
}
//14 NOv
function ogcmap_addLayer(url,
						srvname,
						name,
						title,
						transparent,
						visible,
						format,
						queryable,
						version,
						epsg,
						mdtitle,
						organismo,
						infoFormat,
						tiles,
						tematica,
						agrupacio,
						d_gml,
						org_vincle) {
					
	var fmt = format;
	var nombres = new Array();
	var capas = new Array();
	var visibles = new Array();
	var mdtitulo = new Array();
	var c_gml=new Array();
	var tema= new Array();
	var queryables = new Array();
	var num;
	var srvnombre = srvname;
	mdtitle=mdtitle.replace('\'',' '); 
	organismo=organismo.replace('\'',' '); 
    
	if ((!fmt) || (fmt == "undefined")){fmt = "image/png";}   
	// se divide el arreglo de las capas por comas
	//if(url.indexOf("galileo")!=-1){alert(d_gml);}
	if ((!d_gml) || (d_gml == "undefined")){d_gml = ";";} 
	if ((!org_vincle) || (org_vincle == "undefined")){org_vincle = "";} 
	
	//if(url.indexOf("galileo")!=-1){alert(d_gml);}
	
	if (title.indexOf(';') != -1) {
		nombres = title.split(";");
       
		capas = name.split(";");
		visibles = visible.split(";");
		mdtitulo = mdtitle.split(";");
		c_gml=d_gml.split(";");
		
		if ((!tematica) || (tematica == "undefined")){tematica = "referencia";} 
		if ((!agrupacio) || (agrupacio == "undefined")){agrupacio = 0;} 
			
		tema=tematica.split(";");
		
		num = nombres.length;
		if (queryable == true){
			queryable = "true";
			for (var i=0; i<num; i++) {
				queryables[i] = "true";
			}
		}
		else if (queryable == false){
			queryable = "false";
			for (var i=0; i<num; i++) {
				queryables[i] = "false";
			}
		}else{
			queryables = queryable.split(";");
		}
		
		for (var i=0; i<num; i++) {
			if (visibles[i] == "true") {
		  		visibles[i] = true;
		  	} 
		  	else { 
		  		visibles[i] = false;
		  	}
			if (queryables[i] == "true") {
		  		queryables[i] = true;
		  	} 
		  	else { 
		  		queryables[i] = false;
		  	}
		}
		//se crea el arreglo con las capas de los distintos servidores
        var timeI=0;
        var timeF=0;
		for (var i=0; i<num; i++) {
			this.servidores[this.servidores.length] = new Array(this.layers.length,capas[i],nombres[i],visibles[i],srvnombre,mdtitulo[i],organismo,queryables[i],tema[i],c_gml[i]);
		}
		visible = true;
		this.layers[this.layers.length] = new ogcmap_Layer(url,srvname,capas,nombres,transparent,visible,fmt,queryable,version,epsg,tiles,infoFormat,agrupacio,organismo,timeI,timeF,org_vincle); 
	}
	else {
	//alert("entro");
		if(visible=="false"){
			visible=false;
		}
		else if(visible=="true"){
			visible=true;
		}
		if(queryable=="false"){
			queryable=false;
		}
		else if(queryable=="true"){
			queryable=true;
		}
		this.servidores[this.servidores.length] = new Array(this.layers.length,name,title,visible,srvnombre,mdtitle,organismo,queryable,tema[i],d_gml);
	  	visible = true;
		this.layers[this.layers.length] = new ogcmap_Layer(url,srvname,name,title,transparent,visible,fmt,queryable,version,epsg,tiles,infoFormat,agrupacio,organismo,timeI,timeF,org_vincle); 
	}
}

function ogcmap_Layer(url,srvname,name,title,transparent,visible,format,queryable,version,epsg,tiles,infoFormat,agrupacio,organismo,timeI,timeF,org_vincle) {
  this.url = url;
  this.srvname = srvname;
  this.name = name;
  this.title = title;
  this.transparent = transparent;
  this.visible = visible;
  this.format = format;
  this.queryable = queryable;
  this.agrupacio=agrupacio;
  this.organismo=organismo;
  this.timeI=timeI;
  this.timeF=timeF;
  this.org_vincle=org_vincle;
  if(this.infoFormat != null ||this.infoFormat != "") {
  	this.infoFormat = infoFormat;
  }else {this.infoFormat = "MIME";}
  
  if(this.version != null ||this.version == "") {
  	this.version = version;
  }else {this.version = "1.1.1";}
  //14 Nov
  if(epsg != null) {
 	this.epsg = epsg;
 	
  }
  else {
  
    this.epsg = "EPSG:23031";
  }
  if(tiles != null) {
 	this.tiles = tiles;
  }
  else {
    this.tiles = true;
  }
  this.loaded = false;
  
 
  
}


function ogcmap_layer_url(aLayer,k) {
//alert(aLayer.url);
  var sURL = aLayer.url;
  var llarg=sURL.length;
  var ultim=sURL.substring(llarg-1,llarg);
 
 if(sURL.indexOf('?')==-1){
  sURL=sURL+"?";	
 }
  
  if(ultim != "?"){
  	
  if(ultim != "&"){
  
  
  sURL=sURL+"&";
  
  }
  }
 
  var nom = "";    

	for (var i=0; i<this.servidores.length; i++) {
	  		if (this.servidores[i][0] == k) {
	  			if (this.servidores[i][3] == true || this.servidores[i][3] == "true"){
	  				if (nom == ""){
		  				nom = this.servidores[i][1];
		  			}
		  			else{
		  				nom = nom + "," + this.servidores[i][1];
		  			}
	  			}	
	  		}
	}
	    
  	if (nom != "") {
  		//26 mar se cambio el & del principio por ? 
  	 	
  	 	if(sURL.indexOf('?')!=-1){sURL += "&REQUEST=GetMap";}else{sURL += "?REQUEST=GetMap&";}
  		
  		if(sURL.indexOf('com.esri')!=-1){sURL=sURL.replace('esrimap','Esrimap');sURL += "&REASPECT=false&";}
		
  		
  		//alert(nom+";"+aLayer.epsg); 	
		sURL += "&SRS=" + aLayer.epsg;
		sURL += "&VERSION=" + aLayer.version;
		sURL += "&WIDTH=" + this.mapWidthPX;
		sURL += "&HEIGHT=" + this.mapHeightPX;
		
		sURL += "&STYLES=";
		
		
		if (aLayer.transparent == true || aLayer.transparent == "true"){sURL += "&TRANSPARENT=true";
		}else{sURL += "&TRANSPARENT=false";}
		  
		  sURL += "&LAYERS=" + nom;
		  //14 Nov
		  //26 mar se comentaron estas lineas
		  
		 if(aLayer.epsg!=mainEPSG){
		
		 var req="/idecwebservices/ideunivers/TransCoordenades.jsp?metode=getTranformEPSGBBOX&inEpsg="+mainEPSG+"&outEpsg="+aLayer.epsg+"&coordX0="+this.cBounds[0]+"&coordY0="+this.cBounds[1]+"&coordX1="+this.cBounds[2]+"&coordY1="+this.cBounds[3]+"&";
		//alert(req);
		 
		 var newBBOX=ajaxCoord(req);
		
   sURL += "&BBOX=" +coordTemp[0]+ "," + coordTemp[1] + "," + coordTemp[2] + "," + coordTemp[3];
   //alert(sURL);
		  }else{
		  sURL += "&BBOX=" + this.cBounds[0] + "," + this.cBounds[1] + "," + this.cBounds[2] + "," + this.cBounds[3];
		  }
		  if (!aLayer.transparent){
		    sURL += "&BGCOLOR=" + this.bgColor;
		  }  
		  
		 
		sURL += "&FORMAT=" + aLayer.format;
		
		
        
		
		  return sURL;
		  
	}
	else { 
		sURL = this.baseDir + "misc/blanco.gif";
		return sURL;
	}
	
}

var winInspire;
var winUrbanisme;
var winservMD;
var psI=0;	


function obreUrbanisme(capa){
psI=psI+1
if(psI==1){

winUrbanisme=dhtmlwindow.open("winUrbanisme", "div", 'servUrba', bt_urbanisme+" Ide.PlanUrb", "width=330px,height=390px,left=350px,top=95px,resize=1,scrolling=1");
}else{
winUrbanisme.show();
}	 
  
}

var psI2=0;

function obreServeisMD(capa){
if(capa==0){psI2=0;}
psI2=psI2+1


if(psI2==1){

var yy=parseInt(map.layers.length - fiNov);
var txtns="("+parseInt(yy - 1)+")";


var mds="WMS "+txtns;


winservMD=dhtmlwindow.open("winservMD", "div", 'servMD', mds, "width=330px,height=390px,left=350px,top=95px,resize=1,scrolling=1");
}else{
winservMD.show();
}	 
  avis(1);   
}



var ps=0;	
function obreInspire(capa){
ps=ps+1
        if(ps==1){
        winInspire=dhtmlwindow.open("winInspire", "div","servInspire" , bt_inspire, "width=320px,height=440px,left=350px,top=95px,resize=1,scrolling=1","recal");
        }else{
        winInspire.show();
        }
}


function show3D(){

winWMS=dhtmlwindow.open("win3D", "iframe", "3d.jsp", "3D", "width=800px,height=650px,left=350px,top=95px,resize=1,scrolling=1");

}





function activaCapesTemes(valor,estat){

var pas=0;

for (var i=0; i<map.servidores.length; i++) {

	if (map.servidores[i][8] == valor) {
    pas=pas+1;
		var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
			document.getElementById(nombrechk).checked = estat;
	  		map.servidores[i][3] = estat;
	  		
	}
  }
  if(pas==0){alert(msg_inspire);}
  
  map.redraw();
}


//generates a user interface for turning on/off layers
function ogcmap_layerUI(){
  	var i = 0;
  	var s = "<form name='lyrLeyenda'>\n";
  	var a="";
  	var servidor = "";
  	if(this.leyenda){
  		var ley=""
  		ley = "visible";
  	}
  	else {
  		var ley = "hidden"
 	}
  	document.getElementById('leyendadiv').style.visibility = ley;
  	z=0;
  	if(tipusAplicacio=="Carrerer"){
  		a += "<table width='99%' class='text' border='0' cellpadding='1' cellspacing='1'>";
   		a += "<tr><td class=\"menu\">Visualització</td></tr>";
  		a += "<tr><td width='14'><input type='radio' name='car' id='car'  onclick=\"idec_gestioCar3(this.value);\" value='ortofoto'  CHECKED>Ortofoto</td></tr>";
  		a += "<tr><td width='14'><input type='radio' name='car' id='car'  onclick=\"idec_gestioCar3(this.value)\"  value='topografic'>Topogràfic</td></tr>";
		a += "<tr><td width='100%'><input type='checkbox' id='carrrer' name='carrrer' onclick=\"idec_estatCarrrer(this.checked)\"  value='carrer'><input type='text' id='txtcarrers' class='text'readOnly='true' style='border-style: none; '  value='Desactivar carrerer'></td></tr>";
   		a += "<tr><td class=\"menu\" >"+gui_titservers+"</td></tr>";
  		a += "</table>";
  		document.getElementById('vcp').style.display = 'none';
  		document.getElementById('vcp').innerHTML = a;
  		z=5;
  	}else{
  		s+= "<table  class='text' style=\"width:99%\" border='0' cellpadding='1' cellspacing='1'>";
  		
  		s += "<tr>";
        //s += "<td align=\"center\"><input class=\"boto\" type=\"button\"  OnClick=\"obreInspire();\" value=\"Temes\"</td>";
  		//s += "<td align=\"center\"><input class=\"boto\" type=\"button\"  OnClick=\"obreUrbanisme();\" value=\"Urbanisme\"</td>";
  		s += "<td align=\"right\"><img class=\"img\" onmouseover=\"Tip('" + bt_msg_wms  + "')\" OnClick=\"map.afegirServidor();\" src=\"/idecwebservices/mapawms/images/skin/buttons/images/servidor_"+language+".png\"></td>";
  		s += "</tr>";
  		s += "<tr><td colspan=\"1\" class=\"menu\" >"+gui_titservers+"</td></tr>";
  		s += "</table>";
  		s +="<div id=\"llca\" style=\"overflow:auto;position:absolute;height:85%;width:99%\">";
  		//document.getElementById('leyendadiv').innerHTML = a;
  	}
  	for (i=z; i < this.layers.length; i++) {
  	var dp="none";
  		if(i == iniciUrb){s +="<div id=\"servUrba\" style=\"display:none\">";}
  		if(i ==iniciIns){s +="<div id=\"inspire\" style=\"display:none\">";}
  		if(i ==parseInt(fiNov+1)){s +="<div id=\"servMD\" style=\"display:none\">";}
        if(i ==iniciNov){s +="<table class='text'  bgcolor=\"#EFFBEB\"   style=\"width:99%\" border=0 cellpadding='1' cellspacing=1><tr><td class='img' id='g" + i + "' onClick=cambiarG(\"" + i + "\",\"Novetats\")><img src='" + this.baseDir + "skin/" + this.skin + "/images/folder.gif' width='30' height='16' border='0'><b style=color:red> &nbsp;Novetats 12-02-2010</b></td></tr></table><div style=\"background-color:#EFFBEB;display:none\" id=\"novetats\"  >";}
        
  		if(this.layers[i].srvname != ""){
  			s += "<table class='text' style=\"width:99%\" border=0 cellpadding='1' cellspacing=1><tr>";
  			
  			
  			//s += "<td width='51px'><a id='x" + i + "' href='javascript:cambiar(\"" + i + "\");'>";
  			//s += "<img src=\"" + this.baseDir + "skin/" + this.skin + "/images/folderb.gif\" width=\"30\" height=\"16\" hspace=\"0\" vspace=\"0\" border=\"0\"></a><input type=\"checkbox\" style=\"width:10px; height:10px;\" onmouseover=\"Tip('"+mn_wmsActLay+"')\" onclick=\"activaServidor('"+i+"',this)\"></td>";
  			//s += "<td class='img' onClick=cambiar(\"" + i + "\");>" + this.layers[i].srvname + "</td>";
  			
  			s += "<td width='5px'>";
  			s += "<input type=\"checkbox\" id=\"chk_"+i+"\" style=\"width:10px; height:10px;\" onmouseover=\"Tip('"+mn_wmsActLay+"')\" onclick=\"activaServidor('"+i+"',this);cambiar('" + i + "');\"></td>";
  			s += "<td><a href='#' onClick=cambiar(\"" + i + "\");>" + this.layers[i].srvname + "</a> " + this.layers[i].org_vincle + "</td>";	
  			
  			
  			s += "</tr></table>";
  		}
		if(i==(this.layers.length-1)){dp="none";}else{dp="none";}
  		s += "<div id='" + i + "' style='background-color: #F7F7F7;z-index:250;display: "+dp+"; margin-left: 1em;'>";
   s += "<table class='text' style=\"width:60%\" border=0 cellpadding='2' cellspacing=1><tr><td>";
   
   s +=' <div id="track'+i+'" onmouseover="Tip(\''+mn_lyTr+'\')"  class="track1" style="border:1px solid #009900;width:100px; height:16px;">';
			 //s +='<div class="track1-left" id="track'+i+'-left"></div>';
             s +='<div  id="handle'+i+'" style="cursor:move;width:15px; height:16px;">';
             s +='<img src="images/handle_horizontal.png" alt="" style="float: left;" />';
             s +='</div>';
		 s +='</div></td>';
         if (this.layers[i].organismo !="NO"){
    s +='<td><img class="img" src="images/ogc.gif" onclick="idec_metadades_servei(\'' + this.layers[i].organismo + '\',\'' + this.layers[i].url + '\');"  onmouseover="Tip(\''+mn_lyMdvS+'\')"></td>';
 }
  s +='</tr></table>';
    //console.info(this.servidores[k]);
  		for (k=0; k< this.servidores.length; k++) {
  			if (this.servidores[k][0] == i) {
   				s += "<table class='text'  border=0 cellpadding='1' cellspacing='1' style=\"width:99%\"><tr>";
   				var nomchk = this.servidores[k][0] + "_" + this.servidores[k][1];
   			
                if(this.servidores[k][5]){
               
                if ( this.servidores[k][5] != "a"){
     
		s+='<td> <img class="img" src="images/meta.gif" onmouseover="Tip(\''+mn_lyMdvD+'\')"  onclick="idec_metadades(\'' + this.servidores[k][5] + '\',\'' + this.servidores[k][6] + '\');" ></td>';
             }else{   
	//s+='<td class="normal1" style="font-size:9px;"  onclick="idec_metadades(\'NO\',\'' + this.servidores[k][6] + '\');">'+mn_lyMd+'</td>';
	 }
	}else{
  
    }
                
                
                
                
                
   				//s += "<td width='12px'><img onmouseover=\"Tip('"+mn_lyPro+"')\" style='cursor:pointer;cursor:hand' onclick='menuPropietats(\"" + nomchk + "\", \"" + this.servidores[k][2] + "\", \"" + this.servidores[k][5] + "\", \"" + this.servidores[k][6] + "\", event)' src='" + this.baseDir + "skin/" + this.skin + "/images/text.gif' width='12' height='12' hspace='0' vspace='0' border='0'></td>";
      			
      			//s += "<td width='12px'><img onmouseover=\"Tip('"+mn_lyTr+"')\" style='cursor:pointer;cursor:hand' onclick=\"transparencia('"+ nomchk + "',event);\" src='" + this.baseDir + "skin/" + this.skin + "/images/text.gif' width='12' height='12' hspace='0' vspace='0' border='0'></td>";
      			
      			//texte+='<tr><td class="normal1" style="font-size:9px;" onclick="transparencia(\''+ capes + '\',event);" onmouseover="if (this.className==\'normal1\'){this.className=\'sobre1\'}" onmouseout="if (this.className==\'sobre1\'){this.className=\'normal1\'}">'+mn_lyTr+'</td></tr>';
      			
      			
      			s += "<td width='200px'> <input type='checkbox' id='" + nomchk + "' name='" + nomchk + "'";
      			s += " value='" + this.servidores[k][2] + "'";
      			if (this.servidores[k][3] == true){
      				s += " checked='1'";
  				}
  				s += " onclick='map.toggleLayer(" + k + ");map.redraw(1);'>";
  				s +="<i>"+ this.servidores[k][2];
  				if (this.servidores[k][8] == 'gml'){
      				s += "<img OnmouseOver=\"Tip('GML')\" OnClick=\"idec_ObteGMLAjax('"+ this.servidores[k][2]+"');\" src=\"images/gml.gif\" id=\"gml\" class=\"img\"/>";
  				}
  				s += "&nbsp;<img id='load_"+nomchk+"' name='load_"+i+"' src='images/load_layer.gif' style='visibility:hidden;'/><img id='error_"+nomchk+"' name='error_"+i+"' src='images/error.png' style='visibility:hidden;'/>";
  				s +="</i>";
                
                if(i >= iniciUrb && i <= fiUrb){
               
                var glt=this.layers[i].url +"&version=1.1.1&service=WMS&request=GetLegendGraphic&layer="+this.servidores[k][1]+"&format=image/png";   
              
 s +="<img class=img border=0 src=images/llegenda/lle.gif  Alt=\"Llegenda\" Onclick=idec_llegendaGLG('"+glt+"','"+nomchk+"') >";
              s +='&nbsp;<div id="divglg_'+nomchk+'"></div>';
               }
               
  				s += "</td></tr>"; 
  				s += "</table>";
  			}
  		}
		
  		s += "</div>";
		if(i == fiUrb){s +="</div>";}
		if(i ==fiIns){s +="</div>";}
        if(i ==fiNov){s +="</div>";}
        
        if(i==this.layers.length){s +="</div>";}
  	}
  	s += "</div></form>";
  	document.getElementById('leyendadiv').innerHTML = s;	
    
}

//14 Nov
function idec_estatCarrrer(valor){
	if(valor){
		document.getElementById('fooWS').style.display='block';
		document.getElementById('efecte').style.visibility='visible';
		document.getElementById('txtcarrers').value='Noms carrers';
		idec_connexioWS("getMapaWMS");
	}else{
		document.getElementById('fooWS').style.display='none';
		document.getElementById('efecte').style.visibility='hidden';
		document.getElementById('txtcarrers').value='Noms carrers';
	}
}

function idec_gestioCar(capa){
	var ap=map.cBounds[2]-map.cBounds[0];
	document.getElementById('visual').value=capa;
	if(capa=="ortofoto"){
		map.servidores[0][3]=true;
		map.layers[0].visible=true;
		map.servidores[1][3]=false;
		map.layers[1].visible=false;
		map.servidores[2][3]=false;
		map.layers[2].visible=false;
	}
	if(capa=="topografic"){
		map.servidores[1][3]=true;
		map.layers[1].visible=true;
		map.servidores[0][3]=false;
		map.layers[0].visible=false;
		map.servidores[2][3]=false;
		map.layers[2].visible=false;
		if((ap < 2000)&&(carto5=="SI")){
			map.servidores[1][3]=false;
			map.layers[1].visible=false;
			map.servidores[2][3]=true;
			map.layers[2].visible=true;
		}
	}
	map.redraw();
}

function idec_gestioCar3(capa){
	idec_gestioEscala(capa);
	map.redraw(1);
}

function idec_gestioEscala(capa){
	var ap=map.cBounds[2]-map.cBounds[0];
	document.getElementById('visual').value=capa;
	if(capa=="ortofoto"){
		map.servidores[0][3]=true;
		map.layers[0].visible=true;
		map.servidores[1][3]=false;
		map.layers[1].visible=false;
		map.servidores[2][3]=false;
		map.layers[2].visible=false;
		map.servidores[3][3]=false;
		map.layers[3].visible=false;
		map.servidores[4][3]=false;
		map.layers[4].visible=false;
		if((ap >= 2000) && (ap < 14500)){
			map.servidores[0][3]=false;
			map.layers[0].visible=false;
			map.servidores[1][3]=true;
			map.layers[1].visible=true;
			map.servidores[2][3]=false;
			map.layers[2].visible=false;
		}
		else if (ap < 2000){
			map.servidores[0][3]=false;
			map.layers[0].visible=false;
			map.servidores[1][3]=false;
			map.layers[1].visible=false;
			map.servidores[2][3]=true;
			map.layers[2].visible=true;
		}
	}
	if(capa=="topografic"){
		map.servidores[0][3]=false;
		map.layers[0].visible=false;
		map.servidores[1][3]=false;
		map.layers[1].visible=false;
		map.servidores[2][3]=false;
		map.layers[2].visible=false;
		map.servidores[3][3]=true;
		map.layers[3].visible=true;
		map.servidores[4][3]=false;
		map.layers[4].visible=false;
		if((ap < 2000)&&(carto5=="SI")){
			map.servidores[3][3]=false;
			map.layers[3].visible=false;
			map.servidores[4][3]=true;
			map.layers[4].visible=true;
		}
	}
}

function idec_gestioCar2(capa){
	var ap=map.cBounds[2]-map.cBounds[0];
	if(capa=="topografic"){
		map.servidores[1][3]=true;
		map.layers[1].visible=true;
		map.servidores[0][3]=false;
		map.layers[0].visible=false;
		map.servidores[2][3]=false;
		map.layers[2].visible=false;
		if((ap < 2000)&&(carto5=="SI")){
			map.servidores[1][3]=false;
			map.layers[1].visible=false;
			map.servidores[2][3]=true;
			map.layers[2].visible=true;
		}
	}
}

function ajustaZoom(){

      var extOL = map1.getExtent();

      var bboxOL = extOL.toArray();

      return bboxOL;

}




//redraws all the map layers
function ogcmap_redraw(activa) {
	//29 ene 08	
	var sURL = "";
	
	
	
	var ap=(this.cBounds[2]-this.cBounds[0]);
	if((tipusAplicacio=="Carrerer")&& (activa!=1)){
		idec_gestioEscala(document.getElementById('visual').value);
	}
	
  	if (activa != 1){
		this.showLoading();
  	}
  	this.drawPts();
  	this.writeLabels();
  	idec_connexioWS("getMapaWMS");
  	window.status="IDEC";
  	if(asdf==1){this.moureSlide();}
  	var escala="Escala= 1: "+getScale();
  	document.getElementById('posInfoEscala').innerHTML=escala;
  	//tiles 14 sep 2007
  		//alert(this);
		
	
  	zoomMapa(this,activa);
  	
  	if(activa==2){obreServeisMD('');}
  	if(activa==3){
    
    obreServeisMD('0');}
  	
}

function getPosition(arrayName,arrayItem){
    for(var i=0;i<arrayName.length;i++){ 
       if(arrayName[i].srvname==arrayItem)
            return i;
    }
}


//refresca el mapa cuando de activa o se desactiva una capa
function ogcmap_toggleLayer(idx) {

  	if (idx < 0)
    	return;
  	if (idx >= this.servidores.length)
    	return;
  	this.servidores[idx][3] = ! this.servidores[idx][3];
  	if((tipusAplicacio!="Carrerer")&&(idx==3)){
   		if(this.servidores[idx][3]){
   			document.getElementById('fooWS').style.display='block';
   		}else{
   			document.getElementById('fooWS').style.display='none';
   		}
   	}
   	if (this.servidores[idx][3]){
   
   		var nomchk = this.servidores[idx][0] + "_" + this.servidores[idx][1];
        
        //interaacio
        var nser=this.servidores[idx][4];
        if(nser.indexOf('(') !=-1){nser=nser.substring(0,nser.indexOf('('));
        }else{
            if(nser.indexOf('</') !=-1){nser=nser.substring(0,nser.indexOf('</'))}
        }
            
        var nomS=nser +";"+ this.layers[this.servidores[idx][0]].url + ";" + map.servidores[idx][1]+";"+ map.cBounds[0] + ";" + map.cBounds[1] + ";" + map.cBounds[2] + ";" + map.cBounds[3];       
         interaccio('IDEC','V;'+nomS);
         
         //fi interaccio
         
   		var nom_load = "load_"+nomchk;
       //today = new Date();
      
   		document.getElementById(nom_load).style.visibility = "visible";
          
   	}else{
   
   		var nomchk = this.servidores[idx][0] + "_" + this.servidores[idx][1];
   		var nom_load = "load_"+nomchk;
   		document.getElementById(nom_load).style.visibility = "hidden";
   	}
	if (this.autoRefresh){
    	this.redraw(1);
  	}
}


//difference = Christmas - today;

//days = Math.round(difference/(1000*60*60*24));
var clTxtTit="#446F43";
var clBgTit="#ffffff";
//crea la barra con los botones
//ratoli

var wh;
function idec_posaOffset(top,left,temps,percent){
	if(percent==100){
		document.getElementById('initMap').style.display = 'block';
		var factorPosInfo=eval(top+25);
		wh = new Object();
		wh.nW=eval(document.getElementById('initMap').offsetWidth - left);
		wh.nWP=parseInt(eval((wh.nW*100)/document.getElementById('initMap').offsetWidth));
		
		var Hie = 0;
		var browser = navigator.appName; 
		if(browser == "Microsoft Internet Explorer"){
			Hie = document.documentElement.offsetHeight-15;
			//Hie = document.getElementById('initMap').scrollHeight;
		}else{
			Hie = document.getElementById('initMap').offsetHeight;	
		}
		wh.nH=eval(Hie - factorPosInfo);
		wh.nWP=parseInt(eval((wh.nH*100)/Hie));
		
		document.getElementById('initMap').style.display = 'none';
		
		if(temps==1){
			//11 mar 08
			setTimeout("redimencionaMap()",700);
			
		}
		return wh;
	}
}


function ogcmap_writeInline(topM,leftM,topT,leftT,nEines,posBarra,posZoom,percent) {

this.percent=percent;
var htmlString=new Array();

	codiEmail=codiMun;
	if(document.all){
		topM=parseInt(document.styleSheets[0].rules[27].style.top)+3;
		leftM=parseInt(document.styleSheets[0].rules[27].style.left)+3;
		clTxtTit=document.styleSheets[0].rules[4].style.backgroundColor;
		clBgTit=document.styleSheets[0].rules[4].style.color;
		
	}else{
				
		topM=parseInt(document.styleSheets[0].cssRules[27].style.top)+3;
		leftM=parseInt(document.styleSheets[0].cssRules[27].style.left)+3;
		clTxtTit=document.styleSheets[0].cssRules[4].style.backgroundColor;
		clBgTit=document.styleSheets[0].cssRules[4].style.color;
		
	}
	
	//Genre 24-01-08
	this.topM=topM;this.leftM=leftM;
	
	if(this.percent==100){
	var wh= new Object();
	wh=idec_posaOffset(this.topM,this.leftM,0,this.percent);
	
	this.mapWidthPX=wh.nW;
	this.mapHeightPX=wh.nH;
   
 	//this.WidthDivPer=wh.nWP;
  	//this.HeightDivPer=wh.nHP;	
	}
	
 	//declaracion de variables
  	var gid = this.gid;
  	var s="";
  	var sdiv = "<div style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; margin:0; padding:0; position:absolute;\">";
  	var swh = "width=\"" + this.mapWidthPX + "px\" height=\"" +this.mapHeightPX + "px\"";
  	//contenedor del mapa
  	htmlString.push("<div id=\"avis\" class=\"divCercant\" style=\"display:none;z-index:3000;font-family: Arial, Helvetica, sans-serif;font-size:11px;font-style: normal;font-weight: bold;color: #FFFFFF;background-color: #FF3300;width:85px;height:20px;border: 0px outset #000000;position:absolute;left:"+parseInt(leftM+40)+"px;top:"+topM+"px; \"> CERCANT...</div>");
	htmlString.push("<div id=\"monitoring\" class=\"divCercant\" style=\"display:none;z-index:3000;font-family: Arial, Helvetica, sans-serif;font-size:11px;font-style: normal;font-weight: bold;color: #FFFFFF;background-color: #FF3300;width:250px;height:400px;border: 0px outset #000000;position:absolute;left:"+parseInt(leftM+40)+"px;top:"+topM+"px; \"></div>");
    htmlString.push( "<div id=\"cont_general\" class=\"mapa\" style=\"position:absolute;width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; \" name=\"" + this.prefix + "\">");	
  	if(document.all){var we=0;var he=0;}else{var we=265;var he=275;}
	htmlString.push( "<div id=\"posFitxes\" style=\"display:none;background-color: #EFFBEB;position:absolute;border-color: #FFFFFF #333333 #333333;border-style: solid; border-top-width: 10px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px;width:"+we+"; height:"+he+";overflow:visible; z-index:141; left: 40px; top:40px\">"); 
  	htmlString.push("</div>");	
  	htmlString.push( "<div id=\"posFitxes2\" style=\"display:none;background-color: #EFFBEB;position:absolute;border-color: #FFFFFF #333333 #333333;border-style: solid; border-top-width: 10px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px;width:"+we+"; height:"+he+";overflow:hidden; z-index:142; left: 40px; top:40px; filter:alpha(opacity=85);opacity:0.85;\">"); 
  	htmlString.push("</div>");
  	htmlString.push( "<div id=\"cont_principal\" style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; margin:0; padding:0; position:absolute;clip:rect(0," + this.mapWidthPX + "px," + this.mapHeightPX + "px,0);overflow:hidden;\">\n");
  	htmlString.push( "<div id=\""+gid+"_loadDiv\" style=\"filter:alpha(opacity=70);opacity:0.7;background-color: #FFFFFF;z-index:99;visibility:hidden;width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; margin:0; padding:0; position:absolute;\"><img style=\"left:" + (this.mapWidthPX/2 - 35) + "px;top:" + this.mapHeightPX/2 + "px;position:absolute;\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/loading.gif\"></img>\n");
  	htmlString.push("</div>");
  		//DIV CONTAINER
  	htmlString.push( "<div id=\"" + gid + "_container\" style=\"z-index:25;width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; margin:0; padding:0; position:absolute;\">");
  			
  			
  			var nlayers = this.layers.length;
  			for (var i=0; i < nlayers; i++) {
  				//tiles 14 sep 2007
  				htmlString.push( "<div id=\"div_" + this.prefix+i+ "\"  name=\"div_" + this.prefix+i+ "\" style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; margin:0; padding:0; position:absolute; filter:alpha(opacity=100); opacity:1;\">");
  				htmlString.push( "<img style=\"filter:alpha(opacity=100);opacity:1;\" id=\"" + this.prefix+i+ "\"  name=\"" + this.prefix+i+ "\" onload=\"g_ogcMaps["+gid+"].setLoaded(" + i + ")\"  OnError=\"idec_retoca(this.id);\" src=\"" + this.baseDir + "blank.gif\" " + swh + "></img>\n");
  				//htmlString.push( sdiv + "<img style=\"filter:alpha(opacity=100);opacity:1;\" id=\"" + this.prefix+i+ "\"  name=\"" + this.prefix+i+ "\" onload=\"g_ogcMaps["+gid+"].setLoaded(" + i + ")\"  OnError=\"idec_retoca(this.id);\" src=\"" + this.baseDir + "blank.gif\" " + swh + "></img>\n";
  				htmlString.push("</div>");
  			}
  			

 			htmlString.push("<div id =\"mapOpen\" style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; margin:0; padding:0; position:absolute; filter:alpha(opacity=100); opacity:1;  display:none\">");
 			htmlString.push("</div>");  			
  			htmlString.push( sdiv + "<img style=\"display:none;filter:alpha(opacity=100);opacity:1;\" id=\"fooWS\"  name=\"fooWS\" OnError=\"idec_retoca(this.id)\" src=\"" + this.baseDir + "blank.gif\" " + swh + "></img>\n");
  			htmlString.push("</div>");
  			htmlString.push( sdiv + "<img style=\"visibility:hidden;filter:alpha(opacity=100);opacity:1;\" id=\"fooWSXY\"  name=\"fooWSXY\" OnError=\"idec_retoca(this.id)\"  src=\"" + this.baseDir + "blank.gif\" " + swh + "></img>\n");
  			htmlString.push("</div>");
 			htmlString.push("<div id =\"mapa\" style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; margin:0; padding:0; position:absolute;\">");
 			htmlString.push("</div>");
 			htmlString.push( sdiv + "<div id=\""+gid+"mapCanvas\" style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px;overflow:hidden;clip:rect(0," + this.mapWidthPX + "px," + this.mapHeightPX + "px,0); \">\n");
  			htmlString.push("</div>");
  			htmlString.push("</div>");
  			htmlString.push( sdiv + "<div id=\""+gid+"_labelsDiv\" style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px;overflow:hidden;clip:rect(0," + this.mapWidthPX + "px," + this.mapHeightPX + "px,0); \">\n");
  			htmlString.push("</div>");
  			htmlString.push("</div>");
  			htmlString.push( sdiv + "<div id=\""+gid+"_selectionDiv\" style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px;overflow:hidden;clip:rect(0," + this.mapWidthPX + "px," + this.mapHeightPX + "px,0); \">\n");
  			htmlString.push("</div>");
  			htmlString.push("</div>");
  			htmlString.push( "<div id=\""+gid+"_zoomBox\" style=\"background-color: #F7F7F7;position:absolute;visibility:hidden;z-index:100;filter:alpha(opacity=70);opacity:0.7;border:2px solid red;width:0px;height:0px;\">");
  			htmlString.push("</div>");
  			
  			//31 jul 08 
  			//htmlString.push( "<div id=\"nota_legal\" style=\"position:relative; top:"+ (this.mapHeightPX-10) +"px;left:2px;\"><span class=\"halot\">"+INFO_LEGAL+"</span><span class=\"halob\">"+INFO_LEGAL+"</span><span class=\"halor\">"+INFO_LEGAL+"</span><span class=\"halol\">"+INFO_LEGAL+"</span><span class=\"halo\">"+INFO_LEGAL+"</span></div>");
		htmlString.push("</div>\n");	
  		//FIN DIV CONTAINER
  		htmlString.push( "<div id=\"nota_legal\" style=\"position:relative; top:"+ (this.mapHeightPX-15) +"px;left:2px;z-index:25;\"><span class=\"halot\">"+INFO_LEGAL+"</span><span class=\"halob\">"+INFO_LEGAL+"</span><span class=\"halor\">"+INFO_LEGAL+"</span><span class=\"halol\">"+INFO_LEGAL+"</span><span class=\"halo\">"+INFO_LEGAL+"</span></div>");
  	htmlString.push("</div>\n");	
  	//ratoli
    htmlString.push( "<div id=\""+gid+"_glassPane\"  onmousedown=\"g_ogcMaps["+gid+"].mouseDown(event);\" onmousemove=\"g_ogcMaps["+gid+"].mouseMove(event);\" onmouseup=\"g_ogcMaps["+gid+"].mouseUp(event);\" onmouseover=\"g_ogcMaps["+gid+"].mouseOver(event);\" onmouseout=\"g_ogcMaps["+gid+"].mouseOut(event);\" style=\"z-index:26;cursor:default;border:1px black solid;background-image: url(" + this.baseDir + "blank.gif);position:absolute;width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; \">");
    htmlString.push("</div>\n");
   
   htmlString.push( "<div id=\"puntInci\" OndblClick=\"map.mailing(e)\"  style=\"cursor:hand;cursor:pointer;z-index:501;padding:1px;border:0px none black;position:absolute;top:0px;left:0px;width:5px;height:5px;visibility:hidden;\"><img  src=\"images/pointx.gif\"></img></div>");
   if (document.all){
	   	htmlString.push( "<div id=\"efecte\" style=\"position:absolute;visibility:hidden;z-index:25;border:0px solid red;width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px\">");
		htmlString.push("</div>");
		
	}else{
	   	htmlString.push( "<div id=\"efecte\" style=\"position:absolute; visibility:hidden; z-index:25; width:200px; height:50px; border:0px solid red;\">");
		htmlString.push("</div>");
		
	}	
   
  	htmlString.push("</div>\n"); 	
  	htmlString.push( "<div id=\"barraSlide\" class=\"barrazoom\" style=\"padding-left: 4px;padding-top: 2px;overflow:hidden;position:absolute;z-index:500;border: 1px none #000000\">"); 
  	htmlString.push( "<table width=\"100%\" height=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
    htmlString.push( "<tr> <td align=\"center\" valign=\"top\"><img src=\"images/skin/buttons/images/barra.gif\" width=\"46\" height=\"93\" border=\"0\" usemap=\"#Map\" href=\"#\"></td></tr>");
    htmlString.push( "</table>");
    htmlString.push( "</div>");
    htmlString.push( "<map name=\"Map\">");
    htmlString.push( "<area shape=\"circle\" Onclick=\"map.zoomCentre('mes')\"  coords=\"23,15,7\" href=\"#\">");
    htmlString.push( "<area shape=\"circle\" Onclick=\"map.zoomCentre('menys')\"  coords=\"24,37,7\" href=\"#\">");
    htmlString.push( "<area shape=\"rect\" Onclick=\"map.pan(0.20,'N')\" name=\"N\"coords=\"17,51,29,67\" href=\"#\">");
    htmlString.push( "<area shape=\"rect\" Onclick=\"map.pan(0.20,'S')\" name=\"S\"coords=\"18,76,28,88\" href=\"#\">");
    htmlString.push( "<area shape=\"rect\" Onclick=\"map.pan(0.20,'W')\" name=\"W\" coords=\"30,64,41,77\" href=\"#\">");
    htmlString.push( "<area shape=\"rect\" Onclick=\"map.pan(0.20,'E')\" name=\"E\" coords=\"5,63,15,76\" href=\"#\">");
    htmlString.push( "</map>");		  	
  	htmlString.push( "<input type=\"hidden\" name=\"cX\" id=\"cX\" value=0><input type=\"hidden\" name=\"cY\" id=\"cY\" value=0><input type=\"hidden\" name=\"adreca\" id=\"adreca\" value=0>");
  	htmlString.push( "<input type=\"hidden\" name=\"inciX\" id=\"inciX\" value=0><input type=\"hidden\" name=\"inciY\" id=\"inciY\" value=0>");
  	htmlString.push("<div id=\"bBotondiv\" class=\"barrabotones\" style=\"width:"+this.mapWidthPX+"px;position:absolute;\">");
  	htmlString.push( "<table width=\"20px\" border=\"0\">\n");
  	htmlString.push( "<tr>\n");
		//
  		if(this.toolbar) {
  			var tagPos=""
  			if(posBarra=="V"){tagPos="</tr><tr>";}else{tagPos="";}
      		var ntools = nEines;
    		for (var i=0; i < (ntools-1); i++) {
    			if(this.tools[i].enabled == true) {
					if(i==7 ||i==12){htmlString.push( tagPos +"<td></td><td></td>");}
    				htmlString.push( tagPos +"<td class=\"boto_normal\" id=\""+ this.gid + "_toolcell_" + this.tools[i].opcode + "\"><a  onmouseover=\"Tip('" + this.tools[i].description  + "')\" href=\"javascript:g_ogcMaps["+gid+"]." + this.tools[i].targetFunction + "\"><img title=\"\"  border=\"0\" id=\"" + this.tools[i].name + "\" name=\"" + this.tools[i].name + "\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/" + this.tools[i].name + ".png\"></img></a></td>\n");
      			}
    		}
  		}
        
        htmlString.push("<td align=\"center\">&nbsp;&nbsp;&nbsp;&nbsp;</td><td align=\"center\"><input class=\"boto\" type=\"button\"  OnClick=\"obreInspire();\" value=\""+bt_inspire+"\"</td>");
  		htmlString.push("<td align=\"center\"><input class=\"boto\" type=\"button\"  OnClick=\"obreUrbanisme();\" value=\""+bt_urbanisme+"\"</td>");
        htmlString.push("<td align=\"center\"><img src=\"images/temps.png\" onmouseover=\"Tip('" + avisEst  + "')\"; class=\"img\" OnClick=\"showMonitoring();\" </td>");
       // htmlString.push("<td align=\"center\"><input class=\"boto\" type=\"button\"  OnClick=\"show3D();\" value=\"3D\"</td>");
        
  		htmlString.push( "</tr>");
  	htmlString.push( "</table></div>\n");
  	//htmlString.push("<div class=\"subtitol\" style=\"position:absolute; left: 87%; top: 7px;\"></div></div>\n");
  	var topInci = topM+this.mapHeightPX+3;
	var leftInci = (leftM+this.mapWidthPX)-60;
	if(email!="NO"){ver_email="block";}else{ver_email="none";}
	if(tipusAplicacio=="Visual"){ver_email="none";}
	if(schema=="Urbanisme"){ver_email="block";}
	htmlString.push("<div id=\""+ this.gid + "_toolcell_" + this.tools[i].opcode + "\" class=\"boto_normal\" style=\"align:center;display:"+ver_email+";position:absolute;top:" + topInci + "px;left:" + leftInci + "px;width:56px;height:19px;:4000;\">");
  	htmlString.push("<a  href=\"javascript:g_ogcMaps["+gid+"]." + this.tools[i].targetFunction + "\"><img  onmouseover=\"Tip('" + avisCarrerer  + "')\"; border=\"0\" id=\"" + this.tools[i].name + "\" name=\"" + this.tools[i].name + "\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/" + this.tools[i].name + ".png\"></img></a>");
  	htmlString.push("</div>\n");
  	var wMenu=255;
  	var tf=0;
  	if(tipusAplicacio=="Carrerer"){
	  	if(codiMun.length < 3){tf=20;}
	  	topCerca=parseInt(topM+230+tf);
	  	factor=0;
	  	ampla=(this.mapHeightPX*0.23);
	  	topCerca1=parseInt(topM+130+tf);
	  	mS=120;
		
  	}else{
		
		if(schema=="Urbanisme"){
		htmlString.push("<div class=\"einesCerca\" id=\"EinesCerca\" style=\"position:absolute;width:"+wMenu+"px; border: 1px none #0000FF\">");
	  		//htmlString.push(idec_escriuCerques(tipusAplicacio,leftM);
           
           	htmlString.push(escriuMenuCerca());
           
	  	htmlString.push("</div>");
	 	
	 	htmlString.push("<div class=\"vcp\" id='vcp' style='display:none;border: 1px none #EFFBEB;position:absolute;width:"+wMenu+"px;height:95px;' onmouseover=\"document.getElementById('propietats').style.visibility='hidden';\"></div>");
		
		}
		
		topCerca=parseInt(topM);
   		factor=135;
   		ampla=(this.mapHeightPX - 250);
   		mS=215
  	}
  	
  	//if(tipusAplicacio=="Carrerer"){
  		//htmlString.push("<div id=\"leyendadiv\" class=\"Cleyenda\" style='position:absolute;width:"+wMenu+"px;height:"+parseInt(ampla-tf)+"px;overflow:hidden;' onmouseover=\"document.getElementById('propietats').style.visibility='hidden';\">");
  	//}else{
  		htmlString.push("<div id=\"leyendadiv\" class=\"leyenda\" style=\"position:absolute;width:"+wMenu+"px;height:"+parseInt(ampla-tf)+"px;overflow:hidden;\" onmouseover=\"document.getElementById('propietats').style.visibility='hidden';\">");
  	//}
  	htmlString.push("</div>");
    
  	htmlString.push("<div id=\"propietats\" style=\"z-index:125;position:absolute; visibility:hidden;top:0px;left: 0px\">");
  	htmlString.push("</div>");
    
    /*
    htmlString.push("<div id=\"divTra\" class=\"boto\" style=\"z-index:127;position:absolute; visibility:hidden;top:0px;left:0px;width:105;height:45;overflow:hidden\">");
  	
    htmlString.push("<div id=\"d090\" style='position:absolute; top:0; left:89; height:14'>");
	htmlString.push("<IMG alt=\"\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/x.gif\" width=\"16\" height=\"14\" onclick=\"document.getElementById('propietats').style.visibility='hidden';document.getElementById('divTra').style.visibility='hidden';dd.elements.lineatra.hide();\">");
	
    htmlString.push("</div>");
	
    htmlString.push("<div align=\"center\" style=\"z-index:128;position:absolute; top:26; left:45; height:14\" id=\"numTrans\" name=\"numTrans\">");
	
    
    htmlString.push("</div>");
    
    htmlString.push("<IMG alt=\"\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/handle.gif\" width=\"10\" height=\"25\" id=\"trahand\" name=\"trahand\">");
 	
    htmlString.push("<IMG alt=\"\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/gifhorizontal.gif\" width=\"105\" height=\"15\" aling='left' id=\"lineatra\" name=\"lineatra\">");
    
    htmlString.push("</div>");
    */
    
  //document.write(htmlString);
    
    
    htmlString.push("<div id=\"posInfo\" class=\"info\"  style=\"width:"+parseInt(this.mapWidthPX)+"px;left:"+parseInt(leftM)+"px;top:"+parseInt(topM + this.mapHeightPX)+"px;position:absolute \">");
  	htmlString.push("</div>");
  	htmlString.push("<div id=\"posInfoEscala\" class=\"info\"  style=\"width:150px;left:"+parseInt(leftM+(this.mapWidthPX - ((parseInt(this.mapWidthPX)/4)*3)+ 5))+"px;top:"+parseInt(topM + this.mapHeightPX)+";position:absolute \">");
  	htmlString.push("</div>");
  	htmlString.push("<div id=\"posComboEscala\" name=\"posComboEscala\" class=\"menu\"  style=\"width:300px;border: 1px #30c8ff solid;left:"+parseInt(leftM+40)+"px;top:"+parseInt(topM)+"px;position:absolute;display:none;z-index:3000; \">");
	htmlString.push("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"menu\">");
	htmlString.push("<tr>");
	htmlString.push("<td>Monitor: </td><td><select name=\"monitor\" id=\"monitor\" class=\"menu\" onchange=\"actualizaMonitor(this.value);\">");
	htmlString.push("<option value=\"9.1\">14\"</option>");
	htmlString.push( "<option value=\"10\">15\"</option>");
	htmlString.push( "<option selected value=\"11.5\">17\"</option>");
	htmlString.push( "<option value=\"13.1\">19\"</option>");
		  	htmlString.push( "<option value=\"14.7\">21\"</option>");
		htmlString.push( "</select></td>");
		htmlString.push( "<td>Zoom Escala: </td><td><select name=\"zoomEscala\" id=\"zoomEscala\" class=\"menu\" onchange=\"map.zoomescala(this.value);\">");
		  	htmlString.push( "<option value=\"200\">1:200</option>");
			htmlString.push( "<option value=\"500\">1:500</option>");
			htmlString.push( "<option value=\"1000\">1:1.000</option>");
		  	htmlString.push( "<option selected value=\"5000\">1:5.000</option>");
		  	htmlString.push( "<option value=\"10000\">1:10.000</option>");
		  	htmlString.push( "<option value=\"25000\">1:25.000</option>");
		  	htmlString.push( "<option value=\"50000\">1:50.000</option>");
			htmlString.push( "<option value=\"100000\">1:100.000</option>");
			htmlString.push( "<option value=\"150000\">1:150.000</option>");
			htmlString.push( "<option value=\"200000\">1:200.000</option>");
			htmlString.push( "<option value=\"250000\">1:250.000</option>");
		htmlString.push( "</select></td>");
		htmlString.push( "<td style=\"vertical-align:top; text-align:right;\"><img src=\"" + this.baseDir + "close.gif\" style=\"cursor:pointer\" alt=\"tancar\" onclick=\"document.getElementById('posComboEscala').style.display='none';\"></td></tr></table>");
  	htmlString.push("</div>\n");
  	htmlString.push( "<div id=\"divCercaTopomin\" name=\"divCercaTopomin\" style=\"width:300px;left:"+parseInt(leftM+(this.mapWidthPX - ((parseInt(this.mapWidthPX)/4)*2)))+"px;top:"+parseInt(topM + this.mapHeightPX)+";position:absolute;:3000; \">");
  	htmlString.push("</div>\n");
  	htmlString.push("<div id=\"mapaSituacio\" class=\"minimapa\" style=\"position:absolute;:0;width:150px;height:150px;overflow:hidden;border: 1px outset #0000FF\">");
  htmlString.push("<div id=\"mapRef\" style=\"z-index:20;overflow:hidden;background-image: url(images/creu.gif);display:none;position:absolute;top:70px;left:70px;width:10px;height:10px;border:2px none;border-color:#FF0000;background-color: #FFFFFF; layer-background-color: #FFFFFF\">");
  	htmlString.push("</div>\n");
  	htmlString.push("</div>");
    htmlString.push("<div id=\"servInspire\" style=\"display:none\">");;
   
htmlString.push("<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">");
	htmlString.push("<tr bgcolor=\"#EFFBEB\"><td  class=\"text\" width=\"90%\">"+th_1+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Geographical\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\"></td></tr>");
    htmlString.push("<tr><td class=\"text\" width=\"90%\">"+th_2+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Administrative\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
  	htmlString.push("<tr bgcolor=\"#EFFBEB\"><td class=\"text\" width=\"90%\">"+th_3+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Properties\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
    htmlString.push("<tr><td class=\"text\" width=\"90%\">"+th_4+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" name=\"checkbox\" value=\"Elevation\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
  	htmlString.push("<tr bgcolor=\"#EFFBEB\"><td class=\"text\" width=\"90%\">"+th_5+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" name=\"checkbox\" value=\"Geo-physical\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
    htmlString.push("<tr><td class=\"text\" width=\"90%\">"+th_6+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Land\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
  	htmlString.push("<tr bgcolor=\"#EFFBEB\"><td class=\"text\" width=\"90%\">"+th_7+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Transport\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" value=\"Parcelari\"></td></tr>");
    htmlString.push("<tr><td class=\"text\" width=\"90%\">"+th_8+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Utilities\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
  	htmlString.push("<tr bgcolor=\"#EFFBEB\"><td class=\"text\" width=\"90%\">"+th_9+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Society\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
    htmlString.push("<tr><td class=\"text\" width=\"90%\">"+th_10+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Landuse\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
  	htmlString.push("<tr bgcolor=\"#EFFBEB\"><td class=\"text\" width=\"90%\">"+th_11+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Air\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
   htmlString.push("<tr><td class=\"text\" width=\"90%\">"+th_12+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Water\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
  	htmlString.push("<tr bgcolor=\"#EFFBEB\"><td class=\"text\" width=\"90%\">"+th_13+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Ocean\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
    htmlString.push("<tr><td class=\"text\" width=\"90%\">"+th_14+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Biota\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\"></td></tr>");
  	htmlString.push("<tr bgcolor=\"#EFFBEB\"><td class=\"text\" width=\"90%\">"+th_15+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Natural\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
   htmlString.push("<tr><td class=\"text\" width=\"90%\">"+th_16+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Risks\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");
  	htmlString.push("<tr bgcolor=\"#EFFBEB\"><td class=\"text\" width=\"90%\">"+th_17+"</td><td class=\"text\" width=\"34%\"><input type=\"checkbox\" value=\"Anthropogenic\" name=\"checkbox\" onClick=\"activaCapesTemes(this.value,this.checked)\" ></td></tr>");  	
  	htmlString.push("</table>");
    htmlString.push("<em><font size=\"1\">*"+th_msg+"</font></em>");
  	htmlString.push("</div>");
    
    
    
  	//document.write(s);
   document.write( htmlString.join(' '));
  	this.postWrite(1);
  	var sURL = "codiMun="+codiEmail+"&minX="+this.mapBounds[0]+"&minY="+this.mapBounds[1]+"&maxX="+this.mapBounds[2]+"&maxY="+this.mapBounds[3];
  	//getToponimAjax(sURL);
  	
  	
}


function novaTR(capa){
     capetrans = capa;
  	var ncap = parseInt(capa);   
	var pro=document.getElementById('divTra_'+capa);
    
	pro.above;
	//tiles 14 sep 2007
	capa = "div_" + map.prefix + ncap;
	//capa = map.prefix + ncap;	
   
	pro.style.visibility='visible';
    
	if (document.all){
		x = e.clientX ;
		y = e.clientY ;
		transpa = document.getElementById(capa).filters.alpha.opacity;
		transpa = 100 - transpa;
	}else{
		x = e.pageX ;
		y = e.pageY;
		transpa = document.getElementById(capa).style.opacity;
		transpa = 100 * transpa;
		transpa = 100 - transpa;
	}
	//pro.style.top = y-10;
	//pro.style.left = x;
	document.getElementById('numTrans').innerHTML = transpa + " %";
	dd.elements.lineatra.moveTo(x,y);
    dd.elements.lineatra.setZ(199);
	dd.elements.lineatra.show();
	dd.elements.trahand.moveTo((x + transpa),(y-5));
}

//muestra la barra para seleccionar la transparencia
function transparencia (capa,e){

capa=capa.replace(' ','&nbsp;');
capetrans = capa;
	var num = capa.indexOf("_");
  	var ncap = capa.substring(0,num);
  	var ncap = parseInt(ncap);
    
    
	var pro=document.getElementById('divTra');
    
	pro.above;
	//tiles 14 sep 2007
	capa = "div_" + map.prefix + ncap;
	//capa = map.prefix + ncap;	
   
	pro.style.visibility='visible';
    
	if (document.all){
		x = e.clientX ;
		y = e.clientY ;
		transpa = document.getElementById(capa).filters.alpha.opacity;
		transpa = 100 - transpa;
	}else{
		x = e.pageX ;
		y = e.pageY;
		transpa = document.getElementById(capa).style.opacity;
		transpa = 100 * transpa;
		transpa = 100 - transpa;
	}
	pro.style.top = y-10;
	pro.style.left = x;
	document.getElementById('numTrans').innerHTML = transpa + " %";
	dd.elements.lineatra.moveTo(x,y);
    dd.elements.lineatra.setZ(199);
	dd.elements.lineatra.show();
	dd.elements.trahand.moveTo((x + transpa),(y-5));
}

//asigna un valor de transparencia dado a una capa dada
function transpaDIV(valorDIV,capaTR){

valorDIV=100-valorDIV;

	if (valorDIV > 100){
		valorDIV=100;
	}
	transp = valorDIV;
	//var num = capaTR.indexOf("_");
  	//var ncap = capaTR.substring(0,num);
  	var ncap = parseInt(capaTR);
	//tiles 14 sep 2007
	capaTR = "div_" + map.prefix + ncap;
    
	//capaTR = map.prefix + ncap;	
	if (document.all){
		valorT=eval(valorDIV);
		document.getElementById(capaTR).filters.alpha.opacity=valorT;
	}else{
		valorT=eval(valorDIV/100);
		document.getElementById(capaTR).style.opacity=valorT;
	}
	//document.getElementById('numTrans').innerHTML = 100 - eval(valorDIV) + " %";
}




//llama a transpaDiv desde extra.js para manejar la transparencia.
function haceTransp(x) {
	transpaDIV(x,capetrans);
}

function ogcmap_moureSlide(){
	
	var amplaIni = (coordInici[2] - coordInici[0]);
	var ampla = (this.cBounds[2] - this.cBounds[0]);
	var mouY;
	var rango = amplaIni / 20;
	
	
	if(ampla < rango){mouY=(100);}
	if((ampla >= rango)&&(ampla < (rango*2))){mouY=(95)}
	if((ampla >= (rango*2))&&(ampla < (rango*3))){mouY=(90)}
	if((ampla >= (rango*3))&&(ampla < (rango*4))){mouY=(85)}
	if((ampla >= (rango*4))&&(ampla < (rango*5))){mouY=(80) }
	if((ampla >= (rango*5))&&(ampla < (rango*6))){mouY=(75)}
	if((ampla >= (rango*6))&&(ampla < (rango*7))){mouY=(70)}
	if((ampla >= (rango*7))&&(ampla < (rango*8))){mouY=(65)}
	if((ampla >= (rango*8))&&(ampla < (rango*9))){mouY=(60)}
	if((ampla >= (rango*9))&&(ampla < (rango*10))){mouY=(55)}
	if((ampla >= (rango*10))&&(ampla < (rango*11))){mouY=(50)}
	if((ampla >= (rango*11))&&(ampla < (rango*12))){mouY=(45)}
	if((ampla >= (rango*12))&&(ampla < (rango*13))){mouY=(40)}
	if((ampla >= (rango*13))&&(ampla < (rango*14))){mouY=(35)}
	if((ampla >= (rango*14))&&(ampla < (rango*15))){mouY=(30)}
	if((ampla >= (rango*15))&&(ampla < (rango*16))){mouY=(25)}
	if((ampla >= (rango*16))&&(ampla < (rango*17))){mouY=(20)}
	if((ampla >= (rango*17))&&(ampla < (rango*18))){mouY=(15)}
	if((ampla >= (rango*18))&&(ampla < (rango*19))){mouY=(10)}
	if((ampla >= (rango*19))&&(ampla < (rango*20))){mouY=(5)}
	if(ampla >= (rango*20)){mouY=(0);}
	//alert("mouY " + mouY);
	//moureBarra(mouY,"map");
}

function idec_activaGetMapaPunt(cX,cY,adreca,zFactor1){
	document.getElementById('posFitxes').style.display='none';
	document.getElementById('fooWSXY').style.visibility='visible';
	document.getElementById('cX').value=cX;
	document.getElementById('cY').value=cY;
	if (adreca=="null"){adreca="";}
	document.getElementById('adreca').value=adreca;
	if(zFactor1==null){zFactor1=300;}
	zFactor1=parseInt(zFactor1);
	var x1 = 0;
	var x2 = 0;
	var y1 = 0;
	var y2 = 0;
	
	cX=parseFloat(cX);
	cY=parseFloat(cY);
	if(cY !=0.0){
	x1=eval(cX-zFactor1);
	y1=eval(cY-zFactor1);
	x2=eval(cX + zFactor1);
	y2=eval(cY + zFactor1);
	x1 = parseInt(x1);
	x2 = parseInt(x2);
	y1 = parseInt(y1);
	y2 = parseInt(y2);
	ogcmap_rebre(x1,y1,x2,y2,adreca);
	}
}

//var winInfo=null;

function llistaCadastre(url){

	
winCAD=dhtmlwindow.open("winCAD", "iframe", url, "DGC", "width=450px,height=400px,left=280px,top=160px,resize=1,scrolling=1");
    var cp="Cadastre";
	if(language=="es"){cp="Catastro";}
	
	
	activaCapaxServidor(cp,"http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx?");
	
}


function idec_canviaImatge(url,nom){
	if(document.getElementById('posFitxes').style.display=='block'){
	document.getElementById('posFitxes').style.display='none';
	}
	document.getElementById(nom).src=url;
	
}

function idec_vgeo2MouseX(w,cx){
	return Math.round(w * (cx - coordInici[0] )/ (coordInici[2]- coordInici[0]  ) );
}
	
function idec_vgeo2MouseY(h,cY){
	return Math.round( h * (coordInici[3]-cY ) / ( coordInici[3] - coordInici[1]));
}

function idec_mouse2GeoX(w,mX){
	return coordInici[0] + mX * (coordInici[2] - coordInici[0])/w;
}

function idec_mouse2GeoY(h,mY){
	return coordInici[3] - mY * (coordInici[3] - coordInici[1])/ h;
}	 
	 
function idec_connexioWS(metode){
	//28 marzo
	if (xmlDoc.readyState != 1){
		var capaCarrer=document.getElementById('fooWS');
		xmin = map.cBounds[0];
		ymin = map.cBounds[1];
		xmax = map.cBounds[2];
		ymax = map.cBounds[3];
		mapaW=map.mapWidthPX;
		mapaH=map.mapHeightPX;
		var ampli=xmax - xmin;
		//var centreX=(xmax + xmin)/2;
		//var centreY=(ymax + ymin)/2;
		//var mapRef_left=idec_vgeo2MouseX(150,centreX);
		//var mapRef_top=idec_vgeo2MouseY(150,centreY);
		//document.getElementById('mapRef').style.top=(mapRef_top-5)+'px';
		//document.getElementById('mapRef').style.left=(mapRef_left-5)+'px';
		//mapRef_left="";
		//mapRef_top="";
		srs="23031";
		capes="CARRERS";
		//15 oct 08
		if(tipusAplicacio=="Carrerer" || tipusAplicacio=="Urbanisme" || tipusAplicacio=="Visual"){
			if(metode=="getMapaWMS"){
				if (document.getElementById("carrrer")){
					if (document.getElementById("carrrer").checked){
						if (ampli < 1500){
							ajax("/ideLocal/visual/getGeoWS.jsp?peticio=getMapaWMS&xmin="+xmin+"&ymin="+ymin+"&xmax="+xmax+"&ymax="+ymax+"&width="+mapaW+"&height="+mapaH+"&srs="+srs+"&capes="+capes+"&");
						}else{
							capaCarrer.style.display='none';
						}
					}
				}
			}
		}
		document.getElementById('posFitxes').style.visibility='hidden';
		/*
		if(tipusAplicacio=="Carrerer"){capaCarrer.style.visibility="visible";}
		if(schema=="Urbanisme"){capaCarrer.style.visibility="visible";}
		if(metode=="getMapaWMS"){
		
			if ((ampli < 1300)&&(capaCarrer.style.visibility=="visible")){
				ajax("/ideLocal/visual/getGeoWS.jsp?peticio=getMapaWMS&xmin="+xmin+"&ymin="+ymin+"&xmax="+xmax+"&ymax="+ymax+"&width="+mapaW+"&height="+mapaH+"&srs="+srs+"&capes="+capes+"&");
			}else{
				capaCarrer.style.visibility='hidden';
			}
		}
		*/
		//document.getElementById('posFitxes').style.display='block';
	}
}

function idec_cercaCarrer(){
	var tipusCarrer=document.getElementById('tipusCarrer').value;
	var nomCarrer=document.getElementById('nomCarrer').value;
	//var numCarrer=document.getElementById('numCarrer').value;
	var textcodiMunH = document.getElementById('txtcodiMunH').value;
	codiMun=document.getElementById('txtcodiMun').value;
	if(codiMun=="181609"){codiMun="171609";}
	if(codiMun=="181610"){codiMun="080193";}
	nomCarrer=canviValor(nomCarrer);
	
	if (textcodiMunH != ""){
		if(document.getElementById('cru').checked){
			var nomCarrer2=document.getElementById('nomCarrer2').value;
			ajax("/ideLocal/visual/getGeoWS.jsp?idec=000000&peticio=getCruillaUTM&tipusCarrer="+tipusCarrer+"&nomCarrer="+nomCarrer+"&nomCarrer2="+nomCarrer2+"&zFactor="+zFactor+"&codiMun="+codiMun+"&");
		}else{
			var numCarrer=document.getElementById('numCarrer').value;
			ajax("/ideLocal/visual/getGeoWS.jsp?idec=000000&peticio=getAdrecaUTM&tipusCarrer="+tipusCarrer+"&nomCarrer="+nomCarrer+"&numCarrer="+numCarrer+"&zFactor="+zFactor+"&codiMun="+codiMun+"&");
		}
	}else{
		alert("Has d'indicar un municipi");
	}
    
    if(winGInfo){
    tancaFR();}
}

//Març2007
function idec_cercaCarrerCandidats(tipusCarrer,nomCarrer,numCarrer){
    nomCarrer=canviValor(nomCarrer);
	document.getElementById('posFitxes').style.visibility='hidden';
	document.getElementById('fooWSXY').style.visibility='visible';
	
	
	ajax("/ideLocal/visual/getGeoWS.jsp?peticio=getAdrecaUTM&tipusCarrer="+tipusCarrer+"&nomCarrer="+nomCarrer+"&numCarrer="+numCarrer+"&zFactor="+zFactor+"&codiMun="+codiMun+"&");
}

//Març2007
function idec_cercaCarrerCandidatsIntersect(tipusCarrer,nomCarrer,nomCarrer2){
nomCarrer=canviValor(nomCarrer);
nomCarrer2=canviValor(nomCarrer2);
ajax("/ideLocal/visual/getGeoWS.jsp?peticio=getCruillaUTM&tipusCarrer="+tipusCarrer+"&nomCarrer="+nomCarrer+"&nomCarrer2="+nomCarrer2+"&zFactor="+zFactor+"&codiMun="+codiMun+"&");

}



var actiu="rc";
function idec_cercaCadastre(metode,valor){
	//codiMuniCad=valor;
	var nomViaCad=document.getElementById('nomCarrerCadastre').value;
	var numViaCad=document.getElementById('numCarrerCad2').value;
	codiMun="111111";
	
	if(metode=="getCarrersCadastre"){
	ajax("/ideLocal/visual/cercaCadastre.jsp?codiMun="+codiMun+"&metode="+metode+"&nomVia="+nomViaCad+"&codiMuniCad="+codiMuniCad+"&");	
	}else if(metode=="getAdrecaCadastre"){
	ajax("/ideLocal/visual/cercaCadastre.jsp?codiMun="+codiMun+"&metode="+metode+"&tipuVia="+tipusCarrerCadastre+"&numVia="+numViaCad+"&nomVia="+nomViaCad+"&codiMuniCad="+codiMuniCad+"&");	
	}else if(metode=="getRCCadastre"){
		var txtRC=e('txtRC').value;
		var txtPol=e('txtPol').value;
		var txtPar=e('txtPar').value;
	ajax("/ideLocal/visual/cercaCadastre.jsp?codiMun="+codiMun+"&metode="+metode+"&actiu="+actiu+"&txtRC="+txtRC+"&txtPol="+txtPol+"&txtPar="+txtPar+"&codiMuniCad="+codiMuniCad+"&");	
	}else{
		
	}
	
	}



function ogcmap_rebre(minX,minY,maxX,maxY,valor){
	document.getElementById('posFitxes').style.display='none';
	
	map.zoomFinestra(minX,minY,maxX,maxY);
	escriuValorInfo(valor);
	map.moureSlide();
}

function idec_iniciMapa(codi){
	init_ajax("infoCoord.jsp?valor="+codi+"&");
}

var tt=1;
var iniciMap = makeObject();

function init_ajax(sURL){
	iniciMap.open('GET', sURL,true);
	iniciMap.setRequestHeader("Content-Type", "text/html"); 
	iniciMap.onreadystatechange = parseInfoInit; 
	iniciMap.send('');
}

function parseInfoInit(){
	if(iniciMap.readyState == 1){}
	if(iniciMap.readyState == 4){ 
		if(iniciMap.status == 200){
			if(tt==1){
				document.getElementById('initMap').innerHTML=iniciMap.responseText;
				tt=2;
			}else{
				document.getElementById('initMap').innerHTML="";
			}
		}
	}
}   

function idec_centarZoom(e){
	var op=navigator.userAgent.toLowerCase().indexOf('opera')!=-1;
  	var ie = document.all;
  	if (ie || op) {
    	mX = e.clientX;
   	 	mY = e.clientY;
  	}
  	else {
    	mX = e.pageX;
    	mY = e.pageY;
  	}
 	var leftRR;
 	var topRR;
 	var matriucapes=document.getElementById('mapaSituacio');
	if(document.all){
		topRR=matriucapes.currentStyle.top;
		leftRR=matriucapes.currentStyle.left;
	}else{
		topDN=window.getComputedStyle(matriucapes, "");
		topRR=topDN.getPropertyValue("top");
		leftDN=window.getComputedStyle(matriucapes, "");
		leftRR=topDN.getPropertyValue("left");
	}
	mX=(mX - parseInt(leftRR));
 	mY=(mY - parseInt(topRR));
	mX1=(parseInt(map.mapWidthPX)*parseInt(mX))/150;
  	mY1=(parseInt(map.mapHeightPX)*parseInt(mY))/150;
	var dx = map.cBounds[2] - map.cBounds[0];
  	var dy = map.cBounds[3] - map.cBounds[1];
  	var x0 = idec_mouse2GeoX(parseInt(map.mapWidthPX),mX1);
	var y0=idec_mouse2GeoY(parseInt(map.mapHeightPX),mY1);
  	minX = x0-(dx/2.0);
  	maxX = x0+(dx/2.0);
 	minY = y0-(dy/2.0);
  	maxY = y0+(dy/2.0);
	map.zoomFinestra(minX,minY,maxX,maxY);
}

/**
 * Muestra el formulario de enviar email de incidencia
 * @param x valor en pixel de la posicion x del punteto donde se realizo el click
 * @param y valor en pixel de la posicion y del punteto donde se realizo el click
*/




var winMail;
function ogcmap_mailing(e){
	if (email == "NO"){
		alert("el contacte no està configurat");
	}else{
		//var str = "";
		//str = "<IFRAME id=\"correu\" name=\"correu\" frameborder=\"0\" height=\"340px\" width=\"310px\" src=\"email.jsp?x=" + x +"&y=" + y + "&contacto=" + contacto + "&email=" + email + "&servlet=" + servlet + "\">";
		//str += "</IFRAME>";
		
		
		coord = this.pixelToProj(position[0],position[1]);
    	//this.mailing(coord[0],coord[1]);
		
		
		
		var url="email.jsp?x=" + coord[0] +"&y=" + coord[1] + "&contacto=" + contacto + "&email=" + email + "&servlet=" + servlet;
		
		/*
		winMail= new Window('Info', {className: "alphacube",opacity:1,zIndex:350,top:85, left:270, width:310, height:340,minimizable:false,maximizable:false, showEffect:Element.show, hideEffect: Effect.SwitchOff});		
	winMail.setURL(url);
	winMail.toFront();
	winMail.setDestroyOnClose(true);
	winMail.show();
	*/
	
	winMail = dhtmlwindow.open("winMail", "iframe", url, "Info", "width=310px,height=340px,left=350px,top=95px,resize=1,scrolling=1");
	
	//27 nov 08 Oculta el punto al cerrar la ventana
	//winMail.onclose = cierraMail();
	//winMail.onclose = function(){
	//	document.getElementById('puntInci').style.visibility = 'hidden';
	//}
	
	
		
		//escribeForm(str,x,y);
	}
}

function cierraMail(){
	document.getElementById('puntInci').style.visibility = 'hidden';
}

/**
 * Escribe el formulario para enviar email de incidencia
 * @param str cadena que contiene el formulario
 * @param x valor en pixel de la posicion x del punteto donde se realizo el click
 * @param y valor en pixel de la posicion y del punteto donde se realizo el click
*/
function escribeForm(str,x,y){
	document.getElementById('posFitxes2').innerHTML="";
	document.getElementById('posFitxes2').style.height = "340px";
	document.getElementById('posFitxes2').style.width = "310px";
	document.getElementById('posFitxes2').style.display='block';
	document.getElementById('posFitxes2').innerHTML=str;
}

/**
 * Muestra la imagen de un punto donde se realizo el click
 * @param x valor en pixel de la posicion x del punteto donde se realizo el click
 * @param y valor en pixel de la posicion y del punteto donde se realizo el click
*/
function idec_puntIncidencia(x,y){
	var coord = new Array();
	coord = map.pixelToProj(x,y);
	document.getElementById('inciX').value=coord[0];
	document.getElementById('inciY').value=coord[1];
	document.getElementById('puntInci').style.top= (y-37) + "px";
	document.getElementById('puntInci').style.left= (x-10) + "px";
	document.getElementById('puntInci').style.visibility='visible';
}

/**
 * Muestra la imagen de un punto y una descripcion 
 * @param cX posicion x de la imagen de punto
 * @param cY posicion y de la imagen de punto
 * @param adreca descripcion que se muestra en pantalla
*/
function idec_activaMapaPunt(cX,cY,adreca){
	document.getElementById('posFitxes').style.display='none';
	document.getElementById('fooWSXY').style.visibility='visible';
	document.getElementById('cX').value=cX;
	document.getElementById('cY').value=cY;
	if (adreca=="null"){adreca="";}
	document.getElementById('adreca').value=adreca;
	map.redraw(1);
}

//28 marzo
var xmlDoc3 = makeObject();
/**
 * Realiza una llamada Ajax y retorna el combo con los elementos de interes
 * @param sURL parametros para la busqueda codigo de municipio y bbox
*/
function getToponimAjax(sURL){
	sURL = "metacerca.jsp?"+sURL+"&ramdom="+Math.random();
	xmlDoc3.open('GET', sURL, true);
	xmlDoc3.setRequestHeader("Content-Type", "text/html"); 
	xmlDoc3.onreadystatechange = parseToponimAjax; 
	xmlDoc3.send('');
}

/**
 * Escribe en el div de toponimos el combo de elementos de interes
*/
function parseToponimAjax(){
	document.getElementById('divCercaTopomin').innerHTML="";
	tipus="estacions";
	if(xmlDoc3.readyState == 1){escriuValorInfo('...');}
	if(xmlDoc3.readyState == 4){ 
		if(xmlDoc3.status == 200){
			document.getElementById('divCercaTopomin').innerHTML=xmlDoc3.responseText;
		}
	}
}

/**
 * Se llama cuando se cambia el valor de combo de toponimos
 * @param valor valor del combo de elementos de interes esta formato por "nombre: bbox"
*/
function zoomToponim(valor){

	if (valor != "no"){
		var topo = valor.split(":");
		var tipusEi= topo[2];
		var coords = topo[1];
		var coord = coords.split(" ");
		var pt1 = coord[0].split(",");
		var pt2 = coord[1].split(",");
		var x1 = pt1[0];
		var y1 = pt1[1];
		var x2 = pt2[0];
		var y2 = pt2[1];
		x1 = parseFloat(x1);
		x2 = parseFloat(x2);
		y1 = parseFloat(y1);
		y2 = parseFloat(y2);
		if(tipusEi==0){
			x1 = x1 - 350;
			x2 = x2 + 350;
			y1 = y1 - 350;
			y2 = y2 + 350;
			map.zoomFinestra(x1,y1,x2,y2);
		}else if(tipusEi==1){
			idec_activaGetMapaPunt(x1,y1,topo[0],250);
		}else{
			map.zoomFinestra(x1,y1,x2,y2);
		}
	}
}

/**
 * Muestra el div que contiene el combo con las escalas para hacer zoom.
*/
function ogcmap_muestraZoomEscala(){
	document.getElementById('posComboEscala').style.display = "block";
}

//26 marzo
/**
 * Oculta los divs que contienen la informacion de la escala actual y el de los elementos de interes.
*/
function ocultaInfo(){
	document.getElementById('posInfoEscala').style.display = "none";
	document.getElementById('divCercaTopomin').style.display = "none";
}

/**
 * Muestra los divs que contienen la informacion de la escala actual y el de los elementos de interes.
*/
function muestraInfo(){
	document.getElementById('posInfoEscala').style.display = "block";
	document.getElementById('divCercaTopomin').style.display = "block";
}
//12 julio 2007
function actualizaMonitor(valor){
	MONITOR_WIDTH = valor;
	PIXELPERINCH = RESOLUTION / MONITOR_WIDTH;
	if (ESCALACTUAL == 0){
		var extentWidth = map.cBounds[2] - map.cBounds[0]; 
		var num = parseInt(getScale2(extentWidth, getWidth()));
		ESCALACTUAL = num;
	}
	map.zoomescala(ESCALACTUAL);
}
//fin  12 julio 2007
function writePunt(){
	var puntoLbl = document.getElementById('punt');
	var etiqLbl = document.getElementById('label');
	var W = map.mapWidthPX;
	var H = map.mapHeightPX;
	var Mxmin = 0;
	var Mymin = H;
	var Mxmax = W;
	var Mymax = 0;
	var topE = 0;
	var leftE = 0;
	var topP = 0;
	var leftP = 0;
	if (puntoLbl != null){
		topP = parseInt(puntoLbl.style.top);
		leftP = parseInt(puntoLbl.style.left);
		if (leftP < Mxmin || leftP > (Mxmax - parseInt(puntoLbl.style.width))){
			puntoLbl.style.visibility = "hidden";
		}else{
			if (topP < Mymax || topP > (Mymin - parseInt(puntoLbl.style.height))){
				puntoLbl.style.visibility = "hidden";
			}else{
				puntoLbl.style.visibility = "visible";
			}
		}
	}
	if (etiqLbl != null){
		topE = parseInt(etiqLbl.style.top);
		leftE = parseInt(etiqLbl.style.left);
		if (leftE < Mxmin || leftE > (Mxmax - parseInt(etiqLbl.style.width))){
			etiqLbl.style.visibility = "hidden";
		}else{
		 	if (topE < Mymax || topE > (Mymin - parseInt(etiqLbl.style.height))){
				etiqLbl.style.visibility = "hidden";
			}else{
				etiqLbl.style.visibility = "visible";
			}
		}
	}
}

//28 nov 2007
function ogcmap_zoomLevel(level){
	var amplaIni=(coordInici[2] - coordInici[0]);
	var rango = amplaIni / ZOOMLEVELS;
	var multi = ZOOMLEVELS - parseInt(level);
	if (multi >= ZOOMLEVELS){
		this.fullExtent();
	}else if (multi <= 0){
		var nuevo = rango/2;
		//alert(nuevo);
		this.prevBounds[0] = this.cBounds[0];
	  	this.prevBounds[1] = this.cBounds[1];
	 	this.prevBounds[2] = this.cBounds[2];
	  	this.prevBounds[3] = this.cBounds[3];
	  	var dx = this.cBounds[2] + this.cBounds[0];
	  	dx = dx / 2;
	  	var dy = this.cBounds[3] + this.cBounds[1];
	  	dy = dy / 2;
	  	this.cBounds[0] = dx - nuevo;
	  	this.cBounds[2] = dx + nuevo;
	  	this.cBounds[1] = dy - nuevo;
	  	this.cBounds[3] = dy + nuevo;
	  	this.redraw();
	}
	else{
		var nuevo = (rango*multi)/2;
		//alert(nuevo);
		this.prevBounds[0] = this.cBounds[0];
	  	this.prevBounds[1] = this.cBounds[1];
	 	this.prevBounds[2] = this.cBounds[2];
	  	this.prevBounds[3] = this.cBounds[3];
	  	var dx = this.cBounds[2] + this.cBounds[0];
	  	dx = dx / 2;
	  	var dy = this.cBounds[3] + this.cBounds[1];
	  	dy = dy / 2;
	  	this.cBounds[0] = dx - nuevo;
	  	this.cBounds[2] = dx + nuevo;
	  	this.cBounds[1] = dy - nuevo;
	  	this.cBounds[3] = dy + nuevo;
	  	this.redraw();
	}
}

//28 feb 08
function ogcmap_zoomInicial(){
	bbox = new Array();
	bbox[0]=coordInici[0];
	bbox[2]=coordInici[2];
	bbox[1]=coordInici[1];
	bbox[3]=coordInici[3];
	bbox = this.adjustExtent(bbox);
	this.mapBounds[0] = bbox[0];
	this.mapBounds[1] = bbox[1];
	this.mapBounds[2] = bbox[2];
	this.mapBounds[3] = bbox[3];
	this.cBounds[0] = bbox[0];
	this.cBounds[2] = bbox[2];
	this.cBounds[1] = bbox[1];
	this.cBounds[3] = bbox[3];
	this.redraw();
}

//27 feb 08
function activaServidor(pos, ckc){
 var nser;
     var cp="";
	var visi = false;
	if (ckc.checked){
		visi = true;
	}else{
		visi = false;
	}
	for (k=0; k< map.servidores.length; k++) {
		if (map.servidores[k][0] == pos){
			map.servidores[k][3] = visi;
            nser=map.servidores[k][4];
            cp +=map.servidores[k][1]+",";
			var id = pos+"_"+map.servidores[k][1];
			document.getElementById(id).checked = visi;
		} 
	}
    
     if(nser.indexOf('(') !=-1){nser=nser.substring(0,nser.indexOf('('));
        }else{
            if(nser.indexOf('</') !=-1){nser=nser.substring(0,nser.indexOf('</'))}
        }
            
        var nomS=nser +";"+ map.layers[pos].url + ";" + cp+";"+ map.cBounds[0] + ";" + map.cBounds[1] + ";" + map.cBounds[2] + ";" + map.cBounds[3];       
if (ckc.checked){        
        interaccio('IDEC','V;'+nomS);
  }       
    
	map.redraw(1);
}

function redimencionaMap(){
	var top = map.topM;
	var left = map.leftM;
	map.mapWidthPX=wh.nW;
	map.mapHeightPX=wh.nH;
	var container = map.gid + "_container";
	var h = document.getElementById(container);
	h.style.width=wh.nW+"px";
	h.style.height=wh.nH+"px";
	if (h.hasChildNodes()){
		for (var i = 0; i < h.childNodes.length; i++){
			var divT = h.childNodes[i];
			if (divT.id){
				divT.style.width=wh.nW+"px";
				divT.style.height=wh.nH+"px";
			}
		}
	}
	document.getElementById('fooWS').style.width=wh.nW+"px";
	document.getElementById('fooWS').style.height=wh.nH+"px";
	document.getElementById('fooWSXY').style.width=wh.nW+"px";
	document.getElementById('fooWSXY').style.height=wh.nH+"px";
	document.getElementById('0mapCanvas').style.width=wh.nW+"px";
	document.getElementById('0mapCanvas').style.height=wh.nH+"px";
	document.getElementById('0mapCanvas').style.clip="rect(0," + wh.nW + "px," + wh.nH + "px,0)";
	document.getElementById('0_labelsDiv').style.width=wh.nW+"px";
	document.getElementById('0_labelsDiv').style.height=wh.nH+"px";
	document.getElementById('0_labelsDiv').style.clip="rect(0," + wh.nW + "px," + wh.nH + "px,0)";
	document.getElementById('0_loadDiv').style.width=wh.nW+"px";
	document.getElementById('0_loadDiv').style.height=wh.nH+"px";
	document.getElementById('cont_principal').style.width=wh.nW+"px";
	document.getElementById('cont_principal').style.height=wh.nH+"px";
	document.getElementById('cont_principal').style.clip="rect(0," + wh.nW + "px," + wh.nH + "px,0)";
	document.getElementById('0_selectionDiv').style.width=wh.nW+"px";
	document.getElementById('0_selectionDiv').style.height=wh.nH+"px"; 
	document.getElementById('0_selectionDiv').style.clip="rect(0," + wh.nW + "px," + wh.nH + "px,0)";
	document.getElementById('cont_general').style.width=wh.nW+"px";
	document.getElementById('cont_general').style.height=wh.nH+"px";
	document.getElementById('0_zoomBox').style.width=wh.nW+"px";
	document.getElementById('0_zoomBox').style.height=wh.nH+"px"; 
	document.getElementById('efecte').style.width=wh.nW+"px";
	document.getElementById('efecte').style.height=wh.nH+"px"; 
	document.getElementById('0_glassPane').style.width=wh.nW+"px";
	document.getElementById('0_glassPane').style.height=wh.nH+"px";
	document.getElementById('posInfo').style.top=eval(top + wh.nH)+"px";
	document.getElementById('posInfo').style.width=wh.nW+"px";
	document.getElementById('bBotondiv').style.width=wh.nW+"px";
	document.getElementById('posInfoEscala').style.top=eval(top + wh.nH)+"px";
	document.getElementById('leyendadiv').style.height=eval(wh.nH - 220)+"px";
	document.getElementById('0_toolcell_13').style.top=eval(top + wh.nH)+"px";
	document.getElementById('0_toolcell_13').style.left=eval((left + wh.nW)-60)+"px";
	document.getElementById('divCercaTopomin').style.top=eval(top + wh.nH)+"px";
	document.getElementById('nota_legal').style.top=eval(wh.nH - 15)+"px";
	map.postWrite();
}



function getURL4326(){

var ly=new Array();

	for(i=0;i< map.layers.length;i++){
					var sURL = map.layer_url(map.layers[i],i);					
					if((sURL.indexOf(".gif")==-1)&&(sURL.indexOf("orto5m")==-1)){
                    
                    
                    
                    
						ly.push(replaceBBOX(sURL));												
						
					}
				}


return ly;

}

function replaceBBOX(url){

//http://shagrat.icc.es/lizardtech/iserv/ows?&REQUEST=GetMap&SRS=EPSG:23031&VERSION=1.1.1&WIDTH=986&HEIGHT=787&STYLES=&TRANSPARENT=true&LAYERS=orto5m&BBOX=208085.7143,4466276.73139361,589514.2857,4770723.26860639&FORMAT=JPEG

       if(url.indexOf('23031')!=-1){

            url=url.replace('23031','4326');
            var pos=url.substring(url.indexOf('BBOX='),url.length);
           
           var bbox=pos.substring(5,pos.indexOf('&'));
           var cof=transCoordUTMxGEO();
           url=url.replace(bbox,cof.x0+','+cof.y0+','+cof.x1+','+cof.y1);            
        }
        
        return url;
        
}
