var BLOCKED=IMAGEPATH+"gesperrt.gif";
var IMAGETAG="&nbsp;";
var INPUTTAG1="";
var INPUTTAG2="";
var INPUTTAG3="";

var ASCENDING='<';
var DESCENDING='>';

var GAMEPLAYABLE='0';
var GAMEBLOCKED='1';
var GAMENOTPLAYABLE='2';
var JAVASCRIPTCORRECTION=0.00000001;
var betCount=0; 

var currentOpenBet=-1;


function setCurrentOpenBet(betNumber) {
	if(currentOpenBet==betNumber) {
		currentOpenBet=-1;
	} else {
		currentOpenBet=betNumber;
	}
}

	function createTipps(tipp_quotesArray) {
		if((tipp_quotesArray==undefined)||(tipp_quotesArray==null))
			return;

		var newTipp=null;
		for(a=0;a<tipp_quotesArray.length;a++) {
			if(newTipp==null) {
				newTipp=new BetTopTipp(tipp_quotesArray[a++],tipp_quotesArray[a++],tipp_quotesArray[a++],tipp_quotesArray[a++],tipp_quotesArray[a++],tipp_quotesArray[a]);
			} else {
				var aTipp=new BetTopTipp(tipp_quotesArray[a++],tipp_quotesArray[a++],tipp_quotesArray[a++],tipp_quotesArray[a++],tipp_quotesArray[a++],tipp_quotesArray[a]);
				newTipp.addTipp(aTipp);
			}
		}
		return newTipp;	
	}

