/**
 * pop()
 */
function pop(url, width, height, scrollbars, menubar)
{
    var w = new Popup(url, width, height, scrollbars, menubar)
    w.open()
}

/**
 * Popup
 */
function Popup(url, width, height, scrollbars, menubar, toolbar, statusbar, directories, resizable)
{
    this.directories = (directories ? directories : 0)
    this.height      = (height ? height : 240)
    this.location    = 0
    this.menubar     = (menubar ? menubar : 0)
    this.resizable   = (resizable ? resizable : 1)
    this.scrollbars  = (scrollbars ? scrollbars : 1)
    this.statusbar   = (statusbar ? statusbar : 0)
    this.toolbar     = (toolbar ? toolbar : 0)
    this.url         = url
    this.width       = (width ? width : 320)
    this.window      = null
}

Popup.prototype.close = function()
{
    w = this.window
    if (w && ! w.closed)
    {
        if (w.opener && ! w.opener.closed)
            w.opener.focus()
        w.close()
    }
}

Popup.prototype.getFeatures = function()
{
    features  = "directories=" + (this.directories ? 1 : 0)
    features += ",height="     + (this.height      ? parseInt(this.height) : 0)
    features += ",location="   + (this.location    ? 1 : 0)
    features += ",menubar="    + (this.menubar     ? 1 : 0)
    features += ",resizable="  + (this.resizable   ? 1 : 0)
    features += ",scrollbars=" + (this.scrollbars  ? 1 : 0)
    features += ",status="     + (this.statusbar   ? 1 : 0)
    features += ",toolbar="    + (this.toolbar     ? 1 : 0)
    features += ",width="      + (this.width       ? parseInt(this.width) : 0)
    return features
}

Popup.prototype.getName = function()
{
    u = this.url
    i = u.lastIndexOf("/") + 1
    return u.substring(i, u.indexOf(".", i))
}

Popup.prototype.open = function()
{
    this.close()
    w = window.open(this.url, this.getName(), this.getFeatures())
    if (w)
    {
        w.focus()
        if (w.opener == null)
            w.opener = self
    }
    this.window = w
}
