function Dialog(width, height, title)
{
	this.init(width, height, title)
}

Dialog.dialogs = new Array();

Dialog.prototype.init = function(width, height, title)
{
	this.title = (title == null) ? '' : title;

	this.id = Utility.createDivId('Dialog');

	Dialog.dialogs.push(this);

	this.width = width;
	this.height = height;

	this.contentId = Utility.createDivId('DialogContent');
	this.active = false;

	var div = document.createElement('div');
    div.className = 'dialog';
    div.style.visibility = 'hidden';
    div.id = this.id;
    div.style.width = width;
    div.style.height = height;
	document.getElementById('anchor').appendChild(div);

	this.redx = '<a href="javascript:Dialog.close(\'' + this.id + '\');"><img src="/ingenious/images/redx.gif" width="14" height="13" alt="Close" border="0"/></a>';

    ADD_DHTML(this.id);
}

Dialog.prototype.getId = function()
{
	return this.id;
}

Dialog.prototype.getResponse = function()
{
	return this.response;
}

Dialog.prototype.isActive = function()
{
	return this.active;
}

Dialog.prototype.activate = function(content, callback, center)
{
	this.callback = callback;
	this.active = true;

	if ((center != null) && (center == true))
	{
		var div = document.getElementById(this.id);
		var anchor = document.getElementById('anchor');
		dd.elements[this.id].moveTo
		(
			Math.round((parseInt(anchor.width)/2)-(parseInt(div.style.width)/2)),
			Math.round((parseInt(anchor.height)/2)-(parseInt(div.style.height)/2))
		);
	}

	var html = '' +
		'<table width="100%" height="100%" cellspacing="0">' +
			'<tr class="dialog-header" align="left" valign="center">' +
				'<td width="100%" height="20" valign="center">&nbsp;' +
					this.title +
				'</td>' +
				'<td align="right">' +
					this.redx + '&nbsp;' +
				'</td>' +
			'</tr>' +
			'<tr >' +
				'<td colspan="2" style="background-color: #FCB214;">' +
					'<table width="100%" height="100%" cellspacing="1"><tr><td class="dialog-content">' +
						content +
					'</td></tr></table>' +
				'</td>' +
			'</tr>' +
		'</table>';

	var div = document.getElementById(this.id);
	div.innerHTML = html;

	dd.elements[this.id].maximizeZ();
	dd.elements[this.id].show();
}

Dialog.prototype.deactivate = function()
{
	dd.elements[this.id].hide();
	this.active = false;

	if (this.callback != null)
	{
		var id = this.id;
		var callback = function()
		{
			setTimeout('Dialog.getDialog("' + id + '").callback();', 1);
		};
		callback();
	}
}

Dialog.prototype.onKeyPress = function(key)
{
	this.key = key;
	if (KeyboardConstants.isKeyStroke(key, 'Xx') ||
		(KeyboardConstants.ESCAPE_KEY == key))
	{
		this.deactivate();
	}
}


Dialog.close = function(id)
{
	var dialog = null;
	for (var i=0;i<Dialog.dialogs.length; i++)
	{
		if ((Dialog.dialogs[i] != null) &&
		    (Dialog.dialogs[i].getId() == id))
		{
			Dialog.dialogs[i].deactivate();
		}
	}
}

Dialog.getActiveDialog = function()
{
	for (var i=0; i<Dialog.dialogs.length; i++)
	{
		var d = Dialog.dialogs[i];
		if ((d != null) && d.isActive())
		{
			return d;
		}
	}
	return null;
}

Dialog.getDialog = function(id)
{
	for (var i=0; i<Dialog.dialogs.length; i++)
	{
		var d = Dialog.dialogs[i];
		if ((d != null) && (d.getId() == id))
		{
			return d;
		}
	}
	return null;
}

Dialog.prototype.getCloseButtonHtml = function()
{
    var html = '<center><a href="javascript:Dialog.close(\'' + this.id + '\');">';
    html += '<img src="/ingenious/images/' + Language.getLanguage() + '/close.gif" width="120" height="20" border="0"/></a></center>';
    return html;
}

Dialog.prototype.getNewGameButtonHtml = function()
{
    var html = '<center><a href="javascript:Dialog.close(\'' + this.id + '\');">';
    html += '<img src="/ingenious/images/' + Language.getLanguage() + '/newGame.gif" width="120" height="20" border="0"/></a></center>';
    return html;
}


Dialog.prototype.getStartButtonHtml = function()
{
    var html = '<center><a href="javascript:Dialog.close(\'' + this.id + '\');">';
    html += '<img src="/ingenious/images/' + Language.getLanguage() + '/start.gif" width="120" height="20" border="0"/></a></center>';
    return html;
}