
var doubleNULL=-999.888;
var longNULL = -999;
var betTypeIdShown=-1;
var scopeIdShown=-1;
var filters=new Hash();
var filtersForOutrights=new Hash();
var defaultFilters = new Hash();
var defaultFiltersForOutrights = new Hash();
var timeHashFilter = new Hash();
var handicap1X2hasNext = false;
var selectedFilter=null;
var numOfDivPerRow =4;//number of filter div per row above oddstable

var oddstalbeUrl = '/oddstable.do';
var popularMatchUrl ='/popularMatch.do';
var bannerTournamentORMatchUrl = '/bannerEvent.do';
var urlStatus = 'oddstable';// if url is popularMatchesUrl, the urlStatus will change to 'popularmatch'

var timeFilters="";
var isExpend=false;
var filteTable=false;
var isShowEmptyOddsMatch=false;
var pageNo =0;
var curBetType='all';
var curScope=-1;
var filterL = false;
var dateTimeLine=" ";

var searchedName = ""
var isOutrights = false;
var OutcomeInfo = new Class({
	initialize: function(){
		this.integerParameter=-1;
		this.integerParameter2=-1;
		this.integerParameter3=-1;
		this.doubleParameter=-1.0;
		this.doubleParameter2=-1.0;
		this.resultId=-1;
	}
});

var DisciplineIds=new Class({
	initialize: function(){
	this.SOCCER   = 1;
    this.GOLF     = 2;
    this.TENNIS   = 3;
    this.ICEHOCKEY   = 6;
    this.BASKETBALL   = 8;
    this.FIGHTING = 25;
    this.SNOOKER = 36;
    this.RUGBY_UNION = 39;
    this.RUGBY_LEAGUE = 28;
    this.AM_FOOTBALL = 5;
    this.HANDBALL = 7;
    this.BASEBALL = 9;
    this.DARTS = 45;
    this.GAELIC_FOOTBALL = 47;
    this.VOLLEYBALL = 20;
    this.CRICKET = 26;

    this.BEACH_FOOTBALL = 66;
	}
});

var disciplineIds=new DisciplineIds();

var ScopeIds=new Class({
	initialize: function(){
	this.SCOPE_ID_FULL_EVENT                                         = 0;
    this.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME      = 1;
    this.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME      = 2;
    this.SCOPE_ID_1ST_HALF                                             = 3;
    this.SCOPE_ID_2ND_HALF                                            = 4;
    this.SCOPE_ID_1ST_QUARTER                                      = 5;
    this.SCOPE_ID_2ND_QUARTER                                     = 6;
    this.SCOPE_ID_3RD_QUARTER                                     = 7;
    this.SCOPE_ID_4TH_QUARTER                                     = 8;
    this.SCOPE_ID_1ST_PERIOD                                         = 9;
    this.SCOPE_ID_2ND_PERIOD                                        = 10;
    this.SCOPE_ID_3RD_PERIOD                                        = 11;
    this.SCOPE_ID_FIRST_FIVE_INNINGS                            = 12;
    this.SCOPE_ID_1ST_ROUND                                        = 13;
    this.SCOPE_ID_2ND_ROUND                                       = 14;
    this.SCOPE_ID_3RD_ROUND                                       = 15;
    this.SCOPE_ID_4TH_ROUND                                       = 16;
    this.SCOPE_ID_5TH_ROUND                                       = 17;
    this.SCOPE_ID_6TH_ROUND                                       = 18;
    this.SCOPE_ID_1ST_SET                                              = 19;
    this.SCOPE_ID_2ND_SET                                             = 20;
    this.SCOPE_ID_3RD_SET                                             = 21;
    this.SCOPE_ID_4TH_SET                                             = 22;
    this.SCOPE_ID_5TH_SET                                             = 23;
	}
});

var BetTypes = new Class ({
	initialize: function(){
		this.TYPE_ID_WINNER                                             = 7;
		this.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP                       = 8;
		this.TYPE_ID_DOUBLE_CHANCE                                      = 9;
		this.TYPE_ID_HALF_TIME_FULL_TIME                                = 11;
		this.TYPE_ID_NEXT_TEAM_TO_SCORE                                 = 12;
		this.TYPE_ID_TIME_OF_NEXT_GOAL                                  = 13;
		this.TYPE_ID_NEXT_GOALSCORER                                    = 24;
		this.TYPE_ID_TOP_GOALSCORER                                     = 25;
		this.TYPE_ID_RELEGATION                                         = 26;
		this.TYPE_ID_PROMOTION                                          = 27;
		this.TYPE_ID_TOP_X                                              = 28;
		this.TYPE_ID_LAST_GOALSCORER                                    = 29;
		this.TYPE_ID_ANYTIME_GOALSCORER                                 = 30;
		this.TYPE_ID_NUMBER_OF_GOALS                                    = 32;
		this.TYPE_ID_WINNING_MARGIN                                     = 33;
		this.TYPE_ID_SCORECAST                                          = 34;
		this.TYPE_ID_ODD_OR_EVEN                                        = 35;
		this.TYPE_ID_QUALIFICATION                                      = 37;
		this.TYPE_ID_SET_HANDICAP                                       = 38;
		this.TYPE_ID_GAME_HANDICAP                                      = 39;
		this.TYPE_ID_HOME_DRAW_AWAY										= 43;
		this.TYPE_ID_HOME_AWAY_WITH_POSSIBLE_DRAW                       = 44;
		this.TYPE_ID_CORRECT_SCORE_WITH_SCOPE                           = 45;
		this.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW                     = 46;
		this.TYPE_ID_OVER_UNDER                                         = 47;
		this.TYPE_ID_ASIAN_HANDICAP                                     = 48;
		this.TYPE_ID_NUMBER_OF_CORNERS                                  = 49;
		this.TYPE_ID_NEXT_CORNER                                   		= 50;
		this.TYPE_ID_NEXT_THROW_IN                                   	= 51;
		this.TYPE_ID_NEXT_FREE_KICK                                   	= 52;
		this.TYPE_ID_NEXT_GOAL_KICK                                   	= 53;
		this.TYPE_ID_HEAD_TO_HEAD_WITH_IMPOSSIBLE_DRAW            		= 54;
		this.TYPE_ID_HEAD_TO_HEAD_WITH_POSSIBLE_DRAW              		= 55;
		this.TYPE_ID_HEAD_TO_HEAD                                       = 56;
		this.TYPE_ID_ROCK_BOTTOM                                   		= 57;
		this.TYPE_ID_HOME_DRAW_AWAY_WITH_WINNING_MARGIN        			= 59;
		this.TYPE_ID_GAME_HANDICAP_WITH_DRAW        					= 60;
		this.TYPE_ID_HALF_WITH_MOST_GOALS                               = 61;
		this.TYPE_ID_POLE_POSITION                               		= 65;
		this.TYPE_ID_FASTEST_LAP                               			= 66;
		this.TYPE_ID_FIRST_TO_RETIRE                              		= 67;
		this.TYPE_ID_FIRST_LAP_LEADER                               	= 68;
	}
});

var BetTypeHeadTitle= new Class({
	initialize:function(type,betTypeTitle){
		var header = betTypeTitle.split(",");
		this.type=type;//0:3 cell
		this.homeText=header[0];//homeText;
		this.drawText=header[1];//drawText;
		this.awayText=header[2];//awayText;
	},	
	setDrawText:function(topXParam){//specially for top x
		var betTypeName = this.drawText.substring(0, this.drawText.indexOf(" ")) + " " +topXParam;
		this.drawText= betTypeName;
		return this;
	}
});

var HeadTitle = new Class({
	initialize:function(BTH_HOME_DRAW_AWAY_WITH_HANDICAP,BTH_DOUBLE_CHANCE,BTH_HALF_TIME_FULL_TIME,
	                    BTH_NUMBER_OF_GOALS,BTH_ODD_OR_EVEN,BTH_GAME_HANDICAP,
	                    BTH_HOME_DRAW_AWAY,BTH_CORRECT_SCORE_WITH_SCOPE,BTH_HOME_AWAY_WITH_IMPOSSIBLE_DRAW,
	                    BTH_OVER_UNDER,BTH_ASIAN_HANDICAP,//8,9,11,21,35,39,43,45,46,47,48,28
	                    
	                    BTH_WINNER,BTH_TOP_GOALSCORER,BTH_RELEGATION,BTH_PROMOTION,BTH_TOP_X,BTH_ROCK_BOTTOM,
	                    BTH_POLE_POSITION,BTH_FASTEST_LAP,BTH_FIRST_TO_RETIRE,BTH_FIRST_LAP_LEADER){//7,25,26,27,28,57,65,66,67,68 outrights bettype
		this.HEADTITLE_HOME_DRAW_AWAY_WITH_HANDICAP = new BetTypeHeadTitle(8,BTH_HOME_DRAW_AWAY_WITH_HANDICAP);
		this.HEADTITLE_DOUBLE_CHANCE = new BetTypeHeadTitle(9,BTH_DOUBLE_CHANCE);
		this.HEADTITLE_HALF_TIME_FULL_TIME = new BetTypeHeadTitle(11,BTH_HALF_TIME_FULL_TIME);
		this.HEADTITLE_NUMBER_OF_GOALS = new BetTypeHeadTitle(32,BTH_NUMBER_OF_GOALS);
		this.HEADTITLE_ODD_OR_EVEN = new BetTypeHeadTitle(35,BTH_ODD_OR_EVEN);
		this.HEADTITLE_GAME_HANDICAP = new BetTypeHeadTitle(39,BTH_GAME_HANDICAP);
		this.HEADTITLE_HOME_DRAW_AWAY = new BetTypeHeadTitle(43,BTH_HOME_DRAW_AWAY);
		this.HEADTITLE_CORRECT_SCORE_WITH_SCOPE = new BetTypeHeadTitle(45,BTH_CORRECT_SCORE_WITH_SCOPE);
		this.HEADTITLE_HOME_AWAY_WITH_IMPOSSIBLE_DRAW = new BetTypeHeadTitle(46,BTH_HOME_AWAY_WITH_IMPOSSIBLE_DRAW);
		this.HEADTITLE_OVER_UNDER = new BetTypeHeadTitle(47,BTH_OVER_UNDER);
		this.HEADTITLE_ASIAN_HANDICAP = new BetTypeHeadTitle(48,BTH_ASIAN_HANDICAP);
		this.HEADTITLE_OTHER = new BetTypeHeadTitle(0,",,");
		
		//outrights
		this.HEADTITLE_WINNER  = new BetTypeHeadTitle(7,BTH_WINNER);
		this.HEADTITLE_TOP_GOALSCORER  = new BetTypeHeadTitle(25,BTH_TOP_GOALSCORER);
		this.HEADTITLE_RELEGATION  = new BetTypeHeadTitle(26,BTH_RELEGATION);
		this.HEADTITLE_PROMOTION  = new BetTypeHeadTitle(27,BTH_PROMOTION);
		this.HEADTITLE_TOP_X = new BetTypeHeadTitle(28,BTH_TOP_X);
		this.HEADTITLE_TOP_X_withParam = new BetTypeHeadTitle(28,BTH_TOP_X);
		this.HEADTITLE_ROCK_BOTTOM  = new BetTypeHeadTitle(57,BTH_ROCK_BOTTOM);
		this.HEADTITLE_POLE_POSITION  = new BetTypeHeadTitle(65,BTH_POLE_POSITION);
		this.HEADTITLE_FASTEST_LAP  = new BetTypeHeadTitle(66,BTH_FASTEST_LAP);
		this.HEADTITLE_FIRST_TO_RETIRE  = new BetTypeHeadTitle(67,BTH_FIRST_TO_RETIRE);
		this.HEADTITLE_FIRST_LAP_LEADER  = new BetTypeHeadTitle(68,BTH_FIRST_LAP_LEADER);

	},
	getHEADTITLE_TOP_X_withParam:function (topXParam) {
		this.HEADTITLE_TOP_X_withParam.setDrawText(topXParam);	
		return this.HEADTITLE_TOP_X_withParam;	
	}
});

var betTypes=new BetTypes();
var scopeIds=new ScopeIds();

var BetTypeKey=new Class({
	initialize: function(betTypeId,scopeId){
		this.betTypeId=betTypeId;
		this.scopeId=scopeId;
	}
});



var Util = new Class({
	initialize: function(){
		this.dateRegex=/(\d{1,4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):.+/;
	},
	getDateFromJavaString: function(dateString){
		var rezDate=new Date();
		var rez=dateString.match(this.dateRegex);
		rezDate.setYear(rez[1]);		
		rezDate.setDate(parseFloat(rez[3]));
		rezDate.setMonth(parseFloat(rez[2])-1);		
		rezDate.setHours(parseFloat(rez[4]));
		rezDate.setMinutes(parseFloat(rez[5]));
		return rezDate;
	}
});

var util = new Util();

var OutcomeTypes=new Class({
	initialize: function(){
		this.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.HOMEDRAWAWAY_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY,scopeIds.SCOPE_ID_FULL_EVENT);
		this.HOMEDRAWAWAY_FIRST_HALF=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY,scopeIds.SCOPE_ID_1ST_HALF);
		this.HOMEDRAWAWAY_SECOND_HALF=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY,scopeIds.SCOPE_ID_2ND_HALF);
		this.OVERUNDER_FULLTIME_EXCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_OVER_UNDER,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.OVERUNDER_FULLTIME_INCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_OVER_UNDER,scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME);
		this.OVERUNDER_FIRST_HALF=new BetTypeKey(betTypes.TYPE_ID_OVER_UNDER,scopeIds.SCOPE_ID_1ST_HALF);
		this.OVERUNDER_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_OVER_UNDER,scopeIds.SCOPE_ID_FULL_EVENT);
		this.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_ASIAN_HANDICAP,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_ASIAN_HANDICAP,scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME);
		this.ASIANHANDICAP_FIRST_HALF=new BetTypeKey(betTypes.TYPE_ID_ASIAN_HANDICAP,scopeIds.SCOPE_ID_1ST_HALF);
		this.HOME_DRAW_AWAY_WITH_HANDICAP_FULLTIME_EXCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.HOMEAWAY_FULLEVENT=new BetTypeKey(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW,scopeIds.SCOPE_ID_FULL_EVENT);
		this.HOMEAWAY_FULLEVENT_INCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW,scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME);
		this.HALFTIME_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_HALF_TIME_FULL_TIME,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.CORRECTSCORE_FULLTIME_EXCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.CORRECTSCORE_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE,scopeIds.SCOPE_ID_FULL_EVENT);
		this.CORRECTSCORE_FIRST_HALF=new BetTypeKey(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE,scopeIds.SCOPE_ID_1ST_HALF);
		this.DOUBLE_CHANCE_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_DOUBLE_CHANCE,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
				//----------wolf add bettype---------------------------
		this.DOUBLE_CHANCE_FIRST_HALF=new BetTypeKey(betTypes.TYPE_ID_DOUBLE_CHANCE,scopeIds.SCOPE_ID_1ST_HALF);
		this.GAMEHANDICAP_FULLEVENT = new BetTypeKey(betTypes.TYPE_ID_GAME_HANDICAP,scopeIds.SCOPE_ID_FULL_EVENT);
		this.SETHANDICAP_FULLEVENT = new BetTypeKey(betTypes.TYPE_ID_SET_HANDICAP,scopeIds.SCOPE_ID_FULL_EVENT);
		
		this.TIME_OF_NEXT_GOALFULLTIME_EXCLUDEOVERTIME  = new BetTypeKey(betTypes.TYPE_ID_TIME_OF_NEXT_GOAL,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);

		this.ODD_OR_EVEN_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_ODD_OR_EVEN,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.NUMBER_OF_GOALS_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_NUMBER_OF_GOALS,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		
	}
});
var outcomeTypes=new OutcomeTypes();

var currentExpandedMatch=null;
var topTable;
var topTableBody;
function initTopTable(){
	date1= new Date();// initial the sessionTimeOut data,the variable was defined on frontpage.js
	topTable=new Element('table', {'id':'oddstableTable','class':'oddsInfoTab','width': '100%','cellspacing':'0','cellpadding':'0','border':'0'});
	if(window.ie){
		topTable.setStyle('padding','0');
	    topTable.setStyle('border-collapse','collapse');
	}
	topTableBody=new Element('tbody',{'id':'topTableBody'});
	topTableBody.injectInside(topTable);
}
var CategElement = new Class ({
	initialize: function(elid){
		this.id=elid;
		this.name='';
		//this.topElementTable=new Element('table', {'id': elid,'class':'oddsInfoTab','width': '100%','cellspacing':'0','cellpadding':'0',"border":'1'});
		//this.topElementTable.setStyle('padding','0');
		//this.topElementTable.setStyle('border-collapse','collapse');
		//this.topElement=new Element('tbody');
		//this.topElement.injectInside(this.topElementTable);

	},
	setClassName: function(className){
		this.elementCell.addClass(className);
	},
	setName: function(name){
		this.name=name;
		var elementName=new Element('td',{'colspan':'8','width':'100%'});
		elementName.setHTML(name);
		elementName.injectInside(this.elementLine);
		//this.elementCell.setHTML(name);
	},
	setNameWithDiv: function(name,divId){
		this.name=name;
		var elementName=new Element('td',{'colspan':'8','width':'100%'});
		elementName.setHTML('<div id='+divId+'><p>'+name+'</p></div>');
		elementName.setStyle('border-bottom-style','none');
		elementName.injectInside(this.elementLine);
	},
	appendCategChildRow: function(categElement){
		//var elementDate=new Element('td');
		//elementDate.injectInside(this.elementLine);	//alert(topTableBody.innerHTML);
	},
	appendCategChildRowWithDiv: function(categElement,divId){
		var newLine=new Element('tr');
		var newCell=new Element('td');
		var newDiv = new Element('div',{'id':divId});
		newDiv.injectInside(categElement.topElementTable);
		newCell.injectInside(newLine);
		categElement.topElementTable.injectInside(newCell);
		newLine.injectInside(this.topElement);
	},
	addDiv:function(divStr){

	}
});

