function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}


function numbersonly(myfield, e, dec) {
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
	    (key==9) || (key==13) || (key==27) )
	   return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;

	// decimal point jump
	else if (dec && (keychar == "."))
	   {
	   myfield.form.elements[dec].focus();
	   return false;
	   }
	else
	   return false;
}

function numbersonlyAndPoint(myfield, e, dec) {
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
	    (key==9) || (key==13) || (key==27) )
	   return true;

	// numbers
	else if ((("0123456789.").indexOf(keychar) > -1))
	   return true;

	// decimal point jump
	else if (dec && (keychar == "."))
	   {
	   myfield.form.elements[dec].focus();
	   return false;
	   }
	else
	   return false;
}

function price_change(Num, cena, nauda, txt) {
	
	var fullCena = 0;
	
	if (document.all){
		
		if (parseFloat(document.all[("prodCount_" + Num)].value)>0) {
			skaits=parseFloat(document.all[("prodCount_" + Num)].value);
		} else {
			skaits=0;
		}
		prodSum=CurrencyFormatted(cena*skaits);
		document.all[("prodSum_"+Num)].value = prodSum;
		fullCount=document.all[("fullCount")].value;
		for (i=1; i<=fullCount; i++) {
			fullCena=parseFloat(fullCena)+parseFloat(document.all[("prodSum_"+i)].value);

		}
		fullCena=parseFloat(fullCena)+parseFloat(document.all[("transp_sum")].value);
	}
	
	if (fullCena==0) {
		if (document.getElementById) {

			if (parseFloat(document.getElementById(("prodCount_" + Num)).value)>0) {
				skaits=parseFloat(document.getElementById(("prodCount_" + Num)).value);
				
			} else {
				skaits=0;
			}
			prodSum=CurrencyFormatted(cena*skaits);
			document.getElementById(("prodSum_"+Num)).value = prodSum;
			fullCount=document.getElementById(("fullCount")).value;
			for (i=1; i<=fullCount; i++) {
				fullCena=parseFloat(fullCena)+parseFloat(document.getElementById(("prodSum_"+i)).value);
				
			}
			fullCena=parseFloat(fullCena)+parseFloat(document.getElementById(("transp_sum")).value);
		}
	}
	
	
	
	document.getElementById('sum_'+Num).innerHTML=nauda+' '+prodSum;

	document.getElementById('final_sum').innerHTML=txt+": <span>"+nauda+" "+(CurrencyFormatted(fullCena))+"</span>";
	
	return true;
	
}


function transport_price_change(nauda, txt) {
	
	var transpID=0;
	var transpPrice = 0;
	var fullCena = 0;
	
	if (document.all){

		transpID=document.getElementById("transportType").options[document.all("transportType").selectedIndex].value;

		transpPrice=document.all[("transportType"+transpID)].value;
		document.all[("transp_sum")].value = (CurrencyFormatted(transpPrice));		
		
		fullCount=document.all[("fullCount")].value;
		for (i=1; i<=fullCount; i++) {
			fullCena=parseFloat(fullCena)+parseFloat(document.all[("prodSum_"+i)].value);

		}
		fullCena=parseFloat(fullCena)+parseFloat(document.all[("transp_sum")].value);
	}
	
	if (fullCena==0) {
		if (document.getElementById) {
			
			transpID=document.getElementById("transportType").options[document.getElementById("transportType").selectedIndex].value;
			transpPrice=document.getElementById(("transp_"+transpID)).value;
			document.getElementById(("transp_sum")).value = (CurrencyFormatted(transpPrice));
			
			fullCount=document.getElementById(("fullCount")).value;
			for (i=1; i<=fullCount; i++) {
				fullCena=parseFloat(fullCena)+parseFloat(document.getElementById(("prodSum_"+i)).value);
				
			}
			fullCena=parseFloat(fullCena)+parseFloat(document.getElementById(("transp_sum")).value);
		}
	}
	
	
	if (transpID>0) {
		document.getElementById('transp').innerHTML=nauda+' '+(CurrencyFormatted(transpPrice));
	} else {
		document.getElementById('transp').innerHTML='';
	}
	document.getElementById('final_sum').innerHTML=txt+": <span>"+nauda+" "+(CurrencyFormatted(fullCena))+"</span>";
	
	return true;
	
}


function deleteProd(url)
{
  document.countForm.submit();
}


