/*------- RTF irina ------*/
//this link should be set every time a user goes to another page and used when an error occurs and you need to reload the page.
var currentPageURL = null;
var currentPageParam = null;
var blinkingInternalX = 5*1000;
var blinkingInternalY = 25*1000;
var blinkingUnitTime = 300;
var rtfUpdates = false;
var isHebrew = false;
var m_names;//default value for month
var expandCellIsLink =false; // if expandCellIsLink is true,the expand cell will use href instead text
var counterHash = new Hash();
var minOddsNum=1;
var winnerButtonClass_off = 'ButtonOddsSelectorSmallOff';
var winnerButtonClass_on = 'ButtonOddsSelectorSmallOn';
//--to be processed: change this to true during development

var OddsTableModel = new Class({
	initialize : function(){
		this.disciplines = new Hash();
		this.addBetTypeMatches = '';
		this.emptyMatches = new Hash();
	},
	clearDiscipline:function() {
		this.disciplines = new Hash();		
	},
	countNrOfbo:function() {
		var nrOfBo = 0;
		var disciplines = this.disciplines.values();
		var disciplinesL = disciplines.length;
		for (var i =0; i<disciplinesL; i++){	
			if ($defined(disciplines[i]))	
				nrOfBo += disciplines[i].countNrOfbo();
		}
		this.nrOfBo = nrOfBo;
		return nrOfBo;
	},
	countBettypes:function() {
		var nrOfBettypes = 0;
		var disciplines = this.disciplines.values();
		var disciplinesL = disciplines.length;
		for (var i =0; i<disciplinesL; i++){	
			if ($defined(disciplines[i]))		
				nrOfBettypes += disciplines[i].countBettypes();
		}
		this.nrOfBettypes = nrOfBettypes;
		return nrOfBettypes;
	},
	countValidMatches:function() {
		var nrOfValidMatches = 0;
		var disciplines = this.disciplines.values();
		var disciplinesL = disciplines.length;
		for (var i = 0; i<disciplinesL; i++){	
			if ($defined(disciplines[i]))		
				nrOfValidMatches += disciplines[i].countValidMatches();
		}
		return nrOfValidMatches;		
	},
	addDiscipline: function( disc) {
		this.disciplines.set(disc.id, disc);
	},
	removeDiscipline:function(discId) {
		this.disciplines.set(discId);
	},
	getMatch: function(discId, countryId, tourId, evId){
		var disc = this.disciplines.get(discId);
		if (disc != null)
			return disc.getMatch(countryId, tourId, evId);
		return null;
	},
	setOddsValue: function(outcome){
		var disc = this.disciplines.get(outcome.dId);
		if (disc==null)
			return;
		if (isOutrightsBetType(outcome.typeId)) {
			//get previous value
			var outcomeArray = disc.getOdds(outcome.countryId, outcome.tourId, outcome.evId, outcome.typeId, outcome.scopeId, outcome.oddsId);
			if (outcomeArray==null)
				return;
				
			var oddsObj = outcomeArray[0];
			var outcomeInfo = outcomeArray[1];
			
			var oldValue = oddsObj.value;
			var oldFormattedValue = oddsObj.formattedValue;
			
			//change odds value and resort
			outcome.oV = outcome.oddsV;
			outcome.oId = outcome.oddsId;
			outcome.i1 = outcomeInfo.integerParameter;
			outcome.i2 = outcomeInfo.integerParameter2;
			outcome.i3 = outcomeInfo.integerParameter3;
			outcome.db1 = outcomeInfo.doubleParameter;
			outcome.db2 = outcomeInfo.doubleParameter2;
			outcome.rId = outcomeInfo.resultId;
		
			this.addOdds(outcome,'2');
			outcomeArray = disc.getOdds(outcome.countryId, outcome.tourId, outcome.evId, outcome.typeId, outcome.scopeId, outcome.oddsId);
			var oddsObj = outcomeArray[0];
			//make it blink
			oddsObj.setSimpleValue(oldValue,oldFormattedValue);
			oddsObj.setValue(outcome.oddsV, outcome.oddsFV,outcome.typeId);
			
			return;
		} else {
			disc.setOddsValue(outcome.countryId, outcome.tourId, outcome.evId, outcome.typeId, outcome.scopeId, outcome.oddsId, outcome.oddsV, outcome.oddsFV);
		}
	},	
	addBetType: function(betType) {
		var currentMatch = this.getMatch(betType.dId, betType.countryId, betType.tourId, betType.evId);
		if (currentMatch == null )
			return;
			
		if (getIsInNewExpandPage()) {
			//currentMatch.expanded = true;
			this.addBetTypeMatches = currentMatch.id;
		}	
		
		if (!(betType.typeId == currentMatch.tournament.defaultOutcomeType.betTypeId && betType.scopeId == currentMatch.tournament.defaultOutcomeType.scopeId 
			|| currentMatch.expanded || getIsInNewExpandPage())) {
			this.emptyMatches.set(betType.evId,currentMatch);
			return;
		}
			
		var currentBetType;
		var oldbetType = currentMatch.getBetType(betType.typeId, betType.scopeId);
		if ($defined(oldbetType)) {
			currentBetType = oldbetType;
		} else {
			currentBetType = new BetType(betType.typeId, betType.scopeId);
			currentBetType.setName(betType.betName);
		}
		var outcomes = betType.outcomes;
		for (var i =0; i< outcomes.length;i++){
			var outcome = outcomes[i];
			currentBetType.addOdds(outcome.db1,new Odds(outcome.oId, outcome.oV, outcome.oddsFV), outcome.i1, currentMatch);
			currentBetType.addExtraOutcomeInfo(outcome.oId, outcome.i1, outcome.i2,outcome.i3, outcome.db1, outcome.db2, outcome.rId);
		}
		currentBetType.removeFromDOM();
		currentMatch.addBetType(currentBetType, true);
		currentMatch.addBetTypeToDOM(currentBetType);
		
	},
	showEmptyMatches:function() {
		//these are the matches without default bet type, so make their match line empty 
		var matches = this.emptyMatches.values();
		for (var i=0;i<matches.length;i++) {
			var match = matches[i];
			if (!match.hasDefaultBetType()) {
				match.showEmptyOddsMatch(2);
			}			
		}
		this.emptyMatches.empty();
	},
	deleteBetType: function(betType){
		var match = this.getMatch(betType.dId, betType.countryId, betType.tourId, betType.evId);
		if (match!=null){
			match.deleteBetTypeRows(betType.typeId, betType.scopeId, betType.dbParam1);
			//this.involvedMatches.set(match.id,null);
		}
	},
	deleteOdds: function(outcome){
		var match = this.getMatch(outcome.dId, outcome.countryId, outcome.tourId, outcome.evId);
		if (match == null)
			return;
		var betType = match.getBetType(outcome.typeId, outcome.scopeId);
		if (betType == null)
			return;
		betType.deleteOdds(outcome.oddsId);
		if (isMultiRowBetType(betType.typeId) && betType.odds.keys().length > 0){ 
			//remove bet type
			betType.removeFromDOM();
			match.addBetType(betType, true);
			//add it again - this will reorder the outcomes 
			match.addBetTypeToDOM(betType);
		}
	}, 
	deleteMatch: function(match) {
		var match = this.getMatch(match.dId, match.countryId, match.tourId, match.evId);
		if (match!=null){
			match.deleteMatch();
			//this.involvedMatches.set(match.id,null);
		}
	},
	suspendMatch: function(match) {
		var match = this.getMatch(match.dId, match.countryId, match.tourId, match.evId);
		if (match!=null){
			match.suspendMatch();
			//this.involvedMatches.set(match.id,null);
		}
	},
	addOdds : function (outcome,operType){
		var match = this.getMatch(outcome.dId, outcome.countryId, outcome.tourId, outcome.evId);
		if (match == null)
			return;
		var betType = match.getBetType(outcome.typeId, outcome.scopeId);
		if (betType == null)
			return;
		//first, remove the bet type from memory and DOM
		if (outcome.typeId == match.tournament.defaultOutcomeType.betTypeId && outcome.scopeId == match.tournament.defaultOutcomeType.scopeId){
			betType.removeFromDOM(operType,outcome.dId);
			//then add the new odds
			betType.addOdds(outcome.db1,new Odds(outcome.oId, outcome.oV, outcome.oddsFV), outcome.i1, match);
			betType.addExtraOutcomeInfo(outcome.oId, outcome.i1, outcome.i2,outcome.i3, outcome.db1, outcome.db2, outcome.rId);
			match.addBetTypeToDOM(betType);
		}
		else {
			betType.removeFromDOM(operType,outcome.dId);
			//then add the new odds
			betType.addOdds(outcome.db1,new Odds(outcome.oId, outcome.oV, outcome.oddsFV), outcome.i1, match);
			betType.addExtraOutcomeInfo(outcome.oId, outcome.i1, outcome.i2,outcome.i3, outcome.db1, outcome.db2, outcome.rId);
			// now add the new bet type and append it to DOM
			match.addBetType(betType, true);
			match.addBetTypeToDOM(betType);
		}
	},
	updateNumberOfOutrights : function (num) {
		var match = this.getMatch(num.dId, num.countryId, num.tourId, num.evId);
		if (match!= null) {
			match.updateOrCreateExtraCell(num.number);
		}
	},
	updateMatchInfo:function(match) {		
		var matchObj = this.getMatch(match.dId, match.countryId, match.tourId, match.evId);
		if (matchObj!=null){
			matchObj.updateHourCell(match.score,match.matchStatus,match.matchTimeMin,match.matchTimeType,match.betStatus,match.gs,match.ps,match.ss,match.server,match.team,match.remainTime);
			if (matchObj.showLive() && matchObj.getBetTypeObjs().length==0)
				matchObj.showEmptyOddsMatch('2');
		}
	},
	refreshTimeCounter:function() {
		return;
		var matchIds = this.involvedMatches.keys();
		for (var i=0;i<matchIds.length;i++) {
			lbtcCunter.refreshEvents(matchIds[i]);			
		}
		this.involvedMatches.empty();
	}
});

var CommunicationHandlerRTF = new Class ({
	initialize: function(url){
		this.url=url;
	},
	sendRequest: function(param){
		if($defined(this.channel)){
			this.channel.cancel();
			this.channel=null;
		}
		if(param.indexOf('closeSession')==-1 ){
			this.channel=new XHR({	'method': 'post',
										'autoCancel': 'true',
										onSuccess: function(response){
											processRTFUpdate(response);
										}, 
										onFailure: function() {
										}
									});
		}
		else {
			this.channel=new XHR({ 'method': 'post',
									   'autoCancel': 'true',
									  onSuccess: function(response){
									  		afterCloseConnection(response);}, 
									  onFailure: function(response){
											afterCloseConnection(response);}
									  });
		}
		this.channel.send(this.url , param);
	},
	cancel: function(){
		if($defined(this.channel))
			this.channel.cancel();
		this.channel=null;
	}
});

function processFailure1(){
}
var reqId = 1;
var rtfUpdateSocket = new CommunicationHandlerRTF('/rtfOddsUpdates.do');

function setRtfUpdates() {
	if (!rtfUpdates)
		return;
		
	var needRtf = true;
	//if there is not any match , set rtfUpdates to false,
	//otherwise keep it unchanged from the value set by backend
	var disciplines = oddsTableModel.disciplines.keys();
	if (disciplines.length<=0) {
		needRtf = false;
	} else {
		var validMatches = oddsTableModel.countValidMatches();
		if (validMatches<=0)
			needRtf = false;			
	}
	if (!needRtf) {
		closeConnection();
		rtfUpdates = false;
	}
}

function goForUpdates(){
	setRtfUpdates();
	if (!rtfUpdates)
		return;
	rtfUpdateSocket.sendRequest("rand=" + Math.random()+'&reqId='+reqId);
	reqId +=1;
}
function closeConnection(){
   if (rtfUpdates) {    	
        Cookie.remove('currentRTFnum');
        if(!window.ie)
    		rtfUpdateSocket.sendRequest('closeSession=2&reqId='+reqId);
    	else 
    		rtfUpdateSocket.sendRequest('closeSession=2&rand=' + Math.random()+'&reqId='+reqId);
   }
}
function afterCloseConnection(response) {
	if (response.length >0){
		var res = jsonParse(response);
		var rtfUpdateValue = res.rtfUpdateValue;
		if ($defined(rtfUpdateValue)){
			rtfUpdates = rtfUpdateValue;
			updateRtfStatus();
		}
	}
	rtfUpdateSocket.cancel();
}

window.onbeforeunload = function () {
    closeConnection();
}
function closeRTFConnection() {
	closeConnection();
}
window.unload = function(){
	closeConnection();
}
function reloadOddsTable() {
		
	closeConnection();
	//reload current page and then redraw the page
	var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
				onSuccess: function(response){
					fillOddsTable(response);
					resetEPrightBox();//reset EP part of page.
					hideBetTypeTab();
				},
				onFailure: function(){processFailure();}});
				ajaxReq.send(currentPageURL, currentPageParam);
				ajaxReq=null;
}
	
function processRTFUpdate(response){
	updateRtfStatus();
	
	if (response.length < 2){
		goForUpdates();
		return;
	}
	
	var res = jsonParse(response);
	var responseArray = jsonParse(response);
	var responseArrayLen = responseArray.length;

	for (var x=0;x<responseArrayLen;x++) {
		var res = responseArray[x];
	
		var rtfUpdateValue = res.rtfUpdateValue;
		if ($defined(rtfUpdateValue)){
			rtfUpdates = rtfUpdateValue;
			updateRtfStatus();
		}
		
		var reload = res.reloadOddsTable;
		if ($defined(reload)){
			reloadOddsTable();
			return;
		}
		
		var updateMatchInfo = res.updateMatchInfo;
		if ($defined(updateMatchInfo)){
			for (var i = 0; i< updateMatchInfo.length ;i++ ){
				var updateMatchInfoRow = updateMatchInfo[i];
				oddsTableModel.updateMatchInfo(updateMatchInfoRow);
			}	
			startTimeCounter();
		}
		
		var suspendMatch = res.suspendMatch;
		if ($defined(suspendMatch)){
			for (var i = 0; i< suspendMatch.length ;i++ ){
				var suspendMatchRow = suspendMatch[i];
				oddsTableModel.suspendMatch(suspendMatchRow);
			}	
		}
		
		var deleteMatch = res.deleteMatch;
		if ($defined(deleteMatch)){
			for (var i = 0; i< deleteMatch.length ;i++ ){
				var deleteMatchRow = deleteMatch[i];
				oddsTableModel.deleteMatch(deleteMatchRow);
			}	
		}
		
		var deleteBetType = res.deleteBetType;
		if ($defined(deleteBetType)){
			for (var i = 0; i< deleteBetType.length ;i++ ){
				var deleteRow = deleteBetType[i];
				oddsTableModel.deleteBetType(deleteRow);
			}	
		}
		var deleteOdds = res.deleteOdds;
		if ($defined(deleteOdds)){
			for (var i = 0; i< deleteOdds.length ;i++ ){
				var oldOdds = deleteOdds[i];
				oddsTableModel.deleteOdds(oldOdds);
			}
		}
		var numberOfOutrightsUpdates = res.numberOfOutrights;
		if ($defined(numberOfOutrightsUpdates)) {
			for (var i = 0; i< numberOfOutrightsUpdates.length ;i++ ){
				var newNumber = numberOfOutrightsUpdates[i];
				oddsTableModel.updateNumberOfOutrights(newNumber);
			}
		}
		var newBetTypes = res.newBetTypes;
		if ($defined(newBetTypes)){
			for (var i = 0; i< newBetTypes.length ;i++ ){
				var newBetType = newBetTypes[i];
				oddsTableModel.addBetType(newBetType);
			}			
			
			//show all odds of a match when new bet type is added and it's in new expand page 
			if (oddsTableModel.addBetTypeMatches!='') {
				if (typeof(match0)!== 'undefined' && match0!=null && oddsTableModel.addBetTypeMatches == match0.id && !match0.expanded) {
					match0.expandFully();
				}
				oddsTableModel.addBetTypeMatches = '';
			}
		
			//if it was a SM match and now start but new bettype is not default bettype,we should show empty row.
			oddsTableModel.showEmptyMatches();
		}
		var newOdds = res.newOdds;
		if ($defined(newOdds)){
			for (var i = 0; i< newOdds.length ;i++ ){
				var newOutcome = newOdds[i];
				oddsTableModel.addOdds(newOutcome);
			}
		}
		var changeOdds = res.updateOdds;
		if ($defined(changeOdds)){
			for (var i = 0; i< changeOdds.length ;i++ ){
				var updateOdds = changeOdds[i];
				oddsTableModel.setOddsValue(updateOdds);
			}
		}
		
		//	var balanceUpdates = res.balance;
		//	if ($defined(balanceUpdates)) {
		//		showTheBalanceOnDiv(balanceUpdates);
		//	}
		
		
//		if (myplatform != 'prod') {
//			var checkSum = res.checkSum;
//			if ($defined(checkSum)){		
//				var nrOfbo = oddsTableModel.countNrOfbo();
//				var betTypesNum = oddsTableModel.countBettypes();
//				if (nrOfbo!=checkSum[0].nrOfbo || betTypesNum!=checkSum[0].betTypes) {
//					reloadOddsTable();
//					return;
//				}
//			}
//		}
	}
	date_start_timeout = new Date();
	goForUpdates();
}

var oddsTableModel = new OddsTableModel();


/*-------end RTF irina ------*/
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;
	},
	setText: function(t){
	//should be used when updating odds
		this.text = t;
	}
});

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.GREYHOUNDS = 27;
    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.HORSERACEING = 24;
    this.CRICKET = 26;
	this.FUTSAL = 49;
    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;
		this.TYPE_ID_GAME_OVER_UNDER                               		= 100;
		this.TYPE_ID_HEAD_2                              				= 124;
		this.TYPE_ID_HEAD_3                              				= 128;
		this.TYPE_ID_TEAM_KICKS_OFF										= 501;
		this.TYPE_ID_TEAM_WINS_REST_MATCH								= 502;
		this.TYPE_ID_NEXT_GOAL											= 503;
    	this.TYPE_ID_JUMP_BALL                                          = 504;
    	this.TYPE_ID_GOALS_HOME_TEAM                                    = 505;
    	this.TYPE_ID_GOALS_AWAY_TEAM                                    = 506;
    	this.TYPE_ID_GOALS_NOGOALS                                      = 507;
    	this.TYPE_ID_SETS_NUMBER_3                                      = 508;
    	this.TYPE_ID_SETS_NUMBER_5                                      = 509;
    	this.TYPE_ID_Score_gameX_setN                                   = 510;
    	this.TYPE_ID_Who_wins_gameX_setN                                = 511;
    	this.TYPE_ID_Who_win_gamesXY_setN                               = 512;
	}
});

