
function windowFrame(name, width, height, title)
{
	//this.name = windowFrameId++;
	this.name = name +'windowFrame';
	this.title = title ? title : '';

	this.width = typeof(width) != "undefined" ? width : 500;
	this.height = typeof(height) != "undefined" ? height : 400;

	this.frame;
	this.header;
	this.body;
	this.footer;

	this.closeButton;
	this.submitButton;
	this.cancelButton;
    
    this.panel;
}

windowFrame.prototype.close = function()
{
	if(this.frame !== null)
	{
        var el = document.getElementById(this.name + 'Frame_c');
        if(el)
        {
            document.body.removeChild(el);
        }
        this.panel.destroy();
	}
}

windowFrame.prototype.getName = function()
{
	return this.name;
}

windowFrame.prototype.initAlert = function()
{
	if(this.init())
	{
		this.submitButton.setAttribute('type','button');
		this.submitButton.setAttribute('value','OK');
		this.submitButton.className = "windowButton";

		this.footer.appendChild(this.submitButton);
	}
}

windowFrame.prototype.initConfirm = function()
{
	if(this.init())
	{
		this.submitButton.setAttribute('type','button');
		this.cancelButton.setAttribute('type','button');
		this.submitButton.setAttribute('value','Ja');
		this.cancelButton.setAttribute('value','Nein');

		this.submitButton.className = "windowButton";
		this.cancelButton.className = "windowButton";

		this.footer.appendChild(this.submitButton);
		this.footer.appendChild(this.cancelButton);
	}
}

windowFrame.prototype.initYesNo = function()
{
	this.Confirm();
}

windowFrame.prototype.init = function()
{
	if(document.getElementById(this.name))
	{
		
        el = document.getElementById(this.name);
        //el.style.display = "none";
        //document.body.removeChild(el);
        alert(typeof(el));
	}
    var panel_id = this.name + 'Frame';
    this.frame = document.createElement("div");
    this.frame.setAttribute('id', panel_id);
    this.frame.className = 'yui-panel';

    this.header = document.createElement("div");
    this.header.className = "hd";
    
    this.body = document.createElement("div");
    this.body.setAttribute('id', this.name);
    this.body.className = "bd";

    this.footer = document.createElement("div");
    this.footer.className = "ft";

    this.closeButton = document.createElement("input");
    this.submitButton = document.createElement("input");
    this.cancelButton = document.createElement("input");


    this.frame.appendChild(this.header);
    this.frame.appendChild(this.body);
    this.frame.appendChild(this.footer);

    document.body.appendChild(this.frame);
    
    this.panel = new YAHOO.widget.Panel(panel_id, { 
            width: (this.width + 20) + 'px', 
            visible:false, 
            constraintoviewport:true, 
            draggable:true,
            zindex: 201
        });
    
    this.panel.setHeader(this.title + ' . ');
    this.panel.setBody('');
    this.panel.render();
    this.panel.hideEvent.subscribe(function() {
        this.close();
    }, this, true);

    var fenster = this.frame;
    this.closeButton.onclick = function(){
        fenster.style.display = "none";
        document.getElementsByTagName("body")[0].removeChild(fenster);
    }
	
	return true;
    
}


windowFrame.prototype.setPosition = function()
{
    var Dom = YAHOO.util.Dom,
        height = Dom.getViewportHeight();
        y = (height / 2) - (this.height / 2),
        x = 100;
    this.panel.cfg.setProperty("y", y);
    this.panel.cfg.setProperty("x", x);
	this.show()
}

windowFrame.prototype.show = function()
{
    this.panel.show();
}
