konverzny_kurz = 30.126;
euro_sign = "&#8364;";

max_chars = typeof ( max_chars ) == "undefined" ? 200 : max_chars;
chars_left = typeof ( chars_left ) == "undefined" ? 200 : chars_left;

function cl ()
{
	var obj = document.getElementById ( 'adresat_text_priania' );
	var strlen = obj.value.length;

	if ( strlen > max_chars )
	{
		obj.value = obj.value.substring ( 0, max_chars );
		chars_left = 0;
	}else chars_left = max_chars - strlen;                              

	var obj2 = document.getElementById ( 'adresat_text_priania_celkom' );

	obj2.innerHTML = chars_left;
}

function FormatujCislo ( cislo )
{
	cislo += '';
	x = cislo.split ( '.' );
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;

	while ( rgx.test ( x1 ) )
	{
		x1 = x1.replace ( rgx, '$1' + ' ' + '$2' );
	}

	cislo = x1 + x2;
	cislo = cislo.replace ( ".", "," );

	var dpos = cislo.indexOf ( "," );
	if ( dpos == -1 )
	{
		cislo += ",00";
	}else if ( dpos == cislo.length - 2 )
	{
		cislo += "0";
	}	

	return cislo;
}

function FormatujCenu ( cena, nosign, sk_too )
{
	cena = Math.round ( cena * 100 ) / 100;

	cenas = FormatujCislo ( cena );

	if ( !nosign )
	{
		cenas += " " + euro_sign;
	}

	return cenas;
}

function FormatujCenuSk ( cena, nosign )
{
	cena = Math.round ( cena * konverzny_kurz * 100 ) / 100;

	cenas = FormatujCislo ( cena );

	if ( !nosign )
	{
		cenas += " Sk";
	}

	return cenas;
}

function PrepocitajCenu ( o )
{
	var oform = o.form;
	var oamount = oform.elements["kusov"];
	var osize = oform.elements["velkost"];
	var sizec = osize.length;	
	var amount = oamount.options[oamount.selectedIndex].value;
	var size = 0;

	if ( typeof sizec == "undefined" )
	{
		size = osize.value;
	}else
	{
		for ( var i=0; i<sizec; i++ )
		{
			var oradio = osize[i];

			if ( oradio.checked )
			{
				size = oradio.value;
			}
		}
	}

	var price = sizeprice[size];
	var price_total = amount * price;

	var oprice_total = document.getElementById ( "price_total" );
	oprice_total.innerHTML = FormatujCenu ( price_total, false, true );
}

function Sebe(elem)
{
	var prnt1 = document.getElementById("prnt1");
	var prnt2 = document.getElementById("prnt2");
	var prijemca = document.getElementById("prijemca");
	var objednavatel = document.getElementById("objednavatel");
	var stat = document.getElementById("stat");
	var stat_poznamka = document.getElementById("stat_poznamka");
	var krajina = document.getElementById("krajina");

	if (elem.value == 1) {
		prijemca.style.display = "none";
		prnt1.appendChild(objednavatel);
		objednavatel.firstChild.style.display = "none";
		stat.style.display = "none";
		stat_poznamka.style.display = "none";
		krajina.firstChild.style.display = "none";
		krajina.firstChild.nextSibling.style.display = "";
	}else {
		prnt2.appendChild(objednavatel);
		objednavatel.firstChild.style.display = "";
		stat.style.display = "";
		stat_poznamka.style.display = "";
		krajina.firstChild.style.display = "";
		krajina.firstChild.nextSibling.style.display = "none";
		prijemca.style.display = "";
	}
}
