
Ticketlogic.register('Popup', {
    Version: '0.1.0.0',

    initialise: function() { },
    show : function() {
        var box = arguments[0];
        var inp = (typeof box == 'string') ? box : box.id;
        if (typeof box == 'string') box = document.getElementById(box);         
        box.style.display = 'block';
    },
    hide : function() {
        var box = arguments[0];
        if (typeof box == 'string') box = document.getElementById(box);
        box.style.display = ''; 
    },
    submit : function() {
        var box = arguments[0];
        if (typeof box == 'string') box = document.getElementById(box);
        box.style.display = '';
        // submit form via AJAX?
        return false;
    }
});

Ticketlogic.register('Forms', {
    Version: '0.1.0.0',

    initialise: function() { },

    reset: function() {
        var _id = id(arguments[0]);
        _id.clear();
    },

    toggleSelect: function() {
        return this.toggleSelects(arguments);
    },

    toggleSelects: function() {
        var _name = arguments[0];
        var arr = document.getElementsByTagName("INPUT");
        for (var i = 0; i < arr.length; i++) {
            var inp = arr[i];
            var rgx = new RegExp("^" + _name + ".*$");
            if (inp.type == 'checkbox' && rgx.match(inp.id)) {
                inp.checked = !inp.checked;
            }
        }
    },

    select: function() {
        var _id = id(arguments[0]);
        if (_id.type && _id.type == 'CHECKBOX') {
            _id.checked = true;
        }
        else {
            _id.select();
        }
    },

    check: function() {
        var _id = arguments[0],
        _type = arguments[1];

    },
    
    sync: function() {
        var _one = id(arguments[0]),  _two = id(arguments[1]);
        _two.value = _one.value;
    },
    
    copySafe: function() {
        var _one = id(arguments[0]),
        _two = id(arguments[1]);
        var title = _one.value.toLowerCase().trim();
        _two.value = title.replace(/[\W]+/g, '-').replace(/[\-]+/g, '-');
    },

    disclose: function() {
        var _id = id(arguments[0]);
        _id.type = 'text';
    },

    obscure: function() {
        var _id = id(arguments[0]);
        _id.type = 'password';
    },

    checkboxRow: function() {
        var _row = id('table-row-' + arguments[0]),
        _sel = id('sel-' + arguments[0]);
        var className = _row.className + '';
        if (_sel.checked) {
            _row.className = className + ' table-row-selected';
        }
        else {
            _row.className = className.replace(/ ?table-row-selected/, '');
        }
    },

    highlightRow: function() {
        var _row = id(arguments[0]);
        var className = _row.className + '';
        if (className.indexOf('table-row-selected') == -1) {
            _row.className = className + ' table-row-selected';
        }
        else {
            _row.className = className.replace(/ ?table-row-selected/, '');
        }
    }
});

Ticketlogic.register('Elements', {
    Version: '0.1.0.0',

    initialise: function() { },

    addClass: function() {
        var _f = id(arguments[0]), _c = arguments[1];
        if (!!_f && _f.className.indexOf(_c) == -1) {
            _f.className = _f.className + ' ' + _c;
        }
    },

    removeClass: function() {
        var _f = id(arguments[0]), _c = arguments[1];        
        if (!!_f && _f.className.indexOf(_c) > -1) {
            var rgx = eval('/' + _c + '/g');
            _f.className = _f.className.replace(rgx, '');
        }
    },

    visibility: function() {
        var _id = id(arguments[0]), vis = arguments[1];
        if (!!_id) _id.style.visibility = vis;
    },

    show: function() {
        var _id = id(arguments[0]);
        if (!!_id) _id.style.display = 'block';
    },

    hide: function() {
        var _id = id(arguments[0]);
        if (!!_id) _id.style.display = '';
    }
});

