﻿/*
 *	Hashtag
 */
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);

(function($) {
	$.datepicker.regional['el'] = {
		monthNames: ['Ιανουάριος','Φεβρουάριος','Μάρτιος','Απρίλιος','Μάιος','Ιούνιος',
		'Ιούλιος','Αύγουστος','Σεπτέμβριος','Οκτώβριος','Νοέμβριος','Δεκέμβριος'],
		monthNamesShort: ['Ιαν','Φεβ','Μαρ','Απρ','Μαι','Ιουν',
		'Ιουλ','Αυγ','Σεπ','Οκτ','Νοε','Δεκ'],
		dayNames: ['Κυριακή','Δευτέρα','Τρίτη','Τετάρτη','Πέμπτη','Παρασκευή','Σάββατο'],
		dayNamesShort: ['Κυρ','Δευ','Τρι','Τετ','Πεμ','Παρ','Σαβ'],
		dayNamesMin: ['Κυ','Δε','Τρ','Τε','Πε','Πα','Σα'],
		dateFormat: 'dd/mm/yyyy', firstDay: 1,
		renderer: $.datepicker.defaultRenderer,
		prevText: 'Προηγούμενος', prevStatus: 'Επισκόπηση προηγούμενου μήνα',
		prevJumpText: '&#x3c;&#x3c;', prevJumpStatus: '',
		nextText: 'Επόμενος', nextStatus: 'Επισκόπηση επόμενου μήνα',
		nextJumpText: '&#x3e;&#x3e;', nextJumpStatus: '',
		currentText: 'Τρέχων Μήνας', currentStatus: 'Επισκόπηση τρέχοντος μήνα',
		todayText: 'Τρέχων Μήνας', todayStatus: 'Επισκόπηση τρέχοντος μήνα',
		clearText: 'Σβήσιμο', clearStatus: 'Σβήσιμο της επιλεγμένης ημερομηνίας',
		closeText: 'Κλείσιμο', closeStatus: 'Κλείσιμο χωρίς αλλαγή',
		yearStatus: 'Επισκόπηση άλλου έτους', monthStatus: 'Επισκόπηση άλλου μήνα',
		weekText: 'Εβδ', weekStatus: '',
		dayStatus: 'Επιλογή DD d MM', defaultStatus: 'Επιλέξτε μια ημερομηνία',
		isRTL: false
	};
	$.datepicker.setDefaults($.datepicker.regional['el']);
})(jQuery);

/**
 * Boxy 0.1.4 - Facebook-style dialog, with frills
 *
 * (c) 2008 Jason Frame
 * Licensed under the MIT License (LICENSE)
 */
 
/*
 * jQuery plugin
 *
 * Options:
 *   message: confirmation message for form submit hook (default: "Please confirm:")
 * 
 * Any other options - e.g. 'clone' - will be passed onto the boxy constructor (or
 * Boxy.load for AJAX operations)
 */
jQuery.fn.boxy = function(options) {
    options = options || {};
    return this.each(function() {      
        var node = this.nodeName.toLowerCase(), self = this;
        if (node == 'a') {
            jQuery(this).click(function() {
                var active = Boxy.linkedTo(this),
                    href = this.getAttribute('href'),
                    localOptions = jQuery.extend({actuator: this, title: this.title}, options);
                    
                if (active) {
                    active.show();
                } else if (href.indexOf('#') >= 0) {
                    var content = jQuery(href.substr(href.indexOf('#'))),
                        newContent = content.clone(true);
                    content.remove();
                    localOptions.unloadOnHide = false;
                    new Boxy(newContent, localOptions);
                } else { // fall back to AJAX; could do with a same-origin check
                    if (!localOptions.cache) localOptions.unloadOnHide = true;
                    Boxy.load(this.href, localOptions);
                }
                
                return false;
            });
        } else if (node == 'form') {
            jQuery(this).bind('submit.boxy', function() {
                Boxy.confirm(options.message || 'Please confirm:', function() {
                    jQuery(self).unbind('submit.boxy').submit();
                });
                return false;
            });
        }
    });
};

//
// Boxy Class

function Boxy(element, options) {
    
    this.boxy = jQuery(Boxy.WRAPPER);
    jQuery.data(this.boxy[0], 'boxy', this);
    
    this.visible = false;
    this.options = jQuery.extend({}, Boxy.DEFAULTS, options || {});
    
    if (this.options.modal) {
        this.options = jQuery.extend(this.options, {center: true, draggable: false});
    }
    
    // options.actuator == DOM element that opened this boxy
    // association will be automatically deleted when this boxy is remove()d
    if (this.options.actuator) {
        jQuery.data(this.options.actuator, 'active.boxy', this);
    }
    
    this.setContent(element || "<div></div>");
    this._setupTitleBar();
    
    this.boxy.css('display', 'none').appendTo(document.body);
    this.toTop();

    if (this.options.fixed) {
        if (jQuery.browser.msie && jQuery.browser.version < 7) {
            this.options.fixed = false; // IE6 doesn't support fixed positioning
        } else {
            this.boxy.addClass('fixed');
        }
    }
    
    if (this.options.center && Boxy._u(this.options.x, this.options.y)) {
        this.center();
    } else {
        this.moveTo(
            Boxy._u(this.options.x) ? this.options.x : Boxy.DEFAULT_X,
            Boxy._u(this.options.y) ? this.options.y : Boxy.DEFAULT_Y
        );
    }
    
    if (this.options.show) this.show();

};

Boxy.EF = function() {};

jQuery.extend(Boxy, {
    
    WRAPPER:    "<table cellspacing='0' cellpadding='0' border='0' class='boxy-wrapper'>" +
                "<tr><td class='top-left'></td><td class='top'></td><td class='top-right'></td></tr>" +
                "<tr><td class='left'></td><td class='boxy-inner'></td><td class='right'></td></tr>" +
                "<tr><td class='bottom-left'></td><td class='bottom'></td><td class='bottom-right'></td></tr>" +
                "</table>",
    
    DEFAULTS: {
        title:                  null,           // titlebar text. titlebar will not be visible if not set.
        closeable:              true,           // display close link in titlebar?
        draggable:              true,           // can this dialog be dragged?
        clone:                  false,          // clone content prior to insertion into dialog?
        actuator:               null,           // element which opened this dialog
        center:                 true,           // center dialog in viewport?
        show:                   true,           // show dialog immediately?
        modal:                  false,          // make dialog modal?
        fixed:                  true,           // use fixed positioning, if supported? absolute positioning used otherwise
        closeText:              '[close]',      // text to use for default close link
        unloadOnHide:           false,          // should this dialog be removed from the DOM after being hidden?
        clickToFront:           false,          // bring dialog to foreground on any click (not just titlebar)?
        behaviours:             Boxy.EF,        // function used to apply behaviours to all content embedded in dialog.
        afterDrop:              Boxy.EF,        // callback fired after dialog is dropped. executes in context of Boxy instance.
        afterShow:              Boxy.EF,        // callback fired after dialog becomes visible. executes in context of Boxy instance.
        afterHide:              Boxy.EF,        // callback fired after dialog is hidden. executed in context of Boxy instance.
        beforeUnload:           Boxy.EF         // callback fired after dialog is unloaded. executed in context of Boxy instance.
    },
    
    DEFAULT_X:          0,
    DEFAULT_Y:          0,
    zIndex:             1337,
    dragConfigured:     false, // only set up one drag handler for all boxys
    resizeConfigured:   false,
    dragging:           null,
    
    // load a URL and display in boxy
    // url - url to load
    // options keys (any not listed below are passed to boxy constructor)
    //   type: HTTP method, default: GET
    //   cache: cache retrieved content? default: false
    //   filter: jQuery selector used to filter remote content
    load: function(url, options) {
        
        options = options || {};
        
        var ajax = {
            url: url, type: 'GET', dataType: 'html', cache: false, success: function(html) {
                html = jQuery(html);
                if (options.filter) html = jQuery(options.filter, html);
                new Boxy(html, options);
            }
        };
        
        jQuery.each(['type', 'cache'], function() {
            if (this in options) {
                ajax[this] = options[this];
                delete options[this];
            }
        });
        
        jQuery.ajax(ajax);
        
    },
    
    // allows you to get a handle to the containing boxy instance of any element
    // e.g. <a href='#' onclick='alert(Boxy.get(this));'>inspect!</a>.
    // this returns the actual instance of the boxy 'class', not just a DOM element.
    // Boxy.get(this).hide() would be valid, for instance.
    get: function(ele) {
        var p = jQuery(ele).parents('.boxy-wrapper');
        return p.length ? jQuery.data(p[0], 'boxy') : null;
    },
    
    // returns the boxy instance which has been linked to a given element via the
    // 'actuator' constructor option.
    linkedTo: function(ele) {
        return jQuery.data(ele, 'active.boxy');
    },
    
    // displays an alert box with a given message, calling optional callback
    // after dismissal.
    alert: function(message, callback, options) {
        return Boxy.ask(message, ['OK'], callback, options);
    },
    
    // displays an alert box with a given message, calling after callback iff
    // user selects OK.
    confirm: function(message, after, options) {
        return Boxy.ask(message, ['OK', 'Cancel'], function(response) {
            if (response == 'OK') after();
        }, options);
    },
    
    // asks a question with multiple responses presented as buttons
    // selected item is returned to a callback method.
    // answers may be either an array or a hash. if it's an array, the
    // the callback will received the selected value. if it's a hash,
    // you'll get the corresponding key.
    ask: function(question, answers, callback, options) {
        
        options = jQuery.extend({modal: true, closeable: false},
                                options || {},
                                {show: true, unloadOnHide: true});
        
        var body = jQuery('<div></div>').append(jQuery('<div class="question"></div>').html(question));
        
        // ick
        var map = {}, answerStrings = [];
        if (answers instanceof Array) {
            for (var i = 0; i < answers.length; i++) {
                map[answers[i]] = answers[i];
                answerStrings.push(answers[i]);
            }
        } else {
            for (var k in answers) {
                map[answers[k]] = k;
                answerStrings.push(answers[k]);
            }
        }
        
        var buttons = jQuery('<form class="answers"></form>');
        buttons.html(jQuery.map(answerStrings, function(v) {
            return "<input type='button' value='" + v + "' />";
        }).join(' '));
        
        jQuery('input[type=button]', buttons).click(function() {
            var clicked = this;
            Boxy.get(this).hide(function() {
                if (callback) callback(map[clicked.value]);
            });
        });
        
        body.append(buttons);
        
        new Boxy(body, options);
        
    },
    
    // returns true if a modal boxy is visible, false otherwise
    isModalVisible: function() {
        return jQuery('.boxy-modal-blackout').length > 0;
    },
    
    _u: function() {
        for (var i = 0; i < arguments.length; i++)
            if (typeof arguments[i] != 'undefined') return false;
        return true;
    },
    
    _handleResize: function(evt) {
        var d = jQuery(document);
        jQuery('.boxy-modal-blackout').css('display', 'none').css({
            width: d.width(), height: d.height()
        }).css('display', 'block');
    },
    
    _handleDrag: function(evt) {
        var d;
        if (d = Boxy.dragging) {
            d[0].boxy.css({left: evt.pageX - d[1], top: evt.pageY - d[2]});
        }
    },
    
    _nextZ: function() {
        return Boxy.zIndex++;
    },
    
    _viewport: function() {
        var d = document.documentElement, b = document.body, w = window;
        return jQuery.extend(
            jQuery.browser.msie ?
                { left: b.scrollLeft || d.scrollLeft, top: b.scrollTop || d.scrollTop } :
                { left: w.pageXOffset, top: w.pageYOffset },
            !Boxy._u(w.innerWidth) ?
                { width: w.innerWidth, height: w.innerHeight } :
                (!Boxy._u(d) && !Boxy._u(d.clientWidth) && d.clientWidth != 0 ?
                    { width: d.clientWidth, height: d.clientHeight } :
                    { width: b.clientWidth, height: b.clientHeight }) );
    }

});

Boxy.prototype = {
    
    // Returns the size of this boxy instance without displaying it.
    // Do not use this method if boxy is already visible, use getSize() instead.
    estimateSize: function() {
        this.boxy.css({visibility: 'hidden', display: 'block'});
        var dims = this.getSize();
        this.boxy.css('display', 'none').css('visibility', 'visible');
        return dims;
    },
                
    // Returns the dimensions of the entire boxy dialog as [width,height]
    getSize: function() {
        return [this.boxy.width(), this.boxy.height()];
    },
    
    // Returns the dimensions of the content region as [width,height]
    getContentSize: function() {
        var c = this.getContent();
        return [c.width(), c.height()];
    },
    
    // Returns the position of this dialog as [x,y]
    getPosition: function() {
        var b = this.boxy[0];
        return [b.offsetLeft, b.offsetTop];
    },
    
    // Returns the center point of this dialog as [x,y]
    getCenter: function() {
        var p = this.getPosition();
        var s = this.getSize();
        return [Math.floor(p[0] + s[0] / 2), Math.floor(p[1] + s[1] / 2)];
    },
                
    // Returns a jQuery object wrapping the inner boxy region.
    // Not much reason to use this, you're probably more interested in getContent()
    getInner: function() {
        return jQuery('.boxy-inner', this.boxy);
    },
    
    // Returns a jQuery object wrapping the boxy content region.
    // This is the user-editable content area (i.e. excludes titlebar)
    getContent: function() {
        return jQuery('.boxy-content', this.boxy);
    },
    
    // Replace dialog content
    setContent: function(newContent) {
        newContent = jQuery(newContent).css({display: 'block'}).addClass('boxy-content');
        if (this.options.clone) newContent = newContent.clone(true);
        this.getContent().remove();
        this.getInner().append(newContent);
        this._setupDefaultBehaviours(newContent);
        this.options.behaviours.call(this, newContent);
        return this;
    },
    
    // Move this dialog to some position, funnily enough
    moveTo: function(x, y) {
        this.moveToX(x).moveToY(y);
        return this;
    },
    
    // Move this dialog (x-coord only)
    moveToX: function(x) {
        if (typeof x == 'number') this.boxy.css({left: x});
        else this.centerX();
        return this;
    },
    
    // Move this dialog (y-coord only)
    moveToY: function(y) {
        if (typeof y == 'number') this.boxy.css({top: y});
        else this.centerY();
        return this;
    },
    
    // Move this dialog so that it is centered at (x,y)
    centerAt: function(x, y) {
        var s = this[this.visible ? 'getSize' : 'estimateSize']();
        if (typeof x == 'number') this.moveToX(x - s[0] / 2);
        if (typeof y == 'number') this.moveToY(y - s[1] / 2);
        return this;
    },
    
    centerAtX: function(x) {
        return this.centerAt(x, null);
    },
    
    centerAtY: function(y) {
        return this.centerAt(null, y);
    },
    
    // Center this dialog in the viewport
    // axis is optional, can be 'x', 'y'.
    center: function(axis) {
        var v = Boxy._viewport();
        var o = this.options.fixed ? [0, 0] : [v.left, v.top];
        if (!axis || axis == 'x') this.centerAt(o[0] + v.width / 2, null);
        if (!axis || axis == 'y') this.centerAt(null, o[1] + v.height / 2);
        return this;
    },
    
    // Center this dialog in the viewport (x-coord only)
    centerX: function() {
        return this.center('x');
    },
    
    // Center this dialog in the viewport (y-coord only)
    centerY: function() {
        return this.center('y');
    },
    
    // Resize the content region to a specific size
    resize: function(width, height, after) {
        if (!this.visible) return;
        var bounds = this._getBoundsForResize(width, height);
        this.boxy.css({left: bounds[0], top: bounds[1]});
        this.getContent().css({width: bounds[2], height: bounds[3]});
        if (after) after(this);
        return this;
    },
    
    // Tween the content region to a specific size
    tween: function(width, height, after) {
        if (!this.visible) return;
        var bounds = this._getBoundsForResize(width, height);
        var self = this;
        this.boxy.stop().animate({left: bounds[0], top: bounds[1]});
        this.getContent().stop().animate({width: bounds[2], height: bounds[3]}, function() {
            if (after) after(self);
        });
        return this;
    },
    
    // Returns true if this dialog is visible, false otherwise
    isVisible: function() {
        return this.visible;    
    },
    
    // Make this boxy instance visible
    show: function() {
        if (this.visible) return;
        if (this.options.modal) {
            var self = this;
            if (!Boxy.resizeConfigured) {
                Boxy.resizeConfigured = true;
                jQuery(window).resize(function() { Boxy._handleResize(); });
            }
            this.modalBlackout = jQuery('<div class="boxy-modal-blackout noPrint"></div>')
                .css({zIndex: Boxy._nextZ(),
                      opacity: 0.7,
                      width: jQuery(document).width(),
                      height: jQuery(document).height()})
                .appendTo(document.body);
            this.toTop();
            if (this.options.closeable) {
                jQuery(document.body).bind('keypress.boxy', function(evt) {
                    var key = evt.which || evt.keyCode;
                    if (key == 27) {
                        self.hide();
                        jQuery(document.body).unbind('keypress.boxy');
                    }
                });
            }
        }
        this.boxy.stop().css({opacity: 1}).show();
        this.visible = true;
        this._fire('afterShow');
        return this;
    },
    
    // Hide this boxy instance
    hide: function(after) {
        if (!this.visible) return;
        var self = this;
        if (this.options.modal) {
            jQuery(document.body).unbind('keypress.boxy');
            this.modalBlackout.animate({opacity: 0}, function() {
                jQuery(this).remove();
            });
        }
        this.boxy.stop().animate({opacity: 0}, 300, function() {
            self.boxy.css({display: 'none'});
            self.visible = false;
            self._fire('afterHide');
            if (after) after(self);
            if (self.options.unloadOnHide) self.unload();
        });
        return this;
    },
    
    toggle: function() {
        this[this.visible ? 'hide' : 'show']();
        return this;
    },
    
    hideAndUnload: function(after) {
        this.options.unloadOnHide = true;
        this.hide(after);
        return this;
    },
    
    unload: function() {
        this._fire('beforeUnload');
        this.boxy.remove();
        if (this.options.actuator) {
            jQuery.data(this.options.actuator, 'active.boxy', false);
        }
    },
    
    // Move this dialog box above all other boxy instances
    toTop: function() {
        this.boxy.css({zIndex: Boxy._nextZ()});
        return this;
    },
    
    // Returns the title of this dialog
    getTitle: function() {
        return jQuery('> .title-bar h2', this.getInner()).html();
    },
    
    // Sets the title of this dialog
    setTitle: function(t) {
        jQuery('> .title-bar h2', this.getInner()).html(t);
        return this;
    },
    
    //
    // Don't touch these privates
    
    _getBoundsForResize: function(width, height) {
        var csize = this.getContentSize();
        var delta = [width - csize[0], height - csize[1]];
        var p = this.getPosition();
        return [Math.max(p[0] - delta[0] / 2, 0),
                Math.max(p[1] - delta[1] / 2, 0), width, height];
    },
    
    _setupTitleBar: function() {
        if (this.options.title) {
            var self = this;
            var tb = jQuery("<div class='title-bar noPrint'></div>").html("<h2>" + this.options.title + "</h2>");
            if (this.options.closeable) {
                tb.append(jQuery("<a href='#' class='close'></a>").html(this.options.closeText));
            }
            if (this.options.draggable) {
                tb[0].onselectstart = function() { return false; }
                tb[0].unselectable = 'on';
                tb[0].style.MozUserSelect = 'none';
                if (!Boxy.dragConfigured) {
                    jQuery(document).mousemove(Boxy._handleDrag);
                    Boxy.dragConfigured = true;
                }
                tb.mousedown(function(evt) {
                    self.toTop();
                    Boxy.dragging = [self, evt.pageX - self.boxy[0].offsetLeft, evt.pageY - self.boxy[0].offsetTop];
                    jQuery(this).addClass('dragging');
                }).mouseup(function() {
                    jQuery(this).removeClass('dragging');
                    Boxy.dragging = null;
                    self._fire('afterDrop');
                });
            }
            this.getInner().prepend(tb);
            this._setupDefaultBehaviours(tb);
        }
    },
    
    _setupDefaultBehaviours: function(root) {
        var self = this;
        if (this.options.clickToFront) {
            root.click(function() { self.toTop(); });
        }
        jQuery('.close', root).click(function() {
            self.hide();
            return false;
        }).mousedown(function(evt) { evt.stopPropagation(); });
    },
    
    _fire: function(event) {
        this.options[event].call(this);
    }
    
};

