/* Minification failed. Returning unminified contents.
(6,17): run-time error CSS1031: Expected selector, found '='
(6,17): run-time error CSS1025: Expected comma or open brace, found '='
(7,23): run-time error CSS1031: Expected selector, found '='
(7,23): run-time error CSS1025: Expected comma or open brace, found '='
(8,19): run-time error CSS1031: Expected selector, found '='
(8,19): run-time error CSS1025: Expected comma or open brace, found '='
(9,27): run-time error CSS1031: Expected selector, found ';'
(9,27): run-time error CSS1025: Expected comma or open brace, found ';'
(10,17): run-time error CSS1031: Expected selector, found ';'
(10,17): run-time error CSS1025: Expected comma or open brace, found ';'
(11,20): run-time error CSS1031: Expected selector, found '='
(11,20): run-time error CSS1025: Expected comma or open brace, found '='
(12,18): run-time error CSS1031: Expected selector, found '='
(12,18): run-time error CSS1025: Expected comma or open brace, found '='
(14,10): run-time error CSS1031: Expected selector, found 'RowSelected_Handler('
(14,10): run-time error CSS1025: Expected comma or open brace, found 'RowSelected_Handler('
(129,10): run-time error CSS1031: Expected selector, found 'NullStr('
(129,10): run-time error CSS1025: Expected comma or open brace, found 'NullStr('
(134,10): run-time error CSS1031: Expected selector, found 'BeforeData_Handler('
(134,10): run-time error CSS1025: Expected comma or open brace, found 'BeforeData_Handler('
(159,10): run-time error CSS1031: Expected selector, found 'ShowMobileLoadingBar('
(159,10): run-time error CSS1025: Expected comma or open brace, found 'ShowMobileLoadingBar('
(174,10): run-time error CSS1031: Expected selector, found 'HideMobileLoadingBar('
(174,10): run-time error CSS1025: Expected comma or open brace, found 'HideMobileLoadingBar('
(186,10): run-time error CSS1031: Expected selector, found 'ExecuteSearchForm1('
(186,10): run-time error CSS1025: Expected comma or open brace, found 'ExecuteSearchForm1('
(213,10): run-time error CSS1031: Expected selector, found 'ExecuteSearchVlasnici('
(213,10): run-time error CSS1025: Expected comma or open brace, found 'ExecuteSearchVlasnici('
(237,10): run-time error CSS1031: Expected selector, found 'poiguidSearch('
(237,10): run-time error CSS1025: Expected comma or open brace, found 'poiguidSearch('
(266,10): run-time error CSS1031: Expected selector, found 'ShapeSelected_Handler('
(266,10): run-time error CSS1025: Expected comma or open brace, found 'ShapeSelected_Handler('
(276,10): run-time error CSS1031: Expected selector, found 'fixMapSize('
(276,10): run-time error CSS1025: Expected comma or open brace, found 'fixMapSize('
(290,10): run-time error CSS1031: Expected selector, found 'PhotoGalery('
(290,10): run-time error CSS1025: Expected comma or open brace, found 'PhotoGalery('
(295,10): run-time error CSS1031: Expected selector, found 'fillGrobljaList('
(295,10): run-time error CSS1025: Expected comma or open brace, found 'fillGrobljaList('
(319,10): run-time error CSS1031: Expected selector, found 'init('
(319,10): run-time error CSS1025: Expected comma or open brace, found 'init('
(405,10): run-time error CSS1031: Expected selector, found 'validateDeceased('
(405,10): run-time error CSS1025: Expected comma or open brace, found 'validateDeceased('
(411,10): run-time error CSS1031: Expected selector, found 'delCurrDeceased('
(411,10): run-time error CSS1025: Expected comma or open brace, found 'delCurrDeceased('
(422,10): run-time error CSS1031: Expected selector, found 'postCurrDeceased('
(422,10): run-time error CSS1025: Expected comma or open brace, found 'postCurrDeceased('
(438,10): run-time error CSS1031: Expected selector, found 'setBrowserInfoCookie('
(438,10): run-time error CSS1025: Expected comma or open brace, found 'setBrowserInfoCookie('
(459,1): run-time error CSS1019: Unexpected token, found '$'
(459,2): run-time error CSS1019: Unexpected token, found '('
(459,11): run-time error CSS1031: Expected selector, found ')'
(459,11): run-time error CSS1025: Expected comma or open brace, found ')'
(474,2): run-time error CSS1019: Unexpected token, found ')'
(477,10): run-time error CSS1031: Expected selector, found 'b64EncodeUnicode('
(477,10): run-time error CSS1025: Expected comma or open brace, found 'b64EncodeUnicode('
(483,10): run-time error CSS1031: Expected selector, found 'b64DecodeUnicode('
(483,10): run-time error CSS1025: Expected comma or open brace, found 'b64DecodeUnicode('
 */
