/* Minification failed. Returning unminified contents.
(8,45): run-time error CSS1031: Expected selector, found '='
(8,45): run-time error CSS1025: Expected comma or open brace, found '='
(9,22): run-time error CSS1031: Expected selector, found '='
(9,22): run-time error CSS1025: Expected comma or open brace, found '='
(11,1): run-time error CSS1019: Unexpected token, found '$'
(11,2): run-time error CSS1019: Unexpected token, found '('
(11,11): run-time error CSS1031: Expected selector, found ')'
(11,11): run-time error CSS1025: Expected comma or open brace, found ')'
(13,21): run-time error CSS1031: Expected selector, found '='
(13,21): run-time error CSS1025: Expected comma or open brace, found '='
(15,2): run-time error CSS1019: Unexpected token, found ')'
(17,17): run-time error CSS1031: Expected selector, found '='
(17,17): run-time error CSS1025: Expected comma or open brace, found '='
(20,16): run-time error CSS1031: Expected selector, found '='
(20,16): run-time error CSS1025: Expected comma or open brace, found '='
(21,25): run-time error CSS1031: Expected selector, found '='
(21,25): run-time error CSS1025: Expected comma or open brace, found '='
(25,22): run-time error CSS1031: Expected selector, found '='
(25,22): run-time error CSS1025: Expected comma or open brace, found '='
(27,10): run-time error CSS1031: Expected selector, found 'onPhotoImgLoaded('
(27,10): run-time error CSS1025: Expected comma or open brace, found 'onPhotoImgLoaded('
(50,10): run-time error CSS1031: Expected selector, found 'togglePhotoLink('
(50,10): run-time error CSS1025: Expected comma or open brace, found 'togglePhotoLink('
(63,10): run-time error CSS1031: Expected selector, found 'RowSelected_Handler('
(63,10): run-time error CSS1025: Expected comma or open brace, found 'RowSelected_Handler('
(219,10): run-time error CSS1031: Expected selector, found 'BeforeData_Handler('
(219,10): run-time error CSS1025: Expected comma or open brace, found 'BeforeData_Handler('
(248,10): run-time error CSS1031: Expected selector, found 'reloadPage('
(248,10): run-time error CSS1025: Expected comma or open brace, found 'reloadPage('
(255,10): run-time error CSS1031: Expected selector, found 'domReady('
(255,10): run-time error CSS1025: Expected comma or open brace, found 'domReady('
(348,10): run-time error CSS1031: Expected selector, found 'printMap('
(348,10): run-time error CSS1025: Expected comma or open brace, found 'printMap('
(355,10): run-time error CSS1031: Expected selector, found 'infoFormShow('
(355,10): run-time error CSS1025: Expected comma or open brace, found 'infoFormShow('
(361,10): run-time error CSS1031: Expected selector, found 'infoFormHide('
(361,10): run-time error CSS1025: Expected comma or open brace, found 'infoFormHide('
(367,10): run-time error CSS1031: Expected selector, found 'searchFormFocus('
(367,10): run-time error CSS1025: Expected comma or open brace, found 'searchFormFocus('
(374,10): run-time error CSS1031: Expected selector, found 'ExecuteSearchForm1('
(374,10): run-time error CSS1025: Expected comma or open brace, found 'ExecuteSearchForm1('
(397,10): run-time error CSS1031: Expected selector, found 'ExecuteSearchForm2('
(397,10): run-time error CSS1025: Expected comma or open brace, found 'ExecuteSearchForm2('
(428,10): run-time error CSS1031: Expected selector, found 'poiguidSearch('
(428,10): run-time error CSS1025: Expected comma or open brace, found 'poiguidSearch('
(440,10): run-time error CSS1031: Expected selector, found 'fillGrobljaList('
(440,10): run-time error CSS1025: Expected comma or open brace, found 'fillGrobljaList('
(472,10): run-time error CSS1031: Expected selector, found 'init('
(472,10): run-time error CSS1025: Expected comma or open brace, found 'init('
 */
