
/**
 * PCSG Window Klasse (Popup Ersatz)
 * @author PCSG Henning
 */


if( typeof _ptools == 'undefined' ) {
	var _ptools = {};
};

_ptools._Windows = new Array();

/**
 * Window Construct
 * settings
 	name => Name
 	title => Titel in der Titelleiste
 	body => HTML
 	width => Integer
 	height => Integer
 */
_ptools.Window = function( settings )
{
	var t = this;
	
	if(settings)
	{
		t.settings = settings;
	} else
	{
		t.settings = {};
	};
	
	t.x;
	t.y;
	
	t.oDiv = null;
	t.oDivShadow = null;
	t.oDivTitle = null;
	t.oDivBody = null;
	t.oClose = null;
	t.oMoveable = null;
	t.oDivLoader = null;
	
	t.move = false;
	
	t.tempX;
	t.tempY;
	
	if(typeof t.settings.name == 'undefined') {
		t.settings.name = new Date().getMilliseconds();
	};
};

/**
 * Erstellt ein Window - Popup ähnlich
 */
_ptools.Window.prototype.create = function()
{
	var path = _ptools._System.getAttribute('path');
	var t = this;
	var settings = t.settings;
	var style;

	t.oDiv = document.createElement('div');
	t.oDivShadow = t.oDiv.cloneNode(true);
	t.oDivTitle = t.oDiv.cloneNode(true);
	t.oDivBodyTitle = t.oDiv.cloneNode(true);
	t.oDivBody = t.oDiv.cloneNode(true);
	
	var oDivShadow_rd = t.oDiv.cloneNode(true);
	var oDivShadow_lt = t.oDiv.cloneNode(true);
	var oDivShadow_bl = t.oDiv.cloneNode(true);
	var oDivShadow_rt = t.oDiv.cloneNode(true);

	t.oDivLoader = t.oDiv.cloneNode(true);
	t.oDivLoader.className = 'sWindowLoader';	
	
	t.oClose = document.createElement('img');
	
	t.oDiv.className = 'sWindow';
	style = t.oDiv.style;
	style.position = 'fixed';
	style.visibility = 'hidden';
	
	if(_ptools.zIndex)
	{
		_ptools.zIndex++;
	} else
	{
		_ptools.zIndex = 10000;
	};
	
	style.zIndex = _ptools.zIndex;
	
	if(settings.height)
	{
		style.height = settings.height +'px';
		t.oDivBody.style.height = settings.height-18 +'px';
	};
	
	if(settings.width)
	{
		style.width = (settings.width-2) + 'px';
		t.oDivBody.style.width = (settings.width-2) + 'px';
	};
	
	if(window.innerHeight)
	{
		var maxHeight = window.innerHeight;
		var maxWidth = window.innerWidth;
	} else 	
	{
		var maxHeight = document.body.clientHeight;
		var maxWidth = document.body.clientWidth;
	};
	
	t.oDivTitle.className = 'sWindowTitle';
	
	if(t.settings.image)
	{
		var tImg = '<img src="'+ settings.image +'" style="padding-right: 5px; top: 3px; position: relative;" />';
	} else
	{
		var tImg = '<img src="'+ path + 'window/images/title_placebo.png" />';
	};
	
	t.oDivTitle.innerHTML = '<span style="padding-top: 2px">'+ tImg + settings.title +'</span>';
	style = t.oDivTitle.style;
	style.cursor = 'move';
	style.height = '23px';
	style.width = t.oDiv.style.width;
	
	t.oDivBody.className = 'sWindowBody';
	
	if(settings.body) {
		t.setBody(settings.body);
	};
	
	t.oClose.src = path + 'window/images/close.png';
	style = t.oClose.style;
	style.position = 'absolute';
	style.right = '5px';
	style.top = '1px';
	style.cursor = 'pointer';
	style.zIndex = 1000;
	
	t.oClose.onmouseover = function()
	{
		this.src = path + 'window/images/close_hover.png';
	};
	
	t.oClose.onmouseout = function()
	{
		this.src = path + 'window/images/close.png';
	};
	
	t.oClose.onclick = function()
	{
		t.close();
	};
	
	t.oDiv.appendChild(t.oClose);
	t.oDiv.appendChild(t.oDivTitle);
	t.oDiv.appendChild(t.oDivBodyTitle);
	t.oDiv.appendChild(t.oDivBody);
	
	
	// ins body einbinden
	document.body.appendChild(t.oDiv);
	document.body.appendChild(t.oDivLoader);
	//t.oDiv.focus();
	
	t.oDivTitle.onmousedown = function(event)
	{
		t.onmousedown(event);
	};
	
	t.oDivTitle.onmouseup = function(event)
	{
		t.onmouseup(event);
	};
	
	
	// POS
	if(!t.settings.top)
	{
		t.y = _ptools._System.getScrollXY()[1]+100;
	} else
	{
		t.y = t.settings.top;
	};
	
	if(!t.settings.left)
	{
		t.x = ((maxWidth-t.oDiv.offsetWidth) / 2);
	} else
	{
		t.x = t.settings.left;
	};
	
	t.oDiv.style.top = t.y + 'px';
	t.oDiv.style.left = t.x + 'px';
	
	// Schatten
	var oDiv_offsetWidth = t.oDiv.offsetWidth;
	var oDiv_offsetHeight = t.oDiv.offsetHeight;
	
	style = t.oDivShadow.style;
	style.position = 'absolute';
	style.visibility = 'hidden';
	style.zIndex = _ptools.zIndex-1;
	style.width = oDiv_offsetWidth + 14 + "px";
	style.height = oDiv_offsetHeight + 18 + "px";
	style.top = t.y-7 + 'px';
	style.left = t.x-7 + 'px';
	
	style = oDivShadow_rd.style;
	style.backgroundImage = "url('" + path + "window/images/shadow.png')";
	style.backgroundRepeat = "no-repeat";
	style.backgroundPosition = "bottom right";
	style.position = "absolute";
	style.right = "0px";
	style.bottom = "0px";
	style.width = oDiv_offsetWidth+7 +"px";
	style.height = oDiv_offsetHeight+11 +"px";
	oDivShadow_rd.innerHTML = "&nbsp;";
	
	style = oDivShadow_lt.style;
	style.backgroundImage = "url('" + path + "window/images/shadow_l.png')";
	style.backgroundRepeat = "no-repeat";
	style.backgroundPosition = "top left";
	style.position = "absolute";
	style.left = "0px";
	style.top = "0px";
	style.width = oDiv_offsetWidth+7 +"px";
	style.height = oDiv_offsetHeight+11 +"px";
	oDivShadow_lt.innerHTML = "&nbsp;";
	
	style = oDivShadow_bl.style;
	style.backgroundImage = "url('" + path + "window/images/shadow_bl.png')";
	style.backgroundRepeat = "no-repeat";
	style.backgroundPosition = "bottom left";
	style.position = "absolute";
	style.left = "0px";
	style.bottom = "0px";
	style.width = "8px";
	style.height = "8px";
	oDivShadow_bl.innerHTML = "&nbsp;";
	
	style = oDivShadow_rt.style;
	style.backgroundImage = "url('" + path + "window/images/shadow_rt.png')";
	style.backgroundRepeat = "no-repeat";
	style.backgroundPosition = "top right";
	style.position = "absolute";
	style.right = "0px";
	style.top = "0px";
	style.width = "8px";
	style.height = "8px";
	oDivShadow_rt.innerHTML = "&nbsp;";
	
	t.oDivShadow.appendChild(oDivShadow_lt);
	t.oDivShadow.appendChild(oDivShadow_bl);
	t.oDivShadow.appendChild(oDivShadow_rd);
	t.oDivShadow.appendChild(oDivShadow_rt);
	
	document.body.appendChild(t.oDivShadow);
	
	// Zusatzbody
	if(typeof t.createBody == 'function') {
		t.createBody();
	};
	
	t.oDiv.style.visibility = 'visible';
	t.oDiv.focus();
	
	t.oDivShadow.style.visibility = 'visible';
	t.onopen();
	
	_ptools._Windows[ settings.name ] = t;
};

