    var toolWindow;
    function newToolWindow(contentsURL, winName, x, y, width, height){
     if (!width) var w = 500; 
     else w = width;
     
     w = 0.9*(window.screen.width-10);
     
     if (!height) var h = 400;
     else h = height;
     
     h = 0.9*(window.screen.height-10);
     
     //tool window: without menubar, toolbar, resizable, location, status. set scrollbars.
     //return newWindowCore(contentsURL, winName, x, y, w, h, 0, 0, 0, 0, 1, 0);
     toolWindow = newWindowCore(contentsURL, winName, x, y, w, h, 0, 0, 0, 0, 1, 0);
     toolWindow.focus();
    }
    
    function closeTool(){
	    if (toolWindow){
		    toolWindow.close();
	    }
    }
    
    function newWindowCore(contentsURL, winName, x, y, width, height, menubar, toolbar, resizable, location, scrollbars, status) {
          
     if (!width) var w = 180; 
     else w = width;
     
     if (!height) var h = 300;
     else h = height;
     
     if (!x) var x = 0; 
     else x= (window.screen.width/2) - (w/2);
     if (!y) var y = 0; 
     else y= (window.screen.height/2) - (h/2);

     if (x<0) x=0;
     if (y<0) y=0;

     var winProps = "menubar=" + menubar + ",toolbar=" + toolbar 
      + ",resizable=" + resizable + ",location=" + location 
      + ",status=" + status + ",scrollbars=" + scrollbars;
     
     var args = "width=" + w + ",height=" + h
      + "," + winProps
      + ",screenx=" + x + ",screeny=" + y
      + ",left=" + x + ",top=" + y;
      
     var newWin = window.open(contentsURL, winName, args);
          
     return newWin;
    }
    
    