function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function CalculatePrice(articleID,pricesByAmounts, obj, blAmountPrices, currency, multiplier, calculateEuros, stock, description)
{
	var priceField = 'newprice'+articleID;
	var sumfield = 'sumfield'+articleID;
	var priceFieldEUR = 'newpriceEUR'+articleID;
	var priceLine  = 'priceLine'+articleID;
	var priceLineElement;
	var tmpPriceLineElement;

	var amount = obj.value;
	
	if (amount == '')
		return false;
		
	
	
	if (!IsNumeric(amount) || amount<=0)
	{
		alert(amount_alert);
		obj.value = '1';
	}
	
	amount = parseInt(obj.value);
	
	
	var checkStock = false;
	if (stock && IsNumeric(stock))
	{
		checkStock = true;		
	}
	
	if (checkStock &&  stock<multiplier*amount)
	{
		alert(description);
		obj.value = '1';
		return false;
	}
		
	var amountBefore=0;
	var amountNow;
	var price;
	for(i=0;i<pricesByAmounts.length; i++) 
	{
		amountNow = parseInt(pricesByAmounts[i][0]);	
		tmpPriceLineElement = priceLine + amountNow;
		if (amountNow <= amount)
		{ 
			priceString = new String(pricesByAmounts[i][1]);
			//converting from string format to number format
			priceString = priceString.replace(",",'.');

			price = parseFloat(priceString)*amount*multiplier;
			priceForOne = parseFloat(priceString);
			priceInEUR = price*euroCurrencyRate;
			if (currency=="Ls" || currency=="LS" || currency=="LT" || currency=="Lt")
				price = Number(price).toFixed(2);
				
			//converting from number format to string format
			s = new String(price);
			s = s.replace(".",',');
			price = s;
			priceLineElement = priceLine + amountNow;
			
			//converting from number format to string format
			//EUR
			priceInEUR = Number(priceInEUR).toFixed(2);
			sEUR = new String(priceInEUR);
			sEUR = sEUR.replace(".",',');
			priceInEUR = sEUR;
		}
		if (blAmountPrices==1)
		{
			document.getElementById(tmpPriceLineElement).style.color = '#999999';
			document.getElementById(tmpPriceLineElement).style.background = '#ffffff';
			//document.getElementById(tmpPriceLineElement).style.border = '1px solid #F7F3D0';
		}
		
	}
	if (blAmountPrices==1)
	{
		document.getElementById(priceLineElement).style.color = '#333333';
		document.getElementById(priceLineElement).style.background = '#DFDFCF';
		//document.getElementById(priceLineElement).style.border = '1px solid #D8C47E';
	}
	else 
	{
		if (blAmountPrices==2)
		{
			document.getElementById(sumfield).innerHTML =amount+" x "+priceForOne+" "+currency;
		}
	}
	
	document.getElementById(priceField).innerHTML =price+" " +currency;
	if (calculateEuros)
	{
		//document.getElementById(priceFieldEUR).innerHTML =priceInEUR+" "+euroCurrencySign;
	}
}

function calculateAmount(quantityIdent, sxordamount, quantity, measurement, additionaltext)
{
	qty = parseFloat(sxordamount * quantity);
	qty = Number(qty).toFixed(2);
	qty = new String(qty);
	qty = qty.replace(".",',');
	
	if (!additionaltext)
	{
		additionaltext = '';
	}
	$('#'+quantityIdent).html(additionaltext + qty+'&nbsp;'+measurement);
}
function checkAllAmounts()
{
	sarasas = document.getElementsByName('markedItems[]');
	if (sarasas) 
	{
		for (i=0; i<sarasas.length; i++) 
		{
		 	f = eval('document.'+sarasas[i].value);
			if (f.am.value>0) 
			{
			   if (!checkAmount(f.anid.value, f.tr.value, true))
				{
					return false;
				}
			}
		}
	}
	return true;
}

function disableBuyButton(btnIdent, formIdent)
{
	$("#"+btnIdent).attr("disabled","disabled");
	if (formIdent)
	{
		document.getElementById(formIdent).submit();
	}
}

function deleteArticle(aid, trgr)
{
	$('#deleteArticle input[@name=tr]').val(trgr);
	$('#deleteArticle input[@name=aid]').val(aid);
	$('#deleteArticle').submit();
}

