﻿

(function ($) {

    $.fn.ddTableFilter = function (options) {
        options = $.extend(true, $.fn.ddTableFilter.defaultOptions, options);

        return this.each(function () {
            if ($(this).hasClass('ddtf-processed')) {
                refreshFilters(this);
                return;
            }
            var table = $(this);
            var start = new Date();

            $('th:visible', table).each(function (index) {
                if ($(this).hasClass('skip-filter')) return;
                var selectbox = $('<select>');
                var values = [];
                var opts = new Array();
                selectbox.append('<option value="--all--">' + $(this).text() + '</option>');

                var col = $('tr:not(.skip-filter) td:nth-child(' + (index + 1) + ')', table).each(function (index) {
                    var cellVal = options.valueCallback.apply(this);
                    if (cellVal.length == 0) {
                        cellVal = '--empty--';
                    }
                    $(this).attr('ddtf-value', cellVal);

                    if ($.inArray(cellVal, values) === -1) {
                        var cellText = options.textCallback.apply(this);
                        if (cellText.length == 0) { cellText = options.emptyText; }
                        values.push(cellVal);
                        opts.push({ val: cellVal, text: cellText });
                    }
                });
                if (opts.length < options.minOptions) {
                    return;
                }
                if (options.sortOpt) {
                    opts.sort(options.sortOptCallback);
                }
                $.each(opts, function () {
                    $(selectbox).append('<option value="' + this.val + '">' + this.text + '</option>')
                });

                $(this).wrapInner('<div style="display:none">');
                $(this).append(selectbox);

                selectbox.bind('change', { column: col }, function (event) {
                    var changeStart = new Date();
                    var value = $(this).val();

                    event.data.column.each(function () {
                        if ($(this).attr('ddtf-value') === value || value == '--all--') {
                            $(this).removeClass('ddtf-filtered');
                        }
                        else {
                            $(this).addClass('ddtf-filtered');
                        }
                    });
                    var changeStop = new Date();
                    if (options.debug) {
                        console.log('Search: ' + (changeStop.getTime() - changeStart.getTime()) + 'ms');
                    }
                    refreshFilters(table);
                    var changeStop = new Date();

                });
                table.addClass('ddtf-processed');
                if ($.isFunction(options.afterBuild)) {
                    options.afterBuild.apply(table);
                }
            });


            function refreshFilters(table) {
                var refreshStart = new Date();
                $('tr', table).each(function () {
                    var row = $(this);
                    if ($('td.ddtf-filtered', row).length > 0) {
                        options.transition.hide.apply(row, options.transition.options);
                    }
                    else {
                        options.transition.show.apply(row, options.transition.options);
                    }
                });

                if ($.isFunction(options.afterFilter)) {
                    options.afterFilter.apply(table);
                }

                if (options.debug) {
                    var refreshEnd = new Date();
                    console.log('Refresh: ' + (refreshEnd.getTime() - refreshStart.getTime()) + 'ms');
                }
            }

            if (options.debug) {
                var stop = new Date();
                console.log('Build: ' + (stop.getTime() - start.getTime()) + 'ms');
            }
        });

    }

    $.fn.ddTableFilter.defaultOptions = {
        valueCallback: function () {
            return escape($.trim($(this).text()));
        },
        textCallback: function () {
            return $.trim($(this).text());
        },
        sortOptCallback: function (a, b) {
            return a.text.toLowerCase() > b.text.toLowerCase();
        },
        afterFilter: null,
        afterBuild: null,
        transition: {
            hide: $.fn.hide,
            show: $.fn.show,
            options: []
        },
        emptyText: '--Empty--',
        sortOpt: true,
        debug: false,
        minOptions: 2
    }

})(jQuery);


/* On load */
$(document).ready(function () {

    EndRequestHandler(0, 0);
    // This adds the request handler that ensures the functions above are called 
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

    // Initialize static fancybox 
    $('a[rel*=fancybox]').fancybox()

    // Initialize static fancybox 
    $('a[rel*=fancybox75]').fancybox(
        {
            'width': '75%',
            'height': '75%'
        }
    )

    // Initialize static fancybox 
    $('a[rel*=fancybox90]').fancybox(
        {
            'width': '90%',
            'height': '90%'
        }
    )


    // Initialize treeviews, used in catalogs 
    $("#treeview").treeview({
        control: "#treecontrol",
        collapsed: true,
        unique: false
    });
});



