//<![CDATA[
/*

IDELOCAL 05 sep 2006 Versio 1.9

this library is based on:

inlineWMS
Copyright (c) 2002 The University of Kansas Natural History Museum and 
Biodiversity Research Center (NHM & BRC)

All rights reserved.

Developed by: 		Dave Vieglais
                    NHM & BRC 
                    http://speciesanalyst.net
----------

Also has been modified by Nedjo Rogers (nedjo@gworks.ca)

----------

Finally modified by ideLocal

*/                    
var DELTAMAP = 150;
//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('Palau Robert');return false;}
	}else{
		if(e.which >1){alert('Palau Robert');return false;}
	}
*/
}


window.status="ideLocal";

asdf=0;
var pass="1";
var coordInici= new Array(260383.88,4491989,527495.1,4748184);
var coordIniciR= new Array(260383.88,4491989,527495.1,4748184);
var estatInicial="inici";
var pasZoom="punter";
var avisCarrerer="<b>Ajudan's a millorar:</b><br>Si observes algun error en el carrerer, activa el botó i marca'l sobre el mapa.";
var codiEmail="";




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;
}

// the global set of dynamically generated maps within the document
var g_ogcMaps = new Array();






//finds the image with "name" within the document "doc".
//In netscape, this method recurses through all layers until the
//image is found or not found.
//in:
//  name: the name of the image
//  doc: the document to search in - usually start with window.document.
//out: image object or null if not found.
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) {
  capaQ +=this.servidores[k][1]+",";
  
   }
   }
   }
   var gfh=(capaQ.length-1);
   capaQ=capaQ.substring(0,gfh);
   
   sURL += "&QUERY_LAYERS="+capaQ;
   sURL += "&LAYERS="+capaQ;
  sURL += "&SRS="+aLayer.epsg;
  sURL += "&X=" + x;
  sURL += "&Y=" + y;
  sURL += "&WIDTH="+this.mapWidthPX;
  sURL += "&HEIGHT="+this.mapHeightPX;
  sURL += "&FEATURE_COUNT=1";
  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=MIME";
 }else{
 sURL += "&INFO_FORMAT=text/html";
 }
  // 
  return sURL;
}
String.prototype.equalsIgnoreCase=MatchIgnoreCase;
function MatchIgnoreCase(str1,str2){

if(str1==str2){
return true;
}else{
return false;
}
} //End Function

//Nova funcio per fer Ajax
function ogcmap_queryLayerURLAjax(aLayer,x,y) {
//var servidor=aLayer.url;
var servidor=iservlet;
var sURL ="";
var tp=tipusPRobert;
//var servidor="http://193.144.250.29/cgi-bin/mapserv?map=/opt/idec/dades/umn/localitzador.map&";
//servidor=servidor.replace('?','&');

if(MatchIgnoreCase(tipusPRobert,'0')){
servidor=iservlet;
servidor=servidor.replace('?','&'); 
	sURL +="SERVIDOR="+servidor;
	sURL += "&LAYERS=Municipis,TRACKS";
}

else if(MatchIgnoreCase(tipusPRobert,'NO')){
servidor=servidor.replace('?','&'); 
	sURL +="SERVIDOR="+servidor;
	sURL += "&LAYERS=Municipis,TRACKS";
}
else{


servidor= servlet;
servidor=servidor.replace('?','&'); 
	sURL +="SERVIDOR="+servidor;
	sURL += "&LAYERS=PUNTS";

} 
//servidor=servidor.replace('?','&'); 

  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];
  sURL += "&tipusPRobert=" + tipusPRobert;
   sURL += "&cercaTracks=" + idioma;
 sURL += "&infoMuni=" + infoMuni;
 
  return sURL;
}


//converts pixel to projected (or decimal degree) coordinates
//in: xp = x coordinate, yp= y coordinate
//out: array[0..1], 0 = xcoord, 1 = ycoord
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;
}

//converts projected (or decimal degree) coordinates to pixel
//in: xp = x coordinate, yp= y coordinate
//out: array[0..1], 0 = pixelx, 1 = pixely
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();
}

function ogcmap_queryUI(x,y) {
var sURL

dataWindow=open("","","toolbar=0,directories=0,menu=0,scrollbars=0,location=0,resizable=1,status=0,top=100,left=150,width=350,height=350,menubar=0,dependent=0,hotkeys=0")
dataWindow.document.open();
dataWindow.document.write("<html><head><title>GetfeatureInfo</title></head>");
dataWindow.document.write('<link rel="stylesheet" href="css/'+codiMun+'.css">');
dataWindow.document.write('<script>');
dataWindow.document.write('function getInfo(index,template,format){document.getElementById("ifrFeatureInfo").src=document.getElementById(index).value;}');
dataWindow.document.write('</script>');
dataWindow.document.write('<form name="frmInfo"><u><b>GetFeatureInfo</b></u>');
dataWindow.document.write('<div style=height:140;overflow:auto><table border="1" cellspacing="0" cellpadding="0" bgcolor="#F4F5F7" bordercolor="#FFFFFF" width="100%">');
//10 NOV
var control = 0;
for (i=0;i < this.layers.length;i++){

	if (this.layers[i].queryable){
			var visib = this.serVisible(i);
			//alert(visib);
			if (visib){
			//if (this.layers[i].visible){
				//alert(i);
				control = 1;
				dataWindow.document.write("<tr><td class=\"normal\">"+this.layers[i].srvname+" <img OnClick=\"getInfo("+i+",'si','text/html')\" alt=\"Informació objecte seleccionat\" style=\" cursor:pointer;cursor:hand\" src=\"images/info.png\" width=\"17\" height=\"17\"></td></tr>");
		 		var rutaServ=this.queryLayerURL(i,this.layers[i],x,y);
		 		if (i == this.layers.length){
		 			rutarServ = rutaServ.replace('text/html','mime');
		 		}
		   		dataWindow.document.write('<input type="hidden" id="'+i+'" value="'+rutaServ+'" > ');
		 	}
		
		//sURL = this.queryLayerURL(this.layers[this.queryLayer],x,y);
		//window.open(sURL,this.prefix + "_QlayerUI","height=300,width=300,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes",false);
	}
}
if (control == 0){dataWindow.document.write('No hi ha cap capa activada');}
//10 NOV fin
dataWindow.document.write('</table></div><IFRAME frameborder="0" id="ifrFeatureInfo" width="100%" height="80%">');
dataWindow.document.write("</iframe></form></html>");
dataWindow.document.close();


/*

    
  
   
     
      } 

*/


/*
  if (!this.query)
    return;
  if (this.queryLayer < 0)
    return;
  if (this.queryLayer >= this.layers.length)
    return;
  var sURL = this.queryLayerURL(this.layers[this.queryLayer],x,y);
  */
  
  
  //alert(this.query);
 //alert(sURL);
 //var w =window.open(sURL,this.prefix + "_QlayerUI","height=300,width=300,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes",false);
}





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.style.backgroundColor="white";
     
      prevCell.className="normal"
    }
  }
  this.opcode = idx;
  if(this.toolbar == true) {
    var toolCell = ogcmap_getElt(this.gid + "_toolcell_"+this.tools[this.opcode].opcode);
    
 
    
      toolCell.className="sobre"
     // toolCell.style.backgroundColor="green";
  }
}

//10 NOV
function ogcmap_serVisible(idx) {
  if (idx < 0)
    return;
  if (idx >= this.layers.length)
    return;
    var ver = false;
    //alert(this.servidores[idx][3]);
   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(3);
            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=\"position:absolute;left:" + pt[0]+ "px;top:" + pt[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: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() {
//alert("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;
  //var k = 0;
  //alert(this.inputPts.length);
  
  
   //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').style.visibility='visible';
		document.getElementById('efecte').innerHTML=sWS;
  	}
  
	if(document.getElementById('puntInci').style.visibility=='visible'){
		//alert("entra");
		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
  //alert(k);
  if (i != 0) {
    //alert("entra");
    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
    //alert((xmax - xmin) + " ,  " + (ymax - ymin));
    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.";
    	//alert(total + " mts");
    	escriuValorInfo(stotal);
    }
   }
   
  
   
   
   
  //14 NOV fin
    
    imgxs[imgxs.length] = parseInt(tmp[0]);
    imgys[imgys.length] = parseInt(tmp[1]);
    //alert("X " + imgxs + " , Y " + imgys); 
    s += this.getSelectionPoint(i,tmp,total);
    //k = i;
  }
  if(imgxs.length > 1) {
  	//borra el tramo se elimina un punto
    this.jg.clear();
    //crea la linea
    this.jg.drawPolyline( imgxs, imgys );
//    this.jg.fillEllipse(imgxs[0]-markerdiam, imgys[0]-markerdiam, markerrad, markerrad);
//    this.jg.fillEllipse(imgxs[imgxs.length-1]-markerdiam, imgys[imgys.length-1]-markerdiam, markerrad, markerrad);
  }
  //else if(imgxs.length == 1) {
//    this.jg.fillEllipse(imgxs[0]-markerdiam, imgys[0]-markerdiam, markerrad, markerrad);
  //}
  //dibuja la linea
  this.jg.paint();
  //escribe el punto
  this.selectionDiv.innerHTML = s;
  //hola();
  //alert(s);
  //if(this.inputPts.length > 0) {
  //  this.transferPoints(this.editType, this.inputPts);
  //}
}

