/* $Id */
/**
* Open new windows for links to this url
* 
* @param url        STRING The url snippet to look for.
* @param name       STRING The new window's name.
* @param properties ARRAY  An array of key/value pairs for window properties.
*

properties = { 
    "top": 0,
    "left": 0,
    "scrollbars": "yes",
    "resizable": "yes",
    "menubar": "yes",
    "toolbar": "yes",
    "directories ": "yes",
    "location": "yes",
    "height": 0,
    "width":0,
    "declutter": 1 /* When set to 1, this set all "yes/no" properties to "no".
}

*/
function new_windows_by_url(url, name, properties)
{
   
  $('a[@href$="' + url + '"]').click(function(event){
   
    var top    = 0;
    var left   = 0;
    var scrollbars = "yes";
    var resizable = "yes";
    var menubar = "yes";
    var toolbar = "yes";
    var directories = "yes";
    var location = "yes";
    var height = 0;
    var width  = 0;
    var declutter = -1;

    for (key in properties)
    {
      switch(key)
      {
        case "height":
          height = parseInt(properties[key]);
          break;
        
        case "width":
          width = parseInt(properties[key]);
          break;
          
        case "declutter":
          if (1 == parseInt(properties[key]))
          {
            scrollbars = "no";
            resizable = "no";
            menubar = "no";
            toolbar = "no";
            directories = "no";
            location = "no";
          }
          break;

      case "scrollbars":
        scrollbars = properties[key];
        break;

      case "resizable":
        resizable = properties[key];
        break;

      case "menubar":
        menubar = properties[key];
        break;
        
      case "toolbar":
        toolbar = properties[key];
        break;
        
      case "directories":
        directories = properties[key];
        break;

      case "location":
        location = properties[key];
        break;
      }
    }
  
    if ((height == 0) || (screen.availHeight < height)) 
    {
      height = screen.availHeight;
    }
    
    if ((width == 0) || (screen.availWidth < width)) 
    {
      width = screen.availWidth;
    }
    
    if ( top == 0 ) 
    {
      top = ((screen.availHeight - height) / 2);
    }
    
    if ( left == 0 )
    {
      left = ((screen.availWidth - width) / 2);
    } 

    // Set window properties
    var window_properties = 'top=' + top 
                          + ',left=' + left 
                          + ',scrollbars=' + scrollbars 
                          + ',resizable=' + resizable
                          + ',menubar=' + menubar
                          + ',toolbar=' + toolbar
                          + ',directories=' + directories
                          + ',location=' + location
                          + ',width=' + width 
                          + ',height=' + height;
                          
    window.open(this.href, name, window_properties).focus();
    event.preventDefault();
    return false;
  });
 } // END new_windows_by_url()