_ptools.Window.prototype.setAttribute = function( key, value )
{
	switch( key )
	{
		case "onclose":
			this.settings.onclose = value;
		break;
		
		case "onopen":
			this.settings.onopen = value;
		break;
		
		default:
			this.settings[key] = value;
	};
};

_ptools.Window.prototype.getAttribute = function( name )
{
	if(this.settings[ name ]) {
		return this.settings[ name ];
	};

	return false;
};

_ptools.Window.prototype.onopen = function()
{
	if(this.settings.onopen) {
		eval(this.settings.onopen);
	};
};

/**
 * Setzt den Window Body
 */
_ptools.Window.prototype.setBody = function(html)
{
	this.oDivBody.innerHTML = html;
};

/**
 * Setzt den Window Body
 */
_ptools.Window.prototype.loaderStart = function()
{
	var t = this;
	
	if( t._loader )
	{
		t._loader.style.display = '';
		t.__oImg.style.display = '';
		
		return;
	};
	
	var body = t.oDiv;
	var obj  = document.createElement('div');
	t.__oImg = document.createElement('img');
	
	var style    = obj.style;
	style.width  = body.offsetWidth +'px';
	style.height = body.offsetHeight-t.oDivTitle.offsetHeight +'px';
	style.top    = t.oDivTitle.offsetHeight +'px';
	
	obj.className = '_pWindowLoader';
	
	t.__oImg.src        = URL_BIN_DIR +'js/ptools/window/images/loader_big.gif';
	t.__oImg.className  = '_pWindowLoaderImg'; 
	t.__oImg.style.left = ((body.offsetWidth/2)-110) +'px' ;
	t.__oImg.style.top  = ((body.offsetHeight/2)-10) +'px' ;
	
	t._loader = obj;
	
	t.oDiv.appendChild( t.__oImg );
	t.oDiv.appendChild( t._loader );
};