function isMultiRowBetType(betType) {
	if (betType == betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE ||
		betType == betTypes.TYPE_ID_TOP_X || 
		betType == betTypes.TYPE_ID_WINNER || 
		betType == betTypes.TYPE_ID_TOP_GOALSCORER || 
		betType == betTypes.TYPE_ID_RELEGATION || 
		betType == betTypes.TYPE_ID_PROMOTION ||
		betType == betTypes.TYPE_ID_ROCK_BOTTOM ||
		betType == betTypes.TYPE_ID_POLE_POSITION || 
		betType == betTypes.TYPE_ID_FASTEST_LAP ||
		betType == betTypes.TYPE_ID_FIRST_TO_RETIRE || 
		betType == betTypes.TYPE_ID_FIRST_LAP_LEADER ||
		betType == betTypes.TYPE_ID_HALF_TIME_FULL_TIME ||
		betType == betTypes.TYPE_ID_GOALS_HOME_TEAM ||
		betType == betTypes.TYPE_ID_GOALS_AWAY_TEAM ||
		betType == betTypes.TYPE_ID_HEAD_2 ||
		betType == betTypes.TYPE_ID_HEAD_3) {
		
		return true;
		
	}
	return false;
}
function isMultiGroupBetType(betType) {
	if (
		betType == betTypes.TYPE_ID_HEAD_2 ||
		betType == betTypes.TYPE_ID_HEAD_3) {
		
		return true;
		
	}
	return false;
}
function isOutrightsBetType(betType) {
	if (
		betType == betTypes.TYPE_ID_TOP_X || 
		betType == betTypes.TYPE_ID_WINNER || 
		betType == betTypes.TYPE_ID_TOP_GOALSCORER || 
		betType == betTypes.TYPE_ID_RELEGATION || 
		betType == betTypes.TYPE_ID_PROMOTION ||
		betType == betTypes.TYPE_ID_ROCK_BOTTOM ||
		betType == betTypes.TYPE_ID_POLE_POSITION || 
		betType == betTypes.TYPE_ID_FASTEST_LAP ||
		betType == betTypes.TYPE_ID_FIRST_TO_RETIRE || 
		betType == betTypes.TYPE_ID_FIRST_LAP_LEADER) {
		
		return true;
		
	}
}
function isParamBetType(betType) {
	if (betType == betTypes.TYPE_ID_OVER_UNDER ||
		betType == betTypes.TYPE_ID_ASIAN_HANDICAP ||
		betType == betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP ||
		betType == betTypes.TYPE_ID_SET_HANDICAP ||
		betType == betTypes.TYPE_ID_GAME_HANDICAP ||
		betType == betTypes.TYPE_ID_GAME_HANDICAP_WITH_DRAW ||
		betType == betTypes.TYPE_ID_GAME_OVER_UNDER) {
		
		return true;
	}
	else 
		return false;
}
function isEmptyMatchLineBetType(betType) {
	if (betType == betTypes.TYPE_ID_Score_gameX_setN ||
		betType == betTypes.TYPE_ID_Who_win_gamesXY_setN){		
		return true;
	}
	else 
		return false;
}
function isTwoCellBetType(betType) {
	if(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW== betType
		|| betTypes.TYPE_ID_ODD_OR_EVEN == betType  
		|| betTypes.TYPE_ID_TEAM_KICKS_OFF == betType 
		|| betTypes.TYPE_ID_HOME_AWAY_WITH_POSSIBLE_DRAW == betType
		|| betTypes.TYPE_ID_NEXT_TEAM_TO_SCORE == betType
		|| betTypes.TYPE_ID_NEXT_GOAL == betType
		|| betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE == betType
		|| betTypes.TYPE_ID_GOALS_HOME_TEAM == betType 
		|| betTypes.TYPE_ID_GOALS_AWAY_TEAM == betType 
		|| betTypes.TYPE_ID_GOALS_NOGOALS == betType ){
		return true;
	} else
		return false;
}
function isSmallBtnBetType(betType) {
	if (betType == betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE ||
		betType == betTypes.TYPE_ID_TOP_X || 
		betType == betTypes.TYPE_ID_WINNER || 
		betType == betTypes.TYPE_ID_TOP_GOALSCORER || 
		betType == betTypes.TYPE_ID_RELEGATION || 
		betType == betTypes.TYPE_ID_PROMOTION ||
		betType == betTypes.TYPE_ID_ROCK_BOTTOM ||
		betType == betTypes.TYPE_ID_POLE_POSITION || 
		betType == betTypes.TYPE_ID_FASTEST_LAP ||
		betType == betTypes.TYPE_ID_FIRST_TO_RETIRE || 
		betType == betTypes.TYPE_ID_FIRST_LAP_LEADER ||
		betType == betTypes.TYPE_ID_HALF_TIME_FULL_TIME ||
		betType == betTypes.TYPE_ID_GOALS_HOME_TEAM ||
		betType == betTypes.TYPE_ID_GOALS_AWAY_TEAM ||
		betType == betTypes.TYPE_ID_HEAD_2 ||
		betType == betTypes.TYPE_ID_HEAD_3) {
		
		return true;
		
	}
	return false;
}
function isWinnerBtnBetType(betType){
	if (betType == betTypes.TYPE_ID_TOP_X || 
		betType == betTypes.TYPE_ID_WINNER || 
		betType == betTypes.TYPE_ID_TOP_GOALSCORER || 
		betType == betTypes.TYPE_ID_RELEGATION || 
		betType == betTypes.TYPE_ID_PROMOTION ||
		betType == betTypes.TYPE_ID_ROCK_BOTTOM ||
		betType == betTypes.TYPE_ID_POLE_POSITION || 
		betType == betTypes.TYPE_ID_FASTEST_LAP ||
		betType == betTypes.TYPE_ID_FIRST_TO_RETIRE || 
		betType == betTypes.TYPE_ID_FIRST_LAP_LEADER ||
		betType == betTypes.TYPE_ID_HEAD_2 ||
		betType == betTypes.TYPE_ID_HEAD_3) {		
		return true;
		
	}
	return false;
}
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,BTH_NEXT_TEAM_TO_SCORE,//8,9,11,21,35,39,43,45,46,47,48,28,12
	                    
	                    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,
	                    
	                    BTH_GOAL_NOGOAL,BTH_HEAD_2,BTH_HEAD_3
	                    
	                    ){//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_GOAL_NOGOAL = new BetTypeHeadTitle(507,BTH_GOAL_NOGOAL);
		this.HEADTITLE_OVER_UNDER = new BetTypeHeadTitle(47,BTH_OVER_UNDER);
		this.HEADTITLE_ASIAN_HANDICAP = new BetTypeHeadTitle(48,BTH_ASIAN_HANDICAP);
		this.HEADTITLE_NEXT_TEAM_TO_SCORE = new BetTypeHeadTitle(12,BTH_NEXT_TEAM_TO_SCORE);
		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);		
		
		this.HEADTITLE_HEAD_2 =  new BetTypeHeadTitle(124,BTH_HEAD_2);	
		this.HEADTITLE_HEAD_3 =  new BetTypeHeadTitle(128,BTH_HEAD_3);	
	},
	getHEADTITLE_TOP_X_withParam:function (topXParam) {
		this.HEADTITLE_TOP_X_withParam.setDrawText(topXParam);	
		return this.HEADTITLE_TOP_X_withParam;	
	},
	setHEADTITLE_HOME_DRAW_AWAY:function(title){
		this.HEADTITLE_HOME_DRAW_AWAY=new BetTypeHeadTitle(43,title);
	},
	setHEADTITLE_HOME_DRAW_AWAY_WITH_HANDICAP:function(title){
		this.HEADTITLE_HOME_DRAW_AWAY_WITH_HANDICAP=new BetTypeHeadTitle(8,title);
	},
	setHEADTITLE_OVER_UNDER_TENNIS:function(title){
		this.HEADTITLE_OVER_UNDER_TENNIS = new BetTypeHeadTitle(47,title);
	},
	setHEADTITLE_OVER_UNDER_FIGHTING:function(title){
		this.HEADTITLE_OVER_UNDER_FIGHTING = new BetTypeHeadTitle(47,title);
	},
	setHEADTITLE_GAME_HANDICAP_TENNIS:function(title){
		this.HEADTITLE_GAME_HANDICAP_TENNIS = new BetTypeHeadTitle(39,title);
	},
	setHEADTITLE_SET_HANDICAP_TENNIS:function(title){
		this.HEADTITLE_SET_HANDICAP_TENNIS = new BetTypeHeadTitle(38,title);
	},
	setHEADTITLE_OVER_UNDER_PARAM_Point:function(title){
		this.HEADTITLE_OVER_UNDER_PARAM_Point = new BetTypeHeadTitle(47,title);
	},	
	setHEADTITLE_ODD_EVEN_PARIS365_POINTS:function(title){
		this.HEADTITLE_ODD_EVEN_PARIS365_POINTS = new BetTypeHeadTitle(35,title);
	},
	setHEADTITLE_ODD_EVEN_PARIS365_GOALS:function(title){
		this.HEADTITLE_ODD_EVEN_PARIS365_GOALS = new BetTypeHeadTitle(35,title);
	},
	setHEADTITLE_ODD_EVEN_TENNIS:function(title){
		this.HEADTITLE_ODD_EVEN_TENNIS = new BetTypeHeadTitle(35,title);
	},
	setHEADTITLE_Score_gameX_setN:function(title){
		this.HEADTITLE_Score_gameX_setN = new BetTypeHeadTitle(510,title);
	},	
	setHEADTITLE_Who_wins_gameX_setN:function(title){
		this.HEADTITLE_Who_wins_gameX_setN = new BetTypeHeadTitle(511,title);
	},	
	setHEADTITLE_GAME_OVER_UNDER:function(title){
		this.HEADTITLE_GAME_OVER_UNDER = new BetTypeHeadTitle(100,title);
	},	
	setHEADTITLE_OVER_UNDER_RUNS:function(title){
		this.HEADTITLE_OVER_UNDER_RUNS = new BetTypeHeadTitle(47,title);
	}	
});

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){
		//alert(dateString);
		//var rezDate=new Date(0);
		var rez=dateString.match(this.dateRegex);
		var rezDate=new Date(rez[1], parseFloat(rez[2])-1, parseFloat(rez[3]), parseFloat(rez[4]), parseFloat(rez[5]), 0, 0);
		/*rezDate.setYear(rez[1]);	
		rezDate.setMonth(parseFloat(rez[2] -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);
	
	showRtfStatus();
	
	
}

function showRtfStatus() {	
	if (myplatform == 'prod')
		return;
	var rtfMessageRow = new Element('tr');
	var rtfTd = new Element('td',{'id':'rtfMessage','colspan':'4'});
	var rtfTd2 = new Element('td',{'id':'rtfMessage2','colspan':'4','style':'color:white'});
	
	rtfTd.setHTML(getRtfStatus());
	rtfTd.injectInside(rtfMessageRow);
	rtfTd2.injectInside(rtfMessageRow);
	rtfMessageRow.injectInside(topTableBody);	
}

function updateRtfStatus() {
	if (myplatform == 'prod')
		return;
		
	var rtfTd = $('rtfMessage');
	if ($defined(rtfTd)) {
		rtfTd.setHTML(getRtfStatus());
	}
}
function getRtfStatus() {		
	var message = '';
	if (rtfUpdates) {
		message = rtfYes;
	} else {
		message = rtfNo;
	}
	return message;
}

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'});
		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'});
		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);
	},
	countNrOfbo:function() {
		var nrOfBo = 0;
		var countries = this.countries.values();
		var countriesL = countries.length;
		for (var i =0; i<countriesL; i++){		
			if ($defined(countries[i]))		
				nrOfBo += countries[i].countNrOfbo();
		}
		this.nrOfBo = nrOfBo;
		return nrOfBo;
	},
	countBettypes:function() {
		var nrOfBettypes = 0;
		var countries = this.countries.values();
		var countriesL = countries.length;
		for (var i =0; i<countriesL; i++){		
			if ($defined(countries[i]))		
				nrOfBettypes += countries[i].countBettypes();
		}
		this.nrOfBettypes = nrOfBettypes;
		return nrOfBettypes;
	},
	countValidMatches:function() {
		var nrOfValidMatches = 0;
		var countries = this.countries.values();
		var countriesL = countries.length;
		for (var i =0; i<countriesL; i++){		
			if ($defined(countries[i]))		
				nrOfValidMatches += countries[i].countValidMatches();
		}
		return nrOfValidMatches;
	},
	addCountry: function(country){
		country.setDiscipline(this);
		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_om(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){
		var zoneAndOddsFormatStr = '';
		if ($("zoneAndOddsFormat")!=null) {
			zoneAndOddsFormatStr = $("zoneAndOddsFormat").innerHTML;
		}
		this.name=name+zoneAndOddsFormatStr;
		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);
	},
	setOddsValue: function (countryId, tourId, evId, betType, scopeId, oddsId, oddsValue,formattedValue){
		var country = this.countries.get(countryId);
		if (country != null)
			country.setOddsValue(tourId, evId, betType, scopeId, oddsId, oddsValue, formattedValue);
	},
	getMatch: function (countryId, tourId, evId){
		var country = this.countries.get(countryId);
		if (country!=null)
			return country.getMatch(tourId, evId);
		return null;
	},
	getOdds: function (countryId, tourId, evId, betType, scopeId, oddsId){
		var country = this.countries.get(countryId);
		if (country != null)
			return country.getOdds(tourId, evId, betType, scopeId, oddsId);
	},
	removeCountry:function(country) {
		this.countries.remove(country);
		if (this.countries.length==0) {
			this.removeDisciplineFromDom();
			oddsTableModel.removeDiscipline(this.id);
		}
	},
	removeDisciplineFromDom:function() {
		this.elementLine.remove();
	}
});

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);
	},
	countNrOfbo:function() {
		var nrOfBo = 0;
		var tournaments = this.tournaments.values();
		var tournamentsL = tournaments.length;
		for (var i =0; i<tournamentsL; i++){		
			if ($defined(tournaments[i]))			
				nrOfBo += tournaments[i].countNrOfbo();
		}
		this.nrOfBo = nrOfBo;
		return nrOfBo;
	},
	countBettypes:function() {
		var nrOfBettypes = 0;
		var tournaments = this.tournaments.values();
		var tournamentsL = tournaments.length;
		for (var i =0; i<tournamentsL; i++){			
			if ($defined(tournaments[i]))		
				nrOfBettypes += tournaments[i].countBettypes();
		}
		this.nrOfBettypes = nrOfBettypes;
		return nrOfBettypes;
	},
	countValidMatches:function() {
		var nrOfValidMatches = 0;
		var tournaments = this.tournaments.values();
		var tournamentsL = tournaments.length;
		for (var i =0; i<tournamentsL; i++){			
			if ($defined(tournaments[i]))		
				nrOfValidMatches += tournaments[i].countValidMatches();
		}
		return nrOfValidMatches;
	},
	setDiscipline:function(discipline) {
		this.discipline = discipline;
	},
	addTournament: function(tournament){
		this.tournaments.set(tournament.id,tournament);
		//this.appendCategChildRow(tournament);
		this.appendCategChildRow(tournament);//,
		tournament.setCountry(this);
	}, 
	getTournament:function(tournamentId) {
		var tournament = this.tournaments.get(tourId);
		return tournament;
	},
	removeTournament:function(tournamentId) {
		this.tournaments.remove(tournamentId);
		//delete this country if this is the last tournament
		if (this.tournaments.length ==0) {
			this.removeCountryFromDom();
			this.discipline.removeCountry(this.id);		
		}
	},
	setOddsValue: function(tourId, evId, betType, scopeId, oddsId, oddsV, formattedValue){
		var tournament = this.tournaments.get(tourId);
		if (tournament != null)
			tournament.setOddsValue(evId, betType, scopeId, oddsId, oddsV, formattedValue);
	},
	getOdds: function(tourId, evId, betType, scopeId, oddsId){
		var tournament = this.tournaments.get(tourId);
		if (tournament != null)
			return tournament.getOdds(evId, betType, scopeId, oddsId);
	},
	getMatch: function(tourId, evId){
		var tournament = this.tournaments.get(tourId);
		if (tournament != null)
			return tournament.getMatch(evId);
		return null;
	},
	removeCountryFromDom:function() {
		this.elementLine.remove();
	}
});


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;
	},
	countNrOfbo:function() {
		var nrOfBo = 0;
		var matches = this.matches.values();
		var matchesL = matches.length;
		for (var i =0; i<matchesL; i++){		
			if ($defined(matches[i]))			
				nrOfBo += matches[i].countNrOfbo();
		}
		this.nrOfBo = nrOfBo;
		return nrOfBo;
	},
	countBettypes:function() {
		var nrOfBettypes = 0;
		var matches = this.matches.values();
		var matchesL = matches.length;
		for (var i =0; i<matchesL; i++){		
			if ($defined(matches[i]))			
				nrOfBettypes += matches[i].countBettypes();
		}
		this.nrOfBettypes = nrOfBettypes;
		return nrOfBettypes;
	},
	countValidMatches:function() {
		var nrOfValidMatches = 0;
		var matches = this.matches.values();
		var matchesL = matches.length;
		for (var i =0; i<matchesL; i++){		
			if ($defined(matches[i]))			
				nrOfValidMatches += matches[i].countValidMatches();
		}
		return nrOfValidMatches;
	},
	removeTournamentFromDom:function() {
		this.elementLine.remove();
	},
	setCountry: function(country){
		this.country=country;
	},
	getHeadDivId:function() {
		var divId='MarketH1';
		if (getIsInNewExpandPage()){
			divId='MarketH2';
		}
		return divId;
	},
	setNameWithDiv: function(name,nameForTitle){
		this.name=name;
		var className = this.getHeadDivId();
		var tourNameCell = new Element('td',{'colspan':'4','width':'80%','class':'tourTitle'});
		//tourNameCell.setStyle('border-bottom','0px');
		tourNameCell.setHTML('<div id="'+className+'"><div id="GameHeadline"><p>'+nameForTitle+'</p></div></div>');
		tourNameCell.injectInside(this.elementLine);
	},
	setNameWithScope: function(name,nameForTitle,scopeName){
		var nameCell = this.elementLine.getElement('.tourTitle');
		if (nameCell!=null) {
			nameCell.remove();
		}
		tourName = nameForTitle;		
		var braket1=tourName.indexOf("(");
		var braket2=tourName.indexOf(")");
		if (braket1>0 && braket2 > 0 && braket2 > braket1){
			tourName = tourName.replace(/(\(.+\))/g,'<label class=\'bt TourName\'>$1</label>');
		}
		nameForTitle=tourName;
		this.name=name;
		var className = this.getHeadDivId();
		var tourNameCell = new Element('td',{'colspan':'4','width':'80%','class':'tourTitle'});
		//tourNameCell.setStyle('border-bottom','0px');	
		var BtScope = '<label  class="BtScope">'+scopeName+'</label>';
		if (getIsInNewExpandPage()) {
			BtScope = scopeName;
		}	
		tourNameCell.setHTML('<div id="'+className+'"><div id="GameHeadline"><p><label class=TourName>'+nameForTitle+'</label>'+BtScope+'</p></div></div>');
		
		tourNameCell.injectInside(this.elementLine);
	},
	addMatch: function(match,imgId){
		if(!match.showDefaultBetType() && betTypeIdShown!=-1 && scopeIdShown!=-1 && !match.showLive())
			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);
	},
	removeMatch: function(matchId){
		this.matches.remove(matchId);
		//if this was the last match - we should also delete the tournament
		if (this.matches.length ==0) {			
			this.removeTournamentFromDom();
			this.country.removeTournament(this.id);
		}		
	},
	getMatch: function(evId){
		var match = this.matches.get(evId);
		return match;
	},
	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){
		var className = this.getHeadDivId();
		var cellHome=new Element('td',{'class':'oddsCell'});//,'style':'border-bottom:0px;'
		cellHome.setHTML('<div id="'+className+'"><div id="GameHeadline1X2"><p>'+cellHomeText+'</p></div></div>');
		var cellX=new Element('td',{'class':'oddsCell'});
		cellX.setHTML('<div id="'+className+'"><div id="GameHeadline1X2"><p>'+cellXText+'</p></div></div>');
		var cellAway=new Element('td',{'class':'oddsCell'});
		cellAway.setHTML('<div id="'+className+'"><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);
	},
	getTitle : function(betTypeId) {
		if (betTypeId == null) {
			betTypeId = this.defaultOutcomeType.betTypeId;
		}
		
		var titleTmp = headTitle.HEADTITLE_OTHER;
		if((betTypeId==betTypes.TYPE_ID_HOME_DRAW_AWAY	)||
			(betTypeId==betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP)||
			(betTypeId==betTypes.TYPE_ID_TEAM_WINS_REST_MATCH)){
			titleTmp = headTitle.HEADTITLE_HOME_DRAW_AWAY_WITH_HANDICAP;
		}
		else if(betTypeId==betTypes.TYPE_ID_NEXT_TEAM_TO_SCORE
				|| betTypeId==betTypes.TYPE_ID_NEXT_GOAL){
				titleTmp = headTitle.HEADTITLE_NEXT_TEAM_TO_SCORE;
		}
		else if(betTypeId==betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW ||
					betTypeId==betTypes.TYPE_ID_HOME_AWAY_WITH_POSSIBLE_DRAW ||
					betTypeId==betTypes.TYPE_ID_TEAM_KICKS_OFF){
				titleTmp = headTitle.HEADTITLE_HOME_AWAY_WITH_IMPOSSIBLE_DRAW;
		}
		else if( betTypeId==betTypes.TYPE_ID_GOALS_NOGOALS){
				titleTmp = headTitle.HEADTITLE_GOAL_NOGOAL;
		}
		else if((betTypeId==betTypes.TYPE_ID_ASIAN_HANDICAP) ||
				(betTypeId==betTypes.TYPE_ID_GAME_HANDICAP) ||
				(betTypeId==betTypes.TYPE_ID_SET_HANDICAP)	){
			          titleTmp = headTitle.HEADTITLE_ASIAN_HANDICAP;
				       if (this.country.discipline.id==disciplineIds.TENNIS){
							if (betTypeId==betTypes.TYPE_ID_GAME_HANDICAP){
								titleTmp = headTitle.HEADTITLE_GAME_HANDICAP_TENNIS;
							}else if (betTypeId==betTypes.TYPE_ID_SET_HANDICAP){
								titleTmp = headTitle.HEADTITLE_SET_HANDICAP_TENNIS;
							}
						}
		}
		else if((betTypeId==betTypes.TYPE_ID_OVER_UNDER)){
				titleTmp = headTitle.HEADTITLE_OVER_UNDER;
				if (this.country.discipline.id==disciplineIds.TENNIS){// just for tennis
					titleTmp = headTitle.HEADTITLE_OVER_UNDER_TENNIS;
				}
				else if (this.country.discipline.id==disciplineIds.FIGHTING){
					titleTmp = headTitle.HEADTITLE_OVER_UNDER_FIGHTING;
				}else if(this.country.discipline.id==disciplineIds.AM_FOOTBALL || this.country.discipline.id==disciplineIds.BASEBALL ||
				     this.country.discipline.id==disciplineIds.BASKETBALL || this.country.discipline.id==disciplineIds.RUGBY_UNION ||
				     this.country.discipline.id==disciplineIds.RUGBY_LEAGUE||this.country.discipline.id==disciplineIds.VOLLEYBALL
				     ){
					 titleTmp = headTitle.HEADTITLE_OVER_UNDER_PARAM_Point;					
				} else if (this.country.discipline.id==disciplineIds.CRICKET) {					
					titleTmp = headTitle.HEADTITLE_OVER_UNDER_RUNS	;
				}else{
					titleTmp = headTitle.HEADTITLE_OVER_UNDER;
				}
		}
		else if(betTypeId==betTypes.TYPE_ID_GAME_OVER_UNDER){
				titleTmp = headTitle.HEADTITLE_GAME_OVER_UNDER;
		}
		else if(betTypeId==betTypes.TYPE_ID_ODD_OR_EVEN){
			if (mypartnerId == 36) {
				if (this.country.discipline.id==disciplineIds.BASKETBALL 
						|| this.country.discipline.id==disciplineIds.AM_FOOTBALL
						|| this.country.discipline.id==disciplineIds.VOLLEYBALL
						|| this.country.discipline.id==disciplineIds.RUGBY_LEAGUE
						|| this.country.discipline.id==disciplineIds.RUGBY_UNION)
					titleTmp = headTitle.HEADTITLE_ODD_EVEN_PARIS365_POINTS;
				else if(this.country.discipline.id==disciplineIds.SOCCER 
						|| this.country.discipline.id==disciplineIds.ICEHOCKEY
						|| this.country.discipline.id==disciplineIds.HANDBALL
						|| this.country.discipline.id==disciplineIds.FUTSAL)
					titleTmp = headTitle.HEADTITLE_ODD_EVEN_PARIS365_GOALS;
				else if (this.country.discipline.id==disciplineIds.TENNIS) {
					titleTmp = headTitle.HEADTITLE_ODD_EVEN_TENNIS;
				}
				else
					titleTmp = headTitle.HEADTITLE_ODD_OR_EVEN;
			}else {
				if (this.country.discipline.id==disciplineIds.TENNIS) {
					titleTmp = headTitle.HEADTITLE_ODD_EVEN_TENNIS;
				} else				
					titleTmp = headTitle.HEADTITLE_ODD_OR_EVEN;
			}
		}
		else if(betTypeId==betTypes.TYPE_ID_DOUBLE_CHANCE){
				titleTmp = headTitle.HEADTITLE_DOUBLE_CHANCE;
		}
		//outrights		
		else if(betTypeId==betTypes.TYPE_ID_TOP_X){
				titleTmp = headTitle.getHEADTITLE_TOP_X_withParam(this.defaultOutcomeType.scopeId);
		}
		else if(betTypeId==betTypes.TYPE_ID_WINNER){
				titleTmp = headTitle.HEADTITLE_WINNER;
		}
		else if(betTypeId==betTypes.TYPE_ID_TOP_GOALSCORER){
				titleTmp = headTitle.HEADTITLE_TOP_GOALSCORER;
		}
		else if(betTypeId==betTypes.TYPE_ID_RELEGATION){
				titleTmp = headTitle.HEADTITLE_RELEGATION;
		}
		else if(betTypeId==betTypes.TYPE_ID_PROMOTION){
				titleTmp = headTitle.HEADTITLE_PROMOTION;
		}
		else if(betTypeId==betTypes.TYPE_ID_ROCK_BOTTOM){
				titleTmp = headTitle.HEADTITLE_ROCK_BOTTOM;
		}
		else if(betTypeId==betTypes.TYPE_ID_POLE_POSITION){
				titleTmp = headTitle.HEADTITLE_POLE_POSITION;
		}
		else if(betTypeId==betTypes.TYPE_ID_FASTEST_LAP){
				titleTmp = headTitle.HEADTITLE_FASTEST_LAP;
		}
		else if(betTypeId==betTypes.TYPE_ID_FIRST_TO_RETIRE){
				titleTmp = headTitle.HEADTITLE_FIRST_TO_RETIRE;
		}
		else if(betTypeId==betTypes.TYPE_ID_FIRST_LAP_LEADER){
				titleTmp = headTitle.HEADTITLE_FIRST_LAP_LEADER;
		}
		else if(betTypeId==betTypes.TYPE_ID_Score_gameX_setN){
				titleTmp = headTitle.HEADTITLE_Score_gameX_setN;
		}
		else if(betTypeId==betTypes.TYPE_ID_Who_wins_gameX_setN){
				titleTmp = headTitle.HEADTITLE_Who_wins_gameX_setN;
		}
		else if(betTypeId==betTypes.TYPE_ID_Who_win_gamesXY_setN){
				titleTmp = headTitle.HEADTITLE_HOME_DRAW_AWAY;
		}
		else if(betTypeId==betTypes.TYPE_ID_HEAD_2){
				titleTmp = headTitle.HEADTITLE_HEAD_2;
		}
		else if(betTypeId==betTypes.TYPE_ID_HEAD_3){
				titleTmp = headTitle.HEADTITLE_HEAD_3;
		}
		else {
			titleTmp = headTitle.HEADTITLE_OTHER;
		}
		
		return titleTmp;
	},
	showDefaultOutcomeType: function(imgId){
		var titleTmp = this.getTitle();
		
		this.setOutcomeType(titleTmp.homeText,titleTmp.drawText,titleTmp.awayText);

		var className = this.getHeadDivId();
		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':className});
		//var hideImage = new Element('div',{'id':'img'+imgId,'name':imgId,'class':'loadImgOfTitle','style':'display: none'});
		var hideImage = new Element('div');
		hideImage.setProperty('id','img'+imgId);
		hideImage.setProperty('name',imgId);
		hideImage.setProperty('class','loadImgOfTitle');
		hideImage.setProperty('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);
	},
	prepareForDump: function(imgId){
		var matches=this.matches.values();
		for(var i=0;i<matches.length;i++){
			var match=matches[i];
			match.prepareForDump(imgId);
		}
	}, 
	setOddsValue: function(evId, betType, scopeId, oddsId, oddsV, formattedValue){
		var match = this.matches.get(evId);
		if (match !=null)
			match.setOddsValue(betType, scopeId, oddsId, oddsV, formattedValue);
		
	},
	getOdds: function(evId, betType, scopeId, oddsId){
		var match = this.matches.get(evId);
		if (match !=null)
			return match.getOdds(betType, scopeId, oddsId);
		
	}
});

var liveFootballOrder = new Hash();
	liveFootballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY+','+scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME,65);
	liveFootballOrder.set(betTypes.TYPE_ID_TEAM_KICKS_OFF,60);
	liveFootballOrder.set(betTypes.TYPE_ID_NEXT_GOAL,55);
	liveFootballOrder.set(betTypes.TYPE_ID_TEAM_WINS_REST_MATCH+','+scopeIds.SCOPE_ID_1ST_HALF,50);
	liveFootballOrder.set(betTypes.TYPE_ID_OVER_UNDER+','+scopeIds.SCOPE_ID_1ST_HALF,45);
	liveFootballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP+','+scopeIds.SCOPE_ID_1ST_HALF,40);
	liveFootballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY+','+scopeIds.SCOPE_ID_1ST_HALF,35);
	liveFootballOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE+','+scopeIds.SCOPE_ID_1ST_HALF,33);
	liveFootballOrder.set(betTypes.TYPE_ID_TEAM_WINS_REST_MATCH,30);
	liveFootballOrder.set(betTypes.TYPE_ID_OVER_UNDER,25);
	liveFootballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP,20);
	liveFootballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP,15);
	liveFootballOrder.set(betTypes.TYPE_ID_DOUBLE_CHANCE,13);
	liveFootballOrder.set(betTypes.TYPE_ID_GOALS_NOGOALS,11);
	liveFootballOrder.set(betTypes.TYPE_ID_GOALS_HOME_TEAM,9);
	liveFootballOrder.set(betTypes.TYPE_ID_GOALS_AWAY_TEAM,7);
	liveFootballOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE,5);
	liveFootballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN,1);

var liveTennisOrder = new Hash();
	liveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_FULL_EVENT, 400);
	liveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_1ST_SET, 390);
	liveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_2ND_SET, 380);
	liveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_3RD_SET, 370);
	liveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_4TH_SET, 360);
	liveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_5TH_SET, 350);
	liveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_FULL_EVENT, 340);
	liveTennisOrder.set(betTypes.TYPE_ID_GAME_OVER_UNDER +','+  scopeIds.SCOPE_ID_FULL_EVENT, 340);

	liveTennisOrder.set(betTypes.TYPE_ID_Who_wins_gameX_setN +','+  scopeIds.SCOPE_ID_1ST_SET, 270);
	liveTennisOrder.set(betTypes.TYPE_ID_Score_gameX_setN +','+  scopeIds.SCOPE_ID_1ST_SET, 265);
	liveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_1ST_SET, 260);
	liveTennisOrder.set(betTypes.TYPE_ID_GAME_OVER_UNDER +','+  scopeIds.SCOPE_ID_1ST_SET, 260);
	liveTennisOrder.set(betTypes.TYPE_ID_Who_win_gamesXY_setN +','+  scopeIds.SCOPE_ID_1ST_SET, 255);
		
	liveTennisOrder.set(betTypes.TYPE_ID_Who_wins_gameX_setN +','+  scopeIds.SCOPE_ID_2ND_SET, 250);
	liveTennisOrder.set(betTypes.TYPE_ID_Score_gameX_setN +','+  scopeIds.SCOPE_ID_2ND_SET, 245);
	liveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_2ND_SET, 240);
	liveTennisOrder.set(betTypes.TYPE_ID_GAME_OVER_UNDER +','+  scopeIds.SCOPE_ID_2ND_SET, 240);
	liveTennisOrder.set(betTypes.TYPE_ID_Who_win_gamesXY_setN +','+  scopeIds.SCOPE_ID_2ND_SET, 235);
		
	liveTennisOrder.set(betTypes.TYPE_ID_Who_wins_gameX_setN +','+  scopeIds.SCOPE_ID_3RD_SET, 230);
	liveTennisOrder.set(betTypes.TYPE_ID_Score_gameX_setN +','+  scopeIds.SCOPE_ID_3RD_SET, 225);
	liveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_3RD_SET, 220);
	liveTennisOrder.set(betTypes.TYPE_ID_GAME_OVER_UNDER +','+  scopeIds.SCOPE_ID_3RD_SET, 220);
	liveTennisOrder.set(betTypes.TYPE_ID_Who_win_gamesXY_setN +','+  scopeIds.SCOPE_ID_3RD_SET, 215);
	
	liveTennisOrder.set(betTypes.TYPE_ID_Who_wins_gameX_setN +','+  scopeIds.SCOPE_ID_4TH_SET, 210);
	liveTennisOrder.set(betTypes.TYPE_ID_Score_gameX_setN +','+  scopeIds.SCOPE_ID_4TH_SET, 205);
	liveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_4TH_SET, 200);
	liveTennisOrder.set(betTypes.TYPE_ID_GAME_OVER_UNDER +','+  scopeIds.SCOPE_ID_4TH_SET, 200);
	liveTennisOrder.set(betTypes.TYPE_ID_Who_win_gamesXY_setN +','+  scopeIds.SCOPE_ID_4TH_SET, 195);
	
	liveTennisOrder.set(betTypes.TYPE_ID_Who_wins_gameX_setN +','+  scopeIds.SCOPE_ID_5TH_SET, 190);
	liveTennisOrder.set(betTypes.TYPE_ID_Score_gameX_setN +','+  scopeIds.SCOPE_ID_5TH_SET, 185);
	liveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_5TH_SET, 180);
	liveTennisOrder.set(betTypes.TYPE_ID_GAME_OVER_UNDER +','+  scopeIds.SCOPE_ID_5TH_SET, 180);
	liveTennisOrder.set(betTypes.TYPE_ID_Who_win_gamesXY_setN +','+  scopeIds.SCOPE_ID_5TH_SET, 175);
	
	liveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_1ST_SET, 170);
	liveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_2ND_SET, 160);
	liveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_3RD_SET, 150);
	liveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_4TH_SET, 140);
	liveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_5TH_SET, 130);

	liveTennisOrder.set(betTypes.TYPE_ID_SETS_NUMBER_3,120  );
	liveTennisOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE, 110);

	liveTennisOrder.set(betTypes.TYPE_ID_SETS_NUMBER_5 , 100);

	liveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_FULL_EVENT, 80);
	
var liveIcehockyOrder = new Hash();
	liveIcehockyOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 150);
	liveIcehockyOrder.set(betTypes.TYPE_ID_NEXT_GOAL +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 140);

	liveIcehockyOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+ scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME , 130);
	liveIcehockyOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME , 120);

	liveIcehockyOrder.set(betTypes.TYPE_ID_TEAM_WINS_REST_MATCH +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 110);
	liveIcehockyOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 100);

	liveIcehockyOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY, 80);
	liveIcehockyOrder.set(betTypes.TYPE_ID_OVER_UNDER, 70);
	liveIcehockyOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE, 60);
	
	liveIcehockyOrder.set(betTypes.TYPE_ID_NEXT_GOAL, 50);
	liveIcehockyOrder.set(betTypes.TYPE_ID_TEAM_WINS_REST_MATCH, 40);
	
var liveBasketballOrder = new Hash();
	liveBasketballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+ scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME , 400);
	liveBasketballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+ scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME , 390);
	liveBasketballOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME , 380);
	
	liveBasketballOrder.set(betTypes.TYPE_ID_JUMP_BALL, 370);
	//liveBasketballOrder.set(betTypes.Which team wins race to X points, 360);
	//liveBasketballOrder.set(betTypes.Who scores Xth point, 350);
	
	liveBasketballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 340);

	liveBasketballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+ scopeIds.SCOPE_ID_1ST_QUARTER , 330);
	liveBasketballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+ scopeIds.SCOPE_ID_1ST_QUARTER , 320);
	liveBasketballOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_1ST_QUARTER , 310);
	liveBasketballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+ scopeIds.SCOPE_ID_1ST_QUARTER , 300);

	liveBasketballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+ scopeIds.SCOPE_ID_2ND_QUARTER , 290);
	liveBasketballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+ scopeIds.SCOPE_ID_2ND_QUARTER , 280);
	liveBasketballOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_2ND_QUARTER , 270);
	liveBasketballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+ scopeIds.SCOPE_ID_2ND_QUARTER , 260);

	liveBasketballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+ scopeIds.SCOPE_ID_1ST_HALF , 250);
	liveBasketballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+ scopeIds.SCOPE_ID_1ST_HALF , 240);
	liveBasketballOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_1ST_HALF , 230);
	liveBasketballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+ scopeIds.SCOPE_ID_1ST_HALF , 220);

	liveBasketballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+ scopeIds.SCOPE_ID_3RD_QUARTER , 210);
	liveBasketballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+ scopeIds.SCOPE_ID_3RD_QUARTER , 200);
	liveBasketballOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_3RD_QUARTER , 190);
	liveBasketballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+ scopeIds.SCOPE_ID_3RD_QUARTER , 180);
	
	liveBasketballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+ scopeIds.SCOPE_ID_4TH_QUARTER , 170);
	liveBasketballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+ scopeIds.SCOPE_ID_4TH_QUARTER , 160);
	liveBasketballOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_4TH_QUARTER , 150);
	liveBasketballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+ scopeIds.SCOPE_ID_4TH_QUARTER , 140);

	//liveBasketballOrder.set(betTypes.Will there be overtime  , 130);
	liveBasketballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+ scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME , 120);
	liveBasketballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 110);
	liveBasketballOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 100);
	
var liveHandballOrder = new Hash();
	liveHandballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY+','+scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME,65);
	liveHandballOrder.set(betTypes.TYPE_ID_TEAM_KICKS_OFF,60);
	liveHandballOrder.set(betTypes.TYPE_ID_NEXT_GOAL,55);
	liveHandballOrder.set(betTypes.TYPE_ID_TEAM_WINS_REST_MATCH+','+scopeIds.SCOPE_ID_1ST_HALF,50);
	liveHandballOrder.set(betTypes.TYPE_ID_OVER_UNDER+','+scopeIds.SCOPE_ID_1ST_HALF,45);
	liveHandballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP+','+scopeIds.SCOPE_ID_1ST_HALF,40);
	liveHandballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY+','+scopeIds.SCOPE_ID_1ST_HALF,35);
	liveHandballOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE+','+scopeIds.SCOPE_ID_1ST_HALF,33);
	liveHandballOrder.set(betTypes.TYPE_ID_TEAM_WINS_REST_MATCH,30);
	liveHandballOrder.set(betTypes.TYPE_ID_OVER_UNDER,25);
	liveHandballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP,20);
	liveHandballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP,15);
	liveHandballOrder.set(betTypes.TYPE_ID_DOUBLE_CHANCE,13);
	liveHandballOrder.set(betTypes.TYPE_ID_GOALS_NOGOALS,11);
	liveHandballOrder.set(betTypes.TYPE_ID_GOALS_HOME_TEAM,9);
	liveHandballOrder.set(betTypes.TYPE_ID_GOALS_AWAY_TEAM,7);
	liveHandballOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE,5);
	liveHandballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN,1);
	
var preliveFootballOrder = new Hash();
	preliveFootballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY+','+scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME,200);
	preliveFootballOrder.set(betTypes.TYPE_ID_TEAM_KICKS_OFF,190);
	preliveFootballOrder.set(betTypes.TYPE_ID_DOUBLE_CHANCE,180);
	preliveFootballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW+','+scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME,170);
	preliveFootballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP,160);
	preliveFootballOrder.set(betTypes.TYPE_ID_OVER_UNDER,150);
	preliveFootballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP,140);
	preliveFootballOrder.set(betTypes.TYPE_ID_HALF_TIME_FULL_TIME,130);
	preliveFootballOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE,120);
	preliveFootballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY+','+scopeIds.SCOPE_ID_1ST_HALF,110);
	preliveFootballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP+','+scopeIds.SCOPE_ID_1ST_HALF,100);
	preliveFootballOrder.set(betTypes.TYPE_ID_OVER_UNDER+','+scopeIds.SCOPE_ID_1ST_HALF,90);
	preliveFootballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP+','+scopeIds.SCOPE_ID_1ST_HALF,80);
	preliveFootballOrder.set(betTypes.TYPE_ID_DOUBLE_CHANCE+','+scopeIds.SCOPE_ID_1ST_HALF,70);
	preliveFootballOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE+','+scopeIds.SCOPE_ID_1ST_HALF,60);
	preliveFootballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN+','+scopeIds.SCOPE_ID_1ST_HALF,50);
	preliveFootballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY+','+scopeIds.SCOPE_ID_2ND_HALF,40);
	preliveFootballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP+','+scopeIds.SCOPE_ID_2ND_HALF,35);
	preliveFootballOrder.set(betTypes.TYPE_ID_OVER_UNDER+','+scopeIds.SCOPE_ID_2ND_HALF,30);
	preliveFootballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP+','+scopeIds.SCOPE_ID_2ND_HALF,25);
	preliveFootballOrder.set(betTypes.TYPE_ID_DOUBLE_CHANCE+','+scopeIds.SCOPE_ID_2ND_HALF,20);
	preliveFootballOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE+','+scopeIds.SCOPE_ID_2ND_HALF,15);
	preliveFootballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN+','+scopeIds.SCOPE_ID_2ND_HALF,10);
	preliveFootballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN,5);
	
var preliveTennisOrder = new Hash();
	preliveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_FULL_EVENT, 400);
	preliveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_FULL_EVENT, 390);
	preliveTennisOrder.set(betTypes.TYPE_ID_GAME_HANDICAP +','+  scopeIds.SCOPE_ID_FULL_EVENT, 380);
	preliveTennisOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE +','+  scopeIds.SCOPE_ID_FULL_EVENT, 370);

	preliveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_1ST_SET, 360);
	preliveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_1ST_SET, 350);
	preliveTennisOrder.set(betTypes.TYPE_ID_GAME_HANDICAP +','+  scopeIds.SCOPE_ID_1ST_SET, 340);
	preliveTennisOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE +','+  scopeIds.SCOPE_ID_1ST_SET, 330);

	preliveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_2ND_SET, 320);
	preliveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_2ND_SET, 310);
	preliveTennisOrder.set(betTypes.TYPE_ID_GAME_HANDICAP +','+  scopeIds.SCOPE_ID_2ND_SET, 300);
	preliveTennisOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE +','+  scopeIds.SCOPE_ID_2ND_SET, 290);
	
	preliveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_3RD_SET, 280);
	preliveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_3RD_SET, 270);
	preliveTennisOrder.set(betTypes.TYPE_ID_GAME_HANDICAP +','+  scopeIds.SCOPE_ID_3RD_SET, 260);
	preliveTennisOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE +','+  scopeIds.SCOPE_ID_3RD_SET, 250);
	
	preliveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_4TH_SET, 240);
	preliveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_4TH_SET, 230);
	preliveTennisOrder.set(betTypes.TYPE_ID_GAME_HANDICAP +','+  scopeIds.SCOPE_ID_4TH_SET, 220);
	preliveTennisOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE +','+  scopeIds.SCOPE_ID_4TH_SET, 210);

	preliveTennisOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_5TH_SET, 200);
	preliveTennisOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_5TH_SET, 190);
	preliveTennisOrder.set(betTypes.TYPE_ID_GAME_HANDICAP +','+  scopeIds.SCOPE_ID_5TH_SET, 180);
	preliveTennisOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE +','+  scopeIds.SCOPE_ID_5TH_SET, 170);

	preliveTennisOrder.set(betTypes.TYPE_ID_SET_HANDICAP +','+  scopeIds.SCOPE_ID_FULL_EVENT, 160);

	preliveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_1ST_SET, 150);
	preliveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_2ND_SET, 140);
	preliveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_3RD_SET,130 );
	preliveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_4TH_SET, 120);
	preliveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_5TH_SET, 110);
	preliveTennisOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_FULL_EVENT, 100);
	
var preliveIcehockyOrder = new Hash();
	preliveIcehockyOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 150);
	preliveIcehockyOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+  scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME, 140);
	preliveIcehockyOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+  scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME, 130);
	preliveIcehockyOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME, 120);
	
	preliveIcehockyOrder.set(betTypes.TYPE_ID_DOUBLE_CHANCE +','+  scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME, 110);
	preliveIcehockyOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP +','+  scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME, 100);
	preliveIcehockyOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE +','+  scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME, 90);
	
	preliveIcehockyOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+  scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME, 80);
	preliveIcehockyOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+  scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME, 70);
	preliveIcehockyOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+  scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME, 60);
	
var preliveBasketballOrder = new Hash();
	preliveBasketballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+ scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME , 200);
	preliveBasketballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+ scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME , 190);
	preliveBasketballOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME , 180);
	preliveBasketballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 170);

	preliveBasketballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+ scopeIds.SCOPE_ID_1ST_HALF , 160);
	preliveBasketballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+ scopeIds.SCOPE_ID_1ST_HALF , 150);
	preliveBasketballOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_1ST_HALF , 140);
	preliveBasketballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY +','+ scopeIds.SCOPE_ID_1ST_HALF , 130);
	
	preliveBasketballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW +','+ scopeIds.SCOPE_ID_1ST_QUARTER , 120);
	preliveBasketballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP +','+ scopeIds.SCOPE_ID_1ST_QUARTER , 110);
	preliveBasketballOrder.set(betTypes.TYPE_ID_OVER_UNDER +','+ scopeIds.SCOPE_ID_1ST_QUARTER , 100);
	preliveBasketballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY +','+ scopeIds.SCOPE_ID_1ST_QUARTER , 90);
	
	preliveBasketballOrder.set(betTypes.TYPE_ID_HALF_TIME_FULL_TIME +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 80);
	preliveBasketballOrder.set(betTypes.TYPE_ID_DOUBLE_CHANCE +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 70);
	preliveBasketballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP +','+ scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME , 60);
	
	preliveBasketballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+ scopeIds.SCOPE_ID_1ST_QUARTER , 50);
	preliveBasketballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+ scopeIds.SCOPE_ID_1ST_HALF , 40);
	preliveBasketballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN +','+ scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME , 30);
	
var preliveHandballOrder = new Hash();
	preliveHandballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY+','+scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME,200);
	preliveHandballOrder.set(betTypes.TYPE_ID_DOUBLE_CHANCE,180);
	preliveHandballOrder.set(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW+','+scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME,170);
	preliveHandballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP,160);
	preliveHandballOrder.set(betTypes.TYPE_ID_OVER_UNDER,150);
	preliveHandballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP,140);
	preliveHandballOrder.set(betTypes.TYPE_ID_HALF_TIME_FULL_TIME,130);
	preliveHandballOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE,120);
	preliveHandballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY+','+scopeIds.SCOPE_ID_1ST_HALF,110);
	preliveHandballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP+','+scopeIds.SCOPE_ID_1ST_HALF,100);
	preliveHandballOrder.set(betTypes.TYPE_ID_OVER_UNDER+','+scopeIds.SCOPE_ID_1ST_HALF,90);
	preliveHandballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP+','+scopeIds.SCOPE_ID_1ST_HALF,80);
	preliveHandballOrder.set(betTypes.TYPE_ID_DOUBLE_CHANCE+','+scopeIds.SCOPE_ID_1ST_HALF,70);
	preliveHandballOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE+','+scopeIds.SCOPE_ID_1ST_HALF,60);
	preliveHandballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN+','+scopeIds.SCOPE_ID_1ST_HALF,50);
	preliveHandballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY+','+scopeIds.SCOPE_ID_2ND_HALF,40);
	preliveHandballOrder.set(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP+','+scopeIds.SCOPE_ID_2ND_HALF,35);
	preliveHandballOrder.set(betTypes.TYPE_ID_OVER_UNDER+','+scopeIds.SCOPE_ID_2ND_HALF,30);
	preliveHandballOrder.set(betTypes.TYPE_ID_ASIAN_HANDICAP+','+scopeIds.SCOPE_ID_2ND_HALF,25);
	preliveHandballOrder.set(betTypes.TYPE_ID_DOUBLE_CHANCE+','+scopeIds.SCOPE_ID_2ND_HALF,20);
	preliveHandballOrder.set(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE+','+scopeIds.SCOPE_ID_2ND_HALF,15);
	preliveHandballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN+','+scopeIds.SCOPE_ID_2ND_HALF,10);
	preliveHandballOrder.set(betTypes.TYPE_ID_ODD_OR_EVEN,5);	
	
var Match = CategElement.extend ({
	initialize: function(id,imgId){
		this.id=id;
		this.name='';
		this.date='aa';
		this.matchCenterLine=null;
		if (getIsInNewExpandPage())
			this.elementLine=new Element('tr',{'class': 'matchLine','id':'R2'});
		else
			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;
		this.evtType = 0;
	},
	reset:function() {
		this.expanded = false;	
		this.isExpanded = false;	
		this.numberOfOutrights=0;
		this.rowCount = 0;
		this.betTypes=new Array();
	},
	getBetTypeObjs:function() {		
		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]);
					}
				}
			}
		}
		return betTypes;
	},
	countNrOfbo:function() {
		var nrOfBo = 0;
		var betTypes = this.getBetTypeObjs();
		var betTypesL = betTypes.length;
		for (var i =0; i<betTypesL; i++){		
			if ($defined(betTypes[i]))			
				nrOfBo += betTypes[i].countNrOfbo();
		}
		this.nrOfBo = nrOfBo;
		return nrOfBo;
	},
	countBettypes:function() {		
		//way 2: count the number beside each match
		var nrOfBettypes = parseInt(this.numberOfOutrights);
		return nrOfBettypes;
	},
	countValidMatches:function() {
		var ValidMatches = 0;
		//count this match in when it's not an ended match
		if (this.matchStatusId.indexOf('Ended')<0) {
			ValidMatches = 1;
		}
		return ValidMatches;	
	},	
	addBetType: function(betType, override){
		var betTypeExists=-1;
		for(var i=0;i<this.betTypes.length;i++){
			if($defined(this.betTypes[i])){
				if(i==betType.typeId){
					betTypeExists=1;
					break;
				}
			}
		}
		var exists = 1;
		if(betTypeExists==1){
			var oldBetType = this.betTypes[betType.typeId][betType.scopeId];
			if (!$defined(oldBetType) || override){
				this.betTypes[betType.typeId][betType.scopeId]=betType;
				exists = 0;
			}
		}
		else{
			this.betTypes[betType.typeId]=new Array();
			this.betTypes[betType.typeId][betType.scopeId]=betType;
			exists = 0;			
		}
		
		betType.setMatch(this);
		return exists;
	},
	getBetType : function(typeId, scopeId){
		if (!$defined(this.betTypes[typeId]))
			return null;
		return this.betTypes[typeId][scopeId];
	},
	removeBetType : function(typeId, scopeId){
		if ($defined(this.betTypes[typeId][scopeId])) {
			this.betTypes[typeId][scopeId] = null;
		}
	},
	deleteMatch:function() {
		setMsg();
		this.deleteMatchLines('1');
		this.tournament.removeMatch(this.id);
	},
	suspendMatch:function() {
		this.deleteMatchLines('0');
	},
	deleteMatchLines:function(type) {
		
		this.isExpanded = false;
		this.expanded=false;
	
		var betTypes = this.getBetTypeObjs();
		if ((!$defined(betTypes) || betTypes.length==0)) {
			if( type=='1') {
				//if there is already no bettype , remove match when type==1 
				if ($defined(this.elementLine))
					this.elementLine.remove();
			} else if (type=='0') {
				this.disableDefaultType(null,type);				
			}
		} else {
			for(var i=0;i<betTypes.length;i++){
				var betTypeTemp = betTypes[i];
				//for default type, handle differently according to type
				if (betTypeTemp.isDefaultBetType) {
					this.disableDefaultType(betTypeTemp,type);
				} else {
					this.deleteExpandedBetType(betTypeTemp,type);
				}
			}
		}
		this.reset();
	},
	deleteExpandedBetTypes:function(type) {
		var betTypes = this.getBetTypeObjs();
		for(var i=0;i<betTypes.length;i++){
			var betTypeTemp = betTypes[i];
			if (!betTypeTemp.isDefaultBetType) {
				this.deleteExpandedBetType(betTypeTemp,type);
			}
		}		
	},
	deleteExpandedBetType:function(betTypeTemp,type) {
		//remove expanded rows
		if ($defined(betTypeTemp.betTypeRows)) {
			for(var j=0 ;j<betTypeTemp.betTypeRows.length ;j++){
				betTypeTemp.betTypeRows[j].remove();
				////betTypeTemp.betTypeRows.splice(j,1);
			}			
		} else {
			//when match is ended, but with bettype which not displayed, remove elementline.
			if( type=='1') {
				if ($defined(this.elementLine))
					this.elementLine.remove();
			}					
		}
		this.removeBetType(betTypeTemp.typeId, betTypeTemp.scopeId);		
	},
	disableDefaultType: function (betType,type) {
		//type : 
		// 		1, remove this type , as this match is ended
		//		0, remove this type , and leave an empty row to show sm on this line, as it's a suspended match
		
		//remove expanded rows
		if ($defined(betType)) {
			for(var i=0 ;i<betType.betTypeRows.length ;i++){
				if (type=='1' || this.elementLine != betType.betTypeRows[i]) {
					betType.betTypeRows[i].remove();
					////betType.betTypeRows.splice(i,1);
					if (betType.isDefaultBetType)		
						betType.match.rowCount--;
				}
			}
			this.removeBetType(betType.typeId, betType.scopeId);
		}
		
		if (type=='1') {
			//this.elementLine
		}else if (type=='0') {			
			var tdOdds =this.elementLine.getElements('td');
			var l = tdOdds.length;					
			if (l==7) {
				for (var j=3; j< l; j++){//for non-outrights bettype,remove last 4 cells for odds
					this.showSM(tdOdds[j],j-2);
				}
			} else if (l==5) {//for outrights bettype
				for (var k=3; k< l; k++){
					this.showSM(tdOdds[k]);
				}					
			}
		}
	},
	isLive:function() {
		if (this.showLive() && (this.betStatus=='stopped' || this.betStatus=='started')) 
			return true;
		else 
			return false; 
	},
	isSeLive:function() {
		if (this.evtType == 3)
			return true;
		else
			return false;
	},
	isSuspended:function() {
		if (this.showLive() && this.betStatus=='stopped') 
			return true;
		else 
			return false; 
	},
	showLive:function() {
		if (this.evtType==1 || this.evtType==2 || this.evtType==3 )
			return true;
		else
			return false;
	},
	setBetStatus:function(status) {
		this.betStatus = status;
	},
	setScore:function(score) {
		this.score = score;
	},
	setSetScore:function(setScore) {
		this.setScore = setScore;
	},
	setGameScore:function(gameScore) {
		this.gameScore = gameScore;
	},
	setPointScore:function(pointScore) {
		this.pointScore = pointScore;
	},
	setServer:function(server) {
		this.server = server;
	},
	setTeamName:function(teamName) {
		this.teamName = teamName;
	},
	setMatchStatus:function(matchStatus) {
		this.matchStatus = matchStatus;
	},
	setMatchStatusId:function(matchStatusId) {
		this.matchStatusId = matchStatusId;
	},
	setMatchTime:function(matchTime) {
		this.matchTime = matchTime;
	},
	setMatchTimeType:function(matchTimeType) {
		this.matchTimeType = matchTimeType;
	},
	setRemainTime:function(remainTime) {
		this.remainTime = remainTime;
	},
	getOddsCellText:function(position,betType) {
		var text = '&nbsp';
		if (position===2) {
			if (!$defined(betType))	
				betType = this.tournament.defaultOutcomeType.betTypeId;
			if (isTwoCellBetType(betType)) 
				return text;			
		}	
		
		if (this.showLive()) {
			if (this.isSuspended())
				text = smTxt;
			else			
				text = emptyOddsTxt;
		}
		return text;
	},
	showSM: function(tdObj,position,betType) {
		var txt = '';
		if (tdObj.className == 'expandable') {
			if (isExpandMatchModeType2() && !getIsInNewExpandPage())
				txt = '+';
			else {
				txt = '&nbsp';
				tdObj.removeEvents('click');
			}
		} else {
			var text = this.getOddsCellText(position);
			if (this.isSuspended())
				txt = '<div class=\'smOddsCell\'>'+text+'</div>';
			else			
				txt = '<div class=\'emptyOddsCell\'>'+text+'</div>';
				
			tdObj.removeEvents('click');
		}
		
		var divId=this.getDivId();
		tdObj.innerHTML = '<div id="'+divId+'">'+txt+'</div>';
	},
	deleteBetTypeRows: function(typeId, scopeId, dbParam1){
		if (!$defined(this.betTypes[typeId]))
			return;
		var betType = this.betTypes[typeId][scopeId];
		if (betType == null)
			return;

		var betRowsL = 0;
		if ($defined(betType.betTypeRows))
			betRowsL = betType.betTypeRows.length;
			
		if (betType.isDefaultBetType && isParamBetType(typeId) && betRowsL>1) {
			betType.odds.remove(dbParam1);
			betType.removeFromDOM();
			this.addBetType(betType, true);
			this.addBetTypeToDOM(betType);
		} else {
		
			//if this match is expanded and this is default bettype
			if (betType.isDefaultBetType && (this.expanded || this.showLive()) && !isEmptyMatchLineBetType(betType.typeId)) {
				/** solution A: remove the expanded rows as well as this bettype
				var betTypes=[];
				for(var i=0;i<this.betTypes.length;i++){
					var temp1 = this.betTypes[i];
					if($defined(temp1)){
						for(var j=0;j<temp1.length;j++){
							var betTypeTemp = this.betTypes[i][j];
							if($defined(betTypeTemp)){
								//remove expanded rows
								if (isMultiRowBetType(betTypeTemp.typeId)) {
									//for those bettypes with many separated odds, remove all odds
									betTypeTemp.removeFromDOM();
									this.removeBetType(betTypeTemp.typeId, betTypeTemp.scopeId);
								} else {
									var dbps = betTypeTemp.odds.keys();
									for (var k=0;k< dbps.length;k++) {
										betTypeTemp.deleteBetTypeRows(dbps[k]);
									}
								}
							}
						}
					}
				}
				* **/
				
				//solution B: delete only bettype's odds, keep the bettype row and expanded rows
				var oddsMap = betType.odds.get(dbParam1);
				if ($defined(oddsMap)) {
					var oddsKeys = oddsMap.keys();
					for (var k=0;k<oddsKeys.length;k++) {
						betType.deleteOdds(oddsKeys[k]);
					}
					if (isMultiRowBetType(betType.typeId)) {
						var l = betType.betTypeRows.length;
						for (var h=1;h<l;h++) {
							betType.betTypeRows[h].remove();
							////betType.betTypeRows.splice(h,1);
						}
					}
					this.removeBetType(betType.typeId, betType.scopeId);
				}
			} 
			// else only remove this bettype
			else {		
				if (isMultiRowBetType(betType.typeId)) {
					//for those bettypes with many separated odds, remove all odds
					betType.removeFromDOM('1');
					this.removeBetType(betType.typeId, betType.scopeId);
				} else {
					betType.deleteBetTypeRows(dbParam1);
				}
			}
		}
		
		if (this.showLive())
			return;
			
		// if this was the last bet type from this match - we should proceed with deleting the match
		if (this.betTypes[typeId][scopeId] == null){
			var betTypes = this.getBetTypeObjs();

			if (betTypes.length == 0){	//we should remove event			
				if ($defined(this.elementLine) && this.elementLine.rowIndex>-1 ) {
					this.elementLine.remove();
				}
				this.tournament.removeMatch(this.id);	
			}
		}
		
	},
	setHomeParticipantName: function(participantName){
			this.homeParticipantName=this.replaceContentInBrakets(participantName);
	},
	setAwayParticipantName: function(participantName){
		this.awayParticipantName=this.replaceContentInBrakets(participantName);
	},
	setHomeParticipantShortname: function(participantShortname){
			this.homeParticipantShortname=this.replaceContentInBrakets(participantShortname);
	},
	setAwayParticipantShortname: function(participantShortname){
		this.awayParticipantShortname=this.replaceContentInBrakets(participantShortname);
	},
	replaceContentInBrakets:function(participantName){
		var braket1=participantName.indexOf("(");
		var braket2=participantName.indexOf(")");
		if (braket1>0 && braket2 > 0 && braket2 > braket1){
			participantName = participantName.replace(/(\(.+\))/g,"<div class=bt>$1</div>");			
		}
		return participantName;
		
	},
	setTournament: function(tournament){
		this.tournament=tournament;
	},
	setNumberOfOutrights: function(numberOfOutrights){
		this.numberOfOutrights=numberOfOutrights;
	},
	setMatchRisk:function(risk){
		this.maxRisk = risk;
	},
	hasDefaultBetType:function() {			
		var defaultBetTypeObj = this.getBetType(this.tournament.defaultOutcomeType.betTypeId,this.tournament.defaultOutcomeType.scopeId);
		if ($defined(defaultBetTypeObj)) 
			return true;
		else
			return false;
	},
	showEmptyOddsMatch:function(type) {
		if (type==2) {
			//update cell with empty info
			var tdOdds =this.elementLine.getElements('td');
			var l = tdOdds.length;					
			if (l==7) {
				for (var j=3; j< l-1; j++){//for non-outrights bettype,update 3 cells for odds
					this.showSM(tdOdds[j],j-2);
				}
			} else if (l==5) {//for outrights bettype, 2 cells
				for (var k=3; k< l-1; k++){
					this.showSM(tdOdds[k]);
				}					
			}
		} else {
			//create empty cell
			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'});
				
			//not_started stopped started
			this.showSM(cell1);this.showSM(cell2,2);this.showSM(cell3);
	
			cell1.injectInside(this.elementLine);cell2.injectInside(this.elementLine);cell3.injectInside(this.elementLine);		
		}
	},
	showDefaultOutcomeType: function(outcomeType,needShowEmptyOddsMatch){
		var otherOutrights =0;
		if($defined(this.betTypes[outcomeType.betTypeId]) && $defined(this.betTypes[outcomeType.betTypeId][outcomeType.scopeId]) && !this.isSuspended())
		{
			otherOutrights = this.computeOtherOutrights();
			//otherOutrights = parseInt(this.numberOfOutrights)-1;
			this.betTypes[outcomeType.betTypeId][outcomeType.scopeId].showDefaultBetTypeForMatch(this.elementLine);
		}
		else{//alert('8899');
		  if (needShowEmptyOddsMatch || this.isSuspended()){
			otherOutrights = this.computeOtherOutrights();
		  	this.showEmptyOddsMatch();
		  }else{
		  	this.elementLine.remove();
		  	return;
		  }

			/*
			*/
		}
		//alert("==" + imgId);
		this.showExpandCell(otherOutrights);
	},	
	showExpandCell:function(otherOutrights) {
		var divId=this.getDivId();
		var extraCell=new Element('td',{'class': 'expandable'}); // this is for the +NoOutcomeTypes

		//+ should be showed all the time for ExpandMatchModeType2, and no + in new expand page
		if( (otherOutrights>0 && !this.isSuspended() || isExpandMatchModeType2())
			&& !getIsInNewExpandPage()){
			
			if (otherOutrights==0)
				otherOutrights = '';
			
			extraCell.addEvent('click',function(){
				if(this.expanded){
					collapseMatch(this);
				} else {
					expandMatch(this);
				}
			}.bind_om(this));
			var prefix = '';
			var isFold = '';
			if(this.expanded) {
				prefix = '-';
			}
			else {
				prefix = '+';	
				isFold = 'Fold';		
			}	
			var htmlStr = '';
			if (expandCellIsLink)
			    htmlStr = '<a class="expandLink'+isFold+'" href="javascript:void(0);"><span>'+prefix+otherOutrights+'</span></a>';
			else 
			    htmlStr = prefix+otherOutrights;		
			      
		} else {
			htmlStr = '&nbsp;';
		}
		htmlStr = '<div id="'+divId+'">' +htmlStr +'</div>';
		extraCell.setHTML(htmlStr);
		extraCell.injectInside(this.elementLine);
	},
	getExtraCell : function() {
		var extraCell = this.elementLine.getElementsByClassName('expandable');
		if ($defined(extraCell) && $defined(extraCell[0])) 
			return extraCell[0];
		else
			return null;
	},
	removeExtraCell:function() {
		var extraCell = this.getExtraCell();
		if ($defined(extraCell)) {
			extraCell.remove();
		}
	},
	isExtraCellEffective:function() {
		var extraCell = this.getExtraCell();
		if ($defined(extraCell)) {
			var hasExpandStr = extraCell.innerHTML.search('\\+');
			var hasCollapseStr = extraCell.innerHTML.search('\\-');
			return (hasExpandStr>=0 || hasCollapseStr>=0);
		}
		return false;
	},
	computeOtherOutrights:function() {
		var otherOutrights = parseInt(this.numberOfOutrights);
		var defaultBetTypeObj = this.getBetType(this.tournament.defaultOutcomeType.betTypeId,this.tournament.defaultOutcomeType.scopeId);
		if ($defined(defaultBetTypeObj)) {
			if ( isParamBetType(this.tournament.defaultOutcomeType.betTypeId)) {
				var oddsParam = defaultBetTypeObj.odds.values();
				var oddsL = oddsParam.length;
				otherOutrights -= oddsL;
			} else {
				otherOutrights--;
			}
		}
		return otherOutrights;
	},
	updateOrCreateExtraCell:function(number) {
		//when it's in the new expand page, there is no need to do the job
		if (getIsInNewExpandPage())
			return;
			
		var oldIsEffective = this.isExtraCellEffective();
		this.updateNumberOfOutrights(number);

		var otherOutrights = this.computeOtherOutrights();
		//attach click event to this cell if it was not clickable and now should be clickable
		if(!this.isSuspended() && otherOutrights>0 && !oldIsEffective){
			if (this.isExtraCellEffective()) {
				var extraCell = this.getExtraCell();					
				extraCell.addEvent('click',function(){
					if(this.expanded){
						collapseMatch(this);
					} else {
						expandMatch(this);
					}
				}.bind_om(this));
			}
		}
	},
	updateNumberOfOutrights : function(number) {
		this.setNumberOfOutrights(number);
		var otherOutrights = this.computeOtherOutrights();
		var childen = this.getExtraCell();
		if ($defined(childen)) {
			
			var prefix = '';
			var isFold = '';
			if(this.expanded) {
				prefix='-';
			} else {
				prefix='+';		
				isFold = 'Fold';					
			}
			//ExpandMatchModeType2 requires a + showed no matter how
			if ((otherOutrights<=0 || this.isSuspended()) && !isExpandMatchModeType2()) {
				prefix = '';
				otherOutrights = '&nbsp;';				
				childen.removeEvents('click');
			}
			if (otherOutrights<=0)
				otherOutrights = '&nbsp;';	
				
			if (expandCellIsLink)
			   childen.setHTML('<a class="expandLink'+isFold+'" href="javascript:void(0);"><span>'+prefix+otherOutrights+'</span></a>');
			else 
			   childen.setHTML(prefix+otherOutrights);
		}
	},
	getMatchIcon:function() {
		var liveDiv = '';
		if (this.showLive()) {
			if (this.isLive()) 
				liveDiv="<div id='matchIcon' class=\'livingIcon\'></div>";
			else 
				liveDiv="<div id='matchIcon' class=\'willBeLiveIcon\'></div>";
		}
		return liveDiv;		
	},
	updateHourCell:function(score,matchStatus,matchTime,matchTimeType,betStatus,gameScore,pointScore,setScore,server,teamName,remainTime) {
		this.score = score;
		this.matchStatus = matchStatus;
		this.matchTime = matchTime;
		this.matchTimeType = matchTimeType;
		this.betStatus = betStatus;
		this.gameScore = gameScore;
		this.pointScore = pointScore;
		this.setScore = setScore;
		this.server = server;
		this.teamName = teamName;
		this.setRemainTime(remainTime);
		//when it's in new expand page, the match info is above oddstable instead of in hour cell, so need to update that info.
		if (getIsInNewExpandPage()) {
			this.makeMatchInfoForExpandPage(); 
			//return;
			
		}
		
		//only update hour cell when it is live match
		if (this.showLive()) {			
			//update all hour cells of this match, including expanded ones.
			var betTypeObjs = this.getBetTypeObjs();	
			var counter = 0;	
			//content as replacement
			var content = '';
			//expanded lines
			if (this.expanded) {
				content = this.makeHourCellContent('','','1');		
				for(var i=0;i<betTypeObjs.length;i++){
					var betTypeTemp = betTypeObjs[i];	
					//set expanded row to be without match center
					if ($defined(betTypeTemp.betTypeRows)) {				
						for(var j=0 ;j<betTypeTemp.betTypeRows.length ;j++){
							var tdHour = betTypeTemp.betTypeRows[j].getElements('td.hourWidth');
							for (var k=0;k<tdHour.length;k++) {
								var targetCell = tdHour[k].getChildren('div');
								targetCell.setHTML(content);
							}
						}
					}
				}
			}
			content = this.makeHourCellContent('','','0');	
			//match line should have match center updated
			var hourCell = this.elementLine.getElements('td.hourWidth');
			if ($defined(hourCell)) {
				//do update
				var divCell = hourCell.getElement('div');
				divCell.setHTML(content);
			}
			//update matchCenter;
			this.makeMatchCenter();
			
		}		
	},
	makeHourCellContainer:function(htmlText) {
		var className = '',clickProperty='', liveNowDiv='',classPoint='',
			liveHiddenClass=' hidden ',hourCellHiddenClass='',stylePaddingTop=' style="padding-top:6px" ';
		if (this.showLive()) {
			if (this.isLive() && !this.isSeLive()) {
				if (this.disciplineId == disciplineIds.TENNIS){//for tennis, the match center box has fixed width
					className='livingfix  ';
				}else{
					className='living  ';
				}
				if( enableNewMatchCenter && !getIsInNewExpandPage() ){
					if($defined(this.elementLine.getNext())&&!this.elementLine.getNext().hasClass('hidden')){
						liveHiddenClass = '';
						hourCellHiddenClass = ' hidden ';
					}
					clickProperty=' onClick="showIsMatchCenter(this);" ';
					liveNowDiv='<div class="living point'+liveHiddenClass+'" '+stylePaddingTop+' onClick="showIsMatchCenterLiveNow(this)">'+nameOfMatchlivenow+'</div>';
					classPoint=' point ';
				}
			}else{ 
				//for se live and live at matches
				className='willBeLive';
			}
		} else {
				className='date';			
		}
		
		if(htmlText!==nameOfMatchlivenow)stylePaddingTop='';
		
		return '<div class="'+className+ classPoint+ hourCellHiddenClass +' "'+ clickProperty + stylePaddingTop + '>'+htmlText+'</div>'+liveNowDiv;
		//getIsInNewExpandPage	
	},
	makeSeLiveMatchCenter:function() {
		 if (this.isSeLive()) {
		 	
		 }
	},
	makeHourCellContent:function(dateText,hourText,showEmptyCell) {
		//icon which indicates match status	
		//var liveDiv = this.getMatchIcon();
		
		var defaultTxt = '&nbsp;';
		//for live match , don't show match center in expanded rows
		if (showEmptyCell=='1' && this.showLive())
			return defaultTxt;
		if (getIsInNewExpandPage())
			return defaultTxt;
		var dateCell='';
		if (this.isLive()) {
			//for se live match, show live now only
			if (this.isSeLive()) {
				dateCell = "<div class='SeLiveNow'>"+nameOfMatchlivenow+"</div>";
			} 
			else {
				//if this is a live match, show match info
				var timeStr = '';
				
				if (this.matchTimeType!=0)
					timeStr = "&nbsp;"+this.matchTime;
				if (this.disciplineId == disciplineIds.TENNIS) {//tennis: show only scores
					dateCell = this.formatTennisScore();
				}else if (this.disciplineId == disciplineIds.ICEHOCKEY || this.disciplineId == disciplineIds.BASKETBALL || this.disciplineId == disciplineIds.AM_FOOTBALL) {//ice hockey,BASKETBALL: don't show match time
					dateCell = "<ul class='matchInfo'><li>"+this.matchStatus
						+"</li><li class='hour'>"
						+this.score
						+"</li></ul>";
				} else {
					dateCell = "<ul class='matchInfo'><li>"+this.matchStatus
						+timeStr+"</li><li class='hour'>"
						+this.score
						+"</li></ul>";
				}
				if (enableNewMatchCenter ) {
					//--to be processed: make this a text and add it into textVars.jsp, then call it here
					this.makeMatchCenter();	
				} 
			}
		} else {
			//else show match date.
			if (operName =='NoIQ'){
				dateTimeLine = "<br>";
			}else{
				dateTimeLine = " ";
			}
			if (dateText==null || dateText=='' || hourText==null || hourText=='') {
				if( isHebrew ){
					m_names = m_names_num;
				}else{
					m_names = m_names_short;//default value 
				}
				dateText = (this.date.getDate()<10?'0'+this.date.getDate():this.date.getDate())+'.&nbsp;'+m_names[this.date.getMonth()];
				hourText = (this.date.getHours()<10?'0'+this.date.getHours():this.date.getHours())+':'+(this.date.getMinutes()<10?'0'+this.date.getMinutes():this.date.getMinutes());
				
				this.dateText = dateText;
				this.hourText = hourText;
			}
			if (this.showLive()) {
				dateCell = '<span><span class=\'liveAtPrefix\'>'+liveAt+'&nbsp;</span> <span class="date"> '+dateText+'</span></span>'+ dateTimeLine + '<span class="hour">' +hourText+'</span>';
			} else {
				dateCell = dateText + dateTimeLine + '<span class="hour">' +hourText+'</span>';
			}
		}
		return this.makeHourCellContainer(dateCell);
	},
	makeFootballMatchCenter:function() {
		//--to be processed: score should be abstracted from field this.score and this.setScore
		var score = this.score.split(':');
		var homeTeamScore = '';
		var awayTeamScore = '';
		if (score.length == 2 && $defined(score[0]) && $defined(score[1])) {
			homeTeamScore = score[0];
			awayTeamScore = score[1];
		}
		var setScoreStr = '(&nbsp;&ndash;&nbsp;)';
		var matchTimeStr = '&nbsp;';
		var sportsClass=[];
		sportsClass[disciplineIds.TENNIS] = 'Tennis';
		sportsClass[disciplineIds.ICEHOCKEY] = 'Ice-Hockey';
		sportsClass[disciplineIds.BASKETBALL] = 'Basketball';
		sportsClass[disciplineIds.AM_FOOTBALL] = 'Am-Football';
		
		if(this.disciplineId == disciplineIds.SOCCER || this.disciplineId == disciplineIds.HANDBALL ){
			if (this.matchTime!='')
				matchTimeStr = "("+nameOfMin+" "+this.matchTime+")";
			else
				matchTimeStr = '&nbsp;';
		}
		else if(this.disciplineId == disciplineIds.ICEHOCKEY || this.disciplineId == disciplineIds.BASKETBALL || this.disciplineId == disciplineIds.AM_FOOTBALL){
			if (this.remainTime!='')
				matchTimeStr = "("+nameOfRemainTime+" "+this.remainTime+")";
			else
				matchTimeStr = '&nbsp;';
		}
		
		if(this.setScore.length>0){
			setScoreStr = '';
			this.setScore.split(' - ').each(function(set){
				var setItems = set.split(':');
				setScoreStr = setScoreStr + '('+setItems[0]+'&ndash;'+setItems[1]+')'+'&nbsp;';
			});
		}
		
		return "<div class='EventScore "+ sportsClass[this.disciplineId] +"'><h2>"+
		this.generateHeaderOfMatchCenterHTML()+"</h2><h1><strong>"
		+this.homeParticipantName+"</strong><span>&nbsp;"+nameOfvs+"&nbsp;</span><strong>"+this.awayParticipantName
		+"</strong></h1><div class='fullScore'><div class='SimpleScoreboard home_score'><strong class='CH'>"
		+homeTeamScore+"</strong></div><div class='SimpleScoreboard match_details'><strong class='l-period'>"
		+this.matchStatus+"</strong><strong class='l-time'>"+matchTimeStr
		+"</strong></div><div class='SimpleScoreboard away_score'><strong class='CA'>"+awayTeamScore+"</strong></div><div class='Soon'>"
		+setScoreStr+"</div><div class='Spacer'>&nbsp;</div></div></div>";

		
	},
	makeTennisMatchCenter:function() {
		var setscore_1 = '1';
		var setscore_2 = '2';
		var setscore_3 = '3';
		var setscore_4 = '4';
		var setscore_5 = '5';
		var setscore_p = setscore_full_p;//'P';
		var setscore_g = 'G'; 
		var setscore_s = setscore_full_s;//'sets';
		var tournamentName = this.tournament.name; 

		var scoreHTML = '';
		var topRow ='';
		var bottomRow='';
		var scoreTop = '0';
		var scoreBottom = '0';
		//7:6-3:6-2:4
		var sets = this.setScore.split(' - ');
		var currentGame =0;
		if(sets[0].length>0) currentGame=sets.length;
		var scoreType = '1';
		var setsNum = 5;
		for (var i=0;i<setsNum;i++) {
			
			if (i == currentGame) {
				scoreType = '3';
				scoreHTML += this.makeTennisMatchCenterScore(scoreType,this.gameScore,eval('setscore_'+(i+1)) );	
				scoreType = '5';
			}
			else {
				var temp = '';
				if (sets[i]) {
					temp = sets[i];
				}
				scoreHTML += this.makeTennisMatchCenterScore(scoreType,temp,eval('setscore_'+(i+1)));
			}
		}
		scoreHTML += this.makeTennisMatchCenterScore('2',this.score,setscore_s);	
		scoreHTML += this.makeTennisMatchCenterScore('4',this.pointScore,setscore_p);	
		
		//--to be processed: there is no place to display tennis match status in new match center, to be confirmed with designer
		/**
		//add walkover ,retired team name before status
		var statusStr = this.matchStatus; 
		if ($defined(this.teamName) && this.teamName.length>0)
			statusStr = this.teamName +' '+ statusStr;
		var statusHTML = '<li class=\"matchstatus\">'+statusStr+'</li><li class=\"matchscore\">'+this.score+'</li>';
		**/
		//--

		//add a dot before the team on server
		var serverHomeClass = '';
		var serverAwayClass = '';
		if (this.server==1) {
			serverHomeClass = 'CH Serving';
			serverAwayClass = 'CA';
		} else if (this.server==2) {
			serverAwayClass = 'CH Serving';
			serverHomeClass = 'CA';
		} 

		var homeShortName = this.homeParticipantShortname.substring(0,19);
		var awayShortName = this.awayParticipantShortname.substring(0,19);

		var htmlStr = '<div class="EventScore Tennis"><h2>'+this.generateHeaderOfMatchCenterHTML() + '</h2><h1><strong>'+this.homeParticipantName+'</strong><span>&nbsp;'+nameOfvs+'&nbsp;</span><strong>'+this.awayParticipantName+'</strong></h1><div class="fullScore"><div class="fullCoreIcon"></div><div class="competitors"><div class="'+serverHomeClass+'">'+homeShortName+'</div><div class="'+serverAwayClass+'">'+awayShortName+'</div></div><ol class="scoreboard">'+scoreHTML+'</ol></div></div></td></tr>';

		return htmlStr;
	},
	generateHeaderOfMatchCenterHTML:function(){
		var matchObj = this;
		
		var tournamentName = matchObj.tournament.name; 
		var countryName = matchObj.tournament.country.name;
		var disciplineName = matchObj.tournament.country.discipline.name;
		var tournamentHTML = '';
		//for topsport, no link for tournament
		if (mypartnerId==44) {
			tournamentHTML = tournamentName;
		} else {
			tournamentHTML = "<a href='#' onclick='closeConnection();loadTournamentORMatch(\"&tournamentid="+matchObj.tournament.id+"\")'>"+tournamentName;
		}
		var sHTML = disciplineName+" / "+countryName+" / " + tournamentHTML +"</a>";
		return sHTML;
	},

	makeTennisMatchCenterScore:function(type,setScore,title) {
		var temp = setScore.split(':');
		var scoreTop = '0';
		var scoreBottom = '0';
		
		if (type=='2') {
			scoreTop = '0';
			scoreBottom = '0';			
		}
		
		if ($defined(temp[0]) && temp[0]!='')
			scoreTop = temp[0];
		
		if ($defined(temp[1]) && temp[1]!='') 
			scoreBottom = temp[1];
		
		var className='';
		if (type=='1')
			className = 'Passed';
		else if (type=='2')//total
			className = 'Score';
		else if (type=='3')//game point
			className = 'Current';
		else if (type=='4')
			className = 'Points';
		
		if (title=='')
			title = '&nbsp;';
										
		return '<li class=\''+className+'\'><em><span>Set</span>'+title+'</em><strong class="CH">'+scoreTop+'</strong><span>:</span><strong class="CA">'+scoreBottom+'</strong></li>'
	},
	
	makeMatchCenterLiveHTML:function(){
		var htmlStr = '';
		if (this.disciplineId == disciplineIds.TENNIS) {
				htmlStr = this.makeTennisMatchCenter();
		}else if (this.disciplineId == disciplineIds.ICEHOCKEY 
				|| this.disciplineId == disciplineIds.BASKETBALL
				|| this.disciplineId == disciplineIds.SOCCER
				|| this.disciplineId == disciplineIds.HANDBALL
				|| this.disciplineId == disciplineIds.AM_FOOTBALL) {
			
				htmlStr = this.makeFootballMatchCenter();
		}
		return htmlStr;
	},	
	makeMatchCenter:function() {
		var isResume = false;
		if(this.betStatus=='not_started') isResume=true;
		var htmlStr = '',matchCenter,matchCenterContainer;
		htmlStr = this.makeMatchCenterLiveHTML();
		var nextRow;
		if (getIsInNewExpandPage()) {
			matchCenter = $('topTableBody').getFirst();
		}else{
			var rowIndex = this.elementLine.rowIndex ;
			var addon = this.getDefaultMatchLinesCount()-1;
			nextRow = this.elementLine.parentNode.rows[rowIndex+ addon];
			matchCenter = nextRow;
		}
		if( $defined(matchCenter) && (matchCenter.hasClass('ScoreLine')||matchCenter.hasClass('matchInfoLine'))){
			
			if( isResume && !getIsInNewExpandPage()){
				this.matchCenterLine = matchCenter;
				matchCenter.getElement('td').setHTML('');
			}else if( isResume && getIsInNewExpandPage()){
				matchCenter.getElement('td').setHTML(this.makeMatchInfoHTMLForExpandPage());
			}else{
				matchCenter.getElement('td').setHTML(htmlStr);
			}
		}else if(!getIsInNewExpandPage()){
			var row=new Element('tr',{'class': 'ScoreLine hidden'});
			this.matchCenterLine = row;
			var td = new Element('td',{'colspan':'8','align':'center'});
			td.setHTML(htmlStr);
			td.injectInside(row);
			if (nextRow!=null)
				row.injectAfter(nextRow);
		}	
	},
	makeMatchInfoHTMLForExpandPage: function() {
		var matchObj = this;
		
		var tournamentName = matchObj.tournament.name; 
		var countryName = matchObj.tournament.country.name;
		var disciplineName = matchObj.tournament.country.discipline.name;
		
		var dateText = (matchObj.date.getDate()<10?'0'+matchObj.date.getDate():matchObj.date.getDate())+' &nbsp;'+M_names_full[matchObj.date.getMonth()];
		var hourText = (matchObj.date.getHours()<10?'0'+matchObj.date.getHours():matchObj.date.getHours())+':'+(matchObj.date.getMinutes()<10?'0'+matchObj.date.getMinutes():matchObj.date.getMinutes());
			
		var html = "<div class='EventScore Football'><h2>"+this.generateHeaderOfMatchCenterHTML()+"</h2><h1><strong>"+matchObj.homeParticipantName+"</strong>"
		if (matchObj.awayParticipantName!='')
				html = html +"<span>&nbsp;"+nameOfvs+"&nbsp;</span><strong>"+matchObj.awayParticipantName+"</strong>" ;
				
		html = html + "</h1><div class='fullScore'><div class='Soon'>";

		if (matchObj.isLive()) {		
			html += "<strong class='LIVE'>"+nameOfMatchlivenow+"</strong>";	;		
		} else if (matchObj.showLive()) {
			html += "<strong class='LIVE'>"+nameOf_LIVE+"</strong>"+' '+nameOf_on+' '+dateText+' '+ nameOf_at+' '+hourText;	
		} else {
			html +=  nameOf_starting+' '+nameOf_on+' '+dateText+' '+ nameOf_at+' '+hourText;	
		}
	
		html += "</div></div></div>";	
		return html;	
	},
	makeMatchInfoForExpandPage:function() {
		
		var html = '';
		if( this.isLive() ){ 
			html = this.makeMatchCenterLiveHTML();
		}else{
			html = this.makeMatchInfoHTMLForExpandPage();	
		}
		var matchInfoLine = $('matchInfoLine');
		//create matchInfoLine
		if (!$defined(matchInfoLine)) {
			var row = new Element('tr',{'class':'matchInfoLine','id':'matchInfoLine'});
			var td = new Element('td',{'id':'matchInfoCell','colspan':'8','align':'center'});
			td.injectInside(row);	
			row.injectTop(topTableBody);				
		}
		//set html with content
		$('matchInfoCell').setHTML(html);
		
		//hide traditional date cell on match line , and discipline, country, tournament above as well
		$('oddstableTable').getElements('tr.titleLine').each(function(obj,i){ 
			if (i<2) { 
				obj.style.display = "none"; 
			} else if (i==2){
				//obj.getElement('.TourName').setHTML(nameOfMatchOdds);
				obj.getElement('.TourName').setHTML('');  
			} 
		}); 
		
		if (!this.isLive()) {
			$('oddstableTable').getElements('td.hourWidth').each(function(obj){ 
				obj.getChildren('div').setHTML('&nbsp;') 
			}); 
		}
	},
	
	
	
	formatTennisScore:function() {
		var scoreHTML = '';
		var topRow ='';
		var bottomRow='';
		var scoreTop = '0';
		var scoreBottom = '0';
		
		//total score
		//scoreHTML += this.formatTennisSetScore('2',this.score);
		
		//7:6-3:6-2:4
		var sets = this.setScore.split(' - ');
		var setsNum = 5;
		for (var i=0;i<setsNum-1;i++) {
			var temp = '';
			if (sets[i]) {
				temp = sets[i];
			}
			scoreHTML += this.formatTennisSetScore('1',temp,eval('setscore_'+(i+1)),setsNum);			
		}
		scoreHTML += this.formatTennisSetScore('3',this.gameScore,setscore_g,setsNum);	
		scoreHTML += this.formatTennisSetScore('4',this.pointScore,setscore_p,setsNum);	
		
		//add walkover ,retired team name before status
		var statusStr = this.matchStatus; 
		if ($defined(this.teamName) && this.teamName.length>0)
			statusStr = this.teamName +' '+ statusStr;
		var statusHTML = '<li class=\"matchstatus\">'+statusStr+'</li><li class=\"matchscore\">'+this.score+'</li>';
		
		//add a dot before the team on server
		var serverHTML = '<li class=\'item\'><ul class=\'server\'><li class=\'settitle\'>&nbsp;</li>';
		if (this.server==1) {
			serverHTML += '<li class=\"onserver\">&nbsp;</li><li class=\'score\'>&nbsp;</li></ul></li>';
		} else if (this.server==2) {
			serverHTML += '<li class=\'score\'>&nbsp;</li><li class=\"onserver\">&nbsp;</li></ul></li>';			
		} else {
			serverHTML += '<li class=\'score\'>&nbsp;</li><li class=\'score\'>&nbsp;</li></ul></li>';			
		}
		
		scoreHTML = '<ul class=\'scoreList\'>'+statusHTML+serverHTML + scoreHTML+'</ul>';
		return scoreHTML;
	},
	formatTennisSetScore:function(type,setScore,title,setsNum) {
		var temp = setScore.split(':');
		var scoreTop = '&nbsp;';
		var scoreBottom = '&nbsp;';
		
		if (type=='2') {
			scoreTop = '0';
			scoreBottom = '0';			
		}
		
		if ($defined(temp[0]) && temp[0]!='')
			scoreTop = temp[0];
		
		if ($defined(temp[1]) && temp[1]!='') 
			scoreBottom = temp[1];
		
		var className='';
		if (type=='2')
			className = 'totalscore_'+setsNum;
		else if (type=='3')
			className = 'gamescore_'+setsNum;
		else if (type=='4')
			className = 'pointscore_'+setsNum;
		else 
			className = 'setscore_'+setsNum;
		
		if (title=='')
			title = '&nbsp;';
			
		return '<li class=\'item\'><ul class=\''+className+'\'><li class=\"settitle\">'+title+'</li><li class=\"score\">'+scoreTop+'</li><li class=\"score\">'+scoreBottom+'</li></ul></li>';
	},
	getDivId:function() {
		var divId='MarketR1';
		if (getIsInNewExpandPage()){
			divId='MarketR2';
		}
		return divId;
	},
	getHeadDivId:function() {
		var divId='MarketH1';
		if (getIsInNewExpandPage()){
			divId='MarketH2';
		}
		return divId;
	},
	prepareForDump: function(imgId){
		var divId=this.getDivId();
		var hourCell=new Element('td',{'class': 'hourWidth','colspan':'2'});
		hourCell.setHTML('<div id="'+divId+'">' +this.makeHourCellContent()+'</div>');
		
		var homeCell=new Element('td',{'class': 'teamWidth'});
		//homeCell.setStyle("padding-left","5px");
		homeCell.setHTML('<div id="'+divId+'" style="padding-left:5px">' +this.homeParticipantName+'</div>');
		var awayCell=new Element('td',{'class': 'teamWidth'});
		awayCell.setHTML('<div id="'+divId+'">' +this.awayParticipantName+'</div>');

		hourCell.injectInside(this.elementLine);
		homeCell.injectInside(this.elementLine);
		awayCell.injectInside(this.elementLine);
		
		this.imgId = imgId;
		var needShowEmptyOddsMatch = false;
		if (this.betTypes.length==0 || getIsInNewExpandPage())
			needShowEmptyOddsMatch = true;
			
		if(this.showDefaultBetType()){
			this.showDefaultOutcomeType(this.tournament.defaultOutcomeType,needShowEmptyOddsMatch);
		} else if (needShowEmptyOddsMatch) {
			this.showEmptyOddsMatch();		
			var otherOutrights = this.computeOtherOutrights();
			this.showExpandCell(otherOutrights);
		}

	},
	setDate: function(date){
		this.date=util.getDateFromJavaString(date);
	},
	setEvtType:function(evtType) {
		this.evtType = evtType;
		
		//for se live match, make fake betstatus for dispaly convenience
		if (this.evtType==2)
			this.betStatus = 'not_started';
		else if (this.evtType==3)
			this.betStatus = 'started';
	},
	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){		
		if (this.disciplineId == disciplineIds.HORSERACEING && oddsValue==1) return;//for horseracing , odds value of 1.0 can't be placed bet on
		if (oddsValue<=minOddsNum ) {
			if (getOddsShowType(oddsValue)===3) {
				 oddsValue = 1.01;
				 formattedValue = symbolForSmallOdds;
			}
			else
				return;//if odds less than min odds line then return
		} 
		var typeId=elementStorage.obj[outcomeId].betType.typeId;
		var title = this.name;
		if (betTypes.TYPE_ID_HEAD_2==typeId || betTypes.TYPE_ID_HEAD_3==typeId   ){
			title = elementStorage.obj[outcomeId].title;
		}
		addNewBet(this.id, outcomeId,oddsValue.toFixed(2),formattedValue,title,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,
			{"disciplineId":this.disciplineId,"betTypeId":elementStorage.obj[outcomeId].betType.typeId,
			"tennisScoreParam":elementStorage.obj[outcomeId].betType.extraOutcomeInfo.obj[outcomeId].doubleParameter2});
	},
	addBetTypeToDOM: function(newBetType){
		if (newBetType.typeId == this.tournament.defaultOutcomeType.betTypeId && newBetType.scopeId == this.tournament.defaultOutcomeType.scopeId) {
			if ($defined(this.elementLine)) {
				//for empty match row without odds, left there when match is expanded and default bet type odds removed
				//removed odds cells before show default bet type 
				var tdOdds =this.elementLine.getElements('td');
				var l = tdOdds.length;
				if (l==7) {
					for (var j=3; j< l; j++){//for non-outrights bettype
						tdOdds[j].remove();
					}
				} else if (l==5) {//for outrights bettype
					for (var k=3; k< l; k++){
						tdOdds[k].remove();
					}					
				}
			}
			this.showDefaultOutcomeType(this.tournament.defaultOutcomeType);
		}
		else if (this.isExpanded){
			var rowIndex = this.elementLine.rowIndex ;
			var addon = this.getDefaultMatchLinesCount();
			var nextRow = this.elementLine.parentNode.rows[rowIndex+ addon];
	
			var betTypes = this.getBetTypeObjs();
			
			//sort the bettpyes according the letter, if cancel the next row , it will sort according to the typeId
			betTypes.sort(this.sortExpandBetTypes);
			//now find the place where to insert the new betType
			var nrOfRows = 0;
			
			for(var i=0;i<betTypes.length;i++){
				var betType=betTypes[i];
				if (betType.typeId == newBetType.typeId && betType.scopeId == newBetType.scopeId){
					nextRow = this.elementLine.parentNode.rows[rowIndex + nrOfRows+addon];
					betType.insertIntoDOM(nextRow, true);
					break;
				} else {
					if (betType.typeId == this.tournament.defaultOutcomeType.betTypeId && betType.scopeId == this.tournament.defaultOutcomeType.scopeId) {
						
					} else {
						nrOfRows += (betType.betTypeRows.length);
					}
				}
			}
		}
	},
	//this is the count of rows of (default bettype + new match center). this number is used for adding new bettype.
	getDefaultMatchLinesCount:function() {
		var defaultBetTypeLength = this.rowCount+1;
		if (this.hasNewMatchCenterRow()) {
			defaultBetTypeLength += 1;
		}
		return defaultBetTypeLength;
	},
	//whether this match has a new match center row under it's matchline, no matter it's visible or not.
	hasNewMatchCenterRow:function() {
		if (this.matchCenterLine!=null){
			return true;
		}else{
			return false;
		}
	},
	expandFully: function(){
		this.isExpanded = true;
		this.expanded=true;
		
		var rowIndex = this.elementLine.rowIndex ;
		var addon = this.getDefaultMatchLinesCount();
		var nextRow = this.elementLine.parentNode.rows[rowIndex+ addon];

		var betTypes = this.getBetTypeObjs();		
		//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[i];
			betType.insertIntoDOM(nextRow, false);
		}
		afterInsertExpandedMatchIntoDOM();
	},
	
	sortExpandBetTypes: function(a,b){		
		var match = a.match;
		if ( (match.disciplineId == disciplineIds.SOCCER
			|| match.disciplineId == disciplineIds.TENNIS
			|| match.disciplineId == disciplineIds.ICEHOCKEY
			|| match.disciplineId == disciplineIds.BASKETBALL
			|| match.disciplineId == disciplineIds.HANDBALL
			|| match.disciplineId == disciplineIds.AM_FOOTBALL
		)) {
			var aorder = match.getBetTypeOrder(a);
			var border = match.getBetTypeOrder(b);
			
//			var indexa = (a.name).indexOf(';');
//			if (indexa<0)
//				indexa = a.name.length;
//				
//			var indexb = (b.name).indexOf(';');
//			if (indexb<0)
//				indexb = b.name.length;
//				
//			a.name = (a.name).substr(0,indexa)+';'+aorder;
//			b.name = (b.name).substr(0,indexb)+';'+border;
			if(aorder>=border)
				return -1;
			else if(aorder<border)
				return 1;
			
		} else {
			if (a.typeId == betTypes.TYPE_ID_TEAM_KICKS_OFF)
				return -1;
			if (b.typeId == betTypes.TYPE_ID_TEAM_KICKS_OFF)
				return 1;	
			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;
	},
	getBetTypeOrder: function(betTypeObj) {
		var match = betTypeObj.match;
		
		var orderList = this.getOrderList(match.disciplineId,match.isLive());
		if (orderList==null)
			return -1;
			
		var typeId = betTypeObj.typeId;
		var scopeId = betTypeObj.scopeId;
		var key1st = typeId+','+scopeId;
		var key2nd = typeId;
		
		var value = orderList.get(key1st);
		if (value == null) {
			value = orderList.get(key2nd);
		}
		if (value == null) {
			value = 0;
		}
		return value;
	},
	getOrderList: function(disciplineId,isLive) {
		if (isLive) {
			if ( disciplineId == disciplineIds.SOCCER)
				return liveFootballOrder;
				
			else if ( disciplineId == disciplineIds.TENNIS)
				return liveTennisOrder;
				
			else if ( disciplineId == disciplineIds.ICEHOCKEY)
				return liveIcehockyOrder;
				
			else if ( disciplineId == disciplineIds.BASKETBALL)
				return liveBasketballOrder;
			
			else if ( disciplineId == disciplineIds.HANDBALL)
				return liveHandballOrder;
            else if ( disciplineId == disciplineIds.AM_FOOTBALL)
                return liveHandballOrder;
		} else {
			if ( disciplineId == disciplineIds.SOCCER)
				return preliveFootballOrder;
				
			else if ( disciplineId == disciplineIds.TENNIS)
				return preliveTennisOrder;
				
			else if ( disciplineId == disciplineIds.ICEHOCKEY)
				return preliveIcehockyOrder;
				
			else if ( disciplineId == disciplineIds.BASKETBALL)
				return preliveBasketballOrder;
			
			else if ( disciplineId == disciplineIds.HANDBALL)
				return preliveHandballOrder;
            else if ( disciplineId == disciplineIds.AM_FOOTBALL)
                return preliveHandballOrder;
		}
		return null;
	},

	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;		
		rez = true;// for temporary test
		return rez;
	},
	setOddsValue: function(betType, scopeId, oddsId, oddsValue, formattedValue){
		if ($defined(this.betTypes[betType])){
			var bType = this.betTypes[betType][scopeId];
			if (bType != null)
				bType.setOddsValue(oddsId, oddsValue, formattedValue,betType);
		}
	},
	getOdds: function(betType, scopeId, oddsId){
		if ($defined(this.betTypes[betType])){
			var bType = this.betTypes[betType][scopeId];
			if (bType != null)
				return bType.getOdds(oddsId);
		}
	}
});

