
//'193.144.250.29'
var ruta=document.location.href;
if(ruta.indexOf('delta.icc.cat')!=-1){
	
	ruta=ruta.replace('delta.icc.cat','delta.icc.es');
	document.location.href=ruta;
}
else if (ruta.indexOf('delta.icc.es')!=-1){

}else{
	//document.location.href="http://delta.icc.es/ideLocal/visual/pescadors.jsp?host="+document.location.host+"&codiMun=00000&tipus=&";
}

//+++++++++++++++++++++++++++CORDENADES
var pi = 3.14159265358979;
var sm_a = 6378137.0;
var sm_b = 6356752.314;
var sm_EccSquared = 6.69437999013e-03;
var UTMScaleFactor = 0.9996;
var i=0;

function FootpointLatitude (y)
    {
        var y_, alpha_, beta_, gamma_, delta_, epsilon_, n;
        var result;
        
      
        n = (sm_a - sm_b) / (sm_a + sm_b);
       
        alpha_ = ((sm_a + sm_b) / 2.0)
            * (1 + (Math.pow (n, 2.0) / 4) + (Math.pow (n, 4.0) / 64));
        
       
        y_ = y / alpha_;
        
      
        beta_ = (3.0 * n / 2.0) + (-27.0 * Math.pow (n, 3.0) / 32.0)
            + (269.0 * Math.pow (n, 5.0) / 512.0);
        
     
        gamma_ = (21.0 * Math.pow (n, 2.0) / 16.0)
            + (-55.0 * Math.pow (n, 4.0) / 32.0);
                
      
        delta_ = (151.0 * Math.pow (n, 3.0) / 96.0)
            + (-417.0 * Math.pow (n, 5.0) / 128.0);
     
        epsilon_ = (1097.0 * Math.pow (n, 4.0) / 512.0);
    
        result = y_ + (beta_ * Math.sin (2.0 * y_))
            + (gamma_ * Math.sin (4.0 * y_))
            + (delta_ * Math.sin (6.0 * y_))
            + (epsilon_ * Math.sin (8.0 * y_));
        
        return result;
    }


 function MapXYToLatLon (x, y, lambda0, philambda)
    {
        var phif, Nf, Nfpow, nuf2, ep2, tf, tf2, tf4, cf;
        var x1frac, x2frac, x3frac, x4frac, x5frac, x6frac, x7frac, x8frac;
        var x2poly, x3poly, x4poly, x5poly, x6poly, x7poly, x8poly;
     
        phif = FootpointLatitude (y);
      
        ep2 = (Math.pow (sm_a, 2.0) - Math.pow (sm_b, 2.0))
              / Math.pow (sm_b, 2.0);
     
        cf = Math.cos (phif);
                
    
        nuf2 = ep2 * Math.pow (cf, 2.0);
                
     
        Nf = Math.pow (sm_a, 2.0) / (sm_b * Math.sqrt (1 + nuf2));
        Nfpow = Nf;
     
        tf = Math.tan (phif);
        tf2 = tf * tf;
        tf4 = tf2 * tf2;
      
        x1frac = 1.0 / (Nfpow * cf);
        
        Nfpow *= Nf;  
        x2frac = tf / (2.0 * Nfpow);
        
        Nfpow *= Nf;  
        x3frac = 1.0 / (6.0 * Nfpow * cf);
        
        Nfpow *= Nf;  
        x4frac = tf / (24.0 * Nfpow);
        
        Nfpow *= Nf;   
        x5frac = 1.0 / (120.0 * Nfpow * cf);
        
        Nfpow *= Nf;  
        x6frac = tf / (720.0 * Nfpow);
        
        Nfpow *= Nf;  
        x7frac = 1.0 / (5040.0 * Nfpow * cf);
        
        Nfpow *= Nf;   
        x8frac = tf / (40320.0 * Nfpow);
        
      
        x2poly = -1.0 - nuf2;
        
        x3poly = -1.0 - 2 * tf2 - nuf2;
        
        x4poly = 5.0 + 3.0 * tf2 + 6.0 * nuf2 - 6.0 * tf2 * nuf2
                - 3.0 * (nuf2 *nuf2) - 9.0 * tf2 * (nuf2 * nuf2);
        
        x5poly = 5.0 + 28.0 * tf2 + 24.0 * tf4 + 6.0 * nuf2 + 8.0 * tf2 * nuf2;
        
        x6poly = -61.0 - 90.0 * tf2 - 45.0 * tf4 - 107.0 * nuf2
                + 162.0 * tf2 * nuf2;
        
        x7poly = -61.0 - 662.0 * tf2 - 1320.0 * tf4 - 720.0 * (tf4 * tf2);
        
        x8poly = 1385.0 + 3633.0 * tf2 + 4095.0 * tf4 + 1575 * (tf4 * tf2);
                
       
        philambda[0] = phif + x2frac * x2poly * (x * x)
                + x4frac * x4poly * Math.pow (x, 4.0)
                + x6frac * x6poly * Math.pow (x, 6.0)
                + x8frac * x8poly * Math.pow (x, 8.0);
                
       
        philambda[1] = lambda0 + x1frac * x
                + x3frac * x3poly * Math.pow (x, 3.0)
                + x5frac * x5poly * Math.pow (x, 5.0)
                + x7frac * x7poly * Math.pow (x, 7.0);
                
        return;
    }


 function UTMCentralMeridian (zone)
    {
        var cmeridian;

        cmeridian = DegToRad (-183.0 + (zone * 6.0));
    
        return cmeridian;
    }


 
 function UTMXYToLatLon (x, y, zone, southhemi, latlon)
    {
        var cmeridian;
                
        x -= 500000.0;
        x /= UTMScaleFactor;
                
      
        if (southhemi)
        y -= 10000000.0;
                        
        y /= UTMScaleFactor;
        
        cmeridian = UTMCentralMeridian (zone);
        MapXYToLatLon (x, y, cmeridian, latlon);
                
        return;
    }
     
     function DegToRad (deg)
    {
        return (deg / 180.0 * pi)
    }

     
     
     function RadToDeg (rad)
    {
        return (rad / pi * 180.0)
    }