function EndRequestHandler(sender, args) {

    // Update panels are retarded and mess with the postback, this restores the postback url
    Sys.Application.add_load(function () {
        var form = Sys.WebForms.PageRequestManager.getInstance()._form;
        form._initialAction = form.action = window.location.href;
    });
    //Date pickers on our date pick fields
    //$(".datePicker").datepicker();

    // Add a class called "Odd" to all the odd rows
    $("tr:odd").addClass("odd");
    $("th:odd").addClass("odd");
    $("td:odd").addClass("odd");

    // After every asynchronous call we re-parse the images to "fancyboxify"
    $('a[rel*=fancybox]').fancybox()

    // After every asynchronous call we ensure our accordions are initializaed 
    /*
    $("#accordion").accordion({
    header: ".ui-accordion-header",
    active: 0
    });
    */
    // After every asynchronous call we ensure our tables are sortable again 
    $("table[rel*=sortable]").tablesorter({ widgets: ['zebra'] });
    $(".tablesorter").tablesorter({ widgets: ['zebra'] });


    //alert('a')
    $(".BandResult").ddTableFilter(
                { emptyText: "" }
                
            );


    html5input();

};

function getInternetExplorer8OrWorse()
// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    if (rv >= 9.0) {
        rv = -1;    //9 or better, so we're fine with this.
    }

    return rv;
}


//Fix input typers to html5 - xtype -> type
function html5input() {
    var ver = getInternetExplorer8OrWorse();
    if (ver == -1) {    //Good
        var a = document.getElementsByTagName('input');
        for (var i = 0; i < a.length; i++) {
            if (a[i].getAttribute('xtype')) {
                a[i].removeAttribute('type');
                a[i].setAttribute('type', a[i].getAttribute('xtype'));
                a[i].removeAttribute('xtype');
            };
        };
    };
}



//onclientclick = "PleaseWaitButton(this,'Please Wait...')";
function PleaseWaitButton(obj, message) {

    if (typeof (Page_ClientValidate) == 'function') {
        if (Page_ClientValidate()) {
            obj.disabled = true;
            obj.value = message;
            return true;
        }
    }
    return false;
};



function getWindowHeight() {
    var windowHeight = 0;
    if (typeof (window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        }
        else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }
    return windowHeight;
};

function getWindowWidth() {
    var windowWidth = 0;
    if (typeof (window.innerWidth) == 'number') {
        windowWidth = window.innerWidth;
    }
    else {
        if (document.documentElement && document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        }
        else {
            if (document.body && document.body.clientWidth) {
                windowWidth = document.body.clientWidth;
            }
        }
    }
    return windowWidth;
};


function setFooter() {

    if (document.getElementById) {
        var windowHeight = getWindowHeight();
        if (windowHeight > 0) {

            var headerHeight;
            if (document.getElementById('header')) {
                headerHeight = document.getElementById('header').offsetHeight;
            } else {
                headerHeight = 0;
            }

            var contentHeight;
            if (document.getElementById('contents')) {
                contentHeight = document.getElementById('contents').offsetHeight;
            } else {
                contentHeight = 0;
            }


            var footerHeight;
            var footerElement;
            if (document.getElementById('footer')) {
                footerElement = document.getElementById('footer');
                footerHeight = document.getElementById('footer').offsetHeight;
            } else {
                footerHeight = 0;
            }

            if (document.getElementById('footer_static')) {
                footerElement = document.getElementById('footer_static');
                footerHeight = footerHeight + document.getElementById('footer_static').offsetHeight;
            }


            //var footerHeight = footerElement.offsetHeight;
            if (footerElement) {
                if (windowHeight - (headerHeight + contentHeight + footerHeight) >= 0) {
                    footerElement.style.top = (windowHeight - (headerHeight + contentHeight + footerHeight)) + 'px';
                }
                else {
                    footerElement.style.top = '0px';
                }
            }
        }

    }
};

window.onload = function () { setFooter(); };
window.onresize = function () { setFooter(); };



function QuickAdd(ArtikelId, Quantity, statusObject) {
    //alert('a');
    var loadUrl = "/ajax/QuickAdd.aspx?ArtikelId=" + ArtikelId + "&Quantity=" + Quantity

    $.ajax({
        type: "GET",
        url: loadUrl,
        error: function (responseText) {
            alert('Error ' + responseText);
        },
        success: function (responseText) {
            if (responseText == "0") {
                alert('Error');
            } else {
                alert("Uw artikel is toegevoegd:\n" + responseText + " in bestellijst.");
            }
        }
    });
}