function isParis365() {
	if (mypartnerId == 36)//paris365
		return true;
	else 
		return false;
}
function getOddsShowType(value) {
	if (isParis365()) {
		if (value==null || value<=minOddsNum) {
			return 3;
		}
	} else {
		if (value==null || value<minOddsNum) {
			return 2;			
		}
	}
	
	return 1;
}

var BetType = CategElement.extend ({
	initialize: function(typeId,scopeId){
		this.typeId=typeId;
		this.scopeId=scopeId;
		this.odds=new Hash();
		this.extraOutcomeInfo=new Hash();
		this.isDefaultBetType = false;
	},
	countNrOfbo:function() {
		var nrOfBo = 0;
		var oddsParam = this.odds.values();
		var oddsL = oddsParam.length;
		for (var i =0; i<oddsL; i++){
			var oddsObj = oddsParam[i].keys();
			nrOfBo += oddsObj.length;
		}
		this.nrOfBo = nrOfBo;
		return nrOfBo;
	},
	countBettypes:function() {
		var nrOfBettypes = 0;
		var oddsParam = this.odds.values();
		var oddsL = oddsParam.length;
		nrOfBettypes +=  oddsL;
		this.nrOfBettypes = nrOfBettypes;
		return nrOfBettypes;
	},
	addOdds: function(doubleParameter,odds,integerParameter,match){
		odds.setBetType(this);
	//--------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);
			}
		}

		else 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);
		}
	},
	deleteOdds: function(oddsId){
		var oddsParam = this.odds.values();
		var oddsParamKeys = this.odds.keys();
		var oddsParamKey='';
		var oddsL = oddsParam.length;
		for (var i =0; i<oddsL; i++){
			var oddsObj = oddsParam[i].get(oddsId);
			if (oddsObj == null )
				continue;
				
			oddsParamKey = oddsParamKeys[i];
			//get the cell - change the value
			var html = this.addText_odds(this.match.getOddsCellText(i+1));
			if ($defined(oddsObj.topElement)) {
				oddsObj.topElement.setHTML(html);
			} 
			//remove the odds
			oddsParam[i].remove(oddsId);
			break;
		}	
		//if this is not default bettype and neither expanded
		//if (!(this.isDefaultBetType && (this.match.expanded || this.match.showLive()))) {
			//remove this bettype if no more odds is available
			if (isMultiRowBetType(this.typeId)) {
				
				if (oddsParamKey!='' && this.odds.get(oddsParamKey).length ==0) {
					this.odds.remove(oddsParamKey);
				}
				if (this.odds.keys().length == 0) {
					this.match.deleteBetTypeRows(this.typeId, this.scopeId, oddsParamKey);		
				}			
			} 
			else {
				if ((this.odds.keys().length == 0 || oddsParamKey!='' && this.odds.get(oddsParamKey).length ==0) ) {
					this.match.deleteBetTypeRows(this.typeId, this.scopeId, oddsParamKey);	
				}
			}
		//}
	},
	setOddsValue: function (oddsId, oddsValue,formattedValue,betTypeId){
		var oddsParam = this.odds.values();
		var oddsL = oddsParam.length;
		for (var i =0; i<oddsL; i++){
			var oddsObj = oddsParam[i].get(oddsId);
			if (oddsObj == null)
				continue;
			//var html = oddsFormattedValue(oddsValue);
			oddsObj.setValue(oddsValue,formattedValue,betTypeId);
			break;
		}
	
	},
	getOdds: function (oddsId){
		var oddsParam = this.odds.values();
		var oddsL = oddsParam.length;
		var outcomeArray = new Array();
		for (var i =0; i<oddsL; i++){
			var oddsObj = oddsParam[i].get(oddsId);
			if (oddsObj != null) {
				outcomeArray[0] = oddsObj;
				outcomeArray[1] = this.extraOutcomeInfo.get(oddsId);
				return outcomeArray;
			}
		}	
	},
	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, false);
	},
	removeFromDOM: function(type,outcomeId){
		if (!$defined(this.betTypeRows))
			return;
			
		//clear timeout attribute of odds object
		if (type=='2') {
			var oddsParam = this.odds.values();
			var oddsL = oddsParam.length;
			for (var i =0; i<oddsL; i++){
				var oddsArray = oddsParam[i].values();
				if (oddsArray!=null) {
					for (var f =0; f<oddsArray.length; f++){
						if (oddsArray[f]!=null && outcomeId==oddsArray[f].id)
							clearTimeout(oddsArray[f].blink);				
					}
				}
			}	
		}
		
		if (type=='1') {//remove even the title row
			for(var i=0 ;i<this.betTypeRows.length ;){
				this.betTypeRows[i].remove();	
				this.betTypeRows.splice(i,1);
				if (this.isDefaultBetType)			
					this.match.rowCount--;
			}
		} else {
			for(var i=0 ;i<this.betTypeRows.length ;i++){
				if (this.match.elementLine != this.betTypeRows[i]) {
					this.betTypeRows[i].remove();
					////this.betTypeRows.splice(i,1);
					if (this.isDefaultBetType)		
						this.match.rowCount--;
				}
				else {
					var tdOdds =this.betTypeRows[i].getElements('td');
					var l = tdOdds.length;		
					var start = 3;	
					if (l==7) {
						for (var j=start; j< l; j++){//for non-outrights bettype,remove last 4 cells for odds
							tdOdds[j].remove();
						}
					} else if (l==5) {//for outrights bettype
						for (var k=start; k< l; k++){
							tdOdds[k].remove();
						}					
					}
				}
			}
		}
	},
	deleteBetTypeRows: function(dbParam1){
		//for bettype like 510,512, remove all of it's rows under this param
		if (isEmptyMatchLineBetType(this.typeId)) {
			var l = this.betTypeRows.length || 0;	
			//remove odds lines	
			for (var h=1;h<l;h++) {
				this.betTypeRows[1].remove();	
				this.betTypeRows.splice(1,1);	
				if (this.isDefaultBetType)
					this.match.rowCount--;
			}
			this.odds.remove(dbParam1);
			//only the header is left - remove it
			if (this.betTypeRows.length == 1){ 
				this.betTypeRows[0].remove();	
				this.betTypeRows.splice(0,1);
				if (this.isDefaultBetType)
					this.match.rowCount--;
				this.match.removeBetType(this.typeId, this.scopeId);
			}
			return;
		}
						
						
		var params = this.odds.keys();
		params.sort(this.sortAsianHandicap);
		var i =0;
		for (i=0; i< params.length; i++){
			if (params[i] == dbParam1)
				break;
		}
		if ( i == params.length && (this.betTypeRows == null || this.betTypeRows.length==0))
			return;	
			
		if (this.isDefaultBetType) {	
			//remove from memory
			this.odds.remove(dbParam1);
			//remove row from DOM
			this.betTypeRows[i].remove();
			this.betTypeRows.splice(i,1);	
			this.match.removeBetType(this.typeId, this.scopeId);		
		} else {		
			//remove from memory
			this.odds.remove(dbParam1);
			//remove row from DOM
			if (this.betTypeRows != null) {
				if ($defined(this.betTypeRows[i+1])) {
					this.betTypeRows[i+1].remove();
					this.betTypeRows.splice(i+1,1);
				}
				if (this.betTypeRows.length == 1){ //only the header hass left - remove it
					this.betTypeRows[0].remove();
					this.match.removeBetType(this.typeId, this.scopeId);
					this.betTypeRows.splice(0,1);
				}
			}
		}
	},
	insertIntoDOM: function(parentNode, override){
		if($defined(this.isExpanded)){
			for(var i=0;i<this.betTypeRows.length;i++){
				this.betTypeRows[i].remove;
				this.betTypeRows[i]=null;
			}
			this.betTypeRows=null;
		}
		
		if (this.typeId == this.match.tournament.defaultOutcomeType.betTypeId && this.scopeId == this.match.tournament.defaultOutcomeType.scopeId){
			return;
		}

		this.appendOddsToTheRow(null, override);		
		
		var tmpNode = parentNode.getPrevious();
		
		if (this.betTypeRows==null)
			return;
				
		for(var i=0 ;i<this.betTypeRows.length ;i++){
            var rows = this.betTypeRows[i];
            var isTitle = false;
            var htmlCode = rows.innerHTML;
            //BettypeHeadline is for bettypes like 'the score of game x set n'
            if( htmlCode.indexOf('MarketH2') > 0 || rows.hasClass('matchLine') || htmlCode.indexOf('BettypeHeadline') > 0 )
            	 isTitle=true ;
             else
             	 isTitle=false;

            if (!isTitle){
            	if (this.match.isExpanded){
					var extraCell =new Element('td',{'class':'expandable'});
					extraCell.setHTML('<div id="MarketR2">&nbsp;</div>');
					extraCell.injectInside(rows);
				}
			}

			rows.injectAfter(tmpNode);
			tmpNode = rows;
		}

	},
	makeNameCell: function(date,hour,homeParticipantName,awayParticipantName,clone){
		if($defined(this.match.nameCellStandard) && clone)
			return this.match.nameCellStandard.clone(true);
		//if(isExpend)
		if (this.match.isExpanded)
			var nameCell=new Element('tr',{'class':this.match.id,"id":"R2"});
		else
			var nameCell=new Element('tr',{"id":"R2"});
		var divId=this.getDivId();
		var hourCell=new Element('td',{'class':'hourWidth','colspan':'2'});
		hourCell.setHTML('<div id="'+divId+'">' +this.match.makeHourCellContent(date,hour,'1')+'</div>');

		var homeName = homeParticipantName;
		var awayName = awayParticipantName;
		if (betTypes.TYPE_ID_SETS_NUMBER_3 == this.typeId || betTypes.TYPE_ID_SETS_NUMBER_5 == this.typeId) {			
			homeName = '&nbsp;';
			awayName = '&nbsp;';		
		}
		var team1Cell=new Element('td',{'class': 'teamWidth'});
		team1Cell.setHTML('<div id="'+divId+'"><div style="padding-left:5px">'+ homeName+'</div></div>');
		var team2Cell=new Element('td',{'class': 'teamWidth'});
		team2Cell.setHTML('<div id="'+divId+'"><div>'+ awayName+'</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(this.isR2Row()){
			nameCell = new Element('tr',{'id':'R2','class':this.match.id});
		}else{
			nameCell = new Element('tr',{'class':'matchLine'});
		}
		var divId=this.getDivId();

		var hourCell=new Element('td',{'class': 'hourWidth','colspan':'2'});
		hourCell.setHTML('<div id="'+divId+'">'+this.match.makeHourCellContent(date, hour,'1')+'</div>');

		var team1Cell=new Element('td',{'class': 'teamWidth'});
		team1Cell.setHTML('<div id="'+divId+'" style="padding-left:5px">'+this.addCssToTeam1(homeParticipantName)+'</div>');
		var team2Cell=new Element('td',{'class': 'teamWidth'});
		team2Cell.setHTML('<div id="'+divId+'">'+awayParticipantName+'</div>');

		hourCell.injectInside(nameCell);
		team1Cell.injectInside(nameCell);
		team2Cell.injectInside(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;
	},
	sortParamDescend: 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;
	},

	sort1x2Handicap: function(a,b){
		var betTypeObj = this;
		var homeId = betTypeObj.match.homeParticipantId;
		var oddsMap = betTypeObj.odds;
		
		var oddsA = oddsMap.get(a).values();
		var oddsB = oddsMap.get(b).values();
		var oddsArray = [];
		var homeOddsArray = [];
		oddsArray[0] = oddsA;
		oddsArray[1] = oddsB;
		
		if (oddsA!=null && oddsB!=null) {
			for (var i=0;i<2;i++) {
				var oddsObjArray = oddsArray[i];
				for (j=0;j<oddsObjArray.length;j++) {
					var oddsObj = oddsObjArray[j];
					var extraInfo=betTypeObj.extraOutcomeInfo.get(oddsObj.id);
					var resultId = extraInfo.resultId;
					if (resultId==1 && homeId == extraInfo.integerParameter) {
						homeOddsArray[i] = oddsObj;
						break;
					}
				}
			}
		}
		
		if (homeOddsArray.length==2) {
			var valueA = homeOddsArray[0].value;
			var valueB = homeOddsArray[1].value;
			if(valueA==valueB) 
				return 0;
			else if(valueA>valueB) 
				return 1;
			else if(valueA<valueB) 
				return -1;
		}
		
		return 0;
	},
	
	addStyle:function(text){
		return '<div id="MarketH2"><div id="GameHeadline1X2"><p>'+text+'</p></div></div>';
	},
	isR2Row:function() {
		if (!this.isDefaultBetType || getIsInNewExpandPage()) {
			return true;
		}
		return false;			
	},
	appendOddsToTheRow: function(parentRow, override){
		if (this.typeId == this.match.tournament.defaultOutcomeType.betTypeId && this.scopeId == this.match.tournament.defaultOutcomeType.scopeId)
			this.isDefaultBetType = true;

		// 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)){
			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.isDefaultBetType) && !override){
			return;
		}
		this.betTypeRows =[];
		if(parentRow==null){
			//if(isExpend)
			if (this.match.isExpanded)
				var betTypeHeader = new Element('tr',{'class':this.match.id});
			else
				var betTypeHeader=new Element('tr');

			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 
				|| betTypes.TYPE_ID_GOALS_HOME_TEAM==this.typeId 
				|| betTypes.TYPE_ID_GOALS_AWAY_TEAM==this.typeId
				|| betTypes.TYPE_ID_SETS_NUMBER_3==this.typeId
				|| betTypes.TYPE_ID_SETS_NUMBER_5==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 = this.match.tournament.getTitle(this.typeId);

				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 (this.match.isExpanded){
					var extraCell =new Element('td',{'class':'expandable'});
					extraCell.setHTML('<div id="MarketH2">&nbsp;</div>');
					extraCell.injectInside(betTypeHeader);
				}
			}

			this.betTypeRows.push(betTypeHeader);
		}
		var outcomeName=this.name;

		var homeParticipantName=this.match.homeParticipantName;
		var awayParticipantName=this.match.awayParticipantName;


		if( isHebrew ){
			m_names = m_names_num;
		}else{
			m_names = m_names_short;//default value 
		}
		var dateText = this.match.dateText;
		if (dateText==null || dateText=='') {
			dateText=''+(this.match.date.getDate()<10?'0'+this.match.date.getDate():this.match.date.getDate())+'.&nbsp;'+m_names[this.match.date.getMonth()];
			this.match.dateText = dateText;
		}
		
		//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.hourText;
		if (hourText==null || hourText=='') {
			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());
			this.match.hourText = hourText;
		}
		
		if(betTypes.TYPE_ID_HOME_DRAW_AWAY==this.typeId || betTypes.TYPE_ID_NEXT_TEAM_TO_SCORE==this.typeId  
			|| betTypes.TYPE_ID_TEAM_WINS_REST_MATCH==this.typeId  || betTypes.TYPE_ID_NEXT_GOAL==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;
					this.betTypeRows.push(betTypeRow);
				}
				var oddsValues=[];
				var homeOdds=null;
				var drawOdds=null;
				var awayOdds=null;

				oddsValues=this.odds.get(doubleNULL).values();
				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'});
				var middleTitle = nameOfDraw;
				if (betTypes.TYPE_ID_NEXT_TEAM_TO_SCORE==this.typeId || betTypes.TYPE_ID_NEXT_GOAL==this.typeId)
					middleTitle = nameOfNoGoals;
					
				if($defined(homeOdds)){
					cellHome.setHTML(this.addDivToText_odds(homeOdds.value,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_om(this.match,args));
					homeOdds.setTopElement(cellHome,args);
				}else{
					cellHome.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				var cellX=new Element('td',{'class': 'oddsCell'});
				if($defined(drawOdds)){
					cellX.setHTML(this.addDivToText_odds(drawOdds.value,drawOdds.formattedValue));
					var args=new Array(drawOdds.id , drawOdds.value,drawOdds.formattedValue,middleTitle,''+outcomeName,middleTitle);
					cellX.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind_om(this.match,args));
					drawOdds.setTopElement(cellX,args);
				}else{
					cellX.setHTML(this.addText_odds(this.match.getOddsCellText(2,this.typeId)));
				}
				var cellAway=new Element('td',{'class': 'oddsCell'});
				if($defined(awayOdds)){
					cellAway.setHTML(this.addDivToText_odds(awayOdds.value,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_om(this.match,args));
					awayOdds.setTopElement(cellAway,args);
				}else{
					cellAway.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				cellHome.injectInside(betTypeRow);
				cellX.injectInside(betTypeRow);
				cellAway.injectInside(betTypeRow);
		}
		//outrights
		else 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 
			|| betTypes.TYPE_ID_HEAD_2==this.typeId 
			|| betTypes.TYPE_ID_HEAD_3==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;
					this.betTypeRows.push(betTypeRow1);
				}
				
				//
				var oddsGroups = new Hash();	
				var divId=this.getDivId();
				
				var titleName = headTitle.HEADTITLE_HEAD_2;
				if (betTypes.TYPE_ID_HEAD_2==this.typeId || betTypes.TYPE_ID_HEAD_3==this.typeId   ) {
					var parameters=this.odds.keys();			
					for(var k=0;k<parameters.length;k++){
		
						var oddsValues=this.odds.get(parameters[k]).values();
		
						var homeOdds=null;
						var awayOdds=null;
						for(var j=0;j<oddsValues.length;j++){
							var currentOddsObj = oddsValues[j];
							var extraInfo=this.extraOutcomeInfo.get(currentOddsObj.id);
							var i1 = extraInfo.integerParameter;
							var i2 = extraInfo.integerParameter2;
							var i3 = extraInfo.integerParameter3;
							var db1 = extraInfo.doubleParameter;
							var db2 = extraInfo.doubleParameter2;
							var index = db1 - 1;
							var groupKey = i1+','+i2+','+i3;
							var groupValues = oddsGroups.get(groupKey);
							if (groupValues == null) {
								groupValues = [];
								oddsGroups.set(groupKey,groupValues);
							} 
							groupValues[index] = [];
							groupValues[index][0] = db2;
							groupValues[index][1] = currentOddsObj;
						}
					}
					
					if (betTypes.TYPE_ID_HEAD_3==this.typeId) {
						 titleName = headTitle.HEADTITLE_HEAD_3;
					}
				} else {
					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);
					oddsGroups.set('1',tempArrayForSort);
				}
				titleName = titleName.drawText;
				var divId=this.getDivId();
				var lastRow = parentRow;
				
				var groupKeys = oddsGroups.keys();
				var Head_n_title="";
				for(var gk = 0;gk<groupKeys.length;gk++) {
					var groupKey = groupKeys[gk];
					var tempArrayForSort = oddsGroups.get(groupKey);
					Head_n_title="";
					if (tempArrayForSort!=null && tempArrayForSort.length > 0 ) {
						for(var j=0;j<tempArrayForSort.length;j++){
							if (tempArrayForSort[j]!=null)
								Head_n_title += tempArrayForSort[j][0]+" - "
						}
						//if (Head_n_title!='') Head_n_title = Head_n_title.substring(0,Head_n_title.length - 2);
					   if (Head_n_title!=''){
					   	Head_n_title=Head_n_title.substring(0,Head_n_title.length - 3);
						   	for(var j=0;j<tempArrayForSort.length;j++){
								if (tempArrayForSort[j]!=null)
									tempArrayForSort[j][1].title=Head_n_title;
							}
					   	}
					   
					}
					
					
				}
				for (var gk = 0;gk<groupKeys.length;gk++) {
					var groupKey = groupKeys[gk];
					var tempArrayForSort = oddsGroups.get(groupKey);
					if(gk>0){
								
						var gameHeader=new Element('tr');
						var gameHeaderTd1 = new Element('td',{'colspan':4});
						gameHeaderTd1.injectInside(gameHeader);
						var gameHeaderTd2 = new Element('td',{'class':'oddsCell','colspan':3});
						gameHeaderTd2.injectInside(gameHeader);
						var gameHeaderTd3 = new Element('td',{'colspan':1});
						gameHeaderTd3.injectInside(gameHeader);
						if(!this.isR2Row()){
							gameHeader.className = 'matchLine';
							gameHeaderTd2.setHTML('<div id="MarketH2h" class="marketH2H"><div class="GameHeadline1X2"><p>'+titleName+'</p></div></div>');
							
						}
						else {
							gameHeaderTd1.setHTML('<div id="MarketH2">&nbsp;</div>');
							gameHeaderTd2.setHTML('<div id="MarketH2"  class="marketH2H"><div class="GameHeadline1X2"><p>'+titleName+'</p></div></div>');
							gameHeaderTd3.setHTML('<div id="MarketH2">&nbsp;</div>');
						}
												
						if (lastRow!=null)
							gameHeader.injectAfter(lastRow);
						if(this.isDefaultBetType)
							lastRow = gameHeader;
						this.betTypeRows.push(gameHeader);
					}
					if (tempArrayForSort!=null && tempArrayForSort.length > 0 ) {
						for(var j=0;j<tempArrayForSort.length;j++){
							var csRow=null;
							if(j==0 && gk==0){
								csRow=betTypeRow1;
							}else{
								if(parentRow==null){
		
									if(!this.isDefaultBetType){
										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(this.isR2Row()){
										csRow=new Element('tr',{'id':'R2','class': 'matchLine'});
									}else{
										csRow=new Element('tr',{'class': 'matchLine'});//
									}
									this.betTypeRows.push(csRow);
									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(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],tempArrayForSort[j][1].title);
								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_om(this.match,args));
								tempArrayForSort[j][1].setTopElement(homeCell,args);	
							}else{
								homeCell.setHTML(this.addText_odds(this.match.getOddsCellText()));
							}
		
							homeCell.injectInside(csRow);
							if( (j!=0 || gk>0) && this.isDefaultBetType){
								var emptyCell=new Element('td',{'class': 'emptyTd'});
								emptyCell.setHTML('<div id="'+divId+'">&nbsp;</div>');
								emptyCell.injectInside(csRow);
							}
						}
					}
				}
				//		

				if(this.isDefaultBetType) {
					var rowcount = 0;
					if (betTypes.TYPE_ID_HEAD_2==this.typeId)
						rowcount = groupKeys.length * 3 - 2;
					else if (betTypes.TYPE_ID_HEAD_3==this.typeId ) 
						rowcount = groupKeys.length * 4 - 2;
					else
						rowcount = tempArrayForSort.length - 1;
						
					this.match.rowCount = rowcount;	// For the expend row ,record the next row
				}
				
		}
		else if(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE==this.typeId
			|| this.typeId == betTypes.TYPE_ID_GOALS_HOME_TEAM
			|| this.typeId == betTypes.TYPE_ID_GOALS_AWAY_TEAM 
			|| this.typeId == betTypes.TYPE_ID_SETS_NUMBER_5 
			|| this.typeId == betTypes.TYPE_ID_SETS_NUMBER_3 ){
				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;
					this.betTypeRows.push(betTypeRow1);
				}
				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=[];
				
				if ( this.typeId == betTypes.TYPE_ID_GOALS_HOME_TEAM
					|| this.typeId == betTypes.TYPE_ID_GOALS_AWAY_TEAM) {
					
					for(var i=0;i<oddsValues.length;i=i+2){
						var oddsValue,extraInfo;
						oddsValue = oddsValues[i];
						if($defined(oddsValue)&&oddsValue!==null){
							 extraInfo=this.extraOutcomeInfo.get(oddsValue.id);
							 homeValues.push(oddsValue);
							 homeScoreText.push(extraInfo.doubleParameter.toFixed(0));
						}
						
						/*
						oddsValue = oddsValues[i+1];
						if($defined(oddsValue)&&oddsValue!==null){
							 extraInfo=this.extraOutcomeInfo.get(oddsValue.id);
							 drawValues.push(oddsValue);
							 drawScoreText.push(extraInfo.doubleParameter.toFixed(0));
						}
						*/
						
						oddsValue = oddsValues[i+1];
						if($defined(oddsValue)&&oddsValue!==null){
							extraInfo=this.extraOutcomeInfo.get(oddsValue.id);
							awayValues.push(oddsValue);
						    awayScoreText.push(extraInfo.doubleParameter.toFixed(0));
						}
													
					}
				} 
				else if ( this.typeId == betTypes.TYPE_ID_SETS_NUMBER_3
					|| this.typeId == betTypes.TYPE_ID_SETS_NUMBER_5) {
					
					for(var i=0;i<oddsValues.length;i++){
						var oddsValue = oddsValues[i];
						var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
						var dbParam=extraInfo.doubleParameter;
						
						if (this.typeId == betTypes.TYPE_ID_SETS_NUMBER_3) {
							if (dbParam==2) {
								 homeValues.push(oddsValue);
								 homeScoreText.push(dbParam.toFixed(0));									
							}else if (dbParam==3) {
								 awayValues.push(oddsValue);
								 awayScoreText.push(dbParam.toFixed(0));	
							}
						}
						else if (this.typeId == betTypes.TYPE_ID_SETS_NUMBER_5) {
							if (dbParam==3) {
								 homeValues.push(oddsValue);
								 homeScoreText.push(dbParam.toFixed(0));							
							}
							else if (dbParam==4) {
								 drawValues.push(oddsValue);
								 drawScoreText.push(dbParam.toFixed(0));							
							}
							else if (dbParam==5) {
								 awayValues.push(oddsValue);
								 awayScoreText.push(dbParam.toFixed(0));							
							}
						}
					}
				}else {
					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_om(this));
					homeScoreText.sort(this.sortCorrectScoreText.bind_om(this));
					this.csSortType=2;
					drawValues.sort(this.sortCorrectScore.bind_om(this));
					drawScoreText.sort(this.sortCorrectScoreText.bind_om(this));
					this.csSortType=3;
					awayValues.sort(this.sortCorrectScore.bind_om(this));
					awayScoreText.sort(this.sortCorrectScoreText.bind_om(this));
				}
				var nrRows=homeValues.length;
				if(drawValues.length>nrRows)
					nrRows=drawValues.length;
				if(awayValues.length>nrRows)
					nrRows=awayValues.length;
				var divId=this.getDivId();
				var lastRow = parentRow;//

				//if (!isExpend)
				if(!this.match.isExpanded || this.isDefaultBetType)
					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){
							if(!this.isDefaultBetType){
								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(this.isR2Row()){
								csRow=new Element('tr',{'id':'R2','class': 'matchLine'});
							}else{
								csRow=new Element('tr',{'class': 'matchLine'});
							}
							this.betTypeRows.push(csRow);
							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'});
					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>');*/
						var plus = '';
						if(homeScoreText[j]=='3' && (betTypes.TYPE_ID_SETS_NUMBER_5 != this.typeId && betTypes.TYPE_ID_SETS_NUMBER_3 != this.typeId)) plus='+';
						homeCell.setHTML(this.addDivToText_oddsSmall(homeValues[j].value,homeValues[j].formattedValue,homeScoreText[j]+plus));
						var idHomeValue=homeValues[j].id;
						var valueHomeValue=homeValues[j].value;
						var formattedValueHomeValue=homeValues[j].formattedValue;
						var args='';						
						if (betTypes.TYPE_ID_SETS_NUMBER_5 == this.typeId || betTypes.TYPE_ID_SETS_NUMBER_3 == this.typeId)
							args=new Array(idHomeValue , valueHomeValue,formattedValueHomeValue,homeScoreText[j],outcomeName,homeScoreText[j]);
						else
							args=new Array(idHomeValue , valueHomeValue,formattedValueHomeValue,'home',outcomeName,homeScoreText[j]+plus);
						homeCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind_om(this.match,args));
						homeValues[j].setTopElement(homeCell,args);
					}else{
						homeCellParam.setHTML(this.addText_odds(''));
						var text = '';
						if (!(this.typeId == betTypes.TYPE_ID_SETS_NUMBER_3 || this.typeId == betTypes.TYPE_ID_SETS_NUMBER_5)) {
							text = this.match.getOddsCellText();
						}
						homeCell.setHTML(this.addText_odds(text));
					}

					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>');*/
						var plus = '';
						if(drawScoreText[j]=='3' && (betTypes.TYPE_ID_SETS_NUMBER_5 != this.typeId && betTypes.TYPE_ID_SETS_NUMBER_3 != this.typeId)) plus='+';
						drawCell.setHTML(this.addDivToText_oddsSmall(drawValues[j].value,drawValues[j].formattedValue,drawScoreText[j]+plus));
						
						var args='';						
						if (betTypes.TYPE_ID_SETS_NUMBER_5 == this.typeId || betTypes.TYPE_ID_SETS_NUMBER_3 == this.typeId)
							args=new Array(drawValues[j].id , drawValues[j].value,drawValues[j].formattedValue,drawScoreText[j],outcomeName,drawScoreText[j]);
						else
							args=new Array(drawValues[j].id , drawValues[j].value,drawValues[j].formattedValue,nameOfDraw,outcomeName,drawScoreText[j]+plus);
						drawCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind_om(this.match,args));
						drawValues[j].setTopElement(drawCell,args);
					}else{
						drawCellParam.setHTML(this.addText_odds(''));
						var text = '';
						if (!(this.typeId == betTypes.TYPE_ID_SETS_NUMBER_3 || this.typeId == betTypes.TYPE_ID_SETS_NUMBER_5)) {
							text = this.match.getOddsCellText(2,this.typeId);
						}
						drawCell.setHTML(this.addText_odds(text));
					}
					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>');*/
						var plus = '';
						if(awayScoreText[j]=='3' && (betTypes.TYPE_ID_SETS_NUMBER_5 != this.typeId && betTypes.TYPE_ID_SETS_NUMBER_3 != this.typeId)) plus='+';
						awayCell.setHTML(this.addDivToText_oddsSmall(awayValues[j].value,awayValues[j].formattedValue,awayScoreText[j]+plus));
						
						var args='';						
						if (betTypes.TYPE_ID_SETS_NUMBER_5 == this.typeId || betTypes.TYPE_ID_SETS_NUMBER_3 == this.typeId)
							args=new Array(awayValues[j].id , awayValues[j].value,awayValues[j].formattedValue,awayScoreText[j],outcomeName,awayScoreText[j]);
						else
							args=new Array(awayValues[j].id , awayValues[j].value,awayValues[j].formattedValue,'away',outcomeName,awayScoreText[j]+plus);
						awayCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind_om(this.match,args));
						awayValues[j].setTopElement(awayCell,args);
					}else{
						awayCellParam.setHTML(this.addText_odds(''));
						var text = '';
						if (!(this.typeId == betTypes.TYPE_ID_SETS_NUMBER_3 || this.typeId == betTypes.TYPE_ID_SETS_NUMBER_5)) {
							text = this.match.getOddsCellText();
						}
						awayCell.setHTML(this.addText_odds(text));
					}
					homeCell.injectInside(csRow);
					//homeCellParam.injectInside(csRow);
					drawCell.injectInside(csRow);
					//drawCellParam.injectInside(csRow);
					awayCell.injectInside(csRow);
					//awayCellParam.injectInside(csRow);

					//if(j!=0 && !isExpend){
					if (j!=0 && !this.match.isExpanded){
						var emptyCell=new Element('td',{'class': 'emptyTd'});
						emptyCell.setHTML('<div id="'+divId+'">&nbsp;</div>');
						emptyCell.injectInside(csRow);
					}
				}
		}
		else 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);
				} else {
					betTypeRow1 = parentRow;
				}
				this.betTypeRows.push(betTypeRow1);
				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_om(this));
				homeScoreText.sort(this.sortNubmerofGoalsText.bind_om(this));

				var nrRows=homeValues.length;
				var lastRow=parentRow;
				//if (!isExpend)
				if(!this.match.isExpanded || this.isDefaultBetType) 
					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){
							if(!this.isDefaultBetType){
								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(this.isR2Row()){
								csRow=new Element('tr',{'id':'R2','class': 'matchLine'});
							}else{
								csRow=new Element('tr',{'class': 'matchLine'});
							}
							this.betTypeRows.push(csRow);
							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].value,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_om(this.match,args));
						homeValues[j].setTopElement(homeCell,args);
					}

					homeCell.injectInside(csRow);
					homeCellParam.injectInside(csRow);
					var emptyCell=new Element('td',{'colspan': '1'})
					emptyCell.setHTML(this.addText_odds(this.match.getOddsCellText()));
					//emptyCell.injectInside(csRow);
				}
		}
		else 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;
					}
					this.betTypeRows.push(betTypeRow1);
				}
				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].value,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_om(this.match,args));
					oddsValuesReordered[0].setTopElement(cell1x,args);
				}else{
					cell1x.setHTML(this.addText_odds(this.match.getOddsCellText()));
					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].value,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_om(this.match,args));
					oddsValuesReordered[2].setTopElement(cellx2,args);
				}else{
					cellx2.setHTML(this.addText_odds(this.match.getOddsCellText(2,this.typeId)));
					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].value,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_om(this.match,args));
					oddsValuesReordered[1].setTopElement(cell12,args);
				}else{
					cell12.setHTML(this.addText_odds(this.match.getOddsCellText()));
					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);
		}
		else 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){
					if(!this.isDefaultBetType){
						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);
				} else {
					//if(parentRow.getChildren('td').length<3){
						betTypeRow1 = parentRow;

					if(this.isR2Row()){
						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);
					//}
				}
				this.betTypeRows.push(betTypeRow1);
				this.betTypeRows.push(betTypeRow2);
				this.betTypeRows.push(betTypeRow3);
				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].value,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_om(this.match,args));
					oddsValuesReordered[0].setTopElement(cell11,args);
				}else{
					cell11.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				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].value,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_om(this.match,args));
					oddsValuesReordered[1].setTopElement(cellx1,args);
				}else{
					cellx1.setHTML(this.addText_odds(this.match.getOddsCellText(2,this.typeId)));
				}
				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].value,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_om(this.match,args));
					oddsValuesReordered[2].setTopElement(cell21,args);
				}else{
					cell21.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}

				//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].value,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_om(this.match,args));
					oddsValuesReordered[3].setTopElement(cell1x,args);
				}else{
					cell1x.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				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].value,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_om(this.match,args));
					oddsValuesReordered[4].setTopElement(cellxx,args);
				}else{
					cellxx.setHTML(this.addText_odds(this.match.getOddsCellText(2,this.typeId)));
				}
				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].value,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_om(this.match,args));
					oddsValuesReordered[5].setTopElement(cell2x,args);
				}else{
					cell2x.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				//if (!isExpend)
				if(!this.match.isExpanded || this.isDefaultBetType)
				 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].value,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_om(this.match,args));
					oddsValuesReordered[6].setTopElement(cell12,args);
				}else{
					cell12.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				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].value,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_om(this.match,args));
					oddsValuesReordered[7].setTopElement(cellx2,args);
				}else{
					cellx2.setHTML(this.addText_odds(this.match.getOddsCellText(2,this.typeId)));
				}
				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].value,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_om(this.match,args));
					oddsValuesReordered[8].setTopElement(cell22,args);
				}else{
					cell22.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}

				//cell12Text.injectInside(betTypeRow3);
				cell12.injectInside(betTypeRow3);
				//cellx2Text.injectInside(betTypeRow3);
				cellx2.injectInside(betTypeRow3);
				//cell22Text.injectInside(betTypeRow3);
				cell22.injectInside(betTypeRow3);
								
				//if (!isExpend) {
				if(!this.match.isExpanded){
					var emptyCellEnd2=new Element('td',{'class': 'emptyTd'});
					var emptyCellEnd3=new Element('td',{'class': 'emptyTd'});
					emptyCellEnd2.injectInside(betTypeRow2);
					emptyCellEnd3.injectInside(betTypeRow3);	
				}			
		}
		else if(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW==this.typeId || betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId  ||
					betTypes.TYPE_ID_TEAM_KICKS_OFF==this.typeId  || betTypes.TYPE_ID_HOME_AWAY_WITH_POSSIBLE_DRAW==this.typeId ||
					betTypes.TYPE_ID_GOALS_NOGOALS==this.typeId){
			    var nameCell=null;
				var betTypeRow=null;
				if(parentRow==null){
					//if(isExpend)
					if(this.match.isExpanded)
						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);
				} 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]);
					}*/
				}
				this.betTypeRows.push(betTypeRow);
				var oddsValues=[];
				//--------wolf modify---------------------
				var homeOdds=null;
				var awayOdds=null;

				oddsValues=this.odds.get(doubleNULL).values();
				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');
				var partName1 = "home";
				var partName2 = "away";
				if (betTypes.TYPE_ID_GOALS_NOGOALS==this.typeId){
					partName1 = nameOfYes;
					partName2 = nameOfNo;					
				}else if(betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId){
					partName1 = nameOfOdd;
					partName2 = nameOfEven;
				}else  {
					partName1 = homeParticipantName;
					partName2 = awayParticipantName;					
				}
				//cssDiv.addEvent('onmouseover',function(this){this.className='ButtonOddsSelectorLargeOn';}.bind_om(this.match,args));
				if($defined(homeOdds)){
					cellHome.setHTML(this.addDivToText_odds(homeOdds.value,homeOdds.formattedValue));
					var args=new Array(homeOdds.id , homeOdds.value,homeOdds.formattedValue,partName1,outcomeName,partName1);
					cellHome.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind_om(this.match,args));
					homeOdds.setTopElement(cellHome,args);
				}else{
					cellHome.setHTML(this.addText_odds(this.match.getOddsCellText()));
					}
				var cellAway=new Element('td');
				if($defined(awayOdds)){
					cellAway.setHTML(this.addDivToText_odds(awayOdds.value,awayOdds.formattedValue));
					var args=new Array(awayOdds.id , awayOdds.value,awayOdds.formattedValue,partName2,outcomeName,partName2);
					cellAway.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind_om(this.match,args));
					awayOdds.setTopElement(cellAway,args);
				}else{
					cellAway.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				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);
		}
		else if(betTypes.TYPE_ID_OVER_UNDER==this.typeId || betTypes.TYPE_ID_GAME_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);
				var divId=this.getDivId();
				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_om(this));
				OUText.sort(this.sortOverUnderText.bind_om(this));
				underValues.sort(this.sortOverUnder.bind_om(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)
						if(this.match.isExpanded)
							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);
						}*/
					} else {
						if(k==0)//parentRow.getChildren('td').length<3
						{	betTypeRow = lastRow;}
						else {
							if(this.isR2Row()){
								betTypeRow=new Element('tr',{'class': 'matchLine','id':'R2'});
							} else {
								betTypeRow=new Element('tr',{'class': 'matchLine'});
							}
							var emptyCell=new Element('td',{'colspan':'4'});
							emptyCell.setHTML('<div id="'+divId+'">&nbsp;</div>');
							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;
					}
					this.betTypeRows.push(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].value,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_om(this.match,args));
						overValues[k].setTopElement(cellHome,args);
					}else{
						cellHome.setHTML(this.addText_odds(this.match.getOddsCellText()));
					}
					var cellAway=new Element('td');
					if($defined(underValues[k])){
						cellAway.setHTML(this.addDivToText_odds(underValues[k].value,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_om(this.match,args));
						underValues[k].setTopElement(cellAway,args);
					}else{
						cellAway.setHTML(this.addText_odds(this.match.getOddsCellText()));
					}
					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)
					if(!this.match.isExpanded || this.isDefaultBetType)
						this.match.rowCount++;
					if(k>0 && !this.match.isExpanded){
						var emptyCellEnd2=new Element('td',{'class': 'emptyTd'});
						emptyCellEnd2.setHTML('<div id="'+divId+'">&nbsp;</div>');
						emptyCellEnd2.injectInside(betTypeRow);	
					}
				}		
				if(!this.match.isExpanded || this.isDefaultBetType)
					this.match.rowCount--;
		}
		else if( betTypes.TYPE_ID_ASIAN_HANDICAP==this.typeId ||betTypes.TYPE_ID_GAME_HANDICAP==this.typeId  ||betTypes.TYPE_ID_SET_HANDICAP==this.typeId
				|| betTypes.TYPE_ID_Score_gameX_setN==this.typeId || betTypes.TYPE_ID_Who_wins_gameX_setN==this.typeId ){
			
				var setsMap = new Hash();
				if (betTypes.TYPE_ID_Score_gameX_setN==this.typeId ) {
					var oddsMap = this.odds.values();
					var betTypeObj = this;
					oddsMap.each(function(oddsArray ){
						oddsArray.each(function(oddsObj){
							var oId = oddsObj.id;
							var extraInfo = betTypeObj.extraOutcomeInfo.get(oId);
							var db2 = extraInfo.doubleParameter2;
							var db1 = extraInfo.doubleParameter;
							var i1 = extraInfo.integerParameter;
							
							var scoreMap = setsMap.get(db1);
							
							if (scoreMap == null) {
								scoreMap = new Hash();
								setsMap.set(db1,scoreMap);
							} 

							var oddsPair = scoreMap.get(db2);
							if (oddsPair==null) {
								oddsPair = new Hash();
								scoreMap.set(db2,oddsPair);
							} 

							oddsPair.set(oId,oddsObj);
						});
					});
					var a = 0;
				} else {
					setsMap.set(0,this.odds);
				}
				var divId=this.getDivId();
				var level1 = setsMap.keys();
				level1.sort(this.sortAsianHandicap);				
				for (var r=0;r<level1.length;r++) {
					var key1 = level1[r];
					var level2 = setsMap.get(key1);
					var parameters = level2.keys();
					
					var lastRow=parentRow;
					parameters.sort(this.sortAsianHandicap);
	
					if (betTypes.TYPE_ID_Score_gameX_setN==this.typeId ) {					
						var gameHeader=new Element('tr');
						var gameHeaderTd = new Element('td',{'colspan':8});
						gameHeaderTd.injectInside(gameHeader);
						var titleName = title_game_x+' '+key1;
						if (this.isDefaultBetType) {
							gameHeader.className = 'matchLine';
							gameHeaderTd.setHTML('<div class="BettypeHeadline">'+titleName+'</div>');
						}
						else {
							gameHeaderTd.setHTML('<div id="'+divId+'"><div class="BettypeHeadline">'+titleName+'</div></div>');
						}
						if (lastRow!=null)
							gameHeader.injectAfter(lastRow);
						lastRow = gameHeader;
						this.betTypeRows.push(gameHeader);
					}
					for(var k=0;k<parameters.length;k++){
						var nameCell=null;
						var betTypeRow=null;
	
						if(parentRow==null){
							if(this.match.isExpanded)
								betTypeRow=new Element('tr',{'class':this.match.id});
							else
								betTypeRow=new Element('tr');
							betTypeRow=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
						} else {
							if(k==0 && betTypes.TYPE_ID_Score_gameX_setN !=this.typeId)
								betTypeRow = parentRow;
							else {
								if (k==0 && r==0) {
									for (var x=0;x<3;x++) {
										var emptyCell=new Element('td');
										emptyCell.setHTML(this.addText_odds('&nbsp;'));
										emptyCell.injectInside(parentRow);
									}
								}
								
								if(this.isR2Row()){
									betTypeRow=new Element('tr',{'class': 'matchLine','id':'R2'});
								} else {
									betTypeRow=new Element('tr',{'class': 'matchLine'});
								}
								var emptyCell=new Element('td',{'colspan':'4'});
								emptyCell.setHTML('<div id="'+divId+'">&nbsp;</div>');
								emptyCell.injectInside(betTypeRow);
								var tbody=parentRow.getParent();
								var matchRows=tbody.getElements('tr.matchLine');
								betTypeRow.injectAfter(lastRow);
							}
							lastRow = betTypeRow;
						}
						this.betTypeRows.push(betTypeRow);
						var oddsValues=level2.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];
	
						}
						var cellHome=new Element('td');
						if($defined(homeOdds)){
							cellHome.setHTML(this.addDivToText_odds(homeOdds.value,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_om(this.match,args));
							homeOdds.setTopElement(cellHome,args);
						}else{
							cellHome.setHTML(this.addText_odds(this.match.getOddsCellText()));
						}
						var cellAway=new Element('td');
						if($defined(awayOdds)){
							cellAway.setHTML(this.addDivToText_odds(awayOdds.value,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_om(this.match,args));
							awayOdds.setTopElement(cellAway,args);
						}else{
							cellAway.setHTML(this.addText_odds(this.match.getOddsCellText()));
						}
	
						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 (k!=0 && !this.match.isExpanded || k==0 && betTypes.TYPE_ID_Score_gameX_setN == this.typeId && this.isDefaultBetType){
							var cellBelowExpand=new Element('td',{'class': 'emptyTd'});
							cellBelowExpand.setHTML('<div id="'+divId+'">&nbsp;</div>');
						    cellBelowExpand.injectInside(betTypeRow);// this is for draw column
						}
						if(!this.match.isExpanded || this.isDefaultBetType)
						 this.match.rowCount++;
					}					
				}
				
				//forScore_gameX_setN, rowcount should count in each title row of Game x
				if( this.isDefaultBetType) {
					if ( betTypes.TYPE_ID_Score_gameX_setN == this.typeId) 
						this.match.rowCount+= level1.length;
					else
						this.match.rowCount--;
						
				}
		}
		else 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) {
					this.handicap1X2hasNext =true;
					parameters.sort( this.sort1x2Handicap.bind_om(this) );
				}
				var lastRow=parentRow;
				var divId=this.getDivId();
				for(var k=0;k<parameters.length;k++){
					if(k==parameters.length-1) this.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]);
					}
					//paris365
					if (mypartnerId==36) {
						if (handicap1>0)
							handicap1 = '+'+handicap1;
						if (handicap2>0)
							handicap2 = '+'+handicap2;							
					}
					if(parentRow==null){
						//if(isExpend){
						if(this.isR2Row()){
							betTypeRow=new Element('tr',{'class': 'matchLine','id':'R2'});
						} else {
							betTypeRow=new Element('tr',{'class': 'matchLine'});
						}

						//nameCell=new Element('td',{'align': 'center'});
						betTypeRow=this.handicapCell(dateText,hourText,'<div class=floatCustom>'+ this.match.homeParticipantName +'('+handicap1+')</div>','<div class=floatCustom>'+this.match.awayParticipantName +'('+handicap2+')</div>',false);
						//nameCell.injectInside(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('<div class=floatCustom>'+ this.match.homeParticipantName +'('+handicap1+')</div>'));
							teamCells[1].setHTML(this.addCssToTeam('<div class=floatCustom>'+ this.match.awayParticipantName +'('+handicap2+')</div>'));

							var hourCel = parentRow.getElements('td.hourWidth');
							//var dateCel = parentRow.getElements('td.dateWidth');

							hourCel.setHTML(this.addCssToTeam(this.match.makeHourCellContent(dateText,hourText)));

						}
						else {
							betTypeRow=null;
							betTypeRow=this.handicapCell(dateText,hourText,'<div class=floatCustom>'+ this.match.homeParticipantName +'('+handicap1+')</div>','<div class=floatCustom>'+ this.match.awayParticipantName +'('+handicap2+')</div>',false);

							betTypeRow.injectAfter(lastRow);
						}

					}
					this.betTypeRows.push(betTypeRow);
					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];
					}
					var cellHome=new Element('td',{'class':'oddsCell'});
					if($defined(oddsValuesReordered[0])){
						cellHome.setHTML(this.addDivToText_odds(oddsValuesReordered[0].value,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_om(this.match,args));
						oddsValuesReordered[0].setTopElement(cellHome,args);
					}else{
						cellHome.setHTML(this.addText_odds(''));
					}
					var cellX=new Element('td');
					if($defined(oddsValuesReordered[1])){
						cellX.setHTML(this.addDivToText_odds(oddsValuesReordered[1].value,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_om(this.match,args));
						oddsValuesReordered[1].setTopElement(cellX,args);
					}else{
						cellX.setHTML(this.addText_odds(''));
					}
					var cellAway=new Element('td');
					if($defined(oddsValuesReordered[2])){
						cellAway.setHTML(this.addDivToText_odds(oddsValuesReordered[2].value,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_om(this.match,args));
						oddsValuesReordered[2].setTopElement(cellAway,args);
					}else{
						cellAway.setHTML(this.addText_odds(''));
					}
					cellHome.injectInside(betTypeRow);
					cellX.injectInside(betTypeRow);
					cellAway.injectInside(betTypeRow);
					if(!this.match.isExpanded || this.isDefaultBetType)
					 this.match.rowCount++;
					if(k>0 && !this.match.isExpanded){
						var emptyCell=new Element('td',{'class': 'emptyTd'});
						emptyCell.setHTML('<div id="'+divId+'">&nbsp;</div>');
						emptyCell.injectInside(betTypeRow);	
					}
				}
				if(!this.match.isExpanded || this.isDefaultBetType) 
					this.match.rowCount--;
		} else if ( betTypes.TYPE_ID_Who_win_gamesXY_setN ==this.typeId ) {
			var parameters=this.odds.keys();				
			if(parameters.length>1) {
				if (this.isDefaultBetType)
					parameters.sort( this.sortParamDescend );
				else
					parameters.sort( this.sortAsianHandicap );
			}	
			var divId=this.getDivId();
			var betTypeRow=null;
			for(var k=0;k<parameters.length;k++){
				var lastRow=parentRow;
				
				var gameHeader=new Element('tr');
				var gameHeaderTd = new Element('td',{'colspan':8});
				gameHeaderTd.injectInside(gameHeader);
				var game1 = parameters[k];
				var oddsValues = this.odds.get(game1).values();
				var game2 = parameters[k];
				if (oddsValues!=null && oddsValues.length>0) {
					game2 = this.extraOutcomeInfo.get(oddsValues[0].id).doubleParameter2;
				}
				
				var titleName = title_game_x+' '+game1+' '+title_game_and+' '+game2;
				if (this.isDefaultBetType) {
					gameHeader.className = 'matchLine';
					gameHeaderTd.setHTML('<div class="BettypeHeadline">'+titleName+'</div>');
				}
				else {
					gameHeaderTd.setHTML('<div id="'+divId+'"><div class="BettypeHeadline">'+titleName+'</div></div>');
				}
				if (lastRow!=null)
					gameHeader.injectAfter(lastRow);
				lastRow = gameHeader;
				this.betTypeRows.push(gameHeader);
				
				var nameCell=null;

				if(parentRow==null){
					if(this.match.isExpanded)
						betTypeRow=new Element('tr',{'class':this.match.id});
					else
						betTypeRow=new Element('tr');
					betTypeRow=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
				} else {
					if (k==0) {
						for (var x=0;x<3;x++) {
							var emptyCell=new Element('td');
							emptyCell.setHTML(this.addText_odds('&nbsp;'));
							emptyCell.injectInside(parentRow);
						}
					}
					if(this.isR2Row()){
						betTypeRow=new Element('tr',{'class': 'matchLine','id':'R2'});
					} 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);
					
				}
				lastRow = betTypeRow;
				
				this.betTypeRows.push(betTypeRow);
				var oddsValues=this.odds.get(parameters[k]).values();

				var oddsArray=[];
				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)
						oddsArray[0]=oddsValues[i];
					if(resultId==1 && intParam1==this.match.awayParticipantId)
						oddsArray[2]=oddsValues[i];
					if(resultId==2)
						oddsArray[1]=oddsValues[i];

				}
				var bttext = [];
				bttext[0] = 'home';
				bttext[1] = 'draw';
				bttext[2] = 'away';
				
				var participantName = [];
				participantName[0] = this.match.homeParticipantName;
				participantName[1] = nameOfDraw;
				participantName[2] = this.match.awayParticipantName;				
				
				for (var j =0;j<3;j++) {
					var oddsCell=new Element('td');
					if($defined(oddsArray[j])){
						oddsCell.setHTML(this.addDivToText_odds(oddsArray[j].value,oddsArray[j].formattedValue));
						var args=[];args.push(oddsArray[j].id);args.push(oddsArray[j].value);args.push(oddsArray[j].formattedValue);
						args.push(bttext[j]);args.push(outcomeName);args.push(participantName[j]);
						oddsCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind_om(this.match,args));
						oddsArray[j].setTopElement(oddsCell,args);
					}else{
						oddsCell.setHTML(this.addText_odds(this.match.getOddsCellText()));
					}
					oddsCell.injectInside(betTypeRow);
					
				}
				//rowcount should count in each title row of Game x
				if(!this.match.isExpanded || this.isDefaultBetType) {
					 this.match.rowCount+= 2;
				}
			}	
				
		}

	},
	 addDivToText_odds:function(value,text){
	 	var divId=this.getDivId();
		var oddsTypeValue = getOddsShowType(value);
		if(oddsTypeValue===2){
			return '<div id="'+divId+'" ><div class="emptyOddsCell"><a href="javascript:void(0);" style="cursor:default;text-decoration:none;color:gray;">'+emptyOddsTxt
						                 +'</a></div></div>';
		}else if(oddsTypeValue===3){
//			return '<div id="'+divId+'" ><div class="ButtonOddsSelectorLargeOff" ><a href="javascript:void(0);">&nbsp;'+symbolForSmallOdds
//0169137						                 +'</a></div></div>';
			return '<div id="'+divId+'" ><div class="ButtonOddsSelectorLargeOff" onmouseover="this.className=\'ButtonOddsSelectorLargeOn\'" ' +
					'onmouseout="this.className=\'ButtonOddsSelectorLargeOff\'"><a href="javascript:void(0);">'+symbolForSmallOdds+'</a></div></div>';
			
		} else {
			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=this.getDivId();
		
		var oddsTypeValue = getOddsShowType(value);
		if(oddsTypeValue===2){
			return '<div id="'+divId+'" class="winnerCell" style="overflow-x:hidden;"><div class="emptyOddsCell" style="float:right" ><a href="javascript:void(0);" style="cursor:default;text-decoration:none;color:gray;">'+emptyOddsTxt
						                 +'</a></div><div class="TextOddsSmall">'+param+'</div></div>';
		}else if(oddsTypeValue===3){
//			return '<div id="'+divId+'" class="winnerCell"  style="overflow-x:hidden;"><div class="'+winnerButtonClass_off+'" id="ID'+winnerButtonClass_off+'" ' +
//					' ><a href="javascript:void(0); ">'+symbolForSmallOdds
//						                 +'</a></div><div style="float:left" class="TextOddsSmall">'+param+'</div></div>';		
			return '<div id="'+divId+'" class="winnerCell" style="overflow-x:hidden;"><div class="'+winnerButtonClass_off+'" id="ID'+winnerButtonClass_off+'" onmouseover="this.className=\''+winnerButtonClass_on+'\'" ' +
					'onmouseout="this.className=\''+winnerButtonClass_off+'\'" ><a href="javascript:void(0); ">'+symbolForSmallOdds+'</a></div><div class="TextOddsSmall">'+param+'</div></div>';	
		}else{
			if(value!=null&&value==1) text="NR";
			return '<div id="'+divId+'" class="winnerCell" style="overflow-x:hidden;"><div class="'+winnerButtonClass_off+'" id="ID'+winnerButtonClass_off+'" onmouseover="this.className=\''+winnerButtonClass_on+'\'" ' +
					'onmouseout="this.className=\''+winnerButtonClass_off+'\'" ><a href="javascript:void(0); ">'+text
						                 +'</a></div><div class="TextOddsSmall">'+param+'</div></div>';
		}
	},
	
	addDivToText_oddsSmall:function(value,text,param){
		var divId=this.getDivId();
		var oddsTypeValue = getOddsShowType(value);
		if(oddsTypeValue===2){
			return '<div id="'+divId+'" style="overflow-x:hidden;"><div class="emptyOddsCell"><a href="javascript:void(0);" style="cursor:default;text-decoration:none;color:gray;">'+emptyOddsTxt
						                 +'</a></div></div>';
		}else if(oddsTypeValue===3){
//			return '<div id="'+divId+'" style="overflow-x:hidden;"><div class="ButtonOddsSelectorSmallOff" id="IDButtonOddsSelectorSmallOff" ' +
//					'><a href="javascript:void(0); ">'+symbolForSmallOdds
//						                 +'</a></div><div style="float:left">'+param+'</div></div>';	
			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); ">'+symbolForSmallOdds
						                 +'</a></div><div class="smallTxt" style="float:left;padding-left: 3px;white-space: nowrap;">'+param+'</div></div>';//;padding-left: 8px;white-space: nowrap;	
		}else{
			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 class="smallTxt" style="float:left;padding-left: 3px;white-space: nowrap;">'+param+'</div></div>';//;padding-left: 8px;white-space: nowrap;
		}		
	},	

	 addDivToText_odds_withParam:function(text,param){
		var divId=this.getDivId();
		var oddsTypeValue = getOddsShowType(value);
		if(oddsTypeValue===2){
			return '<div id="'+divId+'" style="overflow-x:hidden;"><div class="emptyOddsCell"><a href="javascript:void(0);" style="cursor:default;text-decoration:none;color:gray;">'+emptyOddsTxt
					                 +'</a></div></div>';
		}else if(oddsTypeValue===3){
//			return '<div id="'+divId+'" style="overflow-x:hidden;"><div class="ButtonOddsSelectorLargeOff" id="ButtonOddsSelectorLargeOff"  ' +
//				' ><a href="javascript:void(0); ">'+symbolForSmallOdds
//					                 +'</a></div><div style="float:left">'+param+'</div></div>';	
			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); ">'+symbolForSmallOdds
					                 +'</a></div><div style="float:left">'+param+'</div></div>';
		}else{
			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=this.getDivId();
		var textStr = text;
		if (!this.isDefaultBetType)
			textStr = '&nbsp;';
			
		if (textStr==null || textStr=='')
			textStr = '&nbsp;';
		return '<div id="'+divId+'">'+textStr+'</div>';
	},
	
	addText_odds:function(text){
		var divId=this.getDivId();
		if (this.isDefaultBetType && !getIsInNewExpandPage())
		   return text;
		return '<div id="'+divId+'"><div align="center">'+text+'</div></div>';
	},
	
	addCssToTeam:function(text){
		var divId=this.getDivId();
		//if (this.match.isExpanded){
			return '<div id="'+divId+'">'+ text+'</div>';
//		}else {
//			if (this.handicap1X2hasNext){
//			   divId = 'MarketR0';
//		    }
//		}
		//return text;
	},
	 addCssToTeam1:function(text){
//			var divId=this.getDivId();
//			if (this.match.isExpanded){
//				return '<div id="'+divId+'"><div style="padding-left:5px">'+ text+'</div></div>';
//			}else {
//				if (this.handicap1X2hasNext){
//				   divId = 'MarketR0';
//			    }
//			}
			return text;
	},
	addDivToText_title:function(text){

	},	
	getDivId:function() {
		var divId='MarketR1';
		if (getIsInNewExpandPage() || !this.isDefaultBetType){  
			divId='MarketR2';
		}
		return divId;
	},
	getHeadDivId:function() {
		var divId='MarketH1';
		if (!this.isDefaultBetType || getIsInNewExpandPage()){
			divId='MarketH2';
		}
		return divId;
	}
});

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;
		this.topElement = null;
		this.id = id;
		this.oldValue = oddsValue;
		this.blink=0;
	},
	getValue:function() {
		return this.value;
	},
	getFormattedValue:function() {
		return this.formattedValue;
	},	
	setValue: function(oddsValue,formattedValue,betTypeId){
		var onBtnClass = 'ButtonOddsSelectorLargeOn';
		var offBtnClass = 'ButtonOddsSelectorLargeOff';
		if (isSmallBtnBetType(betTypeId)) {
			onBtnClass = 'ButtonOddsSelectorSmallOn';
			offBtnClass = 'ButtonOddsSelectorSmallOff';			
		}
		if (isWinnerBtnBetType(betTypeId)){
			onBtnClass = winnerButtonClass_on;
			offBtnClass = winnerButtonClass_off;			
		}
		var oddsTypeValue = getOddsShowType(oddsValue);
		if (this.htmlElement!=null) {
			if(oddsTypeValue===2){
				
				this.htmlElement.getParent().addEvent('mouseover', function(){this.className='';});
				this.htmlElement.getParent().addEvent('mouseout', function(){this.className='';});
				this.htmlElement.getParent().removeProperty('id');
				this.htmlElement.getParent().removeClass(offBtnClass);
				this.htmlElement.setStyle('cursor','default');
				this.htmlElement.setStyle('text-decoration','none');
				this.htmlElement.setStyle('color','grey');
				this.htmlElement.setHTML(emptyOddsTxt);	
				
			}
			else if(oddsTypeValue===3){
	
//				this.htmlElement.getParent().id='ID'+offBtnClass;
//				this.htmlElement.getParent().className=offBtnClass;
//				this.htmlElement.removeProperty('style');			
//				this.htmlElement.setHTML(symbolForSmallOdds);
//				this.htmlElement.getParent().onmouseover=null;
//				this.htmlElement.getParent().onmouseout=null;
				
				this.htmlElement.getParent().id='ID'+offBtnClass;
				this.htmlElement.getParent().className=offBtnClass;
				this.htmlElement.getParent().addEvent('mouseover', function(){this.className=onBtnClass;});
				this.htmlElement.getParent().addEvent('mouseout', function(){this.className=offBtnClass;});
				this.htmlElement.removeProperty('style');			
				this.htmlElement.setHTML(symbolForSmallOdds);
				formattedValue = symbolForSmallOdds;
			} 
			else {
				this.htmlElement.getParent().id='ID'+offBtnClass;
				this.htmlElement.getParent().className=offBtnClass;
				this.htmlElement.getParent().addEvent('mouseover', function(){this.className=onBtnClass;});
				this.htmlElement.getParent().addEvent('mouseout', function(){this.className=offBtnClass;});
				this.htmlElement.removeProperty('style');			
				this.htmlElement.setHTML(formattedValue);
			}
		}
		this.oldValue = this.value;
		this.value = oddsValue;
		this.formattedValue = formattedValue;
		//blink blink effect
		this.defaultClassName = '';//this.htmlElement.className;
		this.updateClickEvent();
		this.applyBlinks();
	},
	setSimpleValue: function(oddsValue,formattedValue){
		this.htmlElement.setHTML(formattedValue);
		this.value = oddsValue;
		this.formattedValue = formattedValue;
	},
	applyBlinks: function(){
		this.htmlElement.className = 'oddsChanged1';
		this.effeCount = 0;
		this.interval = blinkingInternalX;
		this.effectType = 1;
		clearTimeout(this.blink);
		showBlinkEfect1(this.id);
	},
	setBetType:function(betTypeObj) {
		this.betType = betTypeObj;
	},
	
	setTopElement : function(topElement,args){
		this.topElement = topElement;
		this.topElement.id = this.id;
		this.htmlElement =(topElement.getElements('a'))[0]; // this.topElement.getFirst().getFirst().getFirst();
		storeObj(this.id, this);
		this.typeOfBet = args[3];
		this.outcomeName = args[4];
		this.param = args[5];
	},
	
	updateClickEvent:function() {
		this.topElement.removeEvents('click');
		var args=new Array(this.id , this.value,this.formattedValue,this.typeOfBet,this.outcomeName,this.param);
				var args=new Array(this.id , this.value,this.formattedValue,this.typeOfBet,this.outcomeName,this.param);
		this.topElement.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){
			this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}
			.bind_om(this.betType.match,args));
	}
});