_ptools.Window.prototype.loaderStop = function()
{
	var t = this;
	
	if(t._loader)
	{
		var body = t.oDivBody;
		
		t._loader.style.display = 'none';
		t.__oImg.style.display  = 'none';
	};
};

/**
 * Schliesst das Fenster
 */
_ptools.Window.prototype.close = function()
{
	var t = this;
	t.oDiv.parentNode.removeChild(t.oDiv);
	t.oDivShadow.parentNode.removeChild(t.oDivShadow);
	t.oDivLoader.parentNode.removeChild(t.oDivLoader);
	
	if(t.settings.onclose) {
		eval(t.settings.onclose);
	};
	
	//all_sos_windows[this.settings.name] = null;
};

/**
 * Verschiebt das Fenster
 */
_ptools.Window.prototype.onmousemove = function(event)
{
	var t = this;
	if(t.move == true)
	{
		t.mousePos(event);
		
		t.oMoveable.style.top = t.y - t.tempY + "px"; 
		t.oMoveable.style.left = t.x - t.tempX + "px";
	};
};

/**
 * OnMouseDown Event
 */
_ptools.Window.prototype.onmousedown = function(event)
{
	var t = this;
	if(t.move == false)
	{
		t.oMoveable = document.createElement('div');
		var oMoveableStyle = t.oMoveable.style;
		oMoveableStyle.width = t.oDiv.offsetWidth + "px";
		oMoveableStyle.height = t.oDiv.offsetHeight + "px";
		oMoveableStyle.position = "absolute";
		oMoveableStyle.top = t.oDiv.style.top;
		oMoveableStyle.left = t.oDiv.style.left;
		oMoveableStyle.zIndex = 10002;
		oMoveableStyle.border = "3px solid #CFD4E6";
		oMoveableStyle.backgroundColor = "transparent";
		oMoveableStyle.cursor = "pointer";
		
		document.body.appendChild(t.oMoveable);
		
		var self = t;
		document.onmousemove = function(event)
		{
			self.onmousemove(event);
		};
		
		document.onmouseup = function(event)
		{
			self.onmouseup(event);
		};
		
		if (_ptools._Browser.isMSIE) 
		{
			t.tempX = window.event.clientX + document.body.scrollLeft - t.x;
			t.tempY = window.event.clientY + document.body.scrollTop - t.y;
	  	} else 
	  	{
	  		t.tempX = event.pageX - t.x;
			t.tempY = event.pageY - t.y;
	 	};
		t.mousePos(event);
	};
	
	t.move = true;
};

/**
 * OnMouseDown Event
 */