function ArcLengthOfMeridian (phi)
    {
        var alpha, beta, gamma, delta, epsilon, n;
        var result;

        /* Precalculate n */
        n = (sm_a - sm_b) / (sm_a + sm_b);

        /* Precalculate alpha */
        alpha = ((sm_a + sm_b) / 2.0)
           * (1.0 + (Math.pow (n, 2.0) / 4.0) + (Math.pow (n, 4.0) / 64.0));

        /* Precalculate beta */
        beta = (-3.0 * n / 2.0) + (9.0 * Math.pow (n, 3.0) / 16.0)
           + (-3.0 * Math.pow (n, 5.0) / 32.0);

        /* Precalculate gamma */
        gamma = (15.0 * Math.pow (n, 2.0) / 16.0)
            + (-15.0 * Math.pow (n, 4.0) / 32.0);
    
        /* Precalculate delta */
        delta = (-35.0 * Math.pow (n, 3.0) / 48.0)
            + (105.0 * Math.pow (n, 5.0) / 256.0);
    
        /* Precalculate epsilon */
        epsilon = (315.0 * Math.pow (n, 4.0) / 512.0);
    
    /* Now calculate the sum of the series and return */
    result = alpha
        * (phi + (beta * Math.sin (2.0 * phi))
            + (gamma * Math.sin (4.0 * phi))
            + (delta * Math.sin (6.0 * phi))
            + (epsilon * Math.sin (8.0 * phi)));

    return result;
    }
function MapLatLonToXY (phi, lambda, lambda0, xy)
    {
        var N, nu2, ep2, t, t2, l;
        var l3coef, l4coef, l5coef, l6coef, l7coef, l8coef;
        var tmp;

        /* Precalculate ep2 */
        ep2 = (Math.pow (sm_a, 2.0) - Math.pow (sm_b, 2.0)) / Math.pow (sm_b, 2.0);
    
        /* Precalculate nu2 */
        nu2 = ep2 * Math.pow (Math.cos (phi), 2.0);
    
        /* Precalculate N */
        N = Math.pow (sm_a, 2.0) / (sm_b * Math.sqrt (1 + nu2));
    
        /* Precalculate t */
        t = Math.tan (phi);
        t2 = t * t;
        tmp = (t2 * t2 * t2) - Math.pow (t, 6.0);

        /* Precalculate l */
        l = lambda - lambda0;
    
        /* Precalculate coefficients for l**n in the equations below
           so a normal human being can read the expressions for easting
           and northing
           -- l**1 and l**2 have coefficients of 1.0 */
        l3coef = 1.0 - t2 + nu2;
    
        l4coef = 5.0 - t2 + 9 * nu2 + 4.0 * (nu2 * nu2);
    
        l5coef = 5.0 - 18.0 * t2 + (t2 * t2) + 14.0 * nu2
            - 58.0 * t2 * nu2;
    
        l6coef = 61.0 - 58.0 * t2 + (t2 * t2) + 270.0 * nu2
            - 330.0 * t2 * nu2;
    
        l7coef = 61.0 - 479.0 * t2 + 179.0 * (t2 * t2) - (t2 * t2 * t2);
    
        l8coef = 1385.0 - 3111.0 * t2 + 543.0 * (t2 * t2) - (t2 * t2 * t2);
    
        /* Calculate easting (x) */
        xy[0] = N * Math.cos (phi) * l
            + (N / 6.0 * Math.pow (Math.cos (phi), 3.0) * l3coef * Math.pow (l, 3.0))
            + (N / 120.0 * Math.pow (Math.cos (phi), 5.0) * l5coef * Math.pow (l, 5.0))
            + (N / 5040.0 * Math.pow (Math.cos (phi), 7.0) * l7coef * Math.pow (l, 7.0));
    
        /* Calculate northing (y) */
        xy[1] = ArcLengthOfMeridian (phi)
            + (t / 2.0 * N * Math.pow (Math.cos (phi), 2.0) * Math.pow (l, 2.0))
            + (t / 24.0 * N * Math.pow (Math.cos (phi), 4.0) * l4coef * Math.pow (l, 4.0))
            + (t / 720.0 * N * Math.pow (Math.cos (phi), 6.0) * l6coef * Math.pow (l, 6.0))
            + (t / 40320.0 * N * Math.pow (Math.cos (phi), 8.0) * l8coef * Math.pow (l, 8.0));
    
        return;
    }
    function LatLonToUTMXY (lat, lon, zone, xy)
    {
        MapLatLonToXY (lat, lon, UTMCentralMeridian (zone), xy);

        /* Adjust easting and northing for UTM system. */
        xy[0] = xy[0] * UTMScaleFactor + 500000.0;
        xy[1] = xy[1] * UTMScaleFactor;
        if (xy[1] < 0.0)
            xy[1] = xy[1] + 10000000.0;

        return zone;
    }

//++++++++++++++++++++++++
//++++++++++++++++++++++++
//11 Gener

//Funcions per calcular escala

var _screenWidthCm = 32.0; 
var _screenSize = 1024.0;

function getMetersByPixel(){ 
	if (getWidth() > 0) { 
 		extentWidth = top.getMap().getCurrentExtent().getXMax() - top.getMap().getCurrentExtent().getXMin(); 
 		return (getDistanceInMeters(extentWidth) / getWidth()); 
 	}
  	else return 0.0; 
}  
                  