/**
* Zajednička programska logika MOBILNE stranice tražilice pokojnika.
* "Per-tenant" razlike definirati izravno u stranici ili korisnikovom ~/Scripts/App direktoriju.
* Dependency o vanjskim library-jima: AxWebGIS, OData.
*/
var sizechanged = false;
var refreshPhotoTrack = false;
var exec_wait_cnt = 0; // waiting on exec_wait_cnt queries to finish (hide "loading" afterwards)
var loading_timeout_handle;
var currDeceased;
var query_executed = "";
var lastinfodict = null;

function RowSelected_Handler(tableID, infodict)
{
    lastinfodict = infodict;
    // switch to info page
    // isprazni galeriju i sakrij gumb
    $(".gallery").empty();
    $("#fotocollapsible h1").css("display", "none");
    $.mobile.changePage("#infopage", "flip", true, false);
    $("#detailscollapsible").collapsible( "expand" );
    
    currDeceased = undefined;
    if (tableID == "TablicaPokojnika") {
        $("#DeceasedInfo").show();
        $("#OwnerInfo").hide();
        $("#DeceasedInfo .editable").removeClass('editable-unsaved');
        $("#postdeceased").hide();
        currDeceased = {
           HANDLE_KARTA:    infodict["HANDLE_KARTA"]
          ,UKOPANI_GUID:   infodict["SYNC_GUID"]
          ,IME_OSOB:       "" // default - ne mijenjaj
          ,PREZIME_OSOB:   ""
          ,DJEV_PREZIME_OSOB: ""
          ,DATUM_RODJENJA: ""
          ,DATUM_SMRTI:    ""
          ,STAROST_GODINA: ""
          ,BRISANJE: "ne"
        };
        if(typeof(userAuthorized) == "boolean" && userAuthorized) {
            $("#deldeceased").show();
            if(infodict["SYNC_GUID"] == "") // novi
                return;
        }

    }
    else {
        $("#DeceasedInfo").hide();
        $("#OwnerInfo").show();				
    }    

    var groblje = groblja[infodict.NAZIV_GROB];

    // ako nema posebnih podataka o groblju isključi minimap
    if (groblje == undefined)
    {
        $("#minimap").css("display", "none");
        $("#alt_minimap").css("display", "block");
        //        map.zoomToExtent(map.Map.maxExtent);
        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
    if (infodict.KRATICA_OGRMJ != "" || infodict.KRATICA_PGRMJ != "")
        polje = AxWebGIS_CemeteryMinimap.highlightPolje(infodict.NAZIV_GROB, infodict.KRATICA_OGRMJ, infodict.KRATICA_PGRMJ);
    // 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, AxWebGIS_CemeteryMap.Map.zoom < 8 ? 8 : AxWebGIS_CemeteryMap.Map.zoom);
        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);
    }

    if (infodict.FOTOCNT && (infodict.FOTOCNT > 0) && ($("#fotocollapsible").length > 0)) {
        var myPOIGUID = infodict.HANDLE_KARTA;
        OData.defaultHttpClient.enableJsonpCallback = true;
        OData.request({
            requestUri: ToAppPath("ObevBlobs.svc/PoiGuidPhotos?POI_GUID=%27" + myPOIGUID + "%27"),
                headers: { "Content-Type": "application/json" }
            }
            ,function (data, response) {
                if (data.results.length > 0 && data.results[0].POI_GUID == myPOIGUID) {
                    $.each(data.results, function (key, value) {
                        $(".gallery").append('<a href="' + (window.location.protocol === "https:" ? value.FILE_PATH.replace("http:", "https:") : value.FILE_PATH) + '"><img class="gallerythumbs" src="' + (window.location.protocol === "https:" ? value.FILE_PATH.replace("http:", "https:") : value.FILE_PATH) + '" /></a>');
                    });
                    $('.gallery').featherlightGallery();
                    $("#fotocollapsible h1").css("display", "block");
                }
            }
            , function (err) {
            }
            ,OData.jsonHandler
        );
    }

}

