/*
 * Simple jQuery logger / debugger.
 * Based on: http://jquery.com/plugins/Authoring/
 * See var DEBUG below for turning debugging/logging on and off.
 *
 * @version   20070111
 * @since     2006-07-10
 * @copyright Copyright (c) 2006 Glyphix Studio, Inc. http://www.glyphix.com
 * @author    Brad Brizendine <brizbane@gmail.com>
 * @license   MIT http://www.opensource.org/licenses/mit-license.php
 * @requires  >= jQuery 1.0.3
 */
// global debug switch ... add DEBUG = true; somewhere after jquery.debug.js is loaded to turn debugging on
var DEBUG = true;
// shamelessly ripped off from http://getfirebug.com/
if (!("console" in window) || !("firebug" in console)){
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
	// create the logging div
	jQuery(document).ready(
		function(){
			$(document.body).append('<div id="DEBUG"><ol></ol></div>');
		}
	);
	// attach a function to each of the firebug methods
	window.console = {};
	for (var i = 0; i < names.length; ++i){
		window.console[names[i]] = function(msg){ $('#DEBUG ol').append( '<li>' + msg + '</li>' ); }
	}
}

/*
 * debug
 * Simply loops thru each jquery item and logs it
 */
jQuery.fn.debug = function() {
	return this.each(function(){
		$.log(this);
	});
};

/*
 * log
 * Send it anything, and it will add a line to the logging console.
 * If firebug is installed, it simple send the item to firebug.
 * If not, it creates a string representation of the html element (if message is an object), or just uses the supplied value (if not an object).
 */
jQuery.log = function(message){
	// only if debugging is on
	if( window.DEBUG ){
		// if no firebug, build a debug line from the actual html element if it's an object, or just send the string
		var str = message;
		if( !('firebug' in console) ){
			if( typeof(message) == 'object' ){
				str = '&lt;';
				str += message.nodeName.toLowerCase();
				for( var i = 0; i < message.attributes.length; i++ ){
					str += ' ' + message.attributes[i].nodeName.toLowerCase() + '="' + message.attributes[i].nodeValue + '"';
				}
				str += '&gt;';
			}
		}
		console.debug(str);
	}
};
/*
 * jQuery 'onImagesLoaded' plugin v1.1.0
 * Fires callback functions when images have loaded within a particular selector.
 *
 * Copyright (c) Cirkuit Networks, Inc. (http://www.cirkuit.net), 2008.
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * For documentation and usage, visit "http://includes.cirkuit.net/js/jquery/plugins/onImagesLoad/1.1/documentation/"
 */
(function($){$.fn.onImagesLoad=function(options){var self=this;self.opts=$.extend({},$.fn.onImagesLoad.defaults,options);self.bindEvents=function($imgs,container,callback){if($imgs.length===0){if(self.opts.callbackIfNoImagesExist&&callback){callback(container);}}else{var loadedImages=[];if(!$imgs.jquery){$imgs=$($imgs);}$imgs.each(function(i,val){$(this).bind('load',function(){if(jQuery.inArray(i,loadedImages)<0){loadedImages.push(i);if(loadedImages.length==$imgs.length){if(callback){callback(container);}}}}).each(function(){if(this.complete||this.complete===undefined){this.src=this.src;}});});}};var imgAry=[];self.each(function(){if(self.opts.itemCallback){var $imgs;if(this.tagName=="IMG"){$imgs=this;}else{$imgs=$('img',this);}self.bindEvents($imgs,this,self.opts.itemCallback);}if(self.opts.selectorCallback){if(this.tagName=="IMG"){imgAry.push(this);}else{$('img',this).each(function(){imgAry.push(this);});}}});if(self.opts.selectorCallback){self.bindEvents(imgAry,this,self.opts.selectorCallback);}return self.each(function(){});};$.fn.onImagesLoad.defaults={selectorCallback:null,itemCallback:null,callbackIfNoImagesExist:false};})(jQuery);/*
*
* ADDED FOR STAGEMARKT: store a copy of the original cache of all rows
*                    this.config.cache = cache;
* 
* TableSorter 2.0 - Client-side table sorting with ease!
* Version 2.0.3
* @requires jQuery v1.2.3
* 
* Copyright (c) 2007 Christian Bach
* Examples and docs at: http://tablesorter.com
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* 
*/
/**
*
* @description Create a sortable table with multi-column sorting capabilitys
* 
* @example $('table').tablesorter();
* @desc Create a simple tablesorter interface.
*
* @example $('table').tablesorter({ sortList:[[0,0],[1,0]] });
* @desc Create a tablesorter interface and sort on the first and secound column in ascending order.
* 
* @example $('table').tablesorter({ headers: { 0: { sorter: false}, 1: {sorter: false} } });
* @desc Create a tablesorter interface and disableing the first and secound column headers.
* 
* @example $('table').tablesorter({ 0: {sorter:"integer"}, 1: {sorter:"currency"} });
* @desc Create a tablesorter interface and set a column parser for the first and secound column.
* 
* 
* @param Object settings An object literal containing key/value pairs to provide optional settings.
* 
* @option String cssHeader (optional) 			A string of the class name to be appended to sortable tr elements in the thead of the table. 
* 												Default value: "header"
* 
* @option String cssAsc (optional) 			A string of the class name to be appended to sortable tr elements in the thead on a ascending sort. 
* 												Default value: "headerSortUp"
* 
* @option String cssDesc (optional) 			A string of the class name to be appended to sortable tr elements in the thead on a descending sort. 
* 												Default value: "headerSortDown"
* 
* @option String sortInitialOrder (optional) 	A string of the inital sorting order can be asc or desc. 
* 												Default value: "asc"
* 
* @option String sortMultisortKey (optional) 	A string of the multi-column sort key. 
* 												Default value: "shiftKey"
* 
* @option String textExtraction (optional) 	A string of the text-extraction method to use. 
* 												For complex html structures inside td cell set this option to "complex", 
* 												on large tables the complex option can be slow. 
* 												Default value: "simple"
* 
* @option Object headers (optional) 			An array containing the forces sorting rules. 
* 												This option let's you specify a default sorting rule. 
* 												Default value: null
* 
* @option Array sortList (optional) 			An array containing the forces sorting rules. 
* 												This option let's you specify a default sorting rule. 
* 												Default value: null
* 
* @option Array sortForce (optional) 			An array containing forced sorting rules. 
* 												This option let's you specify a default sorting rule, which is prepended to user-selected rules.
* 												Default value: null
*  
* @option Array sortAppend (optional) 			An array containing forced sorting rules. 
* 												This option let's you specify a default sorting rule, which is appended to user-selected rules.
* 												Default value: null
* 
* @option Boolean widthFixed (optional) 		Boolean flag indicating if tablesorter should apply fixed widths to the table columns.
* 												This is usefull when using the pager companion plugin.
* 												This options requires the dimension jquery plugin.
* 												Default value: false
*
* @option Boolean cancelSelection (optional) 	Boolean flag indicating if tablesorter should cancel selection of the table headers text.
* 												Default value: true
*
* @option Boolean debug (optional) 			Boolean flag indicating if tablesorter should display debuging information usefull for development.
*
* @type jQuery
*
* @name tablesorter
* 
* @cat Plugins/Tablesorter
* 
* @author Christian Bach/christian.bach@polyester.se
*/

