jQuery(document).ready(function() {

	jQuery( ':input' ).each( function(i)
	{
		
		jQuery( this ).focus( function()
		{
			jQuery( this ).removeClass( 'error' );
			jQuery( this ).addClass( 'inputting' );
		});



		jQuery( this ).blur( function()
		{
			jQuery( this ).removeClass( 'inputting' );
			
			if( jQuery( this ).attr( 'required' ) )
			{
				checkText( jQuery( this ), jQuery( this ).attr( 'regMatch' ) );
			}
		});

		
	});


	jQuery( 'form' ).each( function ()
	{
		jQuery( this ).submit( function()
		{
			var bFormError = false;
			
			jQuery( '#' + jQuery( this ).attr( 'id' ) + ' :input' ).each( function(i)
			{
				jQuery( this ).blur();
				
				if( jQuery( this ).hasClass( 'error' ) )
				{
					bFormError = true;
				}
			});
			
			if( bFormError )
			{
				return false;
			}
			else
			{
				return true;
			}
		});
	});


});



function checkText( oInput, rExpressionMatch )
{
	iInputMinLength = 1;
	var rExpressionMatch = new RegExp( rExpressionMatch )
	rExpressionMatch = typeof( rExpressionMatch ) != 'undefined' ? rExpressionMatch : /.{0,}/;


	if( oInput.val().length < iInputMinLength )
	{
		oInput.addClass( 'error' );
	}
	else if( !rExpressionMatch.test( oInput.val() ) )
	{
		oInput.addClass( 'error' );
	}
	else
	{
		oInput.removeClass( 'error' );
	}
}
