$(document).ready(
	function()
	{
		if (typeof(init_field) == 'string')
		{
			$('#' + init_field).focus();
		}

		//$('#flashMessage').fadeOut(2000);
		//$('#authMessage').fadeOut(2000);

		$('input:text').each(
			function(i, el)
			{
				el = $(el);
				if (el.attr('placeholder'))
				{
					el.placeholder();
				}
			}
		);

		$('form').submit(
			function()
			{
				if (this.target != '_blank')
				{
					$('input[type=submit]', this).attr('disabled', 'disabled');
					$('input[type=button]', this).attr('disabled', 'disabled');
				}
			}
		);
	}
);

function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber = true;
	var Char;

	for (var i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}

	return (IsNumber);
}

function popup(url, width, height)
{
	var name = 'drPopup';
	var feats = 'status=0,toolbar=0,location=0,menubar=0,resizable=1,scrollbars=1,';

	width = width || 820;
	height = height || 600;

	feats += 'width=' + width + ',height=' + height;

	var popup = window.open(url, name, feats);
	if (popup.focus) { popup.focus(); }
}

function widget(id, name, width, height, layout, custom)
{
	this.id = id;
	this.name = name;
	this.width = width;
	this.height = height;
	this.layout = layout;
	this.custom = custom;

	this.pid = 0;
	this.filter = '0';

	this.dumpHtml = function()
	{
		var html = '';

		html += '<pre>' + "\n";
		html += 'Name: ' + this.name + "\n";
		html += 'Size: ' + this.width + 'x' + this.height + "\n";
		html += 'Layout: ' + this.layout + "\n";
		html += '</pre>';

		return (html);
	};

	this.dump = function(div)
	{
		var html = '';

		html += '<pre>' + "\n";
		html += 'Name: ' + this.name + "\n";
		html += 'Size: ' + this.width + 'x' + this.height + "\n";
		html += 'Layout: ' + this.layout + "\n";
		html += '</pre>';

		$('#' + div).html(html).show();
	};

	this.dims = function()
	{
		return ('width="' + this.width + '" height="' + this.height + '"');
	};

	this.url = function()
	{
		return (
			'/widgets/preview/' + this.id + '?' +
				'w=' + this.id + '&' +
				'f=' + this.filter + '&' +
				'p=' + this.pid
		);
	};

	this.show = function(div)
	{
		var html = '';

		$('#' + div).css('padding', '5px');
		$('#' + div).css('background-color', '#ccc');

		html += '<center><iframe ' +
			this.dims() +
			' scrolling="no" frameborder="no" hspace="0" vspace="0" margin="0"' +
			' src="' + this.url() + '"'
			' style="background-color:#fff">';
		html += '</iframe></center>';

		$('#' + div).html(html).show();
	};
};

