﻿// cene za tarifo v evrih
  var tarifaBonus = 0.07;
  var tarifa007 = 0.07;
  var tarifa008 = 0.08;
  var tarifaIziMobil = 0.12;
// dolzina intervala za posamezno tarifo v sekundah
  var IntervalTarifaBonus = 15;
  var IntervalTarifa007 = 180;
  var IntervalTarifa008 = 60;
  var IntervalTarifaIziMobil = 15;
  var TableBGImg = "url(/template/izimobil/binaryresource/theme/images/bgTable.png)";
  
  function calculate() {
      var errorist = document.getElementById("error");
      var cLength = document.getElementById('callen').value;
      if( cLength > 0 && cLength <= 10000 ) 
      {
        var minDol = (Math.ceil(cLength / 60));
        var minGor = (Math.floor(cLength / 60));
        var priceIziZaInterval = tarifaIziMobil / 4;
        var priceBonusZaInterval = tarifaBonus / 4;
        var price007ZaInterval15 = tarifa007 / 4;
        var price008ZaInterval15 = tarifa008 / 4;
        
        errorist.innerHTML = '';
        document.getElementById("convertToMin").innerHTML = ' = ' + Math.floor(cLength / 60) + ' min ' + (cLength % 60) + 's' ;
        
        var ssloBon1;
        if (cLength <= 180)
        { 
          ssloBon1 = (tarifa007 * 3).toFixed(3);
        } else
        {
           var cLength15 = cLength - 180; // prvih 180 sekund se od�teje in od ostanka se potem dela 15 sekudni interval
           ssloBon1 = (tarifa007 * 3 + ((Math.floor(cLength15 / 60)) * tarifa007 + Math.ceil(Math.ceil(cLength15 % 60) / 15) * price007ZaInterval15)).toFixed(3);
        }

        var ssloBon2;
        if (cLength <= 60)
        { 
          ssloBon2 = tarifa008.toFixed(3);
        } else
        {
           var cLength15 = cLength - 60; // prvih 60 sekund se od�teje in od ostanka se potem dela 15 sekudni interval
           ssloBon2 = (tarifa008 + ((Math.floor(cLength15 / 60)) * tarifa008 + Math.ceil(Math.ceil(cLength15 % 60) / 15) * price008ZaInterval15)).toFixed(3);
        }
        
        var ssloBon3 = (Math.floor(cLength / 60) * tarifaIziMobil + Math.ceil(Math.ceil(cLength % 60) / 15) * priceIziZaInterval).toFixed(3);
        //var ssloBon5 = (Math.floor(cLength / 60) * tarifaBonus + Math.ceil(Math.ceil(cLength % 60) / 15) * priceBonusZaInterval).toFixed(3);
         
        var vseCeneBon = new Array();
        vseCeneBon[0] = ssloBon1;
        vseCeneBon[1] = ssloBon2;
        vseCeneBon[2] = ssloBon3;
        //vseCeneBon[4] = ssloBon5;

        var k = 10000; 
        for(var i = 0; i < vseCeneBon.length; i++) 
        { 
          if( parseFloat( vseCeneBon[i] ) < k) 
          { 
              k = parseFloat( vseCeneBon[i] );
          } 
        }
        
        var izi1 = document.getElementById("sloBon1");
        var izi2 = document.getElementById("sloBon2");
        var izi3 = document.getElementById("sloBon3");
        //var izi5 = document.getElementById("sloBon5");

        if(k == ssloBon1) {
            izi1.style.backgroundColor = "#FF6600";
            izi1.style.backgroundImage = "none";
        } else {
            izi1.style.backgroundImage = TableBGImg;
        }
        if (k == ssloBon2) {
            izi2.style.backgroundColor = "#FF6600";
            izi2.style.backgroundImage = "none";
        } else {
            izi2.style.backgroundImage = TableBGImg;
        }
        if(k == ssloBon3) {
            izi3.style.backgroundColor = "#FF6600";
            izi3.style.backgroundImage = "none";
        } else {
            izi3.style.backgroundImage = TableBGImg;
        }
        /*if(k == ssloBon5) {
            izi5.style.backgroundColor = "#FF6600";
            izi5.style.backgroundImage = "none";
        } else {
            izi5.style.backgroundImage = TableBGImg;
        }*/

        izi1.innerHTML = DecimalToString(ssloBon1) + ' EUR';
        izi2.innerHTML = DecimalToString(ssloBon2) + ' EUR';
        izi3.innerHTML = DecimalToString(ssloBon3) + ' EUR';
        //izi5.innerHTML = DecimalToString(ssloBon5) + ' EUR';
      } else { errorist.innerHTML = "<font style='color: red;'>Vnesi čas od 1 do 10000 sekund.</font>"; }
  }

