/*------- 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';

var OddsTableModel = new Class({
	initialize : function(){
		this.disciplines = new Hash();
		//this.involvedMatches = new Hash();
		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(this.disciplines[i]))
			var dis = 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(this.disciplines[i]))	
			var dis = disciplines[i];				
				nrOfBettypes += disciplines[i].countBettypes();
		}
		this.nrOfBettypes = nrOfBettypes;
		return nrOfBettypes;
	},
	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 (!(betType.typeId == currentMatch.tournament.defaultOutcomeType.betTypeId && betType.scopeId == currentMatch.tournament.defaultOutcomeType.scopeId 
			|| currentMatch.expanded)) {
			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);
		//this.involvedMatches.set(currentMatch.id,null);
	},
	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);
			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 goForUpdates(){
	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);
					},
				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);
			}
			//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.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.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;
	}
});

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 ) {
		
		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;
		
	}
	return false;
}
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) {
		
		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 ) {
		
		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){//7,25,26,27,28,57,65,66,67,68 outrights bettype
		this.HEADTITLE_HOME_DRAW_AWAY_WITH_HANDICAP = new BetTypeHeadTitle(8,BTH_HOME_DRAW_AWAY_WITH_HANDICAP);
		this.HEADTITLE_DOUBLE_CHANCE = new BetTypeHeadTitle(9,BTH_DOUBLE_CHANCE);
		this.HEADTITLE_HALF_TIME_FULL_TIME = new BetTypeHeadTitle(11,BTH_HALF_TIME_FULL_TIME);
		this.HEADTITLE_NUMBER_OF_GOALS = new BetTypeHeadTitle(32,BTH_NUMBER_OF_GOALS);
		this.HEADTITLE_ODD_OR_EVEN = new BetTypeHeadTitle(35,BTH_ODD_OR_EVEN);
		this.HEADTITLE_GAME_HANDICAP = new BetTypeHeadTitle(39,BTH_GAME_HANDICAP);
		this.HEADTITLE_HOME_DRAW_AWAY = new BetTypeHeadTitle(43,BTH_HOME_DRAW_AWAY);
		this.HEADTITLE_CORRECT_SCORE_WITH_SCOPE = new BetTypeHeadTitle(45,BTH_CORRECT_SCORE_WITH_SCOPE);
		this.HEADTITLE_HOME_AWAY_WITH_IMPOSSIBLE_DRAW = new BetTypeHeadTitle(46,BTH_HOME_AWAY_WITH_IMPOSSIBLE_DRAW);
		this.HEADTITLE_OVER_UNDER = new BetTypeHeadTitle(47,BTH_OVER_UNDER);
		this.HEADTITLE_ASIAN_HANDICAP = new BetTypeHeadTitle(48,BTH_ASIAN_HANDICAP);
		this.HEADTITLE_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);

	},
	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_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);
	}
	
	
});

var betTypes=new BetTypes();
var scopeIds=new ScopeIds();

var BetTypeKey=new Class({
	initialize: function(betTypeId,scopeId){
		this.betTypeId=betTypeId;
		this.scopeId=scopeId;
	}
});



var Util = new Class({
	initialize: function(){
		this.dateRegex=/(\d{1,4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):.+/;
	},
	getDateFromJavaString: function(dateString){
		var rezDate=new Date();
		var rez=dateString.match(this.dateRegex);
		rezDate.setYear(rez[1]);		
		rezDate.setDate(parseFloat(rez[3]));
		rezDate.setMonth(parseFloat(rez[2])-1);		
		rezDate.setHours(parseFloat(rez[4]));
		rezDate.setMinutes(parseFloat(rez[5]));
		return rezDate;
	}
});

var util = new Util();

var OutcomeTypes=new Class({
	initialize: function(){
		this.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.HOMEDRAWAWAY_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY,scopeIds.SCOPE_ID_FULL_EVENT);
		this.HOMEDRAWAWAY_FIRST_HALF=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY,scopeIds.SCOPE_ID_1ST_HALF);
		this.HOMEDRAWAWAY_SECOND_HALF=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY,scopeIds.SCOPE_ID_2ND_HALF);
		this.OVERUNDER_FULLTIME_EXCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_OVER_UNDER,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.OVERUNDER_FULLTIME_INCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_OVER_UNDER,scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME);
		this.OVERUNDER_FIRST_HALF=new BetTypeKey(betTypes.TYPE_ID_OVER_UNDER,scopeIds.SCOPE_ID_1ST_HALF);
		this.OVERUNDER_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_OVER_UNDER,scopeIds.SCOPE_ID_FULL_EVENT);
		this.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_ASIAN_HANDICAP,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_ASIAN_HANDICAP,scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME);
		this.ASIANHANDICAP_FIRST_HALF=new BetTypeKey(betTypes.TYPE_ID_ASIAN_HANDICAP,scopeIds.SCOPE_ID_1ST_HALF);
		this.HOME_DRAW_AWAY_WITH_HANDICAP_FULLTIME_EXCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.HOMEAWAY_FULLEVENT=new BetTypeKey(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW,scopeIds.SCOPE_ID_FULL_EVENT);
		this.HOMEAWAY_FULLEVENT_INCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW,scopeIds.SCOPE_ID_FULL_TIME_INCLUDING_OVERTIME);
		this.HALFTIME_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_HALF_TIME_FULL_TIME,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.CORRECTSCORE_FULLTIME_EXCLUDEOVERTIME=new BetTypeKey(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.CORRECTSCORE_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE,scopeIds.SCOPE_ID_FULL_EVENT);
		this.CORRECTSCORE_FIRST_HALF=new BetTypeKey(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE,scopeIds.SCOPE_ID_1ST_HALF);
		this.DOUBLE_CHANCE_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_DOUBLE_CHANCE,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
				//----------wolf add bettype---------------------------
		this.DOUBLE_CHANCE_FIRST_HALF=new BetTypeKey(betTypes.TYPE_ID_DOUBLE_CHANCE,scopeIds.SCOPE_ID_1ST_HALF);
		this.GAMEHANDICAP_FULLEVENT = new BetTypeKey(betTypes.TYPE_ID_GAME_HANDICAP,scopeIds.SCOPE_ID_FULL_EVENT);
		this.SETHANDICAP_FULLEVENT = new BetTypeKey(betTypes.TYPE_ID_SET_HANDICAP,scopeIds.SCOPE_ID_FULL_EVENT);
		
		this.TIME_OF_NEXT_GOALFULLTIME_EXCLUDEOVERTIME  = new BetTypeKey(betTypes.TYPE_ID_TIME_OF_NEXT_GOAL,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);

		this.ODD_OR_EVEN_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_ODD_OR_EVEN,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		this.NUMBER_OF_GOALS_FULLTIME=new BetTypeKey(betTypes.TYPE_ID_NUMBER_OF_GOALS,scopeIds.SCOPE_ID_FULL_TIME_EXCLUDING_OVERTIME);
		
	}
});
var outcomeTypes=new OutcomeTypes();

var currentExpandedMatch=null;
var topTable;
var topTableBody;
function initTopTable(){
	date1= new Date();// initial the sessionTimeOut data,the variable was defined on frontpage.js
	topTable=new Element('table', {'id':'oddstableTable','class':'oddsInfoTab','width': '100%','cellspacing':'0','cellpadding':'0','border':'0'});
	if(window.ie){
		topTable.setStyle('padding','0');
	    topTable.setStyle('border-collapse','collapse');
	}
	topTableBody=new Element('tbody',{'id':'topTableBody'});
	topTableBody.injectInside(topTable);
	
	showRtfStatus();
}

function showRtfStatus() {	
	if (myplatform == 'prod')
		return;
	var rtfMessageRow = new Element('tr');
	var rtfTd = new Element('td',{'id':'rtfMessage','colspan':'8'});
	
	rtfTd.setHTML(getRtfStatus());
	rtfTd.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','width':'100%'});
		elementName.setHTML(name);
		elementName.injectInside(this.elementLine);
		//this.elementCell.setHTML(name);
	},
	setNameWithDiv: function(name,divId){
		this.name=name;
		var elementName=new Element('td',{'colspan':'8','width':'100%'});
		elementName.setHTML('<div id='+divId+'><p>'+name+'</p></div>');
		elementName.setStyle('border-bottom-style','none');
		elementName.injectInside(this.elementLine);
	},
	appendCategChildRow: function(categElement){
		//var elementDate=new Element('td');
		//elementDate.injectInside(this.elementLine);	//alert(topTableBody.innerHTML);
	},
	appendCategChildRowWithDiv: function(categElement,divId){
		var newLine=new Element('tr');
		var newCell=new Element('td');
		var newDiv = new Element('div',{'id':divId});
		newDiv.injectInside(categElement.topElementTable);
		newCell.injectInside(newLine);
		categElement.topElementTable.injectInside(newCell);
		newLine.injectInside(this.topElement);
	},
	addDiv:function(divStr){

	}
});

var Discipline = CategElement.extend ({
	initialize: function(id){
		this.parent(id);
		this.countries=new Hash();
		//this.setClassName('MarketTab');
		/*var headerRow=new Element('tr',{'class': 'headerRow'});
		var dateCell=new Element('td',{'class': 'dateWidth'});
		dateCell.setText('DATE');
		dateCell.injectInside(headerRow);
		var hourCell=new Element('td',{'class': 'hourWidth'});
		hourCell.setText('HOUR');
		hourCell.injectInside(headerRow);
		var homeTeamCell=new Element('td',{'class': 'teamWidth'});
		homeTeamCell.setText('HOME-TEAM');
		homeTeamCell.injectInside(headerRow);
		var awayTeamCell=new Element('td',{'class': 'teamWidth'});
		awayTeamCell.setText('AWAY-TEAM');
		awayTeamCell.injectInside(headerRow);
		var homeCell=new Element('td',{'width': '45','colspan': '2'});
		homeCell.setText('HOME');
		homeCell.injectInside(headerRow);
		var drawCell=new Element('td',{'width': '45','colspan': '2'});
		drawCell.setText('DRAW');
		drawCell.injectInside(headerRow);
		var awayCell=new Element('td',{'width': '45','colspan': '2'});
		awayCell.setText('AWAY');
		awayCell.injectInside(headerRow);
		var expandCell=new Element('td',{'width': '10'});
		expandCell.setHTML('&nbsp;');
		expandCell.injectInside(headerRow);
		//headerRow.injectInside(this.topElement);*/

		this.elementLine=new Element('tr',{'class': 'titleLine'});
		this.elementCell=new Element('td');
		this.elementLine.injectInside(topTableBody);
	},
	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;
	},
	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(this));
		var imgIndex=0;
		for(var i=0;i<countries.length;i++){
			var country=countries[i];
			var tournaments=country.tournaments.values();
			for(var k=0;k<tournaments.length;k++){
				var tournament=tournaments[k];
				tournament.prepareForDump("img"+imgIndex);
				imgIndex++;
			}
		}
		topTable.injectInside(parentNode); //document.write(topTableBody.innerHTML); //
		//alert(topTable.innerHTML);
		//alert(document.getElements('td.middle'));		alert($("oddsTable").height);
	},
	setName: function(name){
		this.name=name+$("zoneAndOddsFormat").innerHTML;
		var elementDate=new Element('td',{'colspan':'8'});
		elementDate.injectInside(this.elementLine);

		var nameSpanHolder=new Element('div',{'id':'MarketTabTL'});
		nameSpanHolder.injectInside(elementDate);

		nameSpanHolder=new Element('div',{'id':'MarketTab'});
		nameSpanHolder.setText(name);
		nameSpanHolder.injectInside(elementDate);
		nameSpanHolder=new Element('div',{'id':'MarketTabTR'});
		nameSpanHolder.injectInside(elementDate);
		elementDate.setStyle('border-bottom-style','none');
		/*if (this.elementLine.rowIndex==0){
			var elementZone=new Element('td',{'colspan':'5','style':'text-align:right'});
			elementZone.setHTML($("zoneAndOddsFormat").innerHTML);
			elementZone.setStyle('border-bottom-style','none');
			elementZone.injectInside(this.elementLine);
		}*/

	},
	appendCategChildRow: function(categElement){
		//var elementDate=new Element('td');
		//elementDate.injectInside(this.elementLine);
	},
	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;
	},
	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;
	},
	removeTournamentFromDom:function() {
		this.elementLine.remove();
	},
	setCountry: function(country){
		this.country=country;
	},
	setNameWithDiv: function(name,nameForTitle){
		this.name=name;
		var tourNameCell = new Element('td',{'colspan':'4','width':'80%'});
		tourNameCell.setStyle('border-bottom','0px');
		tourNameCell.setHTML('<div id="MarketH1"><div id="GameHeadline"><p>'+nameForTitle+'</p></div></div>');
		tourNameCell.injectInside(this.elementLine);
	},
	setNameWithScope: function(name,nameForTitle,scopeName){
		this.name=name;
		var tourNameCell = new Element('td',{'colspan':'4','width':'80%'});
		tourNameCell.setStyle('border-bottom','0px');		
		tourNameCell.setHTML('<div id="MarketH1"><div id="GameHeadline"><p><label class="TourName"> '+nameForTitle+' </label><label  class="BtScope">'+
		scopeName+'</label></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 cellHome=new Element('td',{'class':'oddsCell','style':'border-bottom:0px;'});
		cellHome.setHTML('<div id="MarketH1"><div id="GameHeadline1X2"><p>'+cellHomeText+'</p></div></div>');
		var cellX=new Element('td',{'class':'oddsCell','style':'border-bottom:0px'});
		cellX.setHTML('<div id="MarketH1"><div id="GameHeadline1X2"><p>'+cellXText+'</p></div></div>');
		var cellAway=new Element('td',{'class':'oddsCell','style':'border-bottom:0px'});
		cellAway.setHTML('<div id="MarketH1"><div id="GameHeadline1X2"><p>'+cellAwayText+'</p></div></div>');

		cellHome.setStyle('border-bottom','0px');
		cellX.setStyle('border-bottom','0px');
		cellAway.setStyle('border-bottom','0px');

		cellHome.injectInside(this.elementLine);
		cellX.injectInside(this.elementLine);
		cellAway.injectInside(this.elementLine);
	},
	showDefaultOutcomeType: function(imgId){
		var titleTmp = headTitle.HEADTITLE_OTHER;
		if((this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_HOME_DRAW_AWAY	)||
			(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP)){
			titleTmp = headTitle.HEADTITLE_HOME_DRAW_AWAY_WITH_HANDICAP;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_NEXT_TEAM_TO_SCORE){
				titleTmp = headTitle.HEADTITLE_NEXT_TEAM_TO_SCORE;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW ||
					this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_HOME_AWAY_WITH_POSSIBLE_DRAW){
				titleTmp = headTitle.HEADTITLE_HOME_AWAY_WITH_IMPOSSIBLE_DRAW;
		}
		else if((this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_ASIAN_HANDICAP) ||
				(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_GAME_HANDICAP) ||
				(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_SET_HANDICAP)	){
			          titleTmp = headTitle.HEADTITLE_ASIAN_HANDICAP;
				       if (this.country.discipline.id==3){
							if (this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_GAME_HANDICAP){
								titleTmp = headTitle.HEADTITLE_GAME_HANDICAP_TENNIS;
							}else if (this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_SET_HANDICAP){
								titleTmp = headTitle.HEADTITLE_SET_HANDICAP_TENNIS;
							}
						}
		}
		else if((this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_OVER_UNDER)){
				titleTmp = headTitle.HEADTITLE_OVER_UNDER;
				if (this.country.discipline.id==3){// just for tennis
				 			 titleTmp = headTitle.HEADTITLE_OVER_UNDER_TENNIS;}
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_ODD_OR_EVEN){
				titleTmp = headTitle.HEADTITLE_ODD_OR_EVEN;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_DOUBLE_CHANCE){
				titleTmp = headTitle.HEADTITLE_DOUBLE_CHANCE;
		}
		//outrights		
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_TOP_X){
				titleTmp = headTitle.getHEADTITLE_TOP_X_withParam(this.defaultOutcomeType.scopeId);
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_WINNER){
				titleTmp = headTitle.HEADTITLE_WINNER;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_TOP_GOALSCORER){
				titleTmp = headTitle.HEADTITLE_TOP_GOALSCORER;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_RELEGATION){
				titleTmp = headTitle.HEADTITLE_RELEGATION;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_PROMOTION){
				titleTmp = headTitle.HEADTITLE_PROMOTION;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_ROCK_BOTTOM){
				titleTmp = headTitle.HEADTITLE_ROCK_BOTTOM;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_POLE_POSITION){
				titleTmp = headTitle.HEADTITLE_POLE_POSITION;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_FASTEST_LAP){
				titleTmp = headTitle.HEADTITLE_FASTEST_LAP;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_FIRST_TO_RETIRE){
				titleTmp = headTitle.HEADTITLE_FIRST_TO_RETIRE;
		}
		else if(this.defaultOutcomeType.betTypeId==betTypes.TYPE_ID_FIRST_LAP_LEADER){
				titleTmp = headTitle.HEADTITLE_FIRST_LAP_LEADER;
		}
		else {
			titleTmp = headTitle.HEADTITLE_OTHER;
		}
		this.setOutcomeType(titleTmp.homeText,titleTmp.drawText,titleTmp.awayText);

		var extraCell=new Element('td',{'class': 'expandable'}); // this is for the +NoOutcomeTypes in the match rows
		extraCell.setStyle('border-bottom','0px');
		var divCell=new Element('div',{'id':'MarketH1'});
		var hideImage = new Element('div',{'id':'img'+imgId,'name':imgId,'class':'loadImgOfTitle','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 Match = CategElement.extend ({
	initialize: function(id,imgId){
		this.id=id;
		this.name='';
		this.date='aa';
		this.elementLine=new Element('tr',{'class': 'matchLine'});
		this.elementCell=new Element('td',{'class': 'invisibleHolder'});
		//this.elementCell.injectInside(this.elementLine);
		this.elementLine.injectInside(topTableBody);

		this.betTypes=new Array();
		this.homeParticipantName='';
		this.awayParticipantName='';
		this.numberOfOutrights=0;
		this.rowCount = 0;// flag the bettyperow to get the next row
		this.expanded=false;
		this.maxRisk=1000;
		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 1: count visible bettypes
		var nrOfBettypes = 0;
		var betTypes = this.getBetTypeObjs();
		var betTypesL = betTypes.length;
		for (var i =0; i<betTypesL; i++){		
			if ($defined(betTypes[i]))			
				nrOfBettypes += betTypes[i].countBettypes();
		}
		this.nrOfBettypes = nrOfBettypes;
		* **/
		
		//way 2: count the number beside each match
		var nrOfBettypes = parseInt(this.numberOfOutrights);
		return nrOfBettypes;
	},
	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() {
		this.deleteMatchLines('1');
		this.tournament.removeMatch(this.id);
	},
	suspendMatch:function() {
		this.deleteMatchLines('0');
	},
	deleteMatchLines:function(type) {		
		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();
			}			
		} 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();
					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]);
				}
			} 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; 
	},
	isSuspended:function() {
		if (this.showLive() && this.betStatus=='stopped') 
			return true;
		else 
			return false; 
	},
	showLive:function() {
		if (this.evtType==1)
			return true;
		else
			return false;
	},
	setBetStatus:function(status) {
		this.betStatus = status;
	},
	setScore:function(score) {
		this.score = score;
	},
	setMatchStatus:function(matchStatus) {
		this.matchStatus = matchStatus;
	},
	setMatchTime:function(matchTime) {
		this.matchTime = matchTime;
	},
	setMatchTimeType:function(matchTimeType) {
		this.matchTimeType = matchTimeType;
	},
	getOddsCellText:function() {
		var text = '&nbsp';
		if (this.showLive()) {
			if (this.isSuspended())
				text = smTxt;
			else			
				text = emptyOddsTxt;
		}
		return text;
	},
	showSM: function(tdObj) {
		
		if (tdObj.className == 'expandable') {
			tdObj.innerHTML = '&nbsp';
		} else {
			var text = this.getOddsCellText();
			if (this.isSuspended())
				tdObj.innerHTML = '<div class=\'smOddsCell\'>'+text+'</div>';
			else			
				tdObj.innerHTML = '<div class=\'emptyOddsCell\'>'+text+'</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())) {
				/** 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();
					}
					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=participantName;
	},
	setAwayParticipantName: function(participantName){
		this.awayParticipantName=participantName;
	},
	setTournament: function(tournament){
		this.tournament=tournament;
	},
	setNumberOfOutrights: function(numberOfOutrights){
		this.numberOfOutrights=numberOfOutrights;
	},
	setMatchRisk:function(risk){
		this.maxRisk = risk;
	},
	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]);
				}
			} 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);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 extraCell=new Element('td',{'class': 'expandable'}); // this is for the +NoOutcomeTypes

		if(otherOutrights>0 && !this.isSuspended()){
			extraCell.addEvent('click',function(){
				if(this.expanded){
					collapseMatch(this);
				} else {
					expandMatch(this);
				}
			}.bind(this));
			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);		
			      
		} else {
			extraCell.setHTML('&nbsp;');
		}
		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)) {
			var oddsParam = defaultBetTypeObj.odds.values();
			var oddsL = oddsParam.length;
			otherOutrights -= oddsL;
		}
		return otherOutrights;
	},
	updateOrCreateExtraCell:function(number) {
		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(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';					
			}
			
			if (otherOutrights<=0 || this.isSuspended()) {
				prefix = '';
				otherOutrights = '&nbsp;';				
				childen.removeEvents('click');
			}
			
			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) {
		this.score = score;
		this.matchStatus = matchStatus;
		this.matchTime = matchTime;
		this.matchTimeType = matchTimeType;
		this.betStatus = betStatus;
		
		//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
				hourCell.setHTML(content);
			}
		}		
	},
	makeHourCellContainer:function(htmlText) {
		var className = '';
		if (this.showLive()) {
			if (this.isLive()) 
				className='living';
			else 
				className='willBeLive';
		} else {
				className='date';			
		}
		return "<div class=\'"+className+"\'>"+htmlText+"</div>";
	},
	makeHourCellContent:function(dateText,hourText,showEmptyCell) {
		//icon which indicates match status	
		//var liveDiv = this.getMatchIcon();
		
		//for live match , don't show match center in expanded rows
		if (showEmptyCell=='1' && this.showLive())
			return '';
			
		var dateCell='';
				
		if (this.isLive()) {
			//if this is a live match, show match info
			var timeStr = '';
			if (this.matchTimeType!=0)
				timeStr = "&nbsp;"+this.matchTime;
			dateCell = "<ul class='matchInfo'><li>"+this.matchStatus
					+timeStr+"</li><li>"//+scoreTxt+" "
					+this.score
					+"</li></ul>";
		} else {
			var prefix='';
			if (this.showLive())
				prefix = liveAt+'&nbsp;';
			//else show match date.
			if (operName =='NoIQ'){
				dateTimeLine = "<br>";
			}else{
				dateTimeLine = " ";
			}
			if (dateText==null || dateText=='' || hourText==null || hourText=='') {
				if( isHebrew ){
					m_names = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
				}else{
					m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");//default value 
				}
				dateText = (this.date.getDate()<10?'0'+this.date.getDate():this.date.getDate())+'.'+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());
			}
			dateCell = prefix+dateText + dateTimeLine + hourText;
		}
		return this.makeHourCellContainer(dateCell);
	},
	prepareForDump: function(imgId){
		/*var hTable=new Element('table',{'class':'matchInfo','width':'100%','border':'0'});
		var hBody=new Element('tbody');
		var hRow=new Element('tr');
		var img = new Element('img',{'src':'/jsp/oddsmatrix/'+operName+'/style/CalendarIcon.gif',
		'class':'DateIcon'});*/

		var divId = 'MarketR1';
		
		var hourCell=new Element('td',{'class': 'hourWidth','colspan':'2'});
		hourCell.setHTML(this.makeHourCellContent());

		var homeCell=new Element('td',{'class': 'teamWidth'});
		homeCell.setStyle("padding-left","5px");
		homeCell.setHTML(this.homeParticipantName);
		var awayCell=new Element('td',{'class': 'teamWidth'});
		awayCell.setText(this.awayParticipantName);

		hourCell.injectInside(this.elementLine);
		homeCell.injectInside(this.elementLine);
		awayCell.injectInside(this.elementLine);

		this.imgId = imgId;
		var needShowEmptyOddsMatch = false;
		if (this.betTypes.length==0)
			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;
	},
	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) return;//if odds less than min odds line then return 
		addNewBet(this.id, outcomeId,oddsValue.toFixed(2),formattedValue,this.name,type,'0.0',(this.date.getDate()<10?'0'+this.date.getDate():this.date.getDate())+'.'+(this.date.getMonth()<9?'0'+(this.date.getMonth()+1):(this.date.getMonth()+1))+'.'+this.date.getFullYear().toString().substring(2)+' '+(this.date.getHours()<10?'0'+this.date.getHours():this.date.getHours())+':'+(this.date.getMinutes()<10?'0'+this.date.getMinutes():this.date.getMinutes()),participantName,this.maxRisk,betTypeName,this.tournament.name);
	},
	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 nextRow = this.elementLine.parentNode.rows[rowIndex+ this.rowCount + 1];
	
			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;
			var defaultBetTypeLength = this.rowCount+1;
			
			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+defaultBetTypeLength];
					betType.insertIntoDOM(nextRow, true);
					break;
				} else {
					if (betType.typeId == this.tournament.defaultOutcomeType.betTypeId && betType.scopeId == this.tournament.defaultOutcomeType.scopeId) {
						
					} else {
						nrOfRows += (betType.betTypeRows.length);
					}
				}
			}
		}
	},
	expandFully: function(){

		var rowIndex = this.elementLine.rowIndex ;
		var nextRow = this.elementLine.parentNode.rows[rowIndex+ this.rowCount + 1];

		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);
		}
	},
	
	sortExpandBetTypes: function(a,b){
		var aname = a.name;
		var bname = b.name;
		if(aname>=bname)return 1;
		if(aname<bname)return -1;
		//order desc
//		if(aname>=bname)return -1;
//		if(aname<bname)return 1;
	},
	showDefaultBetType: function(){

		if(betTypeIdShown!=-1 && scopeIdShown!=-1){
			if($defined(this.betTypes[betTypeIdShown])){
				if($defined(this.betTypes[betTypeIdShown][scopeIdShown]))
					return true;
			}
			else
				return false;
		}
		var rez=false;
/*		switch(this.disciplineId){
			case disciplineIds.SOCCER:
				if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.CRICKET:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.ICEHOCKEY:
				if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.BASKETBALL:
				if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId][outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.TENNIS:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.SNOOKER:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.FIGHTING:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.RUGBY_UNION:
				if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.RUGBY_LEAGUE:
				if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.ASIANHANDICAP_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.BASEBALL:
				if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId][outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.AM_FOOTBALL:
				if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.betTypeId][outcomeTypes.ASIANHANDICAP_FULLTIME_INCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.DARTS:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.GAELIC_FOOTBALL:
				if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.HANDBALL:
				if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
			case disciplineIds.VOLLEYBALL:
				if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEAWAY_FULLEVENT.betTypeId][outcomeTypes.HOMEAWAY_FULLEVENT.scopeId]))
						rez=true;
				}
			break;

			case disciplineIds.BEACH_FOOTBALL:
				if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId])){
					if($defined(this.betTypes[outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.betTypeId][outcomeTypes.HOMEDRAWAWAY_FULLTIME_EXCLUDEOVERTIME.scopeId]))
						rez=true;
				}
			break;
		}
*/		rez = true;// for temporary test
		return rez;
	},
	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);
		}
	}
});
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);
			}
		}

		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());
			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 ;i++){
				this.betTypeRows[i].remove();	
				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();
					if (this.isDefaultBetType)		
						this.match.rowCount--;
				}
				else {
					var tdOdds =this.betTypeRows[i].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
							tdOdds[j].remove();
						}
					} else if (l==5) {//for outrights bettype
						for (var k=3; k< l; k++){
							tdOdds[k].remove();
						}					
					}
				}
			}
		}
	},
	deleteBetTypeRows: function(dbParam1){
		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)
			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 ($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();
		for(var i=0 ;i<this.betTypeRows.length ;i++){
            var rows = this.betTypeRows[i];
            var isTitle = false;
            if(rows.innerHTML.indexOf('MarketH2') > 0 || rows.hasClass('matchLine'))
            	 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(this.betTypeRows[i]);
				}
			}

			this.betTypeRows[i].injectAfter(tmpNode);
			tmpNode = this.betTypeRows[i];
		}
	},
	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 dateCell=new Element('td',{'class':'dateWidth'});
		//dateCell.setHTML('<div id="MarketR2"><div>' + date+'</div></div>');//+dateCell.innerHTML

		var hourCell=new Element('td',{'class':'hourWidth','colspan':'2'});
		hourCell.setHTML('<div id="MarketR2">' +this.match.makeHourCellContent(date,hour,'1')+'</div>');

		/*var hourCell=new Element('td',{'class': 'hourWidth'});
		hourCell.setHTML('<div id="MarketR2">' +hour+'</div>');*/

		var team1Cell=new Element('td',{'class': 'teamWidth'});
		team1Cell.setHTML('<div id="MarketR2"><div style="padding-left:5px">'+ homeParticipantName+'</div></div>');
		var team2Cell=new Element('td',{'class': 'teamWidth'});
		team2Cell.setHTML('<div id="MarketR2"><div>'+ awayParticipantName+'</div></div>');


		//dateCell.injectInside(nameCell);
		hourCell.injectInside(nameCell);
		team1Cell.injectInside(nameCell);
		team2Cell.injectInside(nameCell);

		/*img.injectInside(div);
		dateDiv.injectInside(div);
		div.injectInside(dateCell);*/
		/*
		dateCell.setStyle('border-bottom','0px');
		hourCell.setStyle('border-bottom','0px');
		team1Cell.setStyle('border-bottom','0px');
		team2Cell.setStyle('border-bottom','0px');

		dateCell.injectInside(row);
		hourCell.injectInside(row);
		team1Cell.injectInside(row);
		team2Cell.injectInside(row);
		row.injectInside(tbody);
		tbody.injectInside(table);*/
		//table.injectInside(nameCell);
		if(clone)
			this.match.nameCellStandard=nameCell;
		return nameCell;
	},
	handicapCell: function(date,hour,homeParticipantName,awayParticipantName,clone){
		var nameCell=null;
		//if (isExpend){
		if(!this.isDefaultBetType){
			nameCell = new Element('tr',{'id':'R2','class':this.match.id});
		}else{
			nameCell = new Element('tr',{'class':'matchLine'});
		}
		/*var table=new Element('table',{'width': '100%'});
		var tbody=new Element('tbody');
		var row=new Element('tr');

		var img = new Element('img',{'src':'/jsp/oddsmatrix/betonbet/templates/betonbet/CalendarIcon.gif','class':'DateIcon'});*/
		var divId='MarketR1';
		if (this.handicap1X2hasNext){
		   divId = 'MarketR0';
	    }

		//var dateCell=new Element('td',{'class':'dateWidth'});
//		dateCell.setHTML('<div id="'+divId+'"><image src="/jsp/oddsmatrix/betonbet/templates/betonbet/CalendarIcon.gif" ' +' class="DateIcon">' +'<span>'+date +'</span></div>');
		//img.injectInside(dateCell);
		//dateCell.setHTML(this.addCssToTeam(date));
		var hourCell=new Element('td',{'class': 'hourWidth','colspan':'2'});
		hourCell.setHTML(this.addCssToTeam(this.match.makeHourCellContent(date, hour,'1')));

		var team1Cell=new Element('td',{'class': 'teamWidth'});
		//team1Cell.setStyle("padding-left","5px");//team1Cell.setHTML('<div id="MarketR2"><div style="padding-left:5px">'+ homeParticipantName+'</div></div>');

		team1Cell.setHTML(this.addCssToTeam1(homeParticipantName));
		var team2Cell=new Element('td',{'class': 'teamWidth'});
		team2Cell.setHTML(this.addCssToTeam(awayParticipantName));

		//dateCell.injectInside(nameCell);
		hourCell.injectInside(nameCell);
		team1Cell.injectInside(nameCell);
		team2Cell.injectInside(nameCell);

		/*dateCell.injectInside(row);
		hourCell.injectInside(row);
		team1Cell.injectInside(row);
		team2Cell.injectInside(row);
		row.injectInside(tbody);
		tbody.injectInside(table);
		table.injectInside(nameCell);*/
//		if(clone)
//			this.match.nameCellStandard=nameCell;
		return nameCell;
	},

	sortCorrectScoreText: function(a,b){
		var aInf=a.split('-');
		var adP=parseFloat(aInf[0]);var adP2=parseFloat(aInf[1]);
		var bInf=b.split('-');
		var bdP=parseFloat(bInf[0]);var bdP2=parseFloat(bInf[1]);
		return this.CSSorter(adP,adP2,bdP,bdP2);
	} ,
	sortCorrectScore: function(a,b){
		var aInf=this.extraOutcomeInfo.get(a.id);
		var aintParam=aInf.integerParameter;
		var adP=aInf.doubleParameter;
		var adP2=aInf.doubleParameter2;
		if(aintParam==this.match.awayParticipantId)
		{
			adP=aInf.doubleParameter2;
			adP2=aInf.doubleParameter;
		}
		var bInf=this.extraOutcomeInfo.get(b.id);
		var bintParam=aInf.integerParameter;
		var bdP=bInf.doubleParameter;
		var bdP2=bInf.doubleParameter2;
		if(bintParam==this.match.awayParticipantId)
		{
			bdP=bInf.doubleParameter2;
			bdP2=bInf.doubleParameter;
		}
		return this.CSSorter(adP,adP2,bdP,bdP2);
	},
	CSSorter: function(adP,adP2,bdP,bdP2){
		if(this.csSortType==2){
			if(adP+adP2<bdP+bdP2)
				return -1;
			if(adP+adP2==bdP+bdP2)
				return 0;
			if(adP+adP2>bdP+bdP2)
				return 1;
		}
		if(this.csSortType==1){
			if(adP<bdP)
				return -1;
			if(adP>bdP)
				return 1;
			if(adP==bdP){
				if(adP+adP2<bdP+bdP2)
					return -1;
				if(adP+adP2==bdP+bdP2)
					return 0;
				if(adP+adP2>bdP+bdP2)
					return 1;
			}
		}
		if(this.csSortType==3){
			if(adP2<bdP2)
				return -1;
			if(adP2>bdP2)
				return 1;
			if(adP2==bdP2){
				if(adP+adP2<bdP+bdP2)
					return -1;
				if(adP+adP2==bdP+bdP2)
					return 0;
				if(adP+adP2>bdP+bdP2)
					return 1;
			}
		}
	},
	//------wolf add sort for nubmer of goals------
	getGoalsText: function (parms)	{

		var adP;var adP2;
		var parm = parms.toString();
		if(parm.indexOf(' or less')>0)
		{
			adP=longNULL;
			adP2 = parm.substring(0,parm.indexOf(' or less'));
		}
		else if(parm.indexOf(' or more')>=0)
		{
			adP2=longNULL;
			adP = parm.substring(0,parm.indexOf(' or more'));
		}
		else if(parm.indexOf(' to ')>=0 )
		{
			parm = parm.substring(0,parm.indexOf(' goal'));
			var aInf=parm.split(' to ');
			adP=parseFloat(aInf[0]);adP2=parseFloat(aInf[1]);
		}
		else{
			parm = parm.substring(0,parm.indexOf(' goal'));
			adP = parm; adP2 = parm;
		}

		return adP+'@'+adP2;
	},
	sortNubmerofGoalsText: function(a,b){

		var adP;var adP2;var bdP;var bdP2;
		var adPs = this.getGoalsText(a).split('@');
		var bdPs = this.getGoalsText(b).split('@');
		adP = parseFloat(adPs[0]);adP2 = parseFloat(adPs[1]);
		bdP = parseFloat(bdPs[0]);bdP2 = parseFloat(bdPs[1]);

		return this.NOGSorter(adP,adP2,bdP,bdP2);
	} ,
	sortNubmerofGoals: function(a,b){
		var aInf=this.extraOutcomeInfo.get(a.id);
		var adP=aInf.integerParameter;
		var adP2=aInf.integerParameter2;
		var bInf=this.extraOutcomeInfo.get(b.id);
		var bdP=bInf.integerParameter;
		var bdP2=bInf.integerParameter2;
		return this.NOGSorter(adP,adP2,bdP,bdP2);
	},
	NOGSorter: function(adP,adP2,bdP,bdP2){
		if(adP==longNULL)
		{
			adP=adP2; adP2=-99;
		}
		if(bdP==longNULL)
		{
			bdP=bdP2; bdP2=-99;
		}
		if(adP2==longNULL) adP2=99;
		if(bdP2==longNULL) bdP2=99;
			if(adP<bdP)
				return -1;
			if(adP>bdP)
				return 1;
			if(adP==bdP){
				if(adP2<bdP2)
					return -1;
				if(adP2>bdP2)
					return 1;
			}
	},
	sortOutrights:function(array) {
			return array.sort( function(x, y) {
					if(x[1].value==1) return 1;
					if(y[1].value==1) return -1;
					return x[1].value - y[1].value; })
	},