var elementStorage = new Hash();
function storeObj(elId, element){
	elementStorage.set(elId, element);
}

function retrieveObj(elId){
	return elementStorage.get(elId);
}

function showBlinkEfect1(elementId){
	var element = retrieveObj(elementId); 
	if (!$defined(element))
		return;
	var classNameTemp = '';
	if (element.value < element.oldValue) {
		classNameTemp = 'oddsChangedDown1';
	} else if (element.value > element.oldValue){
		classNameTemp = 'oddsChangedUp1';		
	} else {		
		goBackToDefaultEfect(elementId);
		return;
	}
	if (blinkingUnitTime==0) {
		element.htmlElement.className = classNameTemp;	
		clearTimeout(element.blink);
		element.blink=setTimeout('doNothing(' + elementId +')',element.interval);	
	} else {
		if (element.effeCount < element.interval){
			if (element.htmlElement.className == element.defaultClassName)
				element.htmlElement.className = classNameTemp;
			else
				element.htmlElement.className = element.defaultClassName;
				
			element.effeCount +=blinkingUnitTime ;
			clearTimeout(element.blink);
			element.blink=setTimeout('showBlinkEfect1(' + elementId +')',blinkingUnitTime);
		}
		else {
			element.htmlElement.className = classNameTemp;
			doNothing(elementId);		
		}
	}
}
function doNothing(elementId){
	//check the first color effect for a certain time and then start applying effect 2
	var element = retrieveObj(elementId); 
	clearTimeout(element.blink);
	element.effeCount = 0;
	element.interval = blinkingInternalY;
	if (element.interval >0){
		element.blink=showBlinkEfect2(elementId);
	}
	else {
		goBackToDefaultEfect(elementId);
	}
}