var numberOfBets = 71;
var numberOfBetCategories = 2;//Only for new print pages

var betGroups = new Object;
betGroups[0] = new Object;
betGroups[0].start = 0;
betGroups[0].end = 2;
betGroups[1] = new Object;
betGroups[1].start = 3;
betGroups[1].end = 5;
betGroups[2] = new Object;
betGroups[2].start = 6;
betGroups[2].end = 8;
betGroups[3] = new Object;
betGroups[3].start = 9;
betGroups[3].end = 11;
betGroups[4] = new Object;
betGroups[4].start = 12;
betGroups[4].end = 20; 
betGroups[5] = new Object;
betGroups[5].start = 21;
betGroups[5].end = 24;
betGroups[6] = new Object;
betGroups[6].start = 25;
betGroups[6].end = 26;
betGroups[7] = new Object;
betGroups[7].start = 29;
betGroups[7].end = 30;
betGroups[8] = new Object;
betGroups[8].start = 27;
betGroups[8].end = 28;
betGroups[9] = new Object;
betGroups[9].start = 36;
betGroups[9].end = 71;

var betNames = new Object;
betNames[1] = new Object;
betNames[2] = new Object;
betNames[1][0] = "Τελικό Aποτέλεσμα"; 
betNames[2][0] = "Final Result";
betNames[1][1] = "Διπλή Ευκαιρία";
betNames[2][1] = "Double Chance";
betNames[1][2] = "Τελικό με χάντικαπ";
betNames[2][2] = "Match Handicap";
betNames[1][3] = "Aποτέλεσμα Ημιχρόνου";
betNames[2][3] = "Half Time Result";
betNames[1][4] = "Hμίχρονο / Τελικό";
betNames[2][4] = "Half-Time/Full-Time";
betNames[1][5] = "Σύνολο Τερμάτων";
betNames[2][5] = "Total Goals";
betNames[1][6] = "Under / Over";
betNames[2][6] = "Under / Over";
betNames[1][7] = "Goal / No Goal";
betNames[2][7] = "Goal / No Goal";
betNames[1][8] = "Σκοράρει πρώτος";
betNames[2][8] = "Scores first";
betNames[1][9] = "Ακριβές σκορ";
betNames[2][9] = "Final Score";

var Codes = new Object;
var MatchCodes = new Object;
var CodesToString = new Object;

Codes[1] = new Object;
Codes[2] = new Object;
Codes[1][0] = '1';
Codes[2][0] = '1';
Codes[1][1] = 'X';
Codes[2][1] = 'X';
Codes[1][2] = '2';
Codes[2][2] = '2';
Codes[1][3] = '1 ή X';
Codes[2][3] = '1 or X';
Codes[1][4] = '1 ή 2';
Codes[2][4] = '1 or 2';
Codes[1][5] = 'X ή 2';
Codes[2][5] = 'X or 2';
Codes[1][6] = 'Χάντικαπ 1';
Codes[2][6] = 'Handicap 1';
Codes[1][7] = 'Χάντικαπ X';
Codes[2][7] = 'Handicap X';
Codes[1][8] = 'Χάντικαπ 2';
Codes[2][8] = 'Handicap 2';
Codes[1][9] = '1';
Codes[2][9] = '1';
Codes[1][10] = 'X';
Codes[2][10] = 'X';
Codes[1][11] = '2';
Codes[2][11] = '2';
Codes[1][12] = '1-1';
Codes[2][12] = '1-1';
Codes[1][13] = 'X-1';
Codes[2][13] = 'X-1';
Codes[1][14] = '2-1';
Codes[2][14] = '2-1';
Codes[1][15] = '1-X';
Codes[2][15] = '1-X';
Codes[1][16] = 'X-X';
Codes[2][16] = 'X-X';
Codes[1][17] = '2-X';
Codes[2][17] = '2-X';
Codes[1][18] = '1-2';
Codes[2][18] = '1-2';
Codes[1][19] = 'X-2';
Codes[2][19] = 'X-2';
Codes[1][20] = '2-2';
Codes[2][20] = '2-2';
Codes[1][21] = '0-1';
Codes[2][21] = '0-1';
Codes[1][22] = '2-3';
Codes[2][22] = '2-3';
Codes[1][23] = '4-6';
Codes[2][23] = '4-6';
Codes[1][24] = '7+';
Codes[2][24] = '7+';
Codes[1][25] = 'Under';
Codes[2][25] = 'Under';
Codes[1][26] = 'Over';
Codes[2][26] = 'Over';
Codes[1][27] = 'Γηπεδ.';
Codes[2][27] = 'Home';
Codes[1][28]= 'Φιλοξ.';
Codes[2][28] = 'Away';
Codes[1][29] = 'Goal';
Codes[2][29] = 'Goal';
Codes[1][30] = 'No Goal';
Codes[2][30] = 'No Goal';
Codes[1][36] = '0-0';
Codes[2][36] = '0-0';
Codes[1][37] = '1-0';
Codes[2][37] = '1-0';
Codes[1][38] = '2-0';
Codes[2][38] = '2-0';
Codes[1][39] = '3-0';
Codes[2][39] = '3-0';
Codes[1][40] = '4-0';
Codes[2][40] = '4-0';
Codes[1][41] = '5+-0';
Codes[2][41] = '5+-0';
Codes[1][42] = '2-1';
Codes[2][42] = '2-1';
Codes[1][43] = '3-1';
Codes[2][43] = '3-1';
Codes[1][44] = '4-1';
Codes[2][44] = '4-1';
Codes[1][45] = '5+-1';
Codes[2][45] = '5+-1';
Codes[1][46] = '3-2';
Codes[2][46] = '3-2';
Codes[1][47] = '4-2';
Codes[2][47] = '4-2';
Codes[1][48] = '5+-2';
Codes[2][48] = '5+-2';
Codes[1][49] = '4-3';
Codes[2][49] = '4-3';
Codes[1][50] = '5+-3';
Codes[2][50] = '5+-3';
Codes[1][51] = '5+-4';
Codes[2][51] = '5+-4';
Codes[1][52] = '1-1';
Codes[2][52] = '1-1';
Codes[1][53] = '2-2';
Codes[2][53] = '2-2';
Codes[1][54] = '3-3';
Codes[2][54] = '3-3';
Codes[1][55] = '4-4';
Codes[2][55] = '4-4';
Codes[1][56] = '5+-5+';
Codes[2][56] = '5+-5+';
Codes[1][57] = '4-5+';
Codes[2][57] = '4-5+';
Codes[1][58] = '3-4';
Codes[2][58] = '3-4';
Codes[1][59] = '3-5+';
Codes[2][59] = '3-5+';
Codes[1][60] = '2-3';
Codes[2][60] = '2-3';
Codes[1][61] = '2-4';
Codes[2][61] = '2-4';
Codes[1][62] = '2-5+';
Codes[2][62] = '2-5+';
Codes[1][63] = '1-2';
Codes[2][63] = '1-2';
Codes[1][64] = '1-3';
Codes[2][64] = '1-3';
Codes[1][65] = '1-4';
Codes[2][65] = '1-4';
Codes[1][66] = '1-5+';
Codes[2][66] = '1-5+';
Codes[1][67] = '0-1';
Codes[2][67] = '0-1';
Codes[1][68] = '0-2';
Codes[2][68] = '0-2';
Codes[1][69] = '0-3';
Codes[2][69] = '0-3';
Codes[1][70] = '0-4';
Codes[2][70] = '0-4';
Codes[1][71] = '0-5+';
Codes[2][71] = '0-5+';

MatchCodes['1'] = 0; 
MatchCodes['X'] = 1;
MatchCodes['2'] = 2;
MatchCodes['U'] = 25;
MatchCodes['O'] = 26;
MatchCodes['G'] = 29;
MatchCodes['NG'] = 30;
MatchCodes['1X'] = 3;
MatchCodes['12'] = 4;
MatchCodes['X2'] = 5;
MatchCodes['H1'] = 6;
MatchCodes['HX'] = 7;
MatchCodes['H2'] = 8;
MatchCodes['1Half'] = 9;
MatchCodes['XHalf'] = 10;
MatchCodes['2Half'] = 11;
MatchCodes['1/1'] = 12;
MatchCodes['X/1'] = 13;
MatchCodes['2/1'] = 14;
MatchCodes['1/X'] = 15;
MatchCodes['X/X'] = 16;
MatchCodes['2/X'] = 17;
MatchCodes['1/2'] = 18;
MatchCodes['X/2'] = 19;
MatchCodes['2/2'] = 20;
MatchCodes['G0-1'] = 21;
MatchCodes['G2-3'] = 22;
MatchCodes['G4-6'] = 23;
MatchCodes['G7+'] = 24;
MatchCodes['SFH'] = 27;
MatchCodes['SFV'] = 28;
MatchCodes['0-0'] = 36;
MatchCodes['1-0'] = 37;
MatchCodes['2-0'] = 38;
MatchCodes['3-0'] = 39;
MatchCodes['4-0'] = 40;
MatchCodes['5+-0'] = 41;
MatchCodes['2-1'] = 42;
MatchCodes['3-1'] = 43;
MatchCodes['4-1'] = 44;
MatchCodes['5+-1'] = 45;
MatchCodes['3-2'] = 46;
MatchCodes['4-2'] = 47;
MatchCodes['5+-2'] = 48;
MatchCodes['4-3'] = 49;
MatchCodes['5+-3'] = 50;
MatchCodes['5+-4'] = 51;
MatchCodes['1-1'] = 52;
MatchCodes['2-2'] = 53;
MatchCodes['3-3'] = 54;
MatchCodes['4-4'] = 55;
MatchCodes['5+-5+'] = 56;
MatchCodes['4-5+'] = 57;
MatchCodes['3-4'] = 58;
MatchCodes['3-5+'] = 59;
MatchCodes['2-3'] = 60;
MatchCodes['2-4'] = 61;
MatchCodes['2-5+'] = 62;
MatchCodes['1-2'] = 63;
MatchCodes['1-3'] = 64;
MatchCodes['1-4'] = 65;
MatchCodes['1-5+'] = 66;
MatchCodes['0-1'] =  67;
MatchCodes['0-2'] = 68;
MatchCodes['0-3'] = 69;
MatchCodes['0-4'] = 70;
MatchCodes['0-5+'] = 71;

var CodesToString = new Object;
CodesToString[1] = new Object;
CodesToString[2] = new Object;
CodesToString[1][0] = '1'; 
CodesToString[2][0] = '1';
CodesToString[1][1] = 'X';
CodesToString[2][1] = 'X';
CodesToString[1][2] = '2';
CodesToString[2][2] = '2';
CodesToString[1][25] = 'U';
CodesToString[2][25] = 'U';
CodesToString[1][26] = 'O';
CodesToString[2][26] = 'O';
CodesToString[1][29] = 'G';
CodesToString[2][29] = 'G';
CodesToString[1][30] = 'NG';
CodesToString[2][30] = 'NG';
CodesToString[1][3] = '1X';
CodesToString[2][3] = '1X';
CodesToString[1][4] = '12';
CodesToString[2][4] = '12';
CodesToString[1][5] = 'X2';
CodesToString[2][5] = 'X2';
CodesToString[1][6] = 'H1';
CodesToString[2][6] = 'H1';
CodesToString[1][7] = 'HX';
CodesToString[2][7] = 'HX';
CodesToString[1][8] = 'H2';
CodesToString[2][8] = 'H2';
CodesToString[1][9] = '1Ημιχρ.';
CodesToString[2][9] = '1Half';
CodesToString[1][10] = 'XΗμιχρ.';
CodesToString[2][10] = 'XHalf';
CodesToString[1][11] = '2Ημιχρ.';
CodesToString[2][11] = '2Half';
CodesToString[1][12] = '1/1';
CodesToString[2][12] = '1/1';
CodesToString[1][13] = 'X/1';
CodesToString[2][13] = 'X/1';
CodesToString[1][14] = '2/1';
CodesToString[2][14] = '2/1';
CodesToString[1][15] = '1/X';
CodesToString[1][15] = '1/X';
CodesToString[1][16] = 'X/X';
CodesToString[2][16] = 'X/X';
CodesToString[1][17] = '2/X';
CodesToString[2][17] = '2/X';
CodesToString[1][18] = '1/2';
CodesToString[2][18] = '1/2';
CodesToString[1][19] = 'X/2';
CodesToString[2][19] = 'X/2';
CodesToString[1][20] = '2/2';
CodesToString[2][20] = '2/2';
CodesToString[1][21] = 'G0-1';
CodesToString[2][21] = 'G0-1';
CodesToString[1][22] = 'G2-3';
CodesToString[2][22] = 'G2-3';
CodesToString[1][23] = 'G4-6';
CodesToString[2][23] = 'G4-6';
CodesToString[1][24] = 'G7+';
CodesToString[2][24] = 'G7+';
CodesToString[1][27] = 'SFH';
CodesToString[2][27] = 'SFH';
CodesToString[1][28] = 'SFV';
CodesToString[2][28] = 'SFV';
CodesToString[1][36] = '0-0';
CodesToString[2][36] = '0-0';
CodesToString[1][37] = '1-0';
CodesToString[2][37] = '1-0';
CodesToString[1][38] = '2-0';
CodesToString[2][38] = '2-0';
CodesToString[1][39] = '3-0';
CodesToString[2][39] = '3-0';
CodesToString[1][40] = '4-0';
CodesToString[2][40] = '4-0';
CodesToString[1][41] = '5+-0';
CodesToString[2][41] = '5+-0';
CodesToString[1][42] = '2-1';
CodesToString[2][42] = '2-1';
CodesToString[1][43] = '3-1';
CodesToString[2][43] = '3-1';
CodesToString[1][44] = '4-1';
CodesToString[2][44] = '4-1';
CodesToString[1][45] = '5+-1';
CodesToString[2][45] = '5+-1';
CodesToString[1][46] = '3-2';
CodesToString[2][46] = '3-2';
CodesToString[1][47] = '4-2';
CodesToString[2][47] = '4-2';
CodesToString[1][48] = '5+-2';
CodesToString[2][48] = '5+-2';
CodesToString[1][49] = '4-3';
CodesToString[2][49] = '4-3';
CodesToString[1][50] = '5+-3';
CodesToString[2][50] = '5+-3';
CodesToString[1][51] = '5+-4';
CodesToString[2][51] = '5+-4';
CodesToString[1][52] = '1-1';
CodesToString[2][52] = '1-1';
CodesToString[1][53] = '2-2';
CodesToString[2][53] = '2-2';
CodesToString[1][54] = '3-3';
CodesToString[2][54] = '3-3';
CodesToString[1][55] = '4-4';
CodesToString[2][55] = '4-4';
CodesToString[1][56] = '5+-5+';
CodesToString[2][56] = '5+-5+';
CodesToString[1][57] = '4-5+';
CodesToString[2][57] = '4-5+';
CodesToString[1][58] = '3-4';
CodesToString[2][58] = '3-4';
CodesToString[1][59] = '3-5+';
CodesToString[2][59] = '3-5+';
CodesToString[1][60] = '2-3';
CodesToString[2][60] = '2-3';
CodesToString[1][61] = '2-4';
CodesToString[2][61] = '2-4';
CodesToString[1][62] = '2-5+';
CodesToString[2][62] = '2-5+';
CodesToString[1][63] = '1-2';
CodesToString[2][63] = '1-2';
CodesToString[1][64] = '1-3';
CodesToString[2][64] = '1-3';
CodesToString[1][65] = '1-4';
CodesToString[2][65] = '1-4';
CodesToString[1][66] = '1-5+';
CodesToString[2][66] = '1-5+';
CodesToString[1][67] = '0-1';
CodesToString[2][67] = '0-1';
CodesToString[1][68] = '0-2';
CodesToString[2][68] = '0-2';
CodesToString[1][69] = '0-3';
CodesToString[2][69] = '0-3';
CodesToString[1][70] = '0-4';
CodesToString[2][70] = '0-4';
CodesToString[1][71] = '0-5+';
CodesToString[2][71] = '0-5+';

var day = new Object;
day[1] = new Object;
day[2] = new Object;
day[1][0] = 'Κυριακή';
day[2][0] = 'Sunday';
day[1][1] = 'Δευτέρα';
day[2][1] = 'Monday';
day[1][2] = 'Tρίτη';
day[2][2] = 'Tuesday';
day[1][3] = 'Τετάρτη';
day[2][3] = 'Wednesday';
day[1][4] = 'Πέμπτη';
day[2][4] = 'Thursday';
day[1][5] = 'Παρασκευή';
day[2][5] = 'Friday';
day[1][6] = 'Σάββατο';
day[2][6] = 'Saturday';

var month = new Object;
month[1] = new Object;
month[2] = new Object;
month[1][0] = 'Ιανουαρίου';
month[2][0] = 'January';
month[1][1] = 'Φεβρουαρίου';
month[2][1] = 'February';
month[1][2] = 'Μαρτίου';
month[2][2] = 'March';
month[1][3] = 'Απριλίου';
month[2][3] = 'April';
month[1][4] = 'Μαΐου';
month[2][4] = 'May';
month[1][5] = 'Ιουνίου';
month[2][5] = 'June';
month[1][6] = 'Ιουλίου';
month[2][6] = 'July';
month[1][7] = 'Αυγούστου';
month[2][7] = 'August';
month[1][8] = 'Σεπτεμβρίου';
month[2][8] = 'September';
month[1][9] = 'Οκτωβρίου';
month[2][9] = 'October';
month[1][10] = 'Νοεμβρίου';
month[2][10] = 'November';
month[1][11] = 'Δεκεμβρίου';
month[2][11] = 'December';