_ptools.Window.prototype.onmouseup = function(event)
{
	var t = this;
	t.move = false;
	
	t.oDiv.style.top = t.oMoveable.style.top;
	t.oDiv.style.left = t.oMoveable.style.left;
	
	t.oDivShadow.style.top = parseInt(t.oMoveable.style.top) - 7 + "px";
	t.oDivShadow.style.left = parseInt(t.oMoveable.style.left) - 7 + "px";
	
	t.oMoveable.parentNode.removeChild(t.oMoveable);
	t.oMoveable = null;
	
	t.x = t.x - t.tempX;
	t.y = t.y - t.tempY;
	
	document.onmousemove = null;
	document.onmouseup = null;
	
	t.oDiv.focus();
};

/**
 * Setzt die Mausposition
 */
_ptools.Window.prototype.mousePos = function(event)
{
	this.x = document.all ? window.event.clientX : event.pageX;
	this.y = document.all ? window.event.clientY : event.pageY;
};


/**
 * Submit Window
 */
_ptools.SubmitWindow = function( settings ) 
{
	var t = this;
	t.type     = 'pToolObject::SubmitWindow';
	t.settings = settings;
	
	if (!t.settings.height) {
		t.settings.height = 300;
	};
	
	if (!t.settings.width) {
		t.settings.width = 200;
	};
	
	t.x;
	t.y;
	
	t.oDiv       = null;
	t.oDivShadow = null;
	t.oDivTitle  = null;
	t.oDivBody 	 = null;
	t.oClose 	 = null;
	t.oMoveable  = null;
	t.oDivLoader = null;
	
	t.move = false;
	
	t.tempX;
	t.tempY;
};

_ptools.SubmitWindow.prototype = new _ptools.Window();

_ptools.SubmitWindow.prototype.createBody = function()
{
	var t = this;
	var settings = t.settings;
	 
	if(settings.height)
	{
		t.oDivBody.style.height = (settings.height-50) +'px';
	} else
	{
		t.oDivBody.style.height = (t.oDiv.offsetHeight-50)+'px';
	};
	
	// [begin] Buttons
	var oButtons = document.createElement('div');
		oButtons.align = 'center';
	var oButtonsSub = oButtons.cloneNode( true );
	var style = oButtons.style;
	
	style.clear       = 'both';
	style.height      = '30px';
	style.textAlign   = 'center';
	style.marginLeft  = 'auto';
	style.marginRight = 'auto';
	style.width       = '95%';
	align             = 'center';
	style.borderTop   = '1px solid #7c7c7c';
	
	style = oButtonsSub.style;
	style.width       = '130px';
	style.marginLeft  = 'auto';
	style.marginRight = 'auto';
	style.marginTop   = '3px';
	
	t._ok = new _ptools.Button({
		name    : '_ok',
		text    : 'OK',
		onclick : function(_me) 
		{
			var r   = false;
			var fun = _me.getAttribute('onsubmit');
			var Win = _me.getAttribute('Win');
			
			if (typeof fun == 'function')
			{
				var r = fun(Win);
				
			} else if (fun)
			{
				eval('var r = '+ fun +'(Win)');
			};
			
			if(r || typeof r == 'undefined') {
				Win.close(); 
			};
		},
		onsubmit : settings.onsubmit,
		Win      : t
	});
	
	t._cancel = new _ptools.Button({
		name: '_cancel',
		text: 'Abbrechen',
		onclick : function(_me) {
			_me.getAttribute('Win').close(); 
		},
		Win : t
	});
	
	oButtonsSub.appendChild( t._ok.create() );
	oButtonsSub.appendChild( t._cancel.create() );
	oButtons.appendChild(oButtonsSub);
	// [end] Buttons
	
	if(settings.msg)
	{
		var oDivMsg = document.createElement('div');
		var oSpan = document.createElement('span');
		var oBody = t.oDivBody;
		
		oSpan.innerHTML = settings.msg;
		
		oDivMsg.appendChild( oSpan );
		oDivMsg.className = 'infoBox';
		
		oDivMsg.style.width = oBody.style.width;
		 
		//t.oDivBody.style.border = '1px solid red';
		//t.oDiv.style.border = '1px solid red';
		
		t.oDiv.appendChild( oDivMsg );
		
		oBody.style.height = (oBody.offsetHeight-oDivMsg.offsetHeight)+ 'px';
	};
	
	t.oDiv.appendChild( oButtons );
	t.oDiv.style.height = t.oDiv.offsetHeight+3 +'px';
};