(function($) {
    $.extend({
        tablesorter: new function() {

            var parsers = [], widgets = [];

            this.defaults = {
                cssHeader: "header",
                cssAsc: "headerSortUp",
                cssDesc: "headerSortDown",
                sortInitialOrder: "asc",
                sortMultiSortKey: "shiftKey",
                sortForce: null,
                sortAppend: null,
                textExtraction: "simple",
                parsers: {},
                widgets: [],
                widgetZebra: { css: ["even", "odd"] },
                headers: {},
                widthFixed: false,
                cancelSelection: true,
                sortList: [],
                headerList: [],
                dateFormat: "us",
                decimal: '.',
                debug: false
            };

            /* debuging utils */
            function benchmark(s, d) {
                log(s + "," + (new Date().getTime() - d.getTime()) + "ms");
            }

            this.benchmark = benchmark;

            function log(s) {
                if (typeof console != "undefined" && typeof console.debug != "undefined") {
                    console.log(s);
                } else {
                    alert(s);
                }
            }

            /* parsers utils */
            function buildParserCache(table, $headers) {

                if (table.config.debug) { var parsersDebug = ""; }

                var rows = table.tBodies[0].rows;

                if (table.tBodies[0].rows[0]) {

                    var list = [], cells = rows[0].cells, l = cells.length;

                    for (var i = 0; i < l; i++) {
                        var p = false;

                        if ($.metadata && ($($headers[i]).metadata() && $($headers[i]).metadata().sorter)) {

                            p = getParserById($($headers[i]).metadata().sorter);

                        } else if ((table.config.headers[i] && table.config.headers[i].sorter)) {

                            p = getParserById(table.config.headers[i].sorter);
                        }
                        if (!p) {
                            p = detectParserForColumn(table, cells[i]);
                        }

                        if (table.config.debug) { parsersDebug += "column:" + i + " parser:" + p.id + "\n"; }

                        list.push(p);
                    }
                }

                if (table.config.debug) { log(parsersDebug); }

                return list;
            };

            function detectParserForColumn(table, node) {
                var l = parsers.length;
                for (var i = 1; i < l; i++) {
                    if (parsers[i].is($.trim(getElementText(table.config, node)), table, node)) {
                        return parsers[i];
                    }
                }
                // 0 is always the generic parser (text)
                return parsers[0];
            }

            function getParserById(name) {
                var l = parsers.length;
                for (var i = 0; i < l; i++) {
                    if (parsers[i].id.toLowerCase() == name.toLowerCase()) {
                        return parsers[i];
                    }
                }
                return false;
            }

            /* utils */
            function buildCache(table) {

                if (table.config.debug) { var cacheTime = new Date(); }


                var totalRows = (table.tBodies[0] && table.tBodies[0].rows.length) || 0,
					totalCells = (table.tBodies[0].rows[0] && table.tBodies[0].rows[0].cells.length) || 0,
					parsers = table.config.parsers,
					cache = { row: [], normalized: [] };

                for (var i = 0; i < totalRows; ++i) {

                    /** Add the table data to main data array */
                    var c = table.tBodies[0].rows[i], cols = [];

                    cache.row.push($(c));

                    for (var j = 0; j < totalCells; ++j) {
                        cols.push(parsers[j].format(getElementText(table.config, c.cells[j]), table, c.cells[j]));
                    }

                    cols.push(i); // add position for rowCache
                    cache.normalized.push(cols);
                    cols = null;
                };

                if (table.config.debug) { benchmark("Building cache for " + totalRows + " rows:", cacheTime); }

                return cache;
            };

            function getElementText(config, node) {

                if (!node) return "";

                var t = "";

                if (config.textExtraction == "simple") {
                    if (node.childNodes[0] && node.childNodes[0].hasChildNodes()) {
                        t = node.childNodes[0].innerHTML;
                    } else {
                        t = node.innerHTML;
                    }
                } else {
                    if (typeof (config.textExtraction) == "function") {
                        t = config.textExtraction(node);
                    } else {
                        t = $(node).text();
                    }
                }
                return t;
            }

            function appendToTable(table, cache) {

                if (table.config.debug) { var appendTime = new Date() }

                var c = cache,
					r = c.row,
					n = c.normalized,
					totalRows = n.length,
					checkCell = (n[0].length - 1),
					tableBody = $(table.tBodies[0]),
					rows = [];

                for (var i = 0; i < totalRows; i++) {
                    rows.push(r[n[i][checkCell]]);
                    if (!table.config.appender) {

                        var o = r[n[i][checkCell]];
                        var l = o.length;
                        for (var j = 0; j < l; j++) {

                            tableBody[0].appendChild(o[j]);

                        }

                        //tableBody.append(r[n[i][checkCell]]);
                    }
                }

                if (table.config.appender) {

                    table.config.appender(table, rows);
                }

                rows = null;

                if (table.config.debug) { benchmark("Rebuilt table:", appendTime); }

                //apply table widgets
                applyWidget(table);

                // trigger sortend
                setTimeout(function() {
                    $(table).trigger("sortEnd");
                }, 0);

            };

            function buildHeaders(table) {

                if (table.config.debug) { var time = new Date(); }

                var meta = ($.metadata) ? true : false, tableHeadersRows = [];

                for (var i = 0; i < table.tHead.rows.length; i++) { tableHeadersRows[i] = 0; };

                $tableHeaders = $("thead th", table);

                $tableHeaders.each(function(index) {

                    this.count = 0;
                    this.column = index;
                    this.order = formatSortingOrder(table.config.sortInitialOrder);

                    if (checkHeaderMetadata(this) || checkHeaderOptions(table, index)) this.sortDisabled = true;

                    if (!this.sortDisabled) {
                        $(this).addClass(table.config.cssHeader);
                    }

                    // add cell to headerList
                    table.config.headerList[index] = this;
                });

                if (table.config.debug) { benchmark("Built headers:", time); log($tableHeaders); }

                return $tableHeaders;

            };

            function checkCellColSpan(table, rows, row) {
                var arr = [], r = table.tHead.rows, c = r[row].cells;

                for (var i = 0; i < c.length; i++) {
                    var cell = c[i];

                    if (cell.colSpan > 1) {
                        arr = arr.concat(checkCellColSpan(table, headerArr, row++));
                    } else {
                        if (table.tHead.length == 1 || (cell.rowSpan > 1 || !r[row + 1])) {
                            arr.push(cell);
                        }
                        //headerArr[row] = (i+row);
                    }
                }
                return arr;
            };

            function checkHeaderMetadata(cell) {
                if (($.metadata) && ($(cell).metadata().sorter === false)) { return true; };
                return false;
            }

            function checkHeaderOptions(table, i) {
                if ((table.config.headers[i]) && (table.config.headers[i].sorter === false)) { return true; };
                return false;
            }

            function applyWidget(table) {
                var c = table.config.widgets;
                var l = c.length;
                for (var i = 0; i < l; i++) {

                    getWidgetById(c[i]).format(table);
                }

            }

            function getWidgetById(name) {
                var l = widgets.length;
                for (var i = 0; i < l; i++) {
                    if (widgets[i].id.toLowerCase() == name.toLowerCase()) {
                        return widgets[i];
                    }
                }
            };

            function formatSortingOrder(v) {

                if (typeof (v) != "Number") {
                    i = (v.toLowerCase() == "desc") ? 1 : 0;
                } else {
                    i = (v == (0 || 1)) ? v : 0;
                }
                return i;
            }

            function isValueInArray(v, a) {
                var l = a.length;
                for (var i = 0; i < l; i++) {
                    if (a[i][0] == v) {
                        return true;
                    }
                }
                return false;
            }

            function setHeadersCss(table, $headers, list, css) {
                // remove all header information
                $headers.removeClass(css[0]).removeClass(css[1]);

                var h = [];
                $headers.each(function(offset) {
                    if (!this.sortDisabled) {
                        h[this.column] = $(this);
                    }
                });

                var l = list.length;
                for (var i = 0; i < l; i++) {
                    h[list[i][0]].addClass(css[list[i][1]]);
                }
            }

            function fixColumnWidth(table, $headers) {
                var c = table.config;
                if (c.widthFixed) {
                    var colgroup = $('<colgroup>');
                    $("tr:first td", table.tBodies[0]).each(function() {
                        colgroup.append($('<col>').css('width', $(this).width()));
                    });
                    $(table).prepend(colgroup);
                };
            }

            function updateHeaderSortCount(table, sortList) {
                var c = table.config, l = sortList.length;
                for (var i = 0; i < l; i++) {
                    var s = sortList[i], o = c.headerList[s[0]];
                    o.count = s[1];
                    o.count++;
                }
            }

            /* sorting methods */
            function multisort(table, sortList, cache) {

                if (table.config.debug) { var sortTime = new Date(); }

                var dynamicExp = "var sortWrapper = function(a,b) {", l = sortList.length;

                for (var i = 0; i < l; i++) {

                    var c = sortList[i][0];
                    var order = sortList[i][1];
                    var s = (getCachedSortType(table.config.parsers, c) == "text") ? ((order == 0) ? "sortText" : "sortTextDesc") : ((order == 0) ? "sortNumeric" : "sortNumericDesc");

                    var e = "e" + i;

                    dynamicExp += "var " + e + " = " + s + "(a[" + c + "],b[" + c + "]); ";
                    dynamicExp += "if(" + e + ") { return " + e + "; } ";
                    dynamicExp += "else { ";
                }

                // if value is the same keep orignal order	
                var orgOrderCol = cache.normalized[0].length - 1;
                dynamicExp += "return a[" + orgOrderCol + "]-b[" + orgOrderCol + "];";

                for (var i = 0; i < l; i++) {
                    dynamicExp += "}; ";
                }

                dynamicExp += "return 0; ";
                dynamicExp += "}; ";

                eval(dynamicExp);

                cache.normalized.sort(sortWrapper);

                if (table.config.debug) { benchmark("Sorting on " + sortList.toString() + " and dir " + order + " time:", sortTime); }

                return cache;
            };

            function sortText(a, b) {
                return ((a < b) ? -1 : ((a > b) ? 1 : 0));
            };

            function sortTextDesc(a, b) {
                return ((b < a) ? -1 : ((b > a) ? 1 : 0));
            };

            function sortNumeric(a, b) {
                return a - b;
            };

            function sortNumericDesc(a, b) {
                return b - a;
            };

            function getCachedSortType(parsers, i) {
                return parsers[i].type;
            };

            /* public methods */
            this.construct = function(settings) {

                return this.each(function() {

                    if (!this.tHead || !this.tBodies) return;

                    var $this, $document, $headers, cache, config, shiftDown = 0, sortOrder;

                    this.config = {};

                    config = $.extend(this.config, $.tablesorter.defaults, settings);

                    // store common expression for speed					
                    $this = $(this);

                    // build headers
                    $headers = buildHeaders(this);

                    // try to auto detect column type, and store in tables config
                    this.config.parsers = buildParserCache(this, $headers);


                    // build the cache for the tbody cells
                    cache = buildCache(this);

                    //ADDED: store a copy of the original cache of all rows
                    this.config.cache = cache;


                    // get the css class names, could be done else where.
                    var sortCSS = [config.cssDesc, config.cssAsc];

                    // fixate columns if the users supplies the fixedWidth option
                    fixColumnWidth(this);

                    // apply event handling to headers
                    // this is to big, perhaps break it out?
                    $headers.click(function(e) {

                        $this.trigger("sortStart");

                        var totalRows = ($this[0].tBodies[0] && $this[0].tBodies[0].rows.length) || 0;

                        if (!this.sortDisabled && totalRows > 0) {


                            // store exp, for speed
                            var $cell = $(this);

                            // get current column index
                            var i = this.column;

                            // get current column sort order
                            this.order = this.count++ % 2;

                            // user only whants to sort on one column
                            if (!e[config.sortMultiSortKey]) {

                                // flush the sort list
                                config.sortList = [];

                                if (config.sortForce != null) {
                                    var a = config.sortForce;
                                    for (var j = 0; j < a.length; j++) {
                                        if (a[j][0] != i) {
                                            config.sortList.push(a[j]);
                                        }
                                    }
                                }

                                // add column to sort list
                                config.sortList.push([i, this.order]);

                                // multi column sorting
                            } else {
                                // the user has clicked on an all ready sortet column.
                                if (isValueInArray(i, config.sortList)) {

                                    // revers the sorting direction for all tables.
                                    for (var j = 0; j < config.sortList.length; j++) {
                                        var s = config.sortList[j], o = config.headerList[s[0]];
                                        if (s[0] == i) {
                                            o.count = s[1];
                                            o.count++;
                                            s[1] = o.count % 2;
                                        }
                                    }
                                } else {
                                    // add column to sort list array
                                    config.sortList.push([i, this.order]);
                                }
                            };
                            setTimeout(function() {
                                //set css for headers
                                setHeadersCss($this[0], $headers, config.sortList, sortCSS);
                                appendToTable($this[0], multisort($this[0], config.sortList, cache));
                            }, 1);
                            // stop normal event by returning false
                            return false;
                        }
                        // cancel selection	
                    }).mousedown(function() {
                        if (config.cancelSelection) {
                            this.onselectstart = function() { return false };
                            return false;
                        }
                    });

                    // apply easy methods that trigger binded events
                    $this.bind("update", function() {

                        // rebuild parsers.
                        this.config.parsers = buildParserCache(this, $headers);

                        // rebuild the cache map
                        cache = buildCache(this);

                    }).bind("sorton", function(e, list) {

                        $(this).trigger("sortStart");

                        config.sortList = list;

                        // update and store the sortlist
                        var sortList = config.sortList;

                        // update header count index
                        updateHeaderSortCount(this, sortList);

                        //set css for headers
                        setHeadersCss(this, $headers, sortList, sortCSS);


                        // sort the table and append it to the dom
                        appendToTable(this, multisort(this, sortList, cache));

                    }).bind("appendCache", function() {

                        appendToTable(this, cache);

                    }).bind("applyWidgetId", function(e, id) {

                        getWidgetById(id).format(this);

                    }).bind("applyWidgets", function() {
                        // apply widgets
                        applyWidget(this);
                    });

                    if ($.metadata && ($(this).metadata() && $(this).metadata().sortlist)) {
                        config.sortList = $(this).metadata().sortlist;
                    }
                    // if user has supplied a sort list to constructor.
                    if (config.sortList.length > 0) {
                        $this.trigger("sorton", [config.sortList]);
                    }

                    // apply widgets
                    applyWidget(this);
                });
            };

            this.addParser = function(parser) {
                var l = parsers.length, a = true;
                for (var i = 0; i < l; i++) {
                    if (parsers[i].id.toLowerCase() == parser.id.toLowerCase()) {
                        a = false;
                    }
                }
                if (a) { parsers.push(parser); };
            };

            this.addWidget = function(widget) {
                widgets.push(widget);
            };

            this.formatFloat = function(s) {
                var i = parseFloat(s);
                return (isNaN(i)) ? 0 : i;
            };
            this.formatInt = function(s) {
                var i = parseInt(s);
                return (isNaN(i)) ? 0 : i;
            };

            this.isDigit = function(s, config) {
                var DECIMAL = '\\' + config.decimal;
                var exp = '/(^[+]?0(' + DECIMAL + '0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)' + DECIMAL + '(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*' + DECIMAL + '0+$)/';
                return RegExp(exp).test($.trim(s));
            };

            this.clearTableBody = function(table) {
                if ($.browser.msie) {
                    function empty() {
                        while (this.firstChild) this.removeChild(this.firstChild);
                    }
                    empty.apply(table.tBodies[0]);
                } else {
                    table.tBodies[0].innerHTML = "";
                }
            };
        }
    });

    // extend plugin scope
    $.fn.extend({
        tablesorter: $.tablesorter.construct
    });

    var ts = $.tablesorter;

    // add default parsers
    ts.addParser({
        id: "text",
        is: function(s) {
            return true;
        },
        format: function(s) {
            return $.trim(s.toLowerCase());
        },
        type: "text"
    });

    ts.addParser({
        id: "digit",
        is: function(s, table) {
            var c = table.config;
            return $.tablesorter.isDigit(s, c);
        },
        format: function(s) {
            return $.tablesorter.formatFloat(s);
        },
        type: "numeric"
    });

    ts.addParser({
        id: "currency",
        is: function(s) {
            return /^[£$€?.]/.test(s);
        },
        format: function(s) {
            return $.tablesorter.formatFloat(s.replace(new RegExp(/[^0-9.]/g), ""));
        },
        type: "numeric"
    });

    ts.addParser({
        id: "ipAddress",
        is: function(s) {
            return /^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(s);
        },
        format: function(s) {
            var a = s.split("."), r = "", l = a.length;
            for (var i = 0; i < l; i++) {
                var item = a[i];
                if (item.length == 2) {
                    r += "0" + item;
                } else {
                    r += item;
                }
            }
            return $.tablesorter.formatFloat(r);
        },
        type: "numeric"
    });

    ts.addParser({
        id: "url",
        is: function(s) {
            return /^(https?|ftp|file):\/\/$/.test(s);
        },
        format: function(s) {
            return jQuery.trim(s.replace(new RegExp(/(https?|ftp|file):\/\//), ''));
        },
        type: "text"
    });

    ts.addParser({
        id: "isoDate",
        is: function(s) {
            return /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(s);
        },
        format: function(s) {
            return $.tablesorter.formatFloat((s != "") ? new Date(s.replace(new RegExp(/-/g), "/")).getTime() : "0");
        },
        type: "numeric"
    });

    ts.addParser({
        id: "percent",
        is: function(s) {
            return /\%$/.test($.trim(s));
        },
        format: function(s) {
            return $.tablesorter.formatFloat(s.replace(new RegExp(/%/g), ""));
        },
        type: "numeric"
    });

    ts.addParser({
        id: "usLongDate",
        is: function(s) {
            return s.match(new RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/));
        },
        format: function(s) {
            return $.tablesorter.formatFloat(new Date(s).getTime());
        },
        type: "numeric"
    });

    ts.addParser({
        id: "shortDate",
        is: function(s) {
            return /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);
        },
        format: function(s, table) {
            var c = table.config;
            s = s.replace(/\-/g, "/");
            if (c.dateFormat == "us") {
                // reformat the string in ISO format
                s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$1/$2");
            } else if (c.dateFormat == "uk") {
                //reformat the string in ISO format
                s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
            } else if (c.dateFormat == "dd/mm/yy" || c.dateFormat == "dd-mm-yy") {
                s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, "$1/$2/$3");
            }
            return $.tablesorter.formatFloat(new Date(s).getTime());
        },
        type: "numeric"
    });

    ts.addParser({
        id: "time",
        is: function(s) {
            return /^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(s);
        },
        format: function(s) {
            return $.tablesorter.formatFloat(new Date("2000/01/01 " + s).getTime());
        },
        type: "numeric"
    });


    ts.addParser({
        id: "metadata",
        is: function(s) {
            return false;
        },
        format: function(s, table, cell) {
            var c = table.config, p = (!c.parserMetadataName) ? 'sortValue' : c.parserMetadataName;
            return $(cell).metadata()[p];
        },
        type: "numeric"
    });

    // add default widgets
    ts.addWidget({
        id: "zebra",
        format: function(table) {
            if (table.config.debug) { var time = new Date(); }
            $("tr:visible", table.tBodies[0])
	        .filter(':even')
	        .removeClass(table.config.widgetZebra.css[1]).addClass(table.config.widgetZebra.css[0])
	        .end().filter(':odd')
	        .removeClass(table.config.widgetZebra.css[0]).addClass(table.config.widgetZebra.css[1]);
            if (table.config.debug) { $.tablesorter.benchmark("Applying Zebra widget", time); }
        }
    });
})(jQuery);﻿(function($) {
    $.extend({
        tablesorterPager: new function() {

        function updatePageDisplay(c) {
                //var s = $(c.cssPageDisplay, c.container).val((c.page + 1) + c.seperator + c.totalPages);
                var s = $(c.cssPageDisplay, c.container).text((c.page + 1) + c.seperator + c.totalPages);
            }

            function setPageSize(table, size) {
                var c = table.config;
                c.size = size;
                c.totalPages = Math.ceil(c.totalRows / c.size);
                c.pagerPositionSet = false;
                moveToPage(table);
                fixPosition(table);
            }

            function fixPosition(table) {
                var c = table.config;
                if (!c.pagerPositionSet && c.positionFixed) {
                    var c = table.config, o = $(table);
                    if (o.offset) {
                        c.container.css({
                            top: o.offset().top + o.height() + 'px',
                            position: 'absolute'
                        });
                    }
                    c.pagerPositionSet = true;
                }
            }

            function moveToFirstPage(table) {
                var c = table.config;
                c.page = 0;
                moveToPage(table);
            }

            function moveToLastPage(table) {
                var c = table.config;
                c.page = (c.totalPages - 1);
                moveToPage(table);
            }

            function moveToNextPage(table) {
                var c = table.config;
                c.page++;
                if (c.page >= (c.totalPages - 1)) {
                    c.page = (c.totalPages - 1);
                }
                moveToPage(table);
            }

            function moveToPrevPage(table) {
                var c = table.config;
                c.page--;
                if (c.page <= 0) {
                    c.page = 0;
                }
                moveToPage(table);
            }


            function moveToPage(table) {
                var c = table.config;
                if (c.page < 0 || c.page > (c.totalPages - 1)) {
                    c.page = 0;
                }

                renderTable(table, c.rowsCopy);
            }

            function renderTable(table, rows) {

                var c = table.config;
                var l = rows.length;
                var s = (c.page * c.size);
                var e = (s + c.size);
                if (e > rows.length) {
                    e = rows.length;
                }


                var tableBody = $(table.tBodies[0]);

                // clear the table body

                $.tablesorter.clearTableBody(table);

                for (var i = s; i < e; i++) {

                    // tableBody.append(rows[i]);

                    var o = rows[i];
                    var l = o.length;
                    for (var j = 0; j < l; j++) {

                        tableBody[0].appendChild(o[j]);

                    }
                }

                fixPosition(table, tableBody);

                $(table).trigger("applyWidgets");

                if (c.page >= c.totalPages) {
                    moveToLastPage(table);
                }

                updatePageDisplay(c);
            }

            this.appender = function(table, rows) {

                var c = table.config;

                c.rowsCopy = rows;
                c.totalRows = rows.length;
                c.totalPages = Math.ceil(c.totalRows / c.size);

                renderTable(table, rows);
            };

            this.defaults = {
                size: 10,
                offset: 0,
                page: 0,
                totalRows: 0,
                totalPages: 0,
                container: null,
                cssNext: '.next',
                cssPrev: '.prev',
                cssFirst: '.first',
                cssLast: '.last',
                cssPageDisplay: '.pagedisplay',
                cssPageSize: '.pagesize',
                seperator: "/",
                positionFixed: true,
                appender: this.appender
            };

            this.construct = function(settings) {

                return this.each(function() {

                    config = $.extend(this.config, $.tablesorterPager.defaults, settings);

                    var table = this, pager = config.container;

                    $(this).trigger("appendCache");

                    csize = parseInt($(".pagesize", pager).val());
                    if (!isNaN(csize))
                        config.size = csize;

                    $(config.cssFirst, pager).click(function() {
                        moveToFirstPage(table);
                        return false;
                    });
                    $(config.cssNext, pager).click(function() {
                        moveToNextPage(table);
                        return false;
                    });
                    $(config.cssPrev, pager).click(function() {
                        moveToPrevPage(table);
                        return false;
                    });
                    $(config.cssLast, pager).click(function() {
                        moveToLastPage(table);
                        return false;
                    });
                    $(config.cssPageSize, pager).change(function() {
                        setPageSize(table, parseInt($(this).val()));
                        return false;
                    });
                });
            };

        }
    });
    // extend plugin scope
    $.fn.extend({
        tablesorterPager: $.tablesorterPager.construct
    });

})(jQuery);				/*
 * Copyright (c) 2008 Greg Weber greg at gregweber.info
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * documentation at http://gregweber.info/projects/uitablefilter
 *
 * allows table rows to be filtered (made invisible)
 * <code>
 * t = $('table')
 * $.uiTableFilter( t, phrase )
 * </code>
 * arguments:
 *   jQuery object containing table rows
 *   phrase to search for
 *   optional arguments:
 *     column to limit search too (the column title in the table header)
 *     ifHidden - callback to execute if one or more elements was hidden
 */
