////////////////////////////////////////////////////////////////////////////////////
//
//     ValdoPopWinLib.js 'Audiniams'
//
////////////////////////////////////////////////////////////////////////////////////

window.onerror=null; 

var str;
var kf=1;
var scrW, scrH;

var PopWin=null;
var PopWinName="pop";
var PopWinIsOpen="false";

function MyScreen() 
{
  scrW=screen.availWidth;
  scrH=screen.availHeight;
}
 
function OpenPopWin(url,x0,y0) 
{
  if ( parseInt(navigator.appVersion)<4 ) return;  

  ClosePopWin(); MyScreen(); 
  
  PopWin=window.open(url,PopWinName,
    "resizable=no,scrollbars=yes,menubar=no,width="+224+",height="+scrH*2/3+",left="+x0+",top="+y0);

  if ( PopWin.focus ) PopWin.focus();
}

function OpenPopBotWin(url,x,y) 
{
  if ( parseInt(navigator.appVersion)<4 ) return;  

  ClosePopWin(); MyScreen(); x0=8; y0=scrH-y-48;
  
  PopWin=window.open(url,PopWinName,
    "resizable=no,scrollbars=no,menubar=no,width="+x+",height="+y+",left="+x0+",top="+y0);

  if ( PopWin.focus ) PopWin.focus();
}

function OpenOnParent(url) 
{
  if ( parseInt(navigator.appVersion)<4 ) return;  

  if ( window.opener )
  {
    window.opener.location=url;
  }

  if ( window.opener.focus ) window.opener.focus();
  window.close();
}

function openFullImgWindow(url,txtt) 
{
  var str;
  var Zoom=1;

  if ( parseInt(navigator.appVersion)<4 ) return;  

  ClosePopWin(); 

  txth="&nbsp;&nbsp;";

  if ( txtt!=null )
    txt=txtt+txth;
  else txt="Image"+txth;

  str="<html><head><title>"+txt+"</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 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-32 ) { ";
  str=str+"kf=windowWidth/(screen.width-32); ";
  str=str+"windowWidth=windowWidth/kf; ";
  str=str+"windowHeight=windowHeight/kf; ";
  str=str+"ZoomFl=1; } ";

  str=str+"if ( windowHeight>screen.height-64 ) { ";
  str=str+"kf=windowHeight/(screen.height-64); "; 
  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-48 ) ";
  str=str+"{ windowHeight=screen.height-48; ZoomFl=1; hZoomFl=1; }";

  str=str+"self.resizeTo(windowWidth,windowHeight); "; 
  str=str+"theIm=theImg;  "; 

  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)' onclick='window.close()' style='position:absolute; top:0pt; left:0pt; z-index:1;'>";
  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();

  if ( navigator.appName!="Microsoft Internet Explorer" ) 
  {
pop='menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhist=no,width='+scrW-32+',height='+scrH-48+',top=16,left=4';

    PopWin=window.open('','Popupas',pop); 
  }
  else 
  {
pop='menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhist=no,width='+scrW/4+',height='+scrH/4+',top=16,left=4';

    PopWin=window.open('tuscias.htm','Popupas',pop);
  }

  PopWin.document.write(str); 
  if ( PopWin.focus ) PopWin.focus(); 
}

function ClosePopWin() 
{
  if ( parseInt(navigator.appVersion)<4 ) return;
  
  if ( PopWin!=null && PopWin.open ) PopWin.close(); 
  PopWin=null; 
}

function CloseAllWindows() 
{
  ClosePopWin(); 
}

window.onfocus=ClosePopWin;
