﻿kurz = 30.1260;
var valuta;
cislo = '';

function ZmazSumy(){
	document.getElementById("SKK").value = '';
	document.getElementById("EUR").value = '';            
	cislo = '';
}

function VyberMenu(mena){
  if (mena == 'SKK'){	
	document.getElementById("EUR").style.background = 'white';
	document.getElementById("SKK").style.background = '#dfdfdf';  
	document.getElementById("SKK").focus();
	valuta = 'SKK';
	cislo = '';
  } else {
	document.getElementById("SKK").style.backgroundColor = 'white';
	document.getElementById("EUR").style.backgroundColor = '#dfdfdf';
	document.getElementById("EUR").focus();
	valuta = 'EUR';
	cislo = '';
  }
}

function backspace(){
 var InputPole, Presnost = 2, Pom;
	  if (valuta == 'SKK'){document.getElementById("SKK").value = document.getElementById("SKK").value.toString().substring(0,document.getElementById("SKK").value.toString().length-1);}
	  if (valuta == 'EUR'){document.getElementById("EUR").value = document.getElementById("EUR").value.toString().substring(0,document.getElementById("EUR").value.toString().length-1);}
	    
	    
	if (valuta == 'SKK'){
	 cislo = document.getElementById("SKK").value; 
   document.getElementById("SKK").value = cislo;
     
  Pom = cislo / kurz;
  Pom = Math.round((Pom*Math.pow(10,Presnost)))/(Math.pow(10,Presnost));  
  Pom = Pom.toFixed(Presnost);
	document.getElementById("EUR").value = Pom;  
  			  
	}else {
	 cislo = document.getElementById("EUR").value;
   document.getElementById("EUR").value = cislo;
   
  Pom = cislo * kurz;
  Pom = Math.round((Pom*Math.pow(10,Presnost)))/(Math.pow(10,Presnost));
	document.getElementById("SKK").value = Pom;

	}
	    
}
 
function stlac(tlacitko){
 var InputPole, Presnost = 2, Pom;	
	if (tlacitko == 'klaves'){
	  if (valuta == 'SKK'){InputPole = document.getElementById("SKK").value;}
	  if (valuta == 'EUR'){InputPole = document.getElementById("EUR").value;} 
	  InputPole = InputPole.replace(',','.');
          InputPole = OdstranDalsiuBodku(InputPole);
	  cislo = InputPole;
	}else {
            cislo = cislo + tlacitko ;          		 
            cislo = OdstranDalsiuBodku(cislo);
	}
	cislo = OdstranZnaky(cislo);
	if (valuta == 'SKK'){
	document.getElementById("SKK").value = cislo;
  Pom = cislo / kurz;
  Pom = Math.round((Pom*Math.pow(10,Presnost)))/(Math.pow(10,Presnost));  
  Pom = Pom.toFixed(Presnost);
	document.getElementById("EUR").value = Pom;  
			  
	}else {
	document.getElementById("EUR").value = cislo;
  Pom = cislo * kurz;
  Pom = Math.round((Pom*Math.pow(10,Presnost)))/(Math.pow(10,Presnost));
	document.getElementById("SKK").value = Pom;
	}
}

function OdstranZnaky(retazec){
 retazec = retazec.replace(/[a-z]*/ig,'');
 retazec = retazec.replace(/^[,.]*/i, '');
 return retazec;
}

function OdstranDalsiuBodku(retazec){
	  if(retazec.indexOf('.')!==retazec.lastIndexOf('.')){
            retazec = retazec.substr(0, retazec.lastIndexOf('.')).concat(
                           retazec.substr(retazec.lastIndexOf('.')+1,retazec.length - retazec.lastIndexOf('.'))
                                                                              );
          }
 return retazec;
}

if(typeof(Sys)!=="undefined")Sys.Application.notifyScriptLoaded();