var TopBannerWidth = 468; // może zostać dalej zmieniona

// W osobnym oknie.
function ShowPicture(FileName, picWidth, picHeight, left, top, windowTitle, noBanner, pictureID, forArchive) {
  var width = Math.max(TopBannerWidth, picWidth) + 50; // na baner
  var height = picHeight + 100 + 100;
  if(!left) left = 300;
  if(!top) top = 300;
  if(left == -1) left = screen.width - width - 50;
  if(top == -1) top = screen.height - height - 50;
  left = Math.min(left, screen.width - width - 50);
  top = Math.min(top, screen.height - height - 50);
  var w = window.open(VirtDir + '/listings/PictureView.asp?PicFileName=' + 
            URLSafeEncode(FileName) + (windowTitle ? '&WindowTitle=' + windowTitle : '') +
            '&NoBanner=' + (noBanner ? '1' : '0') +
            (pictureID ? '&PictureID=' + pictureID : '') + '&ForArchive=' + (forArchive ? '1' : '0'),
            'Zdjecie',
            'scrollbars=yes,resizable=yes,status=no,width=' + width + ',height=' + height + 
            ',dependent=yes,left=' + left + ',top=' + top);
  w.focus();
}   

// W osobnym oknie.
function LstShowPicturePrevNext(pictNo, left, top) {
  var form = document.forms['LPVHF_Form'];
  var picWidth = parseInt(form.LPVHF_MaxWidth.value);
  var picHeight = parseInt(form.LPVHF_MaxHeight.value);
  var width = Math.max(TopBannerWidth, picWidth) + 50; // na baner
  var height = picHeight + 100 + 100;
  if(!left) left = 300;
  if(!top) top = 300;
  if(left == -1) left = screen.width - width - 50;
  if(top == -1) top = screen.height - height - 50;
  left = Math.min(left, screen.width - width - 50);
  top = Math.min(top, screen.height - height - 50);
  var w = window.open('', 'Zdjecie',
            'scrollbars=yes,resizable=yes,status=no,width=' + width + ',height=' + height + 
            ',dependent=yes,left=' + left + ',top=' + top);
  form['LPVHF_PictNo'].value = pictNo;
  form.submit();
  w.focus();
}   

function PVNavGo(pictNo) {
  f_m_form.LPVHF_PictNo.value = '' + pictNo;
  f_m_form.submit();
}

// Koduje adres WWW tak, aby bez problemów przesłać jako parametr w adresie www.
// W szczególności zamienia znak "&" na coś bez "&".
// Oryginał można otrzymać funkcją URLSafeDecode.
function URLSafeEncode(str)
{
  return(str.replace(/x/g, 'xx').replace(/&/g, 'xy'));
}

// Odtwarza tekst zakodowany funkcją URLSafeEncode.
function URLSafeDecode(str)
{
  return(str.replace(/xx|xy/g, function($0){return $0 == 'xx' ? 'x' : '&';}));
}