/**
* Zajednička programska logika DESKTOP stranice tražilice pokojnika.
* "Per-tenant" razlike definirati izravno u stranici ili korisnikovom ~/Scripts/App direktoriju.
* Dependency o vanjskim library-jima: AxWebGIS, OData.
*/

// view model
OData.defaultHttpClient.enableJsonpCallback = true;
OData.defaultHandler = OData.atomHandler;

$(domReady);

AutoSizeFramedCloud = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
    'autoSize': true
});

var currPOIGUID = "";

// sve stranice slider-a koje nemaju data-forslider=SEARCHTYPE se izbacuju
var SEARCHTYPE = "#pokojnici"; // ujedno je i defaultna ukoliko <li> slider-a nema data-searchtype atribut
var SEARCHTYPES_ALLOWED = {
    "#pokojnici": "Tražilica pokojnika",
    "#gmzaprodaju": "Raspoloživa grobna mjesta",
};
var FOTODISPLAYSTYLE = 1; // ako u slide-u s kartom ne pronađe #photoframe -> verzija 2. (fotografije na svom tab-u), namješta se u domready

function onPhotoImgLoaded() {
	var maxW  = $("#photoframe").width();
	var maxH  = $("#photoframe").height();
	$("#photo").css('width', maxW);
	$("#photo").css('height', 'auto'); // reset širine i visine s pravilnim skaliranjem 	
	var currW = $("#photo").width();
	var currH = $("#photo").height();

	var ratioMax = maxH > 0.001 ? maxW / maxH : maxW * 1000.0;
    var ratio = currH > 0.001 ? currW / currH : currW * 1000.0;
	
	if (ratioMax > ratio) { // max je po visini
		$("#photo").height(maxH);
		$("#photo").width(maxH * ratio);		
	} else if (ratio > 0.001) {
		$("#photo").width(maxW);
		$("#photo").height(maxW / ratio);
	} else {
		$("#photo").width(maxW);
		$("#photo").height(maxH);
	}	
}

function togglePhotoLink(el) {
    el.siblings().css("opacity", 1.0);
    el.css("opacity", 0.3);
    if (el.attr("data-imgsrc") > "") {
        el.siblings("#photolabel").css("opacity", 1.0);		
		$("#photo").attr("src", el.attr("data-imgsrc"));
        if ( typeof($.featherlight) === 'function' ) {
            $('#FeatherLight').attr("href", el.attr("data-imgsrc"));
            $('#FeatherLight').featherlight(); // featherlightGallery();
        }        
    }    
}