Ticketlogic.register('Validator', {
    Version: '0.1.0.0',

    initialise: function() { },
    
    notEmpty: function() {
        var _one = id(arguments[0]);
        if ((_one.value != null) && (_one.value.length >= 1)) {
            Ticketlogic.Elements.removeClass(_one, 'error');
            Ticketlogic.Elements.removeClass(_one.parentNode, 'fielderror'); 
        }
        else {
            Ticketlogic.Elements.addClass(_one, 'error');
            Ticketlogic.Elements.addClass(_one.parentNode, 'fielderror'); 
        }        
    },
    
    password: function() {
        var _one = id(arguments[0]), _two = id(arguments[1]), _role = id(arguments[2]);
        if ((_one.value == _two.value) && (_one.value.length >= 8)) {
            Ticketlogic.Elements.removeClass(_one, 'error');
            Ticketlogic.Elements.removeClass(_two, 'error');
        }
        else {
            Ticketlogic.Elements.addClass(_one, 'error');
            Ticketlogic.Elements.addClass(_two, 'error');
        }
    },

    minLength: function() {
        var f = id(arguments[0]), l = arguments[1];
        if (f.value.length >= l) {
            Ticketlogic.Elements.removeClass(f, 'error');
            Ticketlogic.Elements.removeClass(f.parentNode, 'fielderror'); 
        }
        else { 
            Ticketlogic.Elements.addClass(f, 'error'); 
            Ticketlogic.Elements.addClass(f.parentNode, 'fielderror'); 
        }
    },

    telephone: function() {
        var f = id(arguments[0]);
        if (f.value.match(/ /)) { f.value = f.value.replace(/ /g, ''); }
        if (f.value.match(/^\+?\d+$/) && (f.value.length > 8)) {
            Ticketlogic.Elements.removeClass(f, 'error');
            Ticketlogic.Elements.removeClass(f.parentNode, 'fielderror');
        }
        else { 
            Ticketlogic.Elements.addClass(f, 'error'); 
            Ticketlogic.Elements.addClass(f.parentNode, 'fielderror'); 
        }
    },

    email: function() {
        var f = id(arguments[0]);
        f.value = f.value.toLowerCase();
        if (f.value.match(/^.+@[\w\-\.]{2,}\.[a-z]{2,3}$/)) {
            Ticketlogic.Elements.removeClass(f, 'error');
            Ticketlogic.Elements.removeClass(f.parentNode, 'fielderror');
        }
        else { 
            Ticketlogic.Elements.addClass(f, 'error'); 
            Ticketlogic.Elements.addClass(f.parentNode, 'fielderror'); 
        }
    },

    dateOfBirth: function() {
        var f = id(arguments[0]);
        if (f.value.match(/^\d{2}\/\d{2}\/\d{4}$/)) {
            Ticketlogic.Elements.removeClass(f, 'error');
            Ticketlogic.Elements.removeClass(f.parentNode, 'fielderror');
        }
        else { 
            Ticketlogic.Elements.addClass(f, 'error'); 
            Ticketlogic.Elements.addClass(f.parentNode, 'fielderror'); 
        }
    }
});