var Discipline = CategElement.extend ({
	initialize: function(id){
		this.parent(id);
		this.countries=new Hash();
		//this.setClassName('MarketTab');
		/*var headerRow=new Element('tr',{'class': 'headerRow'});
		var dateCell=new Element('td',{'class': 'dateWidth'});
		dateCell.setText('DATE');
		dateCell.injectInside(headerRow);
		var hourCell=new Element('td',{'class': 'hourWidth'});
		hourCell.setText('HOUR');
		hourCell.injectInside(headerRow);
		var homeTeamCell=new Element('td',{'class': 'teamWidth'});
		homeTeamCell.setText('HOME-TEAM');
		homeTeamCell.injectInside(headerRow);
		var awayTeamCell=new Element('td',{'class': 'teamWidth'});
		awayTeamCell.setText('AWAY-TEAM');
		awayTeamCell.injectInside(headerRow);
		var homeCell=new Element('td',{'width': '45','colspan': '2'});
		homeCell.setText('HOME');
		homeCell.injectInside(headerRow);
		var drawCell=new Element('td',{'width': '45','colspan': '2'});
		drawCell.setText('DRAW');
		drawCell.injectInside(headerRow);
		var awayCell=new Element('td',{'width': '45','colspan': '2'});
		awayCell.setText('AWAY');
		awayCell.injectInside(headerRow);
		var expandCell=new Element('td',{'width': '10'});
		expandCell.setHTML('&nbsp;');
		expandCell.injectInside(headerRow);
		//headerRow.injectInside(this.topElement);*/

		this.elementLine=new Element('tr',{'class': 'titleLine'});
		this.elementCell=new Element('td');
		this.elementLine.injectInside(topTableBody);
	},
	addCountry: function(country){
		this.countries.set(country.id,country);
		this.appendCategChildRow(country);//,'SubMarket'

	},
	sortCountry: function(a,b){	 	
	 	var aname = a.name;
		var bname = b.name;
		if(aname>=bname)return 1;
		if(aname<bname)return -1;

	},
	insertIntoDOM: function(parentNode){
		var countries=this.countries.values();
//		countries.sort(this.sortCountry.bind(this));
		var imgIndex=0;
		for(var i=0;i<countries.length;i++){
			var country=countries[i];
			var tournaments=country.tournaments.values();
			for(var k=0;k<tournaments.length;k++){
				var tournament=tournaments[k];
				tournament.prepareForDump("img"+imgIndex);
				imgIndex++;
			}
		}
		topTable.injectInside(parentNode); //document.write(topTableBody.innerHTML); //
		//alert(topTable.innerHTML);
		//alert(document.getElements('td.middle'));		alert($("oddsTable").height);
	},
	setName: function(name){
		this.name=name+$("zoneAndOddsFormat").innerHTML;
		var elementDate=new Element('td',{'colspan':'8'});
		elementDate.injectInside(this.elementLine);

		var nameSpanHolder=new Element('div',{'id':'MarketTabTL'});
		nameSpanHolder.injectInside(elementDate);

		nameSpanHolder=new Element('div',{'id':'MarketTab'});
		nameSpanHolder.setText(name);
		nameSpanHolder.injectInside(elementDate);
		nameSpanHolder=new Element('div',{'id':'MarketTabTR'});
		nameSpanHolder.injectInside(elementDate);
		elementDate.setStyle('border-bottom-style','none');
		/*if (this.elementLine.rowIndex==0){
			var elementZone=new Element('td',{'colspan':'5','style':'text-align:right'});
			elementZone.setHTML($("zoneAndOddsFormat").innerHTML);
			elementZone.setStyle('border-bottom-style','none');
			elementZone.injectInside(this.elementLine);
		}*/

	},
	appendCategChildRow: function(categElement){
		//var elementDate=new Element('td');
		//elementDate.injectInside(this.elementLine);
	}
});

var Country = CategElement.extend ({
	initialize: function(id){
		this.parent(id);
		this.tournaments=new Hash();
		//this.setClassName('SubMarket');

		this.elementLine=new Element('tr',{'class': 'titleLine'});
		this.elementCell=new Element('td');
		this.elementLine.injectInside(topTableBody);
	},
	addTournament: function(tournament){
		this.tournaments.set(tournament.id,tournament);
		//this.appendCategChildRow(tournament);
		this.appendCategChildRow(tournament);//,
		tournament.setCountryName(this.name);
	}
});


var Tournament = CategElement.extend ({
	initialize: function(id){
		this.parent(id);

		this.elementLine=new Element('tr',{'class': 'titleLine'});
		this.elementCell=new Element('td');
		this.elementLine.injectInside(topTableBody);

		this.matches=new Hash();
		this.elementCell.setStyle('width','900px');
		this.elementCell.setStyle('border-bottom','0px');
		//this.setClassName('tournament');
		this.defaultOutcomeType=outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME;
	},
	setCountryName: function(country){
		this.countryName=country;
	},
	setNameWithDiv: function(name){
		this.name=name;
		var tourNameCell = new Element('td',{'colspan':'4','width':'80%'});
		tourNameCell.setStyle('border-bottom','0px');
		tourNameCell.setHTML('<div id="MarketH1"><div id="GameHeadline"><p>'+name+'</p></div></div>');
		tourNameCell.injectInside(this.elementLine);
	},
	addMatch: function(match,imgId){
		if(!match.showDefaultBetType() && betTypeIdShown!=-1 && scopeIdShown!=-1)
			return;
		if(this.matches.length==0){
			this.showDefaultOutcomeType(imgId);
		}
		this.matches.set(match.id,match);
		//match.topElement.injectInside(this.topElementTable);//alert(match.topElement.innerHTML);
		match.setTournament(this);
	},
	setMaxOutcomeType:function(betTypeId,scopeId){
		this.defaultOutcomeType=new BetTypeKey(betTypeId,scopeId);
	},
	setDefaultOutcomeType: function(disciplineId){
		if(betTypeIdShown==-1){
			if (isOutrights) {
							
			} else {
			if(disciplineId==disciplineIds.SOCCER ||
				disciplineId==disciplineIds.ICEHOCKEY ||
				disciplineId==disciplineIds.GAELIC_FOOTBALL ||
				disciplineId==disciplineIds.HANDBALL ||
				disciplineIds.BEACH_FOOTBALL ||
				disciplineId==disciplineIds.RUGBY_UNION ||
				disciplineId==disciplineIds.RUGBY_LEAGUE)
				this.defaultOutcomeType=new BetTypeKey(outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId,outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId);
			else if(disciplineId==disciplineIds.BASKETBALL ||
				disciplineId==disciplineIds.BASEBALL ||
				disciplineId==disciplineIds.AM_FOOTBALL)
				this.defaultOutcomeType=new BetTypeKey(outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId,outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.scopeId);
			else if(disciplineId==disciplineIds.TENNIS ||
				disciplineId==disciplineIds.SNOOKER ||
				disciplineId==disciplineIds.VOLLEYBALL ||
				disciplineId==disciplineIds.DARTS ||
				disciplineId==disciplineIds.FIGHTING ||
				disciplineId==disciplineIds.CRICKET )
				this.defaultOutcomeType=new BetTypeKey(outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId,outcomeTypes.HOMEAWAY_FULLEVENT.scopeId);

			// for the default bettype which is related to the combination of sport and country
			if((disciplineId==disciplineIds.BASEBALL && (this.countryName=='Germany'||this.countryName=='International'||this.countryName=='Italy') )||
			(disciplineId==disciplineIds.BASKETBALL  && (this.countryName=='Europe'||this.countryName=='Spain'))){
				this.defaultOutcomeType=new BetTypeKey(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW,scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME);//46,1
			}
			else if(disciplineId==disciplineIds.BASKETBALL && this.countryName=='International' ){
				this.defaultOutcomeType=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);//43,2
			}
			else if((disciplineId==disciplineIds.CRICKET && (this.countryName=='England'||this.countryName=='International') )||
			(disciplineId==disciplineIds.FIGHTING  && this.countryName=='International')||
			(disciplineId==disciplineIds.SNOOKER  && this.countryName=='England')){
				this.defaultOutcomeType=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY,scopeIds.SCOPE_ID_FULL_EVENT);//43,0
			}

			else if(disciplineId==disciplineIds.ICEHOCKEY && (this.countryName=='Denmark') ){
				this.defaultOutcomeType=new BetTypeKey(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);//46,2
			}
			else if(disciplineId==disciplineIds.ICEHOCKEY && (this.countryName=='United States') ){
				this.defaultOutcomeType=new BetTypeKey(betTypes.TYPE_ID_ASIAN_HANDICAP,scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME);//48,1
			}
			}
		} else {
			this.defaultOutcomeType=new BetTypeKey(betTypeIdShown,scopeIdShown);
		}
	},
	setOutcomeType: function(cellHomeText,cellXText,cellAwayText){
		/*this.elementCell.setHTML('');
		var cellName=new Element('div',{'id':'GameHeadline'});
		cellName.setHTML("<p>"+this.name+"</p>");
		var cellHome=new Element('div',{'id':'GameHeadline1X2'});
		cellHome.setHTML("<p>"+cellHomeText+"</p>");
		var cellX=new Element('div',{'id':'GameHeadline1X2'});
		cellX.setHTML("<p>"+cellXText+"</p>");
		var cellAway=new Element('div',{'id':'GameHeadline1X2'});
		cellAway.setHTML("<p>"+cellAwayText+"</p>");
		var extraCell = new Element('div',{'id':'ExtraGames'})
		extraCell.setHTML("<p></p>");
		var cssDiv=new Element('div',{'id':'MarketH1'});*/

		var cellHome=new Element('td',{'class':'oddsCell','style':'border-bottom:0px;'});
		cellHome.setHTML('<div id="MarketH1"><div id="GameHeadline1X2"><p>'+cellHomeText+'</p></div></div>');
		var cellX=new Element('td',{'class':'oddsCell','style':'border-bottom:0px'});
		cellX.setHTML('<div id="MarketH1"><div id="GameHeadline1X2"><p>'+cellXText+'</p></div></div>');
		var cellAway=new Element('td',{'class':'oddsCell','style':'border-bottom:0px'});
		cellAway.setHTML('<div id="MarketH1"><div id="GameHeadline1X2"><p>'+cellAwayText+'</p></div></div>');

		cellHome.setStyle('border-bottom','0px');
		cellX.setStyle('border-bottom','0px');
		cellAway.setStyle('border-bottom','0px');

		cellHome.injectInside(this.elementLine);
		cellX.injectInside(this.elementLine);
		cellAway.injectInside(this.elementLine);

		/*var lastCell=new Element('td',{'class': 'expandable','style':'border-bottom:0px'});
		lastCell.setHTML('<div id="MarketH1"></div>');
		lastCell.injectInside(this.elementLine);*/
		//alert(this.elementLine.innerHTML);
		//this.elementCell.setProperty('colspan','11');

		/*cellName.injectInside(cssDiv);
		extraCell.injectInside(cssDiv);
		cellAway.injectInside(cssDiv);
		cellX.injectInside(cssDiv);
		cellHome.injectInside(cssDiv);
		cssDiv.injectInside(this.elementCell);
		* if (cellHomeText=='-1'){
			var cellHome=new Element('td',{'class':'oddsCell','style':'border-bottom:0px;','colspan':'3'});
		    cellHome.setHTML('<div id="MarketH1"><div id="GameHeadline1X2"><p>'+cellXText+'</p></div></div>');
		    cellHome.injectInside(this.elementLine);
		    return;
		}*/
	},
	showDefaultOutcomeType: function(imgId){
		var titleTmp = headTitle.HEADTITLE_OTHER;
		if((this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_HOME_DRAW_AWAY	)||
			(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP)){
			titleTmp = headTitle.HEADTITLE_HOME_DRAW_AWAY_WITH_HANDICAP;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW){
				//this.setOutcomeType('1',' ','2');
				titleTmp = headTitle.HEADTITLE_HOME_AWAY_WITH_IMPOSSIBLE_DRAW;
		}
		else if((this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_ASIAN_HANDICAP) ||
				(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_GAME_HANDICAP) ||
				(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_SET_HANDICAP)
				){
				//this.setOutcomeType('1','H','2');
				titleTmp = headTitle.HEADTITLE_ASIAN_HANDICAP;
		}
		else if((this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_OVER_UNDER)
				){
				//this.setOutcomeType('OVER',' ','UNDER');
				titleTmp = headTitle.HEADTITLE_OVER_UNDER;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_ODD_OR_EVEN){
				//this.setOutcomeType('ODD',' ','EVEN');
				titleTmp = headTitle.HEADTITLE_ODD_OR_EVEN;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_DOUBLE_CHANCE){
				//this.setOutcomeType('ODD',' ','EVEN');
				titleTmp = headTitle.HEADTITLE_DOUBLE_CHANCE;
		}
		//outrights		
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_TOP_X){
				titleTmp = headTitle.getHEADTITLE_TOP_X_withParam(this.defaultOutcomeType.scopeId);
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_WINNER){
				titleTmp = headTitle.HEADTITLE_WINNER;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_TOP_GOALSCORER){
				titleTmp = headTitle.HEADTITLE_TOP_GOALSCORER;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_RELEGATION){
				titleTmp = headTitle.HEADTITLE_RELEGATION;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_PROMOTION){
				titleTmp = headTitle.HEADTITLE_PROMOTION;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_ROCK_BOTTOM){
				titleTmp = headTitle.HEADTITLE_ROCK_BOTTOM;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_POLE_POSITION){
				titleTmp = headTitle.HEADTITLE_POLE_POSITION;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_FASTEST_LAP){
				titleTmp = headTitle.HEADTITLE_FASTEST_LAP;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_FIRST_TO_RETIRE){
				titleTmp = headTitle.HEADTITLE_FIRST_TO_RETIRE;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_FIRST_LAP_LEADER){
				titleTmp = headTitle.HEADTITLE_FIRST_LAP_LEADER;
		}
		/*else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_TIME_OF_NEXT_GOAL){
				//this.setOutcomeType(' ','TIME',' ');
				titleTmp = headTitle.HEADTITLE_HOME_NEXT_GOAL;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_TIME_OF_NEXT_GOAL){
				//this.setOutcomeType('-1','TYPE_ID_CORRECT_SCORE_WITH_SCOPE',' ');
				titleTmp = headTitle.HEADTITLE_HOME_DRAW_AWAY_WITH_HANDICAP;
		}*/
		else {
			//this.setOutcomeType('','','');
			titleTmp = headTitle.HEADTITLE_OTHER;
		}
		this.setOutcomeType(titleTmp.homeText,titleTmp.drawText,titleTmp.awayText);

		var extraCell=new Element('td',{'class': 'expandable'}); // this is for the +NoOutcomeTypes in the match rows
		extraCell.setStyle('border-bottom','0px');
		var divCell=new Element('div',{'id':'MarketH1'});
		var hideImage = new Element('img',{'id':'img'+imgId,'name':imgId,'src':staticServer+'/jsp/oddsmatrix/'+operName+'/style/ajax-loader.gif','style':'display: none'});
		//extraCell.setText('aaaa ');
		hideImage.setStyle('display','none');//alert(hideImage.outerHTML);
		hideImage.injectInside(divCell);
		divCell.injectInside(extraCell);//		alert(extraCell.innerHTML);
		extraCell.injectInside(this.elementLine);
	},
	showDefaultOutcomeTypeDetail: function(imgId){
		if((this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_HOME_DRAW_AWAY	)||
			(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP)){
				var cellHome=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellHome.setText('1');
				var cellX=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellX.setText('X');
				var cellAway=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellAway.setText('2');
				cellHome.injectInside(this.elementLine);
				cellX.injectInside(this.elementLine);
				cellAway.injectInside(this.elementLine);
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW){
				var cellHome=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellHome.setText('1');
				var cellX=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellX.setText(' ');
				var cellAway=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellAway.setText('2');
				cellHome.injectInside(this.elementLine);
				cellX.injectInside(this.elementLine);
				cellAway.injectInside(this.elementLine);
		}
		else if((this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_ASIAN_HANDICAP) ||
				(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_GAME_HANDICAP) || 
				(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_SET_HANDICAP)
				){
				var cellHome=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellHome.setText('1');
				var cellX=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellX.setText('H');
				var cellAway=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellAway.setText('2');
				cellHome.injectInside(this.elementLine);
				cellX.injectInside(this.elementLine);
				cellAway.injectInside(this.elementLine);
		}
		else if((this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_OVER_UNDER)
				){
				var cellHome=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellHome.setText(nameOfOver);
				var cellX=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellX.setText(' ');
				var cellAway=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellAway.setText(nameOfUnder);
				cellHome.injectInside(this.elementLine);
				cellX.injectInside(this.elementLine);
				cellAway.injectInside(this.elementLine);
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_ODD_OR_EVEN){
				var cellHome=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellHome.setText(nameOfOdd);
				var cellX=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellX.setText(' ');
				var cellAway=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellAway.setText(nameOfEven);
		        cellHome.injectInside(this.elementLine);
				cellX.injectInside(this.elementLine);
				cellAway.injectInside(this.elementLine);
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_TIME_OF_NEXT_GOAL){
				var cellHome=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellHome.setText(' ');
				var cellX=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellX.setText('TIME');
				var cellAway=new Element('td',{'class': 'outcomeName','colspan': '2'});
				cellAway.setText(' ');
				cellHome.injectInside(this.elementLine);
				cellX.injectInside(this.elementLine);
				cellAway.injectInside(this.elementLine);
		}
		else {
			var cellHome=new Element('td',{'class': 'outcomeName','colspan': '2'});
			cellHome.setText(' ');
			var cellX=new Element('td',{'class': 'outcomeName','colspan': '2'});
			cellX.setText(' ');
			var cellAway=new Element('td',{'class': 'outcomeName','colspan': '2'});
			cellAway.setText(' ');
			cellHome.injectInside(this.elementLine);
			cellX.injectInside(this.elementLine);
			cellAway.injectInside(this.elementLine);
		}

		var extraCell=new Element('td'); // this is for the +NoOutcomeTypes in the match rows
		var hideImage = new Element('img',{'id':'img'+imgId,'name':imgId,'src':staticServer+'http://imgprod.oddsmatrix.com/pics/ajax-loader.gif','style':'display: none'});
		//extraCell.setText('aaaa ');
		//hideImage.setProperty('id',imgId);//alert(hideImage.outerHTML);
		hideImage.injectInside(extraCell);//		alert(extraCell.innerHTML);
		extraCell.injectInside(this.elementLine);
	},
	prepareForDump: function(imgId){
		var matches=this.matches.values();
		for(var i=0;i<matches.length;i++){
			var match=matches[i];
			match.prepareForDump(imgId);
		}
	}
});