//------------------------------------
// open = 1, closed=0
// num:		gamenumber
// anEvent:	event code letter
// gDate:	gamedate
// gTime:	game time
// liga:	liga name
// betEvent:	text of the bet (for example the teamnames)
// betType:	Torwette,Resultatwette...
// result:	it is the result 1:0,2:1 etc.
// title:	title of that bet
// text: 	text to that bet
// array:	an array with the tipps,quotes and set/not set (1...set,0...not set), up to 36
// information:	information text below the tipps and quotes
//----------------------------------------------------------------------------------------------------------------------------------------------
// open=1/closed=0,gamenumber,event,enddate,endtime,liga,betevent,bettype,result,title,text,array with tipps and quotes,informationtext,betId,score24Detail,scoreInfo,status, leagueHasLink, classic_betid
//--------------------------------------------------------------------------------------------------------------------------------------
// score info is for live scoring and there is no tipp-field in that layout
//--------------------------------------------------------------------------
function BetTop(opened,num,anEvent,gDate,gTime,liga,betEvent,betType,result,title,text,tipp_quotes_array,information,betId,score24Detail,scoreInfo,shortDescription,status, leagueHasLink, classicBetId) {
	this.opened=opened;
	this.gameNumber=num;
	this.eventCode=anEvent;
	this.gameDate=gDate;
	this.gameTime=gTime;
	this.league=liga;
	this.betEvent=betEvent;
	this.betType=betType;
	this.result=result;
	this.title=title;
	this.text=text;	
	this.tipp=createTipps(tipp_quotes_array);

	this.information=information;
	this.betId=betId;
	this.score24Detail=score24Detail;
	this.scoreInfo=scoreInfo;
	this.shortDescription=shortDescription;
	this.status=status;
	this.winningTippId=-1;
	this.nextTopBet=null;
	this.newer=true;
	this.leagueHasLink = leagueHasLink;
	this.classicBetId = classicBetId;
	this.addBet=addBet;
	this.getGameNumber=getGameNumber;
	this.getGameDate=getGameDate;
	this.getGameTime=getGameTime;
	this.setGameDate=setGameDate;
	this.setGameTime=setGameTime;
	this.getLeagueName=getLeagueName;
	this.getTippBox=getTippBox;
	this.getResult=getResult;
	this.setResult=setResult;
	this.getNextTopBet=getNextTopBet;
	this.setNextTopBet=setNextTopBet;
	this.displayAllTopBets=displayAllTopBets;
	this.displayTopBet=displayTopBet;
	this.getTopBetType=getTopBetType;
	this.getQuote=getQuote;
	this.setTipp=setTipp;
	this.getTipp=getTipp;
	this.getTippBoxString=getTippBoxString
	this.setTippBox=setTippBox;
	this.getTippBox=getTippBox;	
	this.getTopBetByNumber=getTopBetByNumber;
	this.getTopBetById=getTopBetById;
	this.setBetStatus=setBetStatus;
	this.getBetStatus=getBetStatus;
	this.checkTippById=checkTippById;
	this.getParams=getParams;
	this.getTippId=getTippId;	
	this.getTippBoxById=getTippBoxById;
	this.getQuoteById=getQuoteById;
	this.setQuoteById=setQuoteById;
	this.setWinningTipp=setWinningTipp;
	this.getStatusByTipp=getStatusByTipp;
	this.getTippNumberByTippId=getTippNumberByTippId;
	this.setStatusByTipp=setStatusByTipp;
	this.setStatusById=setStatusById;
	this.getStatusById=getStatusById;
	this.getTippByTippId=getTippByTippId;
	this.createTopBet=createTopBet;
	this.getBlockImg=getBlockImg;
	this.checkOpened=checkOpened;
	this.getClassicBetId=getClassicBetId;
	this.setClassicBetId=setClassicBetId;

	this.updateTopBet=function(topBet) {
		var aTopBet = this.getTopBetByNumber(topBet.gameNumber);		
		if(aTopBet!=null) {
			aTopBet.opened=topBet.opened;
			aTopBet.gameNumber=topBet.gameNumber;
			aTopBet.eventCode=topBet.getEventCode();
			aTopBet.gameDate=topBet.getGameDate();
			aTopBet.gameTime=topBet.getGameTime();
			aTopBet.league=topBet.getLeagueName();
			aTopBet.betEvent=topBet.getBetEvent();
			aTopBet.classicBetId=topBet.getClassicBetId();
			aTopBet.tipp=topBet.tipp;
			aTopBet.betMoneyArray=topBet.betMoneyArray;
			aTopBet.scoreInfo=topBet.scoreInfo;
			aTopBet.score24Detail=topBet.score24Detail;
			aTopBet.result=topBet.result;
			aTopBet.text=topBet.text;
			aTopBet.information=topBet.information;	
			aTopBet.betType=topBet.betType;
			aTopBet.title=topBet.title;
			aTopBet.betId=topBet.betId;
			aTopBet.shortDescription=topBet.shortDescription;
			aTopBet.status=topBet.status;
			aTopBet.winningTippId=topBet.winningTippId;
						
		}
		return this;
	}
	
	this.createTopBet=function(bet) {
		//			opened,    num,             anEvent,       gDate,      gTime,      liga,      betEvent,    betType,     result,   title,     text,    tipp_quotes_array,   information,   betId,     score24Detail,    scoreInfo,    shortDescription,   status
		var aBet=new BetTop(bet.opened,bet.gameNumber,bet.eventCode,bet.gameDate,bet.gameTime,bet.league,bet.betEvent,bet.betType,bet.result,bet.title,bet.text,null,bet.information,bet.betId,bet.score24Detail,bet.scoreInfo,bet.shortDescription,bet.status, bet.leagueHasLink, bet.classicBetId);
		aBet.tipp=bet.tipp;
		aBet.winningTippId=bet.winningTippId;
		return aBet;
	}
		
	this.deleteSubBet=function(tipp) {
		return this.setTippBox(tipp);
	}	

	this.deleteTopBet=function(num) {
		if(this.gameNumber==num) {
			if(this.getNextTopBet()!=null) {
				return this.getNextTopBet();		
			} else {
				return null;
			}
		}
		var actTopBet=this;
		var oldTopBet=null;
	        while(actTopBet != null) {
			if(actTopBet.gameNumber==num) {
				oldTopBet.setNextTopBet(actTopBet.getNextTopBet());
			}
			oldTopBet=actTopBet;
	            	actTopBet=actTopBet.getNextTopBet();
	        }
	        return this;		
	}

	// POK
	this.getShortDescription=function() {
		return this.shortDescription;
	}

	this.getGameNumber=function() {
		return this.gameNumber;
	}
	
	this.getClassicBetId=function() {
		return this.classicBetId;
	}

	this.setWinningTipp=function(tippId) {
		if(this.winningTippId==-1) {
			this.winningTippId=tippId;
		} else {

			var winningTipIdString=this.winningTippId+'';
			var winArray=winningTipIdString.split(',');
			var alreadyGot=false;
			for(var w=0;w<winArray.length;w++) {
				if(winArray[w]==tippId) {
					alreadyGot=true;
				}
			}
			if(!alreadyGot) {
				this.winningTippId=this.winningTippId+','+tippId;
			}
		}
	}	

	this.isOpened=function() {
		return this.opened;
	}

	this.getBetEvent=function() {
		return this.betEvent;
	}	

	this.getEventCode=function() {
		return this.eventCode;
	}	

	this.getGameDate=function() {		
		return this.gameDate;
	}

	this.setGameDate=function(aDate) {		
		this.gameDate=aDate;
	}
	
	this.getGameTime=function() {
		return this.gameTime;
	}	

	this.setGameTime=function(aTime) {
		this.gameTime=aTime;
	}

	this.getLeagueName=function() {
		return this.league;
	}
	
	this.getBetStatus=function() {
		return this.status;
	}
	
	this.setBetStatus=function(status) {
		this.status=status;
	}

	this.getQuote=function(tipp) {
		return this.tipp.getQuote(tipp);
	}

	this.getTippByTippId=function(tippId) {
		return this.tipp.getTippByTippId(tippId);		
	}

	this.setAllTippStati=function(stat) {
		this.tipp.setAllTippStati(stat);
	}

	this.getTippId=function(tipp) {
		return this.tipp.getTippId(tipp);
	}
	
	this.getTipp=function(tipp) {
		return this.tipp.getTipp(tipp);
	}

	this.getTippBox=function(tipp) {
		return this.tipp.getTippBox;
	}

	this.getTippNumberByTippId=function(tippId) {
		return this.tipp.getTippNumberByTippId(tippId);
	}
	
	this.getTippBoxById=function(tippId) {
		return this.tipp.getTippBoxById(tippId);
	}
	
	this.getQuoteById=function(tippId) {
		return this.tipp.getQuoteById(tippId);
	}	

	this.setQuoteById=function(tippId,quote) {
		return this.tipp.setQuoteById(tippId,quote);
	}	
		
	this.setTippBox=function(tipp) {		
		this.tipp.setTippBox(tipp);
		return this.checkSelectedBets(this.tipp);
	}	
	
	this.getTippBoxString=function() {
		return this.tipp.getTippBoxString();
	}

	this.getStatusById=function(tippId) {
		return this.tipp.getStatusById(tippId);
	}
	
	this.setStatusById=function(tippId,status) {
		return this.tipp.setStatusById(tippId,status);
	}

	this.getStatusByTipp=function(tipp,tippList) {
		return this.tipp.getStatusByTipp(tipp,tippList);
	}

	this.setStatusByTipp=function(tipp,status) {
		return this.tipp.setStatusByTipp();
	}

	this.checkSelectedBets=function(myTipps) {	
		return this.tipp.checkSelectedBets(this.tipp);
	}
	
	this.unselectBets=function() {	
		return this.tipp.unselectBets();		
	}	

	this.getParams=function() {
		var params='';
		var actTopBet=this;
		var idCnt=0;
	        while(actTopBet != null) {
	        	var myTipp=actTopBet.tipp;
	        	while(myTipp!=null) {
	        		if(myTipp.selected=='1') {
	        			var amount=parseFloat(myTipp.betAmount)+JAVASCRIPTCORRECTION;	        			
	        			params=params+'j_tipID_'+idCnt+'='+myTipp.tippId+'&j_quote_'+idCnt+'='+myTipp.quote+'&j_betamount_'+idCnt+'='+parseInt(''+amount)+'&';
	        			idCnt=idCnt+1;
	        		}		        		
	        		myTipp=myTipp.nextTipp;
	        	}
	            	actTopBet=actTopBet.getNextTopBet();			
	        }		
		return params;
	}
	
	this.getResult=function() {
		return this.result;
	}
	
	this.setResult=function(result,detailId) {
		this.result=result;
		this.score24Detail=detailId;
	}	

	this.getTopBetType=function() {
		return this.betType;
	}		

	this.getNextTopBet=function() {
		return this.nextTopBet;
	}

	this.setNextTopBet=function(nexttopbet) {
		 this.nextTopBet=nexttopbet;
	}

	this.checkOpened=function() {
		if(this.opended=='1')
			return true;		
		var actTopBet=this;
	        while(actTopBet != null) {	        	
			if(actTopBet.opended=='1')
				return true;
	            actTopBet=actTopBet.getNextTopBet();
	        }		
		return false;
	}	

	this.getTopBetByNumber=function(num) {
		if(this.gameNumber==num)
			return this;		
		//-------------------------------------------------
		// is this nextTopBet pointer null? if yes, it is the
		// last element, else follow the list and complete
		// the HTML-Code for all cells
		//-------------------------------------------------
		var actTopBet=this;
	        while(actTopBet != null) {	        	
			if(actTopBet.gameNumber==num)
				return actTopBet;
	            actTopBet=actTopBet.getNextTopBet();
	        }		     
		return actTopBet;
	}	
	
	this.countBets=function() {
		var count=0;
		var actTopBet=this;
	        while(actTopBet != null) {	        	
	        	count=count+1;
		        actTopBet=actTopBet.getNextTopBet();
	        }		
		return count;
	}	

	this.getTopBetById=function(id) {
		if(this.betId==id)
			return this;		
		var actTopBet=this;
	        while(actTopBet != null) {	        	
			if(actTopBet.betId==id)
				return actTopBet;
	            actTopBet=actTopBet.getNextTopBet();
	        }		
		return actTopBet;
	}	
	
	this.checkTippById=function(id) {
		//----------------------------
		// if tipp is selectes then
		// the function returns true
		//----------------------------
		for(a=3;a<tipp_quotesArray.length;a++) {
			if((this.tipp_quotesArray[a]==id)&&(this.tipp_quotesArray[a-1]=='1')) 
				return true;
			a=a+4;
		}
		return false;
	}

	this.getBlockImg=function(status,klicked,tippNumber) {	
		var sel="checked=\"checked\"";
		if(klicked==false) {
			sel='';
		}		
		if(status==GAMEPLAYABLE)
			return "<input AUTOCOMPLETE=\"OFF\" "+sel+" onClick=\"handleBet('"+this.gameNumber+"','"+tippNumber+"');\" type=\"checkbox\" name=\"tipp_"+this.gameNumber+"_"+tippNumber+"\" id=\"tipp_"+this.gameNumber+"_"+tippNumber+"\" value=\"ON\">";	
		if(status==GAMEBLOCKED)
			return "<img src=\""+BLOCKED+"\">";;
		if(status==GAMENOTPLAYABLE)
			return "&nbsp;";
		return "&nbsp;";
	}
	

	//--------------------------------------------------------------
	// calls all betlines an gets their datas
	// type:		filter for "all games","not finished games", "my liga"
	// filter:		contains an array with the my liga names
	// detailBet:		the bet which should show its details
	//--------------------------------------------------------------
	this.displayAllTopBets=function(type,filter,openId) {
		bgCol = "";
		cellCode = "";
		var actTopBet = this;
		var actTopBetCode = "";
		betCount = 0;
        while (actTopBet != null) {
			actTopBetCode = actTopBet.displayTopBet(type,filter,openId);
			cellCode = cellCode+actTopBetCode;
           	actTopBet = actTopBet.getNextTopBet();
        }
        return cellCode;
	}	

	//------------------------------------
	// builds the column of a bet 
	// type = filter type (all games, open, my games)
	// filter = an array which contains the myLigaNames
	//------------------------------------
	this.displayTopBet=function(type,filter,openId) {
		this.newer=true;
		var gDate=this.gameDate;	
		var year=parseInt(gDate.substring(6))+2000;
		var mth=parseInt(gDate.substring(3,5))-1;
		var tag=parseInt(gDate.substring(0,2));
		var gTime=this.gameTime;
		var hour=parseInt(gTime.substring(0,2));
		var minute=parseInt(gTime.substring(3));
		var thisDate= new Date(year,mth,tag,hour,minute,0);	
		var actualDate = new Date();		
		if (actualDate.getTime()>thisDate.getTime())
			this.newer=false;
		if (actualDate.getTime()<thisDate.getTime())
			this.newer=true;	
		var display = true;
		IMAGETAG="&nbsp;";
			
		if (type == "OPENGAMES" && this.status != 0) {
			display = false;
		}
		if (type == "MYLIGA") {
			var isMyLeague = false;
			for (i=0;i<filter.length;i++) {
				if (this.league == getLeagueNameById(filter[i]))
					isMyLeague=true;
			}
			if (!isMyLeague)
				display = false;
		}
		betline = "";
		if (display) {
			var prefix = "top_line_";
			var actTopBet = topBetTicket.bets;
			while (actTopBet != null) {
				if (actTopBet.gameNumber == this.gameNumber)
					prefix  = "top_line_marked_";
			       	actTopBet = actTopBet.nextTopBet;
			}	
		        betline = "<TR id=\"GID"+this.gameNumber+"_TR\" class=\""+prefix+(betCount % 2)+" normalTextBlack\" onmouseover=\"markLine('"+this.gameNumber+"');\" onmouseout=\"unmarkLine('"+this.gameNumber+"');\" width=\"591\" onClick=\"setCurrentOpenBet("+this.gameNumber+");checkOK(-1);showRoundTable('"+type+"',"+this.gameNumber+")\" style=\"cursor:pointer;cursor:hand;\">";
			betCount++;
			betline = betline+"<TD width=\"15\">";
			var img = "plus.gif";
			if (this.gameNumber == currentOpenBet)
				img = "minus.gif";
			betline=betline+"	<IMG src=\""+IMAGEPATH+img+"\" width=\"11\" height=\"11\" hspace=\"2\" border=\"0\">";
			betline=betline+"</TD>"+	
			"     <TD width=\"15\" nowrap=\"nowrap\" align=\"left\">"+this.gameNumber+".</TD>"+					
			"     <TD width=\"60\" align=\"center\">"+this.eventCode+"</TD>"+							
			"<TD width=\"55\">"+this.gameDate+"</TD>"+
			"<TD width=\"45\">"+this.gameTime+"</TD>"+
			"<TD width=\"60\"> ";
			if (this.leagueHasLink == 1 && this.classicBetId > -1)
				betline=betline+"<A id=\"GID"+this.gameNumber+"_LL\" href=\"\" onClick=\"javascript:window.open('"+leagueLink+escape(this.classicBetId)+"', 'external', 'scrollbars=yes,resizable=yes'); return false;\" title=\"Tabelle\">"+this.league+"</A>";
			else
				betline=betline+this.league;
			betline=betline+"</TD>"+
			"     <TD width=\"180\">"+this.betEvent+"</TD>"+
			"     <TD width=\"95\">"+this.betType+"</TD>";
			var res = this.result;
			if (this.scoreInfo != "&nbsp;")
				res = this.scoreInfo+" "+res;
			if (this.score24Detail == "-1") {
				betline=betline+"     <TD width=\"78\">"+res+"</TD>";
			} else {
				betline=betline+"     <TD width=\"78\"><a href=\"javascript:startBetDetails(\'"+this.score24Detail+"\',\'"+this.betEvent+"\',\'\');showElement(\'dragDiv\');\">"+res+"</a></TD>";
			}
			betline=betline+"</TR>";
			if (this.gameNumber == currentOpenBet) {
				betline=betline+this.displayTopBetDetail()+
				"<TR height=\"6\">"+
					"<TD colspan=\"9\" bgcolor=\"#d78d10\"></TD>"+		
				"</TR>";
			}															
		}	
		return betline;
	}
	
	//------------------------------------
	// displays the details of this bet
	//------------------------------------	
	this.displayTopBetDetail=function() {
		var line="<tr><td bgcolor=\"#FFFFFF\" colspan=\"9\">"+
			"        <TABLE cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" align=\"right\" bgColor=\"#ffffff\" border=\"0\">"+
                        "            <TR>"+
			"	        <TD class=\"tipp3top_header\" style=\"PADDING-LEFT: 10px; PADDING-BOTTOM: 2px; PADDING-TOP: 2px\">"+
			"		    <span class=\"normalTextBold\">"+this.title+"</span>"+
			"		    <BR><span class=\"normalText\">"+this.text+"</span>"+
			"		</TD>"+
			"            </TR>"+
		        "        </TABLE>"+
			"</td></tr>";
		var rows = parseInt(this.tipp.checkSelectedBets(this.tipp)/3);
		var diff1 = this.tipp.checkSelectedBets(this.tipp)-(parseInt(''+rows)*3);
		var difference=0;
		if (diff1 == 1) {
			rows++;
			difference=2
		}
		if (diff1 == 2) {
			rows++;
			difference=1;
		}
		var totalLength = this.tipp.checkSelectedBets(this.tipp);
		var pos = 0;	
		var aClass = " class=\"alternated\"";
		var tList = this.tipp;
		var betCount = 1;
		line = line+"<tr><td bgcolor=\"#ffffff\" colspan=\"9\" style=\"padding: 0px;\">"+
				"    <TABLE class=\"tipp3top_tippTable\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" border=\"0\">"+
				"        <TR>"+
				"	    <TH width=\"15\">&nbsp;</TH>"+
				"           <TH width=\"25\" align=\"left\">Nr.</TH>"+
				"           <TH width=\"73\" align=\"center\">Tipp</TH>"+
				"	    <TH width=\"75\" align=\"center\" colspan=\"2\">Quote</TH>"+		

				"	    <TH width=\"15\">&nbsp;</TH>"+
				"           <TH width=\"25\" align=\"left\">Nr.</TH>"+
				"           <TH width=\"73\" align=\"center\">Tipp</TH>"+
				"	    <TH width=\"75\" align=\"center\" colspan=\"2\">Quote</TH>"+	

				"	    <TH width=\"15\">&nbsp;</TH>"+
				"           <TH width=\"25\" align=\"left\">Nr.</TH>"+
				"           <TH width=\"73\" align=\"center\">Tipp</TH>"+
				"	    <TH width=\"75\" align=\"center\" colspan=\"2\">Quote</TH>"+	
				"	  </TR>";
		for (a=0; a<rows; a++) {
			line = line+"     <TR>";
			if(aClass==" class=\"alternated\"")
				aClass="";
			else
				aClass=" class=\"alternated\"";
			for (b=0; b<3; b++) {
				if (betCount <= totalLength) {
					//-----------------------------
					// calculate the tipp number
					// for 5 Rows:
					// 1,6,11   -> (a+1)+(rows*b)
					// 2,7,12....
					//-----------------------------
					var tippNumber = (a+1)+(rows*b);
					if (b == 2 && diff1 == 1)
						tippNumber--;
					var thisTipp=tList.getTippByListNumber(tList,tippNumber);
					var color="#000000";
					var winningTipIdString = this.winningTippId+'';
					var winArray = winningTipIdString.split(',');
					for (var w=0; w<winArray.length; w++) {
						if (thisTipp.tippId == winArray[w]) {
							color="#FF0000";
						}
					}
					var style = '';
					if (b > 0)
						style = ' style="border-left: #c8c8c8 1px solid;"';
					line=line+"	<TD width=\"15\" "+aClass+style+"></TD>";
					line=line+"	<TD width=\"25\" "+aClass+"><span  id=\"TIPP"+thisTipp.tippId+"_NR\" style=\"color:"+color+"\">"+thisTipp.tippNr+".</span></TD>"+
					          "	<TD width=\"73\" "+aClass+" nowrap=\"nowrap\" align=\"center\"><span  id=\"TIPP"+thisTipp.tippId+"_TIPP\" style=\"color:"+color+"\">"+thisTipp.tipp+"</span></TD>"+
						  "     <TD width=\"47\" "+aClass+" align=\"right\">&nbsp;<span id=\"TIPP"+thisTipp.tippId+"_QUOTE\" style=\"color:"+color+"\">"+formatQuote(thisTipp.quote)+"</span></TD>";					
					var tmpquote = thisTipp.quote;
					if (tmpquote == 0) {
						this.setStatusByTipp(a,GAMENOTPLAYABLE);
					}
					var sel = false;
					if (thisTipp.selected == '1') {
						sel = true;					
					}
					line=line+"    <TD "+aClass+" align=\"center\" valign=\"middle\">"+this.getBlockImg(this.getStatusByTipp(thisTipp.tippNr,this.tipp),sel,thisTipp.tippNr)+"</TD>";	
				} else {
					var style = '';
					if (b > 0)
						style = ' style="border-left: #c8c8c8 1px solid;"';
					line=line+"	<TD width=\"15\" "+aClass+style+"></TD>"+
					          "    <TD width=\"25\" "+aClass+">&nbsp;</TD>"+
					          "    <TD width=\"73\" "+aClass+">&nbsp;</TD>"+
					          "    <TD width=\"47\" "+aClass+">&nbsp;</TD>"+
					          "    <TD "+aClass+">&nbsp;</TD>";								
				}				
				betCount++;

			}
			line = line+"  </TR>";
		}
		line = line+"</TABLE></td></tr>";
		line = line+"<tr><td bgColor=\"#ffffff\" colspan=\"9\">"+
			"	<TABLE cellSpacing=\"0\" cellPadding=\"0\" width=\"575\" border=\"0\" align=\"right\">"+
    			"           <TR>"+
                        "               <TD class=\"tipp3top_header\" style=\"PADDING-LEFT: 10px\">"+
    			"                   <SPAN class=\"normalTextBlack\">"+this.information+"</SPAN>"+
    			"               </TD>"+
    			"      	    </TR>"+
    			"       </TABLE>"+
			"</td></tr>"+		
    			"<tr><td bgColor=\"#ffffff\" colspan=\"9\" height=\"5\"></td></tr>";			
		return line;
	}
	
	//------------------------------------
	// add a bet to the end of the list
	// of the bet objects
	//------------------------------------
	this.addBet=function(bet) {	
		bet.nextTopBet=null; //reset it to null for any case; necessary it will be the last element in the list
	        if (this.nextTopBet == null) {  
	            this.nextTopBet=bet;
	        } else {
	            var tempBet=this.nextTopBet;
	            tempBet.addBet(bet); 
		} 
	}
		
	//------------------------------------
	// sort by number
	//------------------------------------
	this.sortByNumber=function() {
		return this.sortByNumber();		
	}
	
	//------------------------------------
	// sort by date
	//------------------------------------
	this.sortByDate=function(direction,sortArray,betNumberArray) {
		
		return this.sortByDate();		
	}
	
	//------------------------------------
	// sort by league
	//------------------------------------
	this.sortByLeague=function() {
		return this.sortAlphabetic(LEAGUE,0,null,null,null);		
	}
	
	//------------------------------------
	// sort by TeamName
	// param: 
	// 1...teamlist 1 (left)
	// 2...teamlist 2 (right)
	//------------------------------------
	this.sortByTeamName=function(teamnumber) {
		return this.sortByTeamName(teamnumber);		
	}
	
	//------------------------------------
	// sort alphabetic
	// param: 
	// sortType:
	// T1...teamlist 1 (left)
	// T2...teamlist 2 (right)
	// L....League
	// uniqueNumber....a number to find the right bet again
	//                 this is used for the gamenumber and 
	//                 must start with one
	// direction: 
	// > descending
	// < ascending
	// sortArray
	// array with the quotes
	// betList....necessary to sort the main betlist		
	//------------------------------------
	this.sortAlphabetic=function(sortType,uniqueNumber,direction,sortArray,betList) {
		var returnArray;
		var value;
		if(sortType==EVENT) {
			value=this.eventCode+"_"+this.gameNumber;	

		}
		if(sortType==LEAGUE) {
			value=this.getLeagueName()+"_"+this.gameNumber;	

		}
		if(sortType==BET_EVENT) {
			value=this.betEvent+"_"+this.gameNumber;	

		}
		if(sortType==BETTYPE) {
			value=this.betType+"_"+this.gameNumber;	
			// alert(value);

		}		
		uniqueNumber++;
		if(sortArray==null) {			
			sortArray = new Array();
		}
		if(betList==null) {			
			betList = this.createTopBet(this);
		} else {
			betList.addBet(this.createTopBet(this));
		}
		sortArray.push(value);
		if(this.getNextTopBet()!=null) {
			actTopBet=this.getNextTopBet();
			returnArray=actTopBet.sortAlphabetic(sortType,uniqueNumber,direction,sortArray,betList);
		} else {			
			if(direction=='<') {			
				sortArray.sort();
			} else {
				sortArray.sort();
				sortArray.reverse();				
			}
			var num=sortArray[0].substring(sortArray[0].lastIndexOf('_')+1);
			var tempBet=betList.getTopBetByNumber(num);
			var newBetOrder=this.createTopBet(tempBet);
			for(i=1;i<sortArray.length;i++) {
				num=sortArray[i].substring(sortArray[i].lastIndexOf('_')+1);
				tempBet=betList.getTopBetByNumber(num);
				newBetOrder.addBet(this.createTopBet(tempBet));	
			}
			returnArray = newBetOrder;
		}
		return returnArray;		

	}
			
	
	//------------------------------------
	// sort by Quote
	// param: 
	// sortType:
	// 1........quote 1 (left)
	// X...quote X (middle)
	// 2........quote X (right)
	// N........sort the gamenumbers
	// D........sort dates
	// direction: 
	// > descending
	// < ascending
	// sortArray
	// array with the quotes
	// array with the betnumbers....necessary to find the right bet again	
	//------------------------------------
	this.sortByValue=function(sortType,direction,sortArray,betNumberArray,betList) {
		var returnArray;
		var value;
		if(sortType==GAMENUMBER)
			value=parseInt(this.getGameNumber());
		if(sortType==GAMEDATE) {
			var gDate=this.gameDate;	
			var year=parseInt(gDate.substring(6))+2000;
			var mth=parseInt(gDate.substring(3,5))-1;
			var day=parseInt(gDate.substring(0,2));
			var gTime=this.gameTime;
			var hour=parseInt(gTime.substring(0,2));
			var minute=parseInt(gTime.substring(3));
			value=Date.UTC(year,mth,day,hour,minute,00);
		}
		if(sortArray==null) {			
			sortArray = new Array();
			sortArray.push(value);
			betNumberArray=new Array();
			betNumberArray.push(parseInt(this.getGameNumber()));
		} else {
			var i=0;
			if(direction==ASCENDING) {				
				while(sortArray[i]<value) {
					i++;	
				}
			}
			if(direction==DESCENDING) {
				i=0;
				while(sortArray[i]>value){
					i++;	
				}							
			}
			if(i>=sortArray.length) {
				sortArray.push(value);
				betNumberArray.push(parseInt(this.getGameNumber()));
			} else {
				var tempArray1=sortArray.slice(0,i);
				var tempArray2=sortArray.slice(i,sortArray.length);
				tempArray1.push(value);
				tempArray1=tempArray1.concat(tempArray2);
				sortArray=tempArray1;				
				var tempArray1=betNumberArray.slice(0,i);
				var tempArray2=betNumberArray.slice(i,betNumberArray.length);
				tempArray1.push(parseInt(this.getGameNumber()));
				tempArray1=tempArray1.concat(tempArray2);
				betNumberArray=tempArray1;					
			}
		}
		if(betList==null) {			
			betList = this.createTopBet(this);
		} else {
			betList.addBet(this.createTopBet(this));
		}		
		if(this.getNextTopBet()!=null) {
			actTopBet=this.getNextTopBet();
			returnArray=actTopBet.sortByValue(sortType,direction,sortArray,betNumberArray,betList);
		} else {			
			var tempBet=betList.getTopBetByNumber(betNumberArray[0]);			
			var newBetOrder=this.createTopBet(tempBet);
			for(i=1;i<betNumberArray.length;i++) {
				tempBet=betList.getTopBetByNumber(betNumberArray[i]);
				newBetOrder.addBet(this.createTopBet(tempBet));	
			}
			returnArray = newBetOrder;
		}
		return returnArray;				
	}

	this.isNewer=function() {
		return this.newer;		
	}							
	return this;	
}