function getMetersByPixel2(realWidth, pixelWidth){
	if (getWidth() > 0) { 
    	return (getDistanceInMeters(realWidth) / pixelWidth); 
    } 
    else return 0.0; 
} 
                   
function getScale2(realWidth, pixelWidth) { 
	metersPerPixel = getMetersByPixel2(realWidth, pixelWidth);
	scale = metersPerPixel * (PIXELPERINCH * 39.3701);
	scale = Math.round(scale);
    return scale;
}

function getWidth() { 
	return parseInt(map.mapWidthPX );
} 
 
function getHeight() { 
	return parseInt(map.mapHeightPX);
}  
                  
function getScale() {
 	extentWidth = map.cBounds[2] - map.cBounds[0]; 
   	var num= parseInt(getScale2(extentWidth, getWidth()));             
    //12 juliol 2007
	ESCALACTUAL = num;
	//fin 12 juliol 2007
	var nNmb=num.toString();  
    var sRes = ""; 
	for (var j, i = nNmb.length - 1, j = 0; i >= 0; i--, j++) {
		sRes = nNmb.charAt(i) + ((j > 0) && (j % 3 == 0)? ".": "") + sRes; 
	}
    return sRes;
	// return parseInt(getScale2(extentWidth, getWidth()));
} 
                  
function getDistanceInMeters(distance) { 
	return distance; 
}

//29 marzo
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_1997_1999'}
	//15 gener
	if(ll==3){ll='nodes.png';text=''}
	if(ll==4){ll='links.png';text=''}
	//28 marzo Tematicos
	if(ll==5){ll='munieps.gif';text='Estudis_Primàris_i_Secundàris(%)'}
	if(ll==6){ll='munieu.gif';text='Estudis_Universitàris(%)'}
	if(ll==7){ll='muniarp.gif';text='Agricultura_Ramaderia_i_Pesca(%)'}
	if(ll==8){ll='muniiee.gif';text='Indústria_i_Energia_Electrica(%)'}
	if(ll==9){ll='munic.gif';text='Construcció(%)'}
	if(ll==10){ll='munico.gif';text='Comerç(%)'}
	if(ll==11){ll='munih.gif';text='Hosteleria(%)'}
	if(ll==12){ll='munitc.gif';text='Transports_i_Comunicacions(%)'}
	if(ll==13){ll='munis.gif';text='Serveis(%)'}
	if(ll==14){ll='muni15.gif';text='De_0_a_15_anys(%)'}
	if(ll==15){ll='muni1530.gif';text='15_a_30_anys(%)'}
	if(ll==16){ll='muni65.gif';text='30_a_65_anys(%)'}
	if(ll==17){ll='muni66.gif';text='Més_de_65_anys(%)'}
	if(ll==18){ll='munipobl.gif';text='Població_1996(Total)'}
	if(ll==19){ll='munipao.gif';text='Població_Activa_Ocupats(%)'}
	if(ll==20){ll='munipnaj.gif';text='Població_No_Activa_Jubilats(%)'}
	if(ll==21){ll='munipnae.gif';text='Població_No_Activa_Estudiant(%)'}
	if(ll==22){ll='stac/sectors.png';text='Sectors'}
	if(ll==23){ll='stac/qualificacio.png';text='Qualificacions'}
	if(ll==24){ll='protContLluminosa.jpeg';text='Contaminacio_Lluminosa'}
	
	/*
	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();
	*/
	var wInfo = "<html><title>Llegenda</title>";
	wInfo += "<table border=0><tr><td align=center><b>"+text+"</b></td></tr><tr>";
	wInfo += "<td align=center><img border=0 src='images/llegenda/"+ll+"'></td></tr></table></html>";
	var winInfo = dhtmlwindow.open("winInfo", "inline", wInfo, "Info", "width=400px,height=530px,left=300px,top=95px,resize=1,scrolling=1");	
}



//++++++++++++++++++++++++
//++++++++++++++++++++++++
//1 Juny

//Funcions per crear menu de cerca