var Match = CategElement.extend ({
	initialize: function(id,imgId){
		this.id=id;
		this.name='';
		this.date='aa';
		this.elementLine=new Element('tr',{'class': 'matchLine'});
		this.elementCell=new Element('td',{'class': 'invisibleHolder'});
		//this.elementCell.injectInside(this.elementLine);
		this.elementLine.injectInside(topTableBody);

		this.betTypes=new Array();
		this.homeParticipantName='';
		this.awayParticipantName='';
		this.numberOfOutrights=0;
		this.rowCount = 0;// flag the bettyperow to get the next row
		this.expanded=false;
		this.maxRisk=1000;
	},
	addBetType: function(betType){
		var betTypeExists=-1;
		for(var i=0;i<this.betTypes.length;i++){
			if($defined(this.betTypes[i])){
				if(i==betType.typeId){
					betTypeExists=1;
					break;
				}
			}
		}
		if(betTypeExists==1)
			this.betTypes[betType.typeId][betType.scopeId]=betType;
		else{
			this.betTypes[betType.typeId]=new Array();
			this.betTypes[betType.typeId][betType.scopeId]=betType;
		}
		betType.setMatch(this);
	},
	setHomeParticipantName: function(participantName){
		this.homeParticipantName=participantName;
	},
	setAwayParticipantName: function(participantName){
		this.awayParticipantName=participantName;
	},
	setTournament: function(tournament){
		this.tournament=tournament;
	},
	setNumberOfOutrights: function(numberOfOutrights){
		this.numberOfOutrights=numberOfOutrights;
	},
	setMatchRisk:function(risk){
		this.maxRisk = risk;
	},
	showDefaultOutcomeType: function(outcomeType,imgId){
		var otherOutrights =0;
		if($defined(this.betTypes[outcomeType.betTypeId]) && $defined(this.betTypes[outcomeType.betTypeId][outcomeType.scopeId]))
		{
			otherOutrights = parseInt(this.numberOfOutrights)-1;
			this.betTypes[outcomeType.betTypeId][outcomeType.scopeId].showDefaultBetTypeForMatch(this.elementLine);
		}
		else{//alert('8899');
		  if (isShowEmptyOddsMatch){
		  	otherOutrights = parseInt(this.numberOfOutrights);
			var cell1=new Element('td',{'colspan': '1','class':'oddsCell'});
			var cell2=new Element('td',{'colspan': '1','class':'oddsCell'});
			var cell3=new Element('td',{'colspan': '1','class':'oddsCell'});
			cell1.setHTML('&nbsp;');cell2.setHTML('&nbsp;');cell3.setHTML('&nbsp;');
			cell1.injectInside(this.elementLine);cell2.injectInside(this.elementLine);cell3.injectInside(this.elementLine);
		  }else{
		  	this.elementLine.remove();
		  	return;
		  }

			/*
			*/
		}
		//alert("==" + imgId);

		var extraCell=new Element('td',{'class': 'expandable'}); // this is for the +NoOutcomeTypes

		if(otherOutrights>0){
			extraCell.addEvent('click',function(){
				if(this.expanded){
					this.expanded=false;
					var betTypeRows=topTableBody.childNodes;
					var nrRows=betTypeRows.length;
					for(var i=0;i<nrRows;i++){
						//if($defined(betTypeRows[i]) && betTypeRows[i]!=this.elementLine && !betTypeRows[i].hasClass('matchLine')&& !betTypeRows[i].hasClass('titleLine')){
						if($defined(betTypeRows[i]) && betTypeRows[i]!=this.elementLine && !betTypeRows[i].hasClass('matchLine')&& !betTypeRows[i].hasClass('titleLine')&& betTypeRows[i].hasClass(this.id)){
							betTypeRows[i].remove();
							i--;
						}
					}
					extraCell.setHTML('+'+otherOutrights);
				} else {
					var imgObj = $(imgId);
					imgObj.style.display="block";
					this.expanded=true;
					currentExpandedMatch=this;
					//extraCell.setHTML('<span style="ygtvloading">&nbsp;</span>');			alert('');
					expandMatch(this.disciplineId,imgObj);
					extraCell.setHTML('-'+otherOutrights+'');
					//imgObj.style.display="none";
				}
			}.bind(this));
			extraCell.setHTML('+'+otherOutrights+'');
		} else {
			extraCell.setHTML('&nbsp;');
		}
		extraCell.injectInside(this.elementLine);
	},
	prepareForDump: function(imgId){
		/*var hTable=new Element('table',{'class':'matchInfo','width':'100%','border':'0'});
		var hBody=new Element('tbody');
		var hRow=new Element('tr');
		var img = new Element('img',{'src':'/jsp/oddsmatrix/'+operName+'/style/CalendarIcon.gif',
		'class':'DateIcon'});*/

		var divId = 'MarketR1';

		var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

		var dateCell=''+
		(this.date.getDate()<10?'0'+this.date.getDate():this.date.getDate())+'.'+m_names[this.date.getMonth()];
		if (operName =='NoIQ'){
			dateTimeLine = "<br>";
		}else{
			dateTimeLine = " ";
		}
		var hourCell=new Element('td',{'class': 'hourWidth','colspan':'2'});
		hourCell.setHTML(dateCell+dateTimeLine+(this.date.getHours()<10?'0'+this.date.getHours():this.date.getHours())+':'
		+(this.date.getMinutes()<10?'0'+this.date.getMinutes():this.date.getMinutes()));

		var homeCell=new Element('td',{'class': 'teamWidth'});
		homeCell.setStyle("padding-left","5px");
		homeCell.setHTML(this.homeParticipantName);
		var awayCell=new Element('td',{'class': 'teamWidth'});
		awayCell.setText(this.awayParticipantName);


		hourCell.injectInside(this.elementLine);
		homeCell.injectInside(this.elementLine);
		awayCell.injectInside(this.elementLine);
		/*dateCell.setStyle('border-bottom','0px');
		hourCell.setStyle('border-bottom','0px');
		homeCell.setStyle('border-bottom','0px');
		awayCell.setStyle('border-bottom','0px');


		dateCell.injectInside(hRow);
		hourCell.injectInside(hRow);
		homeCell.injectInside(hRow);
		awayCell.injectInside(hRow);


		hRow.injectInside(hBody);
		hBody.injectInside(hTable);
		hTable.injectInside(this.elementCell);*/

		if(this.showDefaultBetType())
			this.showDefaultOutcomeType(this.tournament.defaultOutcomeType,imgId);

	},
	setDate: function(date){
		this.date=util.getDateFromJavaString(date);
	},
	setName: function(name){
		this.name=name;
	},
	setDisciplineId: function(id){
		this.disciplineId=id;
	},
	setHomeParticipantId: function(hpid){
		this.homeParticipantId=hpid;
	},
	setAwayParticipantId: function(apid){
		this.awayParticipantId=apid;
	},
	addToBetSlip: function(outcomeId,oddsValue,formattedValue,type,betTypeName,participantName){
		addNewBet(this.id, outcomeId,oddsValue.toFixed(2),formattedValue,this.name,type,'0.0',(this.date.getDate()<10?'0'+this.date.getDate():this.date.getDate())+'.'+(this.date.getMonth()<9?'0'+(this.date.getMonth()+1):(this.date.getMonth()+1))+'.'+this.date.getFullYear().toString().substring(2)+' '+(this.date.getHours()<10?'0'+this.date.getHours():this.date.getHours())+':'+(this.date.getMinutes()<10?'0'+this.date.getMinutes():this.date.getMinutes()),participantName,this.maxRisk,betTypeName,this.tournament.name);
	},
	expandFully: function(){

		var rowIndex = this.elementLine.rowIndex ;
		var nextRow = this.elementLine.parentNode.rows[rowIndex+ this.rowCount + 1];

		var betTypes=[];
		for(var i=0;i<this.betTypes.length;i++){
			if($defined(this.betTypes[i])){
				for(var j=0;j<this.betTypes[i].length;j++){
					if($defined(this.betTypes[i][j])){
						betTypes.push(this.betTypes[i][j]);}
				}
			}
		}
		//sort the bettpyes according the letter, if cancel the next row , it will sort according to the typeId
		betTypes.sort(this.sortExpandBetTypes);
		for(var i=0;i<betTypes.length;i++){
			var betType=betTypes[betTypes.length - 1 - i];
			betType.insertIntoDOM(nextRow);
		}
	},
	sortExpandBetTypes: function(a,b){
		var aname = a.name;
		var bname = b.name;
		//if(aname>=bname)return 1;
		//if(aname<bname)return -1;
		//order desc
		if(aname>=bname)return -1;
		if(aname<bname)return 1;
	},
	showDefaultBetType: function(){

		if(betTypeIdShown!=-1 && scopeIdShown!=-1){
			if($defined(this.betTypes[betTypeIdShown])){
				if($defined(this.betTypes[betTypeIdShown][scopeIdShown]))
					return true;
			}
			else
				return false;
		}
		var rez=false;
/*		switch(this.disciplineId){
			case disciplineIds.SOCCER:
				if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.CRICKET:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.ICEHOCKEY:
				if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.BASKETBALL:
				if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId][outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.TENNIS:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.SNOOKER:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.FIGHTING:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.RUGBY_UNION:
				if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.RUGBY_LEAGUE:
				if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.BASEBALL:
				if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId][outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.AM_FOOTBALL:
				if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId][outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.DARTS:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.GAELIC_FOOTBALL:
				if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.HANDBALL:
				if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.VOLLEYBALL:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;

			case disciplineIds.BEACH_FOOTBALL:
				if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
		}
*/		rez = true;// for temporary test
		return rez;
	}
});
var BetType = CategElement.extend ({
	initialize: function(typeId,scopeId){
		this.typeId=typeId;
		this.scopeId=scopeId;
		this.odds=new Hash();
		this.extraOutcomeInfo=new Hash();
	},
	addOdds: function(doubleParameter,odds,integerParameter,match){
	//--------wolf modify-------------------------------------------
		if(this.typeId==betTypes.TYPE_ID_ASIAN_HANDICAP ||this.typeId==betTypes.TYPE_ID_GAME_HANDICAP ||this.typeId==betTypes.TYPE_ID_SET_HANDICAP  ){
			if(integerParameter==match.awayParticipantId){
				if(doubleParameter>0){
					doubleParameter = -doubleParameter;
				}
				else
					doubleParameter = Math.abs(doubleParameter);
			}
		}

		if(this.typeId==betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP)
		{
			if(integerParameter==match.awayParticipantId){
				doubleParameter=-doubleParameter;
			}
		}

		doubleParameter =doubleParameter+'';
		if(this.odds.hasKey(doubleParameter)){
			var parameterOdds=this.odds.get(doubleParameter);
			parameterOdds.set(odds.id,odds);
		} else {
			var parameterOdds=new Hash();
			parameterOdds.set(odds.id,odds);
			this.odds.set(doubleParameter,parameterOdds);
		}
	},
	setMatch: function(match){
		this.match=match;
	},
	addExtraOutcomeInfo: function(outcomeId,ip,ip2,ip3,dp,dp2,rId){
		var outcomeInfo=new OutcomeInfo();
		outcomeInfo.integerParameter=ip;
		outcomeInfo.integerParameter2=ip2;
		outcomeInfo.integerParameter3=ip3;
		outcomeInfo.doubleParameter=dp;
		outcomeInfo.doubleParameter2=dp2;
		outcomeInfo.resultId=rId;
		this.extraOutcomeInfo.set(outcomeId,outcomeInfo);
	},
	setParameters: function(ip,ip2,ip3,dp,dp2){
		this.integerParameter=ip;
		this.integerParameter2=ip2;
		this.integerParameter3=ip3;
		this.doubleParameter=dp;
		this.doubleParameter2=dp2;
	},
	setName: function(name){
		this.name=name;
	},
	showDefaultBetTypeForMatch: function(parentNode){
		this.appendOddsToTheRow(parentNode);
	},
	insertIntoDOM: function(parentNode){
		if($defined(this.isExpanded)){
			for(var i=0;i<this.betTypeRows.length;i++){
				this.betTypeRows[i].remove;
				this.betTypeRows[i]=null;
			}
			this.betTypeRows=null;
		}
		this.betTypeRows=[];
		this.appendOddsToTheRow(null);
		
		var tmpNode = parentNode;
		var newTr = new Element("tr",{"style":"height:0px"});
		newTr.injectBefore(tmpNode);
		for(var i=0 ;i<this.betTypeRows.length ;i++){//alert(this.betTypeRows[i].innerHTML);
		// ---modify by Grace --date:01/19/09
		   /*var extraCell=new Element('td',{'class': 'expandable'});
		   extraCell.setHTML("&nbsp;");
		   extraCell.injectInside(this.betTypeRows[i]);*/
            var rows = this.betTypeRows[i];
            //var cellCt = rows.cells.length;
            var isTitle = false;
            if(rows.innerHTML.indexOf('MarketH2') > 0) isTitle=true ; else  isTitle=false;

            if (!isTitle){//(!(cellCt==1 || cellCt == 5)){
            	if (isExpend){
					var extraCell =new Element('td',{'class':'expandable'});
					extraCell.setHTML('<div id="MarketR2">&nbsp;</div>');
					extraCell.injectInside(this.betTypeRows[i]);
				}
            }

		   	this.betTypeRows[i].injectAfter(newTr);
		   newTr = newTr.getNext();
		}
	},
	makeNameCell: function(date,hour,homeParticipantName,awayParticipantName,clone){
		if($defined(this.match.nameCellStandard) && clone)
			return this.match.nameCellStandard.clone(true);
		if(isExpend)
			var nameCell=new Element('tr',{'class':this.match.id,"id":"R2"});
		else
			var nameCell=new Element('tr',{"id":"R2"});
		//var dateCell=new Element('td',{'class':'dateWidth'});
		//dateCell.setHTML('<div id="MarketR2"><div>' + date+'</div></div>');//+dateCell.innerHTML

		var hourCell=new Element('td',{'class':'hourWidth','colspan':'2'});
		hourCell.setHTML('<div id="MarketR2"><div>' +date + dateTimeLine +hour+'</div></div>');

		/*var hourCell=new Element('td',{'class': 'hourWidth'});
		hourCell.setHTML('<div id="MarketR2">' +hour+'</div>');*/

		var team1Cell=new Element('td',{'class': 'teamWidth'});
		team1Cell.setHTML('<div id="MarketR2"><div style="padding-left:5px">'+ homeParticipantName+'</div></div>');
		var team2Cell=new Element('td',{'class': 'teamWidth'});
		team2Cell.setHTML('<div id="MarketR2"><div>'+ awayParticipantName+'</div></div>');


		//dateCell.injectInside(nameCell);
		hourCell.injectInside(nameCell);
		team1Cell.injectInside(nameCell);
		team2Cell.injectInside(nameCell);

		/*img.injectInside(div);
		dateDiv.injectInside(div);
		div.injectInside(dateCell);*/
		/*
		dateCell.setStyle('border-bottom','0px');
		hourCell.setStyle('border-bottom','0px');
		team1Cell.setStyle('border-bottom','0px');
		team2Cell.setStyle('border-bottom','0px');

		dateCell.injectInside(row);
		hourCell.injectInside(row);
		team1Cell.injectInside(row);
		team2Cell.injectInside(row);
		row.injectInside(tbody);
		tbody.injectInside(table);*/
		//table.injectInside(nameCell);
		if(clone)
			this.match.nameCellStandard=nameCell;
		return nameCell;
	},
	handicapCell: function(date,hour,homeParticipantName,awayParticipantName,clone){
		var nameCell=null;
		if (isExpend){
			nameCell = new Element('tr',{'id':'R2','class':this.match.id});
		}else{
			nameCell = new Element('tr',{'class':'matchLine'});
		}
		/*var table=new Element('table',{'width': '100%'});
		var tbody=new Element('tbody');
		var row=new Element('tr');

		var img = new Element('img',{'src':'/jsp/oddsmatrix/betonbet/templates/betonbet/CalendarIcon.gif','class':'DateIcon'});*/
		var divId='MarketR1';
		if (handicap1X2hasNext){
		   divId = 'MarketR0';
	    }

		var dateCell=new Element('td',{'class':'dateWidth'});
//		dateCell.setHTML('<div id="'+divId+'"><image src="/jsp/oddsmatrix/betonbet/templates/betonbet/CalendarIcon.gif" ' +' class="DateIcon">' +'<span>'+date +'</span></div>');
		//img.injectInside(dateCell);
		dateCell.setHTML(this.addCssToTeam(date));
		var hourCell=new Element('td',{'class': 'hourWidth','colspan':'2'});
		hourCell.setHTML(this.addCssToTeam(date + dateTimeLine + hour));

		var team1Cell=new Element('td',{'class': 'teamWidth'});
		//team1Cell.setStyle("padding-left","5px");//team1Cell.setHTML('<div id="MarketR2"><div style="padding-left:5px">'+ homeParticipantName+'</div></div>');

		team1Cell.setHTML(this.addCssToTeam1(homeParticipantName));
		var team2Cell=new Element('td',{'class': 'teamWidth'});
		team2Cell.setHTML(this.addCssToTeam(awayParticipantName));

		//dateCell.injectInside(nameCell);
		hourCell.injectInside(nameCell);
		team1Cell.injectInside(nameCell);
		team2Cell.injectInside(nameCell);

		/*dateCell.injectInside(row);
		hourCell.injectInside(row);
		team1Cell.injectInside(row);
		team2Cell.injectInside(row);
		row.injectInside(tbody);
		tbody.injectInside(table);
		table.injectInside(nameCell);*/
//		if(clone)
//			this.match.nameCellStandard=nameCell;
		return nameCell;
	},

	sortCorrectScoreText: function(a,b){
		var aInf=a.split('-');
		var adP=parseFloat(aInf[0]);var adP2=parseFloat(aInf[1]);
		var bInf=b.split('-');
		var bdP=parseFloat(bInf[0]);var bdP2=parseFloat(bInf[1]);
		return this.CSSorter(adP,adP2,bdP,bdP2);
	} ,
	sortCorrectScore: function(a,b){
		var aInf=this.extraOutcomeInfo.get(a.id);
		var aintParam=aInf.integerParameter;
		var adP=aInf.doubleParameter;
		var adP2=aInf.doubleParameter2;
		if(aintParam==this.match.awayParticipantId)
		{
			adP=aInf.doubleParameter2;
			adP2=aInf.doubleParameter;
		}
		var bInf=this.extraOutcomeInfo.get(b.id);
		var bintParam=aInf.integerParameter;
		var bdP=bInf.doubleParameter;
		var bdP2=bInf.doubleParameter2;
		if(bintParam==this.match.awayParticipantId)
		{
			bdP=bInf.doubleParameter2;
			bdP2=bInf.doubleParameter;
		}
		return this.CSSorter(adP,adP2,bdP,bdP2);
	},
	CSSorter: function(adP,adP2,bdP,bdP2){
		if(this.csSortType==2){
			if(adP+adP2<bdP+bdP2)
				return -1;
			if(adP+adP2==bdP+bdP2)
				return 0;
			if(adP+adP2>bdP+bdP2)
				return 1;
		}
		if(this.csSortType==1){
			if(adP<bdP)
				return -1;
			if(adP>bdP)
				return 1;
			if(adP==bdP){
				if(adP+adP2<bdP+bdP2)
					return -1;
				if(adP+adP2==bdP+bdP2)
					return 0;
				if(adP+adP2>bdP+bdP2)
					return 1;
			}
		}
		if(this.csSortType==3){
			if(adP2<bdP2)
				return -1;
			if(adP2>bdP2)
				return 1;
			if(adP2==bdP2){
				if(adP+adP2<bdP+bdP2)
					return -1;
				if(adP+adP2==bdP+bdP2)
					return 0;
				if(adP+adP2>bdP+bdP2)
					return 1;
			}
		}
	},
	//------wolf add sort for nubmer of goals------
	getGoalsText: function (parms)	{

		var adP;var adP2;
		var parm = parms.toString();
		if(parm.indexOf(' or less')>0)
		{
			adP=longNULL;
			adP2 = parm.substring(0,parm.indexOf(' or less'));
		}
		else if(parm.indexOf(' or more')>=0)
		{
			adP2=longNULL;
			adP = parm.substring(0,parm.indexOf(' or more'));
		}
		else if(parm.indexOf(' to ')>=0 )
		{
			parm = parm.substring(0,parm.indexOf(' goal'));
			var aInf=parm.split(' to ');
			adP=parseFloat(aInf[0]);adP2=parseFloat(aInf[1]);
		}
		else{
			parm = parm.substring(0,parm.indexOf(' goal'));
			adP = parm; adP2 = parm;
		}

		return adP+'@'+adP2;
	},
	sortNubmerofGoalsText: function(a,b){

		var adP;var adP2;var bdP;var bdP2;
		var adPs = this.getGoalsText(a).split('@');
		var bdPs = this.getGoalsText(b).split('@');
		adP = parseFloat(adPs[0]);adP2 = parseFloat(adPs[1]);
		bdP = parseFloat(bdPs[0]);bdP2 = parseFloat(bdPs[1]);

		return this.NOGSorter(adP,adP2,bdP,bdP2);
	} ,
	sortNubmerofGoals: function(a,b){
		var aInf=this.extraOutcomeInfo.get(a.id);
		var adP=aInf.integerParameter;
		var adP2=aInf.integerParameter2;
		var bInf=this.extraOutcomeInfo.get(b.id);
		var bdP=bInf.integerParameter;
		var bdP2=bInf.integerParameter2;
		return this.NOGSorter(adP,adP2,bdP,bdP2);
	},
	NOGSorter: function(adP,adP2,bdP,bdP2){
		if(adP==longNULL)
		{
			adP=adP2; adP2=-99;
		}
		if(bdP==longNULL)
		{
			bdP=bdP2; bdP2=-99;
		}
		if(adP2==longNULL) adP2=99;
		if(bdP2==longNULL) bdP2=99;
			if(adP<bdP)
				return -1;
			if(adP>bdP)
				return 1;
			if(adP==bdP){
				if(adP2<bdP2)
					return -1;
				if(adP2>bdP2)
					return 1;
			}
	},
	sortOutrights:function(array) {
			return array.sort( function(x, y) {
					if(x[1].value==1) return 1;
					if(y[1].value==1) return -1;
					return x[1].value - y[1].value; })
	},
/*	//------------sort overunder---------------
	sortOverUnderText: function(a,b){
		return this.OUSorter(a,b);
	} ,
	sortOverUnder: function(a,b){
		var aInf=this.extraOutcomeInfo.get(a.id);
		var adP=aInf.doubleParameter;
		var bInf=this.extraOutcomeInfo.get(b.id);
		var bdP=bInf.doubleParameter;
		return this.OUSorter(adP,bdP);
	},
	OUSorter: function(adP,bdP){
			if(adP<bdP)
				return -1;
			if(adP>bdP)
				return 1;
			if(adP==bdP)
				return 0;
	},
*/
	sortAsianHandicap: function(a,b){
		var aFloat = parseFloat(a);
		var bFloat = parseFloat(b);
		if(aFloat==bFloat) return 0;
		if(aFloat>bFloat) return 1;
		if(aFloat<bFloat) return -1;
	},

	addStyle:function(text){
		return '<div id="MarketH2"><div id="GameHeadline1X2"><p>'+text+'</p></div></div>';
	},

	appendOddsToTheRow: function(parentRow){//	alert(this.typeId);alert(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW);
		/* this is not what stian wanted
		if(betTypeIdShown!=-1 && scopeIdShown!=-1){
			if(this.typeId!=betTypeIdShown || this.scopeId!=scopeIdShown){
				return;
			}
		}
		*/
//alert('the third step '+ this.name);
		if (this.typeId==8){
			//alert('999');
		}
		// the condition below is needed in order to remove bettypes from showing when expanding this.typeId == betTypes.TYPE_ID_DOUBLE_CHANCE ||
		if(parentRow==null && (this.typeId == betTypes.TYPE_ID_TIME_OF_NEXT_GOAL || this.typeId == betTypes.TYPE_ID_NEXT_TEAM_TO_SCORE)){
			return;
		}
		// we do not want to show the default bettype for the match that is already shown in the match row
		if(parentRow==null && this.typeId == this.match.tournament.defaultOutcomeType.betTypeId && this.scopeId == this.match.tournament.defaultOutcomeType.scopeId){
			return;
		}
		if(parentRow==null){
			if(isExpend)
				var betTypeHeader = new Element('tr',{'class':this.match.id});
			else
				var betTypeHeader=new Element('tr');
			//betTypeHeader.setStyle('border-bottom','0px');
			var cellHeader=new Element('td',{'colspan':'4'});
			cellHeader.injectInside(betTypeHeader);
			cellHeader.setHTML('<div id="MarketH2"><div id="GameHeadline"><p>'+this.name+'</p></div></div>');
			if(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE==this.typeId ){
				cellHeader.setProperty('colspan','8');
			} else {
				var homeCell =new Element('td',{'colspan': '1','class':'oddsCell','align': 'center'});
				var drawCell =new Element('td',{'colspan': '1','class':'oddsCell','align': 'center'});
				var awayCell =new Element('td',{'colspan': '1','class':'oddsCell','align': 'center'});
				var titleTmp = headTitle.HEADTITLE_OTHER;
				if(betTypes.TYPE_ID_HOME_DRAW_AWAY==this.typeId ||
					   betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP==this.typeId){
					titleTmp = headTitle.HEADTITLE_HOME_DRAW_AWAY;
				}else
					if(betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId ){
						titleTmp = headTitle.HEADTITLE_ODD_OR_EVEN;
					}else
					if(betTypes.TYPE_ID_OVER_UNDER==this.typeId ){
						titleTmp = headTitle.HEADTITLE_OVER_UNDER;
					}else
					if(betTypes.TYPE_ID_ASIAN_HANDICAP==this.typeId ||
					   betTypes.TYPE_ID_GAME_HANDICAP==this.typeId ||
					   betTypes.TYPE_ID_SET_HANDICAP==this.typeId
						){
						titleTmp = headTitle.HEADTITLE_ASIAN_HANDICAP;
					}else
					if(betTypes.TYPE_ID_DOUBLE_CHANCE==this.typeId
						){
						titleTmp = headTitle.HEADTITLE_DOUBLE_CHANCE;
					}
					else if(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW==this.typeId){				
						titleTmp = headTitle.HEADTITLE_HOME_AWAY_WITH_IMPOSSIBLE_DRAW;
					}
					//outrights
					else if(betTypes.TYPE_ID_TOP_X==this.typeId){				
						titleTmp = headTitle.getHEADTITLE_TOP_X_withParam(this.scopeId);
					}
					else if(this.typeId==betTypes.TYPE_ID_WINNER){
							titleTmp = headTitle.HEADTITLE_WINNER;
					}
					else if(this.typeId==betTypes.TYPE_ID_TOP_GOALSCORER){
							titleTmp = headTitle.HEADTITLE_TOP_GOALSCORER;
					}
					else if(this.typeId==betTypes.TYPE_ID_RELEGATION){
							titleTmp = headTitle.HEADTITLE_RELEGATION;
					}
					else if(this.typeId==betTypes.TYPE_ID_PROMOTION){
							titleTmp = headTitle.HEADTITLE_PROMOTION;
					}
					else if(this.typeId==betTypes.TYPE_ID_ROCK_BOTTOM){
							titleTmp = headTitle.HEADTITLE_ROCK_BOTTOM;
					}
					else if(this.typeId==betTypes.TYPE_ID_POLE_POSITION){
							titleTmp = headTitle.HEADTITLE_POLE_POSITION;
					}
					else if(this.typeId==betTypes.TYPE_ID_FASTEST_LAP){
							titleTmp = headTitle.HEADTITLE_FASTEST_LAP;
					}
					else if(this.typeId==betTypes.TYPE_ID_FIRST_TO_RETIRE){
							titleTmp = headTitle.HEADTITLE_FIRST_TO_RETIRE;
					}
					else if(this.typeId==betTypes.TYPE_ID_FIRST_LAP_LEADER){
							titleTmp = headTitle.HEADTITLE_FIRST_LAP_LEADER;
					}

				homeCell.setHTML(this.addStyle(titleTmp.homeText));
				drawCell.setHTML(this.addStyle(titleTmp.drawText));
				awayCell.setHTML(this.addStyle(titleTmp.awayText));
				homeCell.injectInside(betTypeHeader);
				drawCell.injectInside(betTypeHeader);
				awayCell.injectInside(betTypeHeader);
				if (isExpend){
					var extraCell =new Element('td',{'class':'expandable'});
					extraCell.setHTML('<div id="MarketH2">&nbsp;</div>');
					extraCell.injectInside(betTypeHeader);
				}
				/*for(var i=0;i<3;i++){
					var cellHeaderTitle=new Element('td',{'colspan': '1','class':'oddsCell','align': 'center'});

					//BetTypeHeadTitle headTitle = new BetTypeHeadTitle(0,'<tc:string code=/>');
					cellHeaderTitle.injectInside(betTypeHeader);

					if(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW==this.typeId){
						if(i==0)
							cellHeaderTitle.setHTML(this.addStyle('1'));
						if(i==1)
							cellHeaderTitle.setHTML(this.addStyle(' '));
						if(i==2)
							cellHeaderTitle.setHTML(this.addStyle('2'));
					}else
					if(betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId ){
						if(i==0)
							cellHeaderTitle.setHTML(this.addStyle('ODD'));
						if(i==1)
							cellHeaderTitle.setHTML(this.addStyle(' '));
						if(i==2)
							cellHeaderTitle.setHTML(this.addStyle('EVEN'));
					}else
					if(betTypes.TYPE_ID_OVER_UNDER==this.typeId ){
						if(i==0)
							cellHeaderTitle.setHTML(this.addStyle('OVER'));
						if(i==1)
							cellHeaderTitle.setHTML(this.addStyle(' '));
						if(i==2)
							cellHeaderTitle.setHTML(this.addStyle('UNDER'));
					}else
					if(betTypes.TYPE_ID_ASIAN_HANDICAP==this.typeId ||
					   betTypes.TYPE_ID_GAME_HANDICAP==this.typeId
						){
						if(i==0)
							cellHeaderTitle.setHTML(this.addStyle('1'));
						if(i==1)
							cellHeaderTitle.setHTML(this.addStyle('H'));
						if(i==2)
							cellHeaderTitle.setHTML(this.addStyle('2'));
					}else{
						if(i==0)
							cellHeaderTitle.setHTML(this.addStyle(''));
						if(i==1)
							cellHeaderTitle.setHTML(this.addStyle(''));
						if(i==2)
							cellHeaderTitle.setHTML(this.addStyle(''));
					}
				}*/
			}

			this.betTypeRows.push(betTypeHeader);
		}
		var outcomeName=this.name;

		var homeParticipantName=this.match.homeParticipantName;
		var awayParticipantName=this.match.awayParticipantName;


		var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

		var dateText=''+
		(this.match.date.getDate()<10?'0'+this.match.date.getDate():this.match.date.getDate())+'.'+m_names[this.match.date.getMonth()];


		//var dateText=(this.match.date.getDate()<10?'0'+this.match.date.getDate():this.match.date.getDate())+'.'+(this.match.date.getMonth()<9?'0'+(this.match.date.getMonth()+1):(this.match.date.getMonth()+1))+'.'+this.match.date.getFullYear().toString().substring(2);
		var hourText=(this.match.date.getHours()<10?'0'+this.match.date.getHours():this.match.date.getHours())+':'+(this.match.date.getMinutes()<10?'0'+this.match.date.getMinutes():this.match.date.getMinutes());

		if(betTypes.TYPE_ID_HOME_DRAW_AWAY==this.typeId ){
				var nameCell=null;
				var betTypeRow=null;
				if(parentRow==null){
					//betTypeRow=new Element('tr');
					betTypeRow=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
					//nameCell.injectInside(betTypeRow);
					this.betTypeRows.push(betTypeRow);
				} else {
					betTypeRow = parentRow;
				}

				var oddsValues=this.odds.get(doubleNULL).values();
				//var homeOdds=oddsValues[0];
				//var drawOdds=oddsValues[1];
				//var awayOdds=oddsValues[2];
				var homeOdds=null;
				var drawOdds=null;
				var awayOdds=null;
				//if(parentRow==null){
					for(var i=0;i<oddsValues.length;i++){
						var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
						var intParam=extraInfo.integerParameter;
						var resultid = extraInfo.resultId;
						if(resultid==1&&intParam==this.match.homeParticipantId)
							homeOdds=oddsValues[i];
						if(resultid==1&&intParam==this.match.awayParticipantId)
							awayOdds=oddsValues[i];
						if(resultid==2&&intParam==longNULL)
							drawOdds=oddsValues[i];
					}
				//}
				var cellHome=new Element('td',{'class': 'oddsCell'});

				if($defined(homeOdds)){
					cellHome.setHTML(this.addDivToText_odds(homeOdds.formattedValue));
					var args=new Array(homeOdds.id , homeOdds.value,homeOdds.formattedValue,'home',''+outcomeName,homeParticipantName);
					cellHome.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cellHome.setHTML(this.addText_odds('&nbsp;'));
				}
				var cellX=new Element('td',{'class': 'oddsCell'});
				if($defined(drawOdds)){
					cellX.setHTML(this.addDivToText_odds(drawOdds.formattedValue));
					var args=new Array(drawOdds.id , drawOdds.value,drawOdds.formattedValue,nameOfDraw,''+outcomeName,nameOfDraw);
					cellX.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cellX.setHTML(this.addText_odds('&nbsp;'));
				}
				var cellAway=new Element('td',{'class': 'oddsCell'});
				if($defined(awayOdds)){
					cellAway.setHTML(this.addDivToText_odds(awayOdds.formattedValue));
					var args=new Array(awayOdds.id , awayOdds.value,awayOdds.formattedValue,'away',outcomeName,awayParticipantName);
					cellAway.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cellAway.setHTML(this.addText_odds('&nbsp;'));
				}
				cellHome.injectInside(betTypeRow);
				cellX.injectInside(betTypeRow);
				cellAway.injectInside(betTypeRow);
		}
		//outrights
		if(betTypes.TYPE_ID_TOP_X==this.typeId 
			|| betTypes.TYPE_ID_WINNER==this.typeId 
			|| betTypes.TYPE_ID_TOP_GOALSCORER==this.typeId 
			|| betTypes.TYPE_ID_RELEGATION==this.typeId 
			|| betTypes.TYPE_ID_PROMOTION==this.typeId 
			|| betTypes.TYPE_ID_ROCK_BOTTOM==this.typeId 
			|| betTypes.TYPE_ID_POLE_POSITION==this.typeId 
			|| betTypes.TYPE_ID_FASTEST_LAP==this.typeId 
			|| betTypes.TYPE_ID_FIRST_TO_RETIRE==this.typeId 
			|| betTypes.TYPE_ID_FIRST_LAP_LEADER==this.typeId 
			){
				var nameCell=null;
				var betTypeRow1=null;
				if(parentRow==null){
					betTypeRow1=this.makeNameCell(dateText,hourText,this.match.name+' '+this.name,'',false);
					this.betTypeRows.push(betTypeRow1);
				} else {
					betTypeRow1 = parentRow;
				}
				var oddsValues=[];
				var oddsValueNames=[];
				var tempArrayForSort=[];
				for(var i=0;i<this.odds.keys().length;i++){
					var ov=this.odds.get(this.odds.keys()[i]).values();
					for(var j=0;j<ov.length;j++){
						var extraInfo=this.extraOutcomeInfo.get(ov[j].id);
						var integerParameter2=extraInfo.integerParameter2;
						
						var temp = [];
						temp[0] = integerParameter2;
						temp[1] = ov[j];
						tempArrayForSort.push(temp);
					}
				}
				this.sortOutrights(tempArrayForSort);
				var divId='MarketR1';
				if (isExpend)divId='MarketR2';
				var lastRow = parentRow;//

				if (!isExpend)this.match.rowCount = tempArrayForSort.length - 1;	// For the expend row ,record the next row

				for(var j=0;j<tempArrayForSort.length;j++){
					var csRow=null;
					if(j==0){
						csRow=betTypeRow1;
					}else{
						if(parentRow==null){

							if (isExpend){
								csRow=new Element('tr',{'id':'R2','class':this.match.id});
							}else{
								csRow=new Element('tr');
							}
							this.betTypeRows.push(csRow);
							var emptyCell=new Element('td',{'colspan':'4'});
							emptyCell.setHTML('<div id="'+divId+'">&nbsp;</div>');
							emptyCell.injectInside(csRow);
						} else{
							if (isExpend){
								csRow=new Element('tr',{'id':'R2','class': 'matchLine'});
							}else{
								csRow=new Element('tr',{'class': 'matchLine'});
							}
							var emptyCell=new Element('td',{'colspan':'4','class': 'emptyTd'});
							emptyCell.setHTML('<div id="'+divId+'">&nbsp;</div>');
							emptyCell.injectInside(csRow);
							var tbody=parentRow.getParent();
							var matchRows=tbody.getElements('tr.matchLine');
							//csRow.injectAfter(matchRows[matchRows.length-1]);
							//var allRows = tbody.childNodes();//alert(allRows.length);
							csRow.injectAfter(lastRow);
							lastRow = csRow;
						}
					}

					var homeCell=new Element('td',{'class': 'oddsCell','colspan':'3'});
					if($defined(tempArrayForSort[j])){
						var valueHomeValue=tempArrayForSort[j][1].value;
						homeCell.setHTML(this.addDivToText_oddsOutrights(valueHomeValue,tempArrayForSort[j][1].formattedValue,tempArrayForSort[j][0]));
						var idHomeValue=tempArrayForSort[j][1].id;						
						var formattedValueHomeValue=tempArrayForSort[j][1].formattedValue;
						var args=new Array(idHomeValue , valueHomeValue,formattedValueHomeValue,'home',outcomeName,tempArrayForSort[j][0]);
						homeCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){
							//alert('id='+id+' value='+value+' formattedValue='+formattedValue+' typeOfBet='+typeOfBet+' outcomeName='+outcomeName+' param='+param)
							this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						homeCell.setHTML(this.addText_odds('&nbsp;'));
					}

					homeCell.injectInside(csRow);
					if(j!=0){
						var emptyCell=new Element('td',{'class': 'emptyTd'});
						emptyCell.injectInside(csRow);
					}
				}
		}
		if(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE==this.typeId){
				var nameCell=null;
				var betTypeRow1=null;
				if(parentRow==null){
					//betTypeRow1=new Element('tr');
					//nameCell=new Element('td',{'valign': 'top','align': 'center'});
					betTypeRow1=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
					//alert(betTypeRow1.innerHTML);
					//nameCell.injectInside(betTypeRow1);
					this.betTypeRows.push(betTypeRow1);
				} else {
					betTypeRow1 = parentRow;
				}
				var oddsValues=[];
				for(var i=0;i<this.odds.keys().length;i++){
					var ov=this.odds.get(this.odds.keys()[i]).values();
					for(var j=0;j<ov.length;j++){
						oddsValues.push(ov[j]);
					}
				}

				var homeValues=[];var homeScoreText=[];
				var drawValues=[];var drawScoreText=[];
				var awayValues=[];var awayScoreText=[];
				for(var i=0;i<oddsValues.length;i++){
					var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
					var intParam = extraInfo.integerParameter;
					var doubleParam=extraInfo.doubleParameter;
					var doubleParam2=extraInfo.doubleParameter2;

					if(intParam==this.match.homeParticipantId){
						if(doubleParam>doubleParam2){
							homeValues.push(oddsValues[i]);
							homeScoreText.push(doubleParam.toFixed(0)+'-'+doubleParam2.toFixed(0));
						}
						if(doubleParam==doubleParam2){
							drawValues.push(oddsValues[i]);
							drawScoreText.push(doubleParam.toFixed(0)+'-'+doubleParam2.toFixed(0));
						}
						if(doubleParam<doubleParam2){
							awayValues.push(oddsValues[i]);
							awayScoreText.push(doubleParam.toFixed(0)+'-'+doubleParam2.toFixed(0));
						}
					}
					if(intParam==this.match.awayParticipantId){
						if(doubleParam<doubleParam2){
							homeValues.push(oddsValues[i]);
							homeScoreText.push(doubleParam2.toFixed(0)+'-'+doubleParam.toFixed(0));
						}
						if(doubleParam==doubleParam2){
							drawValues.push(oddsValues[i]);
							drawScoreText.push(doubleParam.toFixed(0)+'-'+doubleParam2.toFixed(0));
						}
						if(doubleParam>doubleParam2){
							awayValues.push(oddsValues[i]);
							awayScoreText.push(doubleParam2.toFixed(0)+'-'+doubleParam.toFixed(0));
						}
					}
				}
				this.csSortType=1;

				homeValues.sort(this.sortCorrectScore.bind(this));
				homeScoreText.sort(this.sortCorrectScoreText.bind(this));
				this.csSortType=2;
				drawValues.sort(this.sortCorrectScore.bind(this));
				drawScoreText.sort(this.sortCorrectScoreText.bind(this));
				this.csSortType=3;
				awayValues.sort(this.sortCorrectScore.bind(this));
				awayScoreText.sort(this.sortCorrectScoreText.bind(this));
				var nrRows=homeValues.length;
				if(drawValues.length>nrRows)
					nrRows=drawValues.length;
				if(awayValues.length>nrRows)
					nrRows=awayValues.length;
				var divId='MarketR1';
				if (isExpend)divId='MarketR2';
				var lastRow = parentRow;//

				if (!isExpend)this.match.rowCount = nrRows - 1;	// For the expend row ,record the next row

				for(var j=0;j<nrRows;j++){
					var csRow=null;
					if(j==0){
						csRow=betTypeRow1;
					}else{
						if(parentRow==null){

							if (isExpend){
								csRow=new Element('tr',{'id':'R2','class':this.match.id});
							}else{
								csRow=new Element('tr');
							}
							this.betTypeRows.push(csRow);
							var emptyCell=new Element('td',{'colspan':'4'});
							emptyCell.setHTML('<div id="'+divId+'">&nbsp;</div>');
							emptyCell.injectInside(csRow);
						} else{
							if (isExpend){
								csRow=new Element('tr',{'id':'R2','class': 'matchLine'});
							}else{
								csRow=new Element('tr',{'class': 'matchLine'});
							}
							var emptyCell=new Element('td',{'colspan':'4','class': 'emptyTd'});
							emptyCell.setHTML('<div id="'+divId+'">&nbsp;</div>');
							emptyCell.injectInside(csRow);
							var tbody=parentRow.getParent();
							var matchRows=tbody.getElements('tr.matchLine');
							//csRow.injectAfter(matchRows[matchRows.length-1]);
							//var allRows = tbody.childNodes();//alert(allRows.length);
							csRow.injectAfter(lastRow);
							lastRow = csRow;
						}
					}

					var homeCell=new Element('td',{'class': 'oddsCell','style':'width:60px'});
					var homeCellParam=new Element('td',{'class': 'paramRight','style':'width:8px'});
					if($defined(homeValues[j])){
						/*homeCellParam.setHTML('<div id="'+divId+'">'+homeScoreText[j]+'</div>');
						homeCell.setHTML('<div id="'+divId+'"><div class="ButtonOddsSelectorSmallOff" onmouseover="this.className=\'ButtonOddsSelectorSmallOn\'" ' +
								'onmouseout="this.className=\'ButtonOddsSelectorSmallOff\'"><a href="#">'+homeValues[j].value.toFixed(2)+'</a></div>'+
								homeScoreText[j]+'</div>');*/
						homeCell.setHTML(this.addDivToText_oddsSmall(homeValues[j].formattedValue,homeScoreText[j]));
						var idHomeValue=homeValues[j].id;
						var valueHomeValue=homeValues[j].value;
						var formattedValueHomeValue=homeValues[j].formattedValue;
						var args=new Array(idHomeValue , valueHomeValue,formattedValueHomeValue,'home',outcomeName,homeScoreText[j]);
						homeCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						homeCellParam.setHTML(this.addText_odds(''));
						homeCell.setHTML(this.addText_odds('&nbsp;'));
					}

					var drawCell=new Element('td',{'class': 'oddsCell'});
					var drawCellParam=new Element('td',{'class': 'paramRight'});
					if($defined(drawValues[j])){
						/*drawCellParam.setHTML('<div id='+divId+'>'+drawScoreText[j]+'</div>');
						drawCell.setHTML('<div id='+divId+'><div class="ButtonOddsSelectorSmallOff" onmouseover="this.className=\'ButtonOddsSelectorSmallOn\'" ' +
								'onmouseout="this.className=\'ButtonOddsSelectorSmallOff\'"><a href="#">'+drawValues[j].value.toFixed(2)+
								* '</a></div>'+drawScoreText[j]+'</div>');*/
						drawCell.setHTML(this.addDivToText_oddsSmall(drawValues[j].formattedValue,drawScoreText[j]));
						var args=new Array(drawValues[j].id , drawValues[j].value,drawValues[j].formattedValue,nameOfDraw,outcomeName,drawScoreText[j]);
						drawCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						drawCellParam.setHTML(this.addText_odds(''));
						drawCell.setHTML(this.addText_odds('&nbsp;'));
					}
					var awayCell=new Element('td',{'class': 'oddsCell'});
					var awayCellParam=new Element('td',{'class': 'paramRight'});
					if($defined(awayValues[j])){
						/*awayCellParam.setHTML('<div id='+divId+'>'+awayScoreText[j]+'</div>');
						awayCell.setHTML('<div id='+divId+'><div class="ButtonOddsSelectorSmallOff" onmouseover="this.className=\'ButtonOddsSelectorSmallOn\'" ' +
								'onmouseout="this.className=\'ButtonOddsSelectorSmallOff\'"><a href="#">'+awayValues[j].value.toFixed(2)+'</a></div>'+awayScoreText[j]+'</div>');*/
						awayCell.setHTML(this.addDivToText_oddsSmall(awayValues[j].formattedValue,awayScoreText[j]));
						var args=new Array(awayValues[j].id , awayValues[j].value,awayValues[j].formattedValue,'away',outcomeName,awayScoreText[j]);
						awayCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						awayCellParam.setHTML(this.addText_odds(''));
						awayCell.setHTML(this.addText_odds('&nbsp;'));
					}
					homeCell.injectInside(csRow);
					//homeCellParam.injectInside(csRow);
					drawCell.injectInside(csRow);
					//drawCellParam.injectInside(csRow);
					awayCell.injectInside(csRow);
					//awayCellParam.injectInside(csRow);

					if(j!=0 && !isExpend){
						var emptyCell=new Element('td',{'class': 'emptyTd'});
						emptyCell.injectInside(csRow);
					}
				}
		}
		if(betTypes.TYPE_ID_NUMBER_OF_GOALS==this.typeId ){
				var nameCell=null;
				var betTypeRow1=null;
				if(parentRow==null){
					//betTypeRow1=new Element('tr');
					//nameCell=new Element('td',{'valign': 'top','align': 'center'});
					betTypeRow1=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
					//nameCell.injectInside(betTypeRow1);
					this.betTypeRows.push(betTypeRow1);
				} else {
					betTypeRow1 = parentRow;
				}
				var oddsValues=this.odds.get(doubleNULL).values();

				//-------------wolf modify for score sort-------------------
				var homeValues=[];var homeScoreText=[];

				for(var i=0;i<oddsValues.length;i++){
					var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
					var intParam=extraInfo.integerParameter;
					var intParam2=extraInfo.integerParameter2;

					var paramText='';
					if(intParam==longNULL && intParam2!=longNULL)
						paramText=intParam2+' or less goals';
					if(intParam!=longNULL && intParam2==longNULL)
						paramText=intParam+' or more goals';
					if(intParam!=longNULL && intParam2!=longNULL){
						if(intParam!=intParam2)
							paramText=intParam+' to '+intParam2+ ' goals';
						else{
							if(intParam==1)
								paramText=intParam+' goal';
							else
								paramText=intParam+' goals';
						}
					}
					homeScoreText.push(paramText);
					homeValues.push(oddsValues[i]);
				}
				homeValues.sort(this.sortNubmerofGoals.bind(this));
				homeScoreText.sort(this.sortNubmerofGoalsText.bind(this));

				var nrRows=homeValues.length;
				var lastRow=parentRow;
				if (!isExpend) this.match.rowCount = nrRows - 1;
				for(var j=0;j<nrRows;j++){
					var csRow=null;
					if(j==0)
						csRow=betTypeRow1;
					else{
						if(parentRow==null){
							csRow=new Element('tr');
							if (isExpend){
								csRow=new Element('tr',{'id':'R2'});
							}else{
								csRow=new Element('tr');
							}
							this.betTypeRows.push(csRow);
							var emptyCell=new Element('td',{'colspan':'4'});
							emptyCell.setHTML(this.addText_odds('&nbsp;'));
							emptyCell.injectInside(csRow);
						} else {
							if (isExpend){
								csRow=new Element('tr',{'id':'R2','class': 'matchLine'});
							}else{
								csRow=new Element('tr',{'class': 'matchLine'});
							}
							var emptyCell=new Element('td',{'colspan':'4'});
							emptyCell.setHTML(this.addText_odds('&nbsp;'));
							emptyCell.injectInside(csRow);
							var tbody=parentRow.getParent();
							var matchRows=tbody.getElements('tr.matchLine');
							csRow.injectAfter(lastRow);
							lastRow = csRow;
						}
					}


					var homeCell=new Element('td',{'class': 'oddsCell'});
					var homeCellParam=new Element('td',{'colspan': '2'});
					if($defined(homeValues[j])){
						homeCellParam.setHTML(this.addText_odds("&nbsp;"+homeScoreText[j]));
						homeCell.setHTML(this.addDivToText_odds(homeValues[j].formattedValue,''));
						var idHomeValue=homeValues[j].id;
						var valueHomeValue=homeValues[j].value;
						var formattedValueHomeValue=homeValues[j].formattedValue;
						var args=new Array(idHomeValue , valueHomeValue,formattedValueHomeValue,'home',outcomeName,homeScoreText[j]);
						homeCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}

					homeCell.injectInside(csRow);
					homeCellParam.injectInside(csRow);
					var emptyCell=new Element('td',{'colspan': '1'})
					emptyCell.setHTML(this.addText_odds('&nbsp;'));
					//emptyCell.injectInside(csRow);
				}
		}
		if(betTypes.TYPE_ID_DOUBLE_CHANCE ==this.typeId ){
				var nameCell=null;
				var betTypeRow1=null;
				var lastRow = parentRow;
				if(parentRow==null){
					//betTypeRow1=new Element('tr');
					//nameCell=new Element('td',{'valign': 'top','align': 'center'});
					betTypeRow1=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
					//nameCell.injectInside(betTypeRow1);
					this.betTypeRows.push(betTypeRow1);
				} else {
					if(parentRow.getChildren('td').length<3){
							betTypeRow1 = parentRow;
					}
					else {betTypeRow1 = parentRow;
						//betTypeRow1=new Element('tr',{'class': 'matchLine'});
						//var emptyCell=new Element('td',{'colspan':'4'});
						//emptyCell.setHTML(this.addText_odds('&nbsp;'));
						//emptyCell.injectInside(betTypeRow1);

						//var tbody=parentRow.getParent();
						//var matchRows=tbody.getElements('tr.matchLine');
						//betTypeRow1.injectAfter(lastRow);
						//lastRow = betTypeRow1;
						//lastRow =
					}
				}
				var oddsValues=this.odds.get(doubleNULL).values();
				var oddsValuesReordered=[];
				for(var i=0;i<oddsValues.length;i++){
					var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
					var intParam1=extraInfo.integerParameter;
					if(intParam1==this.match.homeParticipantId)//1X
						oddsValuesReordered[0]=oddsValues[i];
					if(intParam1==longNULL)//12
						oddsValuesReordered[1]=oddsValues[i];
					if(intParam1==this.match.awayParticipantId)//X2
						oddsValuesReordered[2]=oddsValues[i];
				}
				var cell1x=new Element('td',{'class': 'oddsCell'});
				var cell1xText=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[0])){
					cell1xText.setHTML(this.addText_odds('1X'));
					cell1x.setHTML(this.addDivToText_odds(oddsValuesReordered[0].formattedValue,''));
					var args=new Array(oddsValuesReordered[0].id , oddsValuesReordered[0].value,oddsValuesReordered[0].formattedValue,'home',outcomeName,'1X');
					cell1x.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cell1x.setHTML(this.addText_odds('&nbsp;'));
					cell1xText.setHTML(this.addText_odds(''));
				}
				var cellx2=new Element('td',{'class': 'oddsCell'});
				var cellx2Text=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[2])){
					cellx2Text.setHTML(this.addText_odds('X2'));
					cellx2.setHTML(this.addDivToText_odds(oddsValuesReordered[2].formattedValue,''));
					var args=new Array(oddsValuesReordered[2].id , oddsValuesReordered[2].value,oddsValuesReordered[2].formattedValue,nameOfDraw,outcomeName,'X2');
					cellx2.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cellx2.setHTML(this.addText_odds('&nbsp;'));
					cellx2Text.setHTML(this.addText_odds(''));
				}
				var cell12=new Element('td',{'class': 'oddsCell'});
				var cell12Text=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[1])){
					cell12Text.setHTML(this.addText_odds('12'));
					cell12.setHTML(this.addDivToText_odds(oddsValuesReordered[1].formattedValue,''));
					var args=new Array(oddsValuesReordered[1].id , oddsValuesReordered[1].value,oddsValuesReordered[1].formattedValue,'away',outcomeName,'12');
					cell12.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cell12.setHTML(this.addText_odds('&nbsp;'));
					cell12Text.setHTML(this.addText_odds(''));
				}
				//if (!isExpend) this.match.rowCount = 2;
				//cell1xText.injectInside(betTypeRow1);
				cell1x.injectInside(betTypeRow1);
				//cellx2Text.injectInside(betTypeRow1);
				cellx2.injectInside(betTypeRow1);
				//cell12Text.injectInside(betTypeRow1);
				cell12.injectInside(betTypeRow1);
		}
		if(betTypes.TYPE_ID_HALF_TIME_FULL_TIME==this.typeId ){
				var nameCell=null;
				var betTypeRow1=null;
				var betTypeRow2=null;
				var betTypeRow3=null;
				if(parentRow==null){


					if (isExpend){
						betTypeRow1=new Element('tr',{'id':'R2','class':this.match.id});
						betTypeRow2=new Element('tr',{'id':'R2','class':this.match.id});
						betTypeRow3=new Element('tr',{'id':'R2','class':this.match.id});
					}else{
						betTypeRow1=new Element('tr');
						betTypeRow2=new Element('tr');
						betTypeRow3=new Element('tr');
					}
					//nameCell=new Element('td',{'valign': 'top','align': 'center'});
					betTypeRow1=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
					//nameCell.injectInside(betTypeRow1);
					var emptyCell=new Element('td',{'colspan':'4'});
					emptyCell.setHTML(this.addText_odds('&nbsp;'));
					emptyCell.injectInside(betTypeRow2);
					var emptyCell=new Element('td',{'colspan':'4'});
					emptyCell.setHTML(this.addText_odds('&nbsp;'));
					emptyCell.injectInside(betTypeRow3);
					this.betTypeRows.push(betTypeRow1);
					this.betTypeRows.push(betTypeRow2);
					this.betTypeRows.push(betTypeRow3);
				} else {
					//if(parentRow.getChildren('td').length<3){
						betTypeRow1 = parentRow;

					if (isExpend){
						betTypeRow2=new Element('tr',{'id':'R2','class': 'matchLine'});
						betTypeRow3=new Element('tr',{'id':'R2','class': 'matchLine'});
					}else{
						betTypeRow2=new Element('tr',{'class': 'matchLine'});
						betTypeRow3=new Element('tr',{'class': 'matchLine'});
					}
						var emptyCell=new Element('td',{'colspan':'4'});
						emptyCell.setHTML(this.addText_odds('&nbsp;'));
						emptyCell.injectInside(betTypeRow2);
						betTypeRow2.injectAfter(betTypeRow1);
						var emptyCell2=new Element('td',{'colspan':'4'});
						emptyCell2.setHTML(this.addText_odds('&nbsp;'));
						emptyCell2.injectInside(betTypeRow3);
						betTypeRow3.injectAfter(betTypeRow2);
					//}
				}
				var oddsValues=this.odds.get(doubleNULL).values();
				var oddsValuesReordered=[];
				for(var i=0;i<oddsValues.length;i++){
					var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
					var intParam1=extraInfo.integerParameter;
					var intParam2=extraInfo.integerParameter2;
					if(intParam1==this.match.homeParticipantId && intParam2==this.match.homeParticipantId)
						oddsValuesReordered[0]=oddsValues[i];
					if(intParam1==longNULL && intParam2==this.match.homeParticipantId)
						oddsValuesReordered[1]=oddsValues[i];
					if(intParam1==this.match.awayParticipantId && intParam2==this.match.homeParticipantId)
						oddsValuesReordered[2]=oddsValues[i];
					if(intParam1==this.match.homeParticipantId && intParam2==longNULL)
						oddsValuesReordered[3]=oddsValues[i];
					if(intParam1==longNULL && intParam2==longNULL)
						oddsValuesReordered[4]=oddsValues[i];
					if(intParam1==this.match.awayParticipantId && intParam2==longNULL)
						oddsValuesReordered[5]=oddsValues[i];
					if(intParam1==this.match.homeParticipantId && intParam2==this.match.awayParticipantId)
						oddsValuesReordered[6]=oddsValues[i];
					if(intParam1==longNULL && intParam2==this.match.awayParticipantId)
						oddsValuesReordered[7]=oddsValues[i];
					if(intParam1==this.match.awayParticipantId && intParam2==this.match.awayParticipantId)
						oddsValuesReordered[8]=oddsValues[i];
				}
				var cell11=new Element('td',{'class': 'oddsCell'});
				var cell11Text=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[0])){
					cell11Text.setHTML(this.addText_odds('1/1'));
					cell11.setHTML(this.addDivToText_oddsSmall(oddsValuesReordered[0].formattedValue,'1/1'));
					var args=new Array(oddsValuesReordered[0].id , oddsValuesReordered[0].value,oddsValuesReordered[0].formattedValue,'home',outcomeName,'1/1');
					cell11.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cell11.setHTML(this.addText_odds('&nbsp;'));
				}
				var cellx1=new Element('td',{'class': 'oddsCell'});
				var cellx1Text=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[1])){
					cellx1Text.setHTML(this.addText_odds('x/1'));
					cellx1.setHTML(this.addDivToText_oddsSmall(oddsValuesReordered[1].formattedValue,'x/1'));
					var args=new Array(oddsValuesReordered[1].id , oddsValuesReordered[1].value,oddsValuesReordered[1].formattedValue,nameOfDraw,outcomeName,'x/1');
					cellx1.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cellx1.setHTML(this.addText_odds('&nbsp;'));
				}
				var cell21=new Element('td',{'class': 'oddsCell'});
				var cell21Text=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[2])){
					cell21Text.setHTML(this.addText_odds('2/1'));
					cell21.setHTML( this.addDivToText_oddsSmall(oddsValuesReordered[2].formattedValue,'2/1'));
					var args=new Array(oddsValuesReordered[2].id , oddsValuesReordered[2].value,oddsValuesReordered[2].formattedValue,'away',outcomeName,'2/1');
					cell21.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cell21.setHTML(this.addText_odds('&nbsp;'));
				}

				//cell11Text.injectInside(betTypeRow1);
				cell11.injectInside(betTypeRow1);
				//cellx1Text.injectInside(betTypeRow1);
				cellx1.injectInside(betTypeRow1);
				//cell21Text.injectInside(betTypeRow1);
				cell21.injectInside(betTypeRow1);

				var cell1x=new Element('td',{'class': 'oddsCell'});
				var cell1xText=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[3])){
					cell1xText.setHTML(this.addText_odds('1/x'));
					cell1x.setHTML(this.addDivToText_oddsSmall(oddsValuesReordered[3].formattedValue,'1/x'));
					var args=new Array(oddsValuesReordered[3].id , oddsValuesReordered[3].value,oddsValuesReordered[3].formattedValue,'home',outcomeName,'1/x');
					cell1x.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cell1x.setHTML(this.addText_odds('&nbsp;'));
				}
				var cellxx=new Element('td',{'class': 'oddsCell'});
				var cellxxText=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[4])){
					cellxxText.setHTML(this.addText_odds('x/x'));
					cellxx.setHTML( this.addDivToText_oddsSmall(oddsValuesReordered[4].formattedValue,'x/x'));
					var args=new Array(oddsValuesReordered[4].id , oddsValuesReordered[4].value,oddsValuesReordered[4].formattedValue,nameOfDraw,outcomeName,'x/x');
					cellxx.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cellxx.setHTML(this.addText_odds('&nbsp;'));
				}
				var cell2x=new Element('td',{'class': 'oddsCell'});
				var cell2xText=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[5])){
					cell2xText.setHTML(this.addText_odds('2/x'));
					cell2x.setHTML( this.addDivToText_oddsSmall(oddsValuesReordered[5].formattedValue,'2/x'));
					var args=new Array(oddsValuesReordered[5].id , oddsValuesReordered[5].value,oddsValuesReordered[5].formattedValue,'away',outcomeName,'2/x');
					cell2x.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cell2x.setHTML(this.addText_odds('&nbsp;'));
				}
				if (!isExpend) this.match.rowCount = 2;
				//cell1xText.injectInside(betTypeRow2);
				cell1x.injectInside(betTypeRow2);
				//cellxxText.injectInside(betTypeRow2);
				cellxx.injectInside(betTypeRow2);
				//cell2xText.injectInside(betTypeRow2);
				cell2x.injectInside(betTypeRow2);

				var cell12=new Element('td',{'class': 'oddsCell'});
				var cell12Text=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[6])){
					cell12Text.setHTML(this.addText_odds('1/2'));
					cell12.setHTML(this.addDivToText_oddsSmall(oddsValuesReordered[6].formattedValue,'1/2'));
					var args=new Array(oddsValuesReordered[6].id , oddsValuesReordered[6].value,oddsValuesReordered[6].formattedValue,'home',outcomeName,'1/2');
					cell12.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cell12.setHTML(this.addText_odds('&nbsp;'));
				}
				var cellx2=new Element('td',{'class': 'oddsCell'});
				var cellx2Text=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[7])){
					cellx2Text.setHTML(this.addText_odds('x/2'));
					cellx2.setHTML(this.addDivToText_oddsSmall(oddsValuesReordered[7].formattedValue,'x/2'));
					var args=new Array(oddsValuesReordered[7].id , oddsValuesReordered[7].value,oddsValuesReordered[7].formattedValue,nameOfDraw,outcomeName,'x/2');
					cellx2.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cellx2.setHTML(this.addText_odds('&nbsp;'));
				}
				var cell22=new Element('td',{'class': 'oddsCell'});
				var cell22Text=new Element('td',{'class': 'paramRight'});
				if($defined(oddsValuesReordered[8])){
					cell22Text.setHTML(this.addText_odds('2/2'));
					cell22.setHTML(this.addDivToText_oddsSmall(oddsValuesReordered[8].formattedValue,'2/2'));
					var args=new Array(oddsValuesReordered[8].id , oddsValuesReordered[8].value,oddsValuesReordered[8].formattedValue,'away',outcomeName,'2/2');
					cell22.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
					cell22.setHTML(this.addText_odds('&nbsp;'));
				}

				//cell12Text.injectInside(betTypeRow3);
				cell12.injectInside(betTypeRow3);
				//cellx2Text.injectInside(betTypeRow3);
				cellx2.injectInside(betTypeRow3);
				//cell22Text.injectInside(betTypeRow3);
				cell22.injectInside(betTypeRow3);
								
				if (!isExpend) {
					var emptyCellEnd2=new Element('td',{'class': 'emptyTd'});
					var emptyCellEnd3=new Element('td',{'class': 'emptyTd'});
					emptyCellEnd2.injectInside(betTypeRow2);
					emptyCellEnd3.injectInside(betTypeRow3);	
				}			
		}
		if(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW==this.typeId || betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId ){
			    var nameCell=null;
				var betTypeRow=null;
				if(parentRow==null){
					if(isExpend)
						betTypeRow=new Element('tr',{'class':this.match.id});
					else
						betTypeRow=new Element('tr');
					//nameCell=new Element('td',{'align': 'center'});
					betTypeRow=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
					//nameCell.injectInside(betTypeRow);
					this.betTypeRows.push(betTypeRow);
				} else {
					//if(parentRow.getChildren('td').length<3)
							betTypeRow = parentRow;
					/*else {
						betTypeRow=new Element('tr',{'class': 'matchLine'});
						var emptyCell=new Element('td');
						emptyCell.setHTML('&nbsp;');
						emptyCell.injectInside(betTypeRow);
						var tbody=parentRow.getParent();
						var matchRows=tbody.getElements('tr.matchLine');
						betTypeRow.injectAfter(matchRows[matchRows.length-1]);
					}*/
				}
				var oddsValues=this.odds.get(doubleNULL).values();
				//--------wolf modify---------------------
				var homeOdds=null;
				var awayOdds=null;
				for(var i=0;i<oddsValues.length;i++){
					var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
					var intParam=extraInfo.integerParameter;
					if(intParam==this.match.homeParticipantId||5==extraInfo.resultId)
						homeOdds=oddsValues[i];
					if(intParam==this.match.awayParticipantId||6==extraInfo.resultId)
						awayOdds=oddsValues[i];
				}

//				alert(homeOdds.value+"----"+awayOdds.value);
				//var groupCell=new Element('td');
				//nameCell.appendText(' '+this.doubleParameter);
				//groupCell.injectInside(this.betTypeRow);
				var cellHome=new Element('td');
				//cssDiv.addEvent('onmouseover',function(this){this.className='ButtonOddsSelectorLargeOn';}.bind(this.match,args));
				if($defined(homeOdds)){
					cellHome.setHTML(this.addDivToText_odds(homeOdds.formattedValue));
					var args=new Array(homeOdds.id , homeOdds.value,homeOdds.formattedValue,'home',outcomeName,betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId ?nameOfOdd:homeParticipantName);
					cellHome.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
						cellHome.setHTML(this.addText_odds('&nbsp;'));
					}
				var cellAway=new Element('td');
				if($defined(awayOdds)){
					cellAway.setHTML(this.addDivToText_odds(awayOdds.formattedValue));
					var args=new Array(awayOdds.id , awayOdds.value,awayOdds.formattedValue,'away',outcomeName,betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId ?nameOfEven:awayParticipantName);
					cellAway.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
				}else{
						cellAway.setHTML(this.addText_odds('&nbsp;'));
					}
				cellHome.injectInside(betTypeRow);
				var emptyCell=new Element('td',{'class': 'paramCenter'});
				emptyCell.setHTML(this.addEemtyToText_odds(''));
				emptyCell.injectInside(betTypeRow);// this is for draw column
				cellAway.injectInside(betTypeRow);
		}
		if(betTypes.TYPE_ID_OVER_UNDER==this.typeId ){
				//var groupCell=new Element('td');
				var parameters=this.odds.keys();
				var overValues=[];var OUText=[];
				var underValues=[];
				var lastRow=parentRow;
				parameters.sort(this.sortAsianHandicap);
				for(var k=0;k<parameters.length;k++){

					var oddsValues=this.odds.get(parameters[k]).values();
					//---wolf modify--------

					var homeOdds=null;
					var awayOdds=null;
					for(var j=0;j<oddsValues.length;j++){
						var extraInfo=this.extraOutcomeInfo.get(oddsValues[j].id);
						if(3==extraInfo.resultId){
							homeOdds=oddsValues[j];
							overValues.push(homeOdds);
						}
						if(4==extraInfo.resultId){
							awayOdds=oddsValues[j];
							underValues.push(awayOdds);
						}
					}
					OUText.push(parameters[k]);
/*				}
				overValues.sort(this.sortOverUnder.bind(this));
				OUText.sort(this.sortOverUnderText.bind(this));
				underValues.sort(this.sortOverUnder.bind(this));

				var nrRows=overValues.length;
				if(nrRows<underValues.length)
					nrRows = underValues.length;
				for(var k=0;k<nrRows;k++){
*/
					var nameCell=null;
					var betTypeRow=null;

					if(parentRow==null){
						if(isExpend)
							betTypeRow=new Element('tr',{'class':this.match.id});
						else
							betTypeRow=new Element('tr');
						nameCell=new Element('td',{'align': 'center','colspan':'4'});
						betTypeRow=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
						//nameCell.injectInside(betTypeRow);						//alert(nameCell.innerHTML);

						/*for(var i_cell=0;i_cell<4;i_cell++){
						  	var cell = new Element('td');
						  	cell.setHTML(tmpRow.cells[i_cell].innerHTML);
						  	cell.injectInside(betTypeRow);
						}*/
						this.betTypeRows.push(betTypeRow);
						//this.betTypeRows.push(betTypeRow);
					} else {
						if(k==0)//parentRow.getChildren('td').length<3
						{	betTypeRow = lastRow;}
						else {
							betTypeRow=new Element('tr',{'class': 'matchLine'});
							var emptyCell=new Element('td',{'colspan':'4'});
							emptyCell.setHTML('&nbsp;');
							emptyCell.injectInside(betTypeRow);
							var tbody=parentRow.getParent();
							var matchRows=tbody.getElements('tr.matchLine');
							betTypeRow.injectAfter(lastRow);
							//var matchCell=parentRow.getElement('td.invisibleHolder');
							//matchCell.setProperty('rowspan',parseInt(matchCell.getProperty('rowspan'))+1);
						}
						lastRow = betTypeRow;
					}

					//nameCell.appendText(' '+parameters[k]);
					//groupCell.injectInside(this.betTypeRow);
					var cellHome=new Element('td');
					if($defined(overValues[k])){
						cellHome.setHTML(this.addDivToText_odds(overValues[k].formattedValue));
						var args=[];args.push(overValues[k].id);args.push(overValues[k].value);args.push(overValues[k].formattedValue);
						args.push('home');args.push(outcomeName);args.push(nameOfOver + " "+OUText[k]);
						cellHome.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip( id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						cellHome.setHTML(this.addText_odds('&nbsp;'));
					}
					var cellAway=new Element('td');
					if($defined(underValues[k])){
						cellAway.setHTML(this.addDivToText_odds(underValues[k].formattedValue));
						var args=[];args.push(underValues[k].id);args.push(underValues[k].value);args.push(underValues[k].formattedValue);
						args.push('away');args.push(outcomeName);args.push(nameOfUnder + " " +OUText[k]);
						cellAway.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						cellAway.setHTML(this.addText_odds('&nbsp;'));
					}
					cellHome.injectInside(betTypeRow);
					var emptyCell=new Element('td',{'class': 'paramCenterWithoutBold'});
					emptyCell.setHTML(this.addText_odds(OUText[k]));
					emptyCell.injectInside(betTypeRow);// this is for draw column
					cellAway.injectInside(betTypeRow);
					if (!isExpend) this.match.rowCount++;
				}
				if (!isExpend) this.match.rowCount--;
		}
		if( betTypes.TYPE_ID_ASIAN_HANDICAP==this.typeId ||betTypes.TYPE_ID_GAME_HANDICAP==this.typeId  ||betTypes.TYPE_ID_SET_HANDICAP==this.typeId ){
				//var groupCell=new Element('td');
				var parameters=this.odds.keys();
				var lastRow=parentRow;
				parameters.sort(this.sortAsianHandicap);

				for(var k=0;k<parameters.length;k++){
					var nameCell=null;
					var betTypeRow=null;

					if(parentRow==null){
						if(isExpend)
							betTypeRow=new Element('tr',{'class':this.match.id});
						else
							betTypeRow=new Element('tr');
						//nameCell=new Element('td',{'align': 'center'});
						betTypeRow=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
						//nameCell.injectInside(betTypeRow);
						this.betTypeRows.push(betTypeRow);
					} else {
						if(k==0)
							betTypeRow = parentRow;
						else {
							betTypeRow=new Element('tr',{'class': 'matchLine'});
							var emptyCell=new Element('td',{'colspan':'4'});
							emptyCell.setHTML('&nbsp;');
							emptyCell.injectInside(betTypeRow);
							var tbody=parentRow.getParent();
							var matchRows=tbody.getElements('tr.matchLine');
							betTypeRow.injectAfter(lastRow);
							//var matchCell=parentRow.getElement('td.invisibleHolder');
							//matchCell.setProperty('rowspan',parseInt(matchCell.getProperty('rowspan'))+1);
						}
						lastRow = betTypeRow;
					}
					var oddsValues=this.odds.get(parameters[k]).values();
					//---wolf modify--------	if home is without -, then show like 0.50,if home is with -, then show like -0.50


					var homeOdds=null;
					var awayOdds=null;
					for(var i=0;i<oddsValues.length;i++){
						var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
						var intParam=extraInfo.integerParameter;
						if(intParam==this.match.homeParticipantId)
							homeOdds=oddsValues[i];
						if(intParam==this.match.awayParticipantId)
							awayOdds=oddsValues[i];

					}
					//nameCell.appendText(' '+parameters[k]);
					//groupCell.injectInside(this.betTypeRow);
					var cellHome=new Element('td');
					if($defined(homeOdds)){
						cellHome.setHTML(this.addDivToText_odds(homeOdds.formattedValue));
						var args=[];args.push(homeOdds.id);args.push(homeOdds.value);args.push(homeOdds.formattedValue);
						args.push('home');args.push(outcomeName);args.push(this.match.homeParticipantName);
						cellHome.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						cellHome.setHTML(this.addText_odds('&nbsp;'));
					}
					var cellAway=new Element('td');
					if($defined(awayOdds)){
						cellAway.setHTML(this.addDivToText_odds(awayOdds.formattedValue));
						var args=[];args.push(awayOdds.id);args.push(awayOdds.value);args.push(awayOdds.formattedValue);
						args.push('away');args.push(outcomeName);args.push(this.match.awayParticipantName);
						cellAway.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						cellAway.setHTML(this.addText_odds('&nbsp;'));
					}

					cellHome.injectInside(betTypeRow);
					var emptyCell=new Element('td',{'class': 'paramCenterWithoutBold'});
					emptyCell.setHTML(this.addText_odds(parameters[k]));
					emptyCell.injectInside(betTypeRow);// this is for draw column
					cellAway.injectInside(betTypeRow);
					if (!isExpend) this.match.rowCount++;
				}
				if (!isExpend) this.match.rowCount--;
		}
		if(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP==this.typeId ){
				//var groupCell=new Element('td');
				var parameters=this.odds.keys();

				if(parameters.length>1)
				handicap1X2hasNext =true;
				var lastRow=parentRow;
				for(var k=0;k<parameters.length;k++){
					if(k==parameters.length-1) handicap1X2hasNext =false;
					var nameCell=null;
					var betTypeRow=null;
					//--------wolf modify----------------
					var handicap1;  var handicap2;
					if(parameters[k]>=0)
					{
						handicap1=parameters[k]; handicap2=0;
					}
					else
					{
						handicap1=0; handicap2=Math.abs(parameters[k]);
					}
					if(parentRow==null){
						if(isExpend){
							betTypeRow=new Element('tr',{'id':'R2','class':this.match.id});
						}else{
							betTypeRow=new Element('tr');
						}

						//nameCell=new Element('td',{'align': 'center'});
						betTypeRow=this.handicapCell(dateText,hourText,this.match.homeParticipantName + ' ('+handicap1+')',this.match.awayParticipantName+' ('+handicap2+')',false);
						//nameCell.injectInside(betTypeRow);
						this.betTypeRows.push(betTypeRow);
					} else {
						if(k==0){//parentRow.getChildren('td').length<3
							betTypeRow = parentRow;

							//var tbody=parentRow.getParent();
							//var matchRows=tbody.getElements('tr.matchLine');
							//betTypeRow.injectAfter(matchRows[matchRows.length-1]);
							//var matchCell=parentRow.getElement('tr.matchLine');//invisibleHolder
							var teamCells=parentRow.getElements('td.teamWidth');
							teamCells[0].setStyle("padding-left","5px");
							teamCells[0].setHTML(this.addCssToTeam(this.match.homeParticipantName + ' ('+handicap1+')'));
							teamCells[1].setHTML(this.addCssToTeam(this.match.awayParticipantName + ' ('+handicap2+')'));

							var hourCel = parentRow.getElements('td.hourWidth');
							var dateCel = parentRow.getElements('td.dateWidth');

							hourCel.setHTML(this.addCssToTeam(dateText + dateTimeLine+hourText));

							var divId='MarketR1';
							if (handicap1X2hasNext){
							   divId = 'MarketR0';
						    }
							dateCel.setHTML(this.addCssToTeam(dateText + dateTimeLine+hourText));
						}
						else {
							betTypeRow=null;
							//nameCell=new Element('td');
							betTypeRow=this.handicapCell(dateText,hourText,this.match.homeParticipantName + ' ('+handicap1+')',this.match.awayParticipantName+' ('+handicap2+')',false);

							betTypeRow.injectAfter(lastRow);
						}

					}
					lastRow = betTypeRow;
					var oddsValues=this.odds.get(parameters[k]).values();
					var oddsValuesReordered=[];
					for(var i=0;i<oddsValues.length;i++){
						var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
						var intParam1=extraInfo.integerParameter;
						var resultId=extraInfo.resultId;
						if(resultId==1 && intParam1==this.match.homeParticipantId)
							oddsValuesReordered[0]=oddsValues[i];
						if(resultId==1 && intParam1==this.match.awayParticipantId)
							oddsValuesReordered[2]=oddsValues[i];
						if(resultId==2)
							oddsValuesReordered[1]=oddsValues[i];
					}
					//nameCell.appendText(' '+parameters[k]);
					//groupCell.injectInside(this.betTypeRow);
					var cellHome=new Element('td',{'class':'oddsCell'});
					if($defined(oddsValuesReordered[0])){
						cellHome.setHTML(this.addDivToText_odds(oddsValuesReordered[0].formattedValue));
						var args=new Array(oddsValuesReordered[0].id , oddsValuesReordered[0].value,oddsValuesReordered[0].formattedValue,'home',outcomeName,homeParticipantName);
						cellHome.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						cellHome.setHTML(this.addText_odds(''));
					}
					var cellX=new Element('td');
					if($defined(oddsValuesReordered[1])){
						cellX.setHTML(this.addDivToText_odds(oddsValuesReordered[1].formattedValue));
						var args=new Array(oddsValuesReordered[1].id , oddsValuesReordered[1].value,oddsValuesReordered[1].formattedValue,nameOfDraw,outcomeName,nameOfDraw);
						cellX.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						cellX.setHTML(this.addText_odds(''));
					}
					var cellAway=new Element('td');
					if($defined(oddsValuesReordered[2])){
						cellAway.setHTML(this.addDivToText_odds(oddsValuesReordered[2].formattedValue));
						var args=new Array(oddsValuesReordered[2].id , oddsValuesReordered[2].value,oddsValuesReordered[2].formattedValue,'away',outcomeName,awayParticipantName);
						cellAway.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					}else{
						cellAway.setHTML(this.addText_odds(''));
					}
					cellHome.injectInside(betTypeRow);
					cellX.injectInside(betTypeRow);
					cellAway.injectInside(betTypeRow);
					if (!isExpend) this.match.rowCount++;
				}
				if (!isExpend) this.match.rowCount--;
		}

		//alert(betTypeRow.innerHTML);
	},
	addDivToText_odds:function (text){
		var divId='MarketR1';
		if (isExpend){
			divId='MarketR2';
		}else {
			if (handicap1X2hasNext){
			   divId = 'MarketR0';
		    }
		}
		return '<div id="'+divId+'" ><div class="ButtonOddsSelectorLargeOff" onmouseover="this.className=\'ButtonOddsSelectorLargeOn\'" ' +
				'onmouseout="this.className=\'ButtonOddsSelectorLargeOff\'"><a href="javascript:void(0);">&nbsp;'+text
					                 +'</a></div></div>';
	},
	addDivToText_oddsOutrights:function (value,text,param){
		var divId='MarketR1';
		if (isExpend)divId='MarketR2';
		if(value!=null&&value==1) text="NR";
		return '<div id="'+divId+'" style="overflow-x:hidden;"><div class="ButtonOddsSelectorSmallOff" id="IDButtonOddsSelectorSmallOff" onmouseover="this.className=\'ButtonOddsSelectorSmallOn\'" ' +
				'onmouseout="this.className=\'ButtonOddsSelectorSmallOff\'" ><a href="javascript:void(0); ">'+text
					                 +'</a></div><div style="float:left" class="TextOddsSmall">'+param+'</div></div>';
	},
	addDivToText_oddsSmall:function (text,param){
		var divId='MarketR1';
		if (isExpend)divId='MarketR2';

		return '<div id="'+divId+'" style="overflow-x:hidden;"><div class="ButtonOddsSelectorSmallOff" id="IDButtonOddsSelectorSmallOff" onmouseover="this.className=\'ButtonOddsSelectorSmallOn\'" ' +
				'onmouseout="this.className=\'ButtonOddsSelectorSmallOff\'" ><a href="javascript:void(0); ">'+text
					                 +'</a></div><div style="float:left">'+param+'</div></div>';
	},
	addDivToText_odds_withParam:function (text,param){
		var divId='MarketR1';
		if (isExpend)divId='MarketR2';

		return '<div id="'+divId+'" style="overflow-x:hidden;"><div class="ButtonOddsSelectorLargeOff" id="ButtonOddsSelectorLargeOff" onmouseover="this.className=\'ButtonOddsSelectorLargeOn\'" ' +
				'onmouseout="this.className=\'ButtonOddsSelectorLargeOff\'" ><a href="javascript:void(0); ">'+text
					                 +'</a></div><div style="float:left">'+param+'</div></div>';
	},
	addEemtyToText_odds:function (text){
		var divId='MarketR1';
		if (isExpend)
		  divId='MarketR2';
		else
		   return text;
		return '<div id="'+divId+'">&nbsp;</div>';
	},
	addText_odds:function (text){
		var divId='MarketR1';
		if (isExpend)
		  divId='MarketR2'
		else
		   return text;
		return '<div id="'+divId+'"><div align="center">'+text+'</div></div>';
	},
	addCssToTeam:function(text){
		var divId='MarketR1';
		if (isExpend){
			divId='MarketR2';
			return '<div id="'+divId+'"><div>'+ text+'</div></div>';
		}else {
			if (handicap1X2hasNext){
			   divId = 'MarketR0';
		    }
		}
		return text;
	},
	addCssToTeam1:function(text){
		var divId='MarketR1';
		if (isExpend){
			divId='MarketR2';
			return '<div id="'+divId+'"><div style="padding-left:5px">'+ text+'</div></div>';
		}else {
			if (handicap1X2hasNext){
			   divId = 'MarketR0';
		    }
		}
		return text;
	},
	addDivToText_title:function (text){

	}

});