/**
 * Confirm Window
 */
_ptools.Confirm = function( settings ) 
{
	var t = this;
	t.type = 'pToolObject::Confirm';
	t.settings = settings;
	
	if(!t.settings.height) {
		t.settings.height = 300;
	};
	
	if(!t.settings.width) {
		t.settings.width = 200;
	};
	
	t.x;
	t.y;
	
	t.oDiv = null;
	t.oDivShadow = null;
	t.oDivTitle 	= null;
	t.oDivBody 	= null;
	t.oClose 	= null;
	t.oMoveable 	= null;
	t.oDivLoader = null;
	
	t.move = false;
	
	t.tempX;
	t.tempY;
};

_ptools.Confirm.prototype = new _ptools.Window();

_ptools.Confirm.prototype.setBody = function(html)
{
	//this.oDivBody.innerHTML = html;
};

_ptools.Confirm.prototype.createBody = function()
{
	var t = this;
	var settings = t.settings;
	
	if(settings.height)
	{
		t.oDivBody.style.height = (settings.height-50) +'px';
	} else
	{
		t.oDivBody.style.height = (t.oDiv.offsetHeight-50)+'px';
	};
	
	// [begin] Buttons
	var oButtons = document.createElement('div');
	var oButtonsSub = oButtons.cloneNode( true );
	var style = oButtons.style;
	
	style.clear = 'both';
	style.height = '30px';
	style.textAlign = 'center';
	style.marginLeft = 'auto';
	style.marginRight = 'auto';
	style.width = '95%';
	style.borderTop = '1px solid #7c7c7c';
	oButtons.align = 'center';
	
	style = oButtonsSub.style;
	style.width = '130px';
	style.marginLeft = 'auto';
	style.marginRight = 'auto';
	style.marginTop = '3px';
	
	var _ok = new _ptools.Button({
		name: '_ok',
		text: 'OK'
	});
		
	_ok.onclick = function() {
	
		var r = false;
		 
		if(typeof settings.onsubmit == 'function')
		{
			var r = settings.onsubmit(t);
			
		} else if(settings.onsubmit)
		{
			eval('var r = '+ settings.onsubmit +'(t)');
		};
		
		if(r || typeof r == 'undefined')
			t.close(); 
	};
	
	var _cancel = new _ptools.Button({
		name: '_ok',
		text: 'Abbrechen'
	});
		
	_cancel.onclick = function() 
	{ 
		if(typeof settings.oncancel == 'function') 
		{
			settings.oncancel(t);
		} else if(settings.oncancel)
		{
			eval(t.settings.oncancel+'(t)');
		};
		
		t.close(); 
	};
	
	oButtonsSub.appendChild( _ok.create() );
	oButtonsSub.appendChild( _cancel.create() );
	oButtons.appendChild(oButtonsSub);
	// [end] Buttons
	
	if(settings.msg)
	{
		var oDivMsg = document.createElement('div');
		oDivMsg.innerHTML = settings.msg;
		
		style = oDivMsg.style; 
		style.width = t.oDivBody.style.width;
		style.backgroundColor = '#F0E7C0';
		style.borderTop = '1px solid #A29561';
		style.borderBottom = '1px solid #A29561';
		style.textAlign = 'center';
		style.fontSize = '10px';
		style.fontWeight = 'bold';
		style.position = 'absolute';
		style.bottom = '35px';
		style.padding = '4px 0';
		
		t.oDiv.appendChild( oDivMsg );
	};
	
	t.oDiv.appendChild( oButtons );
	
	// Body
	var body = t.oDivBody;
	body.innerHTML = '';
	
	var html = '<table class="ConfirmTable" cellpadding="0" cellspacing="0"><tbody><tr>';
	
	if(settings.textIcon) {
		html = html+'<td rowspan="2" class="ConfirmTextIcon"><img src="'+ settings.textIcon +'" /></td>';
	};
	
	if(settings.text)
	{
		html = html +'<td class="ConfirmText">'+ settings.text +'</td></tr>';
	} else
	{
		html = html +'</tr>';
	};
	
	if(settings.information) {
		html = html +'<tr><td class="ConfirmInformation">'+ settings.information +'<td></tr>';
	};
	
	html = html+'</tbody></table>';
	body.innerHTML = html;
	
	t.oDiv.style.height = t.oDiv.offsetHeight+3 +'px';
};