jQuery.uiTableFilter = function(jq, phrase, column, ifHidden){
  var new_hidden = false;
  if( this.last_phrase === phrase ) return false;

  var phrase_length = phrase.length;
  var words = phrase.toLowerCase().split(" ");

  var success = function(elem) { elem.show() }
  var failure = function(elem) { elem.hide() }

  if( column ) {
    var index = null;
    jq.find("thead > tr:last > th").each( function(i){
      if( $(this).text() == column ){
        index = i;
        return false;
      }
    });
    var iselector = "td:eq(" + index + ")";
  
    var search_text = function( ){
      var elem = jQuery(this);
      jQuery.uiTableFilter.has_words( jQuery(elem.find(iselector)).text(), words ) ?
        success(elem) : failure(elem);
    }
  }
  else {
    var search_text = function(){
        var elem = jQuery(this);
        jQuery.uiTableFilter.has_words( elem.text(), words ) ? elem.show() : elem.hide();
    }
  }

  // if added one letter to last time,
  // just check newest word and only need to hide
  if( (words.size > 1) && (phrase.substr(0, phrase_length - 1) ===
        this.last_phrase) ) {

    if( phrase[-1] === " " )
    { this.last_phrase = phrase; return false; }

    success = function(elem) { elem.hide(); new_hidden = true; }
    failure = function(elem) {;}
    var words = words[-1];
    jq.find("tbody tr:visible").each( search_text )
  }
  else {
    new_hidden = true;
    jq.find("tbody > tr").each( search_text );
  }

  last_phrase = phrase;
  if( ifHidden && new_hidden ) ifHidden();
  return jq;
};
jQuery.uiTableFilter.last_phrase = ""

