/*
Popup-object
*/
function Popup ( url, name ) {
    this.win = false;
    this.url = url;
    this.name = ( name ) ? name : "win" + Math.floor(Math.random() * 100000);
    this.size = {
          width : Math.floor (screen.width / 2),
         height : Math.floor (screen.height / 2)
                };
    this.position = {
                top : Math.floor (screen.width / 2) - Math.floor (this.size.width / 2),
               left : Math.floor (screen.height / 2) - Math.floor (this.size.height / 2)
                    };
    this.display = {
          location : true,
           menubar : true,
        scrollbars : true,
            status : true,
           toolbar : true
                   }
    this.dependent = false;
    this.resizable = true;



    this.active = function () {
        if ( this.win && !this.win.closed ) {
            return true;
        }
        else {
            return false;
        }
    }

    this.open = function () {
        param_string  = "width=" + this.size.width + ",height=" + this.size.height;
        param_string += ",top=" + this.position.top + ",left=" + this.position.left;

        if ( this.display.location )
            param_string += ",location=yes";
        if ( this.display.menubar )
            param_string += ",menubar=yes";
        if ( this.display.scrollbars )
            param_string += ",scrollbars=yes";
        if ( this.display.status )
            param_string += ",status=yes";
        if ( this.display.toolbar )
            param_string += ",toolbar=yes";
        if ( this.display.dependent )
            param_string += ",dependent=yes";
        if ( this.display.resizable )
            param_string += ",resizable=yes"

        this.win = window.open(this.url, this.name, param_string);
        this.focus();

        if (this.win == 'failed' || this.win == null)
            alert ("The window couldn't be opened. Maybe your Browser is blocking Popup-Windows?");
    }

    this.close = function () {
        if ( this.active() )
            this.win.close();
    }

    this.focus = function () {
        if ( this.active() )
            this.win.focus();
    }

    this.blur = function () {
        if ( this.active() )
            this.win.blur();
    }

    this.resize = function ( width, height ) {
        if ( (width >= 100) && (width <= screen.width) )
            this.size.width = width;
        if ( (height >= 100) && (height <= screen.height) )
            this.size.height = height;
        if ( ((this.size.width+this.position.left) > screen.width) ||
             ((this.size.height+this.position.top) > screen.height) )
            this.center();

        if ( this.active() )
            this.win.resizeTo(this.size.width, this.size.height);
    }

    this.move = function ( x, y ) {
        if ( x >= 0 )
            this.position.left = x;
        if ( y >= 0 )
            this.position.top = y;

        if ( this.active() )
            this.win.moveTo(this.position.left, this.position.top);
    }

    this.center = function () {
        this.position.left = Math.floor (screen.width / 2) - Math.floor (this.size.width / 2);
        this.position.top = Math.floor (screen.height / 2) - Math.floor (this.size.height / 2);

        if ( this.active() )
            this.win.moveTo(this.position.left, this.position.top);
    }

    this.displaySimple = function () {
        this.display.location = false;
        this.display.menubar = false;
        this.display.scrollbars = false;
        this.display.status = false;
        this.display.toolbar = false;
    }
}

