﻿var map;
var map2;
var precarga = 0;
if (typeof (DESIGN_TIME) == 'undefined') {
    map = null;
}

else {
    map = new VEMap();
}

// Carrega el mapa cada cop que la pàgina es carrega
function GetMap() {
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx" || location.pathname=="/Default.aspx") {
        //ACS 02-05-2011
        var latitud = $get("ctl00_ContentPlaceHolder1_lbl_latitudCiutat").innerText;
        var longitud = $get("ctl00_ContentPlaceHolder1_lbl_longitudCiutat").innerText;
        var zoom = 1;
        //Si no troba cap latitud carrega el mapa mundi per defecte.
        if (latitud == "") {
            latitud = 41.38658;
            longitud = 2.169426;
            map = new VEMap('myMap');
            map.LoadMap(new VELatLong(parseFloat(latitud), parseFloat(longitud)), zoom, VEMapStyle.Road, false);
            map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
            map.ShowDisambiguationDialog(false);
        }
        //Si troba latitud carrega el mapa que toqui i fa la cerca.
        else 
        {
            zoom = 13;
            map = new VEMap('myMap');
            map.LoadMap(new VELatLong(parseFloat(latitud), parseFloat(longitud)), zoom, VEMapStyle.Road, false);
            map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
            map.ShowDisambiguationDialog(false);
            BuscaWhatWhere();
            vistaCerca();
        }
    }
}

function GetMap2() {
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx") {
        var latitud = $get("ctl00_ContentPlaceHolder1_lbl_latitudCiutat").innerText;
        var longitud;
        if (latitud == undefined) {
            latitud = 41.38658;
            longitud = 2.169426;
        }
        else {
            longitud = $get("ctl00_ContentPlaceHolder1_lbl_longitudCiutat").innerText;
        }
        if (document.getElementById('mymap2')) {
            map = new VEMap('mymap2');
            map.LoadMap(new VELatLong(parseFloat(latitud), parseFloat(longitud)), 13, VEMapStyle.Road, false);
            map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
            map.ShowDisambiguationDialog(false);
            map.AttachEvent('onclick', clickevent);
        }
    }
}

function clickevent(e) {
    map.Clear();
    var x = e.mapX;
    var y = e.mapY;
    pixel = new VEPixel(x, y);
    shp = new VEShape(VEShapeType.Pushpin, map.PixelToLatLong(pixel));
    shp.SetTitle($get("ctl00_ContentPlaceHolder1_NomLocalitzacio").value);
    shp.SetDescription($get("ctl00_ContentPlaceHolder1_Adresa").value);
    shp.SetCustomIcon("<div class='pinStyle2'></div>");
    map.AddShape(shp);
    postback(map.PixelToLatLong(pixel).Latitude, map.PixelToLatLong(pixel).Longitude);

}

function buscai() {
    map.Clear();
    var ciutat = $get("ctl00_ContentPlaceHolder1_lbl_nomCiutat").innerText;
    var adresa = $get("ctl00_ContentPlaceHolder1_Adresa").value + ", "+ciutat+", "+ciutat;
    map.Find(null, adresa, null, null, null, null, null, null, null, null, ipinta);
}

function ipinta() {
    shp = new VEShape(VEShapeType.Pushpin, map.GetCenter());
    shp.SetTitle($get("ctl00_ContentPlaceHolder1_NomLocalitzacio").value);
    shp.SetDescription($get("ctl00_ContentPlaceHolder1_Adresa").value);
    shp.SetCustomIcon("<div class='pinStyle2'></div>");
    map.AddShape(shp);
    postback(map.GetCenter().Latitude, map.GetCenter().Longitude);
}

//Joan 12-02-2010
function vistaCerca() {
var ciutat = $get("ctl00_ContentPlaceHolder1_lbl_nomCiutat").innerText;
if (!(ciutat == "" || ciutat == null)) {
    var result, map, main;
    var Vresult, Vmap, Vmain;

    if (document.getElementById) { // this is the way the standards work
        result = document.getElementById('SearchResult');
        map = document.getElementById('myMap');
        main = document.getElementById('mainContent');
    }
    else if (document.all) { // this is the way old msie versions work
        result = document.all['SearchResult'];
        map = document.all['myMap'];
        main = document.all['mainContent'];
    }
    else if (document.layers) { // this is the way nn4 works
        result = document.layers['SearchResult'];
        map = document.layers['myMap'];
        main = document.layer['mainContent'];
    }

    Vresult = result.style;
    Vmap = map.style;
    Vmain = main.style;

    Vresult.display = 'block';
    Vmap.display = 'block';
    Vmain.display = 'none';
}
	
}