function NullStr(val)
{
    return val == null ? "" : val;
}

function BeforeData_Handler(rowcount)
{
    HideMobileLoadingBar();
    $("#postdeceased").hide();
    if((query_executed == 'deceasedsearch') || (web_ukopani_viewModel.LastShapeHandle() == ""))
        $("#adddeceased").hide();
    if ((query_executed == 'deceasedsearch') && (rowcount == 0)) {
        if (typeof (toastr) === "object")
            toastr.warning("Podaci nisu pronađeni. Promijenite zadane kriterije..");
        else
            alertify.log("Podaci nisu pronađeni. Promijenite zadane kriterije..");
    }
    else if ((query_executed == 'deceasedsearch') && (rowcount > 0))
        alertify.log("Podaci su dohvaćeni.<br>Za detalje kliknite na željeni red!");
    else if(typeof(userAuthorized) == "boolean" && userAuthorized && (query_executed == 'postdeceased') && (rowcount > 0))
        alertify.success('Podaci su snimljeni..');
    else if (typeof(userAuthorized) == "boolean" && userAuthorized && (query_executed == 'deldeceased') && (rowcount == 0)) 
    {
        alertify.success('Podatak o ukopu je obrisan..');
        $("#DeceasedInfo").hide();   
    }
    else if(typeof(userAuthorized) == "boolean" && userAuthorized && (query_executed == 'poiguidsearch') && web_ukopani_viewModel.LastShapeHandle() != "")
        $("#adddeceased").show();
}

function ShowMobileLoadingBar() {
    $.mobile.loading('show', {
        text: 'Tražim...',
        textVisible: true,
        theme: 'b'
    });
    // set timeout to 15s
    loading_timeout_handle = setTimeout(function() {
            exec_wait_cnt = 0;
            $.mobile.loading('hide');
            alertify.error("..spori odaziv web servisa ili poteškoće u internet vezi..");
        }
    ,15000);
}

function HideMobileLoadingBar(cancelall) {
    cancelall = (typeof cancelall === "undefined") ? false : cancelall;
    if (cancelall)
        exec_wait_cnt = 0;
    else
        exec_wait_cnt = --exec_wait_cnt < 0 ? 0 : exec_wait_cnt;    
    if(exec_wait_cnt == 0) {
        $.mobile.loading('hide');        
        clearTimeout(loading_timeout_handle);
    }
}

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 == "")
        $.mobile.changePage("#helppage", "flip", true, false);
    else {
        exec_wait_cnt = ++exec_wait_cnt;
        query_executed = 'deceasedsearch';
        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)
            }
        );
        $.mobile.changePage("#overviewtablepage", "flip", true, false);
        $("#PregledPokojnika").show();
        $("#PregledKorisnika").hide();
        $("#postdeceased").hide();
        $("#adddeceased").hide();
        
        ShowMobileLoadingBar();
    }
};