var Odds = CategElement.extend ({
	initialize: function(id,oddsValue, formattedValue ){
		this.parent(id); // the id here is actually the outcomeId
		this.value=oddsValue;
		this.formattedValue = formattedValue;
	},
	setValue: function(oddsValue){
		this.value=value;
	}
});

//window.addEvent('domready',test1);

function processFailure(){

}

function fillOddsTable(response){
	if ($defined($('div_loadPicTab'))) $("div_loadPicTab").style.display = "none";
	if ($defined($('div_loadPicTabForPopular'))) $("div_loadPicTabForPopular").style.display = "none";
	try{
	   if (timeFilters==null||timeFilters=='') {filters.empty();filtersForOutrights.empty();}
		if($defined($('oddstable').getChildren()[1])){
	       var oddsTabObj = $('oddstable').getChildren();
	       for(i=1;i<oddsTabObj.length;i++){
	           $('oddstable').removeChild(oddsTabObj[i]);
	       }
	     }

	if($defined($('frontPageBoxesTable'))){
		if($('frontPageBoxesTable').getStyle('display')!='none')
		$('frontPageBoxesTable').setStyle('display','none');
		if(window.ie)
			$('filterBetType').setStyle('display','block');
		else
			$('filterBetType').setStyle('display','table');
	}
	if($defined($('lastLoadedCommands'))){
		$('lastLoadedCommands').remove();
	}

	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.defer = true;
	script.id = 'lastLoadedCommands';

	if(window.ie)
		script.text=response;
	else
		script.appendChild(document.createTextNode(response));
	var head = document.getElementsByTagName('head').item(0);
	head.appendChild(script);

	} catch (e){
		alert("oddstable.js 2:"+e);
		/*if(isIE()){
                logErr("Error name: " + e.name+ ". Error description: " + e.description+ ". Error number: " + e.number+ ". Error message: " + e.message);
            }
            else{
               logErr('<b>'+ e+' at line '+e.lineNumber+ '; in file '+e.fileName+'<\b>');
                logErr(e.stack);
          }*/
	}
}