//Joan 12-02-2010
function vistaCanviCerca() {
	var cercaSim, cercaAdv;
	var VcercaSim, VcercaAdv;
	
	if (document.getElementById) { // this is the way the standards work
	    cercaSim = document.getElementById('ctl00_ContentPlaceHolder1_cercalitle');
        cercaAdv = document.getElementById('ctl00_ContentPlaceHolder1_oculto');
    }
    else if (document.all) { // this is the way old msie versions work
        cercaSim = document.all['ctl00_ContentPlaceHolder1_cercalitle'];
        cercaAdv = document.all['ctl00_ContentPlaceHolder1_oculto'];
    }
    else if (document.layers) { // this is the way nn4 works
        cercaSim = document.layers['ctl00_ContentPlaceHolder1_cercalitle'];
        cercaAdv = document.layers['ctl00_ContentPlaceHolder1_oculto'];
    }
	
	VcercaSim = cercaSim.style;
	VcercaAdv = cercaAdv.style;
	
	if (VcercaSim.display == '' && cercaSim.offsetWidth != undefined && cercaSim.offsetHeight != undefined)
            VcercaSim.display = (cercaSim.offsetWidth != 0 && cercaSim.offsetHeight != 0) ? 'block' : 'none';
        VcercaSim.display = (VcercaSim.display == '' || VcercaSim.display == 'block') ? 'none' : 'block';
        
	if (VcercaAdv.display == '' && cercaAdv.offsetWidth != undefined && cercaAdv.offsetHeight != undefined)
            VcercaAdv.display = (cercaAdv.offsetWidth != 0 && cercaAdv.offsetHeight != 0) ? 'block' : 'none';
	VcercaAdv.display = (VcercaAdv.display == '' || VcercaAdv.display == 'block') ? 'none' : 'block';


//	if (document.getElementById("ctl00_ContentPlaceHolder1_lbl_busquedaActiva").value == "true") {
//	    VcercaAdv.display = 'block';
//	}
//	else {
//	    VcercaSim.display = 'block';
//	}
	if (VcercaAdv.display == 'block') {
	    document.getElementById("ctl00_ContentPlaceHolder1_lbl_busquedaActiva").value = "true";
	}
	else {
	    document.getElementById("ctl00_ContentPlaceHolder1_lbl_busquedaActiva").value = "false";
	}
}

//Joan 12-02-2010
//torna a la vista inicial de la web
function backMain(){
    var result, map, main, cercaSim, cercaAdv;
	var Vresult, Vmap, Vmain, VcercaSim, VcercaAdv;
    
    if (document.getElementById) { // this is the way the standards work
        result = document.getElementById('SearchResult');
        map = document.getElementById('myMap');
		main = document.getElementById('mainContent');
		cercaSim = document.getElementById('ctl00_ContentPlaceHolder1_cercalitle');
		cercaAdv = document.getElementById('ctl00_ContentPlaceHolder1_oculto');
    }
    else if (document.all) { // this is the way old msie versions work
        result = document.all['SearchResult'];
        map = document.all['myMap'];
        main = document.all['mainContent'];
        cercaSim = document.all['ctl00_ContentPlaceHolder1_cercalitle'];
        cercaAdv = document.all['ctl00_ContentPlaceHolder1_oculto'];
    }
    else if (document.layers) { // this is the way nn4 works
        result = document.layers['SearchResult'];
        map = document.layers['myMap'];
        main = document.layer['mainContent'];
        cercaSim = document.layers['ctl00_ContentPlaceHolder1_cercalitle'];
        cercaAdv = document.layers['ctl00_ContentPlaceHolder1_oculto'];
    }
    
     
    VcercaSim = cercaSim.style;
	VcercaAdv = cercaAdv.style;    
    Vresult = result.style;
	Vmap = map.style;
	Vmain = main.style;
	
	Vresult.display = 'none';
	//Vmap.display = 'none';	
	Vmain.display = 'block';
	VcercaAdv.display = 'none';
	VcercaSim.display = 'block';
}