/**
 * Confirm Window
 */
_ptools.Prompt = function( settings ) 
{
	var t = this;
	t.type = '_ptools::Window::Prompt';
	t.settings = settings;
	
	if(!t.settings.height) {
		t.settings.height = 300;
	};
	
	if(!t.settings.width) {
		t.settings.width = 200;
	};
	
	t.x;
	t.y;
	
	t.oDiv = null;
	t.oDivShadow = null;
	t.oDivTitle 	= null;
	t.oDivBody 	= null;
	t.oClose 	= null;
	t.oMoveable 	= null;
	t.oDivLoader = null;
	
	t.move = false;
	
	t.tempX;
	t.tempY;
	
	if(typeof t.settings.name == 'undefined') {
		t.settings.name = new Date().getMilliseconds();
	};
};

_ptools.Prompt.prototype = new _ptools.Window();

_ptools.Prompt.prototype.setBody = function(html)
{
	//this.oDivBody.innerHTML = html;
};

_ptools.Prompt.prototype.createBody = function()
{
	var t = this;
	var settings = t.settings;
	
	if(settings.height)
	{
		t.oDivBody.style.height = (settings.height-50) +'px';
	} else
	{
		t.oDivBody.style.height = (t.oDiv.offsetHeight-50)+'px';
	};
	// [begin] Buttons
	var oButtons = document.createElement('div');
	var oButtonsSub = oButtons.cloneNode( true );
	var style = oButtons.style;
	
	style.clear = 'both';
	style.height = '30px';
	style.textAlign = 'center';
	style.marginLeft = 'auto';
	style.marginRight = 'auto';
	style.width = '95%';
	style.borderTop = '1px solid #7c7c7c';
	oButtons.align = 'center';
	
	style = oButtonsSub.style;
	style.width = '130px';
	style.marginLeft = 'auto';
	style.marginRight = 'auto';
	style.marginTop = '3px';
	
	t._ok = new _ptools.Button({
		name: '_ok',text: 'OK'
	});
	t._ok.onclick = function() {
		
		var r = false;
		 
		if(typeof settings.onsubmit == 'function')
		{
			var r = settings.onsubmit(t, document.getElementById("prompt_field").value);
		} else if(settings.onsubmit)
		{
			eval('var r = '+ settings.onsubmit +'(t, document.getElementById("prompt_field").value)');
		};
		
		if(r || typeof r == 'undefined')
		{
			t.close();
		};
			
		return false;
	};
	
	t._cancel = new _ptools.Button({
		name: '_ok',
		text: 'Abbrechen'
	});
	
	t._cancel.onclick = function() { 
		t.close(); 
	};
	
	oButtonsSub.appendChild( t._ok.create() );
	oButtonsSub.appendChild( t._cancel.create() );
	oButtons.appendChild( oButtonsSub );
	// [end] Buttons
	
	if( settings.msg )
	{
		var oDivMsg = document.createElement('div');
		oDivMsg.innerHTML = settings.msg;
		
		style = oDivMsg.style; 
		style.width = t.oDivBody.style.width;
		style.backgroundColor = '#F0E7C0';
		style.borderTop = '1px solid #A29561';
		style.borderBottom = '1px solid #A29561';
		style.textAlign = 'center';
		style.fontSize = '10px';
		style.fontWeight = 'bold';
		style.position = 'absolute';
		style.bottom = '35px';
		style.padding = '4px 0';
		
		t.oDiv.appendChild( oDivMsg );
	};
	
	t.oDiv.appendChild( oButtons );
	
	// Body
	var body = t.oDivBody;
	body.innerHTML = '';
	
	var html = '<form onsubmit="_ptools._Windows[\''+ settings.name +'\']._ok.onclick(); return false;"><table class="ConfirmTable" cellpadding="0" cellspacing="0"><tbody><tr>';
	
	if( settings.textIcon )
	{
		html = html +'<td rowspan="3" class="ConfirmTextIcon"><img src="'+ settings.textIcon +'" /></td>';
	};
	
	if( settings.text )
	{
		html = html +'<td class="ConfirmText">'+ settings.text +'</td></tr>';
	} else
	{
		html = html +'</tr>';
	};
	
	var v = '';
	if(t.settings.value)
	{
		v = t.settings.value;
	};
	
	html = html+'<tr><td class="ConfirmInformation"><input type="text" name="prompt_field" id="prompt_field" style="width: 90%" value="'+ v +'" /><td></tr>';
	
	if(t.settings.information)
	{
		html = html+'<tr><td class="ConfirmInformation">'+ t.settings.information +'<td></tr>';
	} else
	{
		html = html+'<tr><td class="ConfirmInformation"><td></tr>';
	};
	
	html = html+'</tbody></table></form>';
	body.innerHTML = html;
};