function ogcmap_getSelectionPoint(idx,pt,dist) {
	
//  return "<div id=\"" + this.gid + "_selection_" + idx + "\" style=\"padding:1px;cursor:move;border:1px solid black;position:absolute;width:5px;height:5px;left:" + ((pt[0]) - 3) + "px;top:" + ((pt[1]) - 3) + "px;\"><img src=\"" + this.baseDir + "point.gif\"></img>" + idx + "</div>";
  //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\" style=\"z-index:1000;padding:1px;cursor:pointer;cursor:hand;border:0px none black;position:absolute;width:5px;height:5px;left:" + ((pt[0]) - 8) + "px;top:" + ((pt[1]) - 8) + "px;\"><img  src=\"images/point.gif\"></img></div>";
 
  if((dist == "null")||(dist == "")){}else{
  	
   var sj0 = "<div id=\"label\"  style=\"background-color: #FFFFE7;z-index:1000;font-family:Verdana,Helvetica,sans-serif;font-size:11px;color:#FF0000;border:2px solid ridge;border-style: outset;border-color:#FFFFE7;filter:alpha(opacity=80);-moz-opacity:0.8;padding-left:2px;padding-right:2px;position:absolute; ;height:5px;left:" + ((pt[0]) + 15) + "px;top:" + ((pt[1]) - 15) + "px;\"><p STYLE=\"color: red\"><b>" + dist + "</b></p></div>";
  
  }
  
  
  return sj+sj0;
}
//

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]);
    //alert("sURL"+i+":"+sURL);
    var img = 0;
    if (document.all) {
      img = document.images[this.prefix+i];
    
    }
    else {
      img = ogcmap_findImage(this.prefix+i,document);
     
    }
    //this.layers[i].loaded = false;
    
    if (this.layers[i].visible == false) {
      img.src = sURL;
      //alert("sURL0"+i+":"+sURL);
    }
    else {
      img.src = this.baseDir + "blank.gif";
    }
 
 
 }
 
  }
  this.container.style.visibility = "hidden";
  //this.showLoading();
  this.drawPts();
  this.writeLabels();
}




function ogcmap_setLoaded(idx) {
//escriuValorInfo(idx);
//this.layers[idx].src="images/blank.gif";
  if(this.loadDiv) {
  	 
    this.layers[idx].loaded = true;
    this.testLoaded();
    //ogcmap_hideLoading();
  }
}

/*
function ogcmap_showLoading() {
  this.loadDiv.style.visibility = "visible";
}

function ogcmap_hideLoading() {
  if(this.loadDiv) {
    this.loadDiv.style.visibility = "hidden";
    
    this.container.style.left = "0px";
    this.container.style.top = "0px";
    
  }
}
*/
function ogcmap_showLoading() {
  this.loadDiv.style.visibility = "visible";
 
 var nom=this.loadDiv.id;
 
  setTimeout('ogcmap_hideLoading()',2000);
  
  
}

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";
}

 

}


//sets the current map extents to the full extents and redraws the layers
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();
}

//sets the current extent to the previous extent and redraws the layers
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)){
  	//alert("entra");
  	this.fullExtent();
  }else {
  	this.redraw();
  }
}

function ogcmap_afegirServidor() {

var divServ =document.getElementById('posServer');
var ifrmServ=document.getElementById('ifrServer');


finestra = window.open("obert.jsp?estil=resultats","nouserv","top=50,left=150,width=350,height=360,scrollbars=yes,status=yes"); 
finestra.focus() ;
/*
if(divServ.style.display=='block'){
divServ.style.display='none';
}else{
  divServ.style.display='block';
  
  ifrmServ.src='obert.jsp?estil=resultats';
 }
*/ 
  
}

//zooms in on the specified pixel coordinate
function ogcmap_zoom(xp,yp) {
//alert("zoom");
  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() {
//alert("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){
//alert("zoomFinestra");
bbox = new Array();
  bbox[0]=minX;
  bbox[2]=maxX;
  bbox[1]=minY;
  bbox[3]=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();
}


//Does the opposite of zoom()
function ogcmap_zoomOut(xp,yp) {
//alert("zoomOut");
  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){
//alert(valor);
var L = parseFloat(this.cBounds[0]);
var D = parseFloat(this.cBounds[1]);
var R = parseFloat(this.cBounds[2]);
var T = parseFloat(this.cBounds[3]);
valor=parseFloat(valor);

var ampla=parseFloat(R-L);
var alta=parseFloat(D-T);
var C_X = parseFloat(ampla/2);
var C_Y = parseFloat(alta/2);
var Center_X = parseFloat(L+C_X);
var Center_Y = (T+C_Y);
theValue = (this.mapWidthPX) / (72 * 39.3701) * valor;
this.cBounds[0] = Center_X - (theValue/2);
this.cBounds[2] = Center_X + (theValue/2);

this.cBounds[1] = Center_Y - (theValue/2);

this.cBounds[3] = Center_Y + (theValue/2);

this.redraw();
}

function ogcmap_zoomPt(x,y) {

  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;

  this.cBounds[0] = x-(dx/15);
  this.cBounds[2] = x+(dx/15);
  this.cBounds[1] = y-(dy/15);
  this.cBounds[3] = y+(dy/15);

  this.redraw();
}

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_pan(xp,yp) {

}

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);
}

function ogcmap_mouseDown(e) {

  position = this.position(e);
  switch(this.opcode) {
    case 0:
      this.pt1 = position;
      this.zoomBox.style.visibility="visible";
      this.zooming = true;
      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]);
      //this.quering=true;
      //this.mouseStopped = true;
      this.queryAjax(position[0],position[1]);
      break;
    case 6:
      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 7:
      var pt = this.pixelToProj(position[0],position[1]);
      var str = prompt("Escriure text:","");
      if(str != null) {
        this.addLabel(pt,str);
      }
      break;
    case 11:
    	//alert("incidencia");
		idec_puntIncidencia(position[0],position[1]);
		coord = this.pixelToProj(position[0],position[1]);
    	this.mailing(coord[0],coord[1]);
  }
  return false;
}
var posXFinal=0;
var posYFinal=0;
 var tru=0;
function ogcmap_mouseMove(e) {

if(this.opcode==3){this.quering=false;document.getElementById('divEmpresa').style.display='block';}else{this.quering=false;document.getElementById('divEmpresa').style.display='none';document.getElementById('divEmpresa').innerHTML='';}
  position = this.position(e);
  proj = this.pixelToProj(position[0],position[1]);
  window.status = "x: " + Math.round(proj[0]*1000)/1000 + " y: " + Math.round(proj[1]*1000)/1000;
  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";
  }
  
  else if(this.quering) {
  if(this.chrono != null){		clearTimeout(this.chrono); 	}
    this.pt2 = position;
    
    this.pt2[0];
   
   
    if(this.mouseStopped == false){		
    this.chrono = setTimeout("map.ompleMouseXY()", 1000);	}
    
    
  }
  
  return false;
}



function idec_ompleMouseXY(){



clearTimeout(this.chrono);	
this.mouseStopped = true;	

this.queryAjax(position[0],position[1]);
	
this.mouseStopped = false;




}


function ogcmap_mouseUp(e) {
  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) {
    this.panning = false;
    
    //this.container.style.left = "0px";
    //this.container.style.top = "0px";
    this.prevBounds[0] = this.cBounds[0];
    this.prevBounds[1] = this.cBounds[1];
    this.prevBounds[2] = this.cBounds[2];
    this.prevBounds[3] = this.cBounds[3];
    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 == 6) {
    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) {
this.quering=false;
//document.getElementById('divEmpresa').style.display='none'
  window.status = "Palau Robert";
}

function ogcmap_escriuCapa(){

//<div style="margin: 0pt; padding: 0pt; width: 500px; height: 500px; position: absolute;" >
//<img width="500" height="500" src="images/blank.gif" onload="g_ogcMaps[0].setLoaded(10)" name="map_g0_10" id="map_g0_10" style="opacity: 1;"/>

	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;
	//alert(nlayers);
	for (var i=0; i < nlayers; i++) {
		nou = "<div style=\"margin: 0pt; padding: 0pt; width:" + this.mapWidthPX + "px; height: " + this.mapHeightPX + "px; position: absolute;\" ><img style=\"filter:alpha(opacity=100);-moz-opacity:1;\" id=\"" + this.prefix+i+ "\" name=\"" + this.prefix+i+ "\" onload=\"g_ogcMaps["+gid+"].setLoaded(" + i + ")\" src=\"" + this.baseDir + "blank.gif\" " + swh + "></img></div>\n";
	}
	MapActu=MapActu +nou ; 
	
	document.getElementById(contenedor).innerHTML=MapActu;
	this.postWrite();
}