// not jQuery dependent
// "" [""] -> Boolean
// "" [""] Boolean -> Boolean
jQuery.uiTableFilter.has_words = function( str, words, caseSensitive )
{
  var text = caseSensitive ? str : str.toLowerCase();
  for (var i=0; i < words.length; i++) {
    if (text.indexOf(words[i]) === -1) return false;
  }
  return true;
}
﻿/*
 * Copyright (c) 2009 Jeroen Asselman
 */

jQuery(function($) {

	$.fn.jatablefilter = function() {

		$("tbody > tr > td", $(this)).live("click", function(event) {
			if ($(event.target).is("select")) return;
			if ($(event.target).parents("select").is("select")) return;
			if ($(event.target).is("input")) return;
			if ($(event.target).is("a")) return;

			var $td = $(this);
			var $table = $td.parents("table");



			var idx = $td.parent().children().index($td);
			var $header = $("thead>tr>th", $table).eq(idx);

			var filter = $header.data("filter");

			if (!filter)
				filter = [];

			var idxarr = $.inArray($td.text(), filter);
			var isFilterAdded;

			if (idxarr >= 0) {
				isFilterAdded = false;
				filter.splice(idxarr, 1);
			}
			else {
				isFilterAdded = true;
				filter.push($td.text());
			}

			$header.data("filter", filter);

			if (filter.length > 0)
				$header.addClass("filtered");
			else
				$header.removeClass("filtered");

			var rowSelector = "tbody > tr"; //isFilterAdded 
			var rowSelector = "tbody > tr"; //isFilterAdded 
			//? "tbody > tr:visible"
			//: "tbody > tr:hidden";

			var selector = rowSelector + " > td:nth-child(" + (idx + 1) + ")";

			$(selector).each(function() {
				var $mtd = $(this);
				var $mtr = $mtd.parents("tr");
				var mtext = $mtd.text();
				
				var show = filter.length == 0;

				if (show)
					$mtd.removeClass("filtered");
				else
					$mtd.addClass("filtered");

				$.each(filter, function(key, val) {
					if (mtext == val)
						show = true;
				});

				var filteredby = $mtr.data("filteredby");
				if (!filteredby) filteredby = [];

				if (!show) {
					filteredby.push(idx);
					$mtr.hide();
				}
				else {
					if (!isFilterAdded) {

						var l = $.inArray(idx, filteredby)
						if (l >= 0)
							filteredby.splice(l, 1);
					}

					if (filteredby.length == 0)
						$mtr.show();
				}

				$mtr.data("filteredby", filteredby);
			});


		});

	}
});/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};﻿/// <reference path="jquery-1.3.2-vsdoc.js" />