function goBackToDefaultEfect(elementId){
	var element = retrieveObj(elementId); 
	element.htmlElement.className = element.defaultClassName;
	clearTimeout(element.blink);
}

function showBlinkEfect2(elementId){
	var element = retrieveObj(elementId); 
	if (!$defined(element))
		return;
		
	var classNameTemp = '';
	if (element.value < element.oldValue) {
		classNameTemp = 'oddsChangedDown2';
	} else if (element.value > element.oldValue) {
		classNameTemp = 'oddsChangedUp2';		
	} else {		
		goBackToDefaultEfect(elementId);
	}
	
	element.htmlElement.className = classNameTemp;	
	clearTimeout(element.blink);
	element.blink=setTimeout('goBackToDefaultEfect(' + elementId +')',element.interval);	
}


function processFailure(){

}

//var lbtcCunter = new LiveBettingTimeCounter({});
function fillOddsTable(response,IsInNewExpandPage){
	//judge if this is new expand page's oddstable
	if (IsInNewExpandPage!=null && IsInNewExpandPage)
		setIsInNewExpandPage(true);
	else
		setIsInNewExpandPage(false);
		
	var timeOddsFormatDivDom = $('timeOddsFormatDiv');
	if ($defined(timeOddsFormatDivDom)) {
		if (getIsInNewExpandPage()) {
			timeOddsFormatDivDom.style.display = "none";
		} else {
			timeOddsFormatDivDom.style.display = "block";
		}
	}
	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);
	if ($defined($('keyid_OddsTable'))){
		$("keyid_OddsTable").setProperty("height",$("leftmenuarea").scrollHeight - 100);
		
	}
	//for iframe
	afterFillOddsTable();
	resizeBsDiv();
	} 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);
          }*/
	}
	lastExpandedMatch=null;
	goForUpdates();
	
	changeHeadPic();
	//for chilibet etc.
	hideBetTypeTab();
	//lbtcCunter.refresh();
	//lbtcCunter.run();
	//startTimeCounter();
}

