function preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() {
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

oki=null;
function openWindow(nazwa_pliku,_width,_height,plik,sbars,opis_str){
        if (_width==null) _width=100;
        if (_height==null) _height=100;
        if (opis_str==null) opis_str=''; //ustawienie wartosci domyslnej
        //plik: w przypadu gdy chcemy wyswietlic juz gotowa strone html
        //co: w przypadku gdy chemy wyswietlic jedynie obrazek

        yes = 1;  no = 0;

        //musza byc:
        _fullscreen = yes;
        _toolbar = no; //pasek narzedzi
        _location = no; //pasek adresu
        _directories = no; //pasek
        _menubar = no; //pasek menu
        _status = no; //stopka

       if (sbars==null) {
         _scrolling = no;
         _scrollbars = no;
       } else {
         _scrolling = yes;
         _scrollbars = yes;
       }

       _resizable = no;

        _top = screen.availHeight; //polozenie na ekranie - dol ekranu
        _left = screen.availWidth; //polozenie na ekranie - dol ekranu
        _top = (_top-_height)/2; //wysrodkowanie w poziomie
        _left = (_left-_width)/2; //wysrodkowane w pionie

        //budowa stringu
        _features = "'fullscreen=" + _fullscreen + ",toolbar=" + _toolbar + ",location=" + _location + ",directories=" + _directories + ",menubar=" + _menubar + ",status=" + _status + ",scrolling=" + _scrolling + ",scrollbars=" + _scrollbars + ",resizable=" + _resizable + ",width=" + _width + ",height=" + _height + ",top=" + _top + ",left=" + _left + "'";

        nr=Math.round(Math.random()*5000);
        nr="OBR"+nr;
        if (oki==null) {
           oki=window.open(plik,nr,_features);
        }
        //zamkniecie juz otwartego ta funkcja okna
        else {
             oki.close();
             oki=window.open(plik,nr,_features);
        }

        //generowanie strony
        if (plik==''){ oki.document.write ('<html><head><title>'+opis_str+'</title><style type="text/css"><!--body {margin-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;}--></style></head><body><div id="obrazek" style="position:absolute;left:0px;top:0px;"><a href="#" onclick="self.close()"><img src="'+nazwa_pliku+'" width="'+_width+'" height="'+_height+'" border="0" ></a></div></body></html>');
        }
        oki.focus();
}

function selectElement(element) {
  var elementId = element.id.substring(1, element.id.length);
  var checkbox = document.getElementById(elementId);
  if (!checkbox.disabled) {
    checkbox.checked = !checkbox.checked;
  }
  updateComponents();
}

function updateComponents() {
  updateComponent('sprzedaz');
  updateComponent('wynajem');
  updateComponent('domy');
  updateComponent('mieszkania');
  updateComponent('dzialki');
  updateComponent('lokale');
  updateComponent('obiekty');
  updateComponent('kamienice');
  updateComponent('hotele');
  updateComponent('wszystkie');
  updateComponent('stareMiasto');
  updateComponent('srodmiescie');
  updateComponent('krzyki');
  updateComponent('psiePole');
  updateComponent('fabryczna');
  updateComponent('pozaWroclawiem');
  document.getElementById('dzialki').disabled = document.getElementById('wynajem').checked;
  document.getElementById('kamienice').disabled = document.getElementById('wynajem').checked;
  document.getElementById('hotele').disabled = document.getElementById('wynajem').checked;
  document.getElementById('wynajem').disabled = document.getElementById('dzialki').checked || document.getElementById('kamienice').checked || document.getElementById('hotele').checked;
}

function updateComponent(buttonId) {
  var checkbox = document.getElementById(buttonId);
  var button = document.getElementById('_' + buttonId);
  if (checkbox.checked) {
     button.className = 'propertySelectedCategory';
  } else {
     button.className = 'propertyCategory';
  }
}

function search() {
  var result = '';
  var wynajem = document.getElementById('wynajem').checked;
  var sprzedaz = document.getElementById('sprzedaz').checked;
  if (!wynajem && !sprzedaz) {
     result += getMessage('Proszę wybrać typ oferty.');
  }
  var domy = document.getElementById('domy').checked;
  var mieszkania = document.getElementById('mieszkania').checked;
  var dzialki = document.getElementById('dzialki').checked;
  var lokale = document.getElementById('lokale').checked;
  var obiekty = document.getElementById('obiekty').checked;
  var kamienice = document.getElementById('kamienice').checked;
  var hotele = document.getElementById('hotele').checked;
  if (!domy && !mieszkania && !dzialki && !lokale && !obiekty && !kamienice && !hotele) {
    if (result != '') {
      result = getMessage('Proszę wybrać typ oferty oraz kategorię nieruchomości.');
    } else {
      result = getMessage('Proszę wybrać kategorię nieruchomości.');
    }
  }
  if (result != '') {
    alert(result);
    return;
  }
  var newLocation = 'http://www.nieruchomosci-wroclaw.pl/';
  if (domy) {
    newLocation += 'domy/';
  } else if (mieszkania) {
    newLocation += 'mieszkania/';
  } else if (dzialki) {
    newLocation += 'dzialki/';
  } else if (lokale) {
    newLocation += 'lokale/';
  } else if (obiekty) {
    newLocation += 'obiekty/';
  } else if (kamienice) {
    newLocation += 'kamienice-biurowce/';
  } else if (hotele) {
    newLocation += 'hotele-inne/';
  }
  if (sprzedaz) {
    newLocation += 'sprzedaz/';
  } else {
    newLocation += 'wynajem/';
  }
  var stareMiasto = document.getElementById('stareMiasto').checked;
  var srodmiescie = document.getElementById('srodmiescie').checked;
  var psiePole = document.getElementById('psiePole').checked;
  var krzyki = document.getElementById('krzyki').checked;
  var fabryczna = document.getElementById('fabryczna').checked;
  var pozaWroclawiem = document.getElementById('pozaWroclawiem').checked;
  if (stareMiasto) {
    newLocation += 'stare-miasto/';
  } else if (srodmiescie) {
    newLocation += 'srodmiescie/';
  } else if (psiePole) {
    newLocation += 'psie-pole/';
  } else if (krzyki) {
    newLocation += 'krzyki/';
  } else if (fabryczna) {
    newLocation += 'fabryczna/';
  } else if (pozaWroclawiem) {
    newLocation += 'poza-wroclawiem/';
  }
  window.location = newLocation;
}

function findOnMap(address, zoom) {
  if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
    window.document.body.onload = function() { load(); findAddress(address, zoom) };
  } else {
    load();
    findAddress(address, zoom);
  }
}