function addPageListInfo(pageList){
	if ($defined($('oddstable'))){
		var nameCell=new Element('tr',{'class':'titleLine'});
		var dateCell=new Element('td',{'colspan':'8','class':'pListLine'});
		dateCell.setHTML(pageList);
		dateCell.injectInside(nameCell);
		nameCell.injectInside(topTableBody);
	}

}

function addNoMatchRow(matchaccount){
	
	if(matchaccount<1){
		if ($defined($('noMatchShow'))){
			var nomatchshow = $('noMatchShow');
			nomatchshow.style.display = "block";
			if(searchedName.length > 0)
				nomatchshow.innerHTML = text_noMatchFoundFor + " " + searchedName;
			else
				nomatchshow.innerHTML = text_noMatchFound;	
		}
	}	
	else{
		if ($defined($('noMatchShow'))){
			var nomatchshow = $('noMatchShow');
			nomatchshow.style.display = "none";
		}
	}
}

function pageGoto(page){
	$("div_loadPicTab").style.display = "block";
	pageNo = page;
	filterOdds(curBetType,curScope);
}

function expandMatch(disciplineId,imgObj){
    isExpend = true;
    //if ($defined($('div_loadPicTab'))) $("div_loadPicTab").style.display = "block";
    imgObj.style.display="block";
	if($defined(currentExpandedMatch)){
		var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
		               onSuccess: function(response){insertExpandedMatchIntoDOM(response,imgObj);isExpend=false;},
		               onFailure: function(){processFailure();}});
		ajaxReq.send('/expandedMatch.do','id='+currentExpandedMatch.id+'&discId='+disciplineId+'&x='+(Math.random()*100)+'&isOutrights='+isOutrights);
		ajaxReq=null;
	}
}

