////////////////////////////////////////////////////////////////////////////////////
//
//     PergPopLib.js 'Pergamentams'(svetainei)
//
////////////////////////////////////////////////////////////////////////////////////

window.onerror=null; 

var pop=null; 
var popwin=null;

var filwin=null;
var filwinName="FileW";

var scrX, scrY;
var scrW, scrH;

function RodykPagr(File)
{ 
  if ( window.opener )
  {
    if ( window.opener.window.focus ) window.opener.window.focus();
    window.opener.window.location.href=File;
  }
}

function RodykFileTen(File,scrX,scrY,w,h)
{ 
  OpenFileWin(File,scrX,scrY,w,h);
}

function RodykFile(File)
{ 
  w=640; h=screen.availHeight/2+16;
  scrX=screen.availWidth-w-12;
  scrY=screen.availHeight-h-32;
  if ( scrY<32) scrY=32; if ( scrX<16 ) scrY=16; 

  OpenFileWin(File,scrX,scrY,w,h);
}

function RodykFileKampe(File,w,h)
{ 
  scrX=screen.availWidth-w-12;
  if ( scrX<0 ) scrX=0;  

  scrY=screen.availHeight-h-32;
  if ( scrY<0 ) scrY=0;  

  OpenFileWin(File,scrX,scrY,w,h);
}

function OpenFileWin(url,x,y,w,h) 
{
  ClosePopWindow(); 
  CloseFileWindow(); 

  filwin=window.open(url,filwinName,
    "resizable=no,scrollbars=yes,menubar=no,width="+w+",height="+h+",left="+x+",top="+y);     

  if ( filwin.focus ) filwin.focus();  
}


function MyScreen() 
{
  scrW=screen.availWidth-32;
  scrH=screen.availHeight-96;
}
 