function escriuFinestraCerca() {
	
document.getElementById('EinesCerca').innerHTML = escriuMenuCerca();
	
	//var myAccordion2 = new Rico.Accordion( $('menuCerquesDiv'), {panelHeight:50} );

}
function escriuMenuCerca(){
	var htmlString=new Array();
	htmlString.push('<div id="accordion1">');
	htmlString.push('<div id="panel">');
	//Municipis
	
	htmlString.push('<div id="addcomment2Panel">');
	htmlString.push('<div id="addcomment2Header" class="accordionTabTitleBar">');
	htmlString.push('Carrerer');
	htmlString.push('</div>');
	htmlString.push('<div id="addcomment2Content" class="accordionTabContentBox">');
	//htmlString.push(escriuCarrerer();
	htmlString.push(idec_escriuCerques_Urbanisme(tipusAplicacio,0));
	htmlString.push('</div>');
	htmlString.push('</div>');
	
	
	htmlString.push('<div id="addcomment2Panel">');
	htmlString.push('<div id="addcomment2Header" class="accordionTabTitleBar">');
	htmlString.push('Adreça postal (cadastre)');
	htmlString.push('</div>');
	htmlString.push('<div id="addcomment2Content" class="accordionTabContentBox">');
	//htmlString.push(escriuCarrerer_Cadastre();
	htmlString.push(idec_escriuCerques_Cadastre(tipusAplicacio,0));
	htmlString.push('</div>');
	htmlString.push('</div> ');
	htmlString.push('<div id="disclaimer2Panel">');
	htmlString.push('<div id="disclaimer2Header" class="accordionTabTitleBar">');
	htmlString.push('Referència cadastral');
	htmlString.push('</div>');
	htmlString.push('<div id="disclaimer2Content" class="accordionTabContentBox">');
	htmlString.push(idec_escriuCerques_Cadastre('Parcela',0));
	htmlString.push('</div>');
	htmlString.push('</div>');
	htmlString.push('</div>');	

return htmlString.join(' ');

}
function idec_escriuCerques_Cadastre(tipus,posLeft){
	var htmlString=new Array();

	if(tipus=="Parcela"){
	htmlString.push('<table width="98%" height="98%" border="0" cellspacing="2" cellpadding="0">');
  htmlString.push('<tr>'); 
    htmlString.push('<td class="text1" ><input name="radiobutton" onclick="actiu=\'rc\');document.getElementById(\'rc\').style.display=\'block\');document.getElementById(\'pp\').style.display=\'none\'" type="radio" value="rc" checked>');
      htmlString.push('Urbana</td>');
    htmlString.push('<td class="text1" ><input type="radio" onclick="actiu=\'pp\');document.getElementById(\'pp\').style.display=\'block\');document.getElementById(\'rc\').style.display=\'none\'" name="radiobutton" value="pp">');
      htmlString.push('Rústega</td>');
  htmlString.push('</tr><tr>'); 
    htmlString.push('<td colspan="2">'); 
	htmlString.push('<div id="rc" class="text1"  style="display:block; z-index:1;">');
	htmlString.push('RC:<input  class="text1"  name="txtRC" size="20" type="text" value="14 dígits" id="txtRC"></font>');
      htmlString.push('</div>');
	  htmlString.push('<div id="pp" class="text1"  style="display:none; z-index:1; ">');
	htmlString.push('Pol: <input name="txtPol"  class="text1"  type="text" id="txtPol" value="" size="5" maxlength="5">');
	htmlString.push('Par: <input name="txtPar"  class="text1"  type="text" id="txtPar" value="" size="5">');
      htmlString.push('</div>');
	  htmlString.push('</td></tr>');
  htmlString.push('<tr> <td class="text1" align="right"  colspan="2"><input class="boto"  onClick="idec_cercaCadastre(\'getRCCadastre\',0)"  type="button" value="Cercar" name="cercaCad"></td></tr>');
htmlString.push('</table>');	
	}else{
	htmlString.push('<table width="98%" border="0" cellspacing="2" cellpadding="0" >');
	if((codiEmail.length < 4)&&(tipusAplicacio==tipus)){
		//cadastre.sort(ordenaComboMunicipis);
		htmlString.push('<tr><td colspan="2"> ');
		htmlString.push('<select class="text1" style="width:100px" onchange="codiMuniCad=this.value" >');
		codiMuniCad=cadastre[0][0];
		htmlString.push('<option selected  value="'+cadastre[0][0]+'">Escull un municipi</option>');
		for(i=0;i < cadastre.length;i++){
			htmlString.push('<option  value="'+cadastre[i][0]+'">'+cadastre[i][1]+'</option>');
		}
		htmlString.push('</select>');
		htmlString.push('</td></tr> ');
	}
	htmlString.push('<tr><td class="text1" width=\"25%\" >Tipus:</td><td>');
	//htmlString.push('<br>'); 
	htmlString.push('<select class="text1" style="width:60px;" onchange="tipusCarrerCadastre=this.value" id="tipusCarrerCar" name="tipusCarrerCar">');
		htmlString.push('<option value="AG">Agregat</option><option value="AL">Aldea</option><option value="AR">Àrea</option><option value="AU">Autopista</option><option value="AV">Avinguda</option><option value="AY">Rierol</option><option value="BJ">Baixada</option><option value="BO">Barri</option><option value="BR">Barranc</option><option value="CA">Canyissar</option>');
htmlString.push('<option value="CG">Col.legi</option><option value="CH">Xalet</option><option value="CI">Cinturó</option><option value="CJ">Carreró</option>');
htmlString.push('<option selected value="CL">Carrer</option><option value="CM">Camí</option><option value="CN">Colònia</option><option value="CO">Consell</option>');
htmlString.push('<option value="CP">Camp</option><option value="CR">Carretera</option><option value="CS">Caseriu</option><option value="CT">Pujada</option>');
htmlString.push('<option value="CU">Conjunt</option><option value="DE">Darrera</option><option value="DP">Diputació</option><option value="DS">Disseminats</option>');
htmlString.push('<option value="ED">Edificis</option><option value="EM">Extramurs</option><option value="EN">Entrada</option><option value="ER">Extraradi</option>');
htmlString.push('<option value="ES">Escala</option><option value="EX">Explanada</option><option value="FC">Ferrocarril</option><option value="FN">Finca</option>');
htmlString.push('<option value="GL">Glorieta</option><option value="GR">Grup</option><option value="GV">Gran Via</option><option value="HT">Hort</option>');
htmlString.push('<option value="JR">Jardins</option><option value="LD">Vessant</option><option value="LG">Lloc</option><option value="MC">Mercat</option>');
htmlString.push('<option value="ML">Moll</option><option value="MN">Municipi</option><option value="MS">Masia</option><option value="MT">Muntanya</option>');
htmlString.push('<option value="MZ">Illa</option><option value="PB">Poblat</option><option value="PD">Partida</option><option value="PJ">Passatge</option>');
htmlString.push('<option value="PL">Polígon</option><option value="PQ">Parc</option><option value="PR">Prolongació</option><option value="PS">Passeig</option>');
htmlString.push('<option value="PT">Pont</option><option value="PZ">Plaça</option><option value="QT">Quintar</option><option value="RB">Rambla</option>');
htmlString.push('<option value="RC">Racó</option><option value="RD">Ronda</option><option value="RM">Ramal</option><option value="RP">Rampa</option>');
htmlString.push('<option value="RR">Riera</option><option value="RU">Rua</option><option value="SA">Sortida</option><option value="SD">Senda</option>');
htmlString.push('<option value="SL">Solar</option><option value="SN">Saló</option><option value="SU">Pujada</option><option value="TN">Terrenys</option>');
htmlString.push('<option value="TO">Torrent</option><option value="TR">Travessera</option><option value="UR">Urbanització</option><option value="VR">Sendera</option>');

    htmlString.push('</select>');
    htmlString.push('<img class="boto" onClick="idec_cercaCadastre(\'getCarrersCadastre\',0)" onmouseover="Tip(\'Obtenir llistat de carrers segons cadastre\')" src="/ideLocal/visual/images/cerca.gif"  align="absmiddle"></td></tr><tr>'); 
    htmlString.push('<td class="text1" width=\"25%\" >Carrer:</td><td>');
    htmlString.push('<input class="text1" id="nomCarrerCadastre" size="18"  name="nomCarrerCadastre">'); 
	htmlString.push('</td>');
    htmlString.push('</td></tr><tr>'); 
    htmlString.push('<td class="text1" width=\"25%\" >N&uacute;mero:</td><td>');
    //htmlString.push('<br>'); 
    htmlString.push('<input class="text1" id="numCarrerCad2" size="4"  name="numCarrerCad2">');
    htmlString.push('&nbsp;&nbsp;<input class="boto"  onClick="idec_cercaCadastre(\'getAdrecaCadastre\',0)"  type="button" value="Cercar" name="cerca">');
	htmlString.push("</td></tr>");
	htmlString.push( "</table>");
	}
	return htmlString.join(' ');
}
function idec_escriuCerques_Urbanisme(tipus,posLeft){
	var htmlString=new Array();
	htmlString.push('<table width="98%" border="0" cellspacing="2" cellpadding="0" >');
	if((codiMun.length < 4)&&(tipusAplicacio==tipus)){
		//comarca.sort(ordenaComboMunicipis);
		htmlString.push('<tr><td colspan="2"> ');
		htmlString.push('<select class="text1" style="width:100px" onchange="canviaMunicipi(this)" >');
		codiMun=comarca[0][0];
		htmlString.push('<option selected  value="'+comarca[0][0]+'">Escull un municipi</option>');
		for(i=0;i < comarca.length;i++){
			htmlString.push('<option  value="'+comarca[i][0]+'">'+comarca[i][1]+'</option>');
		}
		htmlString.push('</select>');
		htmlString.push('</td></tr> ');
	}
	htmlString.push('<tr><td class="text1" width=\"25%\" >Tipus:</td><td class="text1" >');
	//htmlString.push('<br>'); 
	htmlString.push('<select class="text1" style="width:60px;" id="tipusCarrer" name="tipusCarrer">');
		htmlString.push('<option value="c.">Altres...</option>');
	    htmlString.push('<option value="av.">Avinguda</option>');
	    htmlString.push('<option value="bda.">Baixada</option>');
	     htmlString.push('<option value="Camí">Camí</option>');
	    htmlString.push('<option value="c." selected>Carrer</option>');
	    htmlString.push('<option value="crta.">Carretera</option>');
	    htmlString.push('<option value="Parc">Parc</option>');
	    htmlString.push('<option value="pg.">Passeig</option>');
	    htmlString.push('<option value="pl.">Plaça</option>');
	     htmlString.push('<option value="plta.">Placeta</option>');
	    htmlString.push('<option value="ptge.">Passatge</option>');
	    htmlString.push('<option value="rbla.">Rambla</option>');
	    htmlString.push('<option value="Ronda">Ronda</option>');
	    htmlString.push('<option value="trv.">Travessera</option>');
	    htmlString.push('<option value="Via">Via</option>');
	    htmlString.push('<option value="Vial">Vial</option>');
    htmlString.push('</select>');
    htmlString.push('<input type="checkbox" id="cru" name="cru" onClick="escriuInterseccio(this.checked,1)">Cruïlla');
    htmlString.push('</td></tr><tr>'); 
    htmlString.push('<td class="text1" width=\"25%\" >Carrer:</td><td>');
   // htmlString.push('<br>'); 
    htmlString.push('<input class="text1" id="nomCarrer" size="18" onkeyDown="idec_capturaTecla(event);" name="nomCarrer">');
    //consulta ajax
    // htmlString.push("<input type=\"text\" style=\"width:130px\" class=\"comboLoca\" id=\"nomCarrerH\"  name=\"nomCarrerH\" autocomplete=\"off\"  onkeyup=\"javascript:autocompletar('divnomCarrer',this.value,6);\" >");
   // htmlString.push("<input type=\"hidden\"  name=\"nomCarrer\" id=\"nomCarrer\" value=\"\" ><br>");
   //htmlString.push("<div class=\"lista\"  id=\"divnomCarrer\"></div>");
    
    htmlString.push('</td></tr><tr>'); 
    htmlString.push('<td class="text1" width=\"25%\" ><div id="1car"> N&uacute;mero:</div></td><td>');
    //htmlString.push('<br>'); 
    htmlString.push('<input class="text1" id="numCarrer" value="" name="numCarrer" size="4" onkeyDown="idec_capturaTecla(event);" >');
    htmlString.push('&nbsp;&nbsp;<input class="boto"  onClick="idec_cercaCarrer()"  type="button" value="Cercar" name="cerca">');
	htmlString.push("</td></tr>");
	htmlString.push( "</table>");
	return htmlString.join(' ');
}