function ExecuteSearchVlasnici() {
    if (document.forms["form2"].tform2ImePrezime.value) {
        exec_wait_cnt = ++exec_wait_cnt;
        query_executed = 'ownersearch';
        if ($('#tform2Aktivnost').is(":checked")) {
            web_vlasnici_viewModel.execQuery(ToAppPath("Trazilica.svc/V_WEB_VLASNICI?$inlinecount=allpages&$orderby=AKTIVAN_VLAS,NAZIV_POSP&$filter=substringof('" + document.forms["form2"].tform2ImePrezime.value + "',NAZIV_POSP) and AKTIVAN_VLAS eq 'da'"));
        }
        else {
            web_vlasnici_viewModel.execQuery(ToAppPath("Trazilica.svc/V_WEB_VLASNICI?$inlinecount=allpages&$orderby=AKTIVAN_VLAS,NAZIV_POSP&$filter=substringof('" + document.forms["form2"].tform2ImePrezime.value + "',NAZIV_POSP)"));
        }
        $.mobile.changePage("#overviewtablepage", "flip", true, false);
        $("#PregledPokojnika").hide();
        $("#PregledKorisnika").show();
        $("#postdeceased").hide();
        $("#adddeceased").hide();

        ShowMobileLoadingBar();
    } else {
        $.mobile.changePage("#helppage", "flip", true, false);
    }

};


function poiguidSearch(poiguid) {
    if(typeof(poiguid) == "string")
        poiguid = [poiguid];
    $("#PregledPokojnika").show();
    exec_wait_cnt = ++exec_wait_cnt;
    query_executed = 'poiguidsearch';
    $("#adddeceased").hide();
    web_ukopani_viewModel.LastShapeHandle("");
    web_ukopani_viewModel.execQuery(ToAppPath("Trazilica.svc/V_WEB_UKOPANI?$inlinecount=allpages&$orderby=DATUM_SMRTI desc,ID_UKOP desc&$filter="),
        {HANDLE_KARTA: poiguid}
    );
    if (typeof(userAuthorized) == "boolean" && userAuthorized) {
        $("#PregledKorisnika").show();
        $("#OwnerInfo").show();

        exec_wait_cnt = ++exec_wait_cnt;        
        web_vlasnici_viewModel.execQuery(ToAppPath("Trazilica.svc/V_WEB_VLASNICI?$inlinecount=allpages&$orderby=AKTIVAN_VLAS,NAZIV_POSP&$filter="),
        {HANDLE_KARTA: poiguid}
        );        
    }
    else {
        $("#PregledKorisnika").hide();
        $("#OwnerInfo").hide();

    }
    $.mobile.changePage("#overviewtablepage", "flip", true, false);
    ShowMobileLoadingBar();
}

function ShapeSelected_Handler(poiguid)
{
    if (typeof(userAuthorized) == "boolean" && userAuthorized) {
        $('#selectgrmjclickedactionpage').attr('data-poiguid', poiguid);
        $("#lnkDialog").click();
    }
    else
        poiguidSearch(poiguid);
}

function fixMapSize() {
    if (sizechanged && $('#mappage').is(':visible')) {
        var footer = $("div[data-role='footer']:visible"),
            content = $("div[data-role='content']:visible:visible"),
            viewHeight = $(window).height(),
            contentHeight = viewHeight - footer.outerHeight();

        $("#map").css("height", (contentHeight - 1).toString() + "px");
        $("#map").css("width", "100%");
        AxWebGIS_CemeteryMap.Map.updateSize();
        sizechanged = false;
    }
}

function PhotoGalery() {
    refreshPhotoTrack = true; // refresh PhotoTrack afterwards
    window.open(ToAppPath('ObevBlobs/GetImages/') + $('#selectgrmjclickedactionpage').attr('data-poiguid').split(',')[0]);
}