var scrollbarWidth = 20;

$(document).ready(function() {
	scrollbarWidth = getScrollbarWidth();

	// XHTML doesn't allow the target attribute, using the rel= attribute instead.
	$("a[rel='external']").attr("target", "_blank");

	// $("#main").maxWidth(914);

	$("ul.expandable > li > ul").slideUp();

	$("ul.expandable > li").toggle(
        function() { $(this).children().slideDown("fast"); },
        function() { $(this).children().slideUp("fast"); }
    );


	$("#generalSearchMore").click(function() {
		$("#generalSearch .crebo,#generalSearch .compagnie").slideDown("medium", function() {
			$("div.searchpage").removeClass("collapsed").addClass("expanded");
		});

		return false;
	});
	$("#generalSearchLess").click(function() {
		$("#generalSearch .crebo,#generalSearch .compagnie").slideUp("medium", function() {
			$("div.searchpage").removeClass("expanded").addClass("collapsed");
		});

		return false;
	});

	$("#generalSearch .crebo input[value],#generalSearch .compagnie input[value],#generalSearch .crebo select option:first-child:not(:selected)")
			.parents("#generalSearch")
			.find(".crebo,.compagnie")
			.slideDown("medium", function() {
				$("div.searchpage").removeClass("collapsed").addClass("expanded");
			});

	$("#generalSearch div.range span:not(.validationerror),#generalSearch div.range input:not(.single),#ziprangecollapse").hide();

	//input single checken in selector. als er text is dan een show van van ziprange
	$("#generalSearch div.range input[value]:not(.single)").parent().parent().find("span:not(.validationerror),input").show().each(function() { $("#ziprange").hide(); });

	$("span.shorthelp").hover(function() {
		var $this = $(this);
		$("span", $this).show("fast");
	},
	function() {
		var $this = $(this);
		$("span", $this).hide("fast");
	});

	$("#ziprange").click(function() {
		$(this).hide();
		$("#generalSearch div.range span:not(.validationerror),#generalSearch div.range input:not(.single),#ziprangecollapse").show();

		return false;
	});

	$("#ziprangecollapse").click(function() {
		$(this).hide();
		$("#generalSearch div.range span:not(.validationerror),#generalSearch div.range input:not(.single),#ziprangecollapse").hide();
		$("#ziprange").show();

		return false;
	});

	/* Banner & other animations */
	$("#bannerHeader").append("<img class=\"overlay\" runat=\"server\" src=\"" + base + "/Images/v3/h1_txt_LeerbaanRegelHetZelf.png\" alt=\"Wat nou stage/leerbaan? Regel het gewoon zelf.\" style=\"display:none\" />");

	if (Math.random() >= 0.5)
		$("#bannerHeader .overlay").fadeIn(2500);

	window.setInterval(function() {
		var $overlay = $("#bannerHeader .overlay");
		if ($overlay.css("display") == "none")
			$overlay.fadeIn(2500);
		else
			$overlay.fadeOut(2500);
	}, 10000);


	// XHTML doesn't allow autocomplete is off
	$("#ctl00_Ctrl_Login1_txtGebruikersnaam").attr("autocomplete", "profileusername");
	$("#ctl00_Ctrl_Login1_txtWachtwoord").attr("autocomplete", "profilepassword");

	$("#aspnetForm").attr("autocomplete", "off");


	$("a.languageswitch").click(function() {
		WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(
			this.id        /*eventTarget*/,
			""        /*eventArgument*/,
			false     /*validation*/,
			""        /* validationGroup */,
			this.href /* actionUrl */,
			false     /* trackFocus */,
			true      /* clientSubmit */
		));

		return false;

		$("#aspnetForm").attr("action", this.href).submit(); return false;
	});


	$("#ctl00_contentPlaceHolderLogin_myprofilelogin input[type='text'], #ctl00_contentPlaceHolderLogin_myprofilelogin input[type='password']").keydown(function(e) {
		if(e.keyCode == 13) {
			e.preventDefault();
			$("#ctl00_contentPlaceHolderLogin_Ctrl_Login1_btnLogin").click();
		}
		
	});

	
	// Try to fix layout issue firefox which sometimes occurs.
	//$("#more").css("table-layout", "fixed");
});