function parseCarrerCadastre(tipus,carrer){
tipusCarrerCadastre=tipus;
nomCarrerCadastre=carrer;	
e('nomCarrerCadastre').value=nomCarrerCadastre;	
var master=e('tipusCarrerCar');
for (i=0; i<master.options.length; i++){
if(master.options[i].value==tipus){master.options[i].selected=true;}
}

}

function ordenaComboMunicipis(a,b){
	return (a[1].toUpperCase() < b[1].toUpperCase()) ? -1 : 1;
}

//tiles 14 sep 2007
var NUMTILE = 1;
var numeroTalls=4;
image = null;
var BBOXT = new Array();
var srvTiles = new Array();
//srvTiles[0] = "shagrat.icc.es";
//srvTiles[1] = "galileo.icc.es";
//srvTiles[2] = "ovc.catastro.meh.es";
srvTiles[0] = "delta.icc.es";
srvTiles[1] = "galileo.icc.es/wms/servlet/icc_limadmin_v_r";
srvTiles[2] = "ovc.catastro.meh.es";

function crearMapa(mapa){
//2 dic 2007
var nombreTitW = 2;
var nombreTitH = 2;
//if(mapa.mapWidthPX >= 800){nombreTit=3;}
	nombreTitW = calculaNumTiles(mapa.mapWidthPX);
	nombreTitH = calculaNumTiles(mapa.mapHeightPX);
	var container = mapa.gid + "_container";
	var h = document.getElementById(container);
	if (h.hasChildNodes()){
		for (var i = 0; i < h.childNodes.length; i++){
			var divT = h.childNodes[i];
			var idDiv = divT.id;
			var nombreDiv = "div_"+mapa.prefix;
			if (idDiv != null){
				if (idDiv.indexOf(nombreDiv) != -1){
					var pos = idDiv.lastIndexOf("_");
					var ind = idDiv.substring(pos+1);
					
					var surl = formaUrl(mapa.layers[parseInt(ind)],ind,mapa);
					 
					if (surl.indexOf(".gif") == -1){
						//crearGrid(idDiv, surl, mapa.cBounds, 4);
						var esta = 0;
						//14 abr 08 servidores con tiles o no
						//alert(mapa.layers[parseInt(ind)].tiles);
						if (mapa.layers[parseInt(ind)].tiles == false || mapa.layers[parseInt(ind)].tiles == "false"){
							esta = 1;
						}
						//ve el arreglo de servidores
						for (var s = 0; s < srvTiles.length; s++){
							var srvTil = srvTiles[s];
							if (surl.indexOf(srvTil) != -1){
								esta = 1;
								break;
							}
						}						
						if (editor){
							crearGrid(idDiv, surl, mapa.cBounds, 1, 1);
						}else{
							if (esta == 1){
								crearGrid(idDiv, surl, mapa.cBounds, 1, 1);
								//crearGrid(idDiv, surl, mapa.cBounds, nombreTitW, nombreTitH);
							}
							else{
								crearGrid(idDiv, surl, mapa.cBounds, nombreTitW, nombreTitH);
								//crearGrid(idDiv, surl, mapa.cBounds, 1, 1);
							}
						}
					}
				}
			}
		}
	}
}

