function FreeBonus(iIdZonerCz_Bonus)
{
	if(!document.getElementById(iIdZonerCz_Bonus).checked) document.getElementById(iIdZonerCz_Bonus).checked = true;
}

function ChangePrice(iPrice, iPriceDph, iIdZonerCz_Bonus, iIdZonerCz)
{
	var sElementPrice = "price" + iIdZonerCz;
	var sElementPriceDph = "pricedph" + iIdZonerCz;

	var sActualPrice = String(document.getElementById(sElementPrice).value).replace(/\s+/g,'');
	var sActualPriceDph = String(document.getElementById(sElementPriceDph).value).replace(/\s+/g,'');

	var iActualPrice = parseInt(sActualPrice);
	var iActualPriceDph = parseInt(sActualPriceDph);

	if(document.getElementById(iIdZonerCz_Bonus).checked)
	{
		iActualPrice = iActualPrice + iPrice;
		iActualPriceDph = iActualPriceDph + iPriceDph;
	}
	else
	{
		iActualPrice = iActualPrice - iPrice;
		iActualPriceDph = iActualPriceDph - iPriceDph;
	}

	sActualPrice = String(iActualPrice);
	sActualPriceDph = String(iActualPriceDph);

	sActualPrice = Currency(sActualPrice);
	sActualPriceDph = Currency(sActualPriceDph);	

	document.getElementById(sElementPrice).value = sActualPrice;
	document.getElementById(sElementPriceDph).value = sActualPriceDph;
}

function Mirror(sText)
{
	var sMirror = "";
	for(var i = 0; i < sText.length; i++)
	{
		sMirror = sText.substring(i,i+1) + sMirror;
	}
	return sMirror;
}

function Currency(sPrice)
{
	if(sPrice.length > 3)
	{
		var sPriceMirror = Mirror(sPrice);
		var sMirrorTemp = "";

		sPrice = "";
		while(sPriceMirror.length > 3)
		{
			sMirrorTemp = sPriceMirror.substring(0,3);
			sPriceMirror = sPriceMirror.replace(sMirrorTemp, '');
			sPrice = sPrice + sMirrorTemp + ' ';
		}
		sPrice = sPrice + sPriceMirror;
		sPrice = Mirror(sPrice);
	}
	return sPrice;
}

function isValid()
{
	if(document.getElementById('nazev').value=="")
	{
		window.alert("Proszę uzupelnić nazwę");
		document.getElementById('nazev').style.backgroundColor = "#ffb0b0";
		document.getElementById('nazev').focus();
		return false;
	}
	else if(document.getElementById('adresa1').value=="")
	{
		window.alert("Proszę uzupelnić adres");
		document.getElementById('adresa1').style.backgroundColor = "#ffb0b0";
		document.getElementById('adresa1').focus();
		document.getElementById('nazev').style.backgroundColor = "#ffffff";
		return false;
	}
	else if(document.getElementById('mesto').value=="")
	{
		window.alert("Proszę uzupelnić miasto");
		document.getElementById('mesto').style.backgroundColor = "#ffb0b0";
		document.getElementById('mesto').focus();
		document.getElementById('adresa1').style.backgroundColor = "#ffffff";
		return false;
	}
	else if(document.getElementById('psc').value=="")
	{
		window.alert("Proszę uzupelnić numer kierunkowy");
		document.getElementById('psc').style.backgroundColor = "#ffb0b0";
		document.getElementById('psc').focus();
		document.getElementById('mesto').style.backgroundColor = "#ffffff";
		return false;
	}
	else if(document.getElementById('osoba').value=="")
	{
		window.alert("Proszę uzupelnić osobę kontaktową");
		document.getElementById('osoba').style.backgroundColor = "#ffb0b0";
		document.getElementById('osoba').focus();
		document.getElementById('psc').style.backgroundColor = "#ffffff";
		return false;
	}
	else if(document.getElementById('telefon').value=="")
	{
		window.alert("Proszę uzupelnić telefon");
		document.getElementById('telefon').style.backgroundColor = "#ffb0b0";
		document.getElementById('telefon').focus();
		document.getElementById('osoba').style.backgroundColor = "#ffffff";
		return false;
	}
	else if(!checkEmail(document.getElementById('email').value))
	{
		window.alert("Proszę uzupelnić adres email");
		document.getElementById('email').style.backgroundColor = "#ffb0b0";
		document.getElementById('email').focus();
		document.getElementById('telefon').style.backgroundColor = "#ffffff";
		return false;
	}
	else if(document.getElementById('platba').value=="0")
	{
		window.alert("Proszę uzupelnić sposób płatności");
		document.getElementById('platba').style.backgroundColor = "#ffb0b0";
		document.getElementById('platba').focus();
		document.getElementById('email').style.backgroundColor = "#ffffff";
		return false;
	}
	else
	{
		document.getElementById('platba').style.backgroundColor = "#ffffff";
		return true;
	}
}

function checkEmail(address)
{
  re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
  return address.search(re) == 0;
}

