function Slip(Amount)
{
	this.Amount=Amount;
	this.WinnedAmount = 0.0;
	
	this.Formulas = new Array(arguments.length-1);
	for(i=0;i<arguments.length-1;i++)
	{
		this.Formulas[i]=arguments[i+1];
	}
	this.addFormula = function()
	{
		this.Formulas.push(arguments[0]);
	}
	
	this.Bankers = new Array(0);
	this.addBanker = function()
	{
		this.Bankers.push(arguments[0]);
	}
	this.bankerK = function()
	{
		var banK = 1.0;
		for (i=0;i<this.Bankers.length;i++ )
		{
			banK *= this.Bankers[i].k;
		}
		return banK;
	}
	
	this.slipK = function()
	{
		var slK=1.0; var V= 1.0;
		var fCount =this.Formulas.length; 
		for (iFrml=0;iFrml<fCount;iFrml++)
		{
			slK *= this.Formulas[iFrml].formulaK();
			
		}
		for (j=0;j<fCount;j++)
		{
			V *= parseInt(this.Formulas[j].v);
		}
		
		if (this.bankerK() != 0.0 )
		{
			slK *= this.bankerK();
		}
		this.WinnedAmount = this.Amount * slK / V;
		return slK; 
	}
	
	this.MaxVarK = function()
	{
	    var slMVK = 1.0;
	    var fc = this.Formulas.length; 
	    for(var iFC = 0; iFC<fc;iFC++)
	    {
	        slMVK *= this.Formulas[iFC].MaxK();
	    }
	    if (this.bankerK() != 0.0 )
		{
			slMVK *= this.bankerK();
		}
		return slMVK;
	}
	
	
	this.changeM = function()
	{
		var fID = parseInt(arguments[0]);
		var nM = parseInt(arguments[1]);
		
		for(iFrm=0;iFrm<this.Formulas.length;iFrm++)
		{
			if(this.Formulas[iFrm].id==fID)
			{
				this.Formulas[iFrm].m=nM;
			}
		}
	}
	
	
	this.addLine = function()
	{
		var IsBanker=parseInt(arguments[0]);
		if (IsBanker==1)
		{
			var bankerSlip = new SlipLine(parseFloat(arguments[1]));
			this.Bankers.push(bankerSlip);
		} 
		else
		{
			var formulaN = parseInt(arguments[1]);
			var blockN = parseInt(arguments[2]);
			var oddsK = parseFloat(arguments[3]);
			var newM = parseInt(arguments[4]);
			
			var otherSlip = new SlipLine(oddsK);
			
			var isFormulaFounded = 0; var indexOfFormula=-1;
			for (iForm =0;iForm<this.Formulas.length;iForm++)
			{
				if(this.Formulas[iForm].id==formulaN)
				{
					isFormulaFounded = 1;
					indexOfFormula=iForm;
					break;
				}
			}
			var isBlockFounded = 0; var indexOfBlock=-1;
			if(isFormulaFounded == 1)
			{
				for (iBlock=0;iBlock<this.Formulas[indexOfFormula].Blocks.length;iBlock++)
				{
					if(this.Formulas[indexOfFormula].Blocks[iBlock].id==blockN)
					{
						isBlockFounded=1;
						indexOfBlock=iBlock;
						break
					}
				}
				if(isBlockFounded == 1)
				{
					this.Formulas[indexOfFormula].Blocks[indexOfBlock].addLine(otherSlip);
					this.Formulas[indexOfFormula].m=newM;
				}
				else
				{
					var newBlock = new Block(blockN);
					newBlock.addLine(otherSlip);
					this.Formulas[indexOfFormula].addBlock(newBlock);
					this.Formulas[indexOfFormula].m=newM;
				}
			}
			else
			{
				var newFormula = new Formula(formulaN,newM);
				var newBlock1 = new Block(blockN);
				newBlock1.addLine(otherSlip);
				newFormula.addBlock(newBlock1);
				this.addFormula(newFormula);
			}
			
		}
		
	}
}