/* popuupWindow....................................................................... */

function openWindow(w,h) {
openParam="toolbar=no,resizable=yes,close=yes,status=no,location=no,directories=no,menubar=no,scrollbars=no,width="+w+",height="+h;
return window.open("","launch",openParam);
}
function openWindowWithScrollbar(w,h) {
openParam="toolbar=no,resizable=yes,close=yes,status=no,location=no,directories=no,menubar=no,scrollbars=yes,width="+w+",height="+h;
return window.open("","launch",openParam);
}

/* make a new window and fit to image................................................. */

windowList = new Array();
function tWindowObj(_hWindow, _imgName){
  this.hWindow = _hWindow;
  this.imgName = _imgName;
}

var popWin = window;
var fOpenMode = 1;
function newWindowOpen(popImageUrl, title, fOpenMode, beforeSizeX, beforeSizeY){
  if(beforeSizeX == null) beforeSizeX = 640;
  if(beforeSizeY == null) beforeSizeY = 480;

  var htmlData = '<html><head><title>' +title +'</title>'
                +'<link rel="stylesheet" type="text/css" href="main.css">'
                +'<script type="text/javascript">'
                +'function winAutoResize(){resizeWin(document.images["img"].width, document.images["img"].height)}'
                +'</scr' +'ipt></head><body id="cover">'
                +'<a href="javascript:close()"><img src="' +popImageUrl +'" name="img" title=""></a>'
                +'</body></html>';

  var j = 0;
  if((fOpenMode == 1) && (windowList.length != 0)){
    popWin = window;
    workList = new Array();
    for(i=0;i<windowList.length;i++){
      if(!windowList[i].hWindow.closed){
        workList[j] = windowList[i];
        j++;
      }
    }
    windowList = workList;

    var fMatch = false;
    for(i=0;i<windowList.length;i++){
      if(windowList[i].imgName == popImageUrl){
        popWin = windowList[i].hWindow;
        fMatch = true;
        break;
      }
    }
  }

  if((popWin == window) || popWin.closed || (fOpenMode == 3)) {
    popWin = window.open("" , "_blank", "toolbar=no,resizable=no,close=yes,status=no,location=yes,directories=no,menubar=no,scrollbars=no, width=" +beforeSizeX +", height=" +beforeSizeY)
    if(fOpenMode == 1){
      windowList[windowList.length] = new tWindowObj();
      windowList[windowList.length -1].hWindow = popWin;
      windowList[windowList.length -1].imgName = popImageUrl;
    }
  }else{
    popWin.focus();
  }
  if(((fOpenMode == 1) && !fMatch) || (fOpenMode == 2) || (fOpenMode == 3)){
    popWin.document.open();
    popWin.document.write(htmlData);
    popWin.document.close();
  }
  return(false);
}