function RowSelected_Handler(tableID, infodict) {

    $("#gmnapomena").css("visibility", "hidden");

    if (SEARCHTYPE == "#pokojnici")
        $("#slider").data("AnythingSlider").gotoPage(3);
    else
        $("#slider").data("AnythingSlider").gotoPage(2);

    var groblje = groblja[infodict.NAZIV_GROB];
    
    if ( FOTODISPLAYSTYLE == 2 && $('#FotoSlide').length > 0 ) { // varijanta s fotografijama na posebnom tab-u
        $('#FotoSlide').remove();
        $('#slider').anythingSlider(); // update the slider
        $(".dataTables_wrapper").css("height","");          
    }
    else {
        $("#photobuttons").css("display", "none");
        $("#photoframe").css("display", "none"); 
    }
    
    // ako nema posebnih podataka o groblju isključi minimap
    if (groblje == undefined)
    {
        $("#minimap").css("display", "none");
        $("#alt_minimap").css("display", "block");
        AxWebGIS_CemeteryMap.Map.setCenter(AxWebGIS_CemeteryMap.mapCenter(), 0);
        return;            
    }
    else {
        $("#minimap").css("display", "block");
        $("#alt_minimap").css("display", "none");            
    }
    
    var groblje_centar = new OpenLayers.LonLat(groblje.lon, groblje.lat).transform(WGSPROJ, SMPROJ);
    AxWebGIS_CemeteryMinimap.clearPosition();            
    AxWebGIS_CemeteryMinimap.unrestrictedExtent();
    AxWebGIS_CemeteryMinimap.setCenter(groblje_centar, groblje.overview_zoom);
    AxWebGIS_CemeteryMinimap.restrictToCurrentExtent();            
    
    // ako nema polja, ostaje OSM
    if (groblje.polja.features.length == 0) {
        AxWebGIS_CemeteryMap.Map.setCenter(new OpenLayers.LonLat(groblje.lon, groblje.lat).transform(WGSPROJ, SMPROJ), 6);
        return;
    }            
    
    var markerlayer = AxWebGIS_CemeteryMap.Map.getLayersByName("Markers");
    if (markerlayer.length > 0)
        markerlayer[0].clearMarkers();                    

    var polje = null;
    // imamo barem polje, 24.5.2016, dodan i red, potreban override u customizaciji koja ga prepoznaje
    if (infodict.KRATICA_OGRMJ != "" || infodict.KRATICA_PGRMJ != "" || infodict.KRATICA_RGRMJ != "")
        polje = AxWebGIS_CemeteryMinimap.highlightPolje(infodict.NAZIV_GROB, infodict.KRATICA_OGRMJ, infodict.KRATICA_PGRMJ, infodict.KRATICA_RGRMJ);
    // probaj poziciju
    if (IsNull(infodict.GPS_N,"") != "" && IsNull(infodict.GPS_E, "") != "") {
        var point = new OpenLayers.LonLat(parseFloat(infodict.GPS_E), parseFloat(infodict.GPS_N)).transform(WGSPROJ, SMPROJ);
        AxWebGIS_CemeteryMap.Map.setCenter(point, groblje.minzoomlevel == undefined ? 8 : groblje.minzoomlevel);
        AxWebGIS_CemeteryMap.addMarker(point);
        AxWebGIS_CemeteryMinimap.markPosition(point);
    } else {
        // ako nema, probaj na polje ili barem na groblje
        if(polje) {
            var center = polje.geometry.getCentroid();
            AxWebGIS_CemeteryMap.Map.setCenter(new OpenLayers.LonLat(center.x, center.y), 8);
        }
        else
            AxWebGIS_CemeteryMap.Map.setCenter(groblje_centar, 6);
    }

    currPOIGUID = infodict.HANDLE_KARTA;

    // ukoliko ima fotografija, pokreni upit za dohvat
    if (infodict.FOTOCNT != undefined && infodict.FOTOCNT > 0) {        
        OData.defaultHttpClient.enableJsonpCallback = true;
        OData.request({
            requestUri: ToAppPath("ObevBlobs.svc/PoiGuidPhotos?POI_GUID=%27" + currPOIGUID + "%27"),
                headers: { "Content-Type": "application/json" }
            }
            ,function (data, response) {
                if (data.results.length > 0 && data.results[0].POI_GUID == currPOIGUID) {
                    if (SEARCHTYPE == "#gmzaprodaju" && typeof toastr != "undefined")
                        toastr.success("<center><img style='max-width: 180px;' src='" + (window.location.protocol === "https:" ? data.results[0].FILE_PATH.replace("http:", "https:") : data.results[0].FILE_PATH) + "'></center>");
                    if (FOTODISPLAYSTYLE == 2) { // fotografije na posebnom tab-u
                        if ($("#FotoSlide").length == 0) {
                            $(SEARCHTYPE == "#gmzaprodaju" ? '#infoGMZaProdaju' : '#DeceasedInfo').clone().appendTo("#slider").wrap('<li id="FotoSlide" data-caption="Fotografije"></li>');
                            $('<div id="photoframe"><div id="photobuttons" style="position: absolute; top: 1px;"></div><a id="FeatherLight" href="#"><img id="photo" /></a></div>').appendTo("#FotoSlide");
                            $('#slider').anythingSlider();
                        }
                        // promjena visine retka na datatablici?!
                        // $(".dataTables_wrapper").css("height","");
                        $("#TablicaPokojnika").height(0);
                        $('#photo').on('load', onPhotoImgLoaded);
                        $("#photobuttons").empty();
                    }
                    else {
                        $("#photobuttons").empty();
                        $("#photobuttons").css("display", "block");
                        $("<a href='#' style='opacity: 0.3'>karta</a>").appendTo("#photobuttons").click(
                            function () { 
                                togglePhotoLink($(this)); 
                                $("#minimap").css("display", "block"); 
                                $("#photoframe").css("display", "none"); 
                        });
                        $("#photobuttons").append("<span id='photolabel'>| foto</span>");
                    }
                    var firstfoto = null;
                    $.each( data.results, function (key, value) {
                        var linkel;
                        if ( FOTODISPLAYSTYLE == 2 && data.results.length == 1 ) {                            
                            $("#photo").attr("src", (window.location.protocol === "https:" ? value.FILE_PATH.replace("http:", "https:") : value.FILE_PATH));
                            if ( typeof($.featherlight) === 'function' ) {
                                $('#FeatherLight').attr("href", (window.location.protocol === "https:" ? value.FILE_PATH.replace("http:", "https:") : value.FILE_PATH));
                                $('#FeatherLight').featherlight();
                            }                             
                        }                        
                        else {
                            linkel = $("<a href='#' data-imgsrc='" + (window.location.protocol === "https:" ? value.FILE_PATH.replace("http:", "https:") : value.FILE_PATH) + "'>" + (key + 1).toString() + (FOTODISPLAYSTYLE == 2 ? ".</a><br/>" : "</a>"));
                            if ( !firstfoto )
                                firstfoto = linkel;
                            linkel.appendTo("#photobuttons").click(
                                function (event) {
                                    event.preventDefault();
                                    togglePhotoLink( $(this) ); 
                                    if ( FOTODISPLAYSTYLE == 1 ) {
                                        $("#minimap").css("display", "none"); 
                                        $("#photoframe").css("display", "block"); 
                                    }
                            });
                        }
                    });
                    $("#photoframe").css("display", "block");
                    if ( FOTODISPLAYSTYLE == 2 && firstfoto )
                        togglePhotoLink( firstfoto ); // aktiviraj prvu fotografiju ako su fotografije na svom tab-u
                }
                else {
                    $("#photobuttons").css("display", "none");
                    $("#photoframe").css("display", "none");
                }
            }
            ,function (err) {
                    // console.log("OData, PhotoTrack: " + err.message);
            }
            ,OData.jsonHandler
        );
    }
    else {
        $("#photobuttons").css("display", "none");
        $("#photoframe").css("display", "none");
    }

    if (infodict.NAPOMENA_GM && infodict.NAPOMENA_GM.length > 0)
        $("#gmnapomena").css("visibility", "visible");

}