function ogcmap_imprimir(){

//activaCapesURL("Ajuntament,Biblioteca")

window.open("/idecwebservices/probert/image.htm", "Imprimir", 'width=800,height=750,left=100,top=100,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 = ext[2] - ext[0];
  var dy = ext[3] - ext[1];
  if(dx/this.mapWidthPX>dy/this.mapHeightPX){
    ext[1]=ext[1]-(((dx/this.mapWidthPX*this.mapHeightPX)-dy)/2);
    ext[3]=ext[3]+(((dx/this.mapWidthPX*this.mapHeightPX)-dy)/2);
  }
  else{
    ext[0]=ext[0]-(((dy/this.mapHeightPX*this.mapWidthPX)-dx)/2);
    ext[2]=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.hideLoading();
  this.container.style.visibility = "visible";
}

function ogcmap_postWrite() {
  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");
  this.redraw();
}

function ogcmap_calculaEscala(){

var escala2;
   escalaN=(this.cBounds[2]-this.cBounds[0])/2;
 
   
   	escalaN=escalaN/2
   	//escalaN=Math.round(escalaN*10)/10;
   	
   	
   	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",btZoom,"setTool(0)",true);
  this.addTool(1,"zoomout","zoom out",btZoomMenys,"setTool(1)",true);
  this.addTool(2,"centrar","recenter map",btPan,"setTool(2)",true);
  this.addTool(3,"identificar","add point",btInfo,"setTool(3)",this.query);
  
  if(infoMuni=="NO"){tipusAplicacio="Visual"}
  if(tipusAplicacio=="Visual"){
  this.addTool(4,"inici","home",btInici,"fullExtent()",true);
  }else{
   this.addTool(4,"imprimir","Afegir Servidor",btImprimir,"imprimir()",true);
  }
   this.addTool(5,"inici","home",btInici,"fullExtent()",true);
  //this.addTool(5,"tornar","Vista anterior","Vista anterior","previousExtent()",true);
   if(infoMuni=="NO"){tipusAplicacio="Carrerer"}
  //this.addTool(6,"servidor","Afegir Servidor","Afegir Servidor.","afegirServidor()",true);
  //this.editType
  this.addTool(6,"mesurar","digitize feature","Mesurar distàncies","setTool(6)",editEnabled);
  this.addTool(7,"etiquetar","label","Afegir text en un click","setTool(7)",true);
  this.addTool(8,"esborrar","Afegir Servidor","Esborrar gràfics","limpiar()",true);
  this.addTool(9,"imprimir","Afegir Servidor","Imprimir vista","imprimir()",true);
  this.addTool(10,"resize","Canviar tamany del mapa","Canviar tamany del mapa","resize()",true);
  this.addTool(11,"incidencia","Enviar Incidència","Enviar Incidència","setTool(11)",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.quering=false;
  this.chrono=null;
  this.mouseStopped=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;
  
  
//methods
this.ompleMouseXY=idec_ompleMouseXY;
//23 feb
this.resize = ogcmap_resize;
this.mailing = ogcmap_mailing;
//23 feb fin
this.redibuja = ogcmap_redibuja;
this.imprimir=ogcmap_imprimir;
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;
  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;
//10 NOV
  this.serVisible = ogcmap_serVisible;

// initialization
  this.init();
}

//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 parametres="mapaRefe.jsp?caixaBB="+caixaBB+"&codiMun="+codiMun+"&tipus="+tipusAplicacio;
var consultaWMS="images/maparefe.png";
var a="<img onclick=\"idec_centarZoom(event)\" style=\"cursor:pointer;cursor:hand;\" src=\""+consultaWMS+ "\" ><div id=\"mapRef\"  style=\"z-index:20;background-image: url(images/creu.gif);position:absolute;top:70px;left:70px;overflow:hidden;width:10px;height:10px;border:1px none;border-color:#FF0000;\"></div>" ;

document.getElementById('mapaSituacio').innerHTML=a;
//var consultaWMS="http://shagrat.icc.es/lizardtech/iserv/ows?REQUEST=GetMap&VERSION=1.1.1&SRS=EPSG:23031&Service=WMS&BBOX="+caixaBB+"&WIDTH=150&HEIGHT=150&LAYERS=sat250m,orto25m&STYLES=&FORMAT=JPEG&";

//ajaxIMG2(parametres);

//xmlImg.open('GET',parametres,true);
//xmlImg.setRequestHeader("Content-Type", "text/html"); 
//xmlImg.onreadystatechange = parseImg2; 

//xmlImg.send('');


}


function parseImg2(){

//document.getElementById('posFitxes2').innerHTML="";
	
if(xmlImg.readyState == 1){}
if(xmlImg.readyState == 4){ 

		if(xmlImg.status == 200){
		//alert(xmlImg.responseText);
//document.getElementById('posFitxes').style.visibility='visible';
document.getElementById('mapaSituacio').innerHTML=xmlImg.responseText;


}
}
}   


function idec_escriuCerques(tipus,posLeft){

a ="<table><tr><td>";
a +='<select class="comboLoca" id="Escull" name="Escull" >';
a +='<option value="Municipis">Municipis</option><option value="Comarques">Comarques</option></select>';
a +="</td></tr><tr><td>";
a +="<input type=\"text\"  class=\"comboLoca\" OnMouseOver=\"this.focus();\" name=\"txtDades\" id=\"txtDades\" onkeyDown=\"capturaTecla(event);\"  >";
a +="</td></tr><tr><td>";
a +="<input type=\"button\"  class=\"boto\" value=\"Cercar\"  name=\"botocer\" id=\"botocer\" Onclick=\"cercarDades();\"  >";
a +="</td></tr></table>";

/*
a='<table width="100%" border="0" cellspacing="0" cellpadding="0" >';
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> ';
  
 if((codiMun.length < 4)&&(tipusAplicacio=="Carrerer")){
 a +='</tr><td> ';
a +='<select class="text" style="width:150px" onchange="codiMun=this.value" >';
//a +='<option selected value="'+comarca[0][0]+'">Municipis</option>';
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="Carretera">Carretera</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="Urbanització">Urbanització</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 +='</td> ';
      //a +='<td> ';
        //a +='<div align="right">'; 
         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 +='</div>';
      
a +="</td></tr></table>";

*/
return a;
      
}

//Funcions de cerques

function capturaTecla(e) {

      //if (browser.isNS7){}else{  
        
       if(document.all){
            tecla=event.keyCode;
            //alert("keycode");
        }else{
        //alert("which");
            tecla=e.which; 
        }
        
     if(tecla==13){
      while (tecla==13){
          cercarDades();
          break;}
           
        }
        
    }
    
    function idec_capturaTecla(e) {

      //if (browser.isNS7){}else{  
        
       if(document.all){
            tecla=event.keyCode;
            //alert("keycode");
        }else{
        //alert("which");
            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');


 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;
}

var xmlDoc = makeObject();

function ajax(sURL){
//alert(sURL);
//document.write(sURL);
xmlDoc.open('GET', sURL,true);
xmlDoc.setRequestHeader("Content-Type", "text/html"); 
xmlDoc.onreadystatechange = parseInfo; 

xmlDoc.send('');
}

function parseInfo(){

document.getElementById('posFitxes').innerHTML="";
	tipus="estacions";
if(xmlDoc.readyState == 1){escriuValorInfo('CERCANT...');}
if(xmlDoc.readyState == 4){ 
escriuValorInfo('');
		if(xmlDoc.status == 200){
		//alert(xmlDoc.responseText);
document.getElementById('posFitxes').style.visibility='visible';
document.getElementById('posFitxes').innerHTML=xmlDoc.responseText;


}
}
//escriuValorInfo('')
}   


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){
		//alert(xmlDoc.responseText);
//document.getElementById('posFitxes').style.visibility='visible';
document.getElementById('posFitxes2').innerHTML=xmlDoc2.responseText;


}
}
}   



function getFeatureAjax(sURL){


xmlDoc.open('GET','infoAjax.jsp?'+sURL,true);
xmlDoc.setRequestHeader("Content-Type", "text/html"); 
xmlDoc.onreadystatechange = parseInfoAjax; 

xmlDoc.send('');
}

function parseInfoAjax(){

//document.getElementById('posFitxes').innerHTML="";
	tipus="estacions";
if(xmlDoc.readyState == 1){}
if(xmlDoc.readyState == 4){ 

		if(xmlDoc.status == 200){
		
		
		escriuValorInfo(xmlDoc.responseText);


}
}
}   
//Nova funcio per industria
var newX=0;
var newY=0;
var amp=118;
var alt=65;  
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);

var factorpx=5;
if(document.all){factorpx=0;}

newX=x-factorpx;
newY=y-factorpx;
  
  
  
if(document.all){noie="";}else{
noie="<tr><td align=\"right\"><img style=\"cursor:hand;cursor:pointer\" Onclick=\"javascript:document.getElementById('divIn').style.display='none';\"  name=\"img\"   src=\"images/closex.gif\"></img></td></tr>";}

sj = "<div id=\"divIn\"  OnMouseOver=\" map.mouseStopped = true;\" OnMouseOut=\" map.mouseStopped = false;\"  class=\"toolcoordn\" style=\"border: 1px #AD2942 solid;overflow:auto;width:"+parseInt(amp+2)+"px;height:"+parseInt(alt+2)+"px;left:0px;top:0px;\">";



//sj += "<table class=\"taulaE\" border=\"0\" cellspacing=\"3\">"+noie+"<tr><td>"+nom+"</td></tr><tr><td><a Onclick=obreFitxa('"+ruta+idioma+"&v_codi_esta="+codi_esta+"&v_codi_empre="+codi_empre+"&"+finalruta+"') href='#'>Veure Fitxa</a></td></tr></table>
sj += "</div>";

 //nomTexteDiv="d_punt_" + idx;
document.getElementById('divEmpresa').innerHTML=sj;

 getFeatureAjax(sURL);
  //document.getElementById('einesCerca').innerHTML=sURL;
 //var w =window.open(sURL,this.prefix + "_QlayerUI","height=300,width=300,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes",false);
}


var idObjecte="";
var capaEqui="";
var capaM="capa";
var capaC="capaC";
var tipusAmbit="CODMUN"; 

function tancaDivIn(){

document.getElementById('divEmpresa').style.display='none';
}
 
function cercarDades(){


idObjecte="";
var tipu=document.getElementById('Escull').value;
var topotext1=document.getElementById('txtDades').value;

var topotext=canviValor(topotext1);

ajax("cercaAjax.jsp?capa="+tipu+"&valor="+topotext+"&cerca=0");


}



function escriuValorInfo(valor){


var capaEscriu=document.getElementById('divIn');

if(valor.indexOf('zzzzzz')==-1){

//var alt=parseInt(valor.length/10);



if(parseInt(newX + amp)>= 300){newX=parseInt(newX-amp);}
if(parseInt(newY + alt)>= 300){newY=parseInt(newY-alt);}

capaEscriu.style.visibility='visible';
capaEscriu.style.display='block';
//capaEscriu.style.width=alt+"px";
//capaEscriu.style.height=alt+"px";
capaEscriu.style.top=newY;
capaEscriu.style.left=newX

capaEscriu.innerHTML=valor;

}else{
capaEscriu.style.visibility='hidden';
capaEscriu.style.display='none';
}

}

function capturaID(id,valor){

 if (idObjecte ==""){
 idObjecte=id;
 }else{
 
 document.getElementById(idObjecte).className='normal';
 idObjecte=id;
 }
 
 escriuValorInfo(valor);
}
 
