function emailtest(val)
{
	return /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(val);
}

function spacetest(val)
{
	if(val.length < 1)
		return true;
		
	return /^\s+$/.test(val);
}

$
(
	function()
	{
		$('.col-l').hover
		(
			function()
			{
				$(this).find('.down-black').addClass('down-white');
				$(this).addClass('sel-l');
			},
			function()
			{
				if(!$(this).hasClass('open'))
				{
					$(this).find('.down-black').removeClass('down-white');				
					$(this).removeClass('sel-l');
				}
			}
		);
		
		$('.col1 a').hover
		(
			function()
			{
				$(this).addClass('sel');
			},
			function()
			{
				$(this).removeClass('sel');
			}
		);
		
		$('.sel-l').live
		(
			'click',
			function()
			{
				if($(this).hasClass('sel-l2') && !$(this).hasClass('open'))
				{
					$(this).addClass('sel-l open');
					$(this).find('div:hidden').slideDown();
				}
				else
					if(!$(this).hasClass('open'))
						window.location.href = $(this).attr('href');
			}
		);
		
		$('.line').hover
		(
			function()
			{
				if( $(this).parent().hasClass('open') || $(this).parent().parent().hasClass('open'))
					$(this).addClass('linesel');
			},
			function()
			{
				$(this).removeClass('linesel');
			}
		);
		
		$('.line').click
		(
			function()
			{
				if( $(this).parent().hasClass('open') || $(this).parent().parent().hasClass('open'))
				{
					window.location.href = $(this).attr('href');
				}
			}
		)
		
		$('.bg select').change
		(
			function()
			{
				window.location.href = $(this).val();
			}
		);
		
		// отправка формы заказа с валидацией		
		$('.submit').click
		(
			function()
			{
				var fio   = $('#fio').val();
				var phone = $('#phone').val();
				var email = $('#email').val();
				$('.form .error').hide();
				$('.form .errorf').removeClass('errorf');
				
				if(spacetest(fio)) 
				{
					$('#fio')[0].focus();
					$('#fio').addClass('errorf');
					$('#fio').next().show();
					return false;
				}
				
				if(spacetest(phone))
				{ 
					$('#phone')[0].focus();
					$('#phone').addClass('errorf');
					$('#phone').next().show();
					return false;
				}
				
/*
				if(!emailtest(email)) 
				{
					$('#email')[0].focus();
					$('#email').addClass('errorf');
					$('#email').next().show();
					return false;
				}
*/
				
				$(this).parents('form').submit();
				return false;
			}
		);		
	}
)