////Joan 15-02-2010
//function outResult(){
//    var result;
//	var Vresult;
//    
//    if (document.getElementById) { // this is the way the standards work
//        result = document.getElementById('allResults');
//    }
//    else if (document.all) { // this is the way old msie versions work
//        result = document.all['allResults'];
//    }
//    else if (document.layers) { // this is the way nn4 works
//        result = document.layers['allResults'];
//    }
//        
//    Vresult = result.style;
//	
//	Vresult.display = 'none';	
//}

////Joan 15-02-2010
//function returnResult(){
//    var result;
//	var Vresult;
//    
//    if (document.getElementById) { // this is the way the standards work
//        result = document.getElementById('allResults');
//    }
//    else if (document.all) { // this is the way old msie versions work
//        result = document.all['allResults'];
//    }
//    else if (document.layers) { // this is the way nn4 works
//        result = document.layers['allResults'];
//    }
//        
//    Vresult = result.style;
//	
//	Vresult.display = 'block';
//}


// oculta o muestra whichLayer y Whatlayer en funcion de su estado actual  
//***************************************************************************************** 
// Modificat per en Joan, 10-02-2010 --> S'ha afegit el No mostrar els resultats de cerca
//*****************************************************************************************
function toggleLayer(whichLayer, whatlayer) {
    var elem, vis, elem2, elem3, vis3, vis2;
    //JD
    var elem4, vis4;
    if (document.getElementById) { // this is the way the standards work
        elem = document.getElementById(whichLayer);
        elem2 = document.getElementById(whatlayer);
        //elem3 = document.getElementById('text');
        //JD
        elem4 = document.getElementById('SearchResult');
    }
    else if (document.all) { // this is the way old msie versions work
        elem = document.all[whichLayer];
        elem2 = document.all[whatlayer];
        //elem3 = document.all['text'];
        //JD
        elem4 = document.all['SearchResult'];
    }
    else if (document.layers) { // this is the way nn4 works
        elem = document.layers[whichLayer];
        elem2 = document.layers[whatlayer];
        //elem3 = document.layers['text'];
        //JD
        elem4 = document.layer['SearchResult'];
    }
    vis = elem.style;
    vis2 = elem2.style;
    //vis3 = elem3.style;
    vis4 = elem4.style;
    
    //JD    
    if (vis4.display == '' || vis4.display == 'block'){                
        
        if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
            vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
        vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
        
        if (vis2.display == '' && elem2.offsetWidth != undefined && elem2.offsetHeight != undefined)
                    vis2.display = (elem2.offsetWidth != 0 && elem2.offsetHeight != 0) ? 'block' : 'none';
                vis2.display = (vis2.display == '' || vis2.display == 'block') ? 'none' : 'block';
                
        //vis3.display = 'none';
        
        vis4.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
        
    
    }else{   //JD
        
        // if the style.display value is blank we try to figure it out here
        if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)
            vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
        vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';

        if (vis2.display == '' && elem2.offsetWidth != undefined && elem2.offsetHeight != undefined)
            vis2.display = (elem2.offsetWidth != 0 && elem2.offsetHeight != 0) ? 'block' : 'none';
        vis2.display = (vis2.display == '' || vis2.display == 'block') ? 'none' : 'block';

        if (vis4.visibility == '' || vis4.visibility =='hidden'){   //JD
        
            if (vis3.display == '' && elem3.offsetWidth != undefined && elem3.offsetHeight != undefined)
                vis3.display = (elem3.offsetWidth != 0 && elem3.offsetHeight != 0) ? 'block' : 'none';
            vis3.display = (vis3.display == '' || vis3.display == 'block') ? 'none' : 'block';
            
            //JD
            vis4.display = 'none';
        
        }else{  //JD
            //vis3.display = 'none';
            vis4.display = 'block';
            vis.visibility = 'visible';
        }
                
    }       
}

