
var popupHandle = null;

var isIE = 0;

function __popupCenterWindow(w,h,title,src,content,style,resizable) {
  var win = window.top;
  var win2 = window;
  var xOffset = 0;
  var yOffset = 0;
  //alert(w+" "+screen.availWidth);
  if (w>screen.availWidth || h>screen.availHeight) {
    w = screen.availWidth-120;
    h = screen.availHeight-160;
    resizable = true;
  } else if (isIE) {
    xOffset = win.screenLeft + (win.document.documentElement.offsetWidth-w-10)/2;
    yOffset = win.screenTop + (win.document.documentElement.offsetHeight-h-104)/2;
    xOffset = Math.min(xOffset, screen.availWidth-w-10);
    yOffset = Math.min(yOffset, screen.availHeight-h-30);
  } else {
    xOffset = win.screenX + (win.outerWidth-w-6)/2;
    yOffset = win.screenY + (win.outerHeight-h-44)/2;
    xOffset = Math.min(xOffset, screen.availWidth-w-6);
    yOffset = Math.min(yOffset, screen.availHeight-h-44); 
  }
  xOffset = Number( Math.max(xOffset, 0) );
  yOffset = Number( Math.max(yOffset, 0) );

//  if (!isOpera && popupHandle && !popupHandle.closed) popupHandle.close();
  if (popupHandle && !popupHandle.closed) popupHandle.close();

  var attr = 'toolbar=no,menubar=no,location=no,personalbar=no,directories=no';
  if (resizable) attr += ',status=yes,resizable=yes,scrollbars=yes';
  else attr += ',status=no,resizable=no,scrollbars=no';
  attr += ',width='+w+',height='+h+',screenX='+xOffset+',screenY='+yOffset+',left='+xOffset+',top='+yOffset;
  
  if (src) {
//    alert(src);
  	var popup = win2.open(src,'inventor_popup',attr);
	} else if (content) {
    var s = '';
    s += '<style type="text/css">'
    s += 'body, tbody {font-size:11px;font-family:Verdana,Geneva,Arial,Helvetica,sans-serif}';
    s += 'body {margin:0px;padding:0px}';
    if (!resizable) s += 'body {overflow:hidden}';
    if (style) s += style;
    s += '</style>';
    
    var c = '';
    c += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
    c += '<html xmlns="http://www.w3.org/1999/xhtml"><head>';
    c += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
    c += '<meta http-equiv="imagetoolbar" content="no" />';
    c += '<title>'+title+'</title>'+s+'</head>';
    c += '<body onkeypress="if (event &amp;&amp; event.keyCode==27) self.close()">'+content+'</body>';
    c += '</html>';
    
    var popup = win2.open('','inventor_popup',attr); // on ssl open('/', or open('.',
    popup.document.open();
    popup.document.write(c);
    popup.document.close();
	}

  if (popup && popup.focus) popup.focus();
  popupHandle = popup;

  //popupHandle._onkeypress = 123;
}

function popupImage(sender,src,w,h,Astyle,Atext) {
  winW = w+20;
  winH = h+(Atext?80:20);
//  alert(winW);
  //var content = '<img title="Zamknij" onclick="window.close()" style="cursor:pointer;_cursor:hand" src="'+src+'" border="0" width="'+w+'" height="'+h+'" alt="" />';
  var content = '<img title="Zamknij" onclick="window.close()" style="cursor:pointer" src="'+src+'" border="0" width="'+(w)+'" height="'+(h)+'" alt="" />';
if (Atext) content += '<div style="margin-top:10px;height:48px;overflow:auto">'+unescape(Atext)+'</div>';
var  title = '';
    style = 'body {margin:10px}';

  __popupCenterWindow(winW,winH,title,null,content,style,false);
}

function popupPage(sender,src,w,h) {
  winW = w+20;
  winH = h+20;
//  alert(winW);
  //var content = '<img title="Zamknij" onclick="window.close()" style="cursor:pointer;_cursor:hand" src="'+src+'" border="0" width="'+w+'" height="'+h+'" alt="" />';
//  var content = '<img title="Zamknij" onclick="window.close()" style="cursor:pointer" src="'+src+'" border="0" width="'+(w)+'" height="'+(h)+'" alt="" />';
//if (Atext) content += '<div style="margin-top:10px;height:48px;overflow:auto">'+unescape(Atext)+'</div>';
var  title = '';
    style = 'body {margin:10px}';

  __popupCenterWindow(winW,winH,title,src,content=null,style,true);
}