function createTopBet(bet) {
	this.createTopBet(bet);	
}


function updateTopBet(bet) {
	this.updateTopBet(bet);	
}

function addBet(bet) {
	this.addBet(bet);
}

function getGameNumber() {
	return this.getGameNumber();
}

function getParams() {
	return this.getParams();
}

function getGameDate() {
	return this.getGameDate();
}

function setGameDate(aDate) {
	this.setGameDate(aDate);
}

function isOpened() {
	return this.isOpened();
}

function checkSelectedBets(myTipps) {
	return this.checkSelectedBets(myTipps);
}

function getTippQuotesArray() {
	return this.getTippQuotesArray();
}

function getBetEvent() {
	return this.getBetEvent();
}

function getEventCode() {
	return this.getEventCode();
}

function getGameTime() {
	return this.getGameTime();
}

function setGameTime(aTime) {
	this.setGameTime(aTime);
}

function getLeagueName() {
	return this.getLeagueName();
}

function getTeamName(number) {
	return this.getTeamName(number);
}

function getQuote(quote) {
	return this.getQuote(quote);
}

function getTopBetType() {
	return this.getTopBetType();
}

function deleteSubBet(tipp) {
	return this.deleteSubBet(tipp);
}

function setTippBox(tipp) {
	this.setTippBox(tipp);
}	

