
/**
*	@private
*/
NMap.prototype.wfsObjectClick = function(layerTarget,identifier) {
	
//	if (this.getCurrentTool()=="NOEVENTS") {
		//alert ('>> :poiClick: ' + identifier);
		var poiCodes = this.mapLayer[layerTarget].layersList;
		WFSProxy.getPoiInfo(poiCodes,this.extent.getMinX(),this.extent.getMinY(),this.extent.getMaxX(),this.extent.getMaxY(),this.width,this.height, identifier,1,map.wfsObjectClick_response);
//	}
	return false;
}

/**
*	@private
*/
NMap.prototype.wfsObjectClick_response = function(data) {
	//alert ('>> wfsObjectClick_response\n' + data);
	try {
		this.myWindow.close();
	}
	catch (e) {}
	this.myWindow = window.open("", "tinyWindow", 'width=500,height=300');
	this.myWindow.document.write(data[0]);
	this.myWindow.document.close();
	if (window.focus) {this.myWindow.focus()};
	return false;
}

/**
*	@private
*/
NMap.prototype.wfsObjectMouseOver = function(imgObj,layerTarget,identifier) {
	try {
	
		var btc=document.getElementById("btc");
	//	var btc1=document.getElementById("btc1");
	//	var btc2=document.getElementById("btc2");

		if (btc==null) {
			//estem a imprimir
			return false;
		}

		btc.style.top=parseFloat(imgObj.style.top)+this.mapPixelsY+15+"px";
		btc.style.left=parseFloat(imgObj.style.left)+this.mapPixelsX-20+"px";

		
		var poiCodes = this.mapLayer[layerTarget].layersList;
		WFSProxy.getPoiInfo(poiCodes,this.extent.getMinX(),this.extent.getMinY(),this.extent.getMaxX(),this.extent.getMaxY(),this.width,this.height, identifier,2,map.wfsObjectMouseOver_response)
		return false;
		
	}
	catch (e) {
		alert("Error a wfsObjectMouseOver()\n"+e.message);
	}
}

/**
*	@private
*/
NMap.prototype.wfsTooltipVisibility = function() {
	
	var btc=document.getElementById("btc");
	btc.style.visibility="hidden";
	
}

/**
*	@private
*/
NMap.prototype.wfsObjectMouseOver_response = function(data) {

	//alert ('>> wfsObjectOver_response\n' + data);
	try {
		var btc=document.getElementById("btc");
		var btc1=document.getElementById("btc1");
		var btc2=document.getElementById("btc2");
		var btc3=document.getElementById("btc3");
		btc.style.visibility="visible";
		var id=data[0];
		var nom=data[1];
		var url=data[2];

		btc1.firstChild.nodeValue=nom;
		btc3.onclick=function() {
			map.wfsObjectClick(1,id);
		}
		try {
			if (url.length>30) url=url.substr(0,27)+"...";
		}catch (e) {
			url="";
		}
		btc2.firstChild.nodeValue=url;
	}
	catch (e) {
		alert("Error a NMap.wfsObjectMouseOver_response()\n"+e.message);
	}
}

/**
*	@private
*/
NMap.prototype.wfsObjectMouseOut = function(layerTarget,identifier) {
	
	return false;
}