function showOnMap(point, zoom) {
  if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
    window.document.body.onload = function() { load(); showAddress(point, zoom) };
  } else {
    load();
    showAddress(point, zoom);
  }
}

function selectMenuRow(row) {
  row.className = 'selectedMenuCell';
}

function deselectMenuRow(row) {
  row.className = 'menuCell';
}

function selectRow(row) {
  if (row.className == 'listCellOdd') row.className = 'listCellOddSelected';
  if (row.className == 'listCellEven') row.className = 'listCellEvenSelected';
}

function deselectRow(row) {
  if (row.className == 'listCellOddSelected') row.className = 'listCellOdd';
  if (row.className == 'listCellEvenSelected') row.className = 'listCellEven';
}

function selectDiv(row) {
  if (row.className == 'right0') row.className = 'selectedRight0';
  if (row.className == 'right1') row.className = 'selectedRight1';
  if (row.className == 'bottom0') row.className = 'selectedBottom0';
  if (row.className == 'bottom1') row.className = 'selectedBottom1';
}

function deselectDiv(row) {
  if (row.className == 'selectedRight0') row.className = 'right0';
  if (row.className == 'selectedRight1') row.className = 'right1';
  if (row.className == 'selectedBottom0') row.className = 'bottom0';
  if (row.className == 'selectedBottom1') row.className = 'bottom1';
}