function BeforeData_Handler()
{
    if (SEARCHTYPE == "#gmzaprodaju") { // #gmzaprodaju - ostani na istoj stranici, napuni moguće opcije vrsta grobnih mjesta
        $("#gmzaprodajuloading").hide();
        $('#sform1Vrsta').find('option').remove().end().append('<option value=""></option>');
        var data = $("#TablicaGMZaProdaju").dataTable().fnGetData();
        if (data.length > 0) {
            $.each(ArrayUnique(data.map(function (element) { return element[1]; })).sort(),
                function (key, value) {
                    $('#sform1Vrsta')
                .append($("<option></option>")
                .text(value));
                }
            );
        }
        window.IncRaspolozivaGM = 0;
    }
    else  {
        $("#loading").html("Podaci su dohvaćeni").delay(1200).fadeOut(1400);
        if (typeof (toastr) != 'undefined') {
            toastr.options.positionClass = 'toast-top-left';
            toastr.info("Podaci su dohvaćeni.<br>Za detalje kliknite na željeni red!");
        }
        $("#slider").data("AnythingSlider").gotoPage(2);
    }

    currPOIGUID = "";
}

function reloadPage(search_type) {
    if ((typeof search_type === "undefined") || ($.inArray(search_type, Object.keys(SEARCHTYPES_ALLOWED)) < 0))
        search_type = SEARCHTYPE;
    $(location).attr('hash', search_type);
    location.reload();
}

