﻿// ---------------------------------------------------------------------------------------- //
// -- INIT -- //
// ---------------------------------------------------------------------------------------- //

Sys.Application.add_init(AppInit);

function AppInit(sender) {

    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(Start);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(End);

}

function Start(sender, args) {


    if (sender._postBackSettings.sourceElement != null) {

        //*** init ***
        var dataItem = sender._postBackSettings.sourceElement.id;


        //*** overzicht - datapager ***
        try {
            if ((dpAanbodTop != null) && (dataItem.indexOf(dpAanbodTop.id) != -1)) {
                blockOverzicht();
            }
        }catch(e){}
      

        //*** overzicht - datapager ***
        try {
            if ((dpAanbodBottom != null) && (dataItem.indexOf(dpAanbodBottom.id) != -1)) {
                blockOverzicht();
            }
        } catch (e) { }

        //*** overzicht - prijs ASC ***
        try {
            if ((lnkSortPriceASC != null) && (dataItem.indexOf(lnkSortPriceASC.id) != -1)) {
                blockOverzicht();
            }
        } catch (e) { }

        //*** overzicht - prijs DESC ***
        try {
            if ((lnkSortPriceDESC != null) && (dataItem.indexOf(lnkSortPriceDESC.id) != -1)) {
                blockOverzicht();
            }
        } catch (e) { }

        //*** overzicht - gemeente ASC ***
        try {
            if ((lnkSortCityASC != null) && (dataItem.indexOf(lnkSortCityASC.id) != -1)) {
                blockOverzicht();
            }
        } catch (e) { }

        //*** overzicht - gemeente DESC ***
        try {
            if ((lnkSortCityDESC != null) && (dataItem.indexOf(lnkSortCityDESC.id) != -1)) {
                blockOverzicht();
            }
        } catch (e) { }



        //*** filters - transactie ***
        try {
            if ((ddlTransactie != null) && (dataItem.indexOf(ddlTransactie.id) != -1)) {
                blockFilters();
            }
        } catch (e) { }

        //*** filters - hoofdtype ***
        try {
            if ((ddlHoofdType != null) && (dataItem.indexOf(ddlHoofdType.id) != -1)) {
                blockFilters();
            }
        } catch (e) { }

        //*** filters - type ***
        try {
            if ((ddlType != null) && (dataItem.indexOf(ddlType.id) != -1)) {
                blockFilters();
            }
        } catch (e) { }

        //*** filters - gemeente ***
        try {
            if ((ddlGemeente != null) && (dataItem.indexOf(ddlGemeente.id) != -1)) {
                blockFilters();
            }
        } catch (e) { }

        //*** filters - prijsklasse ***
        try {
            if ((ddlPrijs != null) && (dataItem.indexOf(ddlPrijs.id) != -1)) {
                blockFilters();
            }
        } catch (e) { }

        //*** filters - zoeken ***
        try {
            if ((btnPandenZoeken != null) && (dataItem.indexOf(btnPandenZoeken.id) != -1)) {
                blockOverzicht();
            }
        } catch (e) { }

      
    } else {

        unblockAll();

    }

}

function End(sender, args) {

    unblockAll();   
   
}

// ---------------------------------------------------------------------------------------- //
// -- FUNCTIES -- //
// ---------------------------------------------------------------------------------------- //


function blockOverzicht() {

    $(".aanbod-blockUI").block({ message: $('.loader'),
        css: {
            padding: 0,
            margin: 0,
            width: '160px',
            height: '50px',
            textAlign: 'center',
            color: '#000',
            border: 'none',
            backgroundColor: '#ffffff',
            cursor: 'wait'
        },
        overlayCSS: {
            backgroundColor: '#ffffff',
            opacity: 1
        }

    });

}

function blockFilters() {

    $('.filter-blockUI').block({
        message: $('.zoek-filter-busy'),
        css: {
            padding: 0,
            margin: 0,
     
            textAlign: 'center',
            color: '#000',
            border: 'none',
            backgroundColor: '#ffffff',
            cursor: 'wait'
        },
        overlayCSS: {
            backgroundColor: '#ffffff',
            opacity: 1
        }
    });

  
}

function unblockAll() {
    $(".filter-blockUI").unblock();
    $(".aanbod-blockUI").unblock();
    $.unblockUI();
}