//Joan 10-02-2010
function toggleLayer_Close(){
    var vis, vis2, vis3, vis4;
    var simple, advance, textIni, results;
    
    if (document.getElementById) { // this is the way the standards work
        simple = document.getElementById('cercalitle');
        advance = document.getElementById('oculto');
        //textIni = document.getElementById('text');
        results = document.getElementById('SearchResult');
    }
    else if (document.all) { // this is the way old msie versions work
        simple = document.all['cercalitle'];
        advance = document.all['oculto'];
        //textIni = document.all['text'];
        results = document.all['SearchResult'];
    }
    else if (document.layers) { // this is the way nn4 works
        simple = document.layers['cercalitle'];
        advance = document.layers['oculto'];
        //textIni = document.layers['text'];
        results = document.layer['SearchResult'];
    }
    
    vis = simple.style;
    vis2 = advance.style;
    //vis3 = textIni.style;
    vis4 = results.style;
    
    vis.display = 'block';
    vis2.display = 'none';
    //vis3.display = 'block';
    vis4.display = 'none';
    vis4.visibility = 'hidden';
}

//Joan 10-02-2010
function toggleLayer_Search(displayLayer, noDispLayer_1, noDispLayer_2){
    var elem, vis, elem2, elem3, vis3, vis2;
       
    //****************************
    noDispLayer_2 = noDispLayer_1;
    //****************************       
       
    if (document.getElementById) { // this is the way the standards work
        elem = document.getElementById(displayLayer);
        elem2 = document.getElementById(noDispLayer_1);
        elem3 = document.getElementById(noDispLayer_2);
    }
    else if (document.all) { // this is the way old msie versions work
        elem = document.all[displayLayer];
        elem2 = document.all[noDispLayer_1];
        elem3 = document.all[noDispLayer_2];
    }
    else if (document.layers) { // this is the way nn4 works
        elem = document.layers[displayLayer];
        elem2 = document.layers[noDispLayer_1];
        elem3 = document.layers[noDispLayer_2];
    }
    vis = elem.style;
    vis2 = elem2.style;
    vis3 = elem3.style;
    
    vis.display = 'block';
    vis.visibility = 'visible';
        
    vis2.display = 'none';
  
    vis3.display = 'none';
}

// Crida que permet posar dins el select totes les poblacions
function SetPoblacionsInSelect() {
    UIMapaTeletreball.MapaTeletreballService.GetPoblacions(SetPoblacions);
}

// Crida que col·loca dins un element PoblacionsSelect els resultats de la funcio
// SetPoblacionsInSelect
function SetPoblacions(Poblacions) {
    var selState = $get("PoblacionsSelect");
    selState.length = 0;
    for (var x = 0; x < Poblacions.length; x++) {
        var elOptNew = document.createElement('option');
        elOptNew.text = Poblacions[x].NomPoblacio;
        elOptNew.value = Poblacions[x].NomPoblacio;
        var elSel = document.getElementById('selectX');

        try {
            selState.add(elOptNew, null); // standards compliant; doesn't work in IE
        }
        catch (ex) {
            selState.add(elOptNew); // IE only
        }
    }
}

// Funcio que gestiona la crida buscar localitzacions properes
// Busca el lloc desitjat i delega la funcio a la funcio processafindpropera
function BuscaProperes() {
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx") {
        var ciutat = $get("ctl00_ContentPlaceHolder1_lbl_nomCiutat").innerText;
        // Adreça i poblacio introduida per l'usuari
        var poblacio = $get("PoblacionsSelect").selectedIndex;
        var where = $get("Adresa").value + "," + $get("PoblacionsSelect").options[poblacio].text + ", " + ciutat;
        map.Find(null, where, null, null, null, null, null, null, null, null, GetProperes);
    }
}

function MostraFavorits() {
    map.Clear();
    UIMapaTeletreball.MapaTeletreballService.getlocalitzacionsMesValorades(PintaLocalitzacionsProperes);
    
    //Joan 11-02-2010
    toggleLayer_Search('SearchResult', 'oculto', 'text');
    
    postabackfavorits();
}

function MostraUltimes() {
    map.Clear();
    UIMapaTeletreball.MapaTeletreballService.getUltimeslocalitzacions(PintaLocalitzacionsProperes);
    
    //Joan 11-02-2010
    toggleLayer_Search('SearchResult', 'oculto', 'text');
    
    postbackultimes();
}

