$(document).ready(function(){
	$('.search-form .search-txt').toggleVal();
	$('.search-form .search-btn').click(function(){
		$('#search-form').submit();
		return false;
	});

	$('.sr-form .sr-btn').click(function(){
		$('#sr-form').submit();
		return false;
	});

	$('.cf-btn').click(function(){
		$('#cf-form').submit();
		return false;
	});

	if($('.flash_banner').length){
		$('.flash_banner').each(function(index) {
			swfobject.embedSWF($(this).attr('rel'), $(this).attr('id'), "140", "160", "8.0.0", false, false, {backgrounf:"#ffffff"});
		});
	}

	if($('.wtb').length>0)
	{
		$select = $('.wtb select');
		$table_cont = $('.wtb_cont');
		$select.change(function(){
			$table_cont.load('data/tpl-where_buy_ajax/'+encodeURIComponent($select.val())+'/');
		});
		$table_cont.load('data/tpl-where_buy_ajax/'+encodeURIComponent($select.val())+'/');
	}
	
	var popen = function(url, name, w, h){
		 w += 32;
		 h += 96;
		 var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' +  'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no');
		 win.resizeTo(w, h);
		 win.focus();
	}
	
	var wopen = function(url)
	{
		window.open(url);
	}
	
	if($('.social').length){
		$('.social .vk').click(function(){
			popen('http://vkontakte.ru/share.php?url='+encodeURIComponent(document.location.href), 'share-vk', 580, 380);
			return false;
		});
		$('.social .ok').click(function(){
			popen('http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1&st._surl='+encodeURIComponent(document.location.href), 'share-ok', 580, 380);
			return false;
		});
		$('.social .mm').click(function(){
			popen('http://connect.mail.ru/share?share_url='+encodeURIComponent(document.location.href), 'share-mm', 580, 380);
			return false;
		});
		$('.social .fb').click(function(){
			popen('http://www.facebook.com/sharer.php?u='+encodeURIComponent(document.location.href), 'share-fb', 580, 380);
			return false;
		});
		$('.social .tw').click(function(){
			popen('http://twitter.com/intent/tweet?&text='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(document.location.href), 'share-tw', 580, 380);
			return false;
		});
		$('.social .lj').click(function(){
			wopen('http://www.livejournal.com/update.bml?event='+encodeURIComponent('<p>'+$('meta[name=description]').attr('content')+'</p>'+'<p><a href="'+document.location.href+'">'+document.location.href+'</a></p>')+'&subject='+encodeURIComponent(document.title));
			return false;
		});
	}
});

function checkMail(email){
	var pat=/^[\w-+\.]+@([\w-]+\.)+[\w-]{2,}$/i;
	if(pat.test(email)) return true;
		else return false;
}

function check_feedback_form()
{
	if ($('#contact_name').val()=='')
	{
		$('#feedback_form_error').html("Заполните поле \"Ваше имя\", пожалуйста!");
		$('#feedback_form_error').show();
		return false;
	}

	if (!checkMail($('#contact_email').val()))
	{
		$('#feedback_form_error').html("Заполните поле \"Ваш e-mail\", пожалуйста!");
		$('#feedback_form_error').show();
		return false;
	}

	if ($('#contact_message').val()=='')
	{
		$('#feedback_form_error').html("Заполните поле \"Ваш вопрос или пожелание\", пожалуйста!");
		$('#feedback_form_error').show();
		return false;
	}

	$('#feedback_form_error').html("");
	$('#feedback_form_error').hide();

	return true;
}
