$(document).ready(function(){

	$(".tel a").click(function() {
		$(".telfull").fadeIn("fast");
	});
	
	$(".telfull").click(function() {
		$(".telfull").fadeOut("fast");
	});

	$('#block-menu-menu-catalog ul>li>a').click(function() {
		if ($(this).parent().find('ul').length) {
			$(this).parent().find('ul').slideToggle(200);				
        return false;
		}
	});
	
	var id='search';
	var d_text='Поиск по артикулу';
	$('.'+id).attr('value',d_text);
	$('.'+id).click(function(){// click
		$(this).attr('value','');
	});
	$('.'+id).blur(function(){// blur
	process1(id);
	});
	
/*
$('.'+id).focus(function(){
 funcEnter(e,id);
 alert(1);
});
*/

var eeee=document.getElementById(id)

eeee.onkeypress=function(){funcEnter(id,event);}

	$('.search-box a').click(function() {
		process1(id);
        return false;
	});

}); //end jquery


var d_text='Поиск по артикулу';

function funcEnter(id,e){
 if(e.keyCode == 13)process1(id);
}

function process1(id) {
	var vl=$('.'+id).attr('value');
	if(!vl)
		$('.'+id).attr('value',d_text);
	else{
		if(/^[A-Za-z0-9\-]+$/.test(vl))
			process(vl);
		else
			$('.'+id).attr('value',d_text);
	}
}
function process(vl){// ajax
	$.ajax({
		type:'POST',
		url:'/search.php',
		data:'vl='+vl,
		success:function(p){
			if(p=='n')
				window.location.href='http://bgtrade.ru/search?vl='+vl;
			else
				window.location.href='http://bgtrade.ru/products/'+p;
		}
	});
}