function insertExpandedMatchIntoDOM(response,imgObj){
	if ($defined($('div_loadPicTab'))) $("div_loadPicTab").style.display = "none";
	imgObj.style.display="none";
	try{
	if($defined($('expandLastLoadedCommands'))){
		$('expandLastLoadedCommands').remove();
	}
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.defer = true;
	script.id = 'expandLastLoadedCommands';
	if(window.ie)
		script.text=response;
	else
		script.appendChild(document.createTextNode(response));
	var head = document.getElementsByTagName('head').item(0);
	head.appendChild(script);
	} catch (e){

	}
}
var  _betTypeParam="";  //used by time filter

function filterOdds(betTypeId,scopeId){
	var timeFilter = getTimeFilter();
	var tfArr;
	if (timeFilter!=null){
		tfArr=timeFilter.split("-");
		timeFilter = "&fType="+tfArr[0]+"&tm="+tfArr[1];
	}else{
		timeFilter = "";
	}$("tma").setHTML("&nbsp;");
//	timeFilters="";
//	timeFilter = "";
	pageParam = "&page="+pageNo;
	var betTypeParam='';
	if(betTypeId=='all'){
		betTypeIdShown=-1;
		scopeIdShown=-1;
		_betTypeParam="";
	    curBetType='all';
	    curScope =	scopeId;

	    if (!filterL) timeFilter = "";
		betTypeParam='&bettype=all@'+scopeId;
	} else {
		filteTable = true;
		betTypeIdShown=betTypeId;
		scopeIdShown=scopeId;
	    curBetType=betTypeId;
	    curScope =scopeId;
	    if (!filterL) timeFilter = "";
		betTypeParam='&bettype='+betTypeId+'@'+scopeId;
		_betTypeParam = betTypeParam;
	}//alert(filterL); alert(timeFilter);
	filters = new Hash(); 	//very important ,must be create an new object
	filtersForOutrights = new Hash();
	var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
	onSuccess: function(response){
		fillOddsTable(response);
		filteTable = false;
		},
	onFailure: function(){processFailure();}});
	ajaxReq.send(getUrl(),'searchedName='+searchedName+'&id='+globalID+'&x='+(Math.random()*100)+betTypeParam+timeFilter+pageParam);
	ajaxReq=null;
}