//26 feb 08
function zoomMapa(mapa, activa){
	if (activa != 1){
		limpiarMapa(mapa);
		crearMapa(mapa);
	}
	else{
		for(i = 0; i < mapa.servidores.length; i++){
			var ncapas = 0;
			var activo = false; 
			var posSrv = mapa.servidores[i][0];
			if (mapa.servidores[i][3] == true || mapa.servidores[i][3]=='true'){
				activo = true;
			}
			for(j = i+1; j < mapa.servidores.length; j++){
				var posSrv1 = mapa.servidores[j][0];
				if (posSrv == posSrv1){
					ncapas++;
					if (mapa.servidores[j][3] == true || mapa.servidores[j][3]=='true'){
						activo = true;
					}
				}else{
					break;
				}
			}
			if (activo){
				var posCapa = mapa.servidores[i][0];
				var nombreDiv = "div_"+mapa.prefix+posCapa;
				var capa = document.getElementById(nombreDiv);
				//limpiarCapa(capa);
				var ind = posCapa;
				var idDiv = nombreDiv;
				var nombreTitW = calculaNumTiles(mapa.mapWidthPX);
				var nombreTitH = calculaNumTiles(mapa.mapHeightPX);
				var surl = formaUrl(mapa.layers[parseInt(ind)],ind,mapa);
				if (capa.hasChildNodes()){
					var divT = capa.childNodes[0];
					if (divT.style.backgroundImage.indexOf(surl) != -1){
					
					}else{
						limpiarCapa(capa);
						if (surl.indexOf(".gif") == -1){
							//crearGrid(idDiv, surl, mapa.cBounds, 4);
							var esta = 0;
							//14 abr 08 servidores con tiles o no
							//alert(mapa.layers[parseInt(ind)].tiles);
							if (mapa.layers[parseInt(ind)].tiles == false || mapa.layers[parseInt(ind)].tiles == "false"){
								esta = 1;
							}
							for (var s = 0; s < srvTiles.length; s++){
								var srvTil = srvTiles[s];
								if (surl.indexOf(srvTil) != -1){
									esta = 1;
									break;
								}
							}
							if (editor){
								crearGrid(idDiv, surl, mapa.cBounds, 1, 1);
							}else{
								if (esta == 1){
									crearGrid(idDiv, surl, mapa.cBounds, 1, 1);
									//crearGrid(idDiv, surl, mapa.cBounds, nombreTitW, nombreTitH);
								}
								else{
									crearGrid(idDiv, surl, mapa.cBounds, nombreTitW, nombreTitH);
									//crearGrid(idDiv, surl, mapa.cBounds, 1, 1);
								}
							}
						}
					}
				}else{ 
					if (surl.indexOf(".gif") == -1){
						//crearGrid(idDiv, surl, mapa.cBounds, 4);
						var esta = 0;
						//14 abr 08 servidores con tiles o no
						//alert(mapa.layers[parseInt(ind)].tiles);
						if (mapa.layers[parseInt(ind)].tiles == false || mapa.layers[parseInt(ind)].tiles == "false"){
							esta = 1;
						}
						for (var s = 0; s < srvTiles.length; s++){
							var srvTil = srvTiles[s];
							if (surl.indexOf(srvTil) != -1){
								esta = 1;
								break;
							}
						}
						if (editor){
							crearGrid(idDiv, surl, mapa.cBounds, 1, 1);
						}else{
							if (esta == 1){
								crearGrid(idDiv, surl, mapa.cBounds, 1, 1);
								//crearGrid(idDiv, surl, mapa.cBounds, nombreTitW, nombreTitH);
							}
							else{
								crearGrid(idDiv, surl, mapa.cBounds, nombreTitW, nombreTitH);
								//crearGrid(idDiv, surl, mapa.cBounds, 1, 1);
							}
						}
					}
				}
			}else{
				var posCapa = mapa.servidores[i][0];
				var nombreDiv = "div_"+mapa.prefix+posCapa;
				var capa = document.getElementById(nombreDiv);
				limpiarCapa(capa);
			}
			i = i + ncapas;		
			//alert(posSrv + " CAPAS: " + ncapas);
		}
	}
}