/**
*	@private
*/
NMap.prototype.sendWFSRequest_response = function (layerTarget, data) {
	try {	
		//alert("sendWFSRequest_response "+layerTarget + "  " +data.length);

		this.resetPosition();
		
		var len=data.length;
		var strArray=new Array();
		for (var i=0; i<len; i++) {
			var pixels = new NPoint(data[i][1],data[i][2]); // x, y
			//DebugOut(data[i][1]+" "+data[i][2],INFO);
			var poi=new NPoi(pixels,data[i][3],data[i][0]);	// coord, styleId, identifier
			strArray.push("<img onMouseOver='"+this.mapInstanceName+".wfsObjectMouseOver(this,"+layerTarget+",\""+poi.identifier+"\");' onMouseOut='"+this.mapInstanceName+".wfsObjectMouseOut("+layerTarget+",\""+poi.identifier+"\");' src='"+poi.getImagePath()+"' alt='' title='"+poi.getTitle()+"' style='position:absolute; left:"+pixels.getX()+"px; top:"+pixels.getY()+"px;' />");// onMouseUp='javascript: map.wfsObjectClick("+layerTarget+",\""+poi.identifier+"\");'
			this.mapLayer[layerTarget].poisList.add(poi);

		}
		// bug ie: si no hi ha width i height no es veu res: queda div a 0x0
		this.mapLayer[layerTarget].targetDiv.style.width=this.width+"px";
		this.mapLayer[layerTarget].targetDiv.style.height=this.height+"px";

		this.mapLayer[layerTarget].targetDiv.innerHTML=strArray.join("");
		
		this.afterQueryReceived(layerTarget);
		this.hideLoading();
		DebugOut("("+this.mapInstanceName+") sendWFSRequest_response.eventAfterOneLayerLoaded()",INFO);
		this.eventAfterOneLayerLoaded();

		try {
			document.getElementById("numPois").innerHTML=data.length;
		} catch(e) {}
		
	}
	catch (e) {
		alert("Error a NMap.sendWFSRequest_response()\n"+e.message);
	}
}

/**
*	Envia una petició WFS
*	@param {Integer} layerTarget el numero de layer de la petició.
*	@param {String} layers llista separada per comes dels layers del wfs a demanar
*	@param {Integer} width amplada de la imatge
*	@param {Integer} height alçada de la imatge
*	@param {NExtent} extent extensió de la petició.
*/
NMap.prototype.sendWFSRequest = function (layerTarget, layers, width, height, extent) {
	try {
		dateStamp=new Date();

		var wfsUrl=map.getLayerByPos(layerTarget).getServerUrl();
		
		var retFunc=function(data) {
			map.sendWFSRequest_response(layerTarget,data);
		}
		this.showLoading();
		WFSProxy.getPois(wfsUrl+this.getLayerByPos(layerTarget).getParameters(),layers,extent.getMinX(),extent.getMinY(),extent.getMaxX(),extent.getMaxY(),width,height,retFunc);

	} catch (e) {
		alert("Error a NMap.sendWFSRequest()\n"+e.message);
	}
}

/** 
*	Envia una petició WMS per una de les capes del mapa definida amb el parametre targetLayer.
*	Fa una precarrega de la imatge amb un objecte Image de JS i quan ha rebut la resposta substitueix la imatge del layer.
*
*	@param {String} requestUrl la url de la petició wms, excepte la part del servidor + servei.
*	@param {Integer} targetLayer número del layer al que s'ha d'acabar posant la imatge retorna pel servidor wms.
*	@private
*/
NMap.prototype.sendWMSRequest = function(requestUrl,targetLayer,retryNum) {
	try {
		if (typeof(retryNum)=="undefined") retryNum=0;

		var layer=this.getLayerByPos(targetLayer);
		var url = layer.getServerUrl()+layer.getParameters()+"&"+requestUrl;

		//alert ('>> :' +targetLayer + "   "+ url);
		// quan hi hagi l'indicador fem peticio amb timestamp per passar caches
		if (this.getUseTimeStamp()) {
			var d=new Date();
			url+="&timestamp="+d.getHours()+""+d.getMinutes()+""+d.getSeconds()+""+d.getMilliseconds();
		}

		if (this.mapLayer[targetLayer].queryUrl == url) {
			// quan la url es la mateixa no l'actualitzem i evitem fer una nova peticio
			this.afterQueryReceived(targetLayer); // important executar-ho! sinò queda el layer estatic i sembla que el mapa perdi l'eina
			DebugOut("("+this.mapInstanceName+") sendWMSRequest.eventAfterOneLayerLoaded()",INFO);
			this.eventAfterOneLayerLoaded();
		} else {

			//----------
			var img=this.mapLayer[targetLayer].targetImg;
			eval("img.map="+this.mapInstanceName+";");
			img.requestUrl=requestUrl;
			img.targetLayer=targetLayer;
			img.retryNum=retryNum;
			img.theMap=eval(this.mapInstanceName);

			img.onmousedown=function() {return false;};
			img.onerror=function() {this.theMap.processErrorResponse(this,this.targetLayer,this.retryNum);};
			img.onload=function() {
				this.theMap.resetPosition();
				this.theMap.afterQueryReceived(this.targetLayer);
				this.theMap.processResponse(this);	
				this.theMap=null;
			};

			img.src=url;
			//----------

			this.showLoading();
		}
		this.mapLayer[targetLayer].queryUrl = url; // guardem la url
		
		DebugOut("("+this.mapInstanceName+") NMap.sendWMSRequest(): " + url,INFO);
	} catch (e) {alert("Error a sendRequest()\n"+e.message);}
};