function domReady() {

    // bckwd compatibility: svim stranicama bez data-searchtype dodaj defaultni: SEARCHTYPE
    $("#slider").children(":not([data-searchtype])").attr("data-searchtype", "#pokojnici");

    // http://...#pokojnici || http://...#gmzaprodaju
    if ($(location).attr('hash') != "" && $.inArray($(location).attr('hash'), Object.keys(SEARCHTYPES_ALLOWED)))
        SEARCHTYPE = $(location).attr('hash');
    else
        SEARCHTYPE = '#pokojnici';
    
    if (!(SEARCHTYPE in SEARCHTYPES_ALLOWED))
        SEARCHTYPE = '#pokojnici';

    if (SEARCHTYPE == '#gmzaprodaju' && typeof (web_gm_za_prodaju_viewModel) == "undefined")
        SEARCHTYPE = '#pokojnici';

    if (SEARCHTYPE == "#gmzaprodaju" && typeof ga != "undefined") {
        // toastr za prikaz fotografija
        $('head').append('<style type="text/css">.toast-success {background-color: white}\n .toast { opacity: 1 !important; }\n #toast-container > div {  opacity: 1 !important; }</style>');
        jQuery.extend(toastr.options, { "showDuration": "1000", "timeOut": "1000" });
        // analytics
        ga('set', 'page', ToAppPath('GMZaProdaju'));
        ga('send', 'pageview');
    }
    
    // verzija prikaza fotografija
    if ( $('#photoframe').length > 0 ) // postoji frame (u tab-u s minimap-om)
        FOTODISPLAYSTYLE = 1;
    else
        FOTODISPLAYSTYLE = 2;
    document.title = SEARCHTYPES_ALLOWED[SEARCHTYPE];

    // makni sve stranice koje ne odgovaraju mom search tipu
    $("#slider").children(":not([data-searchtype*='" + SEARCHTYPE + "'])").remove();

    if ( SEARCHTYPE == '#gmzaprodaju' && ($("#upute_gmzaprodaju").length > 0) ) {
        $("#upute_gmzaprodaju").css("display", "block");
        $("#upute").css("display", "none");
    }

    var mySliderOptions = {
        navigationFormatter: function (index, panel) {
            var ret = panel.attr('data-caption'); // ako je dodan <li data-caption="... uzmi taj, inače default
            if(! ret) {
                switch (index) {
                    case 1:
                        ret = 'Traži';
                        break;
                    case 2:
                        ret = 'Pokojnici';
                        break;
                    default:
                        ret = 'Karta';
                        break;
                }
            }
            return ret;
        },
        buildArrows: false,
        buildStartStop: false,
        hashTags: false
    };
    $('#slider').anythingSlider(mySliderOptions);
    $("#slider").data("AnythingSlider").gotoPage(1);
    $("#info_red_starost").css("display", "none");
    $("#alt_minimap").css("display", "none");   
    //$("#sform1Groblje").attr('disabled', 'disabled'); //kad postoji samo jedno groblje - onda se može disable-irati
	
	// nastavi event tako da se mogu skalirati slike
    $('#photo').on('load', onPhotoImgLoaded);

    var searchuri = $(location).attr("search");
    if ( searchuri.indexOf("?companyuri") >= 0 ) {
       $("body").append("<div id='companyurioverlay'><a style='text-align: center; text-decoration: none; margin: 7px' href='" +  decodeURIComponent(searchuri.substring(searchuri.indexOf("?companyuri=")+12)) + "'> &gt;&gt; Pogledajte kako tražilica izgleda u sklopu stranica naših korisnika. &lt;&lt;</a></div>");

       $("#companyurioverlay")
          .css( {              
             'position': 'fixed',
             'top': 10,
             'left': 10,
             'width': '250px',
             'height': '50px',             
             'background-color': 'white',
             'color': 'white',
             'border': '1px solid darkblue',
             'border-radius': '3px',
             'padding': '5px',
             'z-index': 5000
          } );        
    }    
}

function printMap() {
    if ($.browser.msie)
        document.execCommand('print', true, null) //scale to fit
    else
        window.print();
}

function infoFormShow() {
     $("#overlay").show();
     $("#info_form").show();
     $("#slider_container").hide();
}

function infoFormHide() {
     $("#overlay").hide();
     $("#info_form").hide();
     $("#slider_container").show();
}