function fillGrobljaList() {
   //popuni groblja u select
    OData.defaultHttpClient.enableJsonpCallback = true;
   // fix groblje 
    OData.read(ToAppPath("Trazilica.svc/V_WEB_GROBLJA?$inlinecount=allpages&$orderby=NAZIV_GROB"), succPopisGroblja, errPopisGroblja);

    function succPopisGroblja(data) {
        var selectGrobljaHtml;
        // ukoliko je definirana FixNazivGroblja, fiksiraj odabir
        if (typeof(FixNazivGroblja) == "string")
            selectGrobljaHtml = "<OPTION VALUE='" + FixNazivGroblja + "'>" + FixNazivGroblja + "</OPTION>";
        else {
            selectGrobljaHtml = "<OPTION VALUE='%'>-- sva dostupna groblja --</OPTION>";
            $.each(data.results, function (key, value) { selectGrobljaHtml += "<OPTION VALUE='" + value.NAZIV_GROB + "'>" + value.NAZIV_GROB + "</OPTION>"; });
        }
        $("#sform1Groblje").html(selectGrobljaHtml);
        $("#sform1Groblje").trigger("change");
    }

    function errPopisGroblja(err) {
        alertify.error("Greška pri dohvatu podataka o grobljima!");
    }
}

function init() {
    OData.defaultHttpClient.enableJsonpCallback = true;
    OData.defaultHandler = OData.jsonHandler; // OData.atomHandler
    $.fn.editable.defaults.mode = 'inline';   
    $.fn.editableform.buttons = '<button type="submit" class="editable-submit">Prihvati</button>'+'<button type="button" class="editable-cancel">Odustani</button>';
    alertify.set({delay: 2500});
    initGroblja();
    fillGrobljaList();
    AxWebGIS_CemeteryMinimap.init(groblja);
    AxWebGIS_CemeteryMap.init(groblja, "map", true, ShapeSelected_Handler);
    web_ukopani_viewModel.init(true);
    web_vlasnici_viewModel.init(true);
    // event handler-i
    $(window).bind("orientationchange resize", function() {sizechanged = true; fixMapSize()});
    $("#plus").bind('click', function(){AxWebGIS_CemeteryMap.Map.zoomIn();});
    $("#minus").bind('click', function(){AxWebGIS_CemeteryMap.Map.zoomOut();});
    $("#locateme").bind('click', function () {
        if (window.location.protocol != 'https:') {
            var datahash = "#locateme";
            if (lastinfodict != null)
                datahash = datahash + "+data+" + encodeURI(b64EncodeUnicode(JSON.stringify(lastinfodict)));
            alertify.log('Prelazak na sigurnu/https vezu..');
            setTimeout(function () { window.location.replace("https://" + window.location.hostname + window.location.pathname.replace(/TraziPok.html/ig, "Mobile") + datahash); }, 1000);
        }
        else
            AxWebGIS_CemeteryMap.startGeoLocation();
    });
    $('#mappage').bind('pageshow', function (){fixMapSize();});
    sizechanged = true;
    fixMapSize();
    $("#alt_minimap").css("display", "none");
    
    $("#PregledKorisnika").hide();
    $("#PregledPokojnika").hide();
    $("#DeceasedInfo").hide();
    $("#OwnerInfo").hide();
    $("#postdeceased").hide();
    $("#adddeceased").hide();
    $("#deldeceased").hide();
    if (typeof(userAuthorized) == "boolean" && userAuthorized){
        $(".pretragaVlasnika").show();
    }
    else {
        $(".pretragaVlasnika").hide();
    }

    // catch "pageshow" event on the mappage
    $("#mappage" ).on( "pageshow", function( event, ui ) {
        if(refreshPhotoTrack) {
            refreshPhotoTrack = false;
            AxWebGIS_CemeteryMap.populatePhotoTrack();
        }
    });

    // preferiramo toastr umjesto alertify -> remapiraj funkcije
    if (( typeof(alertify) === "object" ) && ( typeof( toastr ) === "object" )) {
        alertify.log = toastr.info;
        alertify.success = toastr.success;
        alertify.error = toastr.error;
        toastr.options.positionClass = 'toast-top-left';
    }

    // redirected to https from http, load last deceased
    var locateme = window.location.hash > "" && window.location.hash.substr(0, 9) == "#locateme";
    var dataparam = window.location.hash > "" && window.location.hash.indexOf('+data+') > -1 ? window.location.hash.substr(window.location.hash.indexOf('+data+') + 6) : "";
    if (dataparam) {
        try {
            var myitem = JSON.parse(b64DecodeUnicode(decodeURI(dataparam)));
            for (var property in myitem) {
                if (myitem.hasOwnProperty(property)) {
                    $("#DeceasedInfo [data-columnname='" + property + "']").text(myitem[property]);
                }
            }
            RowSelected_Handler("TablicaPokojnika", myitem);
            $("#minimapcollapsible").collapsible("expand");
        }
        catch (err) {
            window.location.hash = "";
        }
    }
    if (window.location.protocol == 'https:' && locateme) {
        AxWebGIS_CemeteryMap.startGeoLocation("geoloc_reloadhttps"); // start positioning
        setTimeout(function () { $.mobile.changePage("#mappage", "flip", true, false); }, 1000);
    }
}