//empty function for override in your own pages
function afterFillOddsTable() {}
 
function updateBaseTimeA(){
	//lbtcCunter.updateBaseTime();
}
function startTimeCounter() {
	var matchIds = counterHash.keys();
	for (var i=0;i<matchIds.length;i++) {
		var currentTime = counterHash.get(matchIds[i]);
		var currentTimeValue = currentTime[0];
		var currentTimeType = currentTime[1];
		lbtcCunter.setEventStatuesWithType(matchIds[i],currentTimeValue,currentTimeType);
	}
	counterHash.empty();
}
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);
}
var lastExpandedMatch=null;
var allowOneMatchExpand = true;
function expandMatch(match){
	//show match odds in a new page when it's mode 2
	if (isExpandMatchModeType2()) {
		showMatchAllOdds(match.id,'1');
		return;	
	}
		
	if (allowOneMatchExpand) {
		if (lastExpandedMatch!=null)
			collapseMatch(lastExpandedMatch);
	}
	
	var imgObj = $(match.imgId);
	imgObj.style.display="block";
	match.expanded=true;
	currentExpandedMatch=match;
	match.isExpanded = true;
	
    isExpend = true;
    //if ($defined($('div_loadPicTab'))) $("div_loadPicTab").style.display = "block";
    imgObj.style.display="block";
    //close current RTF socket - cause we will open a new one after the user receives the initial dump for the expanded match 
    //closeConnection();
	if($defined(currentExpandedMatch)){
		lastExpandedMatch = currentExpandedMatch;
		currentExpandedMatch.updateNumberOfOutrights(currentExpandedMatch.numberOfOutrights);
		var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
		               onSuccess: function(response){
		               		insertExpandedMatchIntoDOM(response,$(match.imgId));
		               		isExpend=false;
		               		//goForUpdates();
		               		//lbtcCunter.refreshEvents(currentExpandedMatch.id);
		               		}.bind_om(match),
		               onFailure: function(){processFailure();}});
		ajaxReq.send('/expandedMatch.do','action=expand&id='+currentExpandedMatch.id+'&discId='+match.disciplineId+'&x='+(Math.random()*100)+'&isOutrights='+isOutrights);
		var time_f = new Date();
		ajaxReq=null;
	}
}
function collapseMatch(match) {
	if (allowOneMatchExpand) {
		if (lastExpandedMatch == match)
			lastExpandedMatch = null;
	}
	var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
	               onSuccess: function(response){},
	               onFailure: function(){}});
	ajaxReq.send('/expandedMatch.do','action=collapse&id='+match.id+'&discId='+match.disciplineId+'&x='+(Math.random()*100)+'&isOutrights='+isOutrights);
	ajaxReq=null;
		
	match.expanded=false;
	match.updateNumberOfOutrights(match.numberOfOutrights);

	match.deleteExpandedBetTypes();
	
	afterCollapseMatch();
	//lbtcCunter.refreshEvents(match.id);
}