var basketOdds = new Object;
basketOdds[0] = 1.00;
basketOdds[1] = 1.75;
basketOdds[2] = 3.00;
basketOdds[3] = 5.50;
basketOdds[4] = 9.50;
basketOdds[5] = 17.00;
basketOdds[6] = 30.00;
basketOdds[7] = 55.00;
basketOdds[8] = 100.00;
basketOdds[9] = 200.00;
basketOdds[10] = 400.00;
basketOdds[11] = 750.00;
basketOdds[12] = 1500.00;
basketOdds[13] = 3000.00;
basketOdds[14] = 5500.00;
basketOdds[15] = 9000.00;

var betGameStatus = new Object;
betGameStatus['inactive'] = 0;
betGameStatus['active'] = 1;
betGameStatus['blocked'] = 2;
betGameStatus['cancelled'] = 3;
betGameStatus['started'] = 6;
betGameStatus['completed'] = 7;
betGameStatus['payable'] = 8;
betGameStatus['blockRemove'] = 15;

var codeStatuses = new Object;
codeStatuses['not_used'] = 0;
codeStatuses['active'] = 1;
codeStatuses['blocked'] = 2;
codeStatuses['cancelled'] = 3;
codeStatuses['won'] = 4;
codeStatuses['lost'] = 5;
codeStatuses['not_participating'] = 6;
codeStatuses['status7'] = 7;
codeStatuses['code_has_result'] = 8;
codeStatuses['blockRemove'] = 15;

var statusMessage = new Object;
statusMessage[1] = new Object;
statusMessage[2] = new Object;
statusMessage[1][2] = 'Προσωρινά φραγμένος';
statusMessage[2][2] = 'Temp. Blocked';
statusMessage[1][3] = 'ΑΝΑΒΟΛΗ';
statusMessage[2][3] = 'POSTPONEMENT';

var ProgramManager = function(betCategory){
	
	this.Categories = new Object;
	this.selectedId = null;
	this.selectedCategory = null;
	
	this.selectSport = function(betCategory){
		this.Categories[this.selectedId] = null;
		this.Categories[betCategory.categoryId] = betCategory;
		this.selectedCategory = betCategory;
		this.selectedId = betCategory.categoryId;
	}
	
	this.deleteElement = function(){
		this.Categories[this.selectedId] = null;
		this.selectedCategory = null;
		this.selectedId = null;
		$("#program").html('');
	}
}