function searchFormFocus() {
     $("#slider_container").show();
     $("#slider").data("AnythingSlider").gotoPage(1);
     $("#slider_container").focus();
     $("#tform1Ime").focus();
}

function ExecuteSearchForm1() {
    if (document.forms["form1"].tform1Ime.value == "" && document.forms["form1"].tform1Prezime.value == "" 
        && document.forms["form1"].sform1Groblje.value == "" 
        && document.forms["form1"].tform1GodinaOd.value == "" && document.forms["form1"].tform1GodinaDo.value == "") {
        $("#loading").html("Obavezno je postavljanje barem<br>jednog kriterija pretraživanja!").delay(1200).fadeOut(1400);
        $("#loading").show();
    }
    else {
        $("#loading").html('Tražim... <img src="' + ToAppPath('Content/App/img/ajax-loader-desktop.gif') + '">');
        $("#loading").show();

        web_ukopani_viewModel.execQuery(ToAppPath("Trazilica.svc/PvWebUkopani?"),
            {
                ime:       downcode(document.forms["form1"].tform1Ime.value) + "%"
                ,prezime:  downcode(document.forms["form1"].tform1Prezime.value) + "%"
                ,groblje:  document.forms["form1"].sform1Groblje.value == "" ? "%" : encodeURIComponent(document.forms["form1"].sform1Groblje.value)
                ,godina_od:StrToInt(document.forms["form1"].tform1GodinaOd.value, 1750)
                ,godina_do:StrToInt(document.forms["form1"].tform1GodinaDo.value, 2100)
            }
        );
    }
}

function ExecuteSearchForm2() {
    if (document.forms["form1"].tform1Odjel.value == "" && document.forms["form1"].tform1Polje.value == ""
        && document.forms["form1"].tform1Razred.value == "" && document.forms["form1"].tform1Broj.value == "") {
        ExecuteSearchForm1();
    }
    else if (document.forms["form1"].sform1Groblje.value == "" || document.forms["form1"].tform1Odjel.value == "" || document.forms["form1"].tform1Polje.value == ""
            || document.forms["form1"].tform1Razred.value == "" || document.forms["form1"].tform1Broj.value == "") {
        $("#loading").html("Pri pretraživanju po lokaciji<br>obavezan je unos svih polja!<br>(groblje, odjel, polje, razred i broj)").delay(1200).fadeOut(1400);
        $("#loading").show();
    }
    else {
        $("#loading").html('Tražim... <img src="' + ToAppPath('Content/App/img/ajax-loader-desktop.gif') + '">');
        $("#loading").show();

        web_ukopani_viewModel.execQuery(ToAppPath("Trazilica.svc/PvWebGrmjUkopani?"),
            {
                ime: downcode(document.forms["form1"].tform1Ime.value) + "%"
                , prezime: downcode(document.forms["form1"].tform1Prezime.value) + "%"
                , groblje: document.forms["form1"].sform1Groblje.value == "" ? "%" : encodeURIComponent(document.forms["form1"].sform1Groblje.value)
                , godina_od: StrToInt(document.forms["form1"].tform1GodinaOd.value, 1750)
                , godina_do: StrToInt(document.forms["form1"].tform1GodinaDo.value, 2100)
                , odjel: downcode(document.forms["form1"].tform1Odjel.value == "" ? "%" : encodeURIComponent(document.forms["form1"].tform1Odjel.value))
                , polje: downcode(document.forms["form1"].tform1Polje.value == "" ? "%" : encodeURIComponent(document.forms["form1"].tform1Polje.value))
                , razred: downcode(document.forms["form1"].tform1Razred.value == "" ? "%" : encodeURIComponent(document.forms["form1"].tform1Razred.value))
                , broj: downcode(document.forms["form1"].tform1Broj.value == "" ? "%" : encodeURIComponent(document.forms["form1"].tform1Broj.value))
            }
        );
    }
}


