function FormCheck()
{
	this.questions = new Hash();
	this.fields = new Hash();
};

FormCheck.prototype =
{
	cleanupQuestion : function( str )
	{
		str = str.clean();

		if( str.substring( str.length - 1 ) == ":" || str.substring( str.length - 1 ) == "." )
			str = str.substring( 0, str.length - 1 );

		return str;
	},

	parse : function( form, msg )
	{
		var hasAnyEmpty = false;
		var list = $(form).getElements('.required');

		for( var i = 0; i < list.length; i++ )
		{
			var empty = false;

			if( list[i].match('input') )
			{
				if( list[i].type == "checkbox" )
					empty = !list[i].checked;

				else if( list[i].type == "radio" )
					empty = !list[i].checked;

				else if( list[i].value == "" )
					empty = true;
			}
			else if( list[i].match('textarea') )
			{
				if( list[i].value == "" )
					empty = true;
			}

			if( empty )
			{
				if( (typeof document.documentMode != "undefined" && document.documentMode >= 8) || !Browser.Engine.trident)
				{
					var reset = function() { try { $(this).setStyle('outline', 0); } catch(er){} $(this).removeEvents(); };

					$(list[i]).set({
						'styles': { 'outline': '2px solid red' },
						'events':  { 'keypress': reset, 'change' : reset }
					});
				}
				else
				{
					var prevBorder = $(list[i]).getStyle('border');

					var reset = function() { try { $(this).setStyle('border', prevBorder); } catch(er){} $(this).removeEvents(); };

					$(list[i]).set({
						'styles': { 'border': '2px solid red' },
						'events':  { 'keypress': reset, 'change' : reset }
					});
				}

				if( !hasAnyEmpty )
				{
					var p = $(list[i]).getPosition();
					$(document.body).scrollTo(0, p.y - 50);
					list[i].focus();

					alert( msg );
				}

				hasAnyEmpty = true;
			}
		}

		return !hasAnyEmpty;
	},

	go : function( f, msg )
	{
		if( !this.parse(f, msg) )
			return false;

		return true;
	}
};

var formcheck = new FormCheck();