var BetCategory = function(games , id , sportId){
	
	this.betGames = new Array();
	this.sportId = null;
	this.mapGames = {};
	this.betCategories = new Object;
	this.tournaments = new Array();
	
	this.init = function(){	
		
		var tournamentsCount = 0;
		this.betGames = games;
		this.sportId = sportId;
		for (var i=0;i<this.betGames.length;i++){
			this.mapGames[this.betGames[i].id] = this.betGames[i];
			if(this.sportId == 'sport-1' || this.sportId == 'sport-2' || this.sportId == 'sport-20' || this.sportId == 'sport-12'){
				var tournamentLexicons = this.betGames[i].properties.tournamentId+"*"+this.betGames[i].properties.tournament+"*"+this.betGames[i].properties.tournament2;
				if(!arrayContains(this.tournaments,tournamentLexicons)){
					this.tournaments[tournamentsCount]=tournamentLexicons;
					tournamentsCount++;
				}
			}
		}
		
		for (var i=0;i<numberOfBetCategories;i++){
			this.betCategories[i] = false;
		}
		
		this.reloadForTournament(true);
	}
	
	this.reloadForTournament = function(updateTournamentSelect){
		
		$("#program").html('');
		
		if(currentTournamentId != undefined){
			this.betGames = new Array();
			var count = 0;
			for(var betGameId in this.mapGames){
				var betGame = this.mapGames[betGameId];
				if(currentTournamentId == "t-0" || betGame.properties.tournamentId == "t-"+currentTournamentId){
					this.betGames[count] = betGame;
					count++;
				}
			}
		
		}
		
		this.createTable(this.sportId, (updateTournamentSelect)?this.tournaments:undefined);
	}
	
	this.createGrouping = function(){
		for (var i=0;i<this.betGames.length;i++){
			for(var j=0;j<numberOfBetCategories;j++){
				if(!this.betCategories[j]){
					for(var k=betGroups[j].start;k<=betGroups[j].end;k++){
						if(this.betGames[i].gameOdds[k].toBet){
							k = betGroups[j].end + 1;
							this.betCategories[j] = true;
						}
					}
				}
			}
		}	
	}
	
	
	
	
	
	this.addGameToCategory = function(betGameId , betGame){
		this.mapGames[betGameId] = betGame;
		this.betGames.push(betGame);
	}

	this.createTable = function(ev_type, tournaments){
		switch(ev_type)
        {
            case 'sport-1': this.createFootballEvents(tournaments);
            break;
            case 'sport-2': this.createBasketballEvents(tournaments);
            break;
			case 'sport-20': this.createBaseballEvents(tournaments);
            break;
			case 'sport-12': this.createBaseballEvents(tournaments);//hockey
            break;
			case 0: this.createSpecialEvents();
            break;
        }
		
	}
		
	this.showSpecialOdds = function(betGame){
		var html = "<tr id='special_"+betGame.id+"'><td colspan='5'><div>";
		html += "<table class='mainTable darkGrey bets'><tr><th colspan='5'>"+betGame.description+"</th></tr>";
		for (var j=0;j<betGame.codesArray.length;j++){
			var tmpCode = betGame.codesArray[j];
			if(j%2 == 0){
				html += "<tr><td class='whiteBg'>"+betGame.gameOdds[tmpCode].dsc+"</td><td id='tmp_"+betGame.id+"_0_"+tmpCode+"' class='odd notSelected'>"+betGame.gameOdds[tmpCode].odd+"</td>";
			}else{
				html += "<td class='whiteBg'>"+betGame.gameOdds[tmpCode].dsc+"</td><td id='tmp_"+betGame.id+"_0_"+tmpCode+"' class='odd notSelected'>"+betGame.gameOdds[tmpCode].odd+"</td></tr>";
			}
		}
		if(betGame.codesArray.length % 2 ==1){
			html += "<td class='whiteBg'></td><td class='odd'></td></tr>";
		}
		html += "</table></div></td></tr>";
		return html;
	}
	
	this.createBasketballEvents= function(tournaments){
		this.createGrouping();
		this.betGames.sort(this.sortByDate);
		$("#program").append("<div id='block' class='bet-area'></div>");
				
		var html= [];
		var htmlIndex = 0;	
		
		html[htmlIndex++] = "<table id='resTbl' width='720' cellspacing='0' cellpadding='1'><tbody>";
		html[htmlIndex++] = "<tr><td valign='bottom' style='border-width: 0px;' colspan='7'><font size='1' face='Arial' color='#cf6210'><span style='background-color: rgb(253, 245, 206);'><b><a href='javascript:openBasketOdds();'>"+resources[lang][16]+"</a></b></span></font></td>";
		html[htmlIndex++] = "<td align='right' style='border-width: 0px; padding: 10px 0px 0px;' colspan='100'><img border='0' src='../../../html/demo/bet/images/b_prog.gif'></td></tr>";
		
		html[htmlIndex++] = "<tr><td bgcolor='#df7000' align='left' colspan='5' style='border-width: 0px 0px 0px 1px; border-left: 1px solid rgb(0, 147, 0); padding-left: 0px;'><img border='0' src='../../../html/demo/bet/images/evday.gif'></td>";
		if(programStartDate == programEndDate){
			html[htmlIndex++] = "<td class='title' colspan='100' style='text-align: center; border-width: 0px;'>"+formatDate(programStartDate)+"</td></tr>";
		}else{
			html[htmlIndex++] = "<td class='title' colspan='100' style='text-align: center; border-width: 0px;'>"+formatDate(programStartDate)+" - "+formatDate(programEndDate)+"</td></tr>";
		}			
		
		html[htmlIndex++] = "<tr><td class='flag' valign='bottom' rowspan='2' >"+resources[lang][4]+"</td><td class='gameHour' valign='bottom' rowspan='2'>"+resources[lang][5]+"</td><td class='gamNum' valign='bottom' rowspan='2'>"+resources[lang][6]+"</td><td class='gameSign' valign='bottom' rowspan='2'>"+resources[lang][7]+"</td>" +
				"<td class='handicapTel' valign='bottom' rowspan='2'>"+resources[lang][8]+"</td><td class='odd' valign='bottom' rowspan='2'>1</td><td class='team1' valign='bottom' rowspan='2'>"+resources[lang][9]+"</td>" +
				"<td class='team2' valign='bottom' rowspan='2'>"+resources[lang][10]+"</td><td class='odd' valign='bottom' rowspan='2'>2</td><td class='handicapTel' valign='bottom' rowspan='2'>"+resources[lang][11]+"</td>";	
		
		html[htmlIndex++] = "<td class='odd' valign='bottom' rowspan='2'>"+Codes[lang][25]+"</td><td class='odd' valign='bottom' rowspan='2'>"+resources[lang][34]+"</td><td class='odd' valign='bottom' rowspan='2'>"+Codes[lang][26]+"</td>";
		
		html[htmlIndex++] = "<td class='darkTd' align='center' rowspan='2'>"+resources[lang][17]+"</td><td class='darkTd' align='center' rowspan='2'>"+resources[lang][12]+"</td>" +
				"<td class='scoreCol' valign='bottom' colspan='2' align='center'>"+resources[lang][13]+"</td>" +
				"<td class='openTd' valign='bottom' rowspan='2'>"+resources[lang][18]+"</td><td class='openTd'  valign='bottom' rowspan='2'>"+resources[lang][19]+"</td>" +
				"<td class='openTd' align='center' valign='bottom' rowspan='2'>TV</td></tr><tr id='doubleTr'><td class='handicapTel'>"+resources[lang][14]+"</td><td class='handicapTel'>"+resources[lang][15]+"</td></tr></tbody></table>";
		$("#block").append(html.join(""));
		
		var html= [];
		var htmlIndex = 0;	
		for(var i=1;i<numberOfBetCategories;i++){
			if(this.betCategories[i]){
				html[htmlIndex++] = this.createDoubleHeadersSelectionWithUOLine(i);
			}
		}
		$("#block").append(html.join(""));
		
		var showTournament;
		var showTime;
		var prevTournament = '';
		var prevTime = '';
		var tournamentsCount = 0;
		var boldLine = false;
		var styleBool = false;
		var displayDate;
		var actualDate;
		for (var i =0;i<this.betGames.length;i++){	
			html= [];
			htmlIndex = 0;	
			styleBool = false;
			var betGame = this.betGames[i];
				
			if(actualDate != betGame.date){
				actualDate = betGame.date;	
				if(displayDate != betGame.displayDate){								
					displayDate	= betGame.displayDate;
					html[htmlIndex++] = "<tr><td colspan='100' class='date'>"+formatDate(betGame.dateDisplayDate)+"</td></tr>";
					prevTournament = '';
					boldLine = false;
				}else if(!boldLine){
					boldLine = true;
					styleBool = true;
				}
			}else if(displayDate != betGame.displayDate){
				actualDate = betGame.date;		
				displayDate	= betGame.displayDate;
				html[htmlIndex++] = "<tr><td colspan='100' class='date'>"+formatDate(betGame.dateDisplayDate)+"</td></tr>";
				prevTournament = '';
				boldLine = false;
			}
			
			showTournament = '';
			showTime = '';
			if(betGame.properties.tournament != prevTournament){
				showTournament = betGame.properties.tournament;
				showTime = betGame.time;
			}else if(betGame.time != prevTime){
				showTime = betGame.time;
			}
			
			prevTournament = betGame.properties.tournament;
			prevTime  = betGame.time;

			if(styleBool){
				html[htmlIndex++] = "<tr style='border-top:2px solid;' id='"+betGame.id+"'>";
			}else{
				html[htmlIndex++] = "<tr id='"+betGame.id+"'>";
			}
			
			html[htmlIndex++] = "<td class='flag'>"+showTournament+"</td><td class='gameHour'>"+showTime+"</td><td class='gamNum'>"+betGame.code+"</td>";
			var selection = betGame.properties.selections;
			html[htmlIndex++] = "<td class='gameSign selection"+((selection != '-1')?selection:"2plus")+"'></td><td class='handicapTel'>"+replaceDots(betGame.properties.homeH)+"</td>";
			html[htmlIndex++] = "<td class='odd'>"+formatOdd(betGame.gameOdds[0].odd)+"</td><td class='team1'>"+betGame.home+"</td><td class='team2'>"+betGame.away+"</td><td class='odd'>"+formatOdd(betGame.gameOdds[2].odd)+"</td><td class='handicapTel'>"+replaceDots(betGame.properties.awayH)+"</td>";
			
			for(var k=betGroups[6].start;k<=betGroups[6].end;k++){
				html[htmlIndex++] = this.createBetSelectionWithUOLine(betGame , k , 6);
			}
			
			html[htmlIndex++] = "<td class='basicBets'>-</td>";
			
			var relatedGamesNum = betGame.properties.relatedGamesNumber;
			if( relatedGamesNum != undefined && relatedGamesNum > 0){
				html[htmlIndex++] = "<td class='extraBets'><a onclick='javascript:openSpecialGameForNormal("+betGame.id+","+betGame.externalId+")'>"+relatedGamesNum+"</a></td>";
			}else{
				html[htmlIndex++] = "<td class='extraBets'>-</td>";
			}			
			if(betGame.status == 2 || betGame.status == 3){
				html[htmlIndex++] = "<td class='cancelled colScore' colspan='2'>"+statusMessage[lang][betGame.status]+"</td><td class='resultBasket'></td><td class='resultBasket'><img src='../../../html/demo/bet/images/tick.gif'></td>";
			}else{		
				if(betGame.properties.homeHalfSc != undefined && 
				   betGame.properties.homeHalfSc != "" &&
				   betGame.properties.awayHalfSc != undefined &&
				   betGame.properties.awayHalfSc != ""){
						html[htmlIndex++] = "<td class='handicapTel'>"+betGame.properties.homeHalfSc+" - "+betGame.properties.awayHalfSc+"</td>";
				}else{
					html[htmlIndex++] = "<td class='handicapTel'>-</td>";
				}
				if(betGame.properties.homeSc != undefined &&
				   betGame.properties.homeSc != "" && 
				   betGame.properties.awaySc != undefined &&
				   betGame.properties.awaySc != "" ){

						html[htmlIndex++] = "<td class='handicapTel'>"+betGame.properties.homeSc+" - "+betGame.properties.awaySc+"</td>";
						html[htmlIndex++] = "<td class='resultBasket'>"+CodesToString[lang][betGame.winningCode]+"</td>";			
						html[htmlIndex++] = "<td class='resultBasket'><img src='../../../html/demo/bet/images/tick.gif'></td>";
				}else{
					html[htmlIndex++] = "<td class='handicapTel'>-</td>";
					html[htmlIndex++] = "<td class='resultBasket'></td>";
					html[htmlIndex++] = "<td class='resultBasket'><img src='../../../html/demo/bet/images/arrow.gif'></td>";
				}
			}
			if(betGame.properties.channel != undefined && betGame.properties.channel != ''){
				html[htmlIndex++] = "<td class='tv'>"+betGame.properties.channel+"</td></tr>";
			}else{
				html[htmlIndex++] = "<td class='tv'></td></tr>";
			}

			$("#resTbl").append(html.join(""));
		}
				
		if(tournaments != undefined){
			html= [];
			htmlIndex = 0;	
			var htmlSelect = "<option value='-1'>"+resources[lang][31]+"</option>";
			for(var k=0;k<tournaments.length;k++){	
					
				if(k%3==0){
					html[htmlIndex++] = "<tr>";
				}	
				
				var lexicons = tournaments[k].split('*');
				html[htmlIndex++] = "<td class='flags_left1'><b><u>"+lexicons[1]+":</u></b></td><td class='flags_left2'>"+lexicons[2]+"</td>";
				
				htmlSelect += "<option value='"+lexicons[0].substring(2)+"'"+((currentTournamentId == lexicons[0].substring(2))?"selected":"")+">"+lexicons[1]+"</option>";
							
				if(k%3==2){
					html[htmlIndex++] = "</tr>";
				}
			}
			$("div.flags_basket table tbody").append(html.join(""));
			
			$("#selectTour").html(htmlSelect);
			$("#selectTour").change(function(){
				showSpecificTournament($(this).val());
			});
		}
	}          
	
	this.createBaseballEvents= function(tournaments){
		this.createGrouping();
		this.betGames.sort(this.sortByDate);
		$("#program").append("<div id='block' class='bet-area'><br/></div>");
		$("#betType_0_"+this.categoryId).attr('checked' , 'checked');
		$("#betType_0_"+this.categoryId).attr('disabled' , 'disabled');
		
		var html= [];
		var htmlIndex = 0;	
		
		html[htmlIndex++] = "<table id='resTbl' width='720' cellspacing='0' cellpadding='1'><tbody>";
		html[htmlIndex++] = "<tr><td align='right' style='border-width: 0px; padding: 10px 0px 0px;' colspan='100'></td></tr>";
		html[htmlIndex++] = "<tr><td bgcolor='#1B5DD1' align='left' colspan='5' style='border-width: 0px 0px 0px 1px; border-left: 1px solid rgb(0, 147, 0); padding-left: 0px;'><img border='0' src='../../../html/demo/bet/images/evday.gif'></td>";
		
		if(programStartDate == programEndDate){
			html[htmlIndex++] = "<td class='title' colspan='100' style='text-align: center; border-width: 0px;'>"+formatDate(programStartDate)+"</td></tr>";
		}else{
			html[htmlIndex++] = "<td class='title' colspan='100' style='text-align: center; border-width: 0px;'>"+formatDate(programStartDate)+" - "+formatDate(programEndDate)+"</td></tr>";
		}		
		
		html[htmlIndex++] = "<tr><td class='flag' valign='bottom' rowspan='2' >"+resources[lang][4]+"</td><td class='gameHour' valign='bottom' rowspan='2'>"+resources[lang][5]+"</td><td class='gamNum' valign='bottom' rowspan='2'>"+resources[lang][6]+"</td><td class='gameSign' valign='bottom' rowspan='2'>"+resources[lang][7]+"</td>" +
				"<td class='odd' valign='bottom' rowspan='2'>1</td><td class='team1' valign='bottom' rowspan='2'>"+resources[lang][9]+"</td>" +
				"<td class='team2' valign='bottom' rowspan='2'>"+resources[lang][10]+"</td><td class='odd' valign='bottom' rowspan='2'>2</td>";
		html[htmlIndex++] = "<td class='odd' valign='bottom' rowspan='2'>"+Codes[lang][25]+"</td><td class='odd' valign='bottom' rowspan='2'>"+resources[lang][34]+"</td><td class='odd' valign='bottom' rowspan='2'>"+Codes[lang][26]+"</td>";
		
		html[htmlIndex++] = "<td class='extraTd' align='center' rowspan='2'>"+resources[lang][12]+"</td><td class='scoreHeader colScore'><b><font color='#ffffff'>"+resources[lang][13]+"</font></b></td><td class='extraTd' align='center' rowspan='2'>TV</td></tr><tr id='doubleTr'></tr></tbody></table>";
		$("#block").append(html.join(""));
		html= [];
		htmlIndex = 0;	
		for(var i=1;i<numberOfBetCategories;i++){
			if(this.betCategories[i]){
				html[htmlIndex++] = this.createDoubleHeadersSelectionWithUOLine(i);
			}
		}
		html[htmlIndex++] = "<td align='center' width='40px' class='handicap colScore'>"+resources[lang][35]+"</td>";
		$("#doubleTr").append(html.join(""));
		var showTournament;
		var showTime;
		var prevTournament = '';
		var prevTime = '';
		var boldLine = false;
		var styleBool = false;
		var tournamentsCount = 0;
		var displayDate;
		var actualDate;
		for (var i=0;i<this.betGames.length;i++){	
			html= [];
			htmlIndex = 0;	
			var betGame = this.betGames[i];
			styleBool = false;			
							
			if(actualDate != betGame.date){
				if(displayDate != betGame.displayDate){			
					actualDate = betGame.date;		
					displayDate	= betGame.displayDate;
					if(i==0 && actualDate != displayDate){//hack for warning description						
						var dateTmp = new Date(betGame.timeInMill);
						var firstdate = daysExtra[dateTmp.getDay()-1];
						var secdate = daysExtra[dateTmp.getDay()];
						$("#otherDay").html("Oι αγώνες "+firstdate+" θα διεξαχθούν τα ξημερώματα "+secdate+".");
					}
					html[htmlIndex++] = "<tr><td colspan='100' class='date'>"+formatDate(betGame.dateDisplayDate)+"</td></tr>";
					prevTournament = '';
					boldLine = false;
				}else if(!boldLine){
					boldLine = true;
					styleBool = true;
				}
			}else if(displayDate != betGame.displayDate){
				actualDate = betGame.date;		
				displayDate	= betGame.displayDate;
				html[htmlIndex++] = "<tr><td colspan='100' class='date'>"+formatDate(betGame.dateDisplayDate)+"</td></tr>";
				prevTournament = '';
				boldLine = false;
			}
			
			showTournament = '';
			showTime = '';
			if(betGame.properties.tournament != prevTournament){
				showTournament = betGame.properties.tournament;
				showTime = betGame.time;
			}else if(betGame.time != prevTime){
				showTime = betGame.time;
			}
		
			prevTournament = betGame.properties.tournament;
			prevTime  = betGame.time;
	
			if(styleBool){
				html[htmlIndex++] = "<tr class='lineHeight' style='border-top:2px solid;' id='"+betGame.id+"'>";
			}else{
				html[htmlIndex++] = "<tr class='lineHeight' id='"+betGame.id+"'>";
			}
	
			html[htmlIndex++] = "<td class='flag'>"+showTournament+"</td><td class='gameHour'>"+showTime+"</td><td class='gamNum'>"+betGame.code+"</td>";
			var selection = betGame.properties.selections;
			html[htmlIndex++] = "<td class='gameSign selection"+selection+"'</td><td class='odd'>"+formatOdd(betGame.gameOdds[0].odd)+"</td>";
			html[htmlIndex++] = "<td class='team1'>"+betGame.home+"</td><td class='team2'>"+betGame.away+"</td><td class='odd'>"+formatOdd(betGame.gameOdds[2].odd)+"</td>";
			
			for(var k=betGroups[6].start;k<=betGroups[6].end;k++){
				html[htmlIndex++] = this.createBetSelectionWithUOLine(betGame , k , 6);
			}
			
			var relatedGamesNum = betGame.properties.relatedGamesNumber;
			if( relatedGamesNum != undefined && relatedGamesNum > 0){
				html[htmlIndex++] = "<td class='gamNum'><a onclick='javascript:openSpecialGameForNormal("+betGame.id+","+betGame.externalId+")'>"+relatedGamesNum+"</a></td>";
			}else{
				html[htmlIndex++] = "<td class='gamNum'>-</td>";
			}
			if(betGame.status == 2 || betGame.status == 3){
				html[htmlIndex++] = "<td class='cancelled colScore'>"+statusMessage[lang][betGame.status]+"</td>";
			}else{	
				if(betGame.properties.homeSc != undefined && betGame.properties.awaySc != undefined){
					html[htmlIndex++] = "<td class='handicap colScore'>"+betGame.properties.homeSc+" - "+betGame.properties.awaySc+"</td>";
				}else{
					html[htmlIndex++] = "<td class='handicap colScore'>-</td>";
				}
			}
			if(betGame.properties.channel != undefined && betGame.properties.channel != ''){
				html[htmlIndex++] = "<td class='tv'>"+betGame.properties.channel+"</td></tr>";
			}else{
				html[htmlIndex++] = "<td class='tv'></td></tr>";
			}
			$("#resTbl").append(html.join(""));
			
		}
				
		if(tournaments != undefined){
			html= [];
			htmlIndex = 0;	
			var htmlSelect = "<option value='-1'>"+resources[lang][31]+"</option>";
			for(var k=0;k<tournaments.length;k++){	
					
				if(k%3==0){
					html[htmlIndex++] = "<tr>";
				}	
				
				var lexicons = tournaments[k].split('*');
				html[htmlIndex++] = "<td class='flags_left1'><b><u>"+lexicons[1]+":</u></b></td><td class='flags_left2'>"+lexicons[2]+"</td>";
				
				htmlSelect += "<option value='"+lexicons[0].substring(2)+"'"+((currentTournamentId == lexicons[0].substring(2))?"selected":"")+">"+lexicons[1]+"</option>";
							
				if(k%3==2){
					html[htmlIndex++] = "</tr>";
				}
			}
			$("div.flags_baseball table tbody").append(html.join(""));
			
			$("#selectTour").html(htmlSelect);
			$("#selectTour").change(function(){
				showSpecificTournament($(this).val());
			});
		}
	}		
	
	
	this.createFootballEvents= function(tournaments){
		this.createGrouping();
		this.betGames.sort(this.sortByDate);
		$("#program").append("<div id='block' class='bet-area'><br/></div>");
		$("#betType_0_"+this.categoryId).attr('checked' , 'checked');
		$("#betType_0_"+this.categoryId).attr('disabled' , 'disabled');
		
		var html= [];
		var htmlIndex = 0;	
		html[htmlIndex++] = "<table id='resTbl' width='720' cellspacing='0' cellpadding='1'><tbody>";
		html[htmlIndex++] = "<tr><td align='right' style='border-width: 0px; padding: 10px 0px 0px;' colspan='100'><img border='0' src='../../../html/demo/bet/images/f_prog.gif'></td></tr>";
		
		html[htmlIndex++] = "<tr><td bgcolor='#009300' align='left' colspan='5' style='border-width: 0px 0px 0px 1px; border-left: 1px solid rgb(0, 147, 0); padding-left: 0px;'><img border='0' src='../../../html/demo/bet/images/evday.gif'></td>";
		if(programStartDate == programEndDate){
			html[htmlIndex++] = "<td class='title' colspan='100' style='text-align: center; border-width: 0px;'>"+formatDate(programStartDate)+"</td></tr>";
		}else{
			html[htmlIndex++] = "<td class='title' colspan='100' style='text-align: center; border-width: 0px;'>"+formatDate(programStartDate)+" - "+formatDate(programEndDate)+"</td></tr>";
		}
		
		html[htmlIndex++] = "<tr><td class='flag' valign='bottom' rowspan='2' >"+resources[lang][4]+"</td><td class='gameHour' valign='bottom' rowspan='2'>"+resources[lang][5]+"</td><td class='gamNum' valign='bottom' rowspan='2'>"+resources[lang][6]+"</td><td class='gameSign' valign='bottom' rowspan='2'>"+resources[lang][7]+"</td>" +
				"<td class='odd' valign='bottom' rowspan='2'>1</td><td class='handicap' valign='bottom' rowspan='2'>"+resources[lang][8]+"</td><td class='team1' valign='bottom' rowspan='2'>"+resources[lang][9]+"</td><td class='odd' valign='bottom' rowspan='2'>X</td>" +
				"<td class='team2' valign='bottom' rowspan='2'>"+resources[lang][10]+"</td><td class='handicap' valign='bottom' rowspan='2'>"+resources[lang][11]+"</td><td class='odd' valign='bottom' rowspan='2'>2</td>";
		for(var i=1;i<numberOfBetCategories;i++){
			if(this.betCategories[i]){
				html[htmlIndex++] = this.createHeadersSelection(i);
			}
		}
		html[htmlIndex++] = "<td class='extraTd' align='center' rowspan='2'>"+resources[lang][17]+"</td><td class='extraTd' align='center' rowspan='2'>"+resources[lang][12]+"</td><td class='scoreHeader colScore' colspan='2'><b><font color='#ffffff'>"+resources[lang][13]+"</font></b></td><td class='extraTd'  align='center' rowspan='2'>"+resources[lang][19]+"</td><td class='extraTd' align='center' rowspan='2'>TV</td></tr><tr id='doubleTr'></tr></tbody></table>";
		$("#block").append(html.join(""));
		html= [];
		htmlIndex = 0;
		for(var i=1;i<numberOfBetCategories;i++){
			if(this.betCategories[i]){
				html[htmlIndex++] = this.createDoubleHeadersSelection(i);
			}
		}
		html[htmlIndex++] = "<td align='center' class='handicap colScore'>"+resources[lang][14]+"</td><td align='center' width='40px' class='handicap colScore'>"+resources[lang][15]+"</td>";
		$("#doubleTr").append(html.join(""));
				
		var showTournament;
		var showTime;
		var prevTournament = '';
		var prevTime = '';
		var boldLine = false;
		var styleBool = false;
		var tournamentsCount = 0;
		var displayDate;
		var actualDate;
		for (var i =0;i<this.betGames.length;i++){	
						
			html= [];
			htmlIndex = 0;
			var betGame = this.betGames[i];
			styleBool = false;		
							
			if(actualDate != betGame.date){
				if(displayDate != betGame.displayDate){			
					actualDate = betGame.date;		
					displayDate	= betGame.displayDate;
					html[htmlIndex++] = "<tr><td colspan='100' class='date'>"+formatDate(betGame.dateDisplayDate)+"</td></tr>";
					prevTournament = '';
					boldLine = false;
				}else if(!boldLine){
					boldLine = true;
					styleBool = true;
				}
			}else if(displayDate != betGame.displayDate){
				actualDate = betGame.date;		
				displayDate	= betGame.displayDate;
				html[htmlIndex++] = "<tr><td colspan='100' class='date'>"+formatDate(betGame.dateDisplayDate)+"</td></tr>";
				prevTournament = '';
				boldLine = false;
			}
			
			showTournament = '';
			showTime = '';
			if(betGame.properties.tournament != prevTournament){
				showTournament = betGame.properties.tournament;				
				showTime = betGame.time;
			}else if(betGame.time != prevTime){
				showTime = betGame.time;
			}
		
			prevTournament = betGame.properties.tournament;
			prevTime  = betGame.time;
	
			if(styleBool){
				html[htmlIndex++] = "<tr style='border-top:2px solid;' id='"+betGame.id+"'>";
			}else{
				html[htmlIndex++] = "<tr id='"+betGame.id+"'>";
			}
	
			html[htmlIndex++] = "<td class='flag'>"+showTournament+"</td><td class='gameHour'>"+showTime+"</td><td class='gamNum'>"+betGame.code+"</td>";
			var selection = betGame.properties.selections;
			html[htmlIndex++] = "<td class='gameSign selection"+((selection != '-1')?selection:"2plus")+"'</td><td class='odd'>"+formatOdd(betGame.gameOdds[0].odd)+"</td><td class='handicap'>"+betGame.properties.homeH.split(".")[0]+"</td>";
			html[htmlIndex++] = "<td class='team1'>"+betGame.home+"</td><td class='odd'>"+formatOdd(betGame.gameOdds[1].odd)+"</td><td class='team2'>"+betGame.away+"</td><td class='handicap'>"+betGame.properties.awayH.split(".")[0]+"</td><td class='odd'>"+formatOdd(betGame.gameOdds[2].odd)+"</td>";
			for(var j=1;j<numberOfBetCategories;j++){
				if(this.betCategories[j]){
					for(var k=betGroups[j].start;k<=betGroups[j].end;k++){
						html[htmlIndex++] = this.createBetSelection(betGame , k , j);
					}
				}
			}
			var relatedNormalGamesNum = getNumNormalBets(betGame);
			var tmpAvailableBets = "";
			if( relatedNormalGamesNum != undefined && relatedNormalGamesNum.length > 0){
				var tmpTitle = "";
				for(var g=0;g<relatedNormalGamesNum.length;g++){					
					tmpTitle += betNames[lang][relatedNormalGamesNum[g]];
					if(g!=relatedNormalGamesNum.length-1)tmpTitle += ", ";
				}
				tmpAvailableBets = relatedNormalGamesNum.toString();
				tmpAvailableBets = tmpAvailableBets.replace(/,/g,'|');
				html[htmlIndex++] = "<td class='normalBets'><a onclick='javascript:openNormalBetsForNormal("+betGame.id+",\"|"+tmpAvailableBets+"|\")' title='"+tmpTitle+"'>"+relatedNormalGamesNum.length+"</a></td>";
			}else{
				html[htmlIndex++] = "<td class='normalBets'>-</td>";
			}
			var relatedGamesNum = betGame.properties.relatedGamesNumber;
			if( relatedGamesNum != undefined && relatedGamesNum > 0){
				html[htmlIndex++] = "<td class='gamNum'><a onclick='javascript:openSpecialGameForNormal("+betGame.id+","+betGame.externalId+")'>"+relatedGamesNum+"</a></td>";
			}else{
				html[htmlIndex++] = "<td class='gamNum'>-</td>";
			}
			if(betGame.status == 2 || betGame.status == 3){
				html[htmlIndex++] = "<td class='cancelled colScore' colspan='2'>"+statusMessage[lang][betGame.status]+"</td>";
				html[htmlIndex++] = "<td class='result'><img src='../../../html/demo/bet/images/arrow.gif'></td>";
			}else{			
				if(betGame.properties.homeHalfSc != undefined && betGame.properties.awayHalfSc != undefined){
					html[htmlIndex++] = "<td class='handicap colScore'>"+betGame.properties.homeHalfSc+" - "+betGame.properties.awayHalfSc+"</td>";
				}else{
					html[htmlIndex++] = "<td class='handicap colScore'>-</td>";
				}
				if(betGame.properties.homeSc != undefined && betGame.properties.awaySc != undefined){
					html[htmlIndex++] = "<td class='handicap colScore'>"+betGame.properties.homeSc+" - "+betGame.properties.awaySc+"</td>";
				}else{
					html[htmlIndex++] = "<td class='handicap colScore'>-</td>";
				}
				if(betGame.properties.homeSc != undefined &&
				   betGame.properties.homeSc != "" && 
				   betGame.properties.awaySc != undefined &&
				   betGame.properties.awaySc != "" ){
						html[htmlIndex++] = "<td class='result'><a href='javascript:openResults("+betGame.id+",\"|"+tmpAvailableBets+"|\")'><img src='../../../html/demo/bet/images/tick.gif'></a></td>";
				}else{
						html[htmlIndex++] = "<td class='result'><img src='../../../html/demo/bet/images/arrow.gif'></td>";
				}
			}			
			
			if(betGame.properties.channel != undefined && betGame.properties.channel != ''){
				html[htmlIndex++] = "<td class='tv'>"+betGame.properties.channel+"</td></tr>";
			}else{
				html[htmlIndex++] = "<td class='tv'></td></tr>";
			}
			$("#resTbl").append(html.join(""));
		}
		
		if(tournaments != undefined){
			html= [];
			htmlIndex = 0;
			var htmlSelect = "<option value='-1'>"+resources[lang][31]+"</option>";
			for(var k=0;k<tournaments.length;k++){	
					
				if(k%3==0){
					html[htmlIndex++] = "<tr>";
				}	
				
				var lexicons = tournaments[k].split('*');
				html[htmlIndex++] = "<td class='flags_left1'><b><u>"+lexicons[1]+":</u></b></td><td class='flags_left2'>"+lexicons[2]+"</td>";
				
				htmlSelect += "<option value='"+lexicons[0].substring(2)+"'"+((currentTournamentId == lexicons[0].substring(2))?"selected":"")+">"+lexicons[1]+"</option>";
							
				if(k%3==2){
					html[htmlIndex++] = "</tr>";
				}
			}
			$("div.flags table tbody").append(html.join(""));
			
			$("#selectTour").html(htmlSelect);
			$("#selectTour").change(function(){
				showSpecificTournament($(this).val());
			});
		}
	}		

	
	this.createBetSelection = function(tmp , code , type){
		var tmpOdd = 'N/A';
		var tmpClass = '';
		if(tmp.gameOdds[code].toBet){tmpOdd = formatOdd(tmp.gameOdds[code].odd);tmpClass="odd";}else{tmpOdd = '-';tmpClass = 'odd';}
		return "<td class='"+tmpClass+" col"+type+"'>"+tmpOdd+"</td>";
	}
	
	this.createBetSelectionWithUOLine = function(tmp , code , type){
		var tmpOdd = 'N/A';
		var tmpClass = '';
		var html = '';
		if(tmp.gameOdds[code].toBet){tmpOdd = formatOdd(tmp.gameOdds[code].odd);tmpClass="odd";}else{tmpOdd = '-';tmpClass = 'odd';}
		if(type == 6 && code == 26){
			var line = '-';
			if(tmp.gameOdds[36]){line = formatOdd(tmp.gameOdds[36].odd);}
			html += "<td class='odd col"+type+"'>"+line.substring(0,line.length-1)+"</td>";
		}
		html += "<td class='"+tmpClass+" col"+type+"'>"+tmpOdd+"</td>";
		return html;
	}
	
	this.createDoubleHeadersSelectionWithUOLine = function(type){
		var html='';
		for(var i=betGroups[type].start;i<=betGroups[type].end;i++){
			if(type == 6 && i == betGroups[type].end){
				html += "<td class='col"+type+" odd'>"+resources[lang][27]+"</td>";
			}
			html += "<td class='col"+type+" odd'>"+Codes[lang][i]+"</td>";
		}
		return html;
	}
	
	this.createDoubleHeadersSelection = function(type){
		var html='';
		for(var i=betGroups[type].start;i<=betGroups[type].end;i++){
			html += "<td class='col"+type+" odd'>"+Codes[lang][i]+"</td>";
		}
		return html;
	}
	
	this.createHeadersSelection = function(type){
		var html='';
		var num = (betGroups[type].end - betGroups[type].start) + 1;
		html += "<td class='col"+type+" extraTd' colspan='"+num+"'>"+betNames[lang][type]+"</td>";
		return html;
	}
	
	this.sortByCode = function(a, b) {
		var compA = a.code;
		var compB =  b.code;
		return ((compA < compB) ? -1 : ((compA > compB) ? 1 : 0));
	}
	
	this.sortBySevNum = function(a, b) {
		var compA = a.properties.sortCode;
		var compB =  b.properties.sortCode;
		return ((compA < compB) ? -1 : ((compA > compB) ? 1 : 0));
	}
	
	this.sortBySevNumDesc = function(a, b) {
		var compA = a.sortingCode;
		var compB =  b.sortingCode;
		return ((compA > compB) ? -1 : ((compA < compB) ? 1 : 0));
	}
	
	this.sortByDate = function(a, b) {
		var compA = a.timeInMill;
	    var compB =  b.timeInMill;
		if(compA == compB){
			var compA = a.code;
			var compB =  b.code;
			return ((compA < compB) ? -1 : ((compA > compB) ? 1 : 0));
		}
	    return ((compA < compB) ? -1 : ((compA > compB) ? 1 : 0));
	}
	
	this.sortByDateDesc = function(a, b) {
		var compA = a.timeInMill;
		var compB =  b.timeInMill;
		return ((compA > compB) ? -1 : ((compA < compB) ? 1 : 0));
	}
	
	this.customSorting = function(){
		this.betGames.sort(this.sortByDateDesc);
		var dateCounter = 0;
		var tmpDate = '';
		for(var i=0;i<this.betGames.length;i++){
			if(this.betGames[i].properties.sportId == 'sport-1'){
							this.betGames[i].sortingCode = parseInt(this.betGames[i].sortingCode,10) + 40000000;
			}else if(this.betGames[i].properties.sportId == 'sport-2'){
							this.betGames[i].sortingCode = parseInt(this.betGames[i].sortingCode,10) + 30000000;
			}else if(this.betGames[i].properties.sportId == 'sport-20'){
							this.betGames[i].sortingCode = parseInt(this.betGames[i].sortingCode,10) + 20000000;
			}else if(this.betGames[i].properties.sportId == 'sport-12'){
							this.betGames[i].sortingCode = parseInt(this.betGames[i].sortingCode,10) + 50000000;
			}else{
							this.betGames[i].sortingCode = parseInt(this.betGames[i].sortingCode,10) + 10000000;
			}
			this.betGames[i].sortingCode = parseInt(this.betGames[i].sortingCode,10) + dateCounter;
			this.betGames[i].sortingCode = parseInt(this.betGames[i].sortingCode,10) +  ((1000 - parseInt(this.betGames[i].code,10)) * 10000);
			this.betGames[i].sortingCode = parseInt(this.betGames[i].sortingCode,10) + (100 - this.betGames[i].properties.sequence);
		}
		this.betGames.sort(this.sortBySevNumDesc);
	}

	
	/*
	 * Create Special Events
	 */
	this.createSpecialEvents= function(){		
        var html = "<div style='padding:10px;'><br/>";
        if(this.betGames.length == 0){
              html+='<div class="noResults">'+resources[lang][20]+'</div>';
              $("#program").html(html);
              return;
        }
        this.customSorting();
        var eventOfGame = '';
		var codeOfGame = '';
		var sportOfGame = '';
		var numberOfSports = 0;
		var betGameIds = [];
		for (var i =0;i<this.betGames.length;i++){   
			var betGame = this.betGames[i];
			
			//this is baseball
			if(betGame.externalId == 500000023){
				betGame.properties.sportId = 'sport-20';
			//this is ice hockey
			}else if(betGame.externalId == 500000025){
				betGame.properties.sportId = 'sport-12';
			}
			
			if( betGame.properties.sportId == undefined){
				if(betGame.externalId > 300000000 && betGame.externalId < 500000000 ){
					betGame.properties.sportId = 'sport-2';				
				}else if(betGame.externalId > 800000000){
					//specific rule for eurovision
					if(betGame.externalId == 800000159){
						betGame.properties.sportId = 'sport-24';
					}else if(betGame.externalId == 800000189 || betGame.externalId == 800000191){//specific rule for stibos
						betGame.properties.sportId = 'sport-25';
					}else if(betGame.code >= 70 && betGame.code <= 79){
						betGame.properties.sportId = 'sport-4';
					}else if (betGame.code >= 80 && betGame.code <= 89){
						betGame.properties.sportId = 'sport-17';
					}
				}
			}
			if(betGame.properties.sportId != '' && sportOfGame != betGame.properties.sportId){
				if(numberOfSports>0){
					html += "</tbody></table>";
				}
				sportOfGame = betGame.properties.sportId;
				if(sportOfGame == 'sport-2'){
					html += "<table class='basketSpecialBets'><tbody><tr><td class='headerPhoto'></td></tr>";
				}else if(sportOfGame == 'sport-4'){
					html += "<table class='tennisSpecialBets'><tbody><tr><td class='headerPhoto'></td></tr>";
				}else if(sportOfGame == 'sport-17'){
					html += "<table class='carsSpecialBets'><tbody><tr><td class='headerPhoto'></td></tr>";
				}else if(sportOfGame == 'sport-20'){
					html += "<table class='baseballSpecialBets'><tbody><tr><td class='headerPhoto'></td></tr>";
				}else if(sportOfGame == 'sport-24'){
					html += "<table class='eurovisionBets'><tbody><tr><td class='headerPhoto'></td></tr>";
				}else if(sportOfGame == 'sport-25'){
					html += "<table class='stibosBets'><tbody><tr><td class='headerPhoto'></td></tr>";
				}else if(sportOfGame == 'sport-12'){
					html += "<table class='hockeySpecialBets'><tbody><tr><td class='headerPhoto'></td></tr>";
				}else{
					html += "<table class='specialBets'><tbody><tr><td class='headerPhoto'></td></tr>";
				}
				numberOfSports++;
			}       
            if((betGame.eventDescription != '' && eventOfGame != betGame.eventDescription) || (betGame.code != codeOfGame)){
				if(betGameIds.length > 0){
					html = html.replace('####','['+betGameIds+']');
					betGameIds = [];
				}
                eventOfGame = betGame.eventDescription;
				codeOfGame = betGame.code;
				html +="<tr><td class='event_date'>["+formatDateNumber(betGame.properties.eventStartDate)+" - "+formatDateNumber(betGame.properties.eventEndDate)+"]</td></tr>";
                html +="<tr><td class='event_dsc'><a onclick='javascript:openAllSpecialGamesOfEvent(####)'>("+resources[lang][21]+" "+fillZeros(betGame.code)+") "+betGame.eventDescription+"</a></td></tr>";
			}
			betGameIds.push(betGame.id);
            html += "<tr id='"+betGame.id+"' name='"+betGame.sortingCode+"'><td><a class='event_title_link' onclick='javascript:openSpecialGame("+betGame.id+")'>"+betGame.description+"</a></td></tr>";             
        }
		html = html.replace('####','['+betGameIds+']');
		$("#program").append(html+"</tbody></table><div style='clear:both;'></div></div>");         
  }
}