function attachValidator() {
	var $this = $(this);
	var $ctrl = $('#' + $this.attr("controltovalidate") + ',#' + $this.attr("controltovalidate") + '_tbInput');
	if ($this.attr("isvalid")) {
		$ctrl.removeClass("validationerror");
	}
	else {
		$ctrl.addClass("validationerror");
		
	}
}


function onClientPopulating(sender, e) {
    var $textbox = $(sender.get_element());
    var $completion = $(sender.get_completionList());

    $textbox.addClass("populating");
}

function onClientPopulated(sender, e) {
    var $textbox = $(sender.get_element());
    var $completion = $(sender.get_completionList());

    $textbox.removeClass("populating");
}

var autoComplete_adjustsize_chain;

function autoComplete_adjustsize(sender, e) {
    var $textbox = $(sender.get_element());
    var $completion = $(sender.get_completionList());


	$completion.css("width", "auto");
	
    var max = $textbox.width();
    $("li.item", $completion).each(function() {
		var $this = $(this);
		
		$(this).css("display", "inline-block");
		
    	var width = $this.width();
    	if (width > max) max = width;
    	
    	$(this).css("display", "");

    });

    $completion.css("min-width", max + scrollbarWidth + 2 /* Little margin */);
    
    if (autoComplete_adjustsize_chain)
    	autoComplete_adjustsize_chain(sender, e);
}

