/*
  Otwiera okno przeglądarki na pierwszym planie. 
  Do okna ładwany jest plik graficzny o numerze id.
  
  imageId - numer rekordu z bazy zawierający informacje o pliku  
*/
function gallery(imageId)
{
  var handle = window.open('image.php?src=' + imageId, 'image', 'menubar=no, toolbar=no, location=no, resizable=yes, status=no, scrollbars=no, width=800, height=600').focus();
}

function setPhoto(src) {
  document.getElementById('big_image').src = src;
}

/*
  Otwiera okno przeglądarki na pierwszym planie. 
  Do okna ładwana jest zawartość pliku.
  
  page - plik który ma zostać wczytany
  w - szerokość okna
  h - wysokość okna
  handle - nazwa identyfikatora okna
*/
function openWindow(page, w, h, handle)
{ 
    var handle = window.open(page, handle, 'menubar=no, toolbar=no, location=no, resizable=yes, status=no, scrollbars=yes, width='+w+', height=' + h).focus(); 
}

/* 
  Funckcja kolorująca tabelę. Korzysta z biblioteki prototypejs ver 1.6 (http://www.prototypejs.org).
  idTabla - id tabeli która ma zostac pokolorowana.
   
  s1 - styl wiersza nieparzystego w sekcji tbody
  s2 - styl wiersza parzystego w sekcji tbody  
  
  h1 - styl wiersza nieparzystego w sekcji thead (parametr opcjonalny)
  h2 - styl wiersza parzystego w sekcji thead (parametr opcjonalny)
  
  Style przekazywane są jako obietky, np.:
  var s1 = {backroundColor: '#ffffff', textAlign: 'center'}
  
  Tabela musi zawierać sekcje tbody. Sekcja thead jest opcjonalna.
*/
function colourRowTable(idTable, s1, s2, h1, h2)
{
  if (! $(idTable)) return; // brak tabeli o zadanym id    
    
  /* dla każdego dziecka  - musżą wystąpić sekcje tbody oraz thead */
  $(idTable).childElements().each(
    function(element)
    {
      /* h1 oraz h2 parametry są opcjonalne */
      if (h1 != undefined && h2 != undefined)
      {
        if (element.tagName == 'THEAD') 
        {                      
          /* koloruj wiersze w sekcji thead */                  
          colourRows(element, h1, h2);      
        }
      }
              
      if (element.tagName == 'TBODY') 
      {
        /* koloruj wiersze w sekcji tbody */
        colourRows(element, s1, s2);        
      }                   
    }
  );
}

/* 
  Funcja koloruje wiersze.
  element - obiekt thead lub tbody tabeli\
  s1 - style wierszy nieparzystych
  s2 - style dla wierszy parzystych
*/ 

function colourRows(element, s1, s2)
{  
  var counter = 0;  
  element.childElements().each( function(el)
  {   
    counter++;
    
    var st = s1;
    if (counter % 2 == 0)
    {
      st = s2;
    }
        
    el.childElements().each(
          function(childElement)
          {
            // dzieckiem może być element th lub td
            if (childElement.nodeName == "TH" || childElement.nodeName == "TD")
            {                            
              childElement.setStyle(st);
            }
          });                
  });      
}


function formatColumnTable(idTable, colNr, st)
{
  if (! $(idTable)) return; // brak tabeli o zadanym id    
    
  /* dla każdego dziecka  - musżą wystąpić sekcje tbody oraz thead */
  $(idTable).childElements().each(
    function(element)
    {                    
      if (element.tagName == 'TBODY') 
      {
        /* koloruj wiersze w sekcji tbody */
        formatColumnt(element, colNr, st);        
      }                   
    }
  );
}

function formatColumnt(element, colNr, st)
{  
  
  element.childElements().each( function(el)
  {
      if (el.tagName == "TR")
      {
        var counter = 0;
        var childEl = el.childElements(); 
        childEl[colNr].setStyle(st);        
      }    
  }); 
}

/* 
  funkcja zmieniająca wielkośc okna
  w - szerokość okna
  h - wysokość okna 
*/
function resizeWindow(w, h)
{
  window.resizeTo(w,h);  
}

/* 
  funkcja zamyka okno
*/
function closeWindow()
{
  window.close();
}
