function gRok(rok) {
     var x, y;

     i2np = function(i) {
          switch(i) {
               case 0: return "F";
               case 1: return "E";
               case 2: return "D";
               case 3: return "C";
               case 4: return "B";
               case 5: return "A";
               case 6: return "G";
               case -1: return "G";
               }
          return "?";              
     }

     if ((rok % 4 == 0 && rok % 100 != 0) || (rok % 400 == 0))
          this.jePrestupny = true;
     else
          this.jePrestupny = false;

     x = (rok + 1) % 19;
     this.zlateCislo = (x == 0) ? 19 : x;

     x = (rok + 9) % 28;
     this.slunecniKruh = (x == 0) ? 28 : x;

     x = (rok + 3) % 15;
     this.rimskyPocet = (x == 0) ? 15 : x;

     x = 1 + parseInt(rok / 100);
     y = ((11 * (this.zlateCislo - 1)) % 30 - parseInt(3 * x / 4) + parseInt((8 * x + 5) / 25) + 8) % 30;
     this.novorocniEpakta = (y < 1) ? y % 30 + 30 : (y - 1) % 30 + 1;

     this.nedelniCislo = (rok + parseInt(rok / 4) - parseInt(3 * (parseInt(rok / 100) - 15) / 4)) % 7;
     
     if (this.jePrestupny)
          this.nedelniPismeno = i2np(this.nedelniCislo - 1) + i2np(this.nedelniCislo);
     else
          this.nedelniPismeno = i2np(this.nedelniCislo);

     x = this.novorocniEpakta;
     if (x == 25 && this.zlateCislo > 11) x = 26;
     if (x == 24) x = 25;
     x = (x < 24) ? 44 - x : 74 - x; 
     y = x + 7 - (x + 4 + this.nedelniCislo) % 7;
     if (y > 31)
          this.velikonocniNedele = y - 31 + ".duben";
     else
          this.velikonocniNedele = y + ".březen";
}

function predchozi()
{
     var rok = parseInt(document.getElementById('rok').value);
     rok--;
     document.getElementById('rok').value = rok;
     vypocet();
     setButton()
}
function dalsi()
{
     var rok = parseInt(document.getElementById('rok').value);
     rok++;
     document.getElementById('rok').value = rok;
     vypocet();
     setButton()
}
function setButton()
{
     if (parseInt(document.getElementById('rok').value) < 1584)
          document.getElementById('prevY').disabled = true;
     else
          document.getElementById('prevY').disabled = false;     
}
function vypocet()
{
     var rok;
     rok = parseInt(document.getElementById('rok').value);
     if (isNaN(rok) || rok < 1583)
     {
          alert("Rok musí být větší jak 1582 !");
          rok = new Date().getFullYear();
          document.getElementById('rok').value = rok;
     }
     r = new gRok(rok)
     document.getElementById("rPocet").innerHTML = r.rimskyPocet;
     document.getElementById("nPismeno").innerHTML = r.nedelniPismeno;
     document.getElementById("sKruh").innerHTML = r.slunecniKruh;     
     document.getElementById("zCislo").innerHTML = r.zlateCislo;            
     document.getElementById("nEpakta").innerHTML = r.novorocniEpakta;               
     document.getElementById("vNedele").innerHTML = r.velikonocniNedele;                
}

function Zinit()
{
    var rok = new Date().getFullYear();
    document.getElementById("rok_ted").innerHTML = rok;
    Zvypocet(rok);
}

function Zpred()
{
    var rok = parseInt(document.getElementById("rok_ted").innerHTML);
    if (rok > 1928)
        rok -= 1;
    document.getElementById("rok_ted").innerHTML = rok;
    Zvypocet(rok);
}
function Zpo()
{
    var rok = parseInt(document.getElementById("rok_ted").innerHTML);
    if (rok < 2072)
        rok += 1;
    document.getElementById("rok_ted").innerHTML = rok;
    Zvypocet(rok);
}

function Zvypocet(rok)
{
    if (rok % 4 == 0)
    {
        document.getElementById("rok_pred").innerHTML = rok - 28;
        document.getElementById("rok_po").innerHTML = rok + 28;
    }
    else if (rok % 4 == 1)
    {
        document.getElementById("rok_pred").innerHTML = rok - 11;
        document.getElementById("rok_po").innerHTML = rok + 6;
    }
    else if (rok % 4 == 2)
    {
        document.getElementById("rok_pred").innerHTML = rok - 11;
        document.getElementById("rok_po").innerHTML = rok + 11;
    }
    else if (rok % 4 == 3)
    {
        document.getElementById("rok_pred").innerHTML = rok - 6;
        document.getElementById("rok_po").innerHTML = rok + 11;
    }
}
