// --- netscape resize bugfix
if (document.layers) {
 widthCheck = window.innerWidth;
 heightCheck = window.innerHeight;
}
function resizeFix() {
 if (!document.layers) return;
 if (widthCheck != window.innerWidth || heightCheck != window.innerHeight)
  document.location.href = document.location.href;
}

// --- scrollin'
// based on script by Urs Dudli and Peter Gehrig

var scrollerWidth, scrollerHeight, scrollerLeft, scrollerTop, scrollerPause, scrollerStep;
var scrollerCLeft, scrollerCRight, scrollerCTop, scrollerCBtm;
var scrollTimer, scrollerTWidth, scrollerText;

function getX(obj) {
    return( obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent) );
}

function getY(obj) {
    return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent) );
}

function initScroll() {
 if (scrollTimer) clearTimeout(scrollTimer);

 winW = (document.layers)? window.innerWidth-16 : document.body.offsetWidth-20;
 if (winW < 725) winW = 725;
 scrollerLeft = Math.round((winW- 725) / 2) + 127;

 scrollerWidth=605;
 scrollerHeight = 14;
 scrollerStep=1;
 
 var img = document.images['imgscr'];
 scrollerTop = getY(img)+2;
 scrollerPause=20;

 if(document.all) {
	 document.getElementById('scrollertextdiv').innerHTML=scrollerText;
	 scrollerTWidth=document.getElementById('scrollertextdiv').offsetWidth;
	 document.getElementById('scrollertextdiv').style.posTop=scrollerTop;
	 document.getElementById('scrollertextdiv').style.posLeft=scrollerLeft+scrollerWidth;
	 scrollerCLeft=0; scrollerCRight=0; scrollerCTop=0; scrollerCBtm=scrollerHeight;
	 document.getElementById('scrollertextdiv').style.clip ="rect("+scrollerCTop+" "+scrollerCRight+" "+scrollerCBtm+" "+scrollerCLeft+")";
	 scrollText();
 }
}


function scrollText() {
 if (document.getElementById('scrollertextdiv').style.posLeft >= scrollerLeft - scrollerTWidth) {
  document.getElementById('scrollertextdiv').style.posLeft -= scrollerStep;
  scrollerCRight += scrollerStep;
  if (scrollerCRight > scrollerWidth) scrollerCLeft += scrollerStep;
  document.getElementById('scrollertextdiv').style.clip ="rect("+scrollerCTop+" "+scrollerCRight+" "+scrollerCBtm+" "+scrollerCLeft+")";
  scrollTimer=setTimeout("scrollText()",scrollerPause);
 } else scrollReset();
}

function scrollReset() {
 document.getElementById('scrollertextdiv').style.posLeft = scrollerLeft + scrollerWidth;
 scrollerCLeft=0; 
 scrollerCRight=0;
 document.getElementById('scrollertextdiv').style.clip ="rect("+scrollerCTop+" "+scrollerCRight+" "+scrollerCBtm+" "+scrollerCLeft+")";
 scrollText();
}

function scrollSpeed(inc) {
 if (inc == 0) scrollerStep = 0;
 else scrollerStep += inc;
 if (scrollerStep >= 20) scrollerStep = 20;
 if (scrollerStep<0) scrollerStep = 0;
}



function onWinResize() {
 resizeFix();
 initScroll();
}

// --- main init
var multitabs = new Array();
function initMain() {
 initScroll();
 window.onresize = onWinResize;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_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 MM_swapImgRestore() { //v3.0
  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 MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var ow = null;
function open_window(name) {
    width = 200; height = 100;
    PosX = 0; PosY= 0;
    ScrWidth = 640; ScrHeight = 480;
    if (window.screen) {ScrWidth = window.screen.width; ScrHeight = window.screen.height}
    PosX = Math.round((ScrWidth - width)/2);
    PosY = Math.round((ScrHeight - height)/2);

    if (ow != null && !document.layers) {ow.close();}

    ow = window.open("", name, "menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=" + width + ",height=" + height + ",left=" + PosX + ",top=" + PosY);

}

function popupImage(src) {
    width = 150; height = 150;
    PosX = 0; PosY= 0;
    ScrWidth = 640; ScrHeight = 480;
    if (window.screen) {ScrWidth = window.screen.width; ScrHeight = window.screen.height}
    PosX = Math.round((ScrWidth - width)/2);
    PosY = Math.round((ScrHeight - height)/2);

    window.open('image.php?src=' + src, 'popupWindow', "menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,copyhistory=no,width=" + width + ",height=" + height + ",left=" + PosX + ",top=" + PosY);
}

function ksiegapaste(text) {
    document.ksiegaform.gbtext.value = document.ksiegaform.gbtext.value + text;
    document.ksiegaform.gbtext.focus();
}

function searchpage(page) {
    document.szukaj.page.value = page;
    document.szukaj.submit();
}

function changetype(nr) {
    if(nr==1) {
        document.szukaj.ty1.checked = false;
    }
    if(nr==2) {
        document.szukaj.ty2.checked = false;
    }
}