/** 
*	NMap processResponse
*	@private
*/
NMap.prototype.processResponse = function() {
	DebugOut("NMap.processResponse",WARNING);
	this.hideLoading();
	DebugOut("("+this.mapInstanceName+") processResponse.eventAfterOneLayerLoaded()",INFO);
	this.eventAfterOneLayerLoaded();
}


/** 
*	NMap processErrorResponse
*	@private
*/
NMap.prototype.processErrorResponse = function(imgObj,targetLayer,retryNum) {
	try {
		
		DebugOut ('>> PROCESSERRORRESPONSE: retry: ' + retryNum +" targetLayer: " + targetLayer,WARNING);

		this.hideLoading();
		
		if (retryNum<3) {	
			this.sendWMSRequest(imgObj.requestUrl,targetLayer);
		} else {
			DebugOut("("+this.mapInstanceName+") processErrorResponse.eventAfterOneLayerLoaded()",INFO);
			this.eventAfterOneLayerLoaded();

			if(!confirm(this+"\nError a la resposta del servidor de mapes.\n Veure l'error?")) {
				return false;
			} else{
				window.open(imgObj.src);
			}
		}
		
	} catch (e) {
		alert("Error a NMap.processErrorResponse()\n"+e.message);
	}
}

/** 
*	Configura les capes a demanar per la imatge d'aquest layer. 
*	@param {Integer} targetLayer Numero de la capa a configurar
*	@param {String} layersStr Numero de la capa a configurar
*	@param {String} serverStr URL del servidor WMS a utilitzar per fer la petició d'aquesta capa/imatge
*/
NMap.prototype.setLayers = function(targetLayer,layersStr,serverStr) {
	alert("DEPRECATED: NMap.prototype.setLayers");
}

/** 
*	Retorna una llista amb els noms dels layers separats per comes.
*	If !targetLayer returns list of all the layers.
*/
NMap.prototype.getLayerNames = function(targetLayer) {
	var ret="";
	if (typeof(targetLayer)=='undefined') {
		for (var i=0; i<this.mapLayer.length; i++) {
			var l=this.mapLayer[i].layersList;
			if (l!="") ret+=l+","; // per evitar que quedi: LAYER,,LAYER
		}
		if (ret.length>0){
			ret=ret.substr(0,ret.length-1);
		}
		
	} else ret=this.mapLayer[targetLayer].layersList;
	return ret;
}

/** 
*	posa el servidor per aquest layer
*/
NMap.prototype.setLayersServer = function(targetLayer,serverUrl) {
	alert("DEPRECATED: NMap.prototype.setLayersServer ");
}

/** 
*	Retorna el servidor per aquest layer
*/
NMap.prototype.getLayersServer = function(targetLayer) {
	alert("DEPRECATED: NMap.prototype.getLayersServer ");
	var ret=this.mapLayer[targetLayer].serverUrl;
	if (typeof(ret)=="undefined" || ret=="") ret=this.getMapServerStaticUrl();
	return ret;
}

/** 
*	@param {String} type valors: [wms|wfs]
*/
NMap.prototype.setLayersType = function(targetLayer,type) {
	alert("DEPRECATED: NMap.prototype.setLayersType ");
	this.mapLayer[targetLayer].type=type;
}

/** 
*
*/
NMap.prototype.getLayersType = function(targetLayer) {
	alert("DEPRECATED: NMap.prototype.getLayersType ");
	var ret=this.mapLayer[targetLayer].type;
	return ret;
}



