$(function()
{
	$('.footer .staff').scrollable();
	
	$('.feedback').submit(function()
	{
		errors = '';
		if ($('#name').val().length < 1)
		{
			errors = 'Введите имя\n';
		}
		if ($('#company').val().length < 1)
		{
			errors += 'Введите название организации\n';
		}
		if ($('#email').val().length < 1)
		{
			errors += 'Введите email\n';
		}
		else 
		{
			if (!isValidEmail($('#email').val()))
			{
				errors += 'Неправильный email\n';
			}
		}
		if ($('#question').val().length < 1)
		{
			errors += 'Введите вопрос';
		}
		
		if (errors.length == 0)
		{
			$.get('feedback/send?name=' + $('#name').val() + '&company=' + $('#company').val() + '&phone=' + $('#phone').val() + '&email=' + $('#email').val() + '&question=' + $('#question').val());
			$('.ob').html('Наши менеджеры свяжутся с Вами в ближайшее время. Спасибо за внимание к нашей компании.');
		}
		else
		{
			alert(errors);
		}
		
		return false;
	});
	
	if ($('a.fancybox').length > 0)
	{
		$('.fancybox').fancybox();
	}
});

function isValidEmail (email, strict)
{
 if ( !strict ) email = email.replace(/^\s+|\s+$/g, '');
 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}