_ptools.Prompt.prototype.onopen = function()
{
	if(this.settings.onopen)
	{
		eval(this.settings.onopen);
	};
	
	document.getElementById('prompt_field').focus();
};

/**
 * Confirm Window
 */
_ptools.Alert = function( settings ) 
{
	var t = this;
	t.type = '_ptool::Alert';
	t.settings = settings;
	t.settings.title = 'Alert';
	t.settings.image =  _ptools._System.getAttribute('path') +'window/images/messagebox_warning.png';
	
	if(!t.settings.height)
	{
		t.settings.height = 200;
	};
	
	if(!t.settings.width)
	{
		t.settings.width = 450;
	};
	
	t.x;
	t.y;
	
	t.oDiv = null;
	t.oDivShadow = null;
	t.oDivTitle 	= null;
	t.oDivBody 	= null;
	t.oClose 	= null;
	t.oMoveable 	= null;
	t.oDivLoader = null;
	
	t.move = false;
	
	t.tempX;
	t.tempY;
};

_ptools.Alert.prototype = new _ptools.Window();

_ptools.Alert.prototype.setBody = function(html)
{
	//this.oDivBody.innerHTML = html;
};

_ptools.Alert.prototype.createBody = function()
{
	var t = this;
	var path = _ptools._System.getAttribute('path');
	
	if(t.settings.height)
	{
		t.oDivBody.style.height = (t.settings.height-50) +'px';
	} else
	{
		t.oDivBody.style.height = (t.oDiv.offsetHeight-50)+'px';
	};
	// [begin] Buttons
	var oButtons = document.createElement('div');
	var oButtonsSub = oButtons.cloneNode( true );
	
	var style = oButtons.style;
	style.clear = 'both';
	style.height = '30px';
	style.textAlign = 'center';
	style.marginLeft = 'auto';
	style.marginRight = 'auto';
	style.width = '95%';
	style.borderTop = '1px solid #7c7c7c';
	oButtons.align = 'center';
	
	style = oButtonsSub.style; 
	style.width = '100px';
	style.marginLeft = 'auto';
	style.marginRight = 'auto';
	style.marginTop = '3px';
	
	var _ok = new _ptools.Button({
		name: '_ok',
		text: 'OK',
		width: 100
	});
		
	_ok.onclick = function() {
		t.close(); 
	};
	
	oButtonsSub.appendChild( _ok.create() );
	oButtons.appendChild(oButtonsSub);
	// [end] Buttons
	
	t.oDiv.appendChild( oButtons );
	
	// Body
	var body = t.oDivBody;
	body.innerHTML = '';
	
	var html = '<table class="AlertTable" cellpadding="0" cellspacing="0"><tbody><tr>';
	html = html+'<td rowspan="2" class="AlertTextIcon"><img src="'+ path +'window/images/48x48/messagebox_warning.png" /></td>';
	
	if(t.settings.text)
	{
		html = html+'<td class="AlertText">'+ t.settings.text +'</td></tr>';
	} else
	{
		html = html+'</tr>';
	};
	
	if(t.settings.information)
	{
		html = html+'<tr><td class="AlertInformation">'+ t.settings.information +'<td></tr>';
	};
	
	html = html+'</tbody></table>';
	body.innerHTML = html;
};

/**
 * Einstellungspopup
 */
_ptools.Setting = function( settings ) 
{
	var t = this;
	t.type = 'sToolObject::Settings';
	t.settings = settings;
	
	t.settings.height = 450;
	t.settings.width = 650;
	
	t.x;
	t.y;
	
	t.oDiv = null;
	t.oDivShadow = null;
	t.oDivTitle 	= null;
	t.oDivBody 	= null;
	t.oClose 	= null;
	t.oMoveable 	= null;
	t.oDivLoader = null;
	
	t.Tools = null;
	t.Content = null;
	t.Buttons = null;
	t.Title = null;
	t.Settings = null;
	
	t.move = false;
	
	t.tempX;
	t.tempY;
	
	t.items = [];
};