/** 
*	Especifica un id per el layer.
*	@param {Number} targetLayer El numero de layer.
*/
NMap.prototype.setLayersId= function(targetLayer,id) {
	alert("DEPRECATED: NMap.prototype.setLayersId ");
	this.mapLayer[targetLayer].id=id;
}

/**
 * Retorna la petició WMS amb REQUEST=getmap.
 * @param {String} layersList
 * @param {String} layerFormat
 * @param {Object} width
 * @param {Object} height
 * @param {NExtent} extent
 * @param {Number} scaleDen
 * @private
 */
NMap.prototype.getQueryURL = function(layersList,layerFormat,width,height,extent,scaleDen) {

	DebugOut("getQueryURL widthxheight: " + width + "x" + height, DEBUG);
	DebugOut("getQueryURL extent: " + extent , DEBUG);

	var transparent=this.getConfig_transparent();
	if (layerFormat=="image/jpeg") transparent="false";

	var ret = "REQUEST=GetMap"
		+"&VERSION=1.1.1"
		+"&BBOX=" + extent.getMinX() + "," + extent.getMinY() + "," + extent.getMaxX() + "," + extent.getMaxY()
		+"&SRS=EPSG:"+this.getConfig_epsg()
		+"&HEIGHT=" + height
		+"&WIDTH=" + width
		+"&FORMAT="+layerFormat
		+"&LAYERS="+layersList
		+"&STYLES="
		+"&TRANSPARENT="+transparent
		//+"&EXCEPTIONS=INIMAGE"
		+"&userid="+this.getConfig_userid();

	return ret;
};

/** 
*	Retorna la petició WMS però amb un REQUEST=getzip. Utilitzat a salut.
*	@private
*/
NMap.prototype.getGetConfigURL = function(layersList,layerFormat,width,height,extent,scaleDen) {
	var ret=this.getQueryURL(layersList,layerFormat,width,height,extent,scaleDen);
	ret=ret.replace("REQUEST=","REQUEST=getzip&");
	return ret;
}

/** 
*	Retorna la petició WMS però amb un REQUEST=print. Utilitzat a salut.
*	@private
*/
NMap.prototype.getPrintURL = function(layersList,layerFormat,width,height,extent,scaleDen) {
	var ret=this.getQueryURL(layersList,layerFormat,width,height,extent,scaleDen);
	ret=ret.replace("REQUEST=","REQUEST=print&");
	return ret;
}


/** 
*	Retorna la petició WMS per fer un identify.
*	@private
*/
NMap.prototype.getIdentifyQueryURL = function(layersList,layerFormat,width,height,extent,scaleDen,pixX,pixY,queryLayers,infoFormat) {

	//DebugOut("getIdentifyQueryURL extent: " + extent , DEBUG);

	var idRad=this.getIdentifyRadius();

	var radius="";
	if (idRad >= 0) {
		radius = "&RADIUS="+ idRad;
	}

	var ret = "REQUEST=GetFeatureInfo"
		+"&VERSION=1.1.1"
		+"&BBOX=" + extent.getMinX() + "," + extent.getMinY() + "," + extent.getMaxX() + "," + extent.getMaxY()
		+"&SRS=EPSG:"+this.getConfig_epsg()
		+"&HEIGHT=" + height
		+"&WIDTH=" + width
		+"&FORMAT=image/png"
		+"&LAYERS="+layersList
		+"&STYLES="
		+"&TRANSPARENT=true"
		+"&X="+pixX
		+"&Y="+pixY
		+radius
		+"&INFO_FORMAT="+infoFormat
		+"&QUERY_LAYERS="+queryLayers
		+"&FEATURE_COUNT=2"
		//+"&EXCEPTIONS=INIMAGE"
		+"&userid="+this.getConfig_userid();
	return ret;

};