function poiguidSearch(poiguid) {
    if(typeof(poiguid) == "string")
        poiguid = [poiguid];
	if (SEARCHTYPE != "#pokojnici")
		return;		
    $("#loading").html('Tražim... <img src="' + ToAppPath('Content/App/img/ajax-loader-desktop.gif') + '">');
    $("#loading").show();
    web_ukopani_viewModel.execQuery(ToAppPath("Trazilica.svc/V_WEB_UKOPANI?$inlinecount=allpages&$orderby=DATUM_SMRTI desc,ID_UKOP desc&$filter="),
        {HANDLE_KARTA: poiguid}
    );
}        

function fillGrobljaList() {
   //popuni groblja u select
    OData.defaultHttpClient.enableJsonpCallback = true;
    OData.read(ToAppPath("Trazilica.svc/V_WEB_GROBLJA?$inlinecount=allpages&$orderby=NAZIV_GROB"), succPopisGroblja, errPopisGroblja);

    function succPopisGroblja(data) {
        var selectGrobljaHtml = "<OPTION></OPTION>";
        $.each(data.results, function (key, value) {
            if (value.NAZIV_GROB != 'Sportska dvorana') {
                selectGrobljaHtml += "<OPTION VALUE='" + value.NAZIV_GROB + "'>" + value.NAZIV_GROB + "</OPTION>";
            }
        });
        $("#sGroblje").html(selectGrobljaHtml);
        $("#sform1Groblje").html(selectGrobljaHtml);
        selectGrobljaHtml = "<OPTION>-- Lociraj groblje --</OPTION>";
        $.each(data.results, function (key, value) {
            if (value.NAZIV_GROB != 'Sportska dvorana') {
                selectGrobljaHtml += "<OPTION VALUE='" + value.NAZIV_GROB + "'>" + value.NAZIV_GROB + "</OPTION>";
            }
        });
        $("#sLocirajGroblje").html(selectGrobljaHtml);        
        // ukoliko je definirana FixNazivGroblja, fiksiraj odabir
        if (typeof(FixNazivGroblja) == "string") {
            $("#sform1Groblje").val(FixNazivGroblja);
            $("#sform1Groblje").attr('disabled', 'disabled');
        }
    }
    
    function errPopisGroblja(err) {
    }
}
 
function init() {
    initGroblja();
    fillGrobljaList();
    AxWebGIS_CemeteryMinimap.init(groblja, "minimap");
    AxWebGIS_CemeteryMap.init(groblja, "map", false, poiguidSearch, typeof(CemeteryPlacemarksTitle) == "string" ? CemeteryPlacemarksTitle : "");
    fillGrobljaList();
    $("#overlay").click(function () { infoFormHide(); });            
    if (!Modernizr.svg)
        $(".warningBg").show();
    $("#loading").hide();
    $("#gmzaprodajuloading").hide();

    if (SEARCHTYPE == "#gmzaprodaju" && typeof (web_gm_za_prodaju_viewModel) != "undefined") {
        web_gm_za_prodaju_viewModel.init();
        // odmah dohvati podatke o grobnim mjestima za prodaju
        web_gm_za_prodaju_viewModel.execQuery(ToAppPath("Trazilica.svc/V_GM_ZA_PRODAJU"));
        $("#gmzaprodajuloading").html('Dohvaćanje podataka.. <img src="' + ToAppPath('Content/App/img/ajax-loader-desktop.gif') + '">');
        $("#gmzaprodajuloading").show();
        $(".filterGMZaProdaju select").change(function () { $("#TablicaGMZaProdaju").dataTable().fnFilter(""); });
        $(".filterGMZaProdaju input").change(function () { $("#TablicaGMZaProdaju").dataTable().fnFilter(""); });
        // disable getFeatures funkcije
        AxWebGIS_CemeteryMap.unregisterGetFeatures();
    }
    else
        web_ukopani_viewModel.init();

    // forsiraj reload stranice ukoliko se u #hash upiše nešto na što znamo reagirati
    if ("onhashchange" in window) {
        window.onhashchange = function () {
            var search_type = location.hash == "" ? '#pokojnici' : location.hash; 
            if ($.inArray(search_type, Object.keys(SEARCHTYPES_ALLOWED)) >= 0 && search_type != SEARCHTYPE)
                location.reload();
        };
    }
}

