/**
 *This creates appropriate popups.
 *@author J Francis
 */
 
/**
 *Low level create popup function - this is designed to be very configurable.
 *@param Object options Should be an anonymous class
 *@param window Handle 
 */
function lowLevelPopUpMaker( url, options ){
  
  var mywin = null;

  if( url ){

    var arg = '';
    
    //Height
    if( options.height ){
      
      if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'height=' + options.height;
    }
    
    //left
    if( options.left ){
      
       if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'left=' + options.left;
    }
    
    //menubar
    if( options.menubar ){
      
       if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'menubar=' + options.menubar;
    }
    
    //resizable
    if( options.resizable ){
      
      if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'resizable=' + options.resizable;
    }
    
    //screenX
    if( options.screenX ){
      
       if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'screenX=' + options.screenX;
    }
    
    //screenY
    if( options.screenY ){
      
       if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'screenY=' + options.screenY;
    }
    
    //scrollbars
    if( options.scrollbars ){
      
       if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'scrollbars=' + options.scrollbars;
    }
    
    //status
    if( options.status ){
      
      if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'status=' + options.status;
    }
    
    //toolbar
    if( options.toolbar ){
      
      if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'toolbar=' + options.toolbar;
    }
    
    //top
    if( options.top ){
      
      if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'top=' + options.top;
    }
    
    //Width
    if( options.width ){
      
      if( arg.length > 0 )
        arg = arg + ',';
        
      arg = arg + 'width=' + options.width;
    }
    
    
    mywin = window.open( url, 'Popup', arg);
             
    mywin.focus();
  }

  return mywin;
}
 
/**
 *Open a popup window with a given url.
 *@return handle to the popup.
 */
function activatePopUp( url, width, height, screenX, screenY){
  
  var options = {
    width:   width,
    height:  height,
    screenX: screenX,
    screenY: screenY,
    
    menubar:    'no',
    scrollbars: 'no',
    status:     'no', //yes
    toolbar:    'no',
    
    left: screenX,
    top: screenY,
    
    resizable: 'yes'
  };
  
  var mywin = lowLevelPopUpMaker( url, options);

  /*
  var mywin = null;
  if( url ){

    var arg = '';

    arg = arg + 'height=' + height;
    arg = arg + ',width=' + width;
    arg = arg + ',menubar=no';
    arg = arg + ',scrollbars=no';
    arg = arg + ',status=no'; //yes';
    arg = arg + ',toolbar=no';
    arg = arg + ',screenX=' + screenX;
    arg = arg + ',screenY=' + screenY;
    arg = arg + ',left='    + screenX;
    arg = arg + ',top='     + screenY;
    arg = arg + ',resizable=yes'; //'no'
    
    mywin = window.open( url, 'Popup', arg);
             
    mywin.focus();
  }
  */
  
  return mywin;
}

/**
 *Open a popup window with a given url at a given point on the screen
 *@return false Always! This is for links onclick handlers.
 */
function firePopUp( url, width, height){

  var handle = activatePopUp( url, width, height, 100, 0);

  return false;
}

/**
 *Open a popup window with a given url at a given point on the screen
 *@return false Always! This is for links onclick handlers.
 */
function firePopUpAt( url, width, height, screenX, screenY){

  var handle = activatePopUp( url, width, height, screenX, screenY);

  return false;
}

/**
 *Open a popup window with a given url at a given point on the screen
 *@return false Always! This is for links onclick handlers.
 */
function firePopUpExpanded( url, width, height, scrollbars ){
  
  var options = {
    width:   width,
    height:  height,
    screenX: 100,
    screenY:   0,
    
    menubar:    'no',
    scrollbars: 'no',
    status:     'no', //yes
    toolbar:    'no',
    
    left: 100,
    top:    0,
    
    resizable: 'yes'
  };
  
  if( scrollbars )
    options.scrollbars = 'yes';
  
  var mywin = lowLevelPopUpMaker( url, options);

  return false;
}

