// ------------------------------------------
function el(ID) {
  return document.getElementById(ID);
}

// ------------------------------------------
function showPhoto(obrazek) {
  var width  = 300;
  var height = 300;
  var left = parseInt(screen.width/2-width/2);
  var top  = parseInt(screen.height/2-height/2);
  noweOknoPopup = window.open('showPhoto.php?obrazek='+obrazek,'PopupImg','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,resizable=0,copyhistory=0,left='+left+',top='+top+',width='+width+',height='+height);
  noweOknoPopup.focus();
}

// ------------------------------------------
function showPopupWindow(link,width,height) {
  width  = (!width || width==0) ? 540 : width;
  height = (!height || height==0) ? 520 : height;
  var left = parseInt(screen.width/2-width/2);
  var top  = parseInt(screen.height/2-height/2);
  noweOknoPopup = window.open(link,'PopupWin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,left='+left+',top='+top+',width='+width+',height='+height);
  noweOknoPopup.focus();
}

// ------------------------------------------
function showPopupWindowVideo(link,width,height) {
  width  = (!width || width==0) ? 540 : width;
  height = (!height || height==0) ? 520 : height;
  var left = parseInt(screen.width/2-width/2);
  var top  = parseInt(screen.height/2-height/2);
  noweOknoPopup = window.open(link,'PopupWin','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,copyhistory=0,left='+left+',top='+top+',width='+width+',height='+height);
  noweOknoPopup.focus();
}

// ------------------------------------------
function pobierzPlik(plik) {
//   var left = parseInt(screen.width/2-150);
//   var top  = parseInt(screen.height/2-150);
  //noweOknoPopup = window.open('download.php?plik='+plik,'DownloadWin','');
  noweOknoPopup = window.open('index.php?download/'+plik,'DownloadWin','');
}

//---------------------------------
function replace(s, t, u) {
// s  string
// t  zamien co
// u  zamien  na
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}//function

//---------------------------------
//pokaz/ukryj wiersz tabeli
function showTableRow(id) {
var myElem = document.getElementById(id);

  try {
    myElem.style.display = 'table-row';
  }
  catch(e) {
    myElem.style.display = 'inline';
  }
}
function hideTableRow(id) {
var myElem = document.getElementById(id);
  myElem.style.display = 'none';
}

//---------------------------------
//funkcje do obslugi pol combo
// $combo_nr','$k','$w','$nazwa')
function setComboValue(combo_nr,val,text,pole) {
  document.getElementById(pole).value = val;
  document.getElementById('combo_text_'+combo_nr).innerHTML = text;
  hideCombos();
}
function showCombo(nr) {
  hideCombos();
  document.getElementById('combo_'+nr).style.visibility = 'visible';
}
var combos = false;
function hideCombos() {
  if (!combos)
    combos = document.getElementsByTagName('DIV');
  for (i=0;i<combos.length;i++) {
    if (combos[i].id.indexOf('combo_')!=-1)
      combos[i].style.visibility = 'hidden';
  }
}
//document.onclick=function(){hideCombos()}

//---------------------------------
//funkcje do obslugi cookies
function SetCookie(cookieName,cookieValue,nDays) {
  var today  = new Date();
  var expire = new Date();
  if (nDays==null || nDays==0) nDays=1;
  expire.setTime(today.getTime() + 3600000*24*nDays);
  document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString();
}
function ReadCookie(cookieName) {
  var theCookie=""+document.cookie;
  var ind=theCookie.indexOf(cookieName);
  if (ind==-1 || cookieName=="") return ""; 
  var ind1=theCookie.indexOf(';',ind);
  if (ind1==-1) ind1=theCookie.length; 
  return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

