/**
 * <p>A simple function for turning a link into a popup.</p>
 *
 * <p>Accepts a configuration object (see argument list) which may
 * contain any or all of the following properties:</p>
 *
 * <ul>
 * <li><code>height</code> -- The height of the window to pop up.</li>
 * <li><code>width</code> -- The width of the window to pop up.</li>
 * <li><code>toolbar</code> -- If <code>yes</code>, shows a toolbar in the
 * popup (defaults to <code>no</code>.</li>
 * <li><code>scrollbars</code> -- If <code>yes</code>, shows scrollbars in
 * the popup (defaults to <code>yes</code>).</li>
 * <li><code>menubar</code> -- If <code>yes</code>, shows the menu bar in the
 * popup (defaults to <code>no</code>).</li>
 * <li><code>status</code> -- If <code>yes</code>, shows the status bar in the
 * popup (defaults to <code>yes</code>).</li>
 * </ul>
 *
 * @param {String|HTMLElement} elem The link to turn into a popup.
 * @param {Object} The configuration object. Optional.
 */
WOL.widget.popupLink = function(elem, config) {
   var defaultConfig = {
      'scrollbars': 'yes',
      'menubar': 'no',
      'toolbar': 'no',
      'status': 'yes',
      'resizable': 'yes'
   };
   
   if(typeof(elem) == 'string') {
      elem = document.getElementById(elem);
   }; 
   
   if(typeof(config) == 'undefined') {
      config = {};
   };

   var featureString = '';
   if(config['height']) {
      featureString += 'height=';
      featureString += config['height'];
      featureString += ',';
   };
   if(config['width']) {
      featureString += 'width=';
      featureString += config['width'];
      featureString += ',';
   };
   for(var prop in defaultConfig) {
      featureString += prop;
      featureString += '=';
      featureString += (config[prop] || defaultConfig[prop]);
      featureString += ','
   };
   
   var popFunc = function(e) {
      Evt.preventDefault(e);
      var p = window.open(this.href, 'popup', featureString);
      p.focus();
   };
   
   Evt.addListener(elem, 'click', popFunc);
};