function limpiarMapa(mapa){
	var container = mapa.gid + "_container";
	var h = document.getElementById(container);
	if (h.hasChildNodes()){
		//alert(h.childNodes.length);
		for (var i = 0; i < h.childNodes.length; i++){
			var divT = h.childNodes[i];
			//alert(divT.innerHTML);
			var idDiv = divT.id;
			if (idDiv != null){
				var nombreDiv = "div_"+mapa.prefix;
				//alert(idDiv);
				if (idDiv.indexOf(nombreDiv) != -1){
					limpiarCapa(divT);
				}
			}
		}
	}
}

function limpiarCapa(capa){
	if (capa.hasChildNodes()){
		while(capa.hasChildNodes()){
			capa.removeChild(capa.firstChild);
		}
	}
}

function crearGrid(div, url, bbox, tilesNumW, tilesNumH){
	//alert(url);
	//var im = document.createElement("img");
	//alert(div);
	var h = document.getElementById(div);
  	//while (h.firstChild)
    //h.removeChild(h.firstChild);
  	//h.appendChild(im);
	agregarTiles(h, url, bbox, tilesNumW, tilesNumH);
}

var mainEPSG = "EPSG:23031";

function agregarTiles(div, url, bbox, tilesNumW, tilesNumH){
	var NUMTILEW = parseInt(tilesNumW);
	var NUMTILEH = parseInt(tilesNumH);
	var NUMTILE = NUMTILEW;
	var width;
	var height;
	var tileWidth;
	var tileHeight;
	width = parseInt(div.style.width); // or naturalWidth, or computed width...
	height = parseInt(div.style.height);
	// Allow bottom/right of image to be cut off. better than introducing Obvious White Pixels and 
	// giving away where the edge is.
	//3 dic 2007 fijo el tamaño del tile
	//tileWidth = parseInt(width/NUMTILE);
	//tileHeight = parseInt(height/NUMTILE);
	if (NUMTILEW == 1){
		//14 feb 08
		tileWidth = width;
		tileHeight = height;
		
		if (width > height){
			tileWidth = width;
			tileHeight = width;
		}else{
			tileWidth = height;
			tileHeight = height;
		}
		
		//mapa.mapWidthPX;
		//mapa.mapHeightPX;
		//tileWidth = 1024;
		//tileHeight = 768;
		//width = 1024;
		//height = 768;
		//div.style.width = 1024;
		//div.style.height = 768;
		//alert(tileWidth + "  " + tileHeight);
	}else{
		tileWidth = 256;
		tileHeight = 256;
	}
		
	var urlT = url+"WIDTH="+tileWidth+"&HEIGHT="+tileHeight+"&BBOX=";
	//alert(urlT);
	var tiles = new Array;
	var grid = new Array;
	for (var g=0; g<NUMTILEW; g++){
		tiles[g] = [];
		grid[g] = [];
	}
	
	var theEmptyT, emptyp, emptyq;
	for (var i=0; i<NUMTILEW; ++i)
	 for (var j=0; j<NUMTILEH; ++j)
	 {
	  var t = document.createElement("div");
	  var x = i * tileWidth;
	  var y = j * tileHeight;
	  t.style.position = "absolute";
	  t.style.width = tileWidth + "px";
	  t.style.height = tileHeight + "px";
	if (NUMTILEW == 1){
		//14 feb 08
		/*
		BBOXT[0] = bbox[0];
		BBOXT[1] = bbox[1];
		BBOXT[2] = bbox[2];
		BBOXT[3] = bbox[3];
		*/
		
		var dx = bbox[2] - bbox[0];
		var dy = bbox[3] - bbox[1];
		var pixelsW = dx / width;
		var intx = pixelsW * tileWidth;
		var inty = intx;
		//alert(intx + "  " + inty);
		BBOXT[0] = bbox[0] + (intx*i);
		BBOXT[1] = bbox[3] - (inty*(j+1));
		BBOXT[2] = bbox[0] + (intx*(i+1));
		BBOXT[3] = bbox[3] - (inty*j);
		
	}else{
		var dx = bbox[2] - bbox[0];
		var dy = bbox[3] - bbox[1];
		//3 dic 2007
		//var intx = dx/NUMTILE;
		//var inty = dy/NUMTILE;
		var pixelsW = dx / width;
		var intx = pixelsW * tileWidth;
		var inty = intx;
		//alert(intx + "  " + inty);
		BBOXT[0] = bbox[0] + (intx*i);
		BBOXT[1] = bbox[3] - (inty*(j+1));
		BBOXT[2] = bbox[0] + (intx*(i+1));
		BBOXT[3] = bbox[3] - (inty*j);
	}	
			
	//30 Octubre 2007 reprojecció
	if(urlT.indexOf(mainEPSG)==-1){
		pos1=urlT.indexOf("EPSG:");
		srt1=urlT.substring(pos1,urlT.length);
		pos2=srt1.indexOf("&");
		srt2=srt1.substring(0,pos2);		
		 var req="/idecwebservices/ideunivers/TransCoordenades.jsp?metode=getTranformEPSGBBOX&inEpsg="+mainEPSG+"&outEpsg="+srt2+"&coordX0="+BBOXT[0]+"&coordY0="+BBOXT[1]+"&coordX1="+BBOXT[2]+"&coordY1="+BBOXT[3]+"&";
		 var newBBOX=ajaxCoord(req);
		BBOXT[0] = coordTemp[0];
		BBOXT[1] = coordTemp[1];
		BBOXT[2] = coordTemp[2];
		BBOXT[3] = coordTemp[3];
   
	}
		
		
		
	  var urlTT = urlT + BBOXT;
	  t.style.backgroundImage = "url(" + urlTT + ")";
	  t.style.backgroundAttachment = "scroll";
	  //t.style.backgroundPosition = "-" + x + "px -" + y + "px";
	  t.style.backgroundRepeat = "no-repeat";
	  // setting using shorthand works in ie but not in moz:
	  // t.style.background = "url(" + im.src + ") scroll -" + x + " -" + y + " no-repeat";
	  //t.className = "tile";
	   // i,j is original position. used to determine when you've won.
	  t.i = i;
	  t.j = j;
	  // p,q is current position. initially set by repositionAll();
	  grid[i][j] = t;
	  div.appendChild(t);
	 } // huge for loop to create tiles

	function gradual(ob, prop, start, fin)
	{
		var n = NUMTILE;
		var step = (fin - start) / n;
		ob[prop] = start;
		for (var i=1; i<=n; ++i)
			(function(){
				var I = i;
				setTimeout(function() { ob[prop] = (start + step*I) + "px"; }, 30*i)
			})()
	}

	function repositionAll()
	{
	  var correct = 0, i, j;
	  for (i=0; i<NUMTILEW; ++i)
	   for (j=0; j<NUMTILEH; ++j)
	   {
	     t = grid[i][j];
	     if (t.p != i)
	     {
	       if (t.p != null && !t.isEmpty)
	         gradual(t.style, "left", tileWidth * t.p, tileWidth * i)
	       else
	         t.style.left = tileWidth * i + "px";
	       t.p = i;
	     }
	     if (t.q != j)
	     {
	       if (t.q != null && !t.isEmpty)
	         gradual(t.style, "top", tileHeight * t.q, tileHeight * j)
	       else  
	         t.style.top = tileHeight * j + "px";
	       t.q = j;
	     }
	     if (t.isEmpty)
	     {
	       emptyp = i;
	       emptyq = j;
	     }
	     if (t.i == i && t.j == j)
	       ++correct;
	   }
	   //game.style.borderColor = (correct == (NUMTILE*NUMTILE)) ? "lightgreen" : "black";
	}
	repositionAll();
	//var par = div.parentNode;
	//par.insertBefore(game, div);
	//par.removeChild(div);
}