/** 
*	NMap getQueryURL4ZoomIn
*	@private
*/
NMap.prototype.getQueryURL4ZoomIn = function(layersList,layerFormat,width,height,newExtent,pixBoxX0,pixBoxY0,pixBoxX1,pixBoxY1) {
	
	var newExtentQuad=this.getZoomInTargetExtent(width,height,newExtent,pixBoxX0,pixBoxY0,pixBoxX1,pixBoxY1);
	var newScale=newExtentQuad.getScaleDenominator(width);
	
	this.extentZoomTemp=newExtentQuad;
	DebugOut("getQueryURL4ZoomIn()  newExtentQuad=" + newExtentQuad  ,DEBUG);
	return this.getQueryURL(layersList,layerFormat,width,height,newExtentQuad,newScale);
};

/** 
*	NMap getQueryURL4ZoomOut
*	@private
*/
NMap.prototype.getQueryURL4ZoomOut = function(layersList,layerFormat,width,height,newExtent,pixBoxX0,pixBoxY0,pixBoxX1,pixBoxY1) {
	
	var newExtentQuad = this.getZoomOutTargetExtent(width,height,newExtent,pixBoxX0,pixBoxY0,pixBoxX1,pixBoxY1);
	var newScale= newExtentQuad.getScaleDenominator(width);

	this.extentZoomTemp=newExtentQuad;
	DebugOut("getQueryURL4ZoomOut() newExtentQuad=" + newExtentQuad  ,DEBUG);
	return this.getQueryURL(layersList,layerFormat,width,height,newExtentQuad,newScale);
};


/** 
*	NMap getZoomInTargetExtent
*	@private
*/
NMap.prototype.getZoomInTargetExtent = function(width,height,newExtent,pixBoxX0,pixBoxY0,pixBoxX1,pixBoxY1) {
	try {
		// calculem el nou centre
		var xfinal = Math.round(newExtent.getMinX() + (Math.abs(newExtent.getMaxX() - newExtent.getMinX()) / 2));
		var yfinal = Math.round(newExtent.getMinY() + (Math.abs(newExtent.getMaxY() - newExtent.getMinY()) / 2));
		//DebugOut("getQueryURL4ZoomIn() new centre: x=" + xfinal + " y=" + yfinal ,DEBUG);
		var currentScale = this.extent.getScaleDenominator(width);

		var limiteRequadro = 6;
		if (Math.abs(pixBoxX1 - pixBoxX0) <= limiteRequadro && Math.abs(pixBoxY1-pixBoxY0) <= limiteRequadro){
			var newScale = Math.abs(currentScale * 0.9);
			//DebugOut("getQueryURL4ZoomIn() hacerPeticion_1: salt escala..." + currentScale + " -> " + newScale  ,DEBUG);
		} else {
			if (Math.abs(pixBoxX1 - pixBoxX0) > Math.abs(pixBoxY1 -pixBoxY0)){
				var newScale = Math.abs(pixBoxX1-pixBoxX0) * currentScale / width;
				//DebugOut("getQueryURL4ZoomIn() hacerPeticion_2: salt escala..." + currentScale + " -> " + newScale  ,DEBUG);
			} else {
				var newScale = Math.abs(pixBoxY1-pixBoxY0) * currentScale / height;
				//DebugOut("getQueryURL4ZoomIn() hacerPeticion_3: salt escala..." + currentScale + " -> " + newScale  ,DEBUG);
			}
		}
		// Calculem les noves coordenades a demanar que ja tindran la relacio pixel/coord correcte
		var coordsWidth =  this.widthMeters * newScale;
		var coordX0 = xfinal - coordsWidth/2;
		var coordX1 = xfinal + coordsWidth/2;
		var coordsHeight =  this.heightMeters * newScale;
		var coordY0 = yfinal - coordsHeight/2;
		var coordY1 = yfinal + coordsHeight/2;
		var newExtentQuad = new NExtent(new NPoint(coordX0,coordY0), new NPoint(coordX1,coordY1));
		
		return newExtentQuad;
		
	}
	catch (e) {
		alert("Error a NMap.getZoomOutTargetExtent()\n"+e.message);
	}
};