function capturaIDEqui(id,equipament){
 
 
 if (idObjecte ==""){
 idObjecte=id;
 capaEqui=equipament;
 }else{
 
 document.getElementById(idObjecte).className='normal';
 idObjecte=id;
   capaEqui=equipament;
 }
 }
 
 
 
 function tancaFR(){
 
document.getElementById('posFitxes').style.visibility='hidden'; 	

 }

function tancaDIV(capa){
 
document.getElementById(capa).style.display='none'; 	

 }

 function resultats(estat,capaAct){
 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);

 
 }}
} 
//////nuevos

//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++) {
			//alert(map.servidores[i][0] + "_" + map.servidores[i][1]);
			var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
			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].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++) {
			//alert(map.servidores[i][0] + "_" + map.servidores[i][1]);
			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].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 activaCapesTemes(valor,estat){

for (var i=0; i<map.servidores.length; i++) {
	if (map.servidores[i][7] == valor) {
		var nombrechk = map.servidores[i][0] + "_" + map.servidores[i][1];
			document.getElementById(nombrechk).checked = estat;
	  		map.servidores[i][3] = estat;
	  		
	}
  }
  map.redraw(1);
}

//20 jul fin

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);
	//alert(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) {
//if(item==1){topo2=document.getElementById('2');topo3=document.getElementById('3');}
   obj=document.getElementById(item);
   visible=(obj.style.display!="none")
   key=document.getElementById("x" + item);
   if (visible) {
     obj.style.display="none";
     //if(item==1){topo2.style.display="none";topo3.style.display="none";}
     
     key.innerHTML="<img src='" + map.baseDir + "skin/" + map.skin + "/images/folder.gif' width='16' height='16' hspace='0' vspace='0' border='0'>";
   } else {
      obj.style.display="block";
        //if(item==1){topo2.style.display="block";topo3.style.display="block";}
      key.innerHTML="<img src='" + map.baseDir + "skin/" + map.skin + "/images/textfolder.gif' width='16' height='16' hspace='0' vspace='0' border='0'>";
      //alert(key.innerHTML);
   }
}

//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);
	//alert(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;

	
document.getElementById(id).src="images/blank.gif";
//alert(document.getElementById(id).src);
}

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\'}">Activar capa</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\'}">Desactivar capa</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\'}">Transparencia</td></tr>';
	
	
	if(titulo.indexOf('undefined')==0 ||titulo==""){
	//alert("El titol0:"+titulo);
	}else{
	//alert("El titol1:"+titulo);
	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\'}"> Metadades </td></tr>';
	}
	
	texte+='</table>';

//document.write(texte);
	pro.innerHTML=texte;
}

//adds a layer to the map
//in: url = base url of layer
//    name = ogc wms name of the layer
//    transparent = boolean indicating if the layer should provide a transparent background
//    visible = boolean indicating if the layer is to be retrieved and drawn
//out: no return value

function idec_metadades(capes,nom){

//alert(nom);
if(nom.indexOf('Institut')==-1){
//capes="";
}
//alert(capes);
var id = "cercaRapida=*"+capes+"*,*"+capes+"*&org="+nom;
             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=xmin;
		var yn=ymin;

        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=xmax;
var yx=ymax;
var addNSb=0;
var nomIdiomaCurt="CA";


dataWindow=open('frameset.html','cd','menubar=no,status=no,toolbar=no,width=550,scrollbars=yes,top=100, left=100,resizable=yes,height=300');
dataWindow.document.open();
dataWindow.document.writeln("<HTML><HEAD><TITLE>ICC</TITLE>"); 
dataWindow.document.writeln("<SCRIPT LANGUAGE='JAVASCRIPT' TYPE='TEXT/JAVASCRIPT'>;function initialFunc(){ var _d='<div id=\"dd\" style=\"position:absolute;top:120px;left:185px\" ><table border=\"1\"><tr><td valign=middle align=center bordercolor=#E8E8FF bgcolor=#FFFFFF><i><font size=6 color=#0000FF><img border=0 src=\"images/carregant_01.gif\"></font></i></td></tr></table></div>';document.write(_d);}</SCRIPT>");
dataWindow.document.write("</HEAD><body bgcolor='#F2F2F2' >");
dataWindow.document.write('<script>initialFunc();document.location.href="http://delta.icc.es/wefex/client?idioma='+nomIdiomaCurt+'&do=cercaDatasetsClient&'+id+'&bbox='+(xn)+','+(yn)+','+(xx)+','+(yx)+'&";</script>');

dataWindow.document.write('</body></HTML>');

}

//14 Setembre 2006 afegir parametre tema
function ogcmap_addLayer(url,srvname,name,title,transparent,visible,format,queryable,version,epsg,mdtitle,organismo,tema) {
  
  //alert("antes: " + this.layers.length);
  
  var fmt = format;
  var nombres = new Array();
  var capas = new Array();
  var visibles = new Array();
  var mdtitulo = new Array();
  var temes = 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 (title.indexOf(';') != -1) {
  	nombres = title.split(";");
  	capas = name.split(";");
  	visibles = visible.split(";");
  	mdtitulo = mdtitle.split(";");
  	temes=tema.split(";");
  	num = nombres.length;
  	for (var i=0; i<num; i++) {
  		if (visibles[i] == "true") {
  			visibles[i] = true;
  		} 
  		else { 
  			visibles[i] = false;
  		}
  	}
  	//se crea el arreglo con las capas de los distintos servidores
  	for (var i=0; i<num; i++) {
  		//alert(mdtitulo[i]);
  		this.servidores[this.servidores.length] = new Array(this.layers.length,capas[i],nombres[i],visibles[i],srvnombre,mdtitulo[i],organismo,temes[i]);
  	}
  	visible = true;
  	this.layers[this.layers.length] = new ogcmap_Layer(url,srvname,capas,nombres,transparent,visible,fmt,queryable,version,epsg); 
  }
  else {
  	//alert("visible" + visible);	
	if(visible=="false"){visible=false;}else if(visible=="true"){visible=true;}
	
  	this.servidores[this.servidores.length] = new Array(this.layers.length,name,title,visible,srvnombre,mdtitle,organismo);
  	visible = true;
  	this.layers[this.layers.length] = new ogcmap_Layer(url,srvname,name,title,transparent,visible,fmt,queryable,version,epsg); 	
  }
  //alert("despues: " + this.layers.length + "  nom: " + srvname);
}

function ogcmap_Layer(url,srvname,name,title,transparent,visible,format,queryable,version,epsg) {
  
  
  this.url = url;
  this.srvname = srvname;
  this.name = name;
  this.title = title;
  this.transparent = transparent;
  this.visible = visible;
  this.format = format;
  this.queryable = queryable;
  //alert(srvname+";"+queryable);
  if(this.version != null) {
    this.version = version;
  }
  else {
    this.version = "1.1.0";
  }
  //14 Nov
 
  if(epsg != null) {
 
    this.epsg = epsg;
  }
  else {
    this.epsg = "EPSG:23031";
  }
 
  this.loaded = false;
}

//============= ogcMap object ==============
//internal method to generate the url for the layer
//in: index of the layer
//out: string, url of image
function ogcmap_layer_url(aLayer,k) {
  var sURL = aLayer.url;
  var llarg=sURL.length;
  var ultim=sURL.substring(llarg-1,llarg);
 
  
  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){
	  				if (nom == "")
		  				nom = this.servidores[i][1];
		  			else
		  				nom = nom + "," + this.servidores[i][1];
	  			}	
	  		}
	}
	    
  	if (nom != "") {	
	  	sURL += "REQUEST=GetMap"; 
	  	
	  	if(sURL.indexOf('roses')!=-1){
		
		}else{
		sURL += "&SRS=" + aLayer.epsg;
		}
		sURL += "&VERSION=" + aLayer.version;
		sURL += "&WIDTH=" + this.mapWidthPX;
		sURL += "&HEIGHT=" + this.mapHeightPX;
		sURL += "&STYLES=";
		if (aLayer.transparent == true)
		    sURL += "&TRANSPARENT=true";
		else
		  sURL += "&TRANSPARENT=false";
		  sURL += "&LAYERS=" + nom;
		  //14 Nov
		  
		  if((aLayer.epsg.indexOf('4326')!=-1)||(aLayer.epsg.indexOf('4230')!=-1)){
  latlon = new Array(2);
  latlonMax= new Array(2);
  UTMXYToLatLon (this.cBounds[0], this.cBounds[1], 31, false, latlon);
        xmin = RadToDeg (latlon[1]);
        ymin = RadToDeg (latlon[0]);
  UTMXYToLatLon (this.cBounds[2], this.cBounds[3], 31, false, latlonMax);    
         xmax = RadToDeg (latlonMax[1]);
        ymax = RadToDeg (latlonMax[0]);
 
   sURL += "&BBOX=" + xmin + "," + ymin + "," + xmax + "," + ymax;
   
		  }else{
		  
		  sURL += "&BBOX=" + this.cBounds[0] + "," + this.cBounds[1] + "," + this.cBounds[2] + "," + this.cBounds[3];
		  }//14 nov estaba comentado pero no se ve el del ING
		  if (!aLayer.transparent){
		    sURL += "&BGCOLOR=" + this.bgColor;
		  }  
		  sURL += "&FORMAT=" + aLayer.format;
		//alert(sURL);
		//document.getElementById('posInfo').innerHTML=sURL;
		  return sURL;
		  
	}
	else { 
		sURL = this.baseDir + "blanco.gif";
		
		return sURL;
	}
}