function formaUrl(aLayer,k, mapa) {
	//alert(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<mapa.servidores.length; i++) {
	if (mapa.servidores[i][0] == k) {
		if (mapa.servidores[i][3] == true){
	  		if (nom == ""){
		  		nom = mapa.servidores[i][1];
		  	}
		  	else{
		  		nom = nom + "," + mapa.servidores[i][1];
		  	}
	  	}	
	}
  }
  if (nom != "") {
  	//03 mar 08	
  	nom = nom.replace(/ /g, "%20");
  	//if(sURL.indexOf('?')!=-1){sURL += "REQUEST=GetMap";}else{sURL += "?REQUEST=GetMap";}
  		
  		if(sURL.indexOf('com.esri')!=-1){sURL=sURL.replace('esrimap','Esrimap');sURL += "&REASPECT=false&";}
  
	sURL += "REQUEST=GetMap"; 
	sURL += "&SRS=" + aLayer.epsg;
	sURL += "&VERSION=" + aLayer.version;
	sURL += "&STYLES=";
	if (aLayer.transparent == true){
		sURL += "&TRANSPARENT=true";
	}
	else{
		sURL += "&TRANSPARENT=false";
	}
	sURL += "&LAYERS=" + nom;
	//14 nov estaba comentado pero no se ve el del ING
	if (sURL.indexOf("shagrat.icc.es") != -1){
		sURL += ",&BGCOLOR=0xFFFFFF";
	}
	else{
		sURL += "&BGCOLOR=0xFFFFFF";
	}
   sURL += "&FORMAT=" + aLayer.format;
   sURL += "&";
   return sURL;
  }
  else { 
	sURL = mapa.baseDir + "blanco.gif";
	return sURL;
  }
}

//2 dic 2007
function calculaNumTiles(ancho){
	var numT = 0;
	ancho = parseInt(ancho);
	var num = ancho / 256;
	numT = Math.ceil(num);
	return numT;
}