/** 
*	NMap getZoomOutTargetExtent
*	@private
*/
NMap.prototype.getZoomOutTargetExtent = function(width,height,newExtent,pixBoxX0,pixBoxY0,pixBoxX1,pixBoxY1) {
	try {
			
		// calculem el nou centre
		var xfinal = Math.round( newExtent.getMinX() + (Math.abs(newExtent.getMaxX() - newExtent.getMinX()) / 2) );
		var yfinal = Math.round( newExtent.getMinY() + (Math.abs(newExtent.getMaxY() - newExtent.getMinY()) / 2) );
		//DebugOut("getZoomOutTargetExtent() new centre: x=" + xfinal + " y=" + yfinal ,DEBUG);
		var currentScale = this.extent.getScaleDenominator(width);

		var limiteRequadro = 6;
		if (Math.abs(pixBoxX1 - pixBoxX0) <= limiteRequadro && Math.abs(pixBoxY1-pixBoxY0) <= limiteRequadro){
			var newScale = Math.abs(currentScale * 1.1);
			//DebugOut("getQueryURL4ZoomOut() hacerPeticion_1: salt escala..." + currentScale + " -> " + newScale  ,DEBUG);
		} else {
			if (Math.abs(pixBoxX1 - pixBoxX0) > Math.abs(pixBoxY1 -pixBoxY0)){
				var newScale = currentScale * ( 2 - (Math.abs(pixBoxX1-pixBoxX0)/width) );
				//DebugOut("getQueryURL4ZoomOut() hacerPeticion_2: salt escala..." + currentScale + " -> " + newScale  ,DEBUG);
			} else {
				var newScale = currentScale * ( 2 - (Math.abs(pixBoxY1-pixBoxY0)/height) );
				//DebugOut("getQueryURL4ZoomOut() hacerPeticion_3: salt escala..." + currentScale + " -> " + newScale  ,DEBUG);
			}
		}
		// Calculem les noves coordenades a demanar que ja tindran la relacio pixel/coord correcte
		var coordsWidth =  this.widthMeters * newScale;
		var coordX0 = xfinal - coordsWidth/2;
		var coordX1 = xfinal + coordsWidth/2;
		var coordsHeight =  this.heightMeters * newScale;
		var coordY0 = yfinal - coordsHeight/2;
		var coordY1 = yfinal + coordsHeight/2;
		var newExtentQuad = new NExtent(new NPoint(coordX0,coordY0), new NPoint(coordX1,coordY1));
		
		return newExtentQuad;
		
	}
	catch (e) {
		alert("Error a NMap.getZoomOutTargetExtent()\n"+e.message);
	}
};

/** 
*	Fa una petició d'identify amb WMS. Mostra el resultat en un lloc o altre segons la configuració: panell dojo, popup o al gestor de continguts.
*	@param {Integer} pixX pixel X
*	@param {Integer} pixY pixel Y
*/
NMap.prototype.identifyWithPixels = function(pixX,pixY) {
	try {
		
		if (this.eventBeforeIdentifyQuery(pixX,pixY)==true) return; //permet cancelar la peticio

		var staticUrl=this.getMapServerIdentifyUrl();
		var queryLayers=this.getIdentifyLayers();
		var dynamicUrl=this.getIdentifyQueryURL(this.getLayerNames(),"image/jpeg",this.width,this.height,this.extent,this.extent.getScaleDenominator(this.width),pixX,pixY,queryLayers,this.getConfig_info_format());
		DebugOut("NMap.identifyWithPixels() URL: " + staticUrl+dynamicUrl , DEBUG);

		if (this.identifyResponseType==this.IDENTIFY_POPUP) {

			if (typeof(this.identifyWindow)=="undefined") this.identifyWindow='';
			this.identifyWindow=this.popitup(this.identifyWindow,staticUrl+dynamicUrl);

		} else if (this.identifyResponseType==this.IDENTIFY_DOJO) {

			try {
				var destroyFunc=function() {
					var undef;			
					this.dojoWidget=undef;
				}
				this.dojoWidget=openDojoPane(this.dojoWidget,this.getIdentifyTitle(),staticUrl+dynamicUrl,30,30,this.getIdentifyWindowWidth(),this.getIdentifyWindowHeight(),destroyFunc);
			}
			catch (e) {
				alert("Error dojo a NMap.identifyWithPixels():"+e.message);
				if (typeof(this.identifyWindow)=="undefined") this.identifyWindow='';
				this.identifyWindow=this.popitup(this.identifyWindow,staticUrl+dynamicUrl);
			}

		} else if (this.identifyResponseType==this.IDENTIFY_TOC) {

			this.sendRequest(staticUrl+dynamicUrl,this.processIdentifyTOCResponseCall);
		}
		
	}
	catch (e) {
		alert("Error a NMap.identifyWithPixels()\n"+e.message);
	}
	
}