/* aqFloater v1.1 - Floats an element that attaches itself to a part of the browser window.
Copyright (C) 2009 paul pham <http://aquaron.com/~jquery/aqFloater>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
(function ($) {
    $.fn.aqFloater = function ($o) {
        var _opts = $.extend({
            offsetX: 0, offsetY: 0, attach: '', duration: 50, opacity: '.9'
        }, $o);

        var $obj = this;
        $obj.css({ position: 'absolute', opacity: _opts.opacity });

        var _show = function () {
            var _de = document.documentElement;

            var _y = (_opts.attach.match(/n/) ? 0
            : (_opts.attach.match(/s/)
               ? (_de.clientHeight - $obj.outerHeight() - 10)
               : Math.round((_de.clientHeight - $obj.height()) / 2)));

            var _x = (_opts.attach.match(/w/) ? 0
            : (_opts.attach.match(/e/)
               ? (_de.clientWidth - $obj.outerWidth() - 10)
               : Math.round((_de.clientWidth - $obj.width()) / 2)));

            $obj.animate({
                top: (_y + $(document).scrollTop() + _opts.offsetY) + 'px',
                left: (_x + $(document).scrollLeft() + _opts.offsetX) + 'px'
            }, { queue: false, duration: _opts.duration });
        };

        $(window).scroll(_show).resize(_show);

        $(window).trigger('scroll');
    };
})(jQuery);











(function ($) {
    $.prettyLoader = { version: '1.0.1' }; $.prettyLoader = function (settings) {
        settings = jQuery.extend({ animation_speed: 'fast', bind_to_ajax: true, delay: false, loader: '/images/prettyLoader/ajax-loader.gif', offset_top: 13, offset_left: 10 }, settings); scrollPos = _getScroll(); imgLoader = new Image(); imgLoader.onerror = function () { alert('Preloader image cannot be loaded. Make sure the path is correct in the settings and that the image is reachable.'); }; imgLoader.src = settings.loader; if (settings.bind_to_ajax)
            jQuery(document).ajaxStart(function () { $.prettyLoader.show() }).ajaxStop(function () { $.prettyLoader.hide() }); $.prettyLoader.positionLoader = function (e) { e = e ? e : window.event; cur_x = (e.clientX) ? e.clientX : cur_x; cur_y = (e.clientY) ? e.clientY : cur_y; left_pos = cur_x + settings.offset_left + scrollPos['scrollLeft']; top_pos = cur_y + settings.offset_top + scrollPos['scrollTop']; $('.prettyLoader').css({ 'top': top_pos, 'left': left_pos }); }
        $.prettyLoader.show = function (delay) {
            if ($('.prettyLoader').size() > 0) return; scrollPos = _getScroll(); $('<div></div>').addClass('prettyLoader').addClass('prettyLoader_' + settings.theme).appendTo('body').hide(); if ($.browser.msie && $.browser.version == 6)
                $('.prettyLoader').addClass('pl_ie6'); $('<img />').attr('src', settings.loader).appendTo('.prettyLoader'); $('.prettyLoader').fadeIn(settings.animation_speed); $(document).bind('click', $.prettyLoader.positionLoader); $(document).bind('mousemove', $.prettyLoader.positionLoader); $(window).scroll(function () { scrollPos = _getScroll(); $(document).triggerHandler('mousemove'); }); delay = (delay) ? delay : settings.delay; if (delay) { setTimeout(function () { $.prettyLoader.hide() }, delay); }
        }; $.prettyLoader.hide = function () { $(document).unbind('click', $.prettyLoader.positionLoader); $(document).unbind('mousemove', $.prettyLoader.positionLoader); $(window).unbind('scroll'); $('.prettyLoader').fadeOut(settings.animation_speed, function () { $(this).remove(); }); }; function _getScroll() { if (self.pageYOffset) { return { scrollTop: self.pageYOffset, scrollLeft: self.pageXOffset }; } else if (document.documentElement && document.documentElement.scrollTop) { return { scrollTop: document.documentElement.scrollTop, scrollLeft: document.documentElement.scrollLeft }; } else if (document.body) { return { scrollTop: document.body.scrollTop, scrollLeft: document.body.scrollLeft }; }; }; return this;
    };
})(jQuery);






