//<?php
/**
*	@package    JavaScript
*	@author     Josef Doležal <josef.dolezal@abeo.cz>
*	@author     Jan Mazánek <jan.mazanek@abeo.cz>
*	@copyright  1997-2005 Abeo s.r.o.
*	@since      20050222, version 1.22.123
*	@todo       20050313, jamaz;To:Dolo: ošetření chybových stavů
*	@internal   charset: UTF-8
*	@version    SVN: $Id: calculator.js 7330 2007-08-11 19:25:57Z jan-mazanek $
*/

/**
*/
function sum_total(rows_count, rows_count_total, CalculatorRowMultiplier) {
	var TheContainer=document.getElementById('CalculatorRowSubtotalContainer'+rows_count);
	TheContainer.value=Math.round(document.getElementById('CalculatorRowPrice'+rows_count).value*CalculatorRowMultiplier);
	replaceText(
		document.getElementById('CalculatorRowSubtotal'+rows_count),
		format_currency(TheContainer.value)+',00 Kč'
	);
	total=0;
	for(i=1; i<=rows_count_total; i++) {
		total+=parseInt(document.getElementById('CalculatorRowSubtotalContainer'+i).value);
		total=Math.round(total);
	}
	replaceText(
		document.getElementById('CalculatorTotal'),
		format_currency(total)+',00 Kč'
	);
}

function replaceText(node, text)
{
    while (node.hasChildNodes()) {
        node.removeChild(node.firstChild);
    }
    node.appendChild(document.createTextNode(text));
}

function format_currency(input)
{
	number = new String(input);
	result='';
	for(a=0; a<number.length; a=a+3)
	{
	result=number.substring(number.length-a-3,number.length-a)+" "+result;
	}
	return result;
}

// kontrola zadani INT

function validInt(formField)
{
		var result = true;
		if (!allDigits(formField.value))
 		{
 			alert('Tato položka může obsahovat jen čísla!');
			formField.value='';
			formField.focus();		
			result = false;
		}
	
	return result;
}

function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
	var result = true;

	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}
//?>