Ticketlogic.register('Calendar', {
    Version: '0.1.0.0',

    initialise: function() { },

    init: function() {
        if ( !! !id('ticketlogic-calendar')) {
            var cal = document.createElement('div');
            cal.id = 'ticketlogic-calendar';
            // var cntr = id('container');
            var cntr = document.body;
            cntr.appendChild(cal);
        }
        var inputs = document.getElementsByTagName("INPUT");
        for (var i = 0; i < inputs.length; i++) {
            var inp = inputs[i],
            a = document.createElement("A");
            if (inp.className.indexOf('popupcalendar') == -1) continue;
            var popup = function() {
                var _f = arguments[0];
                return function() {
                    var f = id(_f),
                    c = id('ticketlogic-calendar'),
                    current = Ticketlogic.Date.parse(f.value);
                    var xy = Ticketlogic.Coordinates.locate(f);
                    c.style.left = (xy.x) + 'px';
                    c.style.top = (xy.y + f.offsetHeight + 2) + 'px';
                    c.style.display = 'block';
                    Ticketlogic.Calendar.cal(current.getTime(), f.id);
                }
            };
            a.className = "popupcalendaranchor";
            a.href = "#";
            a.innerHTML = "<img style=\"vertical-align: middle;\" src=\"/images/app1.5/calendar-icon.gif\" />";
            a.onclick = popup(inp.id);
            inp.onclick = popup(inp.id);
            if (inp.nextSibling) {
                inp.parentNode.insertBefore(a, inp.nextSibling);
            } else {
                inp.parentNode.appendChild(a);
            }
        }
    },

    cal: function() {
        var d = new Date(arguments[0]),
        s = new Date(arguments[0]),
        f = id(arguments[1]),
        c = id('ticketlogic-calendar');
        var navl = '<span id="calendar-nav"><span id="calendar-navl"><a href="#" onclick="Ticketlogic.Calendar.clock(' + d.getTime() + ',\'' + f.id +
        '\');"><img style="vertical-align: middle;" src="/images/app1.5/clock-icon.gif" alt="[o]" /></a></span>';
        var navc = '<span id="calendar-navc"><a href="#" onclick="Ticketlogic.Calendar.cal(' + d.addMonths( - 1).getTime() +
        ',\'' + f.id + '\'); return false;">&laquo;</a>&nbsp;' +
        d.getMonthName() + ' ' + d.getFullYear() + '&nbsp;<a href="#" onclick="Ticketlogic.Calendar.cal(' + d.addMonths(1).getTime() + ',\'' + f.id + '\'); return false;">&raquo;</a></span>';
        var navr = '<span id="calendar-navr"><a href="#" onclick="Ticketlogic.Calendar.hide(); return false;"><img style="vertical-align: middle;" src="/images/app1.5/close-icon.gif" alt="[x]" /></a></span></span><span style="clear: both; display: block;"></span>';
        var first = s.addDays(1 - s.getDate()),
        rows = '';
        s = first.addDays(1 - first.getDay());
        if (s.getDate() > 1 && s.getDate() < 7) s = s.addDays( - 7);
        for (var i = 0; ((i < 6) && s.beforeByMonth(d)); i++) {
            rows += '<tr>';
            for (var n = 0; n < 7; n++) {
                var unit = (((i) * 7) + (n + 1));
                rows += '<td class="' + ((s.getMonth() == d.getMonth()) ? 'active-month': '') + ' ' + ((s.isToday()) ? 'today': '') + ' ' + (((s.getDay() == 6) || (s.getDay() == 0)) ? 'weekend': '') +
                '"><a href="#" onclick="Ticketlogic.Calendar.setDate(\'' + f.id + '\',' + (s.getYear() + 1900) + ',' + s.getMonth() +
                ',' + s.getDate() + '); return false;">' + s.getDate() + '</a></td>';
                s = s.addDays(1);
            }
            rows += '</tr>';
        }

        var body = '<tbody>' + rows + '</tbody>';
        var head = '<thead><tr><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr></thead>';
        var table = '<table>' + head + body + '</table>'

        c.innerHTML = navl + navc + navr + table;
    },

    clock: function() {
        var d = new Date(arguments[0]),
        f = id(arguments[1]),
        c = id('ticketlogic-calendar');
        var nav = '<span id="calendar-nav"><span id="calendar-navl"><a href="#" onclick="Ticketlogic.Calendar.cal(' + d.getTime() + ',\'' + f.id +
        '\');"><img style="vertical-align: middle;" src="/images/app1.5/calendar-icon.gif" alt="[o]" /></a></span>' +
        '<span id="calendar-navc">Clock</span><span id="calendar-navr"><a href="#" onclick="Ticketlogic.Calendar.hide(); return false;">' +
        '<img style="vertical-align: middle;" src="/images/app1.5/close-icon.gif" alt="[x]" /></a></span></span><span style="clear: both; display: block;"></span>';

        var hours = '';
        for (var m = 0; m < 24; m++) {
            hours += '<a href="#" onclick="Ticketlogic.Calendar.setHours(\'' + f.id + '\',' + m + '); return false;">' + m + '</a>';
        }

        var mins = '';
        for (var m = 0; m < 60; m += 5) {
            mins += '<a href="#" onclick="Ticketlogic.Calendar.setMins(\'' + f.id + '\',' + m + '); return false;">' + m + '</a>';
        }
        mins += '<a href="#" onclick="Ticketlogic.Calendar.setMins(\'' + f.id + '\',' + 57 + '); return false;">' + 57 + '</a>';
        mins += '<a href="#" onclick="Ticketlogic.Calendar.setMins(\'' + f.id + '\',' + 58 + '); return false;">' + 58 + '</a>';
        mins += '<a href="#" onclick="Ticketlogic.Calendar.setMins(\'' + f.id + '\',' + 59 + '); return false;">' + 59 + '</a>';

        c.innerHTML = nav + '<span class="cl"><strong>Hours</strong></span><span class="cr"><strong>Mins</strong></span><span class="cl">' + hours + '</span><span class="cr">' + mins + '</span>';
    },

    popup: function() {
        var _fld = id(arguments[0]),
        _cal = id('ticketlogic-calendar');
        alert(_fld.id + " " + _cal.id);
    },

    setDate: function() {
        try {
        var f = id(arguments[0]),
        y = parseInt(arguments[1]),
        m = parseInt(arguments[2]),
        d = parseInt(arguments[3]);
        var dat = Ticketlogic.Date.parse(f.value);
        dat.setYear(y);
        dat.setMonth(m);
        dat.setDate(d);
        f.value = Ticketlogic.Date.format(dat);
        f.select();
        } catch (e) {
            alert(e);
        }
    },

    setHours: function() {
        var f = id(arguments[0]),
        h = arguments[1];
        var dat = Ticketlogic.Date.parse(f.value);
        dat.setHours(h);
        f.value = Ticketlogic.Date.format(dat);
        f.select();
    },

    setMins: function() {
        var f = id(arguments[0]),
        m = arguments[1];
        var dat = Ticketlogic.Date.parse(f.value);
        dat.setMinutes(m);
        f.value = Ticketlogic.Date.format(dat);
        f.select();
    },

    hide: function() {
        var _cal = id('ticketlogic-calendar');
        _cal.style.display = '';
    }

});






