function Cena(cenaPocz, liczbaUczest)
{
	var cenaPocz = cenaPocz;
	var cenaAkt = cenaPocz;
	var liczbaUczest = liczbaUczest;
	var cenaInput;
	var poleCeny;	// pole do wyswietlania ceny
	var rabat;
	var wartoscPromocjiStalych;
	var promocjeOpcjCheckBoxes;
	
	this.getCenaPocz = function()
	{ return cenaPocz; };
	
	this.getCenaAkt = function()
	{ return cenaAkt; }
	
	this.setCenaAkt = function(cenaVal)
	{ cenaAkt = cenaVal; };
	
	
	this.getPoleCeny = function()
	{return poleCeny.innerHTML; }
	
	this.setPoleCeny = function(val)
	{ 
		poleCeny.innerHTML = val.toFixed(2) +" zł";
		this.setCenaInputValue(val.toFixed(2));
	}
	
	
	this.getCenaInputValue = function()
	{ return cenaInput.value; };
	
	this.setCenaInputValue = function(cena)
	{ cenaInput.value = cena; };
	
	
	this.getLiczbaUczest = function()
	{ return liczbaUczest; }
	
	
	this.getRabat = function(indx)
	{ 
		if(indx < rabat.length)
			return rabat[indx];
	}
	
	this.rabatLength = function()
	{ return rabat.length; }
	
	
	this.getWartoscPromocjiStalych = function()
	{ return wartoscPromocjiStalych; }
	
	
	this.promocjeOpcjCheckBoxesLength = function()
	{ return promocjeOpcjCheckBoxes.length; }
	
	
	this.getPromocjeOpcjCheckBox = function(indx)
	{
		if(indx < promocjeOpcjCheckBoxes.length)
			return promocjeOpcjCheckBoxes[indx];
	}
	
	
	this.wyswietl = function(gdzieId)
	{
		gdzie = document.getElementById(gdzieId);
		gdzie.innerHTML = cenaAkt +" zł";
	}

	
	this.init = function(cenaInputId, poleCenyId, promocjeStaleValue, promocjeOpcjCheckBoxesArr, rabatArr) //function(poleCheckBox, wart)
	{
		cenaInput = document.getElementById(cenaInputId);
		poleCeny = document.getElementById(poleCenyId);
		rabat = rabatArr;
		wartoscPromocjiStalych = promocjeStaleValue;
		promocjeOpcjCheckBoxes = promocjeOpcjCheckBoxesArr;
		
		this.aktualizujCene();
		
		/*
		if(poleCheckBox.checked)
			this.setWartosc(this.getWartosc() + wart);
			
		this.setWybranaCena(this.getWartosc());
		*/
	}
}

// aktualizacja ceny, bazujaca na liczbie wprowadzonych uczestnikow (rabat)
// oraz na dostepnych promocjach
Cena.prototype.aktualizujCene = function()
{
	var liczbaWpisanychUczest = 0;
	for(var i=0; i<this.getLiczbaUczest(); i++)
	{
		if(document.getElementById('Imie_'+ i) && document.getElementById('Imie_'+ i).value != "" 
			&& document.getElementById('Nazwisko_'+ i) && document.getElementById('Nazwisko_'+ i).value != "")
		{
			liczbaWpisanychUczest = liczbaWpisanychUczest + 1;
		}
	}
	
	
	this.setCenaAkt(this.getCenaPocz());	// rozpoczynamy wyliczenie ceny od ceny poczatkowej
	if(liczbaWpisanychUczest > 0)
	{
		// jezeli wpisalismy chociaz jednego uczestnika, cena szkolenia jest mnozona przez ich liczbe
		this.setCenaAkt(this.getCenaPocz() * liczbaWpisanychUczest);
		
		var bylRabat = false;
		for(i=0; i<this.rabatLength() && !bylRabat; i++)
		{
			var rabatElem = this.getRabat(i);
			if(liczbaWpisanychUczest >= rabatElem[0] && liczbaWpisanychUczest <= rabatElem[1])
			{
				this.setCenaAkt(this.getCenaPocz() - this.getCenaPocz()*rabatElem[2]);
				bylRabat = true;	// koniec przydzielania rabatu
			}
		}
	}
	
	// uwzglednianie promocji stalych
	this.setCenaAkt(this.getCenaAkt() + this.getWartoscPromocjiStalych());
	
	// uwzglednienie promocji opcjonalnych, jezeli zotaly wybrane
	for(i=0; i<this.promocjeOpcjCheckBoxesLength(); i++)
	{
		var checkBox = document.getElementById(this.getPromocjeOpcjCheckBox(i));
		if(checkBox.checked)
			this.setCenaAkt(this.getCenaAkt() + parseInt(checkBox.value));
	}
	
	this.setPoleCeny(this.getCenaAkt());
	
	/*
	if(poleCheckBox.checked)
		this.setWartosc(this.getWartosc() + wart);
	else
		this.setWartosc(this.getWartosc() - wart);
		
	this.setWybranaCena(this.getWartosc());
	*/
}