function pridajbonus(jazyk){
	with(window.document.formular)
	{
		var pozicia, retazec, cena, nazov;
		var tolerancia = new Array();
		var hlaska = new Array();
		
		tolerancia = 1.00;	
		hlaska = "Price is higher than bonus value. Allowable exceeding of bonus price is  " + tolerancia + ",- EUR.";

		
		retazec = bonus.options[bonus.selectedIndex].value;
		pole = retazec.split('#');
		idecko = pole[0];
		cena = pole[1];
		nazov = pole[2];
		zost_bonus =  eval(parseInt(zostavajuci_bonus.value) + parseInt(tolerancia));

		if( zost_bonus < parseInt(cena)){
			alert(hlaska);
		}
		else{
			window.document.getElementById('bonusove_pole').innerHTML += '<div class="bonus_item"><strong>Bonus:</strong> '+ nazov + '<input type="hidden" name="bonus[]" value="'+ idecko + '" /></div>';
			zostavajuci_bonus.value = desatina(zostavajuci_bonus.value - cena);
		}
	}
}

function desatina(cislo)
{
	cislo = cislo.toString();
	kam = cislo.indexOf('.');
			
	if(kam==-1) return cislo+'.0';
	else return cislo.substring(0,kam+2);
}

function del_bonus(cislo){
	document.getElementById('bonusove_pole').innerHTML = '';
	document.getElementById('zb').value = cislo;
}

function zobraz_skry(id){
	el=document.getElementById(id).style;
	el.display=(el.display == 'block')?'none':'block';
}

function zobraz_id(id){
	el=document.getElementById(id).style;
	el.display = 'block';
}
function skry_id(id){
	el=document.getElementById(id).style;
	el.display = 'none';
}

function zap_cookie(meno, hodnota){	
	var expires = "";
	document.cookie = meno+"="+hodnota+expires+"; path=/";
}

function skry(){document.getElementById("blok").style.display= "none";}

function fromTop() {
	if (window.innerHeight) {return (window.pageYOffset)}
	else if (document.documentElement && document.documentElement.scrollTop) {return (document.documentElement.scrollTop)}
	else if (document.body) {return (document.body.scrollTop)}
}

function zobraz() {
 	if(window.document.getElementById('iframe')!=null)
	{
		var y = height();
		var x = width();
		document.getElementById("blok").style.top = Math.round(y/2)+fromTop()+'px';  
		document.getElementById("blok").style.left = Math.round(x/2) + 'px';
		return true;
	}
	else
	{
		window.alert('Page is loading, please wait!');
		return false;
	}	

}

function height() {
   if (window.innerHeight)
      return window.innerHeight;
   else if(document.documentElement && document.documentElement.clientHeight)
   		return document.documentElement.clientHeight;
   else if(document.body && document.body.clientHeight)
   		return document.body.clientHeight;
   else
      return null;
}



function width() {
   if (window.innerWidth)
      return window.innerWidth;
   else if(document.documentElement && document.documentElement.clientWidth)
      return document.documentElement.clientWidth;
   else if(document.body && document.body.clientWidth)
   	  return document.body.clientWidth;
   else
      return null;
}

function checkform(){
	var spravny = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	
	with(window.document.formular)
	{
		if(trim(meno.value) == '')
		{
			alert('Fill in name.');
			meno.focus();
			return false;
		}
		else if((trim(meno.value)).length < 3)
		{
			alert('Name is too short.');
			meno.focus();
			return false;
		}
		else if(trim(priezvisko.value) == '')
		{
			alert('Fill in surname.');
			priezvisko.focus();
			return false;
		}
		else if((trim(priezvisko.value)).length < 3)
		{
			alert('Surname is too short.');
			priezvisko.focus();
			return false;
		}
		else if(trim(ulica.value) == '')
		{
			alert('Fill in street adress.');
			ulica.focus();
			return false;
		}
		else if(trim(mesto.value) == '')
		{
			alert('City is too short.');
			mesto.focus();
			return false;
		}
		else if((trim(mesto.value)).length < 2)
		{
			alert('Fill in city.');
			mesto.focus();
			return false;
		}
		else if(trim(psc.value) == '')
		{
			alert('Fill in ZIP / Postal code.');
			psc.focus();
			return false;
		}
		else if(trim(krajina.value) == '')
		{
			alert('Fill in country.');
			krajina.focus();
			return false;
		}
		else if(!(spravny.test(email.value)))
		{
			alert('Wrong form of the e-mail address.');
			email.focus();
			email.select();
			return false;
		}
		else return true;
	}
}