function getTippBoxString() {
	this.getTippBoxString();
}	

function getTippBox(tipp) {
	return this.getTippBox(tipp);
}

function setTipp(tipp) {
	this.setTipp(tipp);
}	

function getTipp(tipp) {
	return this.getTipp(tipp);
}

function getTippBoxById(tippId) {
	return this.getTippBoxById(tippId);
}

function getQuote(tipp) {
	return this.getQuote(tipp);
}

function getQuoteById(tippId) {
	return this.getQuoteById(tippId);
}

function getBetStatus() {
	return this.getBetStatus();
}

function setBetStatus(status) {
	this.setBetStatus(status);
}

function setStatusById(tippId,status) {
	this.setStatusById(tippId,status);
}

function getStatusById(tippId) {
	return this.getStatusById(tippId);
}

function getStatusByTipp(tipp,tippList) {
	return this.getStatusByTipp(tipp,tippList);
}

function setStatusByTipp(tipp,status) {
	return this.setStatusByTipp(tipp,status);
}

function getResult() {
	return this.getResult();
}

function setResult(result) {
	return this.setResult(result);
}

function getClassicBetId() {
	return this.getClassicBetId();
}

function setClassicBetId(classicBetId) {
	this.setClassicBetId(classicBetId);
}

function setQuoteById(tippId,quote) {
	return this.setQuoteById(tippId,quote);
}