function validateDeceased(response, newValue)
{
    currDeceased[$(this).attr("data-columnname")] = newValue;
    $("#postdeceased").show();
}

function delCurrDeceased()
{
    alertify.set({ labels: {ok: "Prihvati", cancel : "Odustani"}});
    alertify.confirm('Obrisati trenutno izabrani slog pokojnika?', function (e) {
        if(e){
            currDeceased["BRISANJE"] = "da";
            postCurrDeceased();
        }
    });   
}

function postCurrDeceased()
{
    if(currDeceased) {
        if (currDeceased["BRISANJE"] == "da")
            query_executed = "deldeceased";
        else
            query_executed = "postdeceased";    
        web_ukopani_viewModel.execQuery(ToAppPath("Trazilica.svc/SpWebUkopaniIUD?"), currDeceased, true);
        $("#DeceasedInfo .editable").removeClass('editable-unsaved');  
        $.mobile.changePage("#overviewtablepage", "flip", true, false);
    }    
}

/**
* Sets info cookie "browserinfo" with additional data about client browser eg. {"display":[1680,1050,1,24],"tzone":-1,"lang":"hr"}
*/
function setBrowserInfoCookie() {        
    if ((window.location.protocol != 'https:') || document.cookie.indexOf("browserinfo") >= 0)
        return;    
    info = {};
    info.display = [
        Math.max(screen.width, screen.height),
        Math.min(screen.width, screen.height),
        devicePixelRatio,
        screen.colorDepth
    ];
    info.tzone = new Date().getTimezoneOffset() / 60;
    if (typeof (navigator.language) != "undefined")
        info.lang = navigator.language;
    else if (typeof (navigator.browserLanguage) != "undefined")
        info.lang = navigator.language;
    else
        info.lang = "undefined";
            
    document.cookie = "browserinfo=" + JSON.stringify(info);
}

$(document).on("pagecontainershow", function (event, ui) {
    switch (ui.toPage[0].id) {
        case 'searchpage':
            if ($("#tform2ImePrezime").is(":visible")) {
                //vlasnici tab
                $("#tabform1Pokojnici").removeClass("ui-btn-active");
                $("#tabform2Vlasnici").addClass("ui-btn-active");
            }
            else {
                //pokojni tab
                $("#tabform1Pokojnici").addClass("ui-btn-active");
                $("#tabform2Vlasnici").removeClass("ui-btn-active");
            }
            break;
    }
});

// base 64 encode, decode
function b64EncodeUnicode(str) {
    return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
        return String.fromCharCode('0x' + p1);
    }));
}

function b64DecodeUnicode(str) {
    return decodeURIComponent(Array.prototype.map.call(atob(str), function (c) {
        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
    }).join(''));
}