//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='100%' class='text' border='0' cellpadding='0' cellspacing='0'>";
  // a += "<tr><td class=\"menu\" >Visualització</td></tr>";
  a += "<tr><td><input type='radio' name='car' id='car'  onclick=\"idec_gestioCar3(this.value);\" value='ortofoto'CHECKED >"+strOrto+"</td>";
  a += "<td><input type='radio' name='car' id='car'  onclick=\"idec_gestioCar3(this.value)\"  value='topografic'   >"+strTopo+"</td>";
  
  if(tipusPRobert =="NO"){
  a += "<td><input type='radio' name='car' id='car'  onclick=\"idec_gestioCar3(this.value)\"  value='Relleu'   >"+strRelleu+"</td></tr>";
}
   // 14 Nov
//a += "<tr><td valign='middle' width='100%'><input type='checkbox' name='carrer' id='carrrer' name='carrrer'  onclick=\"idec_estatCarrrer(this.checked)\"  value='carrer' checked><input type='text' id='txtcarrers' class='text'readOnly='true' style='border-style: none; '  value='Desactivar carrerer'></td></tr>";
  // a += "<tr><td width='100%'><input type='checkbox' name='carrer' id='carrrer' name='carrrer'  onclick=\"idec_estatCarrrer(this.checked)\"  value='carrer' checked><input type='text' id='txtcarrers' class='text'readOnly='true' style='border-style: none; '  value='Desactivar carrerer'></td></tr>";
   //a += "<tr><td class=\"menu\" >Ajuntaments  <input type=\"button\" class=\"boto\" Onclick=\"ensenyaAvis()\" value=\"Temes\"></td></tr>";
  a += "</table>";
  document.getElementById('vcp').innerHTML = a;
  z=5;
  }else{
  s+= "<table width='100%' class='text' border='0' cellpadding='1' cellspacing='1'>";
  s += "<tr><td class=\"menu\" >Ajuntaments  <input type=\"boto\" name=\"Submit\" Onclick=\"ensenyaAvis()\" value=\"Temes\"></td></tr>";
  s += "</table>";
  }
  
  for (i=z; i < this.layers.length; i++) {
  //14 Nov
  if(this.layers[i].srvname != ""){
  s += "<table class='text' border=0 cellpadding='2' cellspacing=1><tr>";
  s += "<td width='16'><a id='x" + i + "' href='javascript:cambiar(\"" + i + "\");'>";
  s += "<img src='" + this.baseDir + "skin/" + this.skin + "/images/folder.gif' width='16' height='16' hspace='0' vspace='0' border='0'></a></td>";
  s += "<td>" + this.layers[i].srvname + " </table>";
  }
  
  //s += "<div id='" + i + "' style='display: block; margin-left: 1em;'>";
  s += "<div id='" + i + "' style='display: none; margin-left: 1em;'>";
     
  for (k=0; k< this.servidores.length; k++) {
  		if (this.servidores[k][0] == i) {
  		
   			//this.servidores[k][5]=this.servidores[k][5].replace('\'',' ');
   			s += "<table class='text' border=0 cellpadding='1' cellspacing=1><tr>";
   			//10 jul
   			var nomchk = this.servidores[k][0] + "_" + this.servidores[k][1];
   			//if(tipusAplicacio !="Carrerer"){
   			
   			s += "<td width='12'><img style='cursor:pointer;cursor:hand' onclick='menuPropietats(\"" + nomchk + "\", \"" + this.servidores[k][2] + "\", \"" + this.servidores[k][7] + "\", \"" + 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> <input type='checkbox' id='" + nomchk + "' name='" + nomchk + "'";
      		s += " value='" + this.servidores[k][2] + "'";0
      		//10 NOV agregue el == true al if
      		//alert(this.servidores[k][3]);
      		if (this.servidores[k][3] == true){
      			//alert(this.servidores[k][1] + "  " + this.servidores[k][3]);
  				s += " checked='1'";
  			}
  			s += " onclick='map.toggleLayer(" + k + ");map.redraw(1);'>";
  			s +="<i>"+ this.servidores[k][2]+"</i>"; 
  			s += "</table>";
  		}
  	}
  	
  s += "</div>";
  
  }
  s += "</form>";
  
  //4 Novembre
  
  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='Desactivar carrerer';
}else{
document.getElementById('fooWS').style.display='none';
document.getElementById('efecte').style.visibility='hidden';
document.getElementById('txtcarrers').value='Activar carrerer';
}

}

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;

//map.toggleLayer("0");
//map.toggleLayer("1");
//map.toggleLayer("2");

}

if(capa=="topografic"){
//map.toggleLayer("0");
//map.toggleLayer("1");
	
	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){
//alert("gestioEscala:" + capa);
var ap=map.cBounds[2]-map.cBounds[0];
document.getElementById('divEmpresa').style.display='none';
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;
map.servidores[5][3]=false;
map.layers[5].visible=false;

map.servidores[6][3]=false;
map.layers[6].visible=false;

//alert("ap:" + ap);

if((ap >= 2000) && (ap < 14500)){
//alert("ap1:" + ap);
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){
//alert("ap2:" + ap);
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;
	map.servidores[5][3]=false;
	map.layers[5].visible=false;
	map.servidores[6][3]=false;
	map.layers[6].visible=false;
if((ap >= 1000) && (ap < 20500)){
	
	map.servidores[3][3]=false;
	map.layers[3].visible=false;
	map.servidores[4][3]=true;
	map.layers[4].visible=true;
	map.servidores[5][3]=false;
	map.layers[5].visible=false;
	
	
	}else if (ap < 1000){

	map.servidores[3][3]=false;
	map.layers[3].visible=false;
	map.servidores[4][3]=false;
	map.layers[4].visible=false;
	map.servidores[5][3]=true;
	map.layers[5].visible=true;
	}

}
if(capa=="Relleu"){

	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]=false;
	map.layers[3].visible=false;
	map.servidores[4][3]=false;
	map.layers[4].visible=false;
	map.servidores[5][3]=false;
	map.layers[5].visible=false;
	map.servidores[6][3]=true;
	map.layers[6].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;
	}

}

}

//redraws all the map layers
function ogcmap_redraw(activa) {
  var sURL = "";
//alert("redraw: " + activa);
var ap=(this.cBounds[2]-this.cBounds[0]);


//if(tipusAplicacio=="Carrerer"){idec_gestioCar2(document.getElementById('visual').value)}
if((tipusAplicacio=="Carrerer")&& (activa!=1)){idec_gestioEscala(document.getElementById('visual').value)}

  for (var i=0; i < this.layers.length; i++) {
    img = ogcmap_findImage(this.prefix+i,document);
    //alert(img);
    sURL = this.layer_url(this.layers[i],i);
   
    var img = 0;
    if (document.all) {
      img = document.images[this.prefix+i];
    }
    else {
      img = ogcmap_findImage(this.prefix+i,document);
    }
    this.layers[i].loaded = false;
    //alert(this.layers[i].visible);
    
    
   // idec_gestioCar();
    //escriuValorInfo(idx);
if(activa!=1){img.src=this.baseDir + "blank.gif";}
    
    if (this.layers[i].visible == true) {
    	//alert(sURL + "   " + i);
         img.src = sURL;
    }
    else {
        img.src = this.baseDir + "blank.gif";
    }
    this.setLoaded(i);
  }
  if (activa != 1){
	this.showLoading();
  }
  this.drawPts();
  this.writeLabels();
  //alert(this.calculaEscala());
  idec_connexioWS("getMapaWMS");
  window.status="ideLocal";
  //13Octubre
  if(asdf==1){this.moureSlide();}
}

//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;
    //alert(this.servidores[idx][3]);
  this.servidores[idx][3] = ! this.servidores[idx][3];
  //Capa 5000
   if((tipusAplicacio!="Carrerer")&&(idx==3)){
   if(this.servidores[idx][3]){document.getElementById('fooWS').style.visibility='visible';
   }else{document.getElementById('fooWS').style.visibility='hidden';}
   }
   
   
  if (this.autoRefresh){
    this.redraw(1);
  }
}