function getUrl()
{
	var url;
	if(urlStatus == 'oddstable') {
		url = oddstalbeUrl;
	}
	else if(urlStatus == 'bannerEvent'){
		url = bannerTournamentORMatchUrl;
	}
	else
		url = popularMatchUrl;
	return url
}
function changeHeadPic() {
	var obj = document.getElementById("headpic");
	if( obj != null){
		if(urlStatus == 'oddstable'||urlStatus == 'bannerEvent') {
			obj.innerHTML = text_yourSelection;
		}
		else
			obj.innerHTML = text_popularMatch;
	}
}

function chgHeadPicToPopular()
{
	var obj = document.getElementById("headpic");
	if( obj != null ){
		obj.innerHTML = text_popularMatch;
	}
}

function chgHeadPicToSearchResult(searchedName){
	
	var obj = document.getElementById("headpic");
	if( obj != null ){
		obj.innerHTML = text_searchResult + " " +document.getElementById('searchedName').value;
	}
}

/**
 * clear the value of html input
 */
function clearValue(obj) {
	
	if(obj != null)
		obj.value = "";
}

/**
 * fill the input box with some tips.
 */
function fillValue(obj) {
	
	if(obj != null && searchedName.length >1)
		obj.value = searchedName;
}

/**
 * reset the value of searchedName to ""
 * and reset the value searchedName input box
 */