var BetGame = function(id , externalId , code ,status , betStartDate ,  betEndDate , description ,homeTeam ,awayTeam  , Odds , normalSpecial , codesArray , properties, eventDescription){
	
	this.gameOdds = new Object();
	this.id = null;
	this.status = 0;
	this.code = null;
	this.date = null;
	this.displayDate = null;
	this.dateDisplayDate = null;
	this.time = null;
	this.description = null;
	this.externalId = null;
	this.normalGame = true;
	this.codesArray = new Array();
	this.home = null;
	this.away = null;
	this.properties = new Object;
	this.startDate = null;
	this.endDate = null;
	this.sortingCode = 0;	
	this.timeInMill = null;
	this.eventDescription = null;
	this.homeHcp = 0;
	this.awayHcp = 0;
	this.homeScore = 0;
	this.awayScore = 0;
	this.winningCode = -1;
	
	this.init = function(){	
		this.gameOdds = Odds;
		this.id = id;
		this.code = code;
		this.externalId = externalId;
		this.normalGame = normalSpecial;
		this.codesArray = codesArray;
		this.status = betGameStatus[status];
		this.timeInMill = betEndDate;
		this.startDate = betStartDate;
		this.endDate = betEndDate;
		this.setDate(betEndDate);
		this.properties = properties;
		if(this.normalGame){
			this.setNormalEventDetails();
		}else{
			this.setSpecialEventDetails(description);
			this.eventDescription = eventDescription;
		}
	}
	
	this.setNormalEventDetails = function(){
		this.description = homeTeam+" - "+awayTeam;
		this.home = homeTeam;
		this.away = awayTeam;
		this.modifyProperties();
		if (this.status == 8 && this.properties.homeSc != ''){
			this.setResults();
		}
		for(var i=0;i<=numberOfBets;i++){
			if(this.gameOdds[i] != undefined && this.gameOdds[i].odd != 0 && this.gameOdds[i].status > 0 && this.gameOdds[i].status != 2){
				this.gameOdds[i].toBet = true;
			}
			else{
				this.gameOdds[i] = "-";
				this.gameOdds[i].toBet = false;
			}
		}
	}
	
	this.setSpecialEventDetails = function(description){
		this.description = description;
		for(var i=0;i<=this.codesArray.length;i++){
			if(this.gameOdds[this.codesArray[i]] != undefined && this.codesArray[i].odd != 0){
				this.gameOdds[this.codesArray[i]].toBet = true;
			}
			else{
				this.gameOdds[this.codesArray[i]] = "-";
				this.gameOdds[this.codesArray[i]].toBet = false;
			}
		}
	}
	
	this.setDate = function(endDate){
		var date = new Date(endDate);
		var tmpMonth = date.getMonth() + 1;
		var hour = date.getHours() + "";
		var minutes = date.getMinutes() +"";
		tmpMonth = tmpMonth + "";
		if (tmpMonth.length == 1) tmpMonth = "0" + tmpMonth;
		var formattedDate = date.getDate()+ '/' + tmpMonth + '/' + date.getFullYear();
		this.date = formattedDate;
		
		var tmpDate = new Date(endDate);
		tmpDate.setHours(8,0,0,0);
		var gameIsAfterMidnight = (tmpDate > date);
		tmpDate = new Date(endDate);
		if(gameIsAfterMidnight){
			tmpDate.setDate(tmpDate.getDate()-1);
		}
		
		this.dateDisplayDate = tmpDate;
		
		var tmpMonth2 = tmpDate.getMonth() + 1;
		tmpMonth2 = tmpMonth2 + "";
		if (tmpMonth2.length == 1) tmpMonth2 = "0" + tmpMonth2;
		var formattedDate2 = tmpDate.getDate()+ '/' + tmpMonth2 + '/' + tmpDate.getFullYear();		
		this.displayDate = formattedDate2;
		
		if (hour.length == 1) hour = "0" + hour;
		if (minutes.length == 1) minutes = "0" + minutes;
		this.time = hour + ':' + minutes;
	}
	
	this.modifyProperties = function(){
		if (this.properties.homeH != undefined && this.properties.homeH != 0){this.homeHcp = this.properties.homeH;}else{this.properties.homeH = '';}
		if (this.properties.awayH != undefined && this.properties.awayH != 0){this.awayHcp = this.properties.awayH;}else{this.properties.awayH = '';}
		if (this.properties.halfHomeH == undefined || this.properties.halfHomeH == 0){this.properties.halfHomeH = '';}
		if (this.properties.halfAwayH == undefined || this.properties.halfAwayH == 0){this.properties.halfAwayH = '';}
		if (this.properties.overUnderValue == undefined || this.properties.overUnderValue == 0){this.properties.overUnderValue = '';}
		if (this.properties.withOdds == undefined){this.properties.withOdds = 1;}
		if (this.properties.selections == undefined){this.properties.selections = 3;}
		if (this.properties.channel == undefined){this.properties.channel = '';}else{this.properties.channel = "<img border='0' width='30' src='../../../html/demo/bet/images/channel"+this.properties.channel+".gif'>";}
		if (this.properties.homeSc == undefined){this.properties.homeSc = '';}else{this.homeScore = this.properties.homeSc;}
		if (this.properties.awaySc == undefined){this.properties.awaySc = ''}else{this.awayScore = this.properties.awaySc;}
	}
	
	this.setResults = function(){
		var hm = (parseFloat(this.homeScore,10) + parseFloat(this.homeHcp,10));
		var aw = (parseFloat(this.awayScore,10) + parseFloat(this.awayHcp,10));
		var sum = (parseFloat(this.homeScore,10) + parseFloat(this.awayScore,10));
		this.winningCode = 2;
		if(hm > aw){
			this.winningCode = 0;
			this.gameOdds[0].status = codeStatuses['won'];
			if(this.gameOdds[3] != undefined){this.gameOdds[3].status = codeStatuses['won'];}
			if(this.gameOdds[4] != undefined){this.gameOdds[4].status = codeStatuses['won'];}
		}
		else if(hm == aw){
			if(this.gameOdds[1] != undefined){this.gameOdds[1].status = codeStatuses['won'];}
			if(this.gameOdds[3] != undefined){this.gameOdds[3].status = codeStatuses['won'];}
			if(this.gameOdds[5] != undefined){this.gameOdds[5].status = codeStatuses['won'];}
		}
		else{
			this.gameOdds[2].status = codeStatuses['won'];
			if(this.gameOdds[4] != undefined){this.gameOdds[4].status = codeStatuses['won'];}
			if(this.gameOdds[5] != undefined){this.gameOdds[5].status = codeStatuses['won'];}
		}
		if(this.gameOdds[25] != undefined && this.gameOdds[25].status == codeStatuses['code_has_result']){
			if(sum > this.gameOdds[36].odd){
				this.gameOdds[26].status = codeStatuses['won'];
			}else{
				this.gameOdds[25].status = codeStatuses['won'];
			}
		}
	}

}	

    function getNumNormalBets(betGame){
		var availableBets = new Array();
		var counter = 0;
		for(var j=0;j<10;j++){
			for(var k=betGroups[j].start;k<=betGroups[j].end;k++){
				if(betGame.gameOdds[k].toBet){
					k = betGroups[j].end + 1;
					availableBets[counter]=j;
					counter++;					
				}
			}
		}
		return availableBets;
	}
	

	function fillZeros(code){
		var tmpLegth = code.length;
		for (var i=3;i>tmpLegth;i--){
			code = '0' + code;
		}
		return code;
	}

	function formatOdd(odd){
		var newOdd = odd;
		if(odd == undefined)
			return "-"
			
		odd = odd + "";
		var a = odd.split(".");
		if(a.length < 2){
			newOdd = odd + ',00';
		}
		else{
			var tmpLength = a[1].length;
			for (var i=2;i>tmpLength;i--){
				a[1] = a[1] + '0';
			}
			newOdd = a[0] + ',' + a[1];
		}
		return newOdd;
	}

	function formatDate(tmpDate){
		var date = new Date(tmpDate);
		var tmpDay = date.getDay();
		var tmpMonth = date.getMonth();
		var year = date.getFullYear();
		return day[lang][tmpDay] + ' ' +date.getDate()+ ' ' + month[lang][tmpMonth] + ' ' + year;
	}
	
	function formatDateNumber(dateValue){
		var date = new Date(dateValue);
		var tmpDay = date.getDay();
		var tmpMonth = date.getMonth() + 1;
		var year = date.getFullYear();
		tmpMonth = tmpMonth + "";
		if (tmpMonth.length == 1) tmpMonth = "0" + tmpMonth;
		return formattedDate = date.getDate()+ '/' + tmpMonth + '/' + year;
	}

	function formatSevCode(code){
		for(var i=code.length;i<3;i++){
			code = "0" + code;
		}
		return code;
	}

	function replaceDots(data){return data.replace('.' , ',');}

	function arrayContains(array,data){
		for(var i=0;i<array.length;i++){
			if(array[i]==data)
				return true;
		}
		return false;
	}

	var progMan = new ProgramManager();
	var programStartDate;
	var programEndDate;
	var myBoxy;
		
	function showHideScore(){
		if($('#showScoreCheckBox').is(':checked')){
			$(".colScore").show();
		}else{
			$(".colScore").hide();
		}
	}
	
	function makeProgramVisible(){
		$("#wrapper").removeClass("noPrint");		
	}
	
	function printBoxy(id){
		if($.browser.msie){
			if(id == 0){
				id="NormalBetContainer";
			}else{
				id="SpecialBetContainer";
			}
			var WindowObject = window.open("","",
			"width=700,height=800,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
			WindowObject.document.writeln("<link rel='stylesheet' type='text/css' href='/html/demo/bet/couponBetting/couponBetting.css'/>");
			WindowObject.document.writeln("<style type='text/css'>@media print{.noPrint{display:none;}.boxy-content{overflow:visible!important;height:100%!important;}.boxy-wrapper{left:10px!important;top:10px!important;}#printButton{display:none!important;}}</style>");
			WindowObject.document.writeln("<div id='"+id+"' style='display: block;' class='boxy-content'>");
			WindowObject.document.writeln($("#"+id).html());
			WindowObject.document.writeln("</div>");
			WindowObject.document.close();
			WindowObject.focus();
			WindowObject.print();
			WindowObject.close();			
		}else{
			window.print();
		}
		
	}
	
	function openBasketOdds(){	
		var html = $("#basketOddsContainer").html();
		myBoxy  = new Boxy(html, {title: "Βασικός Πίνακας Αποδόσεων ",closeText:resources[lang][25],modal:true,unloadOnHide:true,closeable:true,draggable:false,fixed:false,center:true,x:50,y:50});	
		myBoxy.show();
	}
	
	function chooseGame(id,drawNumber,getCoupon){
		var modeTmp = id;
		id = "sport-" + id;
		if(id == "sport-0"){
			openOtherGames();
		}else{
			var dataParam = {localeId:locale};
			var urlTmp = "/web/services/rs/betting/availableBetGames/sport/program/4100/0/"+id+".json";
			if(getCoupon){//get whole coupon that includes the specific drawNumber.
				dataParam.drawNumber = drawNumber;
			}else{		  //get games only for the specific draw, but apply coupon rules.
				urlTmp = "/web/services/rs/betting/availableBetGames/sport/program/4100/0/"+id+"/"+drawNumber+".json";
			}			
			
			$.ajax({ url: urlTmp, 
					 dataType:'json', 
					 data: dataParam,
					 beforeSend: function(xhrObj){xhrObj.setRequestHeader("LOCALE",locale);}, 
					 success: function(allData){	
					 
				if(allData == undefined || allData == null || allData == '' || allData.betGames == undefined || allData.betGames.length == 0){				
					$("#program").html("<div class='coupon_message'><strong>"+resources[1][42]+"</strong></div>");
					$("#belowProgram").hide();		
					$("#loader").hide();
					$("#searchDiv").show();		
					$("#printButton").show();		
					$("#selectTour").html("");					
				}else{
					programStartDate = allData.programStartDate;
					programEndDate = allData.programEndDate;
					initializeProgram(allData.betGames,id,modeTmp);
				}
			},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					var errorTxt = "textStatus="+textStatus+"\nerrorThrown="+errorThrown;
					$("#program").html("<strong>"+resources[1][42]+"</strong>");
					$("#belowProgram").hide();		
					$("#loader").hide();
					$("#searchDiv").show();		
					$("#printButton").show();		
					$("#selectTour").html("");	
				}

			});			
		}
	}	
	
	function openOtherGames() {
		if (progMan.Categories[0] == null) {
			$.ajax({url:"/web/services/rs/betting/availableBetGames/other/program/4100/0.json", 
					dataType:"json", 
					data: {localeId:locale},
					beforeSend: function(xhrObj){xhrObj.setRequestHeader("LOCALE",locale);},
					success:function (data) {
					
				var games = new Array();
				for (var newGame = 0; newGame < data.length; newGame++) {
					var show = true;
					var codesArray = new Array();
					var allOdds = data[newGame].codes;
					var Odds = new Object();
					
					var tmpBetGameStatus = betGameStatus[data[newGame].status];				
					for (var i = 0; i < allOdds.length; i++) {
						var tmpObject = new Object;
						tmpObject.odd = allOdds[i].odd;
						tmpObject.dsc = data[newGame].lexicon.resources[allOdds[i].dsc];
						codesArray.push(allOdds[i].code.value);
						
						if(tmpBetGameStatus == 1 || tmpBetGameStatus == 6 || tmpBetGameStatus == 7 || tmpBetGameStatus == 8){
							tmpObject.status = allOdds[i].status;
						}else{
							tmpObject.status = data[newGame].status;
						}
						Odds[allOdds[i].code.value] = tmpObject;
					}
					var code;
					var eventDescription = "";
					var props = new Object();
					if (data[newGame].betEvent != null) {
						eventDescription = data[newGame].lexicon.resources[data[newGame].betEvent.description];
						props.eventStartDate = data[newGame].betEvent.startDate;
						props.eventEndDate = data[newGame].betEvent.endDate;
					}
					
					props.sportId = data[newGame].sportId;
					for (var prop = 0; prop < data[newGame].properties.prop.length; prop++) {
						if (data[newGame].properties.prop[prop].id == 7) {
							code = data[newGame].properties.prop[prop].value;
						} else {
							if (data[newGame].properties.prop[prop].id == 28) {
								props.selections = data[newGame].properties.prop[prop].value;
							} else {
								if (data[newGame].properties.prop[prop].id == 47) {
									if (data[newGame].properties.prop[prop].value == 1) {
										show = false;
									}
								}
							}
							if(data[newGame].properties.prop[prop].id == 49){
								props.sequence = data[newGame].properties.prop[prop].value;
							}
						}
						if(data[newGame].properties.prop[prop].id == 16){
							props.sortCode = data[newGame].properties.prop[prop].value;
						}
					}
					var codeDescription = data[newGame].description;
 
					var tmp = new BetGame(data[newGame].id, data[newGame].externalId, code, data[newGame].status, data[newGame].betStartDate , data[newGame].betEndDate, data[newGame].lexicon.resources[codeDescription], null, null, Odds, false, codesArray, props, eventDescription);
					tmp.init();
					games.push(tmp);

				}
				var lastObj = new BetCategory(games, "t-0", 0);
				lastObj.init();
				progMan.selectSport(lastObj);
				
				$("#loader").hide();
				$("#searchDiv").show();
				$("#printButton").show();
			}});
		}
	}
	
	function openResults(betGameId,availableBets){
		var betGame = progMan.selectedCategory.mapGames[betGameId];
		var selection = betGame.properties.selections;
		var htmlResults = [];
		var htmlResultsIndex = 0;
		
		//Title
		htmlResults[htmlResultsIndex++] =  "<div id='NormalBetContainer'><div class='top'><div class='title'><b>"+resources[lang][38]+"</b></div><div class='logo'><img src='../../../html/demo/bet/images/popuplogo.jpg'></div></div>";
		//Game info
		htmlResults[htmlResultsIndex++] =  "<div><div class='main'><div class='top_open'>"+betGame.properties.tournament2+"</div><div class='bg_green'>"+formatDate(betGame.endDate)+"<img src='../../../html/demo/bet/images/img_clock_print.jpg'></div>";
		htmlResults[htmlResultsIndex++] =  "<div class='top_close'><table width='410' border='0' cellpadding='0' cellspacing='0'><tbody><tr><td width='30px' class='selection"+((selection != '-1')?selection:"2plus")+"'></td>";
		htmlResults[htmlResultsIndex++] =  "<td width='60px'>"+resources[lang][21]+"&nbsp;"+betGame.code+"</td><td>"+betGame.home+" - "+betGame.away+"</td><td width='40px' align='right'>&nbsp;</td></tr><tr><td colspan='4'></td></tr></tbody></table></div></div>";
		
		htmlResults[htmlResultsIndex++] =  "<div><div class='main'><div class='open'><b>"+resources[lang][36]+"</b></div><div class='body'><table width='410' border='0' cellpadding='2' cellspacing='5'><tbody>";
						
		//For each games		
		for(var j=0;j<10;j++){
		
			if(j == 0){
				htmlResults[htmlResultsIndex++] =  "<tr><td class='border_green_header'>"+resources[lang][39]+"</td><td class='border_green_header' align='right'>"+resources[lang][40]+"</td><td class='border_green_header' align='center'>"+resources[lang][41]+"</td></tr>";				
			}
			if(availableBets.indexOf("|"+j+"|") != -1){
				
				var htmlCodes = [];
				var htmlCodesIndex = 0;
				for(var k=betGroups[j].start;k<=betGroups[j].end;k++){
					if(betGame.gameOdds[k].status == codeStatuses['won'])
						htmlCodes[htmlCodesIndex++] = "<td class='border_green' align='right'>"+Codes[lang][k]+""+((j==6)?" (2,5)":"")+"</td><td class='border_green' align='right'>"+formatOdd(betGame.gameOdds[k].odd)+"</td>";
				}
				
				for(var k=0;k<htmlCodesIndex;k++){
					htmlResults[htmlResultsIndex++] =  "<tr>";
					if(k == 0){
						htmlResults[htmlResultsIndex++] =  "<td class='border_green' rowspan='"+htmlCodesIndex+"'>"+betNames[lang][j]+"</td>";
					}
					htmlResults[htmlResultsIndex++] =  htmlCodes[k];
					htmlResults[htmlResultsIndex++] =  "</tr>";
				}
				
				
				//<div class='txt_left'>
				
			}
		}			

		htmlResults[htmlResultsIndex++] =  "</tbody></table></div><div class='close'>&nbsp;</div></div></div>";		
				
		if(betGame.properties.relatedGamesNumber != undefined && betGame.properties.relatedGamesNumber > 0){
					
			$.ajax({url:"/web/services/rs/betting/results/specialBetGames/"+betGame.id+"/"+betGame.externalId+".json", 
					dataType:"json", 
					data: {localeId:locale},
					beforeSend: function(xhrObj){xhrObj.setRequestHeader("LOCALE",locale);},
					success:function (data) {
					
				var games = new Array();
				for(var newGame=0;newGame<data.length;newGame++){
					var codesArray = new Array();
					var allOdds = data[newGame].codes;
					var Odds = new Object();
					var tmpBetGameStatus = betGameStatus[data[newGame].status];
					for (var i=0;i<allOdds.length;i++){	
						var tmpObject = new Object;			
						tmpObject.odd=allOdds[i].odd;
						tmpObject.dsc=data[newGame].lexicon.resources[allOdds[i].dsc];
						tmpObject.code=allOdds[i].code.value;
						codesArray.push(allOdds[i].code.value);
						if(tmpBetGameStatus == 1 || tmpBetGameStatus == 6 || tmpBetGameStatus == 7 || tmpBetGameStatus == 8){
							tmpObject.status = allOdds[i].status;
						}else{
							tmpObject.status = data[newGame].status;
						}
						Odds[allOdds[i].code.value] = tmpObject;
					}
					var code;
					var eventDescription = '';
					if(data[newGame].betEvent != null){
						eventDescription = data[newGame].lexicon.resources[data[newGame].betEvent.description];
					}
					var props = new Object();
					for(var prop=0;prop<data[newGame].properties.prop.length;prop++){
						if(data[newGame].properties.prop[prop].id == 7){
							code = data[newGame].properties.prop[prop].value;
						}
						if(data[newGame].properties.prop[prop].id == 16){
							props.sortCode = data[newGame].properties.prop[prop].value;
						}
					}
					var codeDescription = data[newGame].description;
					var tmp = new BetGame(data[newGame].id ,data[newGame].externalId, code, data[newGame].status, data[newGame].betStartDate , data[newGame].betEndDate, data[newGame].lexicon.resources[codeDescription], null, null, Odds, false, codesArray, props, eventDescription);
					tmp.init();
					games.push(tmp);
				}
				
				addSpecialGameResults(htmlResults.join(""),games);
			}});		
		}else{
			displayResults(htmlResults.join(""));
		}
	}	
	
	function addSpecialGameResults(html,betGames){
		var htmlSpecialResults = [];
		var htmlSpecialResultsIndex = 0;
		
		htmlSpecialResults[htmlSpecialResultsIndex++] = html;
		
		var startDate = betGames[0].startDate;
		var endDate = betGames[0].endDate;
		
		if(betGames[0].properties.eventStartDate != null && betGames[0].properties.eventEndDate != null){
			startDate = betGames[0].properties.eventStartDate;
			endDate = betGames[0].properties.eventEndDate;
		}
		
		//Game info
		htmlSpecialResults[htmlSpecialResultsIndex++] = "<div><div class='main'><div class='top_open'>"+betGames[0].eventDescription+"</div><div class='bg_green'>"+formatDate(startDate)+" - "+formatDate(endDate)+"<img src='../../../html/demo/bet/images/img_clock_print.jpg'></div>";
		htmlSpecialResults[htmlSpecialResultsIndex++] = "<div class='top_close'><table width='410' border='0' cellpadding='0' cellspacing='0'><tbody><tr>";
		htmlSpecialResults[htmlSpecialResultsIndex++] = "<td width='60px'>"+resources[lang][21]+"&nbsp;"+fillZeros(betGames[0].code)+"</td><td>"+betGames[0].eventDescription+"</td><td width='40px' align='right'>&nbsp;</td></tr><tr><td colspan='4'></td></tr></tbody></table></div></div>";
		
		htmlSpecialResults[htmlSpecialResultsIndex++] = "<div><div class='main'><div class='open'><b>"+resources[lang][37]+"</b></div><div class='body'><table width='410' border='0' cellpadding='2' cellspacing='5'><tbody>";
					
		for(var i=0;i<betGames.length;i++){
			if(i == 0){
				htmlSpecialResults[htmlSpecialResultsIndex++] =  "<tr><td class='border_green_header'>Τύπος Στοιχήματος</td><td class='border_green_header' align='right'>Ενδεχόμενο που κερδίζει</td><td class='border_green_header' align='center'>Αποδ.</td></tr>";				
			}
			var betGame = betGames[i];
			betGame.codesArray.sort(sortByCodeValue);
			var selection = betGame.properties.selections;		
			
			var htmlCodes = [];
			var htmlCodesIndex = 0;
			for (var k=0;k<betGame.codesArray.length;k++){
				var tmpCode = betGame.codesArray[k];
				if(betGame.gameOdds[tmpCode].status == 'won'){					
					htmlCodes[htmlCodesIndex++] = "<td class='border_green' align='right'>"+betGame.gameOdds[tmpCode].dsc+" ("+resources[lang][21]+" "+specialCodeConverter(tmpCode)+")</td><td class='border_green' align='right'>"+formatOdd(betGame.gameOdds[tmpCode].odd)+"</td>";
				}
			}
			
			for(var k=0;k<htmlCodesIndex;k++){
				htmlSpecialResults[htmlSpecialResultsIndex++] =  "<tr>";
				if(k == 0){
					htmlSpecialResults[htmlSpecialResultsIndex++] =  "<td class='border_green' rowspan='"+htmlCodesIndex+"'>"+betGame.description+"</td>";
				}
				htmlSpecialResults[htmlSpecialResultsIndex++] =  htmlCodes[k];
				htmlSpecialResults[htmlSpecialResultsIndex++] =  "</tr>";
			}				
		}
		
		htmlSpecialResults[htmlSpecialResultsIndex++] = "</tbody></table></div><div class='close'>&nbsp;</div></div></div>";		
		
		displayResults(htmlSpecialResults.join(""));
	}
	
	function displayResults(htmlResults){
		htmlResults += "</div></div>";
		var title = "<div id='printButton2' class='noPrint' style='padding:3px;'><a onclick='javascript:printBoxy(0)'>"+resources[lang][24]+"&nbsp;<img border='0' src='../../../html/demo/bet/images/print.gif' alt='"+resources[lang][24]+"'></a></div>";
		myBoxy = new Boxy(htmlResults, {title: title,closeText:"Κλείσιμο",modal:true,unloadOnHide:true,afterHide:makeProgramVisible,closeable:true,draggable:false,fixed:false,center:false,x:10,y:10});	
		myBoxy.show();
		if($(window).scrollTop()){
			myBoxy.moveTo(10,undefined);
		}
		$("#wrapper").addClass("noPrint");	
		
		return false;
	}
	
	function initializeProgram(data, id, modeTmp){
		var games = new Array();
		for(var newGame=0;newGame<data.length;newGame++){
			var codesArray = new Array();
			var allOdds = data[newGame].codes;
			if(allOdds == null){
				allOdds = new Object;
			}
			var Odds = new Object();
			for (var i=0;i<allOdds.length;i++){	
				var tmpObject = new Object;			
				tmpObject.odd=allOdds[i].odd;
				codesArray.push(allOdds[i].code.value);
				tmpObject.status = codeStatuses[allOdds[i].status];
				Odds[allOdds[i].code.value] = tmpObject;
			}
			var homeTeam = '';
			var awayTeam = '';
			var props = new Object;
			
			props.relatedGamesNumber = data[newGame].relatedNum;
			var shortTournamentKey = data[newGame].tournamentId + "-short";
			
			props.tournamentId = data[newGame].tournamentId;
			props.tournament = data[newGame].lexicon.resources[shortTournamentKey];
			props.tournament2 = data[newGame].lexicon.resources[data[newGame].tournamentId];
			
			var code;
			for(var prop=0;prop<data[newGame].properties.prop.length;prop++){
				if(data[newGame].properties.prop[prop].id == 20){
					props.homeH = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 21){
					props.awayH = data[newGame].properties.prop[prop].value;
				}
				if(data[newGame].properties.prop[prop].id == 22){
					props.homeGameH = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 23){
					props.awayGameH = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 34){
					props.halfHomeH = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 35){
					props.halfAwayH = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 28){
					props.selections = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 42){
					props.overUnderValue = data[newGame].properties.prop[prop].value;	
				}
				else if(data[newGame].properties.prop[prop].id == 43){
					props.withOdds = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 45){
					props.channel = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 11){
					props.homeHalfSc = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 12){
					props.awayHalfSc = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 13){
					props.homeSc = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 14){
					props.awaySc = data[newGame].properties.prop[prop].value;
				}
				else if(data[newGame].properties.prop[prop].id == 30){
					var a = data[newGame].properties.prop[prop].value;
					if(data[newGame].lexicon.resources[a] != undefined){
						homeTeam = data[newGame].lexicon.resources[a];
					}else{
						homeTeam = 'team_0';
					}
				}
				else if(data[newGame].properties.prop[prop].id == 31){
					var b = data[newGame].properties.prop[prop].value;
					if(data[newGame].lexicon.resources[b] != undefined){
						awayTeam = data[newGame].lexicon.resources[b];
					}else{
						awayTeam = 'team_0';
					}
				}
				else if(data[newGame].properties.prop[prop].id == 6){
					code = data[newGame].properties.prop[prop].value;
				}
			}
			
			var tmp = new BetGame(data[newGame].id ,data[newGame].externalId , code ,  data[newGame].status , data[newGame].betStartDate , data[newGame].betEndDate , data[newGame].description ,homeTeam , awayTeam , Odds , true , codesArray , props , null);
			tmp.init();
			games.push(tmp);
		}
		var lastObj = new BetCategory(games , id , id);
		lastObj.init();
		progMan.selectSport(lastObj);
		
		$("#loader").hide();
		$("#searchDiv").show();
		//Add bottom tables
		$("#bottomDiv"+modeTmp).show();		
		$("#belowProgram").show();
		$("#printButton").show();
	}
	
	function groupingBets(index , obj , objId , sportId){
		var categoryId = objId.split('_')[2];
		var bool = $(obj).is(':checked');	
		var betGroup = $(".col"+index);
		for (var j = 0; j<betGroup.length; j++) {
			if(bool){
				$(betGroup[j]).show();
			}else{
				$(betGroup[j]).hide();
			}
		}
	}
		
	function specialCodeConverter(code){
		return (111 + Math.floor(code/36)*100 + Math.floor(((code%36))/6) * 10 + code%6);
	}
	
	function openSpecialGame(id){
		var betGames = new Array();
		betGames[0] = progMan.selectedCategory.mapGames[id];
		showSpecialGames(betGames);
	}
	
	function openAllSpecialGamesOfEvent(ids){
		var betGames = new Array();
		var L = ids.length;
		for(var i=0;i<L;i++){
			betGames[i] = progMan.selectedCategory.mapGames[ids[i]];
		}
		showSpecialGames(betGames);
	}
	
	function openSpecialGameForNormal(id,externalId){
		$.ajax({url:"/web/services/rs/betting/results/specialBetGames/"+id+"/"+externalId+".json", 
				dataType:"json", 
				data: {localeId:locale},
				beforeSend: function(xhrObj){xhrObj.setRequestHeader("LOCALE",locale);},
				success:function (data) {
				
			var games = new Array();
			for(var newGame=0;newGame<data.length;newGame++){
				var codesArray = new Array();
				var allOdds = data[newGame].codes;
				var Odds = new Object();
				var tmpBetGameStatus = betGameStatus[data[newGame].status];
				for (var i=0;i<allOdds.length;i++){	
					var tmpObject = new Object;			
					tmpObject.odd=allOdds[i].odd;
					tmpObject.dsc=data[newGame].lexicon.resources[allOdds[i].dsc];
					tmpObject.code=allOdds[i].code.value;
					codesArray.push(allOdds[i].code.value);
					if(tmpBetGameStatus == 1 || tmpBetGameStatus == 6 || tmpBetGameStatus == 7 || tmpBetGameStatus == 8){
						tmpObject.status = allOdds[i].status;
					}else{
						tmpObject.status = data[newGame].status;
					}
					Odds[allOdds[i].code.value] = tmpObject;
				}
				var code;
				var eventDescription = '';
				if(data[newGame].betEvent != null){
					eventDescription = data[newGame].lexicon.resources[data[newGame].betEvent.description];
				}
				var props = new Object();
				for(var prop=0;prop<data[newGame].properties.prop.length;prop++){
					if(data[newGame].properties.prop[prop].id == 7){
						code = data[newGame].properties.prop[prop].value;
					}
					if(data[newGame].properties.prop[prop].id == 16){
						props.sortCode = data[newGame].properties.prop[prop].value;
					}
				}
				var codeDescription = data[newGame].description;
				var tmp = new BetGame(data[newGame].id ,data[newGame].externalId, code, data[newGame].status, data[newGame].betStartDate , data[newGame].betEndDate, data[newGame].lexicon.resources[codeDescription], null, null, Odds, false, codesArray, props, eventDescription);
				tmp.init();
				games.push(tmp);
			}
			
			showSpecialGames(games);
		}});		
	}	
	
	function sortByCodeValue(a, b){
		var compA = a;
	    var compB =  b;
	    return ((compA < compB) ? -1 : ((compA > compB) ? 1 : 0));
	}
	
	function sortBySevNum(a, b) {
		var compA = a.properties.sortCode;
	    var compB =  b.properties.sortCode;
	    return ((compA < compB) ? -1 : ((compA > compB) ? 1 : 0));
	}
	
	function showSpecialGames(betGames){
		betGames.sort(sortBySevNum);
		var extraStyle = '';
		var tableColor = '"#c4d3aa';
		if(betGames[0].properties.sportId == 'sport-2'){
			extraStyle = 'basketGame';
			tableColor = '#f9c265';
		}else if(betGames[0].properties.sportId == 'sport-4'){			
			extraStyle = 'tennisGame';
			tableColor = '#f6db86';
		}else if(betGames[0].properties.sportId == 'sport-17'){			
			extraStyle = 'carsGame';
			tableColor = '#daaaaa';
		}else if(betGames[0].properties.sportId == 'sport-24'){			
			extraStyle = 'eurovisionGame';
			tableColor = '#9fbbde';
		}
		
		var html= [];
		var htmlIndex = 0;	

		html[htmlIndex++] = "<div id='SpecialBetContainer' class='"+extraStyle+"'><table cellspacing='0' cellpadding='0' border='0' align='center' width='426'><tbody><tr><td class='event_title' colspan='3'>"+betGames[0].eventDescription+"</td></tr>";
		
		var startDate = betGames[0].startDate;
		var endDate = betGames[0].endDate;
		
		if(betGames[0].properties.eventStartDate != null && betGames[0].properties.eventEndDate != null){
			startDate = betGames[0].properties.eventStartDate;
			endDate = betGames[0].properties.eventEndDate;
		}
		html[htmlIndex++] = "<tr><td class='event_game_date'colspan='3'>"+formatDate(startDate)+" - "+formatDate(endDate)+"</td></tr>";
		html[htmlIndex++] = "<tr><td class='event_game_code'>"+resources[lang][21]+" "+fillZeros(betGames[0].code)+"</td>";
		html[htmlIndex++] = "<td class='event_game_desc'>"+betGames[0].eventDescription+"</td></tr></tbody></table><br/>";
		
		for(var i=0;i<betGames.length;i++){
			var betGame = betGames[i];
			betGame.codesArray.sort(sortByCodeValue);
			var selection = betGame.properties.selections;
			html[htmlIndex++] = "<table cellspacing='0' cellpadding='0' bordercolor='"+tableColor+"' border='1' align='center' width='426' style='border-collapse: collapse;'><tbody><tr>";		
			html[htmlIndex++] = "<td class='event_game_title' colspan='3'><div style='float:left'>"+betGame.description+"</div><div style='float:right;padding-bottom: 4px;padding-left: 19px;' class='selection"+((selection != '-1')?selection:"2plus")+"'>&nbsp;</div></td></tr>";
			html[htmlIndex++] = "<tr><td colspan='3' class='event_game_time'>"+betGame.date+" | "+betGame.time+"</td></tr>";		
			html[htmlIndex++] = "<tr><td width='30px' class='event_game_header1'>"+resources[lang][21]+"</td><td class='event_game_header2'>"+resources[lang][22]+"</td><td align='center' width='80px' class='event_game_header3'>"+resources[lang][23]+"</td></tr>";	
			for (var j=0;j<betGame.codesArray.length;j++){
				var tmpCode = betGame.codesArray[j];
				var wonStyle = '';
				if(betGame.gameOdds[tmpCode].status == 'won'){wonStyle = 'wonStyle';}
				html[htmlIndex++] = "<tr><td width='30px' class='event_game_detail1 "+wonStyle+"'>"+specialCodeConverter(tmpCode)+"</td>";			
				html[htmlIndex++] = "<td class='event_game_detail2 "+wonStyle+"'>"+betGame.gameOdds[tmpCode].dsc+"</td>";
				html[htmlIndex++] = "<td align='center' width='80px' class='event_game_detail3 "+wonStyle+"'>";
				if(betGame.status != 0){
					if(betGame.gameOdds[tmpCode].status != 'blocked'){
						html[htmlIndex++] = formatOdd(betGame.gameOdds[tmpCode].odd);
					}else{
						html[htmlIndex++] = statusMessage[lang][2];
					}
				}
				html[htmlIndex++] = "</td></tr>";	
			}
			html[htmlIndex++] = "</tbody></table><br/>";
		}	
		html[htmlIndex++] = "<table cellspacing='0' cellpadding='0' border='0' align='center' width='426'><tbody><tr>";
		html[htmlIndex++] = "<td class='bet_note_title'>ΑΠΟΤΕΛΕΣΜΑΤΑ ΠΑΜΕ ΣΤΟΙΧΗΜΑ:</td></tr><tr><td class='bet_note_dsc'>Όλη η σειρά στην οποία αναγράφεται ο κερδίζων κωδικός σημειώνεται με <span>κόκκινο</span> χρώμα.</td></tr><tr>";
		html[htmlIndex++] = "<td class='bet_note_title'>ΚΩΔΙΚΟΣ που λαμβάνει ως ΑΠΟΔΟΣΗ τη ΜΟΝΑΔΑ:</td></tr><tr><td class='bet_note_dsc'>Για τους κωδικούς που βάσει των Ειδικών Όρων λαμβάνουν ως απόδοση τη μονάδα η απόδοση σημειώνεται με <span>κόκκινα</span> γράμματα.</td>";
		html[htmlIndex++] = "</tr></tbody></table></div>";
		var title = "<div id='printButton2' class='noPrint' style='padding:3px;'><a onclick='javascript:printBoxy(1)'>"+resources[lang][24]+"&nbsp;<img border='0' src='../../../html/demo/bet/images/print.gif' alt='"+resources[lang][24]+"'></a></div>";
		myBoxy = new Boxy(html.join(""), {title: title,closeText:"Κλείσιμο",modal:true,unloadOnHide:true,afterHide:makeProgramVisible,closeable:true,draggable:false,fixed:false,center:false,x:10,y:10});	
		myBoxy.show();
		if($(window).scrollTop()){
			myBoxy.moveTo(10,undefined);
		}
		$("#wrapper").addClass("noPrint");	
		
		$("#loader").hide();
		$("#searchDiv").show();
		$("#printButton").show();
	}
	
	function openNormalBetsForNormal(betGameId,availableBets){
				
		var betGame = progMan.selectedCategory.mapGames[betGameId];		
		var selection = betGame.properties.selections;
		
		var html= [];
		var htmlIndex = 0;	
		
		//Title
		html[htmlIndex++] = "<div id='NormalBetContainer'><div class='top'><div class='title'><b>Βασικά Στοιχήματα</b></div><div class='logo'><img src='../../../html/demo/bet/images/popuplogo.jpg'></div></div>";
		//Game info
		html[htmlIndex++] = "<div><div class='main'><div class='top_open'>"+betGame.properties.tournament2+"</div><div class='bg_green'>"+formatDate(betGame.endDate)+"<img src='../../../html/demo/bet/images/img_clock_print.jpg'></div>";
		html[htmlIndex++] = "<div class='top_close'><table width='410' border='0' cellpadding='0' cellspacing='0'><tbody><tr><td width='30px' class='selection"+((selection != '-1')?selection:"2plus")+"'></td>";
		html[htmlIndex++] = "<td width='60px'>"+resources[lang][21]+"&nbsp;"+betGame.code+"</td><td>"+betGame.home+" - "+betGame.away+"</td><td width='40px' align='right'>&nbsp;</td></tr><tr><td colspan='4'></td></tr></tbody></table></div></div>";
		
		//For each games		
		for(var j=0;j<10;j++){
			if(availableBets.indexOf("|"+j+"|") != -1){
				html[htmlIndex++] = "<div id='availableBet"+j+"'><div class='main'><div class='open'><b>"+betNames[lang][j]+"</b></div><div class='body'><table width='410' border='0' cellpadding='2' cellspacing='5'><tbody>";
				
				if(j==0){
					html[htmlIndex++] = "<tr><td>"+resources[lang][8]+"</td><td>1</td><td>Χ</td><td>2</td><td>"+resources[lang][11]+"</td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'>"+betGame.properties.homeH+"</td>";
					
					html[htmlIndex++] = (betGame.gameOdds[0].toBet)?"<td class='border_green'>"+formatOdd(betGame.gameOdds[0].odd)+"</td>":"<td class='border_green'>&nbsp;</td>";
					html[htmlIndex++] = (betGame.gameOdds[1].toBet)?"<td class='border_green'>"+formatOdd(betGame.gameOdds[1].odd)+"</td>":"<td class='border_green'>&nbsp;</td>";
					html[htmlIndex++] = (betGame.gameOdds[2].toBet)?"<td class='border_green'>"+formatOdd(betGame.gameOdds[2].odd)+"</td>":"<td class='border_green'>&nbsp;</td>";
					
					html[htmlIndex++] = "<td class='border_green'>"+betGame.properties.awayH+"</td></tr>";	
				}
				
				if(j==1){
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+resources[lang][26]+"</div><div class='txt_right'>"+((betGame.gameOdds[3].toBet)?formatOdd(betGame.gameOdds[3].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+resources[lang][27]+"</div><div class='txt_right'>"+((betGame.gameOdds[4].toBet)?formatOdd(betGame.gameOdds[4].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+resources[lang][28]+"</div><div class='txt_right'>"+((betGame.gameOdds[5].toBet)?formatOdd(betGame.gameOdds[5].odd):"-")+"</div></td></tr>";
				}
				
				if(j==2){
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>1</div><div class='txt_right'>"+((betGame.gameOdds[6].toBet)?formatOdd(betGame.gameOdds[6].odd):"-")+"</div></td>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>X</div><div class='txt_right'>"+((betGame.gameOdds[7].toBet)?formatOdd(betGame.gameOdds[7].odd):"-")+"</div></td>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>2</div><div class='txt_right'>"+((betGame.gameOdds[8].toBet)?formatOdd(betGame.gameOdds[8].odd):"-")+"</div></td></tr>";
				}
				
				if(j==3){
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>1</div><div class='txt_right'>"+((betGame.gameOdds[9].toBet)?formatOdd(betGame.gameOdds[9].odd):"-")+"</div></td>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>X</div><div class='txt_right'>"+((betGame.gameOdds[10].toBet)?formatOdd(betGame.gameOdds[10].odd):"-")+"</div></td>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>2</div><div class='txt_right'>"+((betGame.gameOdds[11].toBet)?formatOdd(betGame.gameOdds[11].odd):"-")+"</div></td></tr>";
				}
				
				if(j==4){
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+Codes[lang][12]+"</div><div class='txt_right'>"+((betGame.gameOdds[12].toBet)?formatOdd(betGame.gameOdds[12].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+Codes[lang][13]+"</div><div class='txt_right'>"+((betGame.gameOdds[13].toBet)?formatOdd(betGame.gameOdds[13].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+Codes[lang][14]+"</div><div class='txt_right'>"+((betGame.gameOdds[14].toBet)?formatOdd(betGame.gameOdds[14].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+Codes[lang][15]+"</div><div class='txt_right'>"+((betGame.gameOdds[15].toBet)?formatOdd(betGame.gameOdds[15].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+Codes[lang][16]+"</div><div class='txt_right'>"+((betGame.gameOdds[16].toBet)?formatOdd(betGame.gameOdds[16].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+Codes[lang][17]+"</div><div class='txt_right'>"+((betGame.gameOdds[17].toBet)?formatOdd(betGame.gameOdds[17].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+Codes[lang][18]+"</div><div class='txt_right'>"+((betGame.gameOdds[18].toBet)?formatOdd(betGame.gameOdds[18].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+Codes[lang][19]+"</div><div class='txt_right'>"+((betGame.gameOdds[19].toBet)?formatOdd(betGame.gameOdds[19].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+Codes[lang][20]+"</div><div class='txt_right'>"+((betGame.gameOdds[20].toBet)?formatOdd(betGame.gameOdds[20].odd):"-")+"</div></td></tr>";
				}
				
				if(j==5){
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>0 - 1</div><div class='txt_right'>"+((betGame.gameOdds[21].toBet)?formatOdd(betGame.gameOdds[21].odd):"-")+"</div></td>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>2 - 3</div><div class='txt_right'>"+((betGame.gameOdds[22].toBet)?formatOdd(betGame.gameOdds[22].odd):"-")+"</div></td></tr>";
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>4 - 6</div><div class='txt_right'>"+((betGame.gameOdds[23].toBet)?formatOdd(betGame.gameOdds[23].odd):"-")+"</div></td>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>7+</div><div class='txt_right'>"+((betGame.gameOdds[24].toBet)?formatOdd(betGame.gameOdds[24].odd):"-")+"</div></td></tr>";
				}
				
				if(j==6){
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>Under (2,5)</div><div class='txt_right'>"+((betGame.gameOdds[25].toBet)?formatOdd(betGame.gameOdds[25].odd):"-")+"</div></td>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>Over (2,5)</div><div class='txt_right'>"+((betGame.gameOdds[26].toBet)?formatOdd(betGame.gameOdds[26].odd):"-")+"</div></td></tr>";
				}
				
				if(j==7){
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>GOAL</div><div class='txt_right'>"+((betGame.gameOdds[29].toBet)?formatOdd(betGame.gameOdds[29].odd):"-")+"</div></td>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>NO GOAL</div><div class='txt_right'>"+((betGame.gameOdds[30].toBet)?formatOdd(betGame.gameOdds[30].odd):"-")+"</div></td></tr>";
				}
				
				if(j==8){
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>"+resources[lang][9]+"</div><div class='txt_right'>"+((betGame.gameOdds[27].toBet)?formatOdd(betGame.gameOdds[27].odd):"-")+"</div></td>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>"+resources[lang][10]+"</div><div class='txt_right'>"+((betGame.gameOdds[28].toBet)?formatOdd(betGame.gameOdds[28].odd):"-")+"</div></td></tr>";
				}
				
				if(j==9){
					html[htmlIndex++] = "<tr><td class='border_green'><div class='txt_left'>1 - 0</div><div class='txt_right'>"+((betGame.gameOdds[37].toBet)?formatOdd(betGame.gameOdds[37].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>0 - 0</div><div class='txt_right'>"+((betGame.gameOdds[36].toBet)?formatOdd(betGame.gameOdds[36].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>0 - 1</div><div class='txt_right'>"+((betGame.gameOdds[67].toBet)?formatOdd(betGame.gameOdds[67].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>2 - 0</div><div class='txt_right'>"+((betGame.gameOdds[38].toBet)?formatOdd(betGame.gameOdds[38].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>1 - 1</div><div class='txt_right'>"+((betGame.gameOdds[52].toBet)?formatOdd(betGame.gameOdds[52].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>0 - 2</div><div class='txt_right'>"+((betGame.gameOdds[68].toBet)?formatOdd(betGame.gameOdds[68].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>3 - 0</div><div class='txt_right'>"+((betGame.gameOdds[39].toBet)?formatOdd(betGame.gameOdds[39].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>2 - 2</div><div class='txt_right'>"+((betGame.gameOdds[53].toBet)?formatOdd(betGame.gameOdds[53].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>0 - 3</div><div class='txt_right'>"+((betGame.gameOdds[69].toBet)?formatOdd(betGame.gameOdds[69].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>4 - 0</div><div class='txt_right'>"+((betGame.gameOdds[40].toBet)?formatOdd(betGame.gameOdds[40].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>3 - 3</div><div class='txt_right'>"+((betGame.gameOdds[54].toBet)?formatOdd(betGame.gameOdds[54].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>0 - 4</div><div class='txt_right'>"+((betGame.gameOdds[70].toBet)?formatOdd(betGame.gameOdds[70].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>5(+) - 0</div><div class='txt_right'>"+((betGame.gameOdds[41].toBet)?formatOdd(betGame.gameOdds[41].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>4 - 4</div><div class='txt_right'>"+((betGame.gameOdds[55].toBet)?formatOdd(betGame.gameOdds[55].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>0 - 5(+)</div><div class='txt_right'>"+((betGame.gameOdds[71].toBet)?formatOdd(betGame.gameOdds[71].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>2 - 1</div><div class='txt_right'>"+((betGame.gameOdds[42].toBet)?formatOdd(betGame.gameOdds[42].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>5(+) - 5(+)</div><div class='txt_right'>"+((betGame.gameOdds[56].toBet)?formatOdd(betGame.gameOdds[56].odd):"-")+"</div></td><td class='border_green'><div class='txt_left'>1 - 2</div><div class='txt_right'>"+((betGame.gameOdds[63].toBet)?formatOdd(betGame.gameOdds[63].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>3 - 1</div><div class='txt_right'>"+((betGame.gameOdds[43].toBet)?formatOdd(betGame.gameOdds[43].odd):"-")+"</div></td><td></td><td class='border_green'><div class='txt_left'>1 - 3</div><div class='txt_right'>"+((betGame.gameOdds[64].toBet)?formatOdd(betGame.gameOdds[64].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>4 - 1</div><div class='txt_right'>"+((betGame.gameOdds[44].toBet)?formatOdd(betGame.gameOdds[44].odd):"-")+"</div></td><td></td><td class='border_green'><div class='txt_left'>1 - 4</div><div class='txt_right'>"+((betGame.gameOdds[65].toBet)?formatOdd(betGame.gameOdds[65].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>5(+) - 1</div><div class='txt_right'>"+((betGame.gameOdds[45].toBet)?formatOdd(betGame.gameOdds[45].odd):"-")+"</div></td><td></td><td class='border_green'><div class='txt_left'>1 - 5(+)</div><div class='txt_right'>"+((betGame.gameOdds[66].toBet)?formatOdd(betGame.gameOdds[66].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>3 - 2</div><div class='txt_right'>"+((betGame.gameOdds[46].toBet)?formatOdd(betGame.gameOdds[46].odd):"-")+"</div></td><td></td><td class='border_green'><div class='txt_left'>2 - 3</div><div class='txt_right'>"+((betGame.gameOdds[60].toBet)?formatOdd(betGame.gameOdds[60].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>4 - 2</div><div class='txt_right'>"+((betGame.gameOdds[47].toBet)?formatOdd(betGame.gameOdds[47].odd):"-")+"</div></td><td></td><td class='border_green'><div class='txt_left'>2 - 4</div><div class='txt_right'>"+((betGame.gameOdds[61].toBet)?formatOdd(betGame.gameOdds[61].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>5(+) - 2</div><div class='txt_right'>"+((betGame.gameOdds[48].toBet)?formatOdd(betGame.gameOdds[48].odd):"-")+"</div></td><td></td><td class='border_green'><div class='txt_left'>2 - 5(+)</div><div class='txt_right'>"+((betGame.gameOdds[62].toBet)?formatOdd(betGame.gameOdds[62].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>4 - 3</div><div class='txt_right'>"+((betGame.gameOdds[49].toBet)?formatOdd(betGame.gameOdds[49].odd):"-")+"</div></td><td></td><td class='border_green'><div class='txt_left'>3 - 4</div><div class='txt_right'>"+((betGame.gameOdds[58].toBet)?formatOdd(betGame.gameOdds[58].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>5(+) - 3</div><div class='txt_right'>"+((betGame.gameOdds[50].toBet)?formatOdd(betGame.gameOdds[50].odd):"-")+"</div></td><td></td><td class='border_green'><div class='txt_left'>3 - 5(+)</div><div class='txt_right'>"+((betGame.gameOdds[59].toBet)?formatOdd(betGame.gameOdds[59].odd):"-")+"</div></td></tr><tr>";
					html[htmlIndex++] = "<td class='border_green'><div class='txt_left'>5(+) - 4</div><div class='txt_right'>"+((betGame.gameOdds[51].toBet)?formatOdd(betGame.gameOdds[51].odd):"-")+"</div></td><td></td><td class='border_green'><div class='txt_left'>4 - 5(+)</div><div class='txt_right'>"+((betGame.gameOdds[57].toBet)?formatOdd(betGame.gameOdds[57].odd):"-")+"</div></td></tr>";
				}
				
				html[htmlIndex++] = "</tbody></table></div><div class='close'>&nbsp;</div></div></div>";
			}
		}						
		
		html[htmlIndex++] = "</div></div>";
		var title = "<div id='printButton2' class='noPrint' style='padding:3px;'><a onclick='javascript:printBoxy(0)'>"+resources[lang][24]+"&nbsp;<img border='0' src='../../../html/demo/bet/images/print.gif' alt='"+resources[lang][24]+"'></a></div>";
		myBoxy = new Boxy(html.join(""), {title: title,closeText:"Κλείσιμο",modal:true,unloadOnHide:true,afterHide:makeProgramVisible,closeable:true,draggable:false,fixed:false,center:false,x:10,y:10});	
		myBoxy.show();
		if($(window).scrollTop()){
			myBoxy.moveTo(10,undefined);
		}
		$("#wrapper").addClass("noPrint");	
		
		$("#loader").hide();
		$("#searchDiv").show();
		$("#printButton").show();
	}
	
	function showSpecificTournament(tourId){
		changeHashAttribute("t",(tourId == "-1")?"remove":tourId);
		$("#selectTour").val(tourId);
	}
		
	function showProgram(drawNumber,getCoupon){	
	
		if(mode == undefined){
			return false;
		}
		
		$("#searchDiv").hide();
		$("#printButton").hide();
		$("#loader").show();
		
		//Clear previous program games and styles
		$("#program").html('');
		$("#program").removeClass("basketProgram");	
		$("#program").removeClass("baseballProgram");
		$("div.flags_basket table tbody").html('');
		$("div.flags_baseball table tbody").html('');
		$("div.flags table tbody").html('');		
		$("#bottomDiv1").hide();
		$("#bottomDiv2").hide();	
		$("#bottomDiv20").hide();
		$("#printButton").addClass("displayNone");
		$("#otherDay").html("");	
				
		if(mode == 2)
			$("#program").addClass("basketProgram");	
		
		if(mode == 20)
			$("#program").addClass("baseballProgram");
			
		if(mode == 12)
			$("#program").addClass("baseballProgram");
			
		if(mode > 0)
			$("#printButton").removeClass("displayNone");
		
		if(!getCoupon){
			$("#notAllCoupon").html("Δεν βλέπετε το πλήρες κουπόνι.");
		}else{
			$("#notAllCoupon").html("");
		}
		
		chooseGame(mode,drawNumber,getCoupon);
		
	}
	
	function getDraws(drawParam, tourParam, getCoupon){
		$.ajax({ url: "/web/services/rs/draw/4100/last/180", 
				 dataType:'json', 
				 beforeSend: function(xhrObj){xhrObj.setRequestHeader("LOCALE",locale);},
				 success: function(data){	
				 
			var arrayDraws = new Array();
			var length = data.length;
			var useTmpDraw = false;
			var tmpDrawIndex;
			
			var newData = new Array();
			var lastDrawNumber = data[0].drawNumber;
			var lastDrawDate = data[0].drawDate;
			
			var now = new Date();
			var extraDraws = 0;
			var tmp1 = now.getDay();
			var tmp2 = now.getHours();
			if(tmp1 == 0){//sunday
				extraDraws = 1;
			}else if(tmp1 == 1){//monday
				extraDraws = 0;
			}else if(tmp1 == 2 && tmp2 > 8){//tuesday after 08:00
				extraDraws = 2;
			}else if(tmp1 == 3){//wed
				extraDraws = 1;
			}else if(tmp1 == 4){//thurs
				extraDraws = 0;
			}else if(tmp1 == 5 && tmp2 > 8){//friday after 08:00
				extraDraws = 3;
			}else if(tmp1 == 6){//sat
				extraDraws = 2;
			}
			
			for(var k=0;k<extraDraws;k++){
				var tmp = new Object();
				tmp.drawNumber = lastDrawNumber + k + 1;
				tmp.drawDate = lastDrawDate + ((k+1)*86400000);
				newData[extraDraws - k - 1] = tmp;
			}
			for(var i=0;i<data.length;i++){
				newData[extraDraws + i] = data[i];
			}
			
			for(var i=0;i<newData.length;i++){
				draws[setFormattedDrawDate(newData[i].drawDate)] = newData[i].drawNumber;
				drawsByNumber[newData[i].drawNumber] = newData[i].drawDate;
				if(!useTmpDraw && drawParam != undefined && drawParam == newData[i].drawNumber){
					useTmpDraw = true;
					tmpDrawIndex = i;
				}
			}	
			
			//$("#showProgramButtons").append("<div id='searchDiv' class='searchDiv'><div class='dateSearchDiv'>Αναζήτηση με ημερομηνία: <input type='text' id='dateRange'/></div><div class='tournamentSearchDiv'>Αναζήτηση με διοργάνωση: <select id='selectTour' type='select'></select></div></div>");			
			$("#showProgramButtons").append("<div id='searchDiv' class='searchDiv'><table><tr><td>Αναζήτηση με ημερομηνία: </td><td><input type='text' id='dateRange'/></td><td class='tourSearch'>Αναζήτηση με διοργάνωση: </td><td><select id='selectTour' type='select'></select></td></tr></table><div>");			
			$("#dateRange").datepicker({ dateFormat: 'dd/mm/yy' , maxDate:new Date(newData[0].drawDate) , minDate:new Date(newData[newData.length-1].drawDate)});
			
			var drawIndex = useTmpDraw?tmpDrawIndex:extraDraws;
			currentDrawNumber = newData[drawIndex].drawNumber;			
						
			$("#dateRange").val(setFormattedDrawDate(newData[drawIndex].drawDate));
			
			currentTournamentId = tourParam;
			
			var changedHash = changeHashAttribute("d",currentDrawNumber);
			
			if(!changedHash){
				showProgram(currentDrawNumber,getCoupon);
			}
						
			$("#dateRange").change(changeDraw);	

			$(window).hashchange( function(){
		
				var params = getDrawAndTourFromHash(window.location.hash);
				
				var dateParam = params["d"];
				var tourParam = params["t"];	
				var couponParam = params["c"];	
				var getCoupon = (couponParam != undefined && couponParam == "1");	
				
				if(tourParam != undefined && tourParam != currentTournamentId){
					currentTournamentId = tourParam;
					progMan.selectedCategory.reloadForTournament(false);
					$("#selectTour").val(currentTournamentId);
					return false;
				}else if(currentTournamentId != undefined && tourParam == undefined){
					currentTournamentId = undefined;
					showProgram(currentDrawNumber,getCoupon);
				}
				
				if(dateParam != currentDrawNumber || getCoupon){
					currentDrawNumber = dateParam;
					showProgram(currentDrawNumber,getCoupon);
				}else if(getCouponParamPrevious != getCoupon){
					showProgram(currentDrawNumber,getCoupon);
				}
				getCouponParamPrevious = getCoupon;
				
			});
		}});
	}
	
	function setFormattedDrawDate(currentTime){
		var date = new Date(currentTime);
		var tmpDay = date.getDate()  + '';
		var tmpMonth = date.getMonth()  + 1 +'';
		var year = date.getFullYear();
		var hour = date.getHours();
		if (tmpDay.length == 1) tmpDay = "0" + tmpDay;
		if (tmpMonth.length == 1) tmpMonth = "0" + tmpMonth;
		return tmpDay + '/' + tmpMonth + '/' + year;
	}
	
	function setDrawDate(currentTime){
		var date = new Date(currentTime);
		var tmpDay = date.getDay();
		var tmpMonth = date.getMonth();
		var year = date.getFullYear();
		return day[tmpDay] + ' ' +date.getDate()+ ' ' + month[tmpMonth] + ' ' + year;
	}
	
	function changeDraw(){
		var drawNumber = draws[$("#dateRange").val()];
		if(drawNumber != undefined){			
			currentTournamentId = undefined; 
			window.location.hash = "#d-"+drawNumber;
		}else{
			alert('Δεν έχει οριστεί κλήρωση τη συγκεκριμένη ημερομηνία');

		}
	}
	
	function getDrawAndTourFromHash(hashStr){
		var params = new Object;
		params["d"] = undefined;
		params["t"] = undefined;
		params["c"] = undefined;
		if(hashStr != undefined && hashStr != ""){
			if(hashStr.charAt(0) == '#') hashStr = hashStr.substring(1);
			var hashTags = hashStr.split(",");
			//find if draw has been set
			for(var i=0;i<hashTags.length;i++){
				if(hashTags[i].indexOf("d-")!=-1){
					params["d"] = hashTags[i].substring(2);
				}else if(hashTags[i].indexOf("t-")!=-1){
					params["t"] = hashTags[i].substring(2);
				}else if(hashTags[i].indexOf("c-")!=-1){
					params["c"] = hashTags[i].substring(2);
				}
			}
		}
		return params;
	}
	
	function changeHashAttribute(attr,value){
		var params = getDrawAndTourFromHash(window.location.hash);
		params[attr] = value;
		var newHash = "#";
		for(key in params){
			if(params[key] != undefined && params[key] != "remove"){
				newHash += key+"-"+params[key]+",";
			}
		}
		if(newHash.length > 1)
			newHash = newHash.substring(0,newHash.length-1);
		
		var oldHash = window.location.hash;
		window.location.hash = newHash;
		return oldHash != newHash;
	}
	
	function goToPrintPages(){
		var drawParamTmp = "";
		drawParamTmp = "&d="+currentDrawNumber;
		if(getCouponParamPrevious){
			drawParamTmp += "&c=1";
		}
		var localeParam = "";
		if(lang == 2){
			localeParam = "&localeId=en_GB";
		}
		window.open( "../../../html/demo/bet/printPages/new.html?mode="+mode+""+localeParam+""+drawParamTmp);
		return false;
	}
		
	var mode;
	var locale;
	var lang;
	var draws = new Object;
	var drawsByNumber = new Object;
	var currentDrawNumber = 0;
	var currentTournamentId;
	var getCouponParamPrevious;

	$(document).ready(function() {  
		var givenLocal = localeId;
		givenLocal = (givenLocal == "en_GB")?"en_GB":"el_GR";
		locale = givenLocal;
		lang = (givenLocal == "en_GB")?2:1;//2 english, 1 greek
		if(lang == 2){
			$.datepicker.setDefaults($.datepicker.regional['']);
		}
		
		var html = "<div class='wrapMenuDiscipline' id='accordion'><h3><a class='top'><span class='sport-name'>"+resources[lang][32]+"</span></a></h3><div class='child'><ul>";
		html += "<li><a id='mode-1' "+((mode == 1)?"class='selected'":"")+" href='/"+(lang==2?"en":"el")+"/web/guest/praktoreio-football'>"+resources[lang][0]+"</a></li>";
		html += "<li><a id='mode-2' "+((mode == 2)?"class='selected'":"")+" href='/"+(lang==2?"en":"el")+"/web/guest/praktoreio-basket'>"+resources[lang][1]+"</a></li>";
		html += "<li><a id='mode-20' "+((mode == 20)?"class='selected'":"")+" href='/"+(lang==2?"en":"el")+"/web/guest/praktoreio-baseball'>"+resources[lang][33]+"</a></li>";
		html += "<li><a id='mode-12' "+((mode == 12)?"class='selected'":"")+" href='/"+(lang==2?"en":"el")+"/web/guest/praktoreio-icehockey'>"+resources[lang][43]+"</a></li>";
		html += "<li><a id='mode-0' "+((mode == 0)?"class='selected'":"")+" href='/"+(lang==2?"en":"el")+"/web/guest/praktoreio-special'>"+resources[lang][2]+"</a></li></ul></div></div>";
		$("#flashContent").append(html);
		$("#accordion").accordion({ 
			collapsible: true, 
			autoHeight: false,
			active: 0
		});
		
		if(mode == 1 || mode == 2 || mode == 20 || mode == 12){
			$("#showProgramButtons").append("<img src='../../../html/demo/bet/images/pamest_"+mode+".gif' style='float:left;'/>");
			$("#printButton").append("<input id='coupon' type='button' alt='"+resources[lang][29]+"' title='"+resources[lang][30]+"'/>");
			
			var params = getDrawAndTourFromHash(window.location.hash);
						
			$("#coupon").click(function(){
				if(window.location.hash.indexOf("c-1") == -1){
					currentTournamentId = undefined; window.location.hash += ",c-1";
				}else{
					//remove tournament filter so that coupon will be refreshed.
					showSpecificTournament("-1");
				}
			});
			var couponParam = params["c"];	
			var getCoupon = (couponParam != undefined && couponParam == "1");				
				
			getDraws(params["d"],params["t"],getCoupon);
			
		}else if(mode == 0){
			$("#couponBettingContainer").html("<div id='program'></div>");
			showProgram(undefined,false);
		}
		
		$("#printPagesLink").click(goToPrintPages);
	});	
	
	var daysExtra = new Object;
	daysExtra[0] = "της Κυριακής";
	daysExtra[1] = "της Δευτέρας";
	daysExtra[2] = "της Τρίτης";
	daysExtra[3] = "της Τετάρτης";
	daysExtra[4] = "της Πέμπτης";
	daysExtra[5] = "της Παρασκευής";
	daysExtra[6] = "του Σαββάτου";
	
	var resources = new Object;
	resources[1] = new Object;
	resources[2] = new Object;
	resources[1][0] = "ΠΟΔΟΣΦΑΙΡΟ";
	resources[2][0] = "FOOTBALL";
	resources[1][1] = "ΜΠΑΣΚΕΤ";
	resources[2][1] = "BASKETBALL";
	resources[1][2] = "ΕΙΔΙΚΑ ΣΤΟΙΧΗΜΑΤΑ";
	resources[2][2] = "SPECIAL BETS";
	resources[1][3] = "Σκορ Αγώνα";
	resources[2][3] = "Result";
	resources[1][4] = "Δ";
	resources[2][4] = "COMP";
	resources[1][5] = "ΩΕ";
	resources[2][5] = "K/O";
	resources[1][6] = "A";
	resources[2][6] = "R/N";
	resources[1][7] = "E/E";
	resources[2][7] = "S";
	resources[1][8] = "ΠΓ";
	resources[2][8] = "AH";
	resources[1][9] = "ΓΗΠΕΔΟΥΧΟΣ";
	resources[2][9] = "HOME TEAM";
	resources[1][10] = "ΦΙΛΟΞ/ΜΕΝΗ";
	resources[2][10] = "AWAY TEAM";
	resources[1][11] = "ΠΦ";
	resources[2][11] = "AV";
	resources[1][12] = "ΕΙΔ.<br/> ΣΤΟΙΧ.";
	resources[2][12] = "SPEC.<BR/>BETS";
	resources[1][13] = "ΣΚΟΡ";
	resources[2][13] = "SCORE";
	resources[1][14] = "Ημ/νο";
	resources[2][14] = "F. Half";
	resources[1][15] = "Τελικό";
	resources[2][15] = "S. Half";
	resources[1][16] = "ΒΑΣΙΚΟΣ ΠΙΝΑΚΑΣ ΑΠΟΔΟΣΕΩΝ";
	resources[2][16] = "ODDS TABLE";
	resources[1][17] = "ΒΑΣ.<br/> ΣΤΟΙΧ.";
	resources[2][17] = "NORMAL<br/> BETS";
	resources[1][18] = "ΣΗΜ.";
	resources[2][18] = "ΣΗΜ.";
	resources[1][19] = "ΑΠΟΤ.";
	resources[2][19] = "RES.";
	resources[1][20] = "Δεν υπάρχουν ειδικά στοιχήματα.";
	resources[2][20] = "There are no special bets";
	resources[1][21] = "ΚΩΔ.";
	resources[2][21] = "CODE";
	resources[1][22] = "ΠΕΡΙΓΡΑΦΗ";
	resources[2][22] = "DESCRIPTION";
	resources[1][23] = "ΑΠΟΔΟΣΗ";
	resources[2][23] = "ODD";
	resources[1][24] = "Εκτύπωση Κουπονιού";
	resources[2][24] = "Print Coupon";
	resources[1][25] = "Κλείσιμο";
	resources[2][25] = "Close";
	resources[1][26] = "1 ή Χ";
	resources[2][26] = "1 or X";
	resources[1][27] = "1 ή 2";
	resources[2][27] = "1 or 2";
	resources[1][28] = "X ή 2";
	resources[2][28] = "X or 2";
	resources[1][29] = "Τρέχον κουπόνι";
	resources[2][29] = "Current coupon";
	resources[1][30] = "Δείτε όλο το κουπόνι";
	resources[2][30] = "See the whole coupon";
	resources[1][31] = "Διορ.";
	resources[2][31] = "Tour";
	resources[1][32] = "ΣΤΟΙΧΗΜΑ ΣΤΟ ΠΡΑΚΤΟΡΕΙΟ";
	resources[2][32] = "BETTING IN RETAIL SHOP";
	resources[1][33] = "ΜΠΕΪΖΜΠΟΛ";
	resources[2][33] = "BASEBALL";
	resources[1][34] = "'Οριο";
	resources[2][34] = "Line";
	resources[1][35] = "Τελικό";
	resources[2][35] = "Final";
	resources[1][36] = "Α π ο τ ε λ έ σ μ α τ α &nbsp;&nbsp; Β α σ ι κ ώ ν &nbsp;&nbsp; Σ τ ο ι χ η μ ά τ ω ν";
	resources[2][36] = "R e s u l t s&nbsp;&nbsp; o f &nbsp;&nbsp; N o r m a l &nbsp;&nbsp; B e t s";
	resources[1][37] = "Α π ο τ ε λ έ σ μ α τ α &nbsp;&nbsp; Ε ι δ ι κ ώ ν &nbsp;&nbsp; Σ τ ο ι χ η μ ά τ ω ν";
	resources[2][37] = "R e s u l t s&nbsp;&nbsp; o f &nbsp;&nbsp; S p e c i a l &nbsp;&nbsp; B e t s";
	resources[1][38] = "Αποτελέσματα";
	resources[2][38] = "Results";
	resources[1][39] = "Τύπος Στοιχήματος";
	resources[2][39] = "Type of bet";
	resources[1][40] = "Ενδεχόμενο που κερδίζει";
	resources[2][40] = "Won type";
	resources[1][41] = "Αποδ.";
	resources[2][41] = "Odd";				
	resources[1][42] = "ΤΟ ΚΟΥΠΟΝΙ ΠΟΥ ZΗΤΗΘΗΚΕ ΔΕΝ ΕΙΝΑΙ ΔΙΑΘΕΣΙΜΟ.";
	resources[2][42] = "THE REQUESTED COUPON IS NOT AVAILABLE.";
	resources[1][43] = "ΧΟΚΕΪ ΕΠΙ ΠΑΓΟΥ";
	resources[2][43] = "ICE HOCKEY";
	
	
	
		
