//---------------------------------------------------------------------------
// Filename: BetTopTipp.js
// This function represents a tipp object
//---------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------------------------------------------------------
//Tipp,Quote,selected,tippId,tippStatus,Tipplaufnummer
//--------------------------------------------------------------------------------------------------------------------------------------

function BetTopTipp(tipp,quote,selected,tippId,tippStatus,tippNr) {
	this.tipp=tipp;
	this.quote=quote;
	this.selected=selected;
	this.tippId=tippId;
	this.tippStatus=tippStatus;
	this.tippNr=tippNr;
	this.betAmount=defaultBetamount;
	this.nextTipp=null;
	//---------------------------
	// Object methods
	//---------------------------
	this.addTipp=addTipp;
	this.checkSelectedBets=checkSelectedBets;
	this.getTippBox=getTippBox;
	this.getQuote=getQuote;
	this.setTipp=setTipp;
	this.getTipp=getTipp;
	this.getTippBoxString=getTippBoxString
	this.setTippBox=setTippBox;
	this.getTippBox=getTippBox;	
	this.checkTippById=checkTippById;
	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.getTippStatusByListNumber=getTippStatusByListNumber;
	this.getTippByTippId=getTippByTippId;
	this.createTopBet=createTopBet;
	
	//-----------------------------------
	// for internal use.
	// returns a new bet object out of
	// this object
	//-----------------------------------
	this.createTipp=function(tipp) {
		return new BetTopTipp(tipp.tipp,tipp.quote,tipp.selected,tipp.tippId,tipp.tippStatus,tipp.tippNr);
	}

	//------------------------------------
	// adds a tippObject to the list
	//------------------------------------
	this.addTipp=function(myTipp) {
		myTipp.nextTipp=null; //reset it to null for any case; necessary it will be the last element in the list
		aTipp=this;
		while(aTipp.nextTipp!=null) 
			aTipp=aTipp.nextTipp;
            	aTipp.nextTipp=myTipp;

	}

	//---------------------------------
	// updates the datas of a tipp
	//---------------------------------
	this.updateTipp=function(myTipps,aTipp,tippNumber) {
		//------------------------------------
		// search for the right bet
		//------------------------------------
		var newTipp = myTipps.getTippByNumber(tippNumber);		
		if(newTipp!=null) {
			newTipp.tipp=aTipp.tipp;
			newTipp.selected=aTipp.selected;
			newTipp.tippId=aTipp.tippId;
			newTipp.tippStatus=aTipp.tippStatus;
			newTipp.tippNr=aTipp.tippNr;
			newTipp.betAmount=aTipp.betAmount;
		}
		return myTipps;
	}


	//------------------------------------
	// returns the quote of the tipp
	// tipp: number of the tipp
	//------------------------------------
	this.getQuote=function(tipp) {
		var aTipp=this;
		var cnt=0;
		
		while((aTipp!=null)&&(aTipp.tippNr!=tipp)) {
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		if(aTipp==null)
			return null;
		return aTipp.quote;
	}

	//------------------------------------
	// returns the betmoney of the tipp
	// tipp: number of the tipp
	//------------------------------------
	this.getBetMoney=function(tipp) {
		var aTipp=this;
		var cnt=0;
		
		while((aTipp!=null)&&(aTipp.tippNr!=tipp)) {
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		if(aTipp==null)
			return null;
		return aTipp.betAmount;
	}

	//------------------------------------
	// returns the selected flag of the
	// choosen tippId
	//------------------------------------
	this.getTippByTippId=function(tippId) {
		var aTipp=this;		
		while(aTipp!=null) {
			if(aTipp.tippId==tippId)
				return aTipp.tipp;
			aTipp=aTipp.nextTipp;
		}
		return -1;
	}

	//------------------------------------
	// sets all tipps to the given status
	//------------------------------------
	this.setAllTippStati=function(stat) {
		var aTipp=this;		
		while(aTipp!=null) {
			aTipp.tippStatus=stat;
			aTipp=aTipp.nextTipp;
		}
	}	

	//------------------------------------
	// returns the tippId of the tipp
	// tipp: number of the tipp
	//------------------------------------
	this.getTippId=function(tipp) {
		var aTipp=this;
		var cnt=0;
		
		while((aTipp!=null)&&(aTipp.tippNr!=tipp)) {
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		if(aTipp==null)
			return null;
		return aTipp.tippId;
	}

	//------------------------------------
	// returns the tipp
	// tipp: number of the tipp
	//------------------------------------
	this.getTipp=function(tipp) {
		var aTipp=this;
		var cnt=0;
		
		while((aTipp!=null)&&(aTipp.tippNr!=tipp)) {
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		if(aTipp==null)
			return null;
		return aTipp.tipp;
	}

	//------------------------------------
	// returns the tippbox setting
	// 0...not activated, 1..is activated
	//------------------------------------
	this.getTippBox=function(tipp) {
		var aTipp=this;
		var cnt=0;
		
		while((aTipp!=null)&&(aTipp.tippNr!=tipp)) {
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		if(aTipp==null)
			return null;
		return aTipp.selected;
	}

	//------------------------------------
	// returns the tipp number
	// -1...not found
	//------------------------------------
	this.getTippNumberByTippId=function(tippId) {
		var aTipp=this;	
		var cnt=1;	
		while(aTipp!=null) {
			if(aTipp.tippId==tippId)
				return aTipp.tippNr;
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		return -1;
	}
	//------------------------------------
	// returns the tippbox setting
	// 0...not activated, 1..is activated
	// -1...not found
	//------------------------------------
	this.getTippBoxById=function(tippId) {
		var aTipp=this;	
		while(aTipp!=null) {
			if(aTipp.tippId==tippId)
				return aTipp.selected;
			aTipp=aTipp.nextTipp;
		}
		return -1;
	}

	//------------------------------------
	// returns the tippbox setting
	// returns quote or -1 (not found)
	//------------------------------------
	this.getQuoteById=function(tippId) {
		var aTipp=this;	
		while(aTipp!=null) {
			if(aTipp.tippId==tippId)
				return aTipp.quote;
			aTipp=aTipp.nextTipp;
		}
		return '-1';
	}	

	//------------------------------------
	// sets the quote
	//------------------------------------
	this.setQuoteById=function(tippId,quote) {
		var aTipp=this;	
		while(aTipp!=null) {
			if(aTipp.tippId==tippId)
				aTipp.quote=quote;
			aTipp=aTipp.nextTipp;
		}
	}

	//------------------------------------
	// sets the tipp box setting
	//------------------------------------
	this.setTippBox=function(tipp) {		
		var aTipp=this;
		var cnt=0;
		
		while((aTipp!=null)&&(aTipp.tippNr!=tipp)) {
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		if(aTipp==null)
			return null;
		if(aTipp.selected=='0') {
			aTipp.selected='1';
		} else {
			aTipp.selected='0';
		}
	}

	//------------------------------------
	// sets the tipp box setting
	//------------------------------------
	this.setTippBoxByNumber=function(tipp,selected) {		
		var aTipp=this;
		var cnt=0;
		
		while((aTipp!=null)&&(aTipp.tippNr!=tipp)) {
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		if(aTipp==null)
			return null;
		aTipp.selected=selected;
	}

	//------------------------------------
	// sets the betamount for given number
	//------------------------------------
	this.setBetAmountByNumber=function(tipp,amount) {		
		var aTipp=this;
		var cnt=0;		
		while((aTipp!=null)&&(aTipp.tippNr!=tipp)) {
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		if(aTipp==null)
			return null;
		aTipp.betAmount=amount;
	}

	this.getTippBoxString=function() {
		var tippBoxString="";
		var aTipp=this;	
		while(aTipp!=null) {
			tippBoxString=tippBoxString+aTipp.selected;
			aTipp=aTipp.nextTipp;
		}
		return tippBoxString;
	}	
	
	this.getStatusById=function(tippId) {
		var aTipp=this;	
		while(aTipp!=null) {
			if(aTipp.tippId==tippId)
				return aTipp.tippStatus;
			aTipp=aTipp.nextTipp;
		}
		return null;
	}

	this.setStatusById=function(tippId,status) {
		var aTipp=this;	
		while(aTipp!=null) {
			if(aTipp.tippId==tippId) {
				aTipp.tippStatus=status;
				return true;
			}
			aTipp=aTipp.nextTipp;
		}
		return false;
	}

	this.getStatusByTipp=function(tipp,tippList) {
		var aTipp=tippList;
		var cnt=0;
		
		while((aTipp!=null)&&(aTipp.tippNr!=tipp)) {
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		if(aTipp==null)
			return null;
		return aTipp.tippStatus;
	}

	this.setStatusByTipp=function(tipp,status) {
		var aTipp=this;
		var cnt=0;
		
		while((aTipp!=null)&&(aTipp.tippNr!=tipp)) {
			cnt++;
			aTipp=aTipp.nextTipp;
		}
		if(aTipp==null)
			return false;		
		aTipp.tippStatus=status;
		return true
	}

	//------------------------------------
	// counts tipps
	//------------------------------------
	this.checkSelectedBets=function(myTipps) {	
		var cnt=0;
		while(myTipps!=null) {
			cnt++;			
			myTipps=myTipps.nextTipp;
		}
		return cnt;
	}

	//------------------------------------
	// counts selected tipps)
	//------------------------------------
	this.countSelectedBets=function(myTipps) {	
		var cnt=0;
		while(myTipps!=null) {
			if(myTipps.selected=='1')
				cnt++;			
			myTipps=myTipps.nextTipp;
		}
		return cnt;
	}


	//------------------------------------
	// returns the tipp on given position
	//------------------------------------
	this.getTippByNumber=function(myTipps,tippNumber) {	
		var cnt=1;
		while(myTipps!=null) {
			if(myTipps.tippNr==tippNumber)
				return myTipps;
			cnt++;			
			myTipps=myTipps.nextTipp;
		}
		return null;
	}
	
	//------------------------------------
	// returns the tipp on given position
	//------------------------------------
	this.getTippByListNumber=function(myTipps,tippNumber) {	
		var cnt=1;
		while(myTipps!=null) {
			if(cnt==tippNumber)
				return myTipps;
			cnt++;			
			myTipps=myTipps.nextTipp;
		}
		return null;
	}
	
	//------------------------------------
	// returns the tipp on given position
	//------------------------------------
	this.getTippStatusByListNumber=function(myTipps,tippNumber) {	
		var cnt=1;
		//alert("myTipps="+myTipps);
		while(myTipps!=null) {
			//alert("cnt:"+cnt+"  tippNumber:"+tippNumber);
			if(cnt==tippNumber)
				return myTipps.tippStatus;
			cnt++;			
			myTipps=myTipps.nextTipp;
		}
		return -1;
	}	

	//------------------------------------
	// unselect tipps of a bet
	//------------------------------------
	this.unselectBets=function(myTipps,gameNumber) {	
		var aTipp=myTipps;
		var cnt=1;
		while(aTipp!=null) {
			aTipp.selected='0';
			if((eval('document.GAMES.tipp_'+gameNumber+'_'+cnt)!=undefined)&&(eval('document.GAMES.tipp_'+gameNumber+'_'+cnt)!=null))			
				eval('document.GAMES.tipp_'+gameNumber+'_'+cnt+'.checked=false');			
			cnt++;
			aTipp=aTipp.nextTipp;
		}
	}

	//------------------------------------
	// reset all bet amounts to default
	//------------------------------------
	this.resetBetAmounts=function(myTipps) {	
		var aTipp=myTipps;
		while(aTipp!=null) {
			aTipp.betAmount=defaultBetamount;
			aTipp=aTipp.nextTipp;
		}
	}

}

//------------------------------------
// set the tipp
//------------------------------------
function setTippBox(tipp) {
	this.setTippBox(tipp);
}	


//------------------------------------
// set bet amount by number
//------------------------------------
function setBetAmountByNumber(tipp,amount) {
	this.setBetAmountByNumber(tipp,amount);
}

//------------------------------------
// set the tipp
//------------------------------------
function setTippBoxByNumber(tipp,selected) {
	this.setTippBoxByNumber(tipp,selected);
}

//--------------------------------------
// returns the setting (selected or not)
// as string like 00101101
//--------------------------------------
function getTippBoxString() {
	this.getTippBoxString();
}	

//------------------------------------
// get the tipp
//------------------------------------
function getTippBox(tipp) {
	return this.getTippBox(tipp);
}

//------------------------------------
// set the tipp
//------------------------------------
function setTipp(tipp) {
	this.setTipp(tipp);
}	

//------------------------------------
// get the tipp
//------------------------------------
function getTipp(tipp) {
	return this.getTipp(tipp);
}

//------------------------------------
// get the tipp-setting (0,1)
//------------------------------------
function getTippBoxById(tippId) {
	return this.getTippBoxById(tippId);
}

//------------------------------------
// get the quote of the tipp
//------------------------------------
function getQuote(tipp) {
	return this.getQuote(tipp);
}

//------------------------------------
// get the betmoney of the tipp
//------------------------------------
function getBetMoney(tipp) {
	return this.getBetMoney(tipp);
}

//------------------------------------
// get the quote of the tipp by id
//------------------------------------
function getQuoteById(tippId) {
	return this.getQuoteById(tippId);
}

//--------------------------------------
// sets the status of this tipp of a bet
//--------------------------------------
function setStatusById(tippId,status) {
	this.setStatusById(tippId,status);
}

//--------------------------------------
// gets the status of this tipp of a bet
//--------------------------------------
function getStatusById(tippId) {
	return this.getStatusById(tippId);
}

//--------------------------------------
// gets the status by position number
//--------------------------------------
function getTippStatusByListNumber(myTipps,tippNr) {
	return this.getTippStatusByListNumber(myTipps,tippNr);
}

//--------------------------------------
// gets the status of this tipp of a bet
//--------------------------------------
function getStatusByTipp(tipp,tippList) {
	return this.getStatusByTipp(tipp,tippList);
}

//--------------------------------------
// counts all tipps
//--------------------------------------
function checkSelectedBets(myTipps) {
	return this.checkSelectedBets(myTipps);
}


//--------------------------------------
// counts all selected tipps
//--------------------------------------
function countSelectedBets(myTipps) {
	return this.countSelectedBets(myTipps);
}

//--------------------------------------
// sets the status of this tipp of a bet
//--------------------------------------
function setStatusByTipp(tipp,status) {
	return this.setStatusByTipp(tipp,status);
}

//--------------------------------------
// reset all betamounts tzo default
//--------------------------------------
function resetBetAmounts(myTipps) {
	return this.resetbetAmounts(myTipps);
}

//--------------------------------------
// unselect all tipps
//--------------------------------------
function unselectBets(myTipps) {
	return this.unselectBets(myTipps);
}

//------------------------------------
// set the quote by its tipp-id
//------------------------------------
function setQuoteById(tippId,quote) {
	return this.setQuoteById(tippId,quote);
}

//------------------------------------
// adds a tipp to the list
//------------------------------------
function addTipp(tipp) {
	this.addTipp(tipp);
}

function getTippNumberByTippId(tippId) {
	return this.getTippNumberByTippId(tippId);
}