var autoComplete_hidden_chain;

function autoComplete_hidden(sender, e) {
	if (autoComplete_hidden_chain)
		autoComplete_hidden_chain(sender, e);
}

function getScrollbarWidth() {
	var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');
	// Append our div, do our calculation and then remove it
	$('body').append(div);
	var w1 = $('div', div).innerWidth();
	div.css('overflow-y', 'scroll');
	var w2 = $('div', div).innerWidth();
	$(div).remove();
	return (w1 - w2);
}


var $inputIsdatachanged;

function get$inputIsdatachanged()
{
	if (!$inputIsdatachanged )
		$inputIsdatachanged = $("#ctl00_ContentPlaceHolder1_hidDataChanged");
		
	return $inputIsdatachanged;
}

function setChangedData()
{
	get$inputIsdatachanged().val("true");
}

function getChangedBlocked()
{
	return get$inputIsdatachanged().val() == "true";
}

function alertIfChanged(evt)
{
    if (get$inputIsdatachanged().val() == "true")
	{
		evt.preventDefault();
		$(document.body).prepend("<div id=\"confirmleave\" title=\"Gewijzigde gegevens\">U heeft gegevens gewijzigd zonder deze op te slaan, weet u zeker dat u wilt doorgaan?<br/><br/>->\"Ja\", \"ik ga door en de gegevens worden niet opgeslagen\" <br/> ->\"Nee\", \"ik wil de mogelijkheid hebben om de gegevens op te slaan\"");
		$("#confirmleave").dialog({ 
			modal: true, 
			buttons: { 
				"Ja" : function() { 
						if (evt.target.href)
							window.location = evt.target.href; 
						else if (evt.target.click)
						{
							$(evt.target).unbind("click", alertIfChanged);
							
							$(evt.target).click();
						}
					}, 
				"Nee" : function(){ $(this).dialog("close"); } 
			} 
		});
	}
}

function getASPWS(url, data, success)
{
	$.ajax({
			type: "POST",
			url: url,
			data: data,
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			success: success
		});
}


(function() {

	jQuery.fn.alertIfChanged = function(settings) {

		var alertContainer = this;     //The jquery objects that contain our section to watch for changes.


		// define defaults and override with options, if available
		// by extending the default settings, we don't modify the argument
		settings = jQuery.extend({
			change: "input, select",
			click: "input[type='submit']"
		}, settings);

		alertContainer.each(function() {
		});
	};
})(jQuery);



var overridefunc_ValidatorUpdateDisplay;

function override_aspnet() {


	if (typeof(ValidatorUpdateDisplay) != 'undefined' ) {
		overridefunc_ValidatorUpdateDisplay = ValidatorUpdateDisplay;

		ValidatorUpdateDisplay = function(val) {
			overridefunc_ValidatorUpdateDisplay(val);

			if (val.style.display == 'inline')
				val.style.display = '';
		}
	}
}