function openWindow(url) 
{
  var str;
  var Zoom=1;

  if ( parseInt(navigator.appVersion)<4 ) return;  

  ClosePopWindow(); 

  str="<html><head><title>Zoom</title>";

  str=str+"<SCRIPT language=JavaScript1.2> ";

  str=str+"var curElement, imgHeight=0, imgWidth=0, oldLeft=0, oldTop=0; "; 

  str=str+"var markRefresh=10; "; 
  str=str+"var markID=null; ";
  str=str+"var kf=1; ";
  str=str+"var wMark; ";
  str=str+"var wPosFl=0; ";
  str=str+"var theIm=null; ";
  str=str+"var imReady=null; ";
  str=str+"var ZoomFl=0; ";
  str=str+"var hZoomFl=0; ";
  str=str+"var zooming=0; ";
  str=str+"var ZoomK=10; ";
  str=str+"var evt=0; evl=0; ";
  str=str+"var navDOM=null; ";
  str=str+"var windowHeight, pictHeight, pictActHeight; "; 
  str=str+"var windowWidth, pictWidth, pictActWidth; ";  


  str=str+"function ZoomWin() { ";
  str=str+"if ( zooming==0 || ZoomK<20 ) { ";
  str=str+"ZimnmDiv.style.border='0px'; ";
  str=str+"Zimnm.style.visibility='hidden'; return; } ";

  str=str+"ZimnmDiv.style.top=windowHeight-286; ";
  str=str+"Zimnm.style.visibility='visible'; ";
  str=str+"ZimnmDiv.style.border='1px solid'; ";

  str=str+"evl=event.offsetX; ";
  str=str+"evt=event.offsetY; ";

  str=str+"if ( evl<64 ) evl=32; ";
  str=str+"evl=evl-32; "; 
  str=str+"if ( evt<32 ) evt=32; ";
  str=str+"evt=evt-32; ";
  str=str+"evr=evl+256; evb=evt+256; ";

  str=str+"cr='rect('+evt+','+evr+','+evb+','+evl+')'; ";
  str=str+"if (!Zimnm.src) Zimnm.src=imnm.src; ";
  str=str+"Zimnm.style.clip=cr; } ";


  str=str+"function doDragStart() { "; 
  str=str+"if ( ZoomFl==0 && hZoomFl==0 ) return; ";
  str=str+"if ( event.srcElement.tagName=='IMG' ) event.returnValue=false; ";
  str=str+"} ";


  str=str+"function doMouseDown() { ";
  str=str+"if ((event.button==1) && (event.srcElement.tagName=='IMG' )) { ";
  str=str+"curElement=event.srcElement; ";
  str=str+"curElement.style.cursor='default'; ";  

//  str=str+"alert(zooming+' '+ZoomFl+' '+hZoomFl);";

  str=str+"if ( zooming==1 && hZoomFl==0 ) return; ";
//  str=str+"if ( ZoomFl==0 && hZoomFl==0 ) return; ";

  str=str+"curElement.style.cursor='move'; ";
  str=str+"oldTop=event.clientY; oldLeft=event.clientX; ";
  str=str+"imgWidth=curElement.offsetWidth; ";
  str=str+"imgHeight=curElement.offsetHeight; "; 
  str=str+" } ";
  str=str+"} ";


  str=str+"function doMouseMove() { ";
  str=str+"var dLeft=0, dTop=0, newLeft=0, newTop=0; ";

  str=str+"if ( zooming==1 && hZoomFl==0 ) return; ";
//  str=str+"if ( ZoomFl==0 && hZoomFl==0 ) return; ";

  str=str+"if ( (event.button==1) && (curElement!=null) ) { "; 
  str=str+"newLeft=event.clientX; dLeft=newLeft-oldLeft; oldLeft=newLeft; ";
  str=str+"curElement.style.pixelLeft=curElement.style.pixelLeft+dLeft; ";
  str=str+"if ( curElement.style.pixelLeft>0 ) curElement.style.pixelLeft=0; ";
  str=str+"if ( curElement.style.pixelLeft+imgWidth<windowWidth ) curElement.style.pixelLeft=windowWidth-imgWidth; ";

  str=str+"newTop=event.clientY; dTop=newTop-oldTop; oldTop=newTop; ";
  str=str+"curElement.style.pixelTop=curElement.style.pixelTop+dTop; ";
  str=str+"if ( curElement.style.pixelTop>0 ) curElement.style.pixelTop=0; ";
  str=str+"if ( curElement.style.pixelTop+imgHeight<windowHeight ) curElement.style.pixelTop=windowHeight-imgHeight; ";
  str=str+"dLeft=0; dTop=0; ";

  str=str+"event.returnValue=false; event.cancelBubble=true; ";
  str=str+" } ";
  str=str+"} ";


  str=str+"function DisplayNewSize(theImg){ "; 
  str=str+"windowHeight=pictHeight=pictActHeight=theImg.height; "; 
  str=str+"windowWidth=pictWidth=pictActWidth=theImg.width; ";  

//  str=str+"alert('Img: '+theImg.name+' '+windowHeight+' '+windowWidth); ";
//  str=str+"alert('Scr: '+screen.width+' '+screen.height); ";

//  str=str+"window.document.close();";

  str=str+"if ( windowWidth>screen.width-64 ) { ";
  str=str+"kf=windowWidth/(screen.width-64); ";
  str=str+"windowWidth=windowWidth/kf; ";
  str=str+"windowHeight=windowHeight/kf; ";
  str=str+"ZoomFl=1; } ";

//  str=str+"if ( windowHeight>screen.height-128 ) { ";
//  str=str+"kf=windowHeight/(screen.height-128); "; 
//  str=str+"windowWidth=windowWidth/kf; windowHeight=windowHeight/kf; }";

  str=str+"windowHeight=pictHeight=parseInt(windowHeight); "; 
  str=str+"windowWidth=pictWidth=parseInt(windowWidth); ";  

  str=str+"if ( zooming==1 ) { ";
  str=str+"theImg.height=pictHeight; "; 
  str=str+"theImg.width=pictWidth; ";  
  str=str+"} else { ";
  str=str+"theImg.height=pictActHeight; "; 
  str=str+"theImg.width=pictActWidth; ";  
  str=str+"} ";

  str=str+"ZoomK=parseInt(pictActWidth*10/pictWidth); ";  

  str=str+"if ( windowHeight>screen.height-96 ) ";
  str=str+"{ windowHeight=screen.height-96; ZoomFl=1; hZoomFl=1; }";

  str=str+"self.resizeTo(windowWidth,windowHeight); "; 
  str=str+"theIm=theImg; imReady=true; "; 

  str=str+"return; } ";


  str=str+"function imChange() { ";

  str=str+"if ( imReady==null || ZoomFl==0 ) { ";

  str=str+"if ( theIm ) theIm.style.cursor='default'; ";
  str=str+"return; }";

  str=str+"if ( zooming==1 ) zooming=0; else zooming=1; ";

  str=str+"if ( zooming==1 ) { ";
  str=str+"if ( theIm ) theIm.height=pictHeight; "; 
  str=str+"if ( theIm ) theIm.width=pictWidth; ";  

  str=str+"hZoomFl=1; "; 
  str=str+"if ( pictHeight<=windowHeight+4 ) { ";
  str=str+" hZoomFl=0; } ";  

  str=str+"} ";
  str=str+"else { ";
  str=str+"if ( theIm ) theIm.height=pictActHeight; "; 
  str=str+"if ( theIm ) theIm.width=pictActWidth; "; 
  str=str+"ZimnmDiv.style.border='0px'; ";
  str=str+"Zimnm.style.visibility='hidden'; ";
  str=str+"} ";

  str=str+"if ( theIm ) theIm.style.pixelLeft=0; "; 
  str=str+"if ( theIm ) theIm.style.pixelTop=0; ";

  str=str+"return; } ";


  str=str+"function setVals() { ";
  str=str+"wMark=null; ";
  str=str+"if ( document.layers ) { ";
  str=str+"navDOM=true; wMark=document.waterMark; ";
  str=str+"} else { ";
  str=str+"if ( document.all ) { ";
  str=str+"wMark=document.all['waterMark']; ";
  str=str+"} else { ";
  str=str+"if ( document.getElementById ) { ";
  str=str+"navDOM=true; wMark=document.getElementById('waterMark'); ";
  str=str+"} } } ";

  str=str+"if ( wMark.style ) wMark=wMark.style; ";

  str=str+"} ";


  str=str+"function wRefresh() { ";
  str=str+"wMark.left=2+(navDOM?pageXOffset:document.body.scrollLeft); ";
  str=str+"wMark.top=2+(navDOM?pageYOffset:document.body.scrollTop); ";
  str=str+"} ";


  str=str+"function markMe(){ "; 
  str=str+"setVals(); ";
  str=str+"window.onresize=setVals; ";
  str=str+"markID=setInterval('wRefresh()',markRefresh); ";
  str=str+"} ";


  str=str+"document.ondragstart=doDragStart; ";
  str=str+"document.onmousedown=doMouseDown; ";
  str=str+"document.onmousemove=doMouseMove; ";
  str=str+"document.onmouseup=new Function('curElement=null'); ";

  str=str+"window.onload=markMe; ";

  str=str+"</SCRIPT>";

  str=str+"<style>";
  str=str+"A.eV {color:white; text-decoration:none;}";
  str=str+"A.eV:hover {color:red; text-decoration:none;}";
  str=str+"</style>";
  str=str+"</head>";

  str=str+"<body bgcolor='#dddddd' topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>";

  str=str+"<center>";

  str=str+"<div style='position:absolute; left:0px; top:0px'>";
  str=str+"<img src="+url+" alt='' name='imnm' id='imnm' onload='DisplayNewSize(this)' onmousemove='ZoomWin()' style='position:absolute; top:0pt; left:0pt; z-index:1; cursor:move'>";
  str=str+"</div>"; 

  str=str+"<div id='waterMark' onclick=imChange() style='position:absolute; left:2px; top:2px'>";
  str=str+"<table widh=32 border=1><tr><td>";
  str=str+"<a class='eV' href='javascript:void(0)'><b><font size=+1>&lt;&lt;&nbsp;&gt;&gt;</font></b></a>";
  str=str+"</td></tr></table>";
  str=str+"</div>";

  str=str+"<div id='ZimnmDiv' style='width: 256px; height: 256px; left: 2px; top: 32; overflow: hidden; position: absolute; border: 0px solid'> ";
  str=str+"<img id='Zimnm' style='height: expression(imnm.height*ZoomK/10); left: expression(-evl*ZoomK/10); position: relative; top: expression(-evt*ZoomK/10); width: expression(imnm.width*ZoomK/10); visibility: hidden'> ";
  str=str+"</div> ";

  str=str+"</center></body></html>"; 

  if ( Zoom==0 || navigator.appName!="Microsoft Internet Explorer" ) 
  {
    str="<html><head><title>Zoom</title></head>";

    str=str+"<body bgcolor='#dddddd'><center>";

    str=str+"<div style='position:absolute; left:0px; top:0px'>";
    str=str+"<img src="+url+" id='pav' alt=''>";
    str=str+"</div>"; 

    str=str+"</center></body></html>"; 
  }

  MyScreen();

pop='menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhist=no,width='+scrW+',height='+scrH+',top=16,left=16';

  popwin=window.open("",'Popupas',pop);

  popwin.document.write(str); 
  if ( popwin.focus ) popwin.focus(); 
}