function setWinningTipp(tippId) {
	return this.setWinningTipp(tippId);
}

function getNextTopBet() {
	return this.getNextTopBet();
}

function setNextTopBet(nextTopBet) {
	this.setNextTopBet(nextTopBet);
}

function getTopBetByNumber(num) {
	return this.getBetByNumber(num);
}

function getTopBetById(id) {
	return this.getBetById(id);
}

function checkTippById(id) {
	return this.checkTippById(id);
}

function getTippId(id) {
	return this.getTippId(id);
}

function getTippByTippId(tippId) {
	return this.getTippByTippId(tippId);
}

function getTippNumberByTippId(tippId) {
	return this.getTippNumberByTippId(tippId);
}

function displayAllTopBets(type,filter,openId) {
	return this.displayAllTopBets(type,filter,openId);
}

function displayTopBet(type,filter,openId) {
	return this.displayTopBet(type,filter,openId);
}

function getParams() {
	return this.getParams();
}

function checkOpened() {
	return this.checkOpened();
}

function getBlockImg(status,klicked,tippNumber) {
	return this.getBlockImg(status,klicked,tippNumber);
}

function sortByNumber() {
	return this.sortByNumber();		
}

function sortByDate() {
	return this.sortByDate();		
}

function sortByLeague() {
	return this.sortByLeague();		
}

function sortByTeamName(teamnumber) {
	return this.sortByTeamName(teamnumber);		
}

function sortByQuote(quotenumber,direction,sortArray,betNumberArray) {
	return this.sortByQuote(quotenumber,direction,sortArray,betNumberArray);		
}

function isNewer() {
	return this.isNewer();		
}

function alphaSortUp(a,b) {
	return a-b;
}	

function alphaSortDown(a,b) {
	return b-a;
}
	