/** 
 * [START] new expand page
 * show all odds of a match in a single page without any other match when clicking +x to expand---------------------------------------------------------------------------------
 */
 
var isInNewExpandPage = false; 
function setIsInNewExpandPage (value) {
	isInNewExpandPage = value;
}
function getIsInNewExpandPage() {
	return isInNewExpandPage ;
}

//srcType: 1: by clicking +x in oddstable, 2: otherwise
var newExpandPageSrcType = '1';
function setNewExpandPageSrcType(srctype) {
	if (srctype!=null)
		newExpandPageSrcType = srctype;
	else
		newExpandPageSrcType = '1';	
}
/**
 * judge if src is from clicking +x in oddstable or not (could be by direct url)
 */
function isFromSrcOddstable() {
	if (newExpandPageSrcType==='1')
		return true;
	else
		return false;
}
//1: traditional expand 2: expand in a new page when enableNewMatchPage is true
function isExpandMatchModeType2() {
	if (enableNewMatchPage)
		return true;
	else
		return false;
}

		var timer='';
function showMatchAllOdds(matchId,srctype) {
	closeConnection();
	setNewExpandPageSrcType(srctype);
	
	var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
	onSuccess: function(response){
		fillOddsTable(response,true);
		//match0 is the object of this match
		if (typeof(match0)!== 'undefined' && match0!=null) {
			match0.isExpanded = true;
			showMatchPageInfo();
			match0.expandFully();
		}
		//----------------------------------------------------------------
		//enable Enetpulse
		if(enableEnetpulse){makeEP(matchId);}
		
	},
	onFailure: function(){processFailure();}});
	var time_c = new Date();
	ajaxReq.send('/matchoddstable.do','id='+matchId+'&srctype='+srctype);
	ajaxReq=null;	
}

