var AWin = null; 
var PicWin = null; 

function OpenWindow(template,aWidth,aHeight) {
  var winOptions = "menubar=0,scrollbars=1,resizable=1,width=" + aWidth + ",height=" + aHeight + ",top=10, left=10";
  if (AWin && !AWin.closed) {
    AWin.close();
  }    
  AWin = window.open(template, "",winOptions);
}

function WritePicWin(myDoc, picture, pWidth, pHeight) {
  myDoc.write('<body bgcolor="#000000"></body>');
  myDoc.write('<img src="' + picture + '" width="' + pWidth + '" height ="' + pHeight + '">');
  myDoc.write('<br><br>');
  myDoc.write('<p align="center">');
  myDoc.write('<form><div align="center"><center><INPUT TYPE="BUTTON" VALUE="Close Window" onClick="top.close()"></center></div></form>');
  myDoc.write('</p>');
}

function OpenPicWindow(picture,pWidth,pHeight) {
  var wWidth = pWidth + 20;
  var wHeight = pHeight + 70;
  var picOptions = "menubar=0,scrollbars=0,resizable=0,width="  + wWidth + ",height=" + wHeight;

  if (!PicWin || PicWin.closed) {
    PicWin = window.open("","PicWin",picOptions);
    WritePicWin(PicWin.document, picture, pWidth, pHeight);
  } else {
    window.open("","PicWin",picOptions);
    PicWin.focus();
    PicWin.document.write();
    PicWin.document.close();
    WritePicWin(PicWin.document, picture, pWidth, pHeight);
  }
}

function FocusPicWin(){
   if (PicWin && !PicWin.closed) {
	PicWin.focus();
   }
}