function BuscaWhatWhere() {
    //debugger;
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx") {
        //poblacio introduida per l'usuari
        var ciutat = $get("ctl00_ContentPlaceHolder1_lbl_nomCiutat").innerText;
        if (!(ciutat == "" || ciutat == null)) {
            map.Clear();
            var aux = $get("ctl00_ContentPlaceHolder1_where").value;
            var where = "";
            if (aux.indexOf("Indica") == -1) {
                where = aux + ", " + ciutat + "," + ciutat;
            }
            else 
            {
                where = ", " + ciutat + "," + ciutat;
            }

            map.Find(null, where, null, null, null, null, null, null, null, null, GetWhatWhereCrida);
        }
    }
}

function BuscaWhatWhereAvanzada() {
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx") {
        var ciutat = $get("ctl00_ContentPlaceHolder1_lbl_nomCiutat").innerText;
        if (!(ciutat == "" || ciutat == null)) {
            // Adreça i poblacio introduida per l'usuari
            map.Clear();
            var aux = $get("ctl00_ContentPlaceHolder1_where2").value;
            if (aux.indexOf("Indica") == -1) {
                where = aux + ", " + ciutat + "," + ciutat;
            }
            else {
                where = ", " + ciutat + "," + ciutat;
            }
            map.Find(null, where, null, null, null, null, null, null, null, null, GetWhatWhereCrida2);
        }
    }
}

function CridaParaula(paraula) {
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx") {
        map.Clear();
        document.getElementById("ctl00_ContentPlaceHolder1_what").value = paraula;
        var centre = map.GetCenter();
        UIMapaTeletreball.MapaTeletreballService.Cerca(paraula, -1, -1, PintaLocalitzacionsProperes);

        //Joan 11-02-2010
        toggleLayer_Search('SearchResult', 'oculto', 'text');

        postabackparaula(paraula);
    }
}

function MostraRuta(idruta) {
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx") {
        map.Clear();
        UIMapaTeletreball.MapaTeletreballService.GetLocalitzacionsARuta(idruta, PintaLocalitzacionsProperes);

        //Joan 11-02-2010
        toggleLayer_Search('SearchResult', 'oculto', 'text');

        postbackruta(idruta);
    }
}



// Funcio que obte les localitzacions properes del servei svc
// El where no se usa para nada, hay que implementar consulta.
function GetWhatWhereCrida() {
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx") {
        var centre = map.GetCenter();
        var nomlloc = $get("ctl00_ContentPlaceHolder1_what").value;
        var radio = $get("ctl00_ContentPlaceHolder1_ddl_radioBusqueda").value;
        if (nomlloc == indicanom) { nomlloc = null; }
        //var latitud = centre.Latitude;
        //var longitud = centre.Longitude;
        //if (direccio == indicaadr) { latitud = -1; longitud = -1; }
        postBackHiddenField("ctl00$ContentPlaceHolder1$Button1", centre.Latitude, centre.Longitude);
        UIMapaTeletreball.MapaTeletreballService.Cerca(nomlloc, radio, centre.Latitude, centre.Longitude, PintaLocalitzacionsProperes);
    }
}

