 function enviarPeticio() {

X0=document.frmCataleg.x0.value;
Y0=document.frmCataleg.y0.value;
X1=document.frmCataleg.x1.value;
Y1=document.frmCataleg.y1.value;

//var BBOX=X0+","+Y0+","+X1+","+Y1;

var BBOX=Y0+" "+X0+","+Y1+" "+X1;
var idioma=document.frmCataleg.idioma.value;

document.frmCataleg.caixaCoordenades.value=BBOX;

miraGeometria();
//alert(2);
miraParaules();
//alert(3);
document.frmCataleg.idioma.value=idioma

 //document.frmCataleg.do.value="cercaDatasets";    
  //document.frmCataleg.organitzacio.name="org";     
       
  

  //alert(document.frmCataleg.org.value);
        document.frmCataleg.target="_BLANK"; 
        document.frmCataleg.action = "http://delta.icc.cat/wefex/client";
        document.frmCataleg.method = "GET";
        document.frmCataleg.submit(); 
        
        //document.frmCataleg.reset();
         
        
        
  }
 
 function esborraCoord(){
    document.frmCataleg.x0.value="";
	document.frmCataleg.x1.value="";
	document.frmCataleg.y0.value="";
	document.frmCataleg.y1.value="";
	document.frmCataleg.boxSpatial.body="";
    document.frmCataleg.boxSpatial.value="";
    document.frmCataleg.boxSpatial.text="";
        }

function obreAjudaSpatial(){
window.open('ajuda/helpSpatial.html','help','status=0,toolbar=0,location=0,menubar=0,scrollbars=1,resizable=0,height=500, width=600')
}

function miraParaules(){
var cForm=document.frmCataleg;

if(cForm.cercaTot0.value!=""){
var apre=0;
	for (i=0; i<cForm.tot.length; i++) {
    	if (cForm.tot[i].checked) {
    	apre=1;
    		if(cForm.tot[i].value==0){
				cForm.cercaTot.value =cForm.cercaTot0.value+"*" ;
     		}else{
     			cForm.cercaTot.value ="*"+cForm.cercaTot0.value+"*" ;
     		} 

	}
	}
	if(apre==0){cForm.cercaTot.value ="*"+cForm.cercaTot0.value+"*" ;}
	}else{
    cForm.cercaTot.value="";
    }

if(cForm.paraulaClau0.value!=""){
var cpre=0;
	for (i=0; i<cForm.tot.length; i++) {
    	if (cForm.clau[i].checked) {
    	cpre=1;
    		if(cForm.clau[i].value==0){
				cForm.paraulaClau.value =cForm.paraulaClau0.value+"*" ;
     		}else{
     			cForm.paraulaClau.value ="*"+cForm.paraulaClau0.value+"*" ;
     		} 

	}
	}
	if(cpre==0){cForm.paraulaClau.value ="*"+cForm.paraulaClau0.value+"*" ;}
	}else{
    cForm.paraulaClau.value="";
    }


}
function miraGeometria(){
  
 if (document.getElementById('geoLinea').style.visibility=="visible"){
 	var optionBox=document.frmCataleg.radiobuttonL;
 
	for (i=0; i<optionBox.length; i++) {

    	if (optionBox[i].checked) {

      	document.frmCataleg.boxSpatial.name = optionBox[i].value;
     	}      
 	}
 }
 
 if (document.getElementById('geoPoligon').style.visibility=="visible"){
 	var optionBox=document.frmCataleg.radiobuttonP;
 
	for (i=0; i<optionBox.length; i++) {

    	if (optionBox[i].checked) {

      	document.frmCataleg.boxSpatial.name = optionBox[i].value;
     	}      
 	}
 }
  
 
  
  //alert(document.frmCataleg.boxSpatial.name);
  
  }
  
  
function activaControls(tipus,geometria){
var theForm;
	
	
		theForm = document;
	
if (tipus=="1"){
theForm.frmCataleg.boxSpatial.value="";
theForm.getElementById('boxCoo').style.visibility="hidden";
theForm.getElementById('geoLinea').style.visibility="hidden";
theForm.getElementById('geoPoligon').style.visibility="hidden";

theForm.getElementById('txtNord').style.visibility="visible";
theForm.getElementById('txtSud').style.visibility="visible";
theForm.getElementById('txtEst').style.visibility="visible";
theForm.getElementById('txtOest').style.visibility="visible";
theForm.getElementById('lblNord').style.visibility="visible";
theForm.getElementById('lblSud').style.visibility="visible";
theForm.getElementById('lblEst').style.visibility="visible";
theForm.getElementById('lblOest').style.visibility="visible";

}else{
theForm.frmCataleg.x0.value="";
theForm.frmCataleg.x1.value="";
theForm.frmCataleg.y0.value="";
theForm.frmCataleg.y1.value="";
theForm.getElementById('boxCoo').style.visibility="visible";
theForm.getElementById('txtNord').style.visibility="hidden";
theForm.getElementById('txtSud').style.visibility="hidden";
theForm.getElementById('txtEst').style.visibility="hidden";
theForm.getElementById('txtOest').style.visibility="hidden";
theForm.getElementById('lblNord').style.visibility="hidden";
theForm.getElementById('lblSud').style.visibility="hidden";
theForm.getElementById('lblEst').style.visibility="hidden";
theForm.getElementById('lblOest').style.visibility="hidden";
	if (geometria=="1"){
	//Geometria linea
	theForm.getElementById('geoLinea').style.visibility="visible";
	theForm.getElementById('geoPoligon').style.visibility="hidden";
	}
	
	if (geometria=="2"){
	//Geometria poligon
	theForm.getElementById('geoPoligon').style.visibility="visible";
	theForm.getElementById('geoLinea').style.visibility="hidden";
	}
	
	
	 
}


}