//crea la barra con los botones
function ogcmap_writeInline(topM,leftM,topT,leftT,nEines,posBarra,posZoom) {
 codiEmail=codiMun;
 
  //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
  s += "<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=250;var he=250;}else{var we=0;var he=0;}
	s += "<div id=\"posFitxes\" style=\"background-color: #F2F2F2;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;visibility:hidden;width:"+we+"; height:"+he+";overflow:visible; z-index:141; left: 40px; top:40px\">"; 
  	s +="</div>";
  	
  	
  	s += "<div id=\"posTemes\" style=\"background-color: #F2F2F2;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;visibility:hidden;width:"+we+"; height:"+he+";overflow:visible; z-index:141; left: 40px; top:40px\">"; 
  	s +='<div id="Layer1" class="text" style="left:5px;top:5px;font-family: Arial, Helvetica, sans-serif; font-size: 9px; font-style: normal; position:absolute; width:240px; height:240px; z-index:1; overflow:auto;">   <table width="100%" border="0" cellspacing="2" cellpadding="2"><tr><td class="menu" height="30" colspan="2">Temes</td></tr><tr><td class="text" width="66%">Parcelari</td>';
	s +='<td class="text" width="34%"><input type="checkbox" name="checkbox" onClick="activaCapesTemes(this.value,this.checked)" value="Parcelari"></td></tr><tr><td class="text">Planejament</td><td class="text"><input type="checkbox" name="checkbox2" onClick="activaCapesTemes(this.value,this.checked)" value="Planejament"></td></tr><tr><td class="text">Base</td><td>';
		s +='<input type="checkbox" name="checkbox3" onClick="activaCapesTemes(this.value,this.checked)" value="Base"></td></tr><tr><td class="text">Serveis</td><td><input type="checkbox" name="checkbox4" onClick="activaCapesTemes(this.value,this.checked)" value="Serveis"></td></tr><tr> <td colspan="2"><hr></td></tr><tr align="right"><td colspan="2">';
		s +='<input type="button" class="boto" name="Submit" Onclick="tancaAvis()" value="Tancar"></td></tr></table></div>';
  	
  	
  	s +="</div>";
  	
  	
  	s += "<div id=\"posFitxes2\" style=\"display:none;background-color: #FFFFFF;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;visibility:hidden;width:"+we+"; height:"+he+";overflow:hidden; z-index:142; left: 40px; top:40px; filter:alpha(opacity=85);-moz-opacity:0.85;\">"; 
  	s +="</div>";
  	
  	
  	s += "<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";
  		s += "<div id=\""+gid+"_loadDiv\" style=\" filter:alpha(opacity=70);-moz-opacity:0.7;background-color: #FFFFFF;z-index:500;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";
  		s +="</div>";
  		//DIV CONTAINER
  		s += "<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++) {
  				s += sdiv + "<img style=\"filter:alpha(opacity=100);-moz-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";
  				s +="</div>";
  			}
  			s += sdiv + "<img style=\"visibility:hidden;filter:alpha(opacity=100);-moz-opacity:1;\" id=\"fooWS\"  name=\"fooWS\" OnError=\"idec_retoca(this.id)\" src=\"" + this.baseDir + "blank.gif\" " + swh + "></img>\n";
  			s +="</div>";
  			s += sdiv + "<img style=\"visibility:hidden;filter:alpha(opacity=100);-moz-opacity:1;\" id=\"fooWSXY\"  name=\"fooWSXY\" OnError=\"idec_retoca(this.id)\"  src=\"" + this.baseDir + "blank.gif\" " + swh + "></img>\n";
  			s +="</div>";
 			s +="<div id =\"mapa\" style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px; margin:0; padding:0; position:absolute;\">";
 			s +="</div>";
  			s += 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";
  				s +="</div>";
  			s +="</div>";
  			s += 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";
  				s +="</div>";
  			s +="</div>";
  			s += 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";
  				s +="</div>";
  			s +="</div>";
  		//Zoom BOX
  			s += "<div id=\""+gid+"_zoomBox\" style=\"position:absolute;visibility:hidden;zIndex:100;border:1px solid red;width:0px;height:0px;\">";
  			s +="</div>";
  			s += "<div id=\"efecte\" style=\"position:absolute;visibility:hidden;zIndex:100;border:0px solid red;width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px\">";
  			s +="</div>";
			
			//23 feb
			s += "<div id=\"puntInci\" style=\"z-index:1000;padding:1px;border:1px none black;position:absolute;top:0px;left:0px;width:5px;height:5px;display:none;\"><img  src=\"images/pointx.gif\"></img></div>";
			//23 feb

  		s +="</div>\n";
  		//FIN DIV CONTAINER
  	s +="</div>\n";	
    s += "<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=\"cursor:crosshair;border:1px black solid;background-image: url(" + this.baseDir + "blank.gif);position:absolute;width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px;z-index:100 \">";
    s +="</div>\n";
  s +="</div>\n";
  
	 s +="<div id=\"divEmpresa\" class=\"mapa\" style=\"width:" + this.mapWidthPX + "px; height:" + this.mapHeightPX + "px;z-index:4 \"></div>\n";

  if(posZoom=="H"){
   //alert("H");
  	s += "<div id=\"barraSlide\" class=\"Hbarrazoom\" style=\"display:none;padding-top: 4px;overflow:hidden;position:absolute;z-index:0;border: 1px none #000000\">"; 
  		s += "<IMG  alt=\"\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/barraH.gif\" width=\"130\" name=\"trackH\">"; 
  		s += "<IMG  alt=\"\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/barra_botoH.gif\" width=\"10\" height=\"20\" name=\"thumbH\">"; 
  	s += "</div>";
  	
  }else{
  	
  	s += "<div id=\"barraSlide\" class=\"barrazoom\" style=\"display:none;padding-left: 4px;padding-top: 2px;overflow:hidden;position:absolute;z-index:0;border: 1px none #000000\">"; 
  		s += "<IMG  alt=\"\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/barra.gif\" width=\"20\" height=\"134\" name=\"track\">"; 
  		s += "<IMG  alt=\"\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/barra_boto.gif\" width=\"20\" height=\"10\" name=\"thumb\">"; 
 	s += "</div>";
  }
    
  s += "<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>";
  s += "<input type=\"hidden\" name=\"inciX\" id=\"inciX\" value=0><input type=\"hidden\" name=\"inciY\" id=\"inciY\" value=0>";
  
  
  s +="<div id=\"bBotondiv\" class=\"barrabotones\" OnMouseOver=\"this.quering=false;document.getElementById('divEmpresa').style.display='none';document.getElementById('divEmpresa').innerHTML='';\" style=\"z-index:250;position:absolute;\">";
  	s += "<table width=\"16px\" border=\"1\">\n";
  		s += "<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) {
    				s += tagPos +"<td class=\"normal\" id=\""+ this.gid + "_toolcell_" + this.tools[i].opcode + "\"><a href=\"javascript:g_ogcMaps["+gid+"]." + this.tools[i].targetFunction + "\"><img title=\"" + this.tools[i].description  + "\"  border=\"0\" id=\"" + this.tools[i].name + "\" name=\"" + this.tools[i].name + "\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/" + this.tools[i].name + ".gif\"></img></a></td>\n";
      			}
    		}
  		}
  		s += "</tr>";
  	s += "</table>\n";
  s +="</div>\n";
  
  //23 feb mail
	var topInci = topM+this.mapHeightPX+3;
	var leftInci = (leftM+this.mapWidthPX)-60;
	//s +="<div id=\""+ this.gid + "_toolcell_" + this.tools[i].opcode + "\" class=\"normal\" style=\"position:absolute;top:" + topM+this.mapHeightPX + "px;left:" + leftM+this.mapWidthPX +"px;width:20px;height:20px\">";  
	
	if(email!="NO"){ver_email="block";}else{ver_email="none";}
	if(tipusAplicacio=="Visual"){ver_email="none";}
	s +="<div id=\""+ this.gid + "_toolcell_" + this.tools[i].opcode + "\" class=\"normal\" style=\"align:center;display:"+ver_email+";position:absolute;top:" + topInci + "px;left:" + leftInci + "px;width:56px;height:19px\">";
  
  s+="<a href=\"javascript:g_ogcMaps["+gid+"]." + this.tools[i].targetFunction + "\"><img title=\"" + this.tools[i].description  + "\" onmouseover=\"escriuValorInfo(avisCarrerer); \";\" onmouseout=\"escriuValorInfo('')\" border=\"0\" id=\"" + this.tools[i].name + "\" name=\"" + this.tools[i].name + "\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/" + this.tools[i].name + ".gif\"></img></a>";
  s +="</div>\n";
  //23 feb fin
    				
  	
  var wMenu=200;
  var tf=0;
  if(tipusAplicacio=="Carrerer"){
  if(codiMun.length < 3){tf=20;}
    topCerca=parseInt(topM+230+tf);
    factor=0;
    ampla=315;
    topCerca1=parseInt(topM+80+tf);
    mS=120;
    s +="<div id=\"EinesCerca\" style=\"display:none;position:absolute;z-index:0;width:"+wMenu+"px; left:"+(leftM + this.mapHeightPX + 10)+"px; top: "+ (topM) +"px;  border: 1px none #0000FF\">";
 // s +=idec_escriuCerques(tipusAplicacio,leftM);
  s+="</div>";
   if(tipusPRobert!=0){var vert='block';}else{var vert='none'}
  
  s += "<div id='vcp' style='display:"+vert+";border: 1px none #0000FF;position:absolute;width:300px;height:15px;top:" + (this.mapHeightPX + 10)+ "px; left:" + (leftM ) + "px;'></div>";
  
   }else{
  	topCerca=parseInt(topM);
   	factor=135;
   	ampla=330;
   	mS=215
  }
  if(tipusAplicacio=="Carrerer"){
  	s += "<div id=\"leyendadiv\" class=\"Cleyenda\" style='display:none;border: 1px none #0000FF;position:absolute;width:"+wMenu+"px;height:"+parseInt(ampla-tf)+"px;overflow:auto;' onmouseover=\"document.getElementById('propietats').style.visibility='hidden';setTimeout('tancaDivL()',2000);\">";
  }else{
  	s += "<div id=\"leyendadiv\" class=\"leyenda\" style='display:none;border: 1px none #0000FF;position:absolute;width:"+wMenu+"px;height:"+parseInt(ampla-tf)+"px;overflow:auto;' onmouseover=\"document.getElementById('propietats').style.visibility='hidden';setTimeout('tancaDivL()',2000);\">";
  }
  s +="</div>\n";
  s += "<div id=\"propietats\" style='display:none;position:absolute; visibility:hidden; top:0px; left: 0px' onmouseover=\"document.getElementById('divTra').style.visibility='hidden';\">";
  s +="</div>\n";
  s += "<div id=\"divTra\" style='display:none;position:absolute; visibility:hidden; top:0px; left:0px;width:110'>";
  	//s += "<IMG alt=\"\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/handle.gif\" width=\"10\" height=\"25\" id=\"trahand\" name=\"trahand\">";
 	//s += "<IMG alt=\"\" src=\"" + this.baseDir + "skin/" + this.skin + "/images/gifhorizontal.gif\" width=\"105\" height=\"15\" aling='left' id=\"lineatra\" name=\"lineatra\">";
  s += "</div>";
  s += "<div id=\"posInfo\" class=\"info\"  style=\"display:none;width:400px;left:"+parseInt(leftM)+"px;top:"+parseInt(topM + this.mapHeightPX)+";position:absolute \">";
  	//s += "<table border='0'><tr><td><div  ></div></td></tr></table>";
  s +="</div>\n";
 s +="<div id=\"mapaSituacio\" class=\"minimapa\" style=\"display:none;position:absolute;z-index:0;width:150px;height:150px;overflow:hidden;border: 1px outset #0000FF\">";
  	s+="<div id=\"mapRef\" style=\"display:none;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\">";
  	s +="</div>\n";
  s+="</div>";
  
  
  document.write(s);
  this.postWrite();
}