_ptools.Setting.prototype = new _ptools.Window();

_ptools.Setting.prototype.setBody = function(html)
{
	this.Settings.innerHTML = html;
};

_ptools.Setting.prototype.createBody = function()
{
	var t = this;
	var path = _ptools._System.getAttribute('path');
	var body = t.oDivBody;
	
	t.Tools = document.createElement('div');
	t.Content = t.Tools.cloneNode(true);
	t.Buttons = t.Tools.cloneNode(true);
	t.Buttons.appendChild( t._createButton() );
	
	t.Title = t.Tools.cloneNode(true);
	t.Settings = t.Tools.cloneNode(true);
	
	t.Tools.className = '_pSettingTools';
	t.Content.className = '_pSettingContent';
	t.Buttons.className = '_pSettingButtons';
	
	t.Title.className = '_pSettingTitle';
	t.Settings.className = '_pSettingSettings';
	
	t.Content.appendChild(t.Title);
	t.Content.appendChild(t.Settings);
	
	for(var i = 0, len = t.items.length; i < len; i++)
	{
		t.items[i].setAttribute('width', 150);
		t.items[i].setAttribute('onclick', function( _me ) { 
			t._showSetting( _me );
		});
		
		t.Tools.appendChild( t.items[i].create() );
	};
	
	body.appendChild( t.Tools );
	body.appendChild( t.Content );
	body.appendChild( t.Buttons );
	
	t._showSetting(t.items[0]);
};

_ptools.Setting.prototype.appendChild = function( _btn )
{
	var t = this;
	
	t.items.push( _btn );
	
	if(t.Tools != null)
	{
		t.Tools.appendChild( _btn );
	};
};

_ptools.Setting.prototype._showSetting = function( _btn )
{
	var t = this;
	
	if(t._active != null)
	{
		if(typeof t._active.getAttribute('onunload') == 'function')
		{
			t._active.getAttribute('onunload')(t._active, t);
		};
		
		t._active.setNormal();
	};
	
	t.Title.innerHTML = _btn.getAttribute('title');
	t.Settings.innerHTML = _btn.getAttribute('body');
	
	if(typeof _btn.getAttribute('onload') == 'function')
	{
		_btn.getAttribute('onload')(_btn, t);
	};
	
	_btn.setActive();
	t._active = _btn;
};

_ptools.Setting.prototype._createButton = function( _btn )
{
	var t = this;
	// [begin] Buttons
	var oButtons = document.createElement('div');
	var oButtonsSub = oButtons.cloneNode( true );
	var style = oButtons.style;
	
	style.clear = 'both';
	style.height = '30px';
	style.textAlign = 'center';
	style.marginLeft = 'auto';
	style.marginRight = 'auto';
	style.width = '95%';
	style.borderTop = '1px solid #7c7c7c';
	oButtons.align = 'center';
	
	style = oButtonsSub.style;
	style.width = '200px';
	style.marginLeft = 'auto';
	style.marginRight = 'auto';
	style.marginTop = '3px';
	
	t._ok = new _ptools.Button({
		name: '_ok',
		text: '<img src="'+  URL_BIN_DIR +'16x16/save.png" style="float: left; margin: 0 5px 0 0; padding: 0" /> <span>Speichern</span>',
		onclick : function( _btn ) {
			var r = false;
			var onsubmit = _btn.getAttribute('onsubmit');
			
			if(typeof onsubmit == 'function') {
				var r = onsubmit(t);
			} else if(onsubmit) {
				eval('var r = '+ onsubmit +'(t)');
			};
			
			if(r || typeof r == 'undefined') {
				t.close();
			};
			
			return false;
		},
		onsubmit : t.getAttribute('onsubmit')
	});
	
	t._cancel = new _ptools.Button({
		name: '_ok',
		text: 'Abbrechen',
		onclick : function() { t.close();  } 
	});
	
	oButtonsSub.appendChild( t._ok.create() );
	oButtonsSub.appendChild( t._cancel.create() );
	oButtons.appendChild( oButtonsSub );
	// [end] Buttons
	
	return oButtons;
};