Ticketlogic.register('Shop', {
    timer: null,
    reqst: null,
    active: false,
    args: new Array(),
    initialise: function() {
    },
    init: function() {
        var frm = id(arguments[0]), qur = id(arguments[1]), href = document.location.href, start = id('start'), rows = id('rows'), index = href.indexOf('#');
        if (index > -1) {
            var fragment = href.substring(index + 1); qur.value = decodeURIComponent(fragment);
            this.search(qur);
        }
        start.onkeyup = function(e) {
            var s = id('start'), i = parseInt(f.value), k = e.keyCode;
            if (k >= 37 && k <= 40) {
                if (k == 37 && i > 5) s.value = i-5;
                if (k == 40 && i > 0) s.value = i-1;
                if (k == 38) s.value = i+1;
                if (k == 39) s.value = i+5;
            } 
            Ticketlogic.Shop.search('big-query');
        }
        rows.onkeyup = function(e) {
            var r = id('rows'), i = parseInt(r.value), k = e.keyCode;
            if (k >= 37 && k <= 40) {
                if (k == 37 && i > 5) r.value = i-5;
                if (k == 40 && i > 0) r.value = i-1;
                if (k == 38) r.value = i+1;
                if (k == 39) r.value = i+5;
            } 
            Ticketlogic.Shop.search('big-query');
        }
    },
    search: function() {
        this.args = arguments;
        if (this.timer != null) clearTimeout(this.timer); 
        this.timer = setTimeout('Ticketlogic.Shop.data();', 750);
    },
    working: function() {
        var bool = arguments[0], qur = id('big-query'), but = id('search-big-submit'), start = id('start'), rows = id('rows');
        if (bool) {
            qur.style.backgroundColor = '#eee';
            start.style.backgroundColor = '#eee';
            rows.style.backgroundColor = '#eee';
            qur.style.color = '#bbb';
            start.style.color = '#bbb';
            rows.style.color = '#bbb';
            but.disabled = true;
            but.className = 'working';
        }
        else {
            qur.style.backgroundColor = '';
            start.style.backgroundColor = '';
            rows.style.backgroundColor = '';
            qur.style.color = '';
            start.style.color = '';
            rows.style.color = '';
            but.disabled = false;
            but.className = '';
        }
    },
    start: function() {
        var start = id('start');
        start.value = 0;
    },    
    historic: function() {
        var historic = id('historic'), reverse = id('reverse');
        reverse.checked = historic.checked;
    },
    tab: function() {
        var tab = 'opt-tab'+arguments[0], show = 'results-'+arguments[0], 
            tabs = ['opt-tabproducts', 'opt-tabetickets', 'opt-tabusers'], disp = ['results-products', 'results-etickets', 'results-users'];
        for (var i=0; i<tabs.length; i++) { Ticketlogic.Elements.removeClass(tabs[i], 'enabled'); }
        for (var i=0; i<disp.length; i++) { Ticketlogic.Elements.hide(disp[i]); }
        Ticketlogic.Elements.addClass(tab, 'enabled');
        Ticketlogic.Elements.show(show);        
    },
    next: function() {
        var start = id('start'), count = 1;
        if (arguments.length > 0) count = arguments[0];
        start.value = parseInt(start.value) + count;
        this.search('big-query');
    },
    prev: function() {
        var start = id('start'), count = 1;
        if (arguments.length > 0) count = arguments[0];
        start.value = parseInt(start.value) - count;
        this.search('big-query');
    },
    result: function() {
        var dt, vh, box = id('search-dynamic-results');

        this.args = [];
        this.reqst = null;

        if (arguments.length == 2) {
            dt = arguments[0]; vh = arguments[1];
        }
        else {
            dt = '<div class="center">No results, try another search</div>'; vh = 'auto';
        }

        box.innerHTML = dt; 
        box.style.height = vh + (isNaN(vh) ? '' : 'px');
        box.style.display = 'block';

        this.working(false);
    },
    data: function() {
        var frm = id('search-shop'), qur = id('big-query'), start = id('start'), rows = id('rows'), 
        country = id('country'), historic = id('historic'), reverse = id('reverse'), 
        context = id('context'), out = '';
        this.timer = null;
        this.working(true);
        if (qur.value.match(/^ /)) { qur.value = qur.value.replace(/^ +/, ''); }
        if (qur.value.length < 2) { this.result(); return; }

        var loc = country.options[country.selectedIndex].value;
        
        if (loc == 'GB') {
            loc = 'UK';
        }

        var url = frm.action + '?s=' + start.value + '&r=' + rows.value + '&c=' + loc.toLowerCase() + '&hs=' + historic.checked + '&rv=' + reverse.checked + '&q=' + encodeURIComponent(qur.value);
        document.location = '#' + encodeURIComponent(qur.value);

        if (this.reqst != null) {
            if (!!this.reqst.transport && !!this.reqst.transport.abort) {
                this.reqst.transport.abort();
            }
        }

        this.reqst = new Ajax.Request(url, {
            method: 'post',
            onError: Ticketlogic.Shop.result,
            onSuccess: Ticketlogic.Shop.process
        });
        
        Ticketlogic.Shop.result('<div class="center">Searching...</div><p class="center"><img src="https://cache.clubtickets.com/images/pub1.5/searching-dots-anim.gif" alt="..." /></p>', 'auto');
    },
    process: function(response) {
        setTimeout('Ticketlogic.Shop.working(false);', 8000);
        var res = '', json = response.responseJSON, context = id('context'), start = id('start'), rows = id('rows');

        try {
        var users = response.responseJSON.users || {'count': 0, 'results':[]};
        var products = response.responseJSON.products || {'count': 0, 'results':[]};
        var etickets = response.responseJSON.etickets || {'count': 0, 'results':[]}; 

        var products_count = parseInt(products.count), etickets_count = parseInt(etickets.count), users_count = parseInt(users.count);

        if ((products_count == 0) && (etickets_count == 0) && (users_count == 0)) { Ticketlogic.Shop.result(); return; }

        var height = 'auto', tabenabled = null, maxrows = 0;

        if (products_count > 0) { tabenabled = 'products'; maxrows = products_count; }
        if (etickets_count > products_count) { tabenabled = 'etickets'; maxrows = etickets_count; }
        if ((users_count > products_count) && (users_count > etickets_count)) { tabenabled = 'users'; maxrows = users_count; }

        res += '<div class="tabbedarea" id="tabbedarea-inventory"><div class="menu">'; 

        if (products_count > 0) { 
            res += '<span class="tab';
            if (tabenabled == 'products') res += ' enabled'; 
            res += '" id="opt-tabproducts"><a href="#" onclick="Ticketlogic.Shop.tab(\'products\'); return false;">' + products_count + ' Products</a></span>'; 
        }
        if (etickets_count > 0) { 
            res += '<span class="tab';
            if (tabenabled == 'etickets') res += ' enabled'; 
            res += '" id="opt-tabetickets"><a href="#" onclick="Ticketlogic.Shop.tab(\'etickets\'); return false;">' + etickets_count + ' ETickets</a></span>';
        }
        if (users_count > 0) { 
            res += '<span class="tab';
            if (tabenabled == 'users') res += ' enabled'; 
            res += '" id="opt-tabusers"><a href="#" onclick="Ticketlogic.Shop.tab(\'users\'); return false;">' + users_count + ' Users</a></span>';
        }
        res += '</div><br class="separator" /></div><br class="separator" />';
        res += '<div id="results-products" class="shop-results">';

        if (products_count > 0) {
            for (var i=0; i<products.results.length; i++) {
                var prod = products.results[i], url = prod.img.split('/'), img = url[url.length - 1], title = prod.title, desc = prod.desc, venue = prod.venue.title;
                if (title.length > 60) {
                    title = title.substring(0, 60);
                    title = title.trim();
                    title = title + '...';
                }

                if ((prod.venue.id > 1) && (desc.length >= 140)) desc = desc.substring(0, (desc.length - (3 + venue.length)));
                if (venue.length > 26) venue = venue.substring(0, 26) + '...';

                res += '<div id="product-0000' + prod.id + '" class="partner-result">';
                res += '<div class="col10" style="width: 50px; margin: 0 10px 0 0; border: 1px solid #ccc">';
                res += '<a href="' + context.value + '/id-0000' + prod.id + '/preview"><img src="https://images.clubtickets.com/image/50sq/c/' + img + '"/></a></div>';
                res += '<div class="col50" style="width: 490px; margin-right: 5px;"><strong><a href="' + context.value + '/id-0000' + prod.id + '/preview">' + title + '</a></strong><p>';

                if (prod.promoter.id > 1) {
                    res += 'By <strong><a class="num" href="' + context.value + '/pr-0000' + prod.promoter.id + '/preview">' + prod.promoter.title + '</a></strong>.&nbsp;&nbsp;';
                }

                res += desc + '...</p></div>';
                res += '<div class="col20" style="width: 215px; padding: 5px; margin-right: 0;">';
                res += '<div><strong><a class="alt" href="' + context.value + '/vn-0000' + prod.venue.id + '/preview">' + venue + '</a></strong>';
                if (!!prod.venue.country) {
                    res += ' (' + prod.venue.country + ')';
                }
                res += '</div>';
                res += '<p style="margin: 0;">' + prod.starts + ' - ' + prod.ends  + '</p></div>';
                res += '<div class="col20 end" style="width: 90px; padding: 5px; font-size: 9pt;">';

                var max = 2;
                if (prod.prices.length > max) {
                    res += 'From: <br />';
                    max--;
                }

                for (var n = 0; (n < prod.prices.length) && (n < max); n++) {
                    var pr = prod.prices[n];
                    if (n > 0) res += '<br />';
                    res += '<strong><a href="' + context.value + '/id-0000' + prod.id + '/preview">' + pr.amount + ' ' + pr.label + '</a></strong>';
                }

                res += '</div><br class="separator" /></div>';
            }
        }

        res += '</div>';
        res += '<div id="results-etickets" class="shop-results">';

        if (etickets_count > 0) {
            res += '<table class="vlight"><thead><tr>';
            res += '<th>Atv</th><th>Barcode</th><th>Code</th><th>Reference</th><th>Name</th><th>Units</th><th>Card</th><th>Prn</th><th>Val</th><th>Type</th><th>Flf</th><th class="right">Created</th>';
            res += '</tr></thead><tbody>';
            for (var i=0; i<etickets.results.length; i++) {
                var eticket = etickets.results[i];
                res += '<tr class="' + (eticket.active ? '' : 'cancelled') + '">';
                res += '<td><img src="https://cache.clubtickets.com/images/app1.5/icon-' + (eticket.active ? 'active' : 'inactive') + '.gif"/></td>';
                res += '<td><a class="alt" href="/staff/a/o/search?q=' + encodeURIComponent(eticket.reference) + '">' + eticket.barcode + '</a></td>';
                res += '<td>' + eticket.code + '</td>';
                res += '<td><strong><a href="/staff/a/o/search?q=' + encodeURIComponent(eticket.reference) + '">' + eticket.reference + '</a></strong></td>';
                res += '<td><a class="alt" href="/staff/a/et/search?q=' + encodeURIComponent(eticket.customer) + '">' + eticket.customer + '</a></td>';
                res += '<td>&times;' + eticket.units + '</td>';
                res += '<td>' + eticket.card + '</td>';
                res += '<td>' + eticket.printed + '</td>';
                res += '<td>' + eticket.validity + '</td>';
                res += '<td><img src="https://cache.clubtickets.com/images/app1.5/icon-' + (eticket.downloadable ? 'eticket' : 'print') + '.gif"/></td>';
                res += '<td><img src="https://cache.clubtickets.com/images/app1.5/icon-' + (eticket.fulfilled ? '' : 'un') + 'fulfilled.gif"/></td>';
                res += '<td class="right">' + Ticketlogic.Date.format(eticket.created) + '</td>';
                res += '</tr>';
            }
            res += '</tbody></table>';
        }

        res += '</div>';
        res += '<div id="results-users" class="shop-results">';

        if (users_count > 0) {
            res += '<table class="vlight"><thead><tr>';
            res += '<th>ID</th><th>Name</th><th>Email</th><th>Mobile</th><th class="right">Role</th><th class="right">Created</th><th> </th>';
            res += '</tr></thead><tbody>';
            for (var i=0; i<users.results.length; i++) {
                var user = users.results[i];
                res += '<tr class="type-' + user.type + '"><td><a class="alt" href="/staff/a/u/id-000' + user.id + '">' + user.username + '</a></td>';
                res += '<td><strong>' + user.firstname + ' ' + user.lastname + '</strong></td>';
                res += '<td><strong><a href="/staff/a/u/id-000' + user.id + '">' + user.email + '</a></strong></td>';
                res += '<td>' + ((user.mobile != '') ? '<a class="offsite" href="callto:' + user.mobile + '">' + user.mobile + '</a>' : '') + '</td>';
                res += '<td class="right user-role">' + user.maxrole + '</td>';
                res += '<td class="right">' + Ticketlogic.Date.format(user.created) + '</td>';
                res += '<td class="right"><a class="more" href="/staff/a/s/setuser?user_id=' + user.id + '">Use</a></td></tr>';
            }
            res += '</tbody></table>';
        }

        res += '</div>';
        res += '<div class="col33"><p>';

        var start_value = parseInt(start.value), rows_value = parseInt(rows.value);
        if (start_value > 0) {
            var amount = rows_value;
            if (amount > start_value) amount = start_value;
            res += '<a class="prev" href="#" onclick="Ticketlogic.Shop.prev(' + amount + '); return false;">&laquo; Previous ' + amount + '</a> &nbsp; <a class="prev" href="#" onclick="Ticketlogic.Shop.prev(); return false;"><strong>&laquo; Previous result</strong></a>';
        }
        else {
            res += '&nbsp;';
        }

        try {
        res += '</p></div>';
        res += '<div class="col33"><p class="center">';
        if (maxrows > rows_value) {
            res += '<a href="javascript:id(\'rows\').value = \'' + maxrows + '\'; Ticketlogic.Shop.search(); return false;">Show all ' + maxrows + ' results...</a>';
        }
        else {
            res += '&nbsp;';
        }
        res += '</p></div>';
        res += '<div class="col33 end"><p class="right">';
        } catch (e) {
            alert(e);
        }

        if (maxrows > (start_value + rows_value)) {
            res += '<a class="next" href="#" onclick="Ticketlogic.Shop.next(); return false;"><strong>Next result &raquo;</strong></a> &nbsp; <a class="next" href="#" onclick="Ticketlogic.Shop.next(' + rows.value + '); return false;">Next ' + rows.value + ' &raquo;</a>';
        }
        res += '</p></div>';

        } catch (e) {
            res = '<div class="center">' + e + '</div>';
        } 

        Ticketlogic.Shop.result('<div id="partner-results-list">' + res + '</div>', height);
        Ticketlogic.Elements.show('results-' + tabenabled);
    }
});