function openSchWindow(url) 
{
  var str;
  var Zoom=1;

  if ( parseInt(navigator.appVersion)<4 ) return;  

  ClosePopWindow(); 

  str="<html><head>";
  str=str+"<meta http-equiv='Content-Type' content='text/html; charset=utf-8'> ";
  str=str+"<title>View</title>";
  str=str+"<SCRIPT language=JavaScript1.2> ";

  str=str+"var curElement, imgHeight=0, imgWidth=0, oldLeft=0, oldTop=0; "; 

  str=str+"var kf=1; ";
  str=str+"var wMark; ";
  str=str+"var wPosFl=0; ";
  str=str+"var theIm=null; ";
  str=str+"var imReady=null; ";
  str=str+"var ZoomFl=0; ";
  str=str+"var hZoomFl=0; ";
  str=str+"var zooming=1; ";
  str=str+"var windowHeight, pictHeight, pictActHeight; "; 
  str=str+"var windowWidth, pictWidth, pictActWidth; ";  

  str=str+"function DisplayNewSize(theImg){ "; 
  str=str+"windowHeight=pictHeight=pictActHeight=theImg.height; "; 
  str=str+"windowWidth=pictWidth=pictActWidth=theImg.width; ";  

//  str=str+"alert('Img: '+theImg.name+' '+pictActWidth+' '+pictActHeight); ";
//  str=str+"alert('Scr: '+screen.width+' '+screen.height); ";

//  str=str+"window.document.close();";

  str=str+"if ( windowWidth>screen.width-64 ) { ";
  str=str+"kf=windowWidth/(screen.width-64); ";
  str=str+"windowWidth=windowWidth/kf; ";
  str=str+"windowHeight=windowHeight/kf; ";
  str=str+"ZoomFl=1; } ";

//  str=str+"if ( windowHeight>screen.height-128 ) { ";
//  str=str+"kf=windowHeight/(screen.height-128); "; 
//  str=str+"windowWidth=windowWidth/kf; windowHeight=windowHeight/kf; }";

  str=str+"windowHeight=pictHeight=parseInt(windowHeight); "; 
  str=str+"windowWidth=pictWidth=parseInt(windowWidth); ";  

  str=str+"if ( zooming==1 ) { ";
  str=str+"theImg.height=pictHeight; "; 
  str=str+"theImg.width=pictWidth; ";  
  str=str+"} else { ";
  str=str+"theImg.height=pictActHeight; "; 
  str=str+"theImg.width=pictActWidth; ";  
  str=str+"} ";

  str=str+"windowWidth=windowWidth+26; ";
  str=str+"windowHeight=windowHeight+29; ";
//  str=str+"alert('Win: '+windowWidth+' '+windowHeight); ";

  str=str+"if ( windowHeight>screen.height-96 ) ";
  str=str+"{ windowHeight=screen.height-96; ZoomFl=1; hZoomFl=1; }";

  str=str+"self.resizeTo(windowWidth,windowHeight); "; 
  str=str+"theIm=theImg; imReady=true; "; 

  str=str+"return; } ";

  str=str+"function imChange() { ";

  str=str+"if ( imReady==null || ZoomFl==0 ) return; ";

  str=str+"if ( zooming==1 ) zooming=0; else zooming=1; ";

  str=str+"if ( zooming==1 ) { ";
  str=str+"theIm.height=pictHeight; "; 
  str=str+"theIm.width=pictWidth; ";  

  str=str+"hZoomFl=1; "; 
  str=str+"if ( pictHeight<=windowHeight+4 ) { ";
  str=str+" hZoomFl=0; } ";  

  str=str+"} ";
  str=str+"else { ";
  str=str+"theIm.height=pictActHeight; "; 
  str=str+"theIm.width=pictActWidth; "; 
  str=str+"} ";

  str=str+"theIm.style.pixelLeft=0; "; 
  str=str+"theIm.style.pixelTop=0; ";

  str=str+"return; } ";

  str=str+"</SCRIPT>";

  str=str+"</head>";

  str=str+"<body bgcolor='#eeeeee' topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>";

  str=str+"<center>";

  str=str+"<div style='position:absolute; left:0px; top:0px'>";
  str=str+"<img src="+url+" alt='' name='imnm' onload='DisplayNewSize(this)' style='position:absolute; top:0pt; left:0pt; z-index:1;'>";
  str=str+"</div>";

//  str=str+"<p><font size='1' face='Verdana' color='#FFFFFF'><b>";
//  str=str+"Paveikslas";
//  str=str+"</b></font>";
 
  str=str+"</center></body></html>"; 

  if ( Zoom==0 || navigator.appName!="Microsoft Internet Explorer" ) 
  {
    str="<html><head><title>Zoom</title></head>";

    str=str+"<body bgcolor='#dddddd'><center>";

    str=str+"<div style='position:absolute; left:0px; top:0px'>";
    str=str+"<img src="+url+" id='pav' alt=''>";
    str=str+"</div>"; 

    str=str+"</center></body></html>"; 
  }

  MyScreen();

pop='menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhist=no,width='+scrW/2+',height='+scrH/2+',top=16,left=4';

  popwin=window.open("",'Popupas',pop); 

  popwin.document.write(str); 
  if ( popwin.focus ) popwin.focus(); 
}


function CloseFileWindow() 
{
  if ( filwin!=null && filwin.open ) { filwin.close(); }
  filwin=null; 
}

function ClosePopWindow() 
{
//  CloseFileWindow(); 

  if ( parseInt(navigator.appVersion)<4 ) return;

  if ( popwin!=null && popwin.open ) popwin.close(); 
  popwin=null; 
}

function CloseAllWindows() 
{
  ClosePopWindow();
  CloseFileWindow(); 
}

window.onfocus=CloseAllWindows;