function addTest() {
	$('rtfMessage2').innerHTML = timer;
}
/**
 * show go back button in the new expand page
 */
function showMatchPageInfo() {		
	showMatchInfo();
	showMsg();	
}

function showGoBack() {
	if(isFromSrcOddstable())
		return '<a href=\'#\' id=\'goback\' onclick=\'reloadOddsTable(); \'>&lt;&lt;&nbsp;'+nameOfGoBack+'</a>';
	else
		return '';	
}

function showMsg() {
	if (getIsInNewExpandPage()) {
		var msgRow = new Element('tr');
		var msgTd = new Element('td',{'id':'msgrow','colspan':'8','align':'center'});
		msgTd.injectInside(msgRow);
		msgRow.injectInside(topTableBody);	
	}
}

function setMsg() {
	//when it's in the new expand page, show ' no more bets accepted ' if a match finished
	if (getIsInNewExpandPage()) {
		var msgrow = $('msgrow');
		if ($defined(msgrow)) {
			msgrow.setHTML(nobetsforendedmatch);
		}
	}
}

function showMatchInfo() {
	if (getIsInNewExpandPage()) {
		if (typeof(match0)!== 'undefined' && match0!=null) {
			var matchObj = match0;			
				
			match0.makeMatchInfoForExpandPage();
		}
		
		var focusObj = $('searchedName');
		if ($defined(focusObj)){
			focusObj.focus();
		}
	}
}

/** 
 * [END] new expand page
 * ---------------------------------------------------------------------------------
 */
 
//empty function for override in your own pages
function afterCollapseMatch() {}

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);
	
	//call after insertExpandedMatchIntoDOM
    afterInsertExpandedMatchIntoDOM();
   		
	} catch (e){

	}
	
}

//empty function for override in your own pages
function afterInsertExpandedMatchIntoDOM() {}

var  _betTypeParam="";  //used by time filter

function filterOdds(betTypeId,scopeId){
	closeConnection();
	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'){
		filteTable = false;
		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){
		currentPageURL = getUrl();
		currentPageParam = 'searchedName='+searchedName+'&id='+globalID+'&x='+(Math.random()*100)+betTypeParam+timeFilter+pageParam;
		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 (getIsInNewExpandPage()) {
			obj.innerHTML = showGoBack();	
			//merely for paris365
			if (mypartnerId == 36) {
				document.getElementById("BettingSelectionsHead").style.display='block';
				document.getElementById("timeOddsFormatDiv").style.display='none';				
			}
		} else {
			if(urlStatus == 'oddstable'||urlStatus == 'bannerEvent') {
				obj.innerHTML = text_yourSelection;
			}
			else
				obj.innerHTML = text_popularMatch;
				
			//merely for paris365
			if (mypartnerId == 36) {
				document.getElementById("BettingSelectionsHead").style.display='none';		
			}
		}
	}
}

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) {
	//closeConnection();
	//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 = "";
	}
	 */
	
	closeConnection();
	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;
	                 	    currentPageURL = getUrl();
	                 	    currentPageParam ='id='+globalID+timeFilter+_betTypeParam+'&searchedName='+searchedName
	                 	    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;
	//close current RTF connection first
	//closeConnection();
	filterOdds(parts[0],parts[1]);
}
function presentFilters(){
	var filterTable=$('filterBetType');
	if (filterTable==null)
		return;
		
	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 '
	filterLink.setProperty('name','defaultFilter');
	
	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 tdCell = $('filterTd_'+isOutrightsFilter);
	var tdWidth = tdCell.offsetWidth;
	var firstFilter = tdCell.getElement('div').getElement('a');
	var filterWidth = firstFilter.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();

		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();
		}
		//expandCellIsLink
		/*
		 var prefix = '';
			var isFold = '';
			if(this.expanded) {
				prefix = '-';
			}
			else {
				prefix = '+';	
				isFold = 'Fold';		
			}	
			if (expandCellIsLink)
			    extraCell.setHTML('<a class="expandLink'+isFold+'" href="javascript:void(0);"><span>'+prefix+otherOutrights+'</span></a>');
			else 
			    extraCell.setHTML(prefix+otherOutrights);		
		 
		 * */
		var numOfMoreFilter = filtersNum - currentNumOfDivPerRow;
		var td = $('expander_'+isOutrightsFilter);
		if (expandCellIsLink)
		   td.setHTML('<a href="javascript:void(0);" class="expandLink"><span>-'+numOfMoreFilter+'</span></a>');
		else		    
		   td.setHTML('-'+numOfMoreFilter);
		td.addEvent('click',function(){displayFilter('filterRow_'+isOutrightsFilter,'filterRowSingle_'+isOutrightsFilter)});
		
		var td2 = currentRow2.getChildren()[1];
		td2.id = 'expanderSingle_'+isOutrightsFilter;
		if (expandCellIsLink)
		   td2.setHTML('<a href="javascript:void(0);" class="expandLinkFold"><span>+'+numOfMoreFilter+'</span></a>');	
		else
		   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 = '';
	//for iframe calling
	afterDisplayFilter();
}

//empty function for override in your own pages
function afterDisplayFilter() {}

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 initialParams() {
	betTypeIdShown=-1;
	scopeIdShown=-1;
	curBetType='all';
	curScope=-1;
	filteTable = false;
	timeFilters = null;
}
function showOddsa(tm,type){
	closeConnection();
     var ajaxReq=new XHR({'method': 'post',
     					'autoCancel': 'true',
     					 onSuccess: function(response){
     					 		currentPageURL = '/oddstable.do';
     					 		currentPageParam = 'fType='+type+'&tm='+tm;
     					 		fillOddsTable(response);
     					 		urlStatus = 'oddstable';
     					 }, 
     					 onFailure: function(){
     					 	processFailure();
     					 }});
     ajaxReq.send('/oddstable.do','fType='+type+'&tm='+tm);
	 ajaxReq=null;
	 afterClickLeftTree();
}
function showOddsb(tm,fType){
	
	closeConnection();
	filterL = true;
	if (timeFilters!=(fType+"-"+tm)){// 2 hours ---> 4 hours :make the 'default' filter default

    }
    initialParams();
    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;
	                 		currentPageURL = '/oddstable.do';
	                 		currentPageParam = timeFilter;
	                 	    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();
	
	initialParams();
	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){
                         	currentPageURL = '/popularMatch.do';
                         	currentPageParam = param;
                         	fillOddsTable(response);
                         	urlStatus = 'popularMatch';
                         	//goForUpdates();
                         	},
                         onFailure: function(){processFailure();}});
		ajaxReq.send('/popularMatch.do',param);
		ajaxReq=null;
		
		//for iframe calling
		afterLoadPopularMatch();
}

//empty function for override in your own pages
function afterLoadPopularMatch() {}

/**
 * search Matches by searched name(player name, match name, tournament name) 
 */
function searchMatchesByName() {
	closeConnection();
	//reset parameters
	initialParams();
	
	var param='';
	var searchedName_0 = document.getElementById('searchedName').value;
	
	var reg = re = /\'/g;  
	if(searchedName_0.length >=3 && searchedName_0.length <= 15) {
		
		searchedName = searchedName_0.replace(reg,"''");//replace ' with double ' to avoid sql error
		
		//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){ 
	                         	currentPageURL = '/popularMatch.do';
	                         	currentPageParam = param;
	                         	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)
{
	
	resetEPrightBox();//reset EP part of page.
	
	//if the param contains srctype, it means all the odds of an event is needed for presentation
	if ( bannerParam!=null && bannerParam.indexOf('srctype')>=0) {
		var matchid = '';
		var q=bannerParam.substring(1);
		//all parameter arrays. 
		var params=q.split('&');
		for(var i=0;i<params.length;i++){
			//seeks 'id'
			var p=params[i];
			var pnv=p.split('=');			  
			var pn=pnv[0];
			if(pn === 'id'){
				var matchid = pnv[1];
				break;
			}
		}
		
		//go to load all odds of an event
		showMatchAllOdds(matchid,'0');
		return;
	}
	
	//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";
	initialParams();
	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){
                         	currentPageURL = '/bannerEvent.do';
                         	currentPageParam = param; 
                         	urlStatus = 'bannerEvent';
                         	fillOddsTable(response);
                         },
                         onFailure: function(){processFailure();}});
		ajaxReq.send('/bannerEvent.do',param);
		ajaxReq=null;
		//for iframe calling
		afterLoadTournamentORMatch();
}

//empty function for override in your own pages
function afterLoadTournamentORMatch() {}


function changeZoneOrOddsFormat(type,value){
	closeConnection();
	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'){
		
		if(value.indexOf(":") > 0){
			var strArr = value.split(":");
			setParam += strArr[0];
			setParam += "&gmtTimeZoneOffsetMin=";
			setParam += strArr[1];
		} else {
			setParam += value;
			setParam += "&gmtTimeZoneOffsetMin=0";
		}
		
	}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){
	                 	    currentPageURL = getUrl();
	                 	    currentPageParam = 'id='+globalID+'&x='+(Math.random()*100)+timeParam+_betTypeParam+setParam;
	                 	    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 href=\"javascript:changeBetTypeTab('0')\">"+bettypesC+"</a>";
		//$('defaultBtRow').style.display='none';
		$('allBtRow').style.display='block';
	} else {
		$('BetTypeTab').innerHTML="<a href=\"javascript:changeBetTypeTab('1')\">"+bettypesE+"</a>";	
		//$('defaultBtRow').style.display='block';
		$('allBtRow').style.display='none';
	}
}

function changeBetTypeTabForBetexpress(inType) {
	if (inType=='1') {
		$('BetTypeTab').setStyle('background','url(/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(/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 hideBetTypeTab() {
	var defaultBtRow = $('defaultBtRow');
	if ($defined(defaultBtRow)) {
		if (getIsInNewExpandPage())
			defaultBtRow.style.display='none';
		else
			defaultBtRow.style.display='block';
	}
}

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;
}

function showIsMatchCenter(element){
	var divTemp = $(element);
	divTemp.toggleClass('hidden');
	divTemp.getNext().toggleClass('hidden');
	toggleMatchCenter(divTemp);
}
function toggleMatchCenter(divTemp) {
	var matchCenter = divTemp.getParent().getParent().getParent().getNext();
	var index = 0;
	while (true && index<100) {
		if (matchCenter.hasClass('ScoreLine')||matchCenter.hasClass('matchInfoLine')) {
			matchCenter.toggleClass('hidden');
			break;
		} else {
			matchCenter = matchCenter.getNext();
		}
		index++;
	}	
}
function showIsMatchCenterLiveNow(element){
	var divTemp = $(element);
	divTemp.toggleClass('hidden');
	divTemp.getPrevious().toggleClass('hidden');
	toggleMatchCenter(divTemp);
}
/**--end betting type tab event --**/
//for Enetplus

var lockedEP = false;

function makeEP(matchId){
	initEPlusEl(matchId);	
}

function makeSubEP(topdiv){
	//for different types.
	var types = [epType.H2H_CLUB_EVENT,epType.H2H_CLUB_EVENT,epType.H2H_AGAINST,epType.H2H_STANDING,epType.H2H_STANDING,epType.H2H_STANDING],
	paramters = [{event_participant_number:1,sort:"date_desc"},
				 {event_participant_number:2,sort:"date_desc"},
				 {sort:"date_desc"},
				 {theme:'over_under',type:'over_under'},
				 {theme:'handicap',type:'handicap'},
				 {theme:'halftime_fulltime',type:'halftime_fulltime'}],

	contents = [epText.lastMatchEP + '&nbsp;' + match0.homeParticipantName,
				epText.lastMatchEP + '&nbsp;' + match0.awayParticipantName,
				epText.lastEventAgainstEP ,
				epText.overUnderEP,
				epText.HandicapEP ,
				epText.HalftimeFulltimeEP
				];
					
	var topdivTemp = topdiv;
	contents.each(function(item, index){
		var div = new Element('div',{'class':'clickbarHidden'});
		div.setHTML(item);
		div.injectAfter(topdivTemp);
		topdivTemp = div;
		
		var loadDiv = new Element('div',{'class':'div_loadPicTab'});
		loadDiv.addClass('hidden');
		loadDiv.injectInside(div);
		
		div.addEvent('click',function(){
			if(lockedEP) return;
			if( div.hasClass('clickbarHidden')){
				lockedEP = true;
				loadDiv.removeClass('hidden');
				var contentDiv =  new EnetplusInfo({
					isShowBar:false,
					isShowLeague:true,
					onComplete:function(req){
						loadDiv.addClass('hidden');
						div.removeClass('clickbarHidden').addClass('clickbarShow');
						lockedEP = false;
					}
				}).show(types[index],paramters[index],this);
				contentDiv.injectAfter(div);
			}else{
				div.getNext().remove();		
				this.removeClass('clickbarShow').addClass('clickbarHidden');
			}
		});
	});
}

/**
 * init EP data, get mapping FK from backend and make EP center box.
 * now only football has EP FK.
 */
function initEPlusEl(matchId){
	var ajax = new XHR({'method':'post',
				onSuccess:function(req){
					//req =  '[{"omEventId":409840, "enetPlusEventId" : 835988, "participants":[{"participant":[{"enID":333, "OMID":444}] , "participant" :[{"enID":111, "OMID":222}]}]}]';
					var fk = getEventFK(req);
					if (fk=='')return;
					//avoid delay of matchInfoPage
					if( $defined($('matchLineEP')) ){
						$('matchLineEP').remove();
					}
					var toprow = new Element('tr',{'class':'matchLine','id':'matchLineEP'}),
					toptd = new Element('td',{'id':'matchInfoCell','colspan':'8','align':'center'}),
					topBar = new Element('div',{'id':'topbar','class':'topbarEPExpandLoad'}),
					contentEPRow = new Element('tr',{'class':'matchLine hidden','id':'matchLineEP'}),
					contentEPTd = new Element('td',{'id':'matchInfoCell','colspan':'8','align':'center'}),
					outSideDiv = new Element('div',{'id':'omep','class':'omep'}),
					parentDiv = new Element('div',{'id':'inlineWidgets'});
					
					topBar.setText(epText.loadingTopBarEP);
					topBar.injectInside(toptd);
					toptd.injectInside(toprow);
					toprow.injectAfter($('matchInfoLine'));
					
					parentDiv.injectInside(outSideDiv);
					outSideDiv.injectInside(contentEPTd);
					contentEPTd.injectInside(contentEPRow);
					contentEPRow.injectAfter(toprow);
					var eventInfoDiv = new EnetplusInfo({
						onComplete:function(){
							topBar.addEvent('click',function(){
								contentEPRow.toggleClass('hidden');
								if(contentEPRow.hasClass('hidden')){
									this.setText(epText.expandEP);
									this.removeClass('topbarEPCollapse').addClass('topbarEPExpand');
								}else{
									this.setText(epText.collpseEP);
									this.removeClass('topbarEPExpand').addClass('topbarEPCollapse');
								}
							});
							topBar.removeClass('topbarEPExpandLoad').addClass('topbarEPExpand');
							topBar.setText(epText.expandEP);
						}
					}).show(epType.EVENT_INFO);
					eventInfoDiv.injectInside(parentDiv);
					resetEPrightBox();
					makeSubEP(eventInfoDiv);
					var loadDivEPtab = new Element('Div',{'id':'loadEPtab','class':'div_loadPicTab2'});
					loadDivEPtab.injectInside($('sidebarWidgets'));
					makeEPWidget();
				},
				onFailure:function(req){
					alert('Can not load EP data! info:' + req);
				}});
	ajax.send("/enetplusWidget.do","eventId="+matchId);//Action to get
}


function makeTabsOfEP(){
	var types = [epType.H2H_CLUB_EVENT,epType.H2H_CLUB_EVENT],
	paramters = [{event_participant_number:1},{event_participant_number:2},],
	contents = [match0.homeParticipantName,match0.awayParticipantName];
	var tabEPDiv = new Element('Div',{'id':'tabEP'});
	var topdivTemp = null;
	contents.each(function(item, index){
		var div = new Element('div');
		div.setHTML(item);
		if(topdivTemp == null){
			div.injectInside(tabEPDiv);
			div.addClass('tabSubEPShow');
		}else{
			div.injectAfter(topdivTemp);
			div.addClass('tabSubEPHidden');
		}
		topdivTemp = div;
		div.addEvent('click',function(){
			if( div.hasClass('tabSubEPHidden') ){
				tabEPDiv.getElementsBySelector('.tabSubEPShow').removeClass('tabSubEPShow').addClass('tabSubEPHidden');
				div.removeClass('tabSubEPHidden').addClass('tabSubEPShow');
				tabEPDiv.getNext().remove();
				var loadDivEPtab = new Element('Div',{'id':'loadEPtab','class':'div_loadPicTab2'});
				loadDivEPtab.injectInside(tabEPDiv);
				var contentDiv =  new EnetplusInfo({
					isShowBar:true,
					isShowLeague:false,
					onComplete:function(req){
						loadDivEPtab.remove();
						contentDiv.injectAfter(tabEPDiv);
					}
				}).show(types[index],paramters[index],this);	
			}
			//contentDiv.injectAfter(div);
		});
	});
	
	return tabEPDiv;
}

function makeEPWidget(){
	var slidDiv = $('sidebarWidgets');
	var tabDiv = makeTabsOfEP();
	var contentDiv =  new EnetplusInfo({
		isShowBar:true,
		isShowLeague:false,
		onComplete:function(req){
			$('loadEPtab').addClass('hidden');
			tabDiv.injectInside(slidDiv);
			contentDiv.injectAfter(tabDiv);
		}
	}).show(epType.H2H_CLUB_EVENT,{event_participant_number:1},this);
}

function resetEPrightBox(){
	if($defined($('sidebarWidgets'))){
		$('sidebarWidgets').setHTML('');	
	}
	return;
}