/*	//------------sort overunder---------------
	sortOverUnderText: function(a,b){
		return this.OUSorter(a,b);
	} ,
	sortOverUnder: function(a,b){
		var aInf=this.extraOutcomeInfo.get(a.id);
		var adP=aInf.doubleParameter;
		var bInf=this.extraOutcomeInfo.get(b.id);
		var bdP=bInf.doubleParameter;
		return this.OUSorter(adP,bdP);
	},
	OUSorter: function(adP,bdP){
			if(adP<bdP)
				return -1;
			if(adP>bdP)
				return 1;
			if(adP==bdP)
				return 0;
	},
*/
	sortAsianHandicap: function(a,b){
		var aFloat = parseFloat(a);
		var bFloat = parseFloat(b);
		if(aFloat==bFloat) return 0;
		if(aFloat>bFloat) return 1;
		if(aFloat<bFloat) return -1;
	},

	addStyle:function(text){
		return '<div id="MarketH2"><div id="GameHeadline1X2"><p>'+text+'</p></div></div>';
	},

	appendOddsToTheRow: function(parentRow, override){//	alert(this.typeId);alert(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW);
		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.typeId == this.match.tournament.defaultOutcomeType.betTypeId && this.scopeId == this.match.tournament.defaultOutcomeType.scopeId) && !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 ){
				cellHeader.setProperty('colspan','8');
			} else {
				var homeCell =new Element('td',{'colspan': '1','class':'oddsCell','align': 'center'});
				var drawCell =new Element('td',{'colspan': '1','class':'oddsCell','align': 'center'});
				var awayCell =new Element('td',{'colspan': '1','class':'oddsCell','align': 'center'});
				var titleTmp = headTitle.HEADTITLE_OTHER;
				if(betTypes.TYPE_ID_HOME_DRAW_AWAY==this.typeId ||
					   betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP==this.typeId){
					titleTmp = headTitle.HEADTITLE_HOME_DRAW_AWAY;
				}else
					if(betTypes.TYPE_ID_NEXT_TEAM_TO_SCORE==this.typeId){
						titleTmp = headTitle.HEADTITLE_NEXT_TEAM_TO_SCORE;
					}else
					if(betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId ){
						titleTmp = headTitle.HEADTITLE_ODD_OR_EVEN;
					}else
					if(betTypes.TYPE_ID_OVER_UNDER==this.typeId ){						
						if (this.match.tournament.country.discipline.id==3){// just for tennis
				 			 titleTmp = headTitle.HEADTITLE_OVER_UNDER_TENNIS;}
				 	    else
				 	      titleTmp = headTitle.HEADTITLE_OVER_UNDER;
					}else
					if(betTypes.TYPE_ID_ASIAN_HANDICAP==this.typeId ||
					   betTypes.TYPE_ID_GAME_HANDICAP==this.typeId ||
					   betTypes.TYPE_ID_SET_HANDICAP==this.typeId
						){	
						titleTmp = headTitle.HEADTITLE_ASIAN_HANDICAP;					
						if (this.match.tournament.country.discipline.id==3){
							if (betTypes.TYPE_ID_GAME_HANDICAP==this.typeId){
								titleTmp = headTitle.HEADTITLE_GAME_HANDICAP_TENNIS;
							}else if (betTypes.TYPE_ID_SET_HANDICAP==this.typeId){
								titleTmp = headTitle.HEADTITLE_SET_HANDICAP_TENNIS;
							}
						}
					}else
					if(betTypes.TYPE_ID_DOUBLE_CHANCE==this.typeId
						){
						titleTmp = headTitle.HEADTITLE_DOUBLE_CHANCE;
					}
					else if(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW==this.typeId ||
						betTypes.TYPE_ID_HOME_AWAY_WITH_POSSIBLE_DRAW==this.typeId  ){				
						titleTmp = headTitle.HEADTITLE_HOME_AWAY_WITH_IMPOSSIBLE_DRAW;
					}
					//outrights
					else if(betTypes.TYPE_ID_TOP_X==this.typeId){				
						titleTmp = headTitle.getHEADTITLE_TOP_X_withParam(this.scopeId);
					}
					else if(this.typeId==betTypes.TYPE_ID_WINNER){
							titleTmp = headTitle.HEADTITLE_WINNER;
					}
					else if(this.typeId==betTypes.TYPE_ID_TOP_GOALSCORER){
							titleTmp = headTitle.HEADTITLE_TOP_GOALSCORER;
					}
					else if(this.typeId==betTypes.TYPE_ID_RELEGATION){
							titleTmp = headTitle.HEADTITLE_RELEGATION;
					}
					else if(this.typeId==betTypes.TYPE_ID_PROMOTION){
							titleTmp = headTitle.HEADTITLE_PROMOTION;
					}
					else if(this.typeId==betTypes.TYPE_ID_ROCK_BOTTOM){
							titleTmp = headTitle.HEADTITLE_ROCK_BOTTOM;
					}
					else if(this.typeId==betTypes.TYPE_ID_POLE_POSITION){
							titleTmp = headTitle.HEADTITLE_POLE_POSITION;
					}
					else if(this.typeId==betTypes.TYPE_ID_FASTEST_LAP){
							titleTmp = headTitle.HEADTITLE_FASTEST_LAP;
					}
					else if(this.typeId==betTypes.TYPE_ID_FIRST_TO_RETIRE){
							titleTmp = headTitle.HEADTITLE_FIRST_TO_RETIRE;
					}
					else if(this.typeId==betTypes.TYPE_ID_FIRST_LAP_LEADER){
							titleTmp = headTitle.HEADTITLE_FIRST_LAP_LEADER;
					}

				homeCell.setHTML(this.addStyle(titleTmp.homeText));
				drawCell.setHTML(this.addStyle(titleTmp.drawText));
				awayCell.setHTML(this.addStyle(titleTmp.awayText));
				homeCell.injectInside(betTypeHeader);
				drawCell.injectInside(betTypeHeader);
				awayCell.injectInside(betTypeHeader);
				if (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 = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
		}else{
			m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");//default value 
		}

		var dateText=''+
		(this.match.date.getDate()<10?'0'+this.match.date.getDate():this.match.date.getDate())+'.'+m_names[this.match.date.getMonth()];


		//var dateText=(this.match.date.getDate()<10?'0'+this.match.date.getDate():this.match.date.getDate())+'.'+(this.match.date.getMonth()<9?'0'+(this.match.date.getMonth()+1):(this.match.date.getMonth()+1))+'.'+this.match.date.getFullYear().toString().substring(2);
		var hourText=(this.match.date.getHours()<10?'0'+this.match.date.getHours():this.match.date.getHours())+':'+(this.match.date.getMinutes()<10?'0'+this.match.date.getMinutes():this.match.date.getMinutes());

		if(betTypes.TYPE_ID_HOME_DRAW_AWAY==this.typeId || betTypes.TYPE_ID_NEXT_TEAM_TO_SCORE==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=this.odds.get(doubleNULL).values();
				//var homeOdds=oddsValues[0];
				//var drawOdds=oddsValues[1];
				//var awayOdds=oddsValues[2];
				var homeOdds=null;
				var drawOdds=null;
				var awayOdds=null;
				//if(parentRow==null){
					for(var i=0;i<oddsValues.length;i++){
						var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
						var intParam=extraInfo.integerParameter;
						var resultid = extraInfo.resultId;
						if(resultid==1&&intParam==this.match.homeParticipantId)
							homeOdds=oddsValues[i];
						if(resultid==1&&intParam==this.match.awayParticipantId)
							awayOdds=oddsValues[i];
						if(resultid==2&&intParam==longNULL)
							drawOdds=oddsValues[i];
					}
				//}
				var cellHome=new Element('td',{'class': 'oddsCell'});
				var middleTitle = nameOfDraw;
				if (betTypes.TYPE_ID_NEXT_TEAM_TO_SCORE==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(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(this.match,args));
					drawOdds.setTopElement(cellX,args);
				}else{
					cellX.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				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(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
		if(betTypes.TYPE_ID_TOP_X==this.typeId 
			|| betTypes.TYPE_ID_WINNER==this.typeId 
			|| betTypes.TYPE_ID_TOP_GOALSCORER==this.typeId 
			|| betTypes.TYPE_ID_RELEGATION==this.typeId 
			|| betTypes.TYPE_ID_PROMOTION==this.typeId 
			|| betTypes.TYPE_ID_ROCK_BOTTOM==this.typeId 
			|| betTypes.TYPE_ID_POLE_POSITION==this.typeId 
			|| betTypes.TYPE_ID_FASTEST_LAP==this.typeId 
			|| betTypes.TYPE_ID_FIRST_TO_RETIRE==this.typeId 
			|| betTypes.TYPE_ID_FIRST_LAP_LEADER==this.typeId 
			){
				var nameCell=null;
				var betTypeRow1=null;
				if(parentRow==null){
					betTypeRow1=this.makeNameCell(dateText,hourText,this.match.name+' '+this.name,'',false);
					this.betTypeRows.push(betTypeRow1);
				} else {
					betTypeRow1 = parentRow;
					this.betTypeRows.push(betTypeRow1);
				}
				var oddsValues=[];
				var oddsValueNames=[];
				var tempArrayForSort=[];
				for(var i=0;i<this.odds.keys().length;i++){
					var ov=this.odds.get(this.odds.keys()[i]).values();
					for(var j=0;j<ov.length;j++){
						var extraInfo=this.extraOutcomeInfo.get(ov[j].id);
						var integerParameter2=extraInfo.integerParameter2;
						
						var temp = [];
						temp[0] = integerParameter2;
						temp[1] = ov[j];
						tempArrayForSort.push(temp);
					}
				}
				this.sortOutrights(tempArrayForSort);
				var divId='MarketR1';
				//if (isExpend)
				if(this.match.isExpanded)
					divId='MarketR2';
				var lastRow = parentRow;//

				//if (!isExpend)
				if(!this.match.isExpanded || this.isDefaultBetType)
					this.match.rowCount = tempArrayForSort.length - 1;	// For the expend row ,record the next row

				for(var j=0;j<tempArrayForSort.length;j++){
					var csRow=null;
					if(j==0){
						csRow=betTypeRow1;
					}else{
						if(parentRow==null){

							//if (isExpend){
							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 (isExpend){
							if(!this.isDefaultBetType){
								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','colspan':'3'});
					if($defined(tempArrayForSort[j])){
						var valueHomeValue=tempArrayForSort[j][1].value;
						homeCell.setHTML(this.addDivToText_oddsOutrights(valueHomeValue,tempArrayForSort[j][1].formattedValue,tempArrayForSort[j][0]));
						var idHomeValue=tempArrayForSort[j][1].id;						
						var formattedValueHomeValue=tempArrayForSort[j][1].formattedValue;
						var args=new Array(idHomeValue , valueHomeValue,formattedValueHomeValue,'home',outcomeName,tempArrayForSort[j][0]);
						homeCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){
							//alert('id='+id+' value='+value+' formattedValue='+formattedValue+' typeOfBet='+typeOfBet+' outcomeName='+outcomeName+' param='+param)
							this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
						tempArrayForSort[j][1].setTopElement(homeCell,args);	
					}else{
						homeCell.setHTML(this.addText_odds(this.match.getOddsCellText()));
					}

					homeCell.injectInside(csRow);
					if(j!=0){
						var emptyCell=new Element('td',{'class': 'emptyTd'});
						emptyCell.injectInside(csRow);
					}
				}
		}
		if(betTypes.TYPE_ID_CORRECT_SCORE_WITH_SCOPE==this.typeId){
				var nameCell=null;
				var betTypeRow1=null;
				if(parentRow==null){
					//betTypeRow1=new Element('tr');
					//nameCell=new Element('td',{'valign': 'top','align': 'center'});
					betTypeRow1=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
					//alert(betTypeRow1.innerHTML);
					//nameCell.injectInside(betTypeRow1);
					this.betTypeRows.push(betTypeRow1);
				} else {
					betTypeRow1 = parentRow;
					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=[];
				for(var i=0;i<oddsValues.length;i++){
					var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
					var intParam = extraInfo.integerParameter;
					var doubleParam=extraInfo.doubleParameter;
					var doubleParam2=extraInfo.doubleParameter2;

					if(intParam==this.match.homeParticipantId){
						if(doubleParam>doubleParam2){
							homeValues.push(oddsValues[i]);
							homeScoreText.push(doubleParam.toFixed(0)+'-'+doubleParam2.toFixed(0));
						}
						if(doubleParam==doubleParam2){
							drawValues.push(oddsValues[i]);
							drawScoreText.push(doubleParam.toFixed(0)+'-'+doubleParam2.toFixed(0));
						}
						if(doubleParam<doubleParam2){
							awayValues.push(oddsValues[i]);
							awayScoreText.push(doubleParam.toFixed(0)+'-'+doubleParam2.toFixed(0));
						}
					}
					if(intParam==this.match.awayParticipantId){
						if(doubleParam<doubleParam2){
							homeValues.push(oddsValues[i]);
							homeScoreText.push(doubleParam2.toFixed(0)+'-'+doubleParam.toFixed(0));
						}
						if(doubleParam==doubleParam2){
							drawValues.push(oddsValues[i]);
							drawScoreText.push(doubleParam.toFixed(0)+'-'+doubleParam2.toFixed(0));
						}
						if(doubleParam>doubleParam2){
							awayValues.push(oddsValues[i]);
							awayScoreText.push(doubleParam2.toFixed(0)+'-'+doubleParam.toFixed(0));
						}
					}
				}
				this.csSortType=1;

				homeValues.sort(this.sortCorrectScore.bind(this));
				homeScoreText.sort(this.sortCorrectScoreText.bind(this));
				this.csSortType=2;
				drawValues.sort(this.sortCorrectScore.bind(this));
				drawScoreText.sort(this.sortCorrectScoreText.bind(this));
				this.csSortType=3;
				awayValues.sort(this.sortCorrectScore.bind(this));
				awayScoreText.sort(this.sortCorrectScoreText.bind(this));
				var nrRows=homeValues.length;
				if(drawValues.length>nrRows)
					nrRows=drawValues.length;
				if(awayValues.length>nrRows)
					nrRows=awayValues.length;
				var divId='MarketR1';
				//if (isExpend)
				if(this.match.isExpanded)
					divId='MarketR2';
				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 (isExpend){
							if(!this.isDefaultBetType){
								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','style':'width:60px'});
					var homeCellParam=new Element('td',{'class': 'paramRight','style':'width:8px'});
					if($defined(homeValues[j])){
						/*homeCellParam.setHTML('<div id="'+divId+'">'+homeScoreText[j]+'</div>');
						homeCell.setHTML('<div id="'+divId+'"><div class="ButtonOddsSelectorSmallOff" onmouseover="this.className=\'ButtonOddsSelectorSmallOn\'" ' +
								'onmouseout="this.className=\'ButtonOddsSelectorSmallOff\'"><a href="#">'+homeValues[j].value.toFixed(2)+'</a></div>'+
								homeScoreText[j]+'</div>');*/
						homeCell.setHTML(this.addDivToText_oddsSmall(homeValues[j].value,homeValues[j].formattedValue,homeScoreText[j]));
						var idHomeValue=homeValues[j].id;
						var valueHomeValue=homeValues[j].value;
						var formattedValueHomeValue=homeValues[j].formattedValue;
						var args=new Array(idHomeValue , valueHomeValue,formattedValueHomeValue,'home',outcomeName,homeScoreText[j]);
						homeCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
						homeValues[j].setTopElement(homeCell,args);
					}else{
						homeCellParam.setHTML(this.addText_odds(''));
						homeCell.setHTML(this.addText_odds(this.match.getOddsCellText()));
					}

					var drawCell=new Element('td',{'class': 'oddsCell'});
					var drawCellParam=new Element('td',{'class': 'paramRight'});
					if($defined(drawValues[j])){
						/*drawCellParam.setHTML('<div id='+divId+'>'+drawScoreText[j]+'</div>');
						drawCell.setHTML('<div id='+divId+'><div class="ButtonOddsSelectorSmallOff" onmouseover="this.className=\'ButtonOddsSelectorSmallOn\'" ' +
								'onmouseout="this.className=\'ButtonOddsSelectorSmallOff\'"><a href="#">'+drawValues[j].value.toFixed(2)+
								* '</a></div>'+drawScoreText[j]+'</div>');*/
						drawCell.setHTML(this.addDivToText_oddsSmall(drawValues[j].value,drawValues[j].formattedValue,drawScoreText[j]));
						var args=new Array(drawValues[j].id , drawValues[j].value,drawValues[j].formattedValue,nameOfDraw,outcomeName,drawScoreText[j]);
						drawCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
						drawValues[j].setTopElement(drawCell,args);
					}else{
						drawCellParam.setHTML(this.addText_odds(''));
						drawCell.setHTML(this.addText_odds(this.match.getOddsCellText()));
					}
					var awayCell=new Element('td',{'class': 'oddsCell'});
					var awayCellParam=new Element('td',{'class': 'paramRight'});
					if($defined(awayValues[j])){
						/*awayCellParam.setHTML('<div id='+divId+'>'+awayScoreText[j]+'</div>');
						awayCell.setHTML('<div id='+divId+'><div class="ButtonOddsSelectorSmallOff" onmouseover="this.className=\'ButtonOddsSelectorSmallOn\'" ' +
								'onmouseout="this.className=\'ButtonOddsSelectorSmallOff\'"><a href="#">'+awayValues[j].value.toFixed(2)+'</a></div>'+awayScoreText[j]+'</div>');*/
						awayCell.setHTML(this.addDivToText_oddsSmall(awayValues[j].value,awayValues[j].formattedValue,awayScoreText[j]));
						var args=new Array(awayValues[j].id , awayValues[j].value,awayValues[j].formattedValue,'away',outcomeName,awayScoreText[j]);
						awayCell.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
						awayValues[j].setTopElement(awayCell,args);
					}else{
						awayCellParam.setHTML(this.addText_odds(''));
						awayCell.setHTML(this.addText_odds(this.match.getOddsCellText()));
					}
					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.injectInside(csRow);
					}
				}
		}
		if(betTypes.TYPE_ID_NUMBER_OF_GOALS==this.typeId ){
				var nameCell=null;
				var betTypeRow1=null;
				if(parentRow==null){
					//betTypeRow1=new Element('tr');
					//nameCell=new Element('td',{'valign': 'top','align': 'center'});
					betTypeRow1=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
					//nameCell.injectInside(betTypeRow1);
				} 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(this));
				homeScoreText.sort(this.sortNubmerofGoalsText.bind(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 (isExpend){
							if(!this.isDefaultBetType){
								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(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);
				}
		}
		if(betTypes.TYPE_ID_DOUBLE_CHANCE ==this.typeId ){
				var nameCell=null;
				var betTypeRow1=null;
				var lastRow = parentRow;
				if(parentRow==null){
					//betTypeRow1=new Element('tr');
					//nameCell=new Element('td',{'valign': 'top','align': 'center'});
					betTypeRow1=this.makeNameCell(dateText,hourText,this.match.homeParticipantName,this.match.awayParticipantName,false);
					//nameCell.injectInside(betTypeRow1);
					this.betTypeRows.push(betTypeRow1);
				} else {
					if(parentRow.getChildren('td').length<3){
							betTypeRow1 = parentRow;
					}
					else {betTypeRow1 = parentRow;
						//betTypeRow1=new Element('tr',{'class': 'matchLine'});
						//var emptyCell=new Element('td',{'colspan':'4'});
						//emptyCell.setHTML(addText_odds('&nbsp;'));
						//emptyCell.injectInside(betTypeRow1);

						//var tbody=parentRow.getParent();
						//var matchRows=tbody.getElements('tr.matchLine');
						//betTypeRow1.injectAfter(lastRow);
						//lastRow = betTypeRow1;
						//lastRow =
					}
					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(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(this.match,args));
					oddsValuesReordered[2].setTopElement(cellx2,args);
				}else{
					cellx2.setHTML(this.addText_odds(this.match.getOddsCellText()));
					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(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);
		}
		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 (isExpend){
					if(!this.isDefaultBetType){
						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(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(this.match,args));
					oddsValuesReordered[1].setTopElement(cellx1,args);
				}else{
					cellx1.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				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(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(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(this.match,args));
					oddsValuesReordered[4].setTopElement(cellxx,args);
				}else{
					cellxx.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				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(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(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(this.match,args));
					oddsValuesReordered[7].setTopElement(cellx2,args);
				}else{
					cellx2.setHTML(this.addText_odds(this.match.getOddsCellText()));
				}
				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(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);	
				}			
		}
		if(betTypes.TYPE_ID_HOME_AWAY_WITH_IMPOSSIBLE_DRAW==this.typeId || betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId  ||
					betTypes.TYPE_ID_HOME_AWAY_WITH_POSSIBLE_DRAW==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=this.odds.get(doubleNULL).values();
				//--------wolf modify---------------------
				var homeOdds=null;
				var awayOdds=null;
				for(var i=0;i<oddsValues.length;i++){
					var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
					var intParam=extraInfo.integerParameter;
					if(intParam==this.match.homeParticipantId||5==extraInfo.resultId)
						homeOdds=oddsValues[i];
					if(intParam==this.match.awayParticipantId||6==extraInfo.resultId)
						awayOdds=oddsValues[i];
				}

//				alert(homeOdds.value+"----"+awayOdds.value);
				//var groupCell=new Element('td');
				//nameCell.appendText(' '+this.doubleParameter);
				//groupCell.injectInside(this.betTypeRow);
				var cellHome=new Element('td');
				//cssDiv.addEvent('onmouseover',function(this){this.className='ButtonOddsSelectorLargeOn';}.bind(this.match,args));
				if($defined(homeOdds)){
					cellHome.setHTML(this.addDivToText_odds(homeOdds.value,homeOdds.formattedValue));
					var args=new Array(homeOdds.id , homeOdds.value,homeOdds.formattedValue,'home',outcomeName,betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId ?nameOfOdd:homeParticipantName);
					cellHome.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					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,'away',outcomeName,betTypes.TYPE_ID_ODD_OR_EVEN==this.typeId ?nameOfEven:awayParticipantName);
					cellAway.addEvent('click',function(id,value,formattedValue,typeOfBet,outcomeName,param){this.addToBetSlip(id,value,formattedValue,typeOfBet,outcomeName,param);}.bind(this.match,args));
					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);
		}
		if(betTypes.TYPE_ID_OVER_UNDER==this.typeId ){
				//var groupCell=new Element('td');
				var parameters=this.odds.keys();
				var overValues=[];var OUText=[];
				var underValues=[];
				var lastRow=parentRow;
				parameters.sort(this.sortAsianHandicap);
				for(var k=0;k<parameters.length;k++){

					var oddsValues=this.odds.get(parameters[k]).values();
					//---wolf modify--------

					var homeOdds=null;
					var awayOdds=null;
					for(var j=0;j<oddsValues.length;j++){
						var extraInfo=this.extraOutcomeInfo.get(oddsValues[j].id);
						if(3==extraInfo.resultId){
							homeOdds=oddsValues[j];
							overValues.push(homeOdds);
						}
						if(4==extraInfo.resultId){
							awayOdds=oddsValues[j];
							underValues.push(awayOdds);
						}
					}
					OUText.push(parameters[k]);
/*				}
				overValues.sort(this.sortOverUnder.bind(this));
				OUText.sort(this.sortOverUnderText.bind(this));
				underValues.sort(this.sortOverUnder.bind(this));

				var nrRows=overValues.length;
				if(nrRows<underValues.length)
					nrRows = underValues.length;
				for(var k=0;k<nrRows;k++){
*/
					var nameCell=null;
					var betTypeRow=null;

					if(parentRow==null){
						//if(isExpend)
						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 {
							betTypeRow=new Element('tr',{'class': 'matchLine'});
							var emptyCell=new Element('td',{'colspan':'4'});
							emptyCell.setHTML('&nbsp;');
							emptyCell.injectInside(betTypeRow);
							var tbody=parentRow.getParent();
							var matchRows=tbody.getElements('tr.matchLine');
							betTypeRow.injectAfter(lastRow);
							//var matchCell=parentRow.getElement('td.invisibleHolder');
							//matchCell.setProperty('rowspan',parseInt(matchCell.getProperty('rowspan'))+1);
						}
						lastRow = betTypeRow;
					}
					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(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(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 (!isExpend)
				if(!this.match.isExpanded || this.isDefaultBetType)
				 this.match.rowCount--;
		}
		if( betTypes.TYPE_ID_ASIAN_HANDICAP==this.typeId ||betTypes.TYPE_ID_GAME_HANDICAP==this.typeId  ||betTypes.TYPE_ID_SET_HANDICAP==this.typeId ){
				//var groupCell=new Element('td');
				var parameters=this.odds.keys();
				var lastRow=parentRow;
				parameters.sort(this.sortAsianHandicap);

				for(var k=0;k<parameters.length;k++){
					var nameCell=null;
					var betTypeRow=null;

					if(parentRow==null){
						//if(isExpend)
						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(k==0)
							betTypeRow = parentRow;
						else {
							betTypeRow=new Element('tr',{'class': 'matchLine'});
							var emptyCell=new Element('td',{'colspan':'4'});
							emptyCell.setHTML('&nbsp;');
							emptyCell.injectInside(betTypeRow);
							var tbody=parentRow.getParent();
							var matchRows=tbody.getElements('tr.matchLine');
							betTypeRow.injectAfter(lastRow);
							//var matchCell=parentRow.getElement('td.invisibleHolder');
							//matchCell.setProperty('rowspan',parseInt(matchCell.getProperty('rowspan'))+1);
						}
						lastRow = betTypeRow;
					}
					this.betTypeRows.push(betTypeRow);
					var oddsValues=this.odds.get(parameters[k]).values();
					//---wolf modify--------	if home is without -, then show like 0.50,if home is with -, then show like -0.50


					var homeOdds=null;
					var awayOdds=null;
					for(var i=0;i<oddsValues.length;i++){
						var extraInfo=this.extraOutcomeInfo.get(oddsValues[i].id);
						var intParam=extraInfo.integerParameter;
						if(intParam==this.match.homeParticipantId)
							homeOdds=oddsValues[i];
						if(intParam==this.match.awayParticipantId)
							awayOdds=oddsValues[i];

					}
					//nameCell.appendText(' '+parameters[k]);
					//groupCell.injectInside(this.betTypeRow);
					var cellHome=new Element('td');
					if($defined(homeOdds)){
						cellHome.setHTML(this.addDivToText_odds(homeOdds.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(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(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 (!isExpend)
					if(!this.match.isExpanded || this.isDefaultBetType)
					 this.match.rowCount++;
				}
				//if (!isExpend)
				if(!this.match.isExpanded || this.isDefaultBetType)
				 this.match.rowCount--;
		}
		if(betTypes.TYPE_ID_HOME_DRAW_AWAY_WITH_HANDICAP==this.typeId ){
				//var groupCell=new Element('td');
				var parameters=this.odds.keys();

				if(parameters.length>1)
				this.handicap1X2hasNext =true;
				var lastRow=parentRow;
				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]);
					}
					if(parentRow==null){
						//if(isExpend){
						if(this.match.isExpanded){
							betTypeRow=new Element('tr',{'id':'R2','class':this.match.id});
						}else{
							betTypeRow=new Element('tr');
						}

						//nameCell=new Element('td',{'align': 'center'});
						betTypeRow=this.handicapCell(dateText,hourText,'<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)));

							var divId='MarketR1';
							if (this.handicap1X2hasNext){
							   divId = 'MarketR0';
						    }
							//dateCel.setHTML(this.addCssToTeam(dateText + dateTimeLine+hourText));
						}
						else {
							betTypeRow=null;
							//nameCell=new Element('td');
							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];
					}
					//nameCell.appendText(' '+parameters[k]);
					//groupCell.injectInside(this.betTypeRow);
					var cellHome=new Element('td',{'class':'oddsCell'});
					if($defined(oddsValuesReordered[0])){
						cellHome.setHTML(this.addDivToText_odds(oddsValuesReordered[0].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(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(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(this.match,args));
						oddsValuesReordered[2].setTopElement(cellAway,args);
					}else{
						cellAway.setHTML(this.addText_odds(''));
					}
					cellHome.injectInside(betTypeRow);
					cellX.injectInside(betTypeRow);
					cellAway.injectInside(betTypeRow);
					//if (!isExpend)
					if(!this.match.isExpanded || this.isDefaultBetType)
					 this.match.rowCount++;
				}
				//if (!isExpend)
				if(!this.match.isExpanded || this.isDefaultBetType) 
					this.match.rowCount--;
		}

		//alert(betTypeRow.innerHTML);
	},

	 addDivToText_odds:function(value,text){
		var divId='MarketR1';
		if (!this.isDefaultBetType){
			divId='MarketR2';
		}else {
			if (this.handicap1X2hasNext){
			   divId = 'MarketR0';
		    }
		}
		if(value!=null&&value<minOddsNum){
			return '<div id="'+divId+'" ><div style="text-align: center"><a href="javascript:void(0);" style="cursor:default;text-decoration:none;color:black;">'+emptyOddsTxt
						                 +'</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='MarketR1';
		if (isExpend)divId='MarketR2';
		if(value!=null&&value<minOddsNum){
			return '<div id="'+divId+'" style="overflow-x:hidden;"><div style="text-align: center"><a href="javascript:void(0);" style="cursor:default;text-decoration:none;color:black;">'+emptyOddsTxt
						                 +'</a></div></div>';
		}else{
			if(value!=null&&value==1) text="NR";
			return '<div id="'+divId+'" 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 style="float:left" class="TextOddsSmall">'+param+'</div></div>';
		}
	},
	
	addDivToText_oddsSmall:function(value,text,param){
		var divId='MarketR1';
		if (!this.isDefaultBetType)
			divId='MarketR2';
		if(value!=null&&value<minOddsNum){
			return '<div id="'+divId+'" style="overflow-x:hidden;"><div style="text-align: center"><a href="javascript:void(0);" style="cursor:default;text-decoration:none;color:black;">'+emptyOddsTxt
						                 +'</a></div></div>';
		}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 style="float:left">'+param+'</div></div>';
		}		
	},

	 addDivToText_odds_withParam:function(text,param){
		var divId='MarketR1';
		if (!this.isDefaultBetType)
			divId='MarketR2';
		if(value!=null&&value<minOddsNum){
			return '<div id="'+divId+'" style="overflow-x:hidden;"><div style="text-align: center"><a href="javascript:void(0);" style="cursor:default;text-decoration:none;color:black;">'+emptyOddsTxt
					                 +'</a></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='MarketR1';
		if (!this.isDefaultBetType)
		  divId='MarketR2';
		else
		   return text;
		return '<div id="'+divId+'">&nbsp;</div>';
	},
	
	addText_odds:function(text){
		var divId='MarketR1';
		if (!this.isDefaultBetType)
		  divId='MarketR2'
		else
		   return text;
		return '<div id="'+divId+'"><div align="center">'+text+'</div></div>';
	},
	
	addCssToTeam:function(text){
		var divId='MarketR1';
		if (this.match.isExpanded){
			divId='MarketR2';
			return '<div id="'+divId+'">'+ text+'</div>';
		}else {
			if (this.handicap1X2hasNext){
			   divId = 'MarketR0';
		    }
		}
		return text;
	},
	 addCssToTeam1:function(text){
			var divId='MarketR1';
			if (this.match.isExpanded){
				divId='MarketR2';
				return '<div id="'+divId+'"><div style="padding-left:5px">'+ text+'</div></div>';
			}else {
				if (this.handicap1X2hasNext){
				   divId = 'MarketR0';
			    }
			}
			return text;
	},
	addDivToText_title:function(text){

	}
});

var Odds = CategElement.extend ({
	initialize: function(id,oddsValue, formattedValue ){
		this.parent(id); // the id here is actually the outcomeId
		this.value=oddsValue;
		this.formattedValue = formattedValue;
		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(oddsValue!==null&&oddsValue<minOddsNum){
			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','black');
			this.htmlElement.setHTML(emptyOddsTxt);	
		}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 = 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(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){
	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();
	//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){
	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(match),
		               onFailure: function(){processFailure();}});
		ajaxReq.send('/expandedMatch.do','action=expand&id='+currentExpandedMatch.id+'&discId='+match.disciplineId+'&x='+(Math.random()*100)+'&isOutrights='+isOutrights);
		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);
}

//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(urlStatus == 'oddstable'||urlStatus == 'bannerEvent') {
			obj.innerHTML = text_yourSelection;
		}
		else
			obj.innerHTML = text_popularMatch;
	}
}

function chgHeadPicToPopular()
{
	var obj = document.getElementById("headpic");
	if( obj != null ){
		obj.innerHTML = text_popularMatch;
	}
}

function chgHeadPicToSearchResult(searchedName){
	
	var obj = document.getElementById("headpic");
	if( obj != null ){
		obj.innerHTML = text_searchResult + " " +document.getElementById('searchedName').value;
	}
}

/**
 * clear the value of html input
 */
function clearValue(obj) {
	
	if(obj != null)
		obj.value = "";
}

/**
 * fill the input box with some tips.
 */
function fillValue(obj) {
	
	if(obj != null && searchedName.length >1)
		obj.value = searchedName;
}

/**
 * reset the value of searchedName to ""
 * and reset the value searchedName input box
 */
function resetValueOfSearchedName() {
	
	if(searchedName.length > 0) {
		searchedName = "";
		document.getElementById("searchedName").value = text_searchTEP;
	}
}

/**
 * when press Enter key in searched name box
 */
function searchedNameKeyDown(event) {
	//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(window.ie){
		$("fbtBody").removeNode(true);
	}else {
		filterTable.empty();//alert(filterTable.innerHTML);
	}
	
	var tbody=new Element('tbody',{'id':'fbtBody'});

	if(betTypeIdShown==-1 && scopeIdShown==-1){
		defaultFilters = filters;
		defaultFiltersForOutrights = filtersForOutrights;
	}else{
		filters= defaultFilters;//		bettypes= defaultFilters.keys();
		//defaultFiltersKey = filters.keys();
		filtersForOutrights = defaultFiltersForOutrights;
	}
	if (filters.length>0)
		presentFiltersSub(false,filters,tbody);
	if (filtersForOutrights.length>0)
		presentFiltersSub(true,filtersForOutrights,tbody);
	
	tbody.injectInside(filterTable);
	
	if (filters.length>0)
		expandableFilter(false);
	if (filtersForOutrights.length>0)
		expandableFilter(true);
}

function presentFiltersSub(isOutrightsFilter,filtersData,tbody) {	
	var currentRow=new Element('tr',{'id':'filterRow_'+isOutrightsFilter});
	var cell=new Element('td',{'width':'100%','id':'filterTd_'+isOutrightsFilter});
	var divCss = new Element ('div',{'id':'MarketSelectionOff'});
	var filterLink=new Element('a',{'href': '#','filterValue': 'all,'+isOutrightsFilter,'events': {'click': function(){applyFilter(this);}}});
	filterLink.injectInside(divCss);
	divCss.injectInside(cell);
	
	if(betTypeIdShown==-1 && scopeIdShown==-1 && isOutrightsFilter==isOutrights){
		divCss.setProperty('id','MarketSelectionOn');
		selectedFilter=filterLink;
		_betTypeParam = "";
		filterLink.id='defaultFilter';
	}
	
	var bettypes=filtersData.keys();
	filterLink.setText(defautFilter);//' Default '

	var keyAndvalueArray = [] ;
	for(var i=0;i<bettypes.length ;i++){
		var value = filtersData.get(bettypes[i]);
		if(value.indexOf(',')<0)
			keyAndvalueArray.push(filtersData.get(bettypes[i])+' @'+bettypes[i]);
		else
			keyAndvalueArray.push(filtersData.get(bettypes[i])+'@'+bettypes[i]);
	}

	keyAndvalueArray.sort();
	for(var i=0;i<keyAndvalueArray.length ;i++){ //+1
		var vauleAndKey = keyAndvalueArray[i].split('@');
		var divCss = new Element('div',{'id':'MarketSelectionOff'});
		filterLink=new Element('a',{'href': '#','filterValue': vauleAndKey[1],'events': {'click': function(){applyFilter(this);}}});
		filterLink.injectInside(divCss);
		if(vauleAndKey[1]==betTypeIdShown+','+scopeIdShown){
			divCss.setProperty('id','MarketSelectionOn');
			selectedFilter=filterLink;
			filterLink.id='defaultFilter';
		}

		filterLink.setText(' '+vauleAndKey[0]+' ');
		divCss.injectInside(cell);

	}	
	
	if (!isOutrightsFilter){
		var timeF = new Element('div',{'id':'MarketSelectionOff','overflow':'30'});
		timeF.innerHTML = $("timeFTable").innerHTML;
		timeF.injectInside(cell);
	}
	
	cell.injectInside(currentRow);
	currentRow.injectInside(tbody);
	var td = new Element('td',{'class':'expandableFilter','id':'expander_'+isOutrightsFilter});
	td.setText("+00");
	td.injectInside(currentRow);	
	//currentRow.style.display="none";
}
function expandableFilter(isOutrightsFilter) {
	var tdWidth = $('filterTd_'+isOutrightsFilter).offsetWidth;
	var filterWidth = $('defaultFilter').offsetWidth;
	var oddsTableWidth = $('oddstable').offsetWidth;
	
	var expandFlag = false;
	var currentRow = $('filterRow_'+isOutrightsFilter);
	var filtersNum = currentRow.getChildren()[0].getChildren().length;
	var currentNumOfDivPerRow = Math.floor(tdWidth/filterWidth);
	if (isNaN(currentNumOfDivPerRow))
		currentNumOfDivPerRow = numOfDivPerRow;
	if (filtersNum > currentNumOfDivPerRow) {
		var currentRow2 = currentRow.clone();
		currentRow2.id = 'filterRowSingle_'+isOutrightsFilter;
		var children = currentRow2.getChildren()[0].getChildren();
		
		if(!window.ie){
			for (var i=0;i<currentNumOfDivPerRow;i++) {		
				children[i].getChildren()[0].addEvent('click',function(){applyFilter(this);});
			}
		}
		
		for (var i=currentNumOfDivPerRow;i<filtersNum;i++) {
			if (children[i].id == 'MarketSelectionOn')
				expandFlag = true;
	        children[i].remove();
		}
		//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;
	
	if(searchedName_0.length >=3 && searchedName_0.length <= 15) {
		
		searchedName = searchedName_0;
		
		//show pic to hint player to wait a moment
		var dom = document.getElementById("div_loadPicTabForPopular");
		if (!$defined(dom)){
			return;
		}
		dom.style.display = "block";
		
		param += 'searchedName='+ searchedName;
		var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
	                         onSuccess: function(response){ 
	                         	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)
{
	
	//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; 
                         	fillOddsTable(response);
                         	urlStatus = 'bannerEvent';
                         	changeHeadPic();
                         },
                         onFailure: function(){processFailure();}});
		ajaxReq.send('/bannerEvent.do',param);
		ajaxReq=null;
}

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'){
		setParam += value;
	}else{
		setParam = "&oddsFormat="+value;
	}
	$("div_loadPicTab").style.display = "block";
	filters = new Hash(); 	//very important ,must be create an new object
	var ajaxReq=new XHR({'method': 'post','autoCancel': 'true',
	                 onSuccess: function(response){
	                 	    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 setDefaultStatus() {
	$('singleBetTypeTd').innerHTML='';
	var idstr='MarketSelectionOff';
	if ($('filterBetType')) {
		if ($('MarketSelectionOn').innerHTML.search(defautFilter)>0) {
			idstr='MarketSelectionOn';
		}  
	}
	var divCss = new Element ('div',{'id':idstr});
	var filterLink=new Element('a',{'href': '#','filterValue': 'all','events': {'click': function(){applyFilter(this);}}});
	filterLink.injectInside(divCss);
	filterLink.setText(defautFilter);
	divCss.injectInside($('singleBetTypeTd'));
	return;
}
/**--end betting type tab event --**/