//muestra la barra para seleccionar la transparencia
function transparencia (capa,e){
	//10 jul
	var num = capa.indexOf("_");
  	var ncap = capa.substring(0,num);
  	var ncap = parseInt(ncap);
	//10 jul fin  
	//alert(ncap);
	var pro=document.getElementById('divTra');
	pro.above;
	capa = map.prefix + ncap;	
	pro.style.visibility='visible';
	if (document.all){
		x = e.clientX - 40;
		y = e.clientY - 10;
		transpa = document.getElementById(capa).filters.alpha.opacity;
		transpa = 100 - transpa;
	}else{
		x = e.pageX - 40;
		y = e.pageY;
		transpa = document.getElementById(capa).style.MozOpacity;
		transpa = 100 * transpa;
		transpa = 100 - transpa;
	}
	//var bro=document.getElementById('lineatra');
	dd.elements.lineatra.moveTo(x,y);
	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){
	//alert(capaTR);
	if (valorDIV > 100){
		valorDIV=100;
	}

	transp = valorDIV;
	
	var num = capaTR.indexOf("_");
  	var ncap = capaTR.substring(0,num);
  	var ncap = parseInt(ncap);
	
	//alert(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.MozOpacity=valorT;
		}
}

//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;
	//alert("AMPLA " + ampla);
	var rango = amplaIni / 10;
	//alert (rango);
	//alert("2: " + this.cBounds[2] + " ,0: " + this.cBounds[0]);
	if (ampla < 1){ampla=2;}
	if((ampla >= 1)&&(ampla < rango)){mouY=(100) }
	if((ampla >= rango)&&(ampla < (rango*2))){mouY=(90)}
	if((ampla >= (rango*2))&&(ampla < (rango*3))){mouY=(80)}
	if((ampla >= (rango*3))&&(ampla < (rango*4))){mouY=(70)}
	if((ampla >= (rango*4))&&(ampla < (rango*5))){mouY=(60) }
	if((ampla >= (rango*5))&&(ampla < (rango*6))){mouY=(50)}
	if((ampla >= (rango*6))&&(ampla < (rango*7))){mouY=(40)}
	if((ampla >= (rango*7))&&(ampla < (rango*8))){mouY=(30)}
	if((ampla >= (rango*8))&&(ampla < (rango*9))){mouY=(20)}
	if((ampla >= (rango*9))&&(ampla < (rango*10))){mouY=(10)}
	if(ampla >= (rango*10)){mouY=(0) }
	
	//alert("ampla:"+ampla);
	//alert(mouY);
	moureBarra(mouY);

}
//27 Octubre
function idec_activaGetMapaPunt(cX,cY,adreca,zFactor1){

document.getElementById('posFitxes').style.visibility='hidden';
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);
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);
}

function idec_canviaImatge(url,nom){

//alert(nom);
//alert(url);

document.getElementById('posFitxes').style.visibility='hidden';
document.getElementById(nom).src=url;
//alert(document.images[nom].src);

}
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){

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";
if(tipusAplicacio=="Carrerer"){capaCarrer.style.visibility="visible";}
//20Gener
/*
if(document.getElementById('fooWSXY').style.visibility=="visible"){

	var cX=document.getElementById('cX').value;
	var cY=document.getElementById('cY').value;
	var adreca=document.getElementById('adreca').value;

	//if((cX > xmin)&&(cX < xmax)){ 
	idec_ajax2("getGeoWS.jsp?peticio=getMapaPuntXY&xmin="+xmin+"&ymin="+ymin+"&xmax="+xmax+"&ymax="+ymax+"&width="+mapaW+"&height="+mapaH+"&cx="+cX+"&cy="+cY+"&adreca="+adreca+"&");
	
	//}else{document.getElementById('fooWSXY').style.visibility="hidden";}

	} */
//
 
if(metode=="getMapaWMS"){
if ((ampli < 1500)&&(capaCarrer.style.visibility=="visible")){

	//document.getElementById('fooWS').style.visibility="visible";
	//ajax("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.visibility='hidden';



}
function idec_cercaCarrer(){

	var tipusCarrer=document.getElementById('tipusCarrer').value;
	var nomCarrer=document.getElementById('nomCarrer').value;
	var numCarrer=document.getElementById('numCarrer').value;
	if(codiMun=="181609"){codiMun="171609";}
	
	nomCarrer=canviValor(nomCarrer);
	 	
	ajax("getGeoWS.jsp?peticio=getAdrecaUTM&tipusCarrer="+tipusCarrer+"&nomCarrer="+nomCarrer+"&numCarrer="+numCarrer+"&zFactor="+zFactor+"&codiMun="+codiMun+"&");

}

//14 Octubre
function ogcmap_rebre(minX,minY,maxX,maxY,valor){
/*
if(valor=="inici"){
map.zoomFinestra(minX,minY,maxX,maxY);
coordInici[0]=minX;
coordInici[1]=minY;
coordInici[2]=maxX;
coordInici[3]=maxY;
idec_escriuMapa(minX,minY,maxX,maxY);

	map.mapBounds[0]=minX;
	map.mapBounds[1]=minY;
	map.mapBounds[2]=maxX;
	map.mapBounds[3]=maxY;

}else{
*/
document.getElementById('posFitxes').style.visibility='hidden';
map.zoomFinestra(minX,minY,maxX,maxY);
escriuValorInfo(valor);
//}

// 3 NOVIEMBRE
	map.moureSlide();
}
//Funcions iniciatiques


function idec_iniciMapa(codi){
init_ajax("infoCoord.jsp?valor="+codi+"&");
}

var iniciMap = makeObject();
var tt=1;
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 = coordInici[2] - coordInici[0];
  //var dy = coordInici[3] - coordInici[1];

  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);

}

function idec_llegenda(w,h,ll,text){

if(ll==1){ll='cobertes.gif';text='Cobertes_del_sòl_1993'}
if(ll==2){ll='cultius.gif';text='Cultius_i_aprofitaments_1977_1979'}
	
	w=window.open("", "Llegenda", 'scrollbars,width='+w+',height='+h+',left=150,top=150');
	w.document.write("<html><title>Llegenda</title><table border=0><tr><td  align=center><b>"+text+"</b></td></tr><tr>"+
	"<td align=center><img border=0 src=visual/images/llegenda/"+ll+"></td></tr></table></html>");

	w.document.close();	
	
}

//23 feb
function modifica(pos,caso){
	var top;
	var left;
	var w = 500;
	var h = 500;
	var dm = DELTAMAP;
	var topM = parseInt(pos[0]) + w;
	var leftM = parseInt(pos[1]) + h;
	for (var i = 2; i < pos.length; i++){
		top = parseInt(pos[i]);
		if (top > topM){
			if (caso == 1){
				topt = top + dm;
			}else{
				topt = top - dm;
			}
			pos[i] = topt + "px";
		}
		i++;
		left = parseInt(pos[i]);
		if (left > leftM){
			if (caso == 1){
				leftt = left + dm;
			}else{
				leftt = left - dm;
			}
			pos[i] = leftt + "px";
		}
	}
	return pos;
}

function modificaPos(pos){
	if (document.all){
		//IE
		document.styleSheets[0].rules[27].style.top = pos[0];
		document.styleSheets[0].rules[27].style.left = pos[1];
		document.styleSheets[0].rules[28].style.top = pos[2];
		document.styleSheets[0].rules[28].style.left = pos[3];
		document.styleSheets[0].rules[29].style.top = pos[4];
		document.styleSheets[0].rules[29].style.left = pos[5];
		document.styleSheets[0].rules[30].style.top = pos[6];
		document.styleSheets[0].rules[30].style.left = pos[7];
		document.styleSheets[0].rules[31].style.top = pos[8];
		document.styleSheets[0].rules[31].style.left = pos[9];
		document.styleSheets[0].rules[32].style.top = pos[10];
		document.styleSheets[0].rules[32].style.left = pos[11];
		document.styleSheets[0].rules[33].style.top = pos[12];
		document.styleSheets[0].rules[33].style.left = pos[13];
		document.styleSheets[0].rules[34].style.top = pos[14];
		document.styleSheets[0].rules[34].style.left = pos[15];
		document.styleSheets[0].rules[35].style.top = pos[16];
		document.styleSheets[0].rules[35].style.left = pos[17];
		document.styleSheets[0].rules[36].style.top = pos[18];
		document.styleSheets[0].rules[36].style.left = pos[19];
	}else{
		document.styleSheets[0].cssRules[27].style.top = pos[0];
		document.styleSheets[0].cssRules[27].style.left = pos[1];
		document.styleSheets[0].cssRules[28].style.top = pos[2];
		document.styleSheets[0].cssRules[28].style.left = pos[3];
		document.styleSheets[0].cssRules[29].style.top = pos[4];
		document.styleSheets[0].cssRules[29].style.left = pos[5];
		document.styleSheets[0].cssRules[30].style.top = pos[6];
		document.styleSheets[0].cssRules[30].style.left = pos[7];
		document.styleSheets[0].cssRules[31].style.top = pos[8];
		document.styleSheets[0].cssRules[31].style.left = pos[9];
		document.styleSheets[0].cssRules[32].style.top = pos[10];
		document.styleSheets[0].cssRules[32].style.left = pos[11];
		document.styleSheets[0].cssRules[33].style.top = pos[12];
		document.styleSheets[0].cssRules[33].style.left = pos[13];
		document.styleSheets[0].cssRules[34].style.top = pos[14];
		document.styleSheets[0].cssRules[34].style.left = pos[15];
		document.styleSheets[0].cssRules[35].style.top = pos[16];
		document.styleSheets[0].cssRules[35].style.left = pos[17];
		document.styleSheets[0].cssRules[36].style.top = pos[18];
		document.styleSheets[0].cssRules[36].style.left = pos[19];
	}
}