/**
*	Rep la resposta amb l'xml de la llegenda a carregar.
*	@private
*/
NMap.prototype.processIdentifyTOCResponseCall = function(nmap, responseXML, req) {
	
	
	try {
//		alert ('>> processIdentifyTOCResponseCall:' + req.responseText );
//		document.getElementById("infoDiv").innerHTML=req.responseText;
		nmap.processIdentifyTOCResponse(req.responseText);
	}
	catch (e) {
		alert("Error a NMap.processIdentifyTOCResponseCall()\n"+e.message);
	}

};


/**
*	Rep la resposta amb l'xml de la llegenda a carregar.
*	@private
*/
NMap.prototype.processIdentifyTOCResponse = function(responseText) {}

/**
*	petició via ajax
*	@private
*/
NMap.prototype.sendRequest = function(servletPath,processResponse) {
	try {
		
		DebugOut("NContent.sendRequest() "+servletPath ,INFO);
		var req = newXMLHttpRequest();

		// Set the handler function to receive callback notifications from the request object
		var handlerFunction = getReadyStateHandler(req, this, processResponse);
		req.onreadystatechange = handlerFunction;

		// Open an HTTP POST connection. Third parameter specifies request is asynchronous.
		req.open("GET", servletPath, true);

		// Specify that the body of the request contains form data
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send("");
		
	}
	catch (e) {
		alert("Error a NMap.sendRequest()\n"+e.message);
	}
};

/**
*	Obre una nova finestra de 500x400. S'utilitza en fer l'identify
*	@private
*/
NMap.prototype.popitup = function(newwindow,url) {
	DebugOut("NMap.popitup()" , DEBUG);
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = "loading.html";
	} else{
		//newwindow=window.open(url,'name','height=400,width=500,scrollbars=yes,resizable=yes');
		newwindow=window.open('loading.html','name','height=400,width=500,scrollbars=yes,resizable=yes');
		if (!newwindow.opener) newwindow.opener = self;
	}
	try {
		newwindow.document.write("<HTML>");
		newwindow.document.write("<TITLE></TITLE>");
		newwindow.document.write("<BODY BGCOLOR=white>");
		newwindow.document.write("<p>carregant...</p>");
		newwindow.document.write("<img src='img/wait.gif' alt='loading' />");
		newwindow.document.write("</BODY>");
		newwindow.document.write("</HTML>");
		newwindow.location.href = url;
	}
	catch (e) {
		newwindow.location.href = url;
	}

	try {
		newwindow.focus()	
	} catch (e) {}

	return newwindow;
}


/** 
*	Canvia el format de la imatge del layer especificat per parametre.
*	@param {Integer} targetLayer El número del layer a canviar el format. Si només hi ha una imatge/layer = 0.
*	@param {String} value El nou format a demanar. Ex: "image/jpeg", "image/gif" ... Atenció: això depen del servidor WMS!
*/
NMap.prototype.setConfig_format = function(targetLayer,value) {
	alert("DEPRECATED: NMap.prototype.setConfig_format ");
	this.mapLayer[targetLayer].imageFormat=value;
	//this.queryFormat=value;
}

/** 
*	Canvia el sistema de coordenades a utilitzar en la petició WMS. 
*	@param {String} value El nou sistema de coordenades. Ex: 23031= utm31"
*/
NMap.prototype.setConfig_epsg = function(value) {
	this.queryEPSG=value;
}

/** 
*	Indica si les imatges s'han de demanar amb transparència o no. &TRANSPARENT=TRUE
*	@param {boolean} value Transparència activa.
*/
NMap.prototype.setConfig_transparent = function(value) {
	this.queryTransparent=value;
}