function checkobj(){
	var hlaska = new Array();
	

	hlaska = new Array(4);
	hlaska[1] = 'Please select relevant method of delivery.',
	hlaska[2] = 'Please select preferred payment method.';
	hlaska[3] = 'Please specify: Replace unavailable species with another similar one?';

with(window.document.formular)
	{
		var pay_flag = 0;
		var dor_flag = 0;
		var all_checks = getElementsByTagName('input');
		
		for (var x=0;x<all_checks.length;x++) {
			if (all_checks[x].name == 'postmethod' && all_checks[x].checked) dor_flag++;
			if (all_checks[x].name == 'paymethod' && all_checks[x].checked) pay_flag++;
		}
		
		if (!dor_flag)
		{
			alert(hlaska[1]);
			return false;
		}
		
		if (!pay_flag)
		{
			alert(hlaska[2]);
			return false;
		}
		
		if(document.getElementById('ano').checked==false && document.getElementById('ne').checked==false)
		{
			alert(hlaska[3]);
			return false;			
		}
		else return true;
		
	}
}

function trim(str)
{
    return str.replace(/^\s+|\s+$/g,'');
}

function anonie(text)
{
pokracovat = confirm(text);
if(!pokracovat) return false;
}


function f_certificat(cena)
{
	if(window.document.formular.certificat.checked==true) window.document.formular.h_certificat.value = cena;
	else window.document.formular.h_certificat.value = 0;
	deselect_radio();
	pocitaj();
}

function postovne(cena)
{
	window.document.formular.h_posta.value = cena;	
	deselect_radio();
	pocitaj();
}

function charge(co,cena)
{
	if(co.checked==true)
		window.document.formular.h_charge.value = parseInt(window.document.formular.h_charge.value) + parseInt(cena);
	else
		window.document.formular.h_charge.value = parseInt(window.document.formular.h_charge.value) - parseInt(cena);
	deselect_radio();
	pocitaj();
}

function pay(cena, percento)
{
	if(percento==0) window.document.formular.h_pay.value = cena;
	else window.document.formular.h_pay.value = Math.ceil((parseInt(window.document.formular.h_medzisucet.value) + parseInt(window.document.formular.h_posta.value) + parseInt(window.document.formular.h_certificat.value)) * (parseFloat(percento)/100));
	
	pocitaj();
}

function pocitaj()
{
	kurz = window.document.formular.h_kurz.value;
	cena = Math.ceil(parseInt(window.document.formular.h_medzisucet.value) + parseInt(window.document.formular.h_posta.value) + parseInt(window.document.formular.h_pay.value) + parseInt(window.document.formular.h_charge.value) + parseInt(window.document.formular.h_certificat.value));
	
	document.getElementById('mainCurrency').innerHTML = cena;
	
	if(kurz!=1) document.getElementById('otherCurrency').innerHTML = Math.ceil(kurz*cena);
}

function deselect_radio(){
	with(window.document.formular)
	{
		var all_checks = getElementsByTagName('input');
		
		for (var x=0;x<all_checks.length;x++) {
			if (all_checks[x].name == 'paymethod') all_checks[x].checked=false;
		}
		window.document.formular.h_pay.value = 0;
		pocitaj();
	}
}


function expand(name) {

document.getElementById(name).style.width = '500px';
}

function contract(name) {
document.getElementById(name).style.width = '500px';

}

/***********************************************
* Dynamic Countdown script- © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function cdtime(container, curentdate, targetdate){
if (!document.getElementById || !document.getElementById(container)) return
this.container=document.getElementById(container)
this.currentTime=new Date(curentdate*1000)
this.targetdate=new Date(targetdate*1000)
this.timesup=false
this.updateTime()
}

cdtime.prototype.updateTime=function(){
var thisobj=this
this.currentTime.setSeconds(this.currentTime.getSeconds()+1)
setTimeout(function(){thisobj.updateTime()}, 1000) //update time every second
}

cdtime.prototype.displaycountdown=function(baseunit, functionref){
this.baseunit=baseunit
this.formatresults=functionref
this.showresults()
}

cdtime.prototype.showresults=function(){
var thisobj=this


var timediff=(this.targetdate-this.currentTime)/1000 //difference btw target date and current date, in seconds
if (timediff<0){ //if time is up
this.timesup=true
this.container.innerHTML=this.formatresults()
return
}
var oneMinute=60 //minute unit in seconds
var oneHour=60*60 //hour unit in seconds
var oneDay=60*60*24 //day unit in second
var dayfield=Math.floor(timediff/oneDay)
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour)
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute)
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute))
if (this.baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
hourfield=dayfield*24+hourfield
dayfield="n/a"
}
else if (this.baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
minutefield=dayfield*24*60+hourfield*60+minutefield
dayfield=hourfield="n/a"
}
else if (this.baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
var secondfield=timediff
dayfield=hourfield=minutefield="n/a"
}
this.container.innerHTML=this.formatresults(dayfield, hourfield, minutefield, secondfield)
setTimeout(function(){thisobj.showresults()}, 1000) //update results every second
}

function formatresults(){
if (this.timesup==false){//if target date/time not yet met
var displaystring="<strong>"+arguments[0]+"</strong>d "+"<strong>"+arguments[1]+"</strong>h "+"<strong>"+arguments[2]+"</strong>m "+"<strong>"+arguments[3]+"</strong>s"
}
else{ //else if target date/time met
var displaystring=window.location.reload();
}
return displaystring
}