function agranda(){
	var pos = posIni();
	var npos = modifica(pos,1);
	modificaPos(npos);
	//alert("agranda");
}

function disminuye(){
	var pos = posIni();
	var npos = modifica(pos,2);
	modificaPos(npos);
}

function posIni(){
	//alert("agranda");
	if (document.all){
		//IE
		var mapaT = document.styleSheets[0].rules[27].style.top;
		var mapaL = document.styleSheets[0].rules[27].style.left;
		var leyendT = document.styleSheets[0].rules[28].style.top;
		var leyendL = document.styleSheets[0].rules[28].style.left;
		var CleyendT = document.styleSheets[0].rules[29].style.top;
		var CleyendL = document.styleSheets[0].rules[29].style.left;
		var vcpT = document.styleSheets[0].rules[30].style.top;
		var vcpL = document.styleSheets[0].rules[30].style.left;
		var einesT = document.styleSheets[0].rules[31].style.top;
		var einesL = document.styleSheets[0].rules[31].style.left;
		var minmapaT = document.styleSheets[0].rules[32].style.top;
		var minmapaL = document.styleSheets[0].rules[32].style.left;
		var barBT = document.styleSheets[0].rules[33].style.top;
		var barBL = document.styleSheets[0].rules[33].style.left;
		var barZT = document.styleSheets[0].rules[34].style.top;
		var barZL = document.styleSheets[0].rules[34].style.left;
		var barZTH = document.styleSheets[0].rules[35].style.top;
		var barZLH = document.styleSheets[0].rules[35].style.left;
		var barZTV = document.styleSheets[0].rules[36].style.top;
		var barZLV = document.styleSheets[0].rules[36].style.left;
	}else{
		var mapaT = document.styleSheets[0].cssRules[27].style.top;
		var mapaL = document.styleSheets[0].cssRules[27].style.left;
		var leyendT = document.styleSheets[0].cssRules[28].style.top;
		var leyendL = document.styleSheets[0].cssRules[28].style.left;
		var CleyendT = document.styleSheets[0].cssRules[29].style.top;
		var CleyendL = document.styleSheets[0].cssRules[29].style.left;
		var vcpT = document.styleSheets[0].cssRules[30].style.top;
		var vcpL = document.styleSheets[0].cssRules[30].style.left;
		var einesT = document.styleSheets[0].cssRules[31].style.top;
		var einesL = document.styleSheets[0].cssRules[31].style.left;
		var minmapaT = document.styleSheets[0].cssRules[32].style.top;
		var minmapaL = document.styleSheets[0].cssRules[32].style.left;
		var barBT = document.styleSheets[0].cssRules[33].style.top;
		var barBL = document.styleSheets[0].cssRules[33].style.left;
		var barZT = document.styleSheets[0].cssRules[34].style.top;
		var barZL = document.styleSheets[0].cssRules[34].style.left;
		var barZTH = document.styleSheets[0].cssRules[35].style.top;
		var barZLH = document.styleSheets[0].cssRules[35].style.left;
		var barZTV = document.styleSheets[0].cssRules[36].style.top;
		var barZLV = document.styleSheets[0].cssRules[36].style.left;
	}
	var pos = new Array();
	pos[0] = mapaT;
	pos[1] = mapaL;
	pos[2] = leyendT;
	pos[3] = leyendL;
	pos[4] = CleyendT;
	pos[5] = CleyendL;
	pos[6] = vcpT;
	pos[7] = vcpL;
	pos[8] = einesT;
	pos[9] = einesL;
	pos[10] = minmapaT;
	pos[11] = minmapaL;
	pos[12] = barBT;
	pos[13] = barBL;
	pos[14] = barZT;
	pos[15] = barZL;
	pos[16] = barZTH;
	pos[17] = barZLH;
	pos[18] = barZTV;
	pos[19] = barZLV;
	return pos; 
}

function ogcmap_resize(){
	var val = "";
	var nombre = map.tools[10].name;
	var img = document.getElementById(nombre);
	var ruta = img.src;
	var rutaimg = ruta.substring(0,(ruta.length-5));
	var archivo = ruta.substring((ruta.length-5),(ruta.length-4));
	var extimg = ruta.substring((ruta.length-4),ruta.length);
	if (archivo == "1"){
		val = "500px";
		ruta = rutaimg + extimg;
		img.src = ruta;
		disminuye();
		this.redibuja(val);
		if (document.all){
			var y = document.styleSheets[0].rules[34].style.top;
			var x = document.styleSheets[0].rules[34].style.left;
		}else{
			var y = document.styleSheets[0].cssRules[34].style.top;
			var x = document.styleSheets[0].cssRules[34].style.left;
		}
		resizeBZ(x,y);
	}else{
		val = "650px";
		ruta = rutaimg + "e1" + extimg;
		img.src = ruta;
		agranda();
		this.redibuja(val);
		if (document.all){
			var y = document.styleSheets[0].rules[34].style.top;
			var x = document.styleSheets[0].rules[34].style.left;
		}else{
			var y = document.styleSheets[0].cssRules[34].style.top;
			var x = document.styleSheets[0].cssRules[34].style.left;
		}
		resizeBZ(x,y);
	}
	map.redraw(1);
}

function ogcmap_redibuja(val){
	var nlayers = this.layers.length;
	var w = parseInt(val);
  	for (var i=0; i < nlayers; i++) {
  	    var nom = this.prefix+i;
  	    document.getElementById(nom).style.width = val;
  		document.getElementById(nom).style.height = val;
  	}
  	map.mapWidthPX = w;
  	map.mapHeightPX = w;
  	document.getElementById('cont_principal').style.width = val;
  	document.getElementById('cont_principal').style.height = val;
  	document.getElementById('cont_principal').style.clip = "rect(0,"+this.mapWidthPX + "px," + this.mapHeightPX + "px,0)";
  	document.getElementById('cont_general').style.width = val;
  	document.getElementById('cont_general').style.height = val;
  	document.getElementById('posFitxes').style.width = val;
  	document.getElementById('posFitxes').style.height = val;
  	document.getElementById('posFitxes2').style.width = val;
  	document.getElementById('posFitxes2').style.height = val;
  	document.getElementById('efecte').style.width = val;
  	document.getElementById('efecte').style.height = val;
  	document.getElementById('mapa').style.width = val;
  	document.getElementById('mapa').style.height = val;
  	var cont =  this.gid + "_container";
  	document.getElementById(cont).style.width = val;
  	document.getElementById(cont).style.height = val;
  	cont = this.gid + "_loadDiv";
  	document.getElementById(cont).style.width = val;
  	document.getElementById(cont).style.height = val;
  	cont = this.gid + "mapCanvas";
  	document.getElementById(cont).style.width = val;
  	document.getElementById(cont).style.height = val;
  	cont = this.gid + "_labelsDiv";
  	document.getElementById(cont).style.width = val;
  	document.getElementById(cont).style.height = val;
  	cont = this.gid + "_selectionDiv";
  	document.getElementById(cont).style.width = val;
  	document.getElementById(cont).style.height = val;
  	cont = this.gid + "_zoomBox";
  	document.getElementById(cont).style.width = val;
  	document.getElementById(cont).style.height = val;
  	cont = this.gid + "_glassPane";
  	document.getElementById(cont).style.width = val;
  	document.getElementById(cont).style.height = val;
  	//modificar la posicion de posInfo
  	if (document.all){
  		var mapT = document.styleSheets[0].rules[27].style.top;
  	}else{
  		var mapT = document.styleSheets[0].cssRules[27].style.top;
  	}
  	var top = parseInt(mapT);
  	var pos = top + w;
  	pos = pos + "px";
  	document.getElementById('posInfo').style.top = pos;
  	var bmail = this.gid + "_toolcell_" + (this.tools.length-1);
  	document.getElementById(bmail).style.top = pos;
  	if (val == "500px"){
		var dm = DELTAMAP;
		var leftI = parseInt(document.getElementById(bmail).style.left);
		leftI = leftI - dm;
		document.getElementById(bmail).style.left = leftI + "px";  
	}else{
		var dm = DELTAMAP;
		var leftI = parseInt(document.getElementById(bmail).style.left);
		leftI = leftI + dm;
		document.getElementById(bmail).style.left = leftI + "px";
	}
}

function ogcmap_mailing(x,y){
	if (email == "NO"){
		alert("no se ha configuado el contacto para las incidencias");
	}else{
		if (tipusAplicacio=="Visual"){
			var tipus = "v";
		}else {
			var tipus = "c";
		}
		var str = "";
		str = "<IFRAME id=\"correu\" name=\"correu\" frameborder=\"0\" height=\"340px\" width=\"310px\" src=\"email.jsp?muni="+titInici+"&x=" + x +"&y=" + y + "&contacto=" + contacto + "&email=" + email + "&servlet=" + servlet + "&codi=" + codiEmail + "&tipus=" + tipus + "&appInt=" + appIntern + "\">";
		str += "</IFRAME>";
		escribeForm(str,x,y);
	}
}

function escribeForm(str,x,y){
	//idec_activaGetMapaPunt(x,y,"",200);
	document.getElementById('posFitxes2').innerHTML="";
	document.getElementById('posFitxes2').style.height = "340px";
	document.getElementById('posFitxes2').style.width = "310px";
	document.getElementById('posFitxes2').style.visibility='visible';
	document.getElementById('posFitxes2').innerHTML=str;
}

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-5) + "px";
	document.getElementById('puntInci').style.left= (x-4) + "px";
	document.getElementById('puntInci').style.visibility='visible';
}
//23 feb fin

//18 abr
function idec_activaMapaPunt(cX,cY,adreca){
	//alert("activaMapaPunt");
	document.getElementById('posFitxes').style.visibility='hidden';
	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);
}
//18 abr fin
//]]>

