var BLOCKED=IMAGEPATH+"gesperrt.gif";

var IMAGETAG="&nbsp;";
var INPUTTAG1="";
var INPUTTAG2="";
var INPUTTAG3="";

var ASCENDING='<';
var DESCENDING='>';
var JAVASCRIPTCORRECTION=0.000000000001;
var bgCol="#FFFFFF"; 
var black_white="schwarz"; //alternating image for finished bets;

var GAMEPLAYABLE='0';
var GAMEBLOCKED='1';
var GAMENOTPLAYABLE='2';

var betCount=0; 

//------------------------------------
// open = 1, closed=0
// num:	gamenumber
// gameID:	Id of this bet
// gDate:	gamedate
// gTime:	game time
// betQuestion:	The betquestion
// quote:	the quote of that betquestion
// title:	title of that bet
// text1: 	text1 (above the question table) to that bet
// text2: 	text2 (below the question table) to that bet
// questionsArray: an array with the questions: question, answer1, answerID1,answer2,answerID2
// gameStatus: status if the game is betable or already closed
//------------------------------------------------------------------------------------------------------------------- ---------------------------
// open=1/closed=0,gamenumber,enddate,endtime,betQuestion,quote,result,title,text,array with tipps and  quotes,informationtext	,betId,betstatus
//------------------------------------------------------------------------------------------------------------------- -------------------
function BetHit(opened,num,gDate,gTime,betQuestion,quote,result,title,text,questionArray,information,betId,status,shortQuestion,betAmount,eventCode) {
	this.opened=opened
	this.gameNumber=num;
	this.betId=betId;
	this.betStatus=status;
	this.gameDate=gDate;
	this.gameTime=gTime;
	this.betQuestion=betQuestion;
	this.quote=quote;
	this.result=result;
	this.title=title;
	this.text=text;	
	this.information=information;
	this.questionArray=questionArray;
	this.shortQuestion=shortQuestion;
	this.betAmount=betAmount;
	this.eventCode=eventCode;
	this.nextHitBet=null;
	this.newer=true;

	this.addBet=addBet;
	this.getGameNumber=getGameNumber;
	this.getGameDate=getGameDate;
	this.getGameTime=getGameTime;
	this.getTippBox=getTippBox;
	this.getNextHitBet=getNextHitBet;
	this.setNextHitBet=setNextHitBet;
	this.displayAllHitBets=displayAllHitBets;
	this.displayHitBet=displayHitBet;	
	this.getQuote=getQuote;
	this.setTipp=setTipp;
	this.getTipp=getTipp;
	this.getTippBoxString=getTippBoxString
	this.setTippBox=setTippBox;
	this.getTippBox=getTippBox;	
	this.getHitBetByNumber=getHitBetByNumber;
	this.getHitBetById=getHitBetById;
	this.selectBet=selectBet;
	this.getParams=getParams;
	this.getSelectedTippId=getSelectedTippId;
	//this.createHitBet=createHitBet;
	this.resetBet=resetBet;
	this.getBlockImg=getBlockImg;
	this.getBetStatus=getBetStatus;

	this.updateHitBet=function(hitBet) {
		var aHitBet = this.getHitBetByNumber(hitBet.getGameNumber());		
		if(aHitBet!=null) {
			aHitBet.opened=hitBet.isOpened();
			aHitBet.gameNumber=hitBet.getGameNumber();
			aHitBet.gameDate=hitBet.getGameDate();
			aHitBet.gameTime=hitBet.getGameTime();
			aHitBet.questionArray=hitBet.questionArray;
		}
	}

	this.deleteSubBet=function(tipp) {
		return this.setTippBox(tipp);
	}	

	this.resetBet=function(thisBet) {
		var aBet=hitBetList.getHitBetByNumber(thisBet.gameNumber);
		var str=aBet.getTippBoxString();
		for(var a=0;a<str.length;a++) {
			aBet.setTippBoxByNumber((a+1),'0');
		}
		hitBetList.updateHitBet(aBet);		
	}
	
	this.createHitBet=function(bet) {
		return new BetHit(bet.opened,bet.gameNumber,bet.gameDate,bet.gameTime,bet.betQuestion,bet.quote,bet.result,bet.title,this.text,bet.questionArray,bet.information,bet.betId,bet.betStatus,bet.shortQuestion,bet.betAmount,bet.eventCode);
	}	

	this.deleteHitBet=function(num) {
		if(this.gameNumber==num) {
			if(this.getNextHitBet()!=null) {
				return this.getNextHitBet();		
			} else {
				return null;
			}
		}
		var actHitBet=this;
		var oldHitBet=null;
	        while(actHitBet != null) {
			if(actHitBet.gameNumber==num) {
				oldHitBet.setNextHitBet(actHitBet.getNextHitBet());
			}
			oldHitBet=actHitBet;
	            	actHitBet=actHitBet.getNextHitBet();
	        }
	        return this;		
	}	

	this.getGameNumber=function() {
		return this.gameNumber;
	}

	this.isOpened=function() {
		return this.opened;
	}

	this.getQuestionsArray=function() {
		return this.questionsArray;
	}	

	this.getGameDate=function() {		
		return this.gameDate;
	}

	this.getGameTime=function() {
		return this.gameTime;
	}	

	this.getQuote=function() {
		return this.quote;
	}

	this.getBetPosition=function(tipp) {
		var cnt=1;
		for(a=0;a<this.questionArray.length;a++) {
			if(cnt==tipp)
				break;
			a=a+(this.questionArray[a+1]*2)+3;
			cnt=cnt+1;
		}
		return a;
	}

	this.getBetStatus=function(tipp) {
		var pos=this.getBetPosition(tipp);
		return this.questionArray[a+(this.questionArray[a+1]*2)+3];
	}

	this.getTipp=function(tipp) {
		return this.questionArray[((tipp-1)*7)];
	}

	this.setTipp=function(tippNr,tipp) {
		this.questionArray[((tippNr-1)*7)]=tipp;
	}

	this.getTippBox=function(tipp) {
		var pos=this.getBetPosition(tipp);
		return this.questionArray[pos+(this.questionArray[pos+1]*2)+2];
	}

	this.setTippBox=function(tipp) {
		if(this.questionArray[5+((tipp-1)*7)]=='1') {
			this.questionArray[5+((tipp-1)*7)]='2';
		} 		
		if(this.questionArray[5+((tipp-1)*7)]=='2') {
			this.questionArray[5+((tipp-1)*7)]='1';
		}
		return this.checkSelectedBets();
	}	

	this.setTippBoxByNumber=function(tippNr,tipp) {
		var pos=this.getBetPosition(tippNr);
		this.questionArray[pos+(this.questionArray[pos+1]*2)+2]=tipp;
		return;// this.checkSelectedBets();
	}
	
	this.getTippBoxString=function() {
		var tippBoxString="";
		for(a=0;a<this.questionArray.length;a++) {
			var numOfAnswers=this.questionArray[a+1];
			tippBoxString=tippBoxString+this.questionArray[a+(numOfAnswers*2)+2];
			a=a+(numOfAnswers*2)+3;			
		}
		return tippBoxString;
	}

	this.getSelectedTippId=function(tippnr) {
		var id="";	
		var pos=this.getBetPosition(tippnr+1);	
		var numOfAnswers=this.questionArray[pos+1];
		var selectedAnswer=this.questionArray[pos+(numOfAnswers*2)+2];
		id=this.questionArray[pos+((selectedAnswer-1)*2)+3];
		return id;
	}

	this.getBlockImg=function(sel,questionNumber,answerNumber) {
		if(hitBetTicket.confirmTicket==true) {
			if((this.betStatus==GAMENOTPLAYABLE)&&(sel=="checked=\"checked\""))
				return "<img src=\""+IMAGEPATH+"hackerl.gif\">";
			else
				return "<INPUT "+sel+" name=\"tipp"+this.gameNumber+"_"+questionNumber+"_"+answerNumber+"\" disabled type=\"radio\" value=\"\">\r\n";
		}
		if(this.betStatus==GAMEPLAYABLE) {	
			if(((BETSTATUS=='')&&(SYSTEMERROR==''))||(this.confirmTicket==undefined)) {
				return "<INPUT "+sel+" name=\"tipp"+this.gameNumber+"_"+questionNumber+"_"+answerNumber+"\" onClick=\"handleSelectTipp("+this.gameNumber+","+questionNumber+","+answerNumber+");\" type=\"radio\" value=\"\">\r\n";
			} else {
				return "<INPUT "+sel+" name=\"tipp"+this.gameNumber+"_"+questionNumber+"_"+answerNumber+"\" onClick=\"handleSelectTipp("+this.gameNumber+","+questionNumber+","+answerNumber+");\" type=\"radio\" value=\"\">\r\n";
			}
		}
		if(this.betStatus==GAMEBLOCKED)
			return "<img src=\""+BLOCKED+"\">";;
		if(this.betStatus==GAMENOTPLAYABLE) {	
			if(sel=="checked=\"checked\"")
				return "<img src=\""+IMAGEPATH+"hackerl.gif\">";			
			else
				return "<INPUT "+sel+" name=\"tipp"+this.gameNumber+"_"+questionNumber+"_"+answerNumber+"\" disabled type=\"radio\" value=\"\">\r\n";
		}
		return "&nbsp;";
	}

	this.checkSelectedBets=function() {	
		var cnt=0;
		for(a=0;a<this.questionArray.length;a++) {
			a=a+(this.questionArray[a+1]*2)+2;
			if(this.questionArray[a]!='=')
				cnt=cnt+1;
			a++;
		}
		return cnt;
	}
	
	this.getNextHitBet=function() {
		return this.nextHitBet;
	}

	this.setNextHitBet=function(nexthitbet) {
		 this.nextHitBet=nexthitbet;
	}	

	this.getHitBetByNumber=function(num) {
		if(this.gameNumber==num)
			return this;		
		var actHitBet=this;
	        while(actHitBet != null) {	        	
			if(actHitBet.gameNumber==num)
				return actHitBet;
	            actHitBet=actHitBet.getNextHitBet();
	        }		
		return actHitBet;
	}	

	this.getHitBetById=function(betId) {
		if(this.betId==betId)
			return this;		
		var actHitBet=this;
	        while(actHitBet != null) {	        	
			if(actHitBet.betId==betId)
				return actHitBet;
	            actHitBet=actHitBet.getNextHitBet();
	        }		
		return actHitBet;
	}	

	this.displayAllHitBets=function(type,filter,openId) {
		black_white = 'schwarz';
		cellCode = "";
		betCount = 0;
		var actHitBet = this;
		var actHitBetCode = "";
	        while (actHitBet != null) {
	        	actHitBetCode = actHitBet.displayHitBet(type,filter,openId);
			cellCode = cellCode+actHitBetCode;
	            	actHitBet = actHitBet.getNextHitBet();
     	
	        }
	        return cellCode;
	}	

	this.displayHitBet=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;		
		if (type == "OPENGAMES" && this.betStatus != "0")
			display = false;

		if (type == "MYLIGA") {
			var found = false;
			for (i=0; i<filter.length; i++) {
				if (this.league == filter[i])
					found = true;
			}
			if (!found)
				display = false;
		}
		var betline="";		
		if (display) {	
			var prefix = "hit_line_";
			if (betCount % 2 == 0) {
				minus_gif="minus.gif";
				plus_gif="plus.gif";
				black_white = "schwarz";
			} else {
				minus_gif="minus_weiss.gif";
				plus_gif="plus_weiss.gif";
				black_white="weiss";
			}
			var actHitBet = hitBetTicket.bets;
			while (actHitBet != null) {
				if (actHitBet.gameNumber == this.gameNumber) {
					prefix  = "hit_line_marked_";
					minus_gif="minus_weiss.gif";
					plus_gif="plus_weiss.gif";
					black_white="weiss";
				}
			       	actHitBet = actHitBet.nextHitBet;
			}
			if ((openId == this.gameNumber && this.opened == 0) || (openId == this.gameNumber && this.opened == 1 && keepOpen == true)) {
				betline=betline+'<TR id="GID'+this.gameNumber+'_TR" class="'+prefix+(betCount % 2)+'" onmouseover="markLine('+this.gameNumber+');" onmouseout="unmarkLine('+this.gameNumber+');" style="cursor:pointer;cursor:hand;" onClick="checkOK(-1);drawRoundTable(getCode('+this.gameNumber+'));openedBetId=0">';
			} else {
				betline=betline+'<TR id="GID'+this.gameNumber+'_TR" class="'+prefix+(betCount % 2)+'" onmouseover="markLine('+this.gameNumber+');" onmouseout="unmarkLine('+this.gameNumber+');" style="cursor:pointer;cursor:hand;" onClick="checkOK(-1);drawRoundTable(getCode('+this.gameNumber+'));openedBetId='+this.gameNumber+';">';
			}
			betCount++;
			betline=betline+'<TD width="15">';
			if ((openId == this.gameNumber && this.opened == 0) || (openId == this.gameNumber && this.opened == 1 && keepOpen == true)) {
				openedBetId = this.gameNumber;
				betline=betline+"<IMG id=\"GID"+this.gameNumber+"_PM\" height=\"11\" hspace=\"2\" src=\""+IMAGEPATH+minus_gif+"\" width=\"11\" border=\"0\">";
			} else {
				betline=betline+"<IMG id=\"GID"+this.gameNumber+"_PM\" height=\"11\" hspace=\"2\" src=\""+IMAGEPATH+plus_gif+"\" width=\"11\" border=\"0\">";
			}			
			betline=betline+'</TD>'+
			'	<TD width="15">'+this.gameNumber+'.</TD>'+
			'       <TD width="50" align="center">'+this.eventCode+'</TD>'+							
			'	<TD width="100">'+this.gameDate+'&nbsp;&nbsp;'+this.gameTime+'</TD>'+
			'	<TD width="315" align="left">'+this.betQuestion+'</TD>'+
			'	<TD width="60">';
			if (this.quote == 100)
				betline=betline+'abgesagt';
			else
				betline=betline+formatQuote(this.quote);
			betline=betline+'</TD>'+
			'	<TD width="30">';
			if (this.result == '1')
				betline=betline+'<img id="GID'+this.gameNumber+'_HAK" src=\"'+IMAGEPATH+'hackerl'+black_white+'.gif\" style=\"margin-left:10px;\">';
			else
				betline=betline+'&nbsp;';
			betline=betline+'</TD>'+
			'</TR>';						    
			if ((openId == this.gameNumber && this.opened == 0) || (openId == this.gameNumber && this.opened == 1 && keepOpen == true)) {
			   	betline=betline+"<tr><td bgcolor=\"#FFFFFF\" colspan=\"7\" style=\"padding-left: 0px; padding-right: 0px;\">"+this.displayHitBetDetail()+"</td></tr>";	
			   	this.opened=1;
			} else {
			   	this.opened=0;
			}
		} 						
		return betline;
	}

	this.displayHitBetDetail=function() {
		var line='<table style="margin-left: 6px;" border="0" cellpadding="4" cellspacing="0" width="580" bgcolor="#FFFFFF">'+
		'<tr>'+
		'	<td class="normalText"><b style="color:#C02024">'+this.title+'</b></td>'+
		'</tr>'+
		'<tr>'+
		'	<td class="normalTextBlack" bgcolor="#FFF6B8">'+this.text+'</td>'+
		'</tr>'+
		'<tr>'+
		'	<td align="center" style="padding-top: 6px; padding-left: 0px; padding-right: 0px;">'+
		'		<table class="tipp3top_tippTable" border="0" cellpadding="2" cellspacing="0" width="580" id="table4">';
		var pos = 0;
		var questionNumber = 0;
		var status = '0';
		var cnt = 0;
		for (a=0; a<this.questionArray.length; a++) {
			a=a+(this.questionArray[a+1]*2)+3;
			if (a < this.questionArray.length);
				cnt=cnt+1;
		}
		cnt=cnt/2;
		var aClass='';
		for (a=0; a<cnt; a++) {
			if (aClass == '') {
				aClass='class="alternated"';
			} else {
				aClass='';	
			}
			line=line+'<tr>';
			if (questionArray[pos] != undefined) {
				frage = questionArray[pos++];
			} else {
				frage='&nbsp;';				
				pos++;
			}
			var style = '';
			if (a == 0)
				style = 'border-top: #c8c8c8 1px solid;';
			line=line+'<td style="padding-left: 10px; '+style+'" align="left" '+aClass+'>'+frage+'&nbsp;</td>\n';
			var numberOfAnswers=questionArray[pos++];
			var selPosCounter=(numberOfAnswers*2)-1;
			for (an=0; an<numberOfAnswers; an++) {
				if (questionArray[pos] != undefined) {
					antwort=questionArray[pos++];
				} else {
					antwort='&nbsp;';				
					pos++;
				}
				line=line+'<td align="right" '+aClass;
				if (style != '')
					line = line+' style="'+style+'"';
				line=line+'>'+antwort+'</td>';
				var sel="";
				if (this.questionArray[pos+selPosCounter] == ''+(an+1))
					sel="checked=\"checked\"";					
				status = questionArray[pos+selPosCounter+1];
				var borderRight = '';
				if (an == numberOfAnswers-1) 
					borderRight = ' border-right: #c8c8c8 1px solid;';
				line=line+'<td '+aClass;
				if (style != '' || borderRight != '')
					line = line+' style="'+style+borderRight+'"';
				line=line+'>';
				if (antwort != '&nbsp;')			
					line=line+this.getBlockImg(sel,questionNumber,(an+1));
				line=line+"</td>\n";
				selPosCounter = selPosCounter-2;
				pos++;																
			}
			questionNumber++;
			pos=pos+2;
			status=questionArray[pos-1];								
			if (questionArray[pos] != undefined) {
				frage=questionArray[pos++];
			} else {
				frage='&nbsp;';				
				pos++;
			}	
			line=line+'<td align="left" '+aClass+' style="padding-left: 10px; '+style+'">'+frage+'&nbsp;</td>\n';
			if (questionArray[pos] != undefined)
				numberOfAnswers=questionArray[pos];	
			pos++;
			selPosCounter=(numberOfAnswers*2)-1;
			for (an=0; an<numberOfAnswers; an++) {
				if (questionArray[pos] != undefined) {
					antwort=questionArray[pos++];
				} else {
					antwort='&nbsp;';				
					pos++;
				}		
				line=line+'<td align="right" '+aClass
				if (style != '')
					line = line+' style="'+style+'"';
				line=line+'>'+antwort+'</td>';
				var sel="";
				if (this.questionArray[pos+selPosCounter] == ''+(an+1))
					sel="checked=\"checked\"";					
				status = questionArray[pos+selPosCounter+1];
				line=line+'<td '+aClass
				if (style != '')
					line = line+' style="'+style+'"';
				line=line+'>';
				if (antwort != '&nbsp;')			
					line=line+this.getBlockImg(sel,questionNumber,(an+1));
				line=line+"</td>\n";
				selPosCounter=selPosCounter-2;
				pos++;	
			}
			questionNumber++;
			pos=pos+2;
			status=questionArray[pos-1];
			line=line+'</tr>';
		}
		line=line+'             	</table>'+
		'			</td>'+
		'		</tr>'+														
		'		<tr><td style="height:6px"></td></tr>'+																																						
		'		<tr>'+
		'			<td class="normalTextBlack">'+this.information+'</td>'+
		'		</tr>'+
		'		<tr><td style="height:6px"></td></tr>'+									
		'	</table>';
		            
		return line;
		
	}

	this.getParams=function() {
		var params='';
		var actHitBet=this;
		var betCounter=0;
	        while(actHitBet != null) {
			var idCnt=0;
			var theAmount=hitBetTicket.betMoneyArray[idCnt]*100;
			theAmount=theAmount+JAVASCRIPTCORRECTION;
			params=params+'&j_quote_'+betCounter+'='+actHitBet.quote+'&j_betamount_'+betCounter+'='+parseInt(theAmount);
			var counter=1;
	        	for(a=0;a<actHitBet.questionArray.length;a++) {
				var pos=actHitBet.getBetPosition(counter++);
				if(actHitBet.getSelectedTippId(idCnt)!='undefined')
					params=params+'&j_tipID_'+betCounter+'_'+idCnt+'='+actHitBet.getSelectedTippId(idCnt);
	        		idCnt=idCnt+1;
				a=a+(actHitBet.questionArray[pos+1]*2)+3;
	        	}
			betCounter=betCounter+1;
	            	actHitBet=actHitBet.getNextHitBet();			
	        }		
		return params;
	}	

	this.addBet=function(bet) {	
		bet.nextHitBet=null;
	        if (this.nextHitBet == null) {        
	            this.nextHitBet=bet;
	        } else {
	            var tempBet=this.nextHitBet;
	            tempBet.addBet(bet);
	        }	
	}

	this.selectBet=function(betNumber,answerNumber,answer) {
		if(this.gameNumber==betNumber) {
			var num=0;
			var pos=0;
			var numOfAnswers=0;
			while(num!=answerNumber) {
				numOfAnswers=this.questionArray[pos+1];	
				pos=pos+(numOfAnswers*2)+4;
				num++;
			}
			numOfAnswers=this.questionArray[pos+1];	
			this.questionArray[pos+(numOfAnswers*2)+2]=answer;
			var cnt=1;
			while((eval('document.GAMES.tipp'+betNumber+'_'+answerNumber+'_'+cnt)!=undefined)||(eval('document.GAMES.tipp'+betNumber+'_'+answerNumber+'_'+cnt)!=null)) {
				if(cnt!=answer) {
					eval('document.GAMES.tipp'+betNumber+'_'+answerNumber+'_'+cnt+'.checked=false');
				} else {
					eval('document.GAMES.tipp'+betNumber+'_'+answerNumber+'_'+cnt+'.checked=true');
				}
				cnt++;
			}
		} else {
			if(this.nextHitBet!=null)
				this.nextHitBet.selectBet(betNumber,answerNumber,answer);	
		}
	}
		
	this.sortByNumber=function() {
		return this.sortByNumber();		
	}
	
	this.sortByDate=function(direction,sortButtonArray,betNumberArray) {
		
		return this.sortByDate();		
	}
	
	this.sortByLeague=function() {
		return this.sortAlphabetic(LEAGUE,0,null,null,null);		
	}
	
	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
	// sortButtonArray
	// array with the quotes
	// betList....necessary to sort the main betlist		
	//------------------------------------
	this.sortAlphabetic=function(sortType,uniqueNumber,direction,sortButtonArray,betList) {
		var returnArray;
		var value;
		if(sortType==BETEVENT) {
			value=this.betEvent+"_"+uniqueNumber;	

		}
		uniqueNumber++;
		if(sortButtonArray==null) {			
			sortButtonArray = new Array();
		}
		if(betList==null) {			
			betList = this.createHitBet(this);
		} else {
			betList.addBet(this.createHitBet(this));
		}
		sortButtonArray.push(value);
		if(this.getNextHitBet()!=null) {
			actHitBet=this.getNextHitBet();
			returnArray=actHitBet.sortAlphabetic(sortType,uniqueNumber,direction,sortButtonArray,betList);
		} else {			
			if(direction=='>') {			
				sortButtonArray.sort();
			} else {
				sortButtonArray.sort();
				sortButtonArray.reverse();				
			}
			var num=sortButtonArray[0].substring(sortButtonArray[0].lastIndexOf('_')+1);
			var tempBet=betList.getHitBetByNumber(num);
			var newBetOrder=this.createHitBet(tempBet);
			for(i=1;i<sortButtonArray.length;i++) {
				num=sortButtonArray[i].substring(sortButtonArray[i].lastIndexOf('_')+1);
				tempBet=betList.getHitBetByNumber(num);
				newBetOrder.addBet(this.createHitBet(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
	// sortButtonArray
	// array with the quotes
	// array with the betnumbers....necessary to find the right bet again	
	//------------------------------------
	this.sortByValue=function(sortType,direction,sortButtonArray,betNumberArray,betList) {
		var returnArray;
		var value;
		if(sortType==GAMENUMBER) {
			value=parseInt(this.getGameNumber());
		}
		if(sortType==QUOTE) {
			value=parseFloat(this.getQuote());
		}
		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(sortButtonArray==null) {			
			sortButtonArray = new Array();
			sortButtonArray.push(value);
			betNumberArray=new Array();
			betNumberArray.push(parseInt(this.getGameNumber()));
		} else {
			var i=0;
			if(direction==ASCENDING) {				
				while(sortButtonArray[i]<value) {
					i++;	
				}
			}
			if(direction==DESCENDING) {
				i=0;
				while(sortButtonArray[i]>value){
					i++;	
				}							
			}
			if(i>=sortButtonArray.length) {
				sortButtonArray.push(value);
				betNumberArray.push(parseInt(this.getGameNumber()));
			} else {
				var tempArray1=sortButtonArray.slice(0,i);
				var tempArray2=sortButtonArray.slice(i,sortButtonArray.length);
				tempArray1.push(value);
				tempArray1=tempArray1.concat(tempArray2);
				sortButtonArray=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.createHitBet(this);
		} else {
			betList.addBet(this.createHitBet(this));
		}		
		if(this.getNextHitBet()!=null) {
			actHitBet=this.getNextHitBet();
			returnArray=actHitBet.sortByValue(sortType,direction,sortButtonArray,betNumberArray,betList);
		} else {			
			var newBetOrder=null;			
			for(i=0;i<betNumberArray.length;i++) {
				var temp=betList.getHitBetByNumber(betNumberArray[i]);
				if(newBetOrder==null) {
					newBetOrder=this.createHitBet(temp);					
				} else {
					newBetOrder.addBet(this.createHitBet(temp));
				}
			}
			returnArray = newBetOrder;
		}
		return returnArray;				
	}
	this.isNewer=function() {
		return this.newer;		
	}							
	return this;	
}

function updateBet(bet) {
	this.updateBet(bet);	
}

function addBet(bet) {
	this.addBet(bet);
}

function getGameNumber() {
	return this.getGameNumber();
}

function getGameDate() {
	return this.getGameDate();
}

function isOpened() {
	return this.isOpened();
}

function checkSelectedBets() {
	return this.checkSelectedBets();
}

function getTippQuotesArray() {
	return this.getTippQuotesArray();
}

function getBetEvent() {
	return this.getBetEvent();
}

function getEventCode() {
	return this.getEventCode();
}

function getGameTime() {
	return this.getGameTime();
}

function getLeagueName() {
	return this.getLeagueName();
}

function getTeamName(number) {
	return this.getTeamName(number);
}

function getQuote() {
	return this.getQuote();
}

function getHitBetType() {
	return this.getHitBetType();
}

function getParams() {
	return this.getParams();
}

function deleteSubBet(tipp) {
	return this.deleteSubBet(tipp);
}

function resetBet(aBet) {
	return this.resetBet(aBet);
}

function selectBet(betNumber,answerNumber,answer) {
	this.selectBet(betNumber,answerNumber,answer);
}

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 getResult() {
	return this.getResult();
}

function getSelectedTippId() {
	return this.getSelectedTippId();
}

function getNextHitBet() {
	return this.getNextHitBet();
}

function setNextHitBet(nextHitBet) {
	this.setNextHitBet(nextHitBet);
}

function getHitBetByNumber(num) {
	return this.getBetByNumber(num);
}

function getHitBetById(betId) {
	return this.getBetById(BetId);
}

function displayAllHitBets(type,filter,openId) {
	return this.displayAllHitBets(type,filter,openId);
}

function displayHitBet(type,filter,openId) {
	return this.displayHitBet(type,filter,openId);
}

function getBlockImg(sel,questionNumber,answerNumber) {
	return this.getBlockImg(sel,questionNumber,answerNumber);
}

function getBetStatus(tipp) {
	return this.getBetStatus(tipp);
	
}

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,sortButtonArray,betNumberArray) {
	return this.sortByQuote(quotenumber,direction,sortButtonArray,betNumberArray);		
}

function isNewer() {
	return this.isNewer();		
}

function alphaSortUp(a,b) {
	return a-b;
}	

function alphaSortDown(a,b) {
	return b-a;
}
	