function GetWhatWhereCrida2() {
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx") {
        var centre = map.GetCenter();
        var nomlloc = $get("ctl00_ContentPlaceHolder1_what2").value;
        var radio = $get("ctl00_ContentPlaceHolder1_ddl_radioBusqueda2").value;

        var connectivitat = new Array(5);

        //Joan 24-02-2010
        //    if ($get("ctl00_ContentPlaceHolder1_connectivitat1").checked == true) {
        //        connectivitat[0] = 1;
        //    }
        //    
        //    if ($get("ctl00_ContentPlaceHolder1_connectivitat2").checked == true) {
        //        connectivitat[1] = 2;
        //    }
        //    
        //    if ($get("ctl00_ContentPlaceHolder1_connectivitat3").checked == true) {
        //        connectivitat[2] = 3;
        //    }
        if ($get("ctl00_ContentPlaceHolder1_connectivitat1").checked == true) {
            connectivitat[0] = 2;
        }

        if ($get("ctl00_ContentPlaceHolder1_connectivitat2").checked == true) {
            connectivitat[1] = 3;
        }

        if ($get("ctl00_ContentPlaceHolder1_connectivitat3").checked == true) {
            connectivitat[2] = 4;
        }
        //if ($get("ctl00_ContentPlaceHolder1_connectivitat4").checked == true) {
        //    connectivitat[3] = 4;
        //}
        //if ($get("ctl00_ContentPlaceHolder1_connectivitat5").checked == true) {
        //    connectivitat[4] = 5;
        //}

        var tipuslloc = new Array(6);
        if ($get("ctl00_ContentPlaceHolder1_tipuslloc1").checked == true) {
            //tipuslloc[0] = 1;
            tipuslloc[0] = 2;
        }
        if ($get("ctl00_ContentPlaceHolder1_tipuslloc2").checked == true) {
            //tipuslloc[1] = 2;
            tipuslloc[1] = 5;
        }
        if ($get("ctl00_ContentPlaceHolder1_tipuslloc3").checked == true) {
            //tipuslloc[2] = 3;
            tipuslloc[2] = 6;
        }
        if ($get("ctl00_ContentPlaceHolder1_tipuslloc4").checked == true) {
            //tipuslloc[3] = 4;
            tipuslloc[3] = 4;
        }
        if ($get("ctl00_ContentPlaceHolder1_tipuslloc5").checked == true) {
            //tipuslloc[4] = 6;
            tipuslloc[4] = 8;
        }
        if ($get("ctl00_ContentPlaceHolder1_tipuslloc6").checked == true) {
            //tipuslloc[5] = 7;
            tipuslloc[5] = 14;
        }

        if (nomlloc == indicanom) { nomlloc = null; }
        //var latitud = centre.Latitude;
        //var longitud = centre.Longitude;
        //if (direccio == indicaadr) { latitud = -1; longitud = -1; }
        postBackHiddenField2("ctl00$ContentPlaceHolder1$Button9", centre.Latitude, centre.Longitude);
        UIMapaTeletreball.MapaTeletreballService.CercaAvant(nomlloc, radio, centre.Latitude, centre.Longitude, connectivitat, tipuslloc, PintaLocalitzacionsProperes);
    }
}


// Funcio que obte les localitzacions properes del servei svc
function GetProperes() {
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx") {
        var centre = map.GetCenter();
        postBackHiddenField("ctl00$ContentPlaceHolder1$Button1", centre.Latitude, centre.Longitude);
        UIMapaTeletreball.MapaTeletreballService.GetLocalitzacionsProperes(centre.Latitude, centre.Longitude, PintaLocalitzacionsProperes);
    }
}


function PintaLocalitzacionsProperes(locs) {
    if (location.pathname == "/default.aspx" || location.pathname == "/" || location.pathname=="/novalocalitzacio.aspx" || location.pathname=="/Default.aspx") {
        for (var i = 0; i < locs.length; i++) {
            LatLong = new VELatLong(locs[i].Latitud, locs[i].Longitud);
            shp = new VEShape(VEShapeType.Pushpin, LatLong);
            shp.SetTitle(locs[i].NomLocalitzacio);
            shp.SetDescription(locs[i].Adresa + "<br/>" + "<a href=\"javascript:postabackdetalls(" +
                locs[i].IDLocalitzacio + ")\">" + veuredetalls + "</a>");
            var k = (i + 1);
            var img = "../imatgesTercer/" + locs[i].Imatge;
            //background:url('../Images/pin100.png') no-repeat 0 0; 
            shp.SetCustomIcon("<div class='pinStyle1' style='background : url("+img+") no-repeat 0 0;' ><div class='text'>" + k + "</div></div>");
            map.AddShape(shp);
        }
        var centre = map.GetCenter();
        map.ShowAllShapeLayers();
    }
}


//// Funcio que a partir del tipus de localitzacio indica quina es la icona
//function TriaImatge(tipus)
//{
//    var biblioteca = "images/T.png";
//    var restaurant = "images/restaurante.png";
//    var banc = "images/banc.png";
//    var arbre = "images/arbol.png";
//    var bar = "images/bar.png";
//    var estandar = "images/pin100.png";

//    if (tipus == 1) return estandar;
//    if (tipus == 2) return estandar;
//    if (tipus == 3) return estandar;
//    if (tipus == 4) return estandar;
//    if (tipus == 6) return estandar;
//    if (tipus == 7) return estandar;
//    else return "";
//}


