var regEmail = /^[\.\-_A-Za-z0-9]+?@[\.\-A-Za-z0-9]+?\.[A-Za-z0-9]{2,6}$/;
var regInt = /^\d+$/;

function checkInputs( oForm, oInput )
{	oForm.find('input[@type = "submit"]').attr('disabled', 'disabled').css('cursor', 'default');
	//oForm.find('.error').removeClass('error');
	var val = oInput.val();
	if ( val.length == 0)
	{	oInput.removeClass('checked').removeClass('error');
		return;
	}
	oInput.removeClass('error');

	if ( oInput.hasClass('notEmpty') )
	{	if ( val.length < 1 ) 			{	oInput.removeClass('checked').addClass('error');	}
		else 									{	oInput.addClass('checked').removeClass('error');	}
	}
	if ( oInput.hasClass('int') )
	{	if ( !regInt.test( val ) )		{	oInput.removeClass('checked').addClass('error');	}
		else
		{	if ( oInput.hasClass('phoneCode') )
			{	if ( val.length < 3 || val.length > 5 )	{	oInput.removeClass('checked').addClass('error');	}
				else													{	oInput.addClass('checked').removeClass('error');	}
			}
			else if ( oInput.hasClass('phoneNumber') )
			{	if ( val.length < 5 || val.length > 7 )	{	oInput.removeClass('checked').addClass('error');	}
				else													{	oInput.addClass('checked').removeClass('error');	}
			}
			else
			{	var maxLen = oInput.attr('minlength');
				if ( val.length < maxLen )	{	oInput.removeClass('checked').addClass('error');	}
				else									{	oInput.addClass('checked').removeClass('error');	}
			}
		}
	}
	if ( oInput.hasClass('mail') )
	{	if ( !regEmail.test( val ) )	{	oInput.removeClass('checked').addClass('error');	}
		else									{	oInput.addClass('checked').removeClass('error');	}
	}

	var fields = oForm.find('.required').length;
	var checked = oForm.find('.checked').length;

	if( oForm.find('.required').length == oForm.find('.checked').length )
	{	oForm.find('input[@type = "submit"]').removeAttr('disabled').css('cursor', 'pointer');	}
}

$(function() {
	$('.check').find('input[@type = "submit"]').attr('disabled', 'disabled').css('cursor', 'default');

	$('.check .notEmpty').keyup(function(e)
		{	if ( e.keyCode != 9 ){	checkInputs( $(this).parents('.check'), $(this) );	}	});
	$('.check .notEmpty').change(function()
		{	checkInputs( $(this).parents('.check'), $(this) ); });
	$('.check .notEmpty').blur(function()
		{	checkInputs( $(this).parents('.check'), $(this) ); });

	$('.check .mail').keyup(function()
		{ if ( $(this).hasClass('error') ) checkInputs( $(this).parents('.check'), $(this) ); });
	$('.check .mail').change(function()
		{ checkInputs( $(this).parents('.check'), $(this) ); });
	$('.check .mail').blur(function()
		{ checkInputs( $(this).parents('.check'), $(this) ); });

	$('.check .int').keyup(function()
		{ if ( $(this).hasClass('error') ) checkInputs( $(this).parents('.check'), $(this) ); });
	$('.check .int').change(function()
		{ checkInputs( $(this).parents('.check'), $(this) ); });
	$('.check .int').blur(function()
		{ checkInputs( $(this).parents('.check'), $(this) ); });

});
