function initMap(XHR){

    var options = {
        controls: []
    };
    //var map = eGV.addMap(new eGV.Map("divMap",options));
    var format = new eGV.Format.WMC();
    var map = format.read(XHR.responseText,{
        map: "divMap",
        mapOptions: options
    });

    eGV.Lang.setCode("ca");
    eGV.includeStyle(eGV.scriptRoot + "egv/theme/default/style.css","csseGV");
    eGV.includeStyle("css/egv.css","cssmap");



    var printingOptions = {
        "personaltext":"Plànol sense valor normatiu",
        "showcoordinates":true,
        "showreferencesystem":false,
        "legendwidth":"151",
        "qfactor":"2",
        "showselectionitem":true,
        "footerheight":"60",
        "scalebar":"numeric",
        "legendqfactor":"0.7",
        "showreferencemap":false,
        "setopacity":true
    };
    var embeddedLayerSenders = map.getConnection("senders").getLayer("xv_senders");
    embeddedLayerSenders.legendType = "embedded";

    /*
    var embeddedLayerCtres = map.getConnection("senders").getLayer("xv_ctres");
    embeddedLayerCtres.legendType = "embedded";
    */
   
    var inuncatCons = map.getConnection("inuncat").getLayer("inuncat_cons");
    inuncatCons.legendType = "embedded";

    var cadastre = map.getConnection("cadastre").getLayer("cadastre");
    cadastre.showLegend = false;


    eGV.addControl(new eGV.Control.LayersManager("divMenuLayersManagerBody",{
        "active":true,
        "legendType":"inline",
        "displayTitle":false,
        "displayExplanationText":false
    }));

    statusBar = eGV.addControl(new eGV.Control.ScaleStatusBar("divStatusBarBody",{"id":"stbar", "drawScale": false}));
     var scaleSelector = eGV.addControl(new eGV.Control.ScaleSelector("divScaleSelector",{"id":"scaleSelector"}));
    /*
    var statusBar = eGV.addControl(new eGV.Control.ScaleStatusBar("divStatusBarBody",{"id":"stbar", "drawScale": false}));
    var scaleSelector = eGV.addControl(new eGV.Control.ScaleSelector("divScaleSelector",{"id":"scaleSelector"}));
    */
    
    var controls = [
    new OpenLayers.Control.Navigation({
        displayClass: "egvControlButton egvControlNavigation",
        title:eGV.Lang.translate("pan")
    }),
    new OpenLayers.Control.ZoomBox({
        displayClass: "egvControlButton egvControlZoomBox",
        title:eGV.Lang.translate("zoomin")
    }),
    new OpenLayers.Control.ZoomBox({
        out:true,
        displayClass: "egvControlButton egvControlZoomOutClick",
        title:eGV.Lang.translate("zoomout")
    }),
    new eGV.Control({
        type: OpenLayers.Control.TYPE_BUTTON,
        displayClass: "egvControlButton egvControlZoomToMaxExtent",
        title:eGV.Lang.translate("fullextent"),
        trigger: zoomToTremp
    }),
    new eGV.Control.Ruler({
        statusbar: statusBar,
        displayClass: "egvControlButton egvControlRule",
        title :"Càlcul de distàncies: seleccionar l\'eina i clicar sobre el mapa els punt de mesura. Doble clic per finalitzar"
    }),
    new eGV.Control.Area({
        id:"eGV_AreaControl",
        statusbar: statusBar,
        displayClass: "egvControlButton egvControlArea",
        title :"Càlcul d'àrees: seleccionar l\'eina i clicar sobre el mapa els punt de mesura. Doble clic per finalitzar"
    }),
    new UserControlPrint("divPrintBody",{
        id:"printControl",
        displayClass: "egvControlButton egvControlPrint",
        title:eGV.Lang.translate("print"),
        logoUrl:"http://oslo.geodata.es/tremp/img/logoprint.jpg",
        printOptions:printingOptions
    }),
    new eGV.Control.Info("divInfoBody",{
        id:"infoControl",
        displayClass: "egvControlButton egvControlInfo",
        viewall:false,
        title:eGV.Lang.translate("info")
    }),
    new UserControlProfile("divProfileBody",{
        id:"profileControl",
        imgId:"profileImg",
        displayClass: "egvControlButton egvControlUserControlProfile",
        title:"Obtenció de perfils d\'altimetria"
    }),
    new UserControlListFiles("divPrintBody",{
        id:"listFilesControl",
        displayClass: "egvControlButton egvControlUserControlListFiles",
        title:"Llistat de fitxes"
    }),
    new UserControlListShapes("divPrintBody",{
        id:"listShapesControl",
        displayClass: "egvControlButton egvControlUserControlListShapes",
        title:"Cartografia en format .shp"
    }),
    new UserControlGPX("divPrintBody",{
        id:"gpxControl",
        displayClass: "egvControlButton egvControlUserControlGPX",
        title:"Carrega de GPX"
    }),
    new UserControlOpenKML("divProfileBody",{
        id:"KMLControl",
        displayClass: "egvControlButton egvControlUserControlKML",
        title:"Exportació a Google Earth"
    }),
    new UserControlHelp("divPrintBody",{
        id:"helpControl",
        displayClass: "egvControlButton egvControlUserControlHelp",
        title:"Ajuda"
    })
    ];

    var toolBar = eGV.addControl(new eGV.Control.ToolBar("divMapToolBarBody",{
        defaultControl:controls[0],
        "id":"toolbar"
    }));
    toolBar.addControls(controls);
    map.addControl(toolBar);


    var transparencyConnectionsBack = [
    map.getConnection("capesICC"),
    map.getConnection("mdeTremp")
    ];

    var transparencyConnectionsLayers = [
    map.getConnection("altres"),
    map.getConnection("proteccions"),
    map.getConnection("cp"),
    map.getConnection("inuncat_tr"),
    map.getConnection("inundacio"),
    map.getConnection("caca"),
    map.getConnection("forests"),
    map.getConnection("inuncat"),
    map.getConnection("inuncat_tr"),
    map.getConnection("inuncat_tr"),
    map.getConnection("mgc50m"),
    map.getConnection("mcsc")
    ];

    var transControlBack = new eGV.Control.Transparency({
        id:"controlTransparencyBack",
        minOpacity:0,
        defaultOpacity:0.75,
        connections:transparencyConnectionsBack
    });
    eGV.addControl(transControlBack);

    var transControlLayers = new eGV.Control.Transparency({
        id:"controlTransparencyLayers",
        minOpacity:0,
        defaultOpacity:1,
        connections:transparencyConnectionsLayers
    });
    eGV.addControl(transControlLayers);


    om1 = new OpenLayers.Layer.WMS(
        "MDE",
        "http://donosti.geodata.es/wms52/geodata/mapabase/mde",
        {
            "layers":"mde",
            "format":"image/jpeg",
            "exceptions":"application/vnd.ogc.se_xml"
        },
        {
            buffer:0,
            transitionEffect:'resize'
        }
        )
    om2 = new OpenLayers.Layer.WMS(
        "Munis",
        "http://oslo.geodata.es/wms50/icc/atles_nacional/ref_icc",
        {
            "transparent":"true",
            "layers":"munis",
            "format":"image/png",
            "exceptions":"application/vnd.ogc.se_xml"
        },
        {
            buffer:0,
            transitionEffect:'resize'
        }
        )
	
	
    var baseLayers = [
    fonsTopo = eGV.getMap().getGroup("fonsTopo"),
    fonsOrto = eGV.getMap().getGroup("fonsOrto"),
    fonsMde = eGV.getMap().getGroup("fonsMde")

    ];
    eGV.addControl(new eGV.Control.BaseLayerSwitcher("divBaseLayerSwitcher",{
        activeBase:fonsOrto,
        bases:baseLayers,
        id:"eGVBaseLayersSwitcher"
    }));

    eGV.addControl(new eGV.Control.OverviewMap("divOverviewMap",{
        staticMap: false,
        size:[100,100],
        layers:[om1,om2],
        id:"eGVOverviewMap"
    }));

    var highConn = eGV.getMap().getConnection("highlight");
    highConn.olLayer.params.SLD = serverUrl+"/tremp/php/sld.php?layer=senders&field=xv_senders_fid&value=1";

    //eGV envents
    toolBar.getControl("profileControl").events.register("actionstart", {
        "divId":"divProfile",
        "embedded": true
    },effects.showFloatingDiv);
    //toolBar.getControl("gpxControl").events.register("actionstart", {"divId":"divProfile","embedded": true},effects.showFloatingDiv);
    toolBar.getControl("listFilesControl").events.register("actionstart", {
        "divId":"divPrint"
    },effects.showModalDiv);
    toolBar.getControl("listFilesControl").events.register("actionend", {
        "divId":"fileTree","fileType":"pdf"
    },effects.createFileTree);

    toolBar.getControl("listShapesControl").events.register("actionstart", {
        "divId":"divPrint"
    },effects.showModalDiv);
    toolBar.getControl("listShapesControl").events.register("actionend", {
        "divId":"fileTree","fileType":"shp"
    },effects.createFileTree);



    toolBar.getControl("gpxControl").events.register("actionstart", {
        "divId":"divPrint"
    },effects.showModalDiv);
    toolBar.getControl("gpxControl").events.register("actionend", {
        "divId":"fileUpload"
    },effects.createFileLoader);
    toolBar.getControl("infoControl").events.register("actionstart", {
        "divId":"divInfo"
    },effects.showFloatingDiv);
    toolBar.getControl("printControl").events.register("actionstart", {
        "divId":"divPrint"
    },effects.showModalDiv);
    toolBar.getControl("printControl").events.register("actionend", {
        "divId":"divPrint"
    },effects.hideModalDiv);
    toolBar.getControl("helpControl").events.register("actionstart", {
        "divId":"divPrint"
    },effects.showModalDiv);
    toolBar.getControl("helpControl").events.register("actionend", {
        "divId":"divHelp"
    },effects.createCodaSlider);


    //effects.createSlider("divTransparency", {max:transControl.maxOpacity*100, min:transControl.minOpacity*100, value:75});

    //<div id='divTransparencyBack'><label><?= _TRANS_BACK_TITLE ?></label><div id='divTransparencyBackSlider'></div></div>
    //<div id='divTransparencyLayers'><label><?= _TRANS_LAYERS_TITLE ?></label><div id='divTransparencyLayersSlider'></div></div>

    var sliders = [
    {
        "id":"divTransparencyBack",
        "title":"Fons"
    },

    {
        "id":"divTransparencyLayers",
        "title":"Temes"
    }
    ];

    effects.createSlidersContent("divTransparencyBody",sliders);

    effects.createSlider("divTransparencyBack", {
        control: "controlTransparencyBack",
        max:transControlBack.maxOpacity*100,
        min:transControlBack.minOpacity*100,
        value:75
    });
    effects.createSlider("divTransparencyLayers", {
        control: "controlTransparencyLayers",
        max:transControlLayers.maxOpacity*100,
        min:transControlLayers.minOpacity*100,
        value:100
    });

    effects.hideLoading("divLoading");

    if ((jQuery.browser.msie) && (jQuery.browser.version.substr(0,1) <= "6")) {
        scroll(0,0);
    } else {
        scroll(0,95);
    }
    eGV.getMap().getConnection("mcsc").infoFormat = "text/html";
    eGV.getMap().getConnection("sigpac").infoFormat = "text/html";
    eGV.getMap().getConnection("sima").infoFormat = "text/html";
}


function zoomToTremp(){
    var bounds = new OpenLayers.Bounds(279650,4643395,362547,4712150);
    eGV.getMap().zoomToExtent(bounds);
}
