b = document.images.length; //spocita obrazky na strance
a = new  Array(36);
var obr;
//obr="prazdno_";

nahodne_cislo = Math.ceil(4*Math.random()) ;
//var nahodne_cislo=1;

switch (nahodne_cislo) {
  case 1 :
     obr = "aero_" ;
     break ;
  case 2 :
     obr = "okno_" ;
     break ;
  case 3 :
     obr = "dvere_" ;
     break ;
  default :
     obr = "logo_" ;
}

pom = "prazdno" ;

function divka()
{obr = "divka_" ; pom = "plno" ;}
function logo()
{obr = "logo_" ; pom = "plno" ;}


function kontrola1(){
if  (pom == "plno")  {document.getElementById('odesli').style.display='none';}
if  (pom == "plno")  {document.getElementById('neodesli').style.display='block';}
//if  (pom == "plno")  {document.getElementById('nehrajeme').style.display='none';}
}
//alert (obr);

var vyhra;


function  zobraz()
  {
  for (i = 1; i <= 4; i++)
       {  for (j = 1; j <= 4; j++)
       {  document.images[4*(i-1) + j-1 + b].src = '../images/hra/'+obr + a[6*i + j] + '.jpg';  }}

//if  (a[7] == '01')  { document.images[15 + b].src = '../images/hra/'+obr+'16.jpg'; document.getElementById('odesli').style.display='block'; document.getElementById('neodesli').style.display='none'; alert ("Gratulujeme !"); document.getElementById('vyhr').action='index.php?los=hra-form&strPHP=yes';}
if  ((a[7] == '01')  &&  (a[8] == '02')  &&  (a[9] == '03')  &&  (a[10] == '04')  &&  (a[13] == '05')  &&  (a[14] == '06')  &&  (a[15] == '07')  &&  (a[16] == '08')  &&  (a[19] == '09')  &&  (a[20] == '10')  &&  (a[21] == '11')  &&  (a[22] == '12')  &&  (a[25] == '13')  &&  (a[26] == '14')  &&  (a[27] == '15'))  { document.images[15 + b].src = '../images/hra/'+obr+'16.jpg'; document.getElementById('odesli').style.display='block'; document.getElementById('neodesli').style.display='none'; alert ("Gratulujeme !"); document.getElementById('vyhr').action='index.php?los=hra-form&strPHP=yes';}




//if  (a[7] == '01')  { document.images[15 + b].src = '../images/hra/'+obr+'16.jpg'; alert ("Gratulujeme !"); document.getElementById('odesli').style.display='block'; document.getElementById('nehrajeme').style.display='none'; document.getElementById('neodesli').style.display='none'; document.vyhr.action='index.php?los=hra-form&strPHP=yes';nahoda();}
//if  ((a[7] == '01')  &&  (a[8] == '02')  &&  (a[9] == '03')  &&  (a[10] == '04')  &&  (a[13] == '05')  &&  (a[14] == '06')  &&  (a[15] == '07')  &&  (a[16] == '08')  &&  (a[19] == '09')  &&  (a[20] == '10')  &&  (a[21] == '11')  &&  (a[22] == '12')  &&  (a[25] == '13')  &&  (a[26] == '14')  &&  (a[27] == '15')) { document.images[15 + b].src = '../images/hra/'+obr+'16.jpg'; alert ("Gratulujeme !"); document.getElementById('odesli').style.display='block'; document.getElementById('neodesli').style.display='none'; document.vyhr.action='index.php?los=hra-form&strPHP=yes';nahoda();}

//if  ((a[7] == '01')  &&  (a[8] == '02')  &&  (a[9] == '03')  &&  (a[10] == '04')  &&  (a[13] == '05')  &&  (a[14] == '06')  &&  (a[15] == '07')  &&  (a[16] == '08')  &&  (a[19] == '09')  &&  (a[20] == '10')  &&  (a[21] == '11')  &&  (a[22] == '12')  &&  (a[25] == '13')  &&  (a[26] == '14')  &&  (a[27] == '15'))  { document.images[15 + b].src = '../images/hra/'+obr+'16.jpg'; alert('gratulace !!');  }

document.brcko.src = '../images/hra/'+obr+'foto.jpg';


}

function  nahoda()
{
if (pom == "plno") {
  pomPole = new Array(16);
  pomPole[0] = Math.ceil(15*Math.random());
  for (i = 1; i <= 4; i++)
       {  for (j = 1; j <= 4; j++)
         {  var  index = 4*(i-1) + j-1;
      cisloUzJePouzito = true;
      if ((index > 0)  &&  (index < 15))
           {  while  (cisloUzJePouzito)
             {  pomPole[index] = Math.ceil(15*Math.random());
          for (x = 0; x < index; x++)
               {   cisloUzJePouzito  =  (pomPole[x] == pomPole[index]);   
            if  (cisloUzJePouzito)  {break;  };  }
           }        }
      if  (pomPole[index] < 10)   {  a[6*i + j] = '0' + pomPole[index];   }; 
      if  (pomPole[index] >   9)   {  a[6*i + j] = ''   + pomPole[index];   }; 
        }        }
  a[28] = '';
  zobraz();
  
}}

function  tah(r, s)    //   r = øádek (1 až 4),  s = sloupec (1 až 4)
  {
  nelze = true;    //   nelze-li provést tah, vypíše hlášení "alert"
  x = 6*r + s;
  if  (a[x-1] == '')     {  a[x-1]=a[x];  a[x]='';   nelze=false;   };
  if  (a[x+1] == '')     {  a[x+1]=a[x];  a[x]='';   nelze=false;   };
  if  (a[x-6] == '')     {  a[x-6]=a[x];  a[x]='';   nelze=false;   };
  if  (a[x+6] == '')     {  a[x+6]=a[x];  a[x]='';   nelze=false;   };
  //if  (nelze)  { alert('Tímto dílkem nelze táhnout! \nŽádné sousední pole není volné.');  };
  zobraz();
  }
function vymen()
  {
  for  (i = 7;  i < 29;  i++)
         {    if  (a[i] == '14')   {var  u = i;  };
      if  (a[i] == '15')   {var  v = i;  };  };
  a[u] = '15';
  a[v] = '14';
  zobraz();
  }
  