function activa(index){
	for (var i=0; i<map.servidores.length; i++) {
		if (map.servidores[i][1] == index){
			map.servidores[i][3] = true;	
		}else{
			if (map.servidores[i][1] != "orto5m,"){
				map.servidores[i][3] = false;
			}	
		}
	}
   	map.redraw(1);
}

function desactiva(index){
	for (var i=0; i<map.servidores.length; i++) {
		if (map.servidores[i][1] != "orto5m,"){
			map.servidores[i][3] = false;
		}	
	}
   	map.redraw(1);
}

function cercarText(){
	//alert("cercar");
	var nom = document.getElementById("textCerca").value;
	//alert(nom);
	var capa = document.getElementById("select").value;
	var cerca = 0;
	switch (capa){
		case "Municipis":
			cerca = 1;
			break;
		case "Comarques":
			cerca = 2;
			break;
		case "t5":
			cerca = 3;
			break;
		case "t10":
			cerca = 4;
			break;
		case "t25":
			cerca = 5;
			break;
		case "t50":
			cerca = 6;
			break;
	}
	var sURL = queryNomAjax(capa, nom, cerca);
  	getNomAjax(sURL);
}

function queryNomAjax(capa, nom, cerca){
  //var sURL = "capa="+capa+"&valor="+nom+"&cerca="+cerca;
  var sURL = "capa="+capa+"&valor="+nom+"&cerca=0";
  return sURL;
}

function getNomAjax(sURL){
	//alert("getFeatureAjax    " + sURL);
	//xmlDoc.open('GET','infoAjax1.jsp?'+sURL,true);
	xmlDoc.open('GET','cercaAjax1.jsp?'+sURL,true);
	xmlDoc.setRequestHeader("Content-Type", "text/html");
	//14 feb
	//xmlDoc.onreadystatechange = parseInfoAjax;  
	xmlDoc.onreadystatechange = parseInfoAjax3; 
	//14 feb fin
	xmlDoc.send('');
	//document.getElementById('infoDivCerca').style.visibility='visible';
}

function zoomSelNom(capaAct, capaCodiValor){
	capaCodiValor = capaCodiValor.replace("@","'");
	ajax("cercaAjax1.jsp?cerca=0&action=1&capa="+capaAct+"&valor="+capaCodiValor);
}

function SelSelNom(capaAct, capaCodiValor){
	capaCodiValor = capaCodiValor.replace("@","'");
	ajax("cercaAjax1.jsp?cerca=0&action=2&capa="+capaAct+"&valor="+capaCodiValor);
}

//18 abr
 function tancaResultado(){
	//alert("tranca");
	document.getElementById('infoDivCerca').style.visibility='hidden';
}

function selecRes(minx, miny, maxx, maxy){
	var pt1 = window.parent.map.projToPixel(minx,maxy);
	var pt2 = window.parent.map.projToPixel(maxx,miny);
	window.parent.map.limpiar();
	window.parent.map.pt1 = pt1;
	window.parent.map.pt2 = pt2;
	selecSelec1(pt1,pt2);
}

function selecSelec1(pt1,pt2){
	
	
	
	if (pt1[0]>pt2[0]){
    	w = pt1[0] - pt2[0];
    	x = pt2[0];
    }else{
    	w = pt2[0] - pt1[0];
    	x = pt1[0];
    }
    if (pt1[1]>pt2[1]){
    	h = pt1[1] - pt2[1];
    	y = pt2[1];
    }else{
    	h = pt2[1] - pt1[1];
    	y = pt1[1];
    }
    	
    //Coloco los puntos del cuadrado en el arreglo de puntos
    var pt = window.parent.map.pixelToProj(x,y);
    window.parent.map.PtsPoli[window.parent.map.PtsPoli.length] = pt;
    pt = window.parent.map.pixelToProj(x+w,y);
    window.parent.map.PtsPoli[window.parent.map.PtsPoli.length] = pt;
    pt = window.parent.map.pixelToProj(x+w,y+h);
    window.parent.map.PtsPoli[window.parent.map.PtsPoli.length] = pt;
    pt = window.parent.map.pixelToProj(x,y+h);
    window.parent.map.PtsPoli[window.parent.map.PtsPoli.length] = pt;
	//dibujo los puntos
	window.parent.map.drawPts();
    window.parent.map.actualizaCoord();
    window.parent.document.getElementById('posFitxes').style.visibility='hidden';
    //window.parent.document.getElementById('infoDivCerca').style.visibility='hidden';
}