function resetValueOfSearchedName() {
	
	if(searchedName.length > 0) {
		searchedName = "";
		document.getElementById("searchedName").value = text_searchTEP;
	}
}

/**
 * when press Enter key in searched name box
 */
function searchedNameKeyDown(event) {
	
	//for both IE and FIREFOX
	e = event?event:(window.event?window.event:null);
	
	//if user presses 'Enter', search.
	if (e.keyCode == 13)
    {
        event.returnValue=false;
        event.cancel = true;
        searchMatchesByName();
    }
    
}


function filterOddsByTime(fType,tm,filterText){
	/*
	 var timeFilter = getTimeFilter();
	var tfArr;
	if (timeFilter!=null){
		tfArr=timeFilter.split("-");
		timeFilter = "&fType="+tfArr[0]+"&tm="+tfArr[1];
	}else{
		timeFilter = "";
	}
	 */
	var	timeFilter = "&fType="+fType+"&tm="+tm;//alert('id='+globalID+timeFilter+_betTypeParam);
	$("div_loadPicTab").style.display = "block";
	//filters = new Hash(); 	//very important ,must be create an new object
	filter = new Hash();
	var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
	                 onSuccess: function(response){
	                 	if (_betTypeParam!='')filteTable=true;
	                 	    fillOddsTable(response);$("tma").innerHTML=filterText;
	                 	},
	                 onFailure: function(){processFailure();}});
	ajaxReq.send(getUrl(),'id='+globalID+timeFilter+_betTypeParam+'&searchedName='+searchedName);
	ajaxReq=null;
}

function applyFilter(el){
	$("div_loadPicTab").style.display = "block";
	var parts=el.getProperty('filterValue').split(',');
	pageNo = 1;
	filterOdds(parts[0],parts[1]);
}

function presentFilters(){
	var filterTable=$('filterBetType');
	if(window.ie){
		$("fbtBody").removeNode(true);
	}else {
		filterTable.empty();//alert(filterTable.innerHTML);
	}
	
	var tbody=new Element('tbody',{'id':'fbtBody'});

	if(betTypeIdShown==-1 && scopeIdShown==-1){
		defaultFilters = filters;
		defaultFiltersForOutrights = filtersForOutrights;
	}else{
		filters= defaultFilters;//		bettypes= defaultFilters.keys();
		//defaultFiltersKey = filters.keys();
		filtersForOutrights = defaultFiltersForOutrights;
	}
	if (filters.length>0)
		presentFiltersSub(false,filters,tbody);
	if (filtersForOutrights.length>0)
		presentFiltersSub(true,filtersForOutrights,tbody);
	
	tbody.injectInside(filterTable);
	
	if (filters.length>0)
		expandableFilter(false);
	if (filtersForOutrights.length>0)
		expandableFilter(true);
}

function presentFiltersSub(isOutrightsFilter,filtersData,tbody) {	
	var currentRow=new Element('tr',{'id':'filterRow_'+isOutrightsFilter});
	var cell=new Element('td',{'width':'100%','id':'filterTd_'+isOutrightsFilter});
	var divCss = new Element ('div',{'id':'MarketSelectionOff'});
	var filterLink=new Element('a',{'href': '#','filterValue': 'all,'+isOutrightsFilter,'events': {'click': function(){applyFilter(this);}}});
	filterLink.injectInside(divCss);
	divCss.injectInside(cell);
	
	if(betTypeIdShown==-1 && scopeIdShown==-1 && isOutrightsFilter==isOutrights){
		divCss.setProperty('id','MarketSelectionOn');
		selectedFilter=filterLink;
		_betTypeParam = "";
		filterLink.id='defaultFilter';
	}
	
	var bettypes=filtersData.keys();
	filterLink.setText(defautFilter);//' Default '

	var keyAndvalueArray = [] ;
	for(var i=0;i<bettypes.length ;i++){
		var value = filtersData.get(bettypes[i]);
		if(value.indexOf(',')<0)
			keyAndvalueArray.push(filtersData.get(bettypes[i])+' @'+bettypes[i]);
		else
			keyAndvalueArray.push(filtersData.get(bettypes[i])+'@'+bettypes[i]);
	}

	keyAndvalueArray.sort();
	for(var i=0;i<keyAndvalueArray.length ;i++){ //+1
		var vauleAndKey = keyAndvalueArray[i].split('@');
		var divCss = new Element('div',{'id':'MarketSelectionOff'});
		filterLink=new Element('a',{'href': '#','filterValue': vauleAndKey[1],'events': {'click': function(){applyFilter(this);}}});
		filterLink.injectInside(divCss);
		if(vauleAndKey[1]==betTypeIdShown+','+scopeIdShown){
			divCss.setProperty('id','MarketSelectionOn');
			selectedFilter=filterLink;
			filterLink.id='defaultFilter';
		}

		filterLink.setText(' '+vauleAndKey[0]+' ');
		divCss.injectInside(cell);

	}	
	
	if (!isOutrightsFilter){
		var timeF = new Element('div',{'id':'MarketSelectionOff','overflow':'30'});
		timeF.innerHTML = $("timeFTable").innerHTML;
		timeF.injectInside(cell);
	}
	
	cell.injectInside(currentRow);
	currentRow.injectInside(tbody);
	var td = new Element('td',{'class':'expandableFilter','id':'expander_'+isOutrightsFilter});
	td.setText("+00");
	td.injectInside(currentRow);	
	//currentRow.style.display="none";
}
function expandableFilter(isOutrightsFilter) {
	var tdWidth = $('filterTd_'+isOutrightsFilter).offsetWidth;
	var filterWidth = $('defaultFilter').offsetWidth;
	var oddsTableWidth = $('oddstable').offsetWidth;
	
	var expandFlag = false;
	var currentRow = $('filterRow_'+isOutrightsFilter);
	var filtersNum = currentRow.getChildren()[0].getChildren().length;
	var currentNumOfDivPerRow = Math.floor(tdWidth/filterWidth);
	if (isNaN(currentNumOfDivPerRow))
		currentNumOfDivPerRow = numOfDivPerRow;
	if (filtersNum > currentNumOfDivPerRow) {
		var currentRow2 = currentRow.clone();
		currentRow2.id = 'filterRowSingle_'+isOutrightsFilter;
		var children = currentRow2.getChildren()[0].getChildren();
		
		if(!window.ie){
			for (var i=0;i<currentNumOfDivPerRow;i++) {		
				children[i].getChildren()[0].addEvent('click',function(){applyFilter(this);});
			}
		}
		
		for (var i=currentNumOfDivPerRow;i<filtersNum;i++) {
			if (children[i].id == 'MarketSelectionOn')
				expandFlag = true;
	        children[i].remove();
		}
		
		var numOfMoreFilter = filtersNum - currentNumOfDivPerRow;
		var td = $('expander_'+isOutrightsFilter);
		td.setText("-"+numOfMoreFilter);
		td.addEvent('click',function(){displayFilter('filterRow_'+isOutrightsFilter,'filterRowSingle_'+isOutrightsFilter)});
		
		var td2 = currentRow2.getChildren()[1];
		td2.id = 'expanderSingle_'+isOutrightsFilter;
		td2.setText("+"+numOfMoreFilter);	
		td2.addEvent('click',function(){displayFilter('filterRowSingle_'+isOutrightsFilter,'filterRow_'+isOutrightsFilter)});
		
		if (expandFlag) 
			currentRow2.style.display="none";
		else
			currentRow.style.display="none";
		
		currentRow2.injectBefore(currentRow);
	} else {
		$('expander_'+isOutrightsFilter).setText(" ");	
	}
}
function displayFilter(rowId,rowId2) {
	$(rowId).style.display = 'none';	
	$(rowId2).style.display = '';	
}

function getTimeFilter(){
//	var obj=$("Filtetime")
//	var obj = document.getElementById("tFilter");
	return timeFilters;
	/*// Used by checked type
	if (obj.checked){
	   return obj.value;
	}else
	   return null;
	*/
}
function afterClickLeftTree() {	
}
function showOddsa(tm,type){
     var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',onSuccess: function(response){fillOddsTable(response);urlStatus = 'oddstable';}, onFailure: function(){processFailure();}});
     ajaxReq.send('/oddstable.do','fType='+type+'&tm='+tm);
	 ajaxReq=null;
	 afterClickLeftTree();
}
function showOddsb(tm,fType){
	filterL = true;
	if (timeFilters!=(fType+"-"+tm)){// 2 hours ---> 4 hours :make the 'default' filter default

    }
    betTypeIdShown=-1;
    scopeIdShown=-1;
    globalID = "";
	timeFilters=fType+"-"+tm;
	var	timeFilter = "&fType="+fType+"&tm="+tm;
	$("div_loadPicTab").style.display = "block";
	filters = new Hash(); 	//very important ,must be create an new object
	//filter = new Hash();
	var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
	                 onSuccess: function(response){filteTable=false;
	                 	    fillOddsTable(response);urlStatus = 'oddstable';
	                 	},
	                 onFailure: function(){processFailure();}});
	ajaxReq.send('/oddstable.do',timeFilter);
	ajaxReq=null;
	afterClickLeftTree();
}

function loadpopularMatches()
{
	//show pic to hint player to wait a moment
	var dom = document.getElementById("div_loadPicTabForPopular");
	if (!$defined(dom)){
		return;
	}
	dom.style.display = "block";
	
	//reset
	resetValueOfSearchedName();
	
	betTypeIdShown=-1;
	scopeIdShown=-1;
	timeFilters = null;
	var param='';
	if (needRefreshZoneOffset && $('gmtTimeZoneOffset')) {
        Cookie.set('OM_zone', $('gmtTimeZoneOffset').value,{duration: 3});         
        timeZoneAdjust();//in the clock.jsp which is used to show the current time
		param+='actFlag=set&gmtTimeZoneOffset='+$('gmtTimeZoneOffset').value;		
	}
	var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
                         onSuccess: function(response){ fillOddsTable(response);urlStatus = 'popularMatch';},
                         onFailure: function(){processFailure();}});
		ajaxReq.send('/popularMatch.do',param);
		ajaxReq=null;
}

/**
 * search Matches by searched name(player name, match name, tournament name) 
 */
function searchMatchesByName() {
	
	//reset parameters
	betTypeIdShown=-1;
	scopeIdShown=-1;
	timeFilters = null;
	
	var param='';
	var searchedName_0 = document.getElementById('searchedName').value;
	
	if(searchedName_0.length >=3 && searchedName_0.length <= 15) {
		
		searchedName = searchedName_0;
		
		//show pic to hint player to wait a moment
		var dom = document.getElementById("div_loadPicTabForPopular");
		if (!$defined(dom)){
			return;
		}
		dom.style.display = "block";
		
		param += 'searchedName='+ searchedName;
		var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
	                         onSuccess: function(response){ fillOddsTable(response);urlStatus = 'popularMatch';},
	                         onFailure: function(){processFailure();}});
			ajaxReq.send('/popularMatch.do', param);
			ajaxReq=null;
			
		chgHeadPicToSearchResult();	
		afterClickLeftTree();
		fillValue(document.getElementById('searchedName'));
	} else {
		showDiv("searchedNameErrorMessage");
	}
	
}

function loadTournamentORMatch(bannerParam)
{
	
	//reset the value of searchedName
	resetValueOfSearchedName();
	
	//show pic to hint player to wait a moment
	var dom = document.getElementById("div_loadPicTabForPopular");
	if (!$defined(dom)){
		return;
	}
	dom.style.display = "block";
	betTypeIdShown=-1;
	scopeIdShown=-1;
	timeFilters = null;
	var param='';
	if (needRefreshZoneOffset && $('gmtTimeZoneOffset')) {
        Cookie.set('OM_zone', $('gmtTimeZoneOffset').value,{duration: 3});         
        timeZoneAdjust();//in the clock.jsp which is used to show the current time
		param+='actFlag=set&gmtTimeZoneOffset='+$('gmtTimeZoneOffset').value;		
	}
	if(param.length>0) param+=bannerParam;
	else param+='x=1'+bannerParam;
	globalID = bannerParam.substr(1);
	
	var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
                         onSuccess: function(response){fillOddsTable(response);urlStatus = 'bannerEvent';changeHeadPic();},
                         onFailure: function(){processFailure();}});
		ajaxReq.send('/bannerEvent.do',param);
		ajaxReq=null;
}

function changeZoneOrOddsFormat(type,value){
	filterL = true;
	var timeParam="";
	if (timeFilters==""||timeFilters=="undefined"||timeFilters==null){
		timeFilters = "";
	}else{
		var typeTime = timeFilters.split("-");
		timeParam = "&fType="+typeTime[0]+"&tm="+typeTime[1];
	}
	if (_betTypeParam==""||_betTypeParam=="undefined"||_betTypeParam==null){
		_betTypeParam = "";
	}else{
		filteTable=true;
	}

	if (globalID==""||globalID=="undefined"){
		globalID = "";
	}
	var setParam = "&actFlag=set&gmtTimeZoneOffset=";
	if (type=='zone'){
		setParam += value;
	}else{
		setParam = "&oddsFormat="+value;
	}
	$("div_loadPicTab").style.display = "block";
	filters = new Hash(); 	//very important ,must be create an new object
	var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
	                 onSuccess: function(response){
	                 	    fillOddsTable(response);filteTable=false;
	                 	    var selOddsSelect = $('oddsFormat');
	                 	    if($defined(selOddsSelect)){
	                 	    	var selectedValue = selOddsSelect.value;
	                 	    	formatAllOdds(selectedValue);
	                 	    }
	                 	    
	                 	},
	                 onFailure: function(){processFailure();}});               
	ajaxReq.send(getUrl(),'id='+globalID+'&x='+(Math.random()*100)+timeParam+_betTypeParam+setParam);
	ajaxReq=null;

	
}

// betting type filter from Sharon 20090826
var submenu = '';
var ol_fgcolor = "#ffffff";
var ol_bgcolor = "#ffffff";
var ol_capcolor = "#000000";
var ol_textsize = '4';
var ol_textfontclass = 'ol_fonttext';
var ol_captionfontclass = 'ol_fontcaption';
var ol_bgclass = 'ol_bg';
function findPosX( obj ) {
	var curleft = 0;
	if ( obj.offsetParent ) {
		while ( obj.offsetParent ) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if ( obj.x )
		curleft += obj.x;
	return curleft;
}

function findPosY( obj ) {
	var curtop = 0;
	if ( obj.offsetParent ) {
		while ( obj.offsetParent ) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if ( obj.y )
		curtop += obj.y;
	return curtop;
}

function setLyr( obj, lyr ) {
	var newX = findPosX( obj );
	var newY = findPosY( obj );

	var x = new getObj( lyr );
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
}

function getObj( name ) {
	if ( document.getElementById ) {
	   this.obj = document.getElementById( name );
	   this.style = document.getElementById( name ).style;
	   return;
	}
	if ( document.all ) {
	   this.obj = document.all[ name ];
	   this.style = document.all[ name ].style;
	   return;
	}
	if ( document.layers ) {
		if ( document.layers[ name ] ) {
			this.obj = document.layers[ name ];
			this.style = document.layers[ name ];
		} else {
			this.obj = document.layers.testP.layers[ name ];
			this.style = document.layers.testP.layers[ name ];
	   }
	}
}

function showmenu( source, target ) {
	var x = new getObj( target );
	var obj = new getObj( source );
    x.style.visibility = 'visible';
	setLyr( obj.obj, target );
}

function hidemenu( target ) {
	var x = new getObj( target );
	x.style.visibility = 'hidden';
}

/**--start betting type tab event --**/
function changeBetTypeTab(inType) {
	if (inType=='1') {
		$('BetTypeTab').innerHTML="<a onclick=\"changeBetTypeTab('0')\">"+bettypesC+"</a>";
		//$('defaultBtRow').style.display='none';
		$('allBtRow').style.display='';
	} else {
		$('BetTypeTab').innerHTML="<a onclick=\"changeBetTypeTab('1')\">"+bettypesE+"</a>";	
		//$('defaultBtRow').style.display='';
		$('allBtRow').style.display='none';
	}
}

function changeBetTypeTabForBetexpress(inType) {
	if (inType=='1') {
		$('BetTypeTab').setStyle('background','url(http://imgprod.oddsmatrix.com/jsp/oddsmatrix/betexpress/style/images/listTypes_bg_down.jpg) no-repeat scroll 0 0');
		$('BetTypeTab').innerHTML="<a onclick=\"changeBetTypeTabForBetexpress('0')\">"+bettypesC+"</a>";
		//$('defaultBtRow').style.display='none';
		$('allBtRow').style.display='';
	} else {
		$('BetTypeTab').setStyle('background','url(http://imgprod.oddsmatrix.com/jsp/oddsmatrix/betexpress/style/images/listTypes_bg.jpg) no-repeat scroll 0 0');
		$('BetTypeTab').innerHTML="<a onclick=\"changeBetTypeTabForBetexpress('1')\">"+bettypesE+"</a>";	
		//$('defaultBtRow').style.display='';
		$('allBtRow').style.display='none';
	}
}

function setDefaultStatus() {
	$('singleBetTypeTd').innerHTML='';
	var idstr='MarketSelectionOff';
	if ($('filterBetType')) {
		if ($('MarketSelectionOn').innerHTML.search(defautFilter)>0) {
			idstr='MarketSelectionOn';
		}  
	}
	var divCss = new Element ('div',{'id':idstr});
	var filterLink=new Element('a',{'href': '#','filterValue': 'all','events': {'click': function(){applyFilter(this);}}});
	filterLink.injectInside(divCss);
	filterLink.setText(defautFilter);
	divCss.injectInside($('singleBetTypeTd'));
	return;
}
/**--end betting type tab event --**/