/** 
*	Assignem un userid que es passarà a les peticions WMS com a &USERID=ADMDES
*/
NMap.prototype.setConfig_userid = function(value) {
	this.queryUserId=value;
}

/** 
*	Definim el parametre a utilitzar a peticions WMS de identify GETFEATURES amb &INFO_FORMAT=VALUE
*/
NMap.prototype.setConfig_info_format = function(value) {
	this.infoFormat=value;
}

/** 
*	Retorna el format actual del layer especificat per parametre.
*	@param {Integer} targetLayer El número del layer.
*	@return {String}
*/
NMap.prototype.getConfig_format = function(targetLayer) {
	alert("DEPRECATED: NMap.prototype.getConfig_format ");
}

/** 
*	Retorna l'epsg actual
*	@return {String}
*/
NMap.prototype.getConfig_epsg = function() {
	var v=this.queryEPSG;
	if (typeof(v)=="undefined") v="23031";
	return v;
}

/** 
*	Retorna si la transparencia està activada
*	@return {boolean}
*/
NMap.prototype.getConfig_transparent = function() {
	var v=this.queryTransparent;
	if (typeof(v)=="undefined") v="false";
	return v;
}

/** 
*	Retorna l'userid actual
*	@return {String}
*/
NMap.prototype.getConfig_userid = function() {
	var v=this.queryUserId;
	if (typeof(v)=="undefined") v="";
	return v;
}

/** 
*	Retorna l'info format a utilitzar a peticions identify
*	@return {String}
*/
NMap.prototype.getConfig_info_format = function() {
	var v=this.infoFormat;
	if (typeof(v)=="undefined") v="gml"; // per defecte gml!
	return v;
}

/** 
*	Posa la mida per defecte de la finestra identify.
*	@param {Number} width
*	@param {Number} height
*/
NMap.prototype.setIdentifyWindowSize = function(width,height) {
	this.identifyWindowWidth=parseFloat(width);
	this.identifyWindowHeight=parseFloat(height);
}

/** 
*	Retorna el width de la finestra d'identify
*	@return {Number}
*/
NMap.prototype.getIdentifyWindowWidth = function() {
	if (isFinite(this.identifyWindowWidth)) return this.identifyWindowWidth;
	else return 500;
}

/** 
*	Retorna el width de la finestra d'identify
*	@return {Number}
*/
NMap.prototype.getIdentifyWindowHeight = function() {
	if (isFinite(this.identifyWindowHeight)) return this.identifyWindowHeight;
	else return 400;
}

/** 
*	Retorna el width de la finestra d'identify
*	@return {String}
*/
NMap.prototype.getIdentifyTitle = function() {
	if (typeof(this.identifyWindowTitle)=="undefined") return "Informació";
	else return this.identifyWindowTitle;
	return v;
}

/** 
*	Especifica el text a posar com a titol de la finestra.
*	@param {String} text
*/
NMap.prototype.setIdentifyWindowTitle = function(text) {
	this.identifyWindowTitle=text;
}


/** 
*	Retorna el valor del RADIUS. Parametre utilitzat a una petició de identify o getfeaturerequest
*	El valor per defecte és 5.
*	@return {String}
*/
NMap.prototype.getIdentifyRadius = function() {
	if (isFinite(this.identifyRadius)) return this.identifyRadius;
	else return -1;
}

/** 
*	Permet especificar el valor del parametre RADIUS d'una petició de REQUEST=GETFEATUREREQUEST.
*	Serveix per ajustar la sensibilitat del click al fer una petició. Distancia entre punt clickat i el poi.
*	@param {Number} radius Valor en pixels del radi de la circumferencia on s'ha fet el click.
*/
NMap.prototype.setIdentifyRadius = function(radius) {
	this.identifyRadius=parseFloat(radius);
}

/** 
*
*/
NMap.prototype.getUseTimeStamp = function() {
	if (typeof(this.useTimeStamp)=="undefined") return false;
	else return this.useTimeStamp;
}

/** 
*
*/
NMap.prototype.setUseTimeStamp = function(useTimeStamp) {
	this.useTimeStamp=useTimeStamp;
}


