$(document).ready (function()
{

	$("#ftxt").focus();
	fast_search();

	/* Регионы на страницах
	-----------------------------------------
	*/
	selectRegion ();

	/* Профиль на страницах
	-----------------------------------------
	*/
	changeProfile ();


easypay_tooltip();

	/* Закрытие окон подсказок и опенбай-меню при клике на странице */
	$("#TB_overlay2").click(function() {
		$(".tooltip, #openbyMenu, .b-easypay").fadeOut(200);
		$(this).hide();

		remove_fast_search();
		
		hide_all_banners();
		$('#ad9972ce').removeAttr('class');
		return false;
	});

	/* ------- Табы ----------- */

	var firstTabLink = $('a[rel*=tab1]');
	var secondTabLink = $('a[rel*=tab2]');
	var secondTabShops = $('a[rel*=images]');
	var firstTab = $('div.tabcontentone');
	var secondTab = $('div.tabcontenttwo');
	var activeurl = document.location.hash;

	firstTabLink.click(function () {
		firstTab.show();
		$(this).addClass('selected');
		secondTabLink.removeClass('selected');
		secondTab.hide();
	});
	secondTabLink.click(function () {
		firstTab.hide();
		secondTab.show();
		$(this).addClass('selected');
		firstTabLink.removeClass('selected');
	});
	if(activeurl == '#images') {
		secondTabLink.click();
	}
	/* ------- // Табы --------- */


	/* ------- Подсветка select'ов в классификаторе --------- */

	var selList = $("select.fl");
	
	//selList.attr("style", "background:#FFE066");
	$("option:selected[value!=0]",selList).each(
		function()
		{
			$(this).attr("style", "background:#FFE066");
			$(this).parents("select").attr("style", "background:#FFE066");
		}
	);

		/*if ($("select.f1 > option"))
		{	
			$(this).attr("style", "background:#FFE066");
			$(this).parents('select.fl').attr("style", "background:#FFE066");
		}*/

	selList.change(function() {
		$("option", this).attr("style", "background:#FFF");
		$(this).attr("style", "background:#FFF");
		if ($("option:selected", this).attr("value") != 0)
		{
			$("option:selected", this).attr("style", "background:#FFE066");
			$(this).attr("style", "background:#FFE066");
		}
	});
	/* ------ // Подсветка select'ов в классификаторе--------- */

	var line = $('#compareTable tbody tr').not('.tdWrap, .groupTitle, .price1, .price2');

	line.mouseover(function () {
		$('td', $(this)).css('background','#FFFBE9');
	});
	line.mouseout(function () {
		$('td', $(this)).removeAttr('style');
	});
});


/* Регионы
-------------------------------------
*/
function selectRegion() {

	var moreRegionLink = $('span.moreRegion');
	moreRegionLink.click(function() {
		var loader = $('<div class="popup-loader"></div>');
		if (!$('div.fullRegionList').length)
		{
			loader.appendTo('body');
			loadOpenbyMenu ();
		}
		$('div.fullRegionList, div#TB_overlay').toggle(hideshowBanners());

		return false;
	})
}

/* загрузка страницы ajax */
function loadOpenbyMenu () {
	if(!$('div.fullRegionList').length) {
		$.ajax({
			url: '/region2.html?fdwdwdff',
			dataType : "html",
			success: function (data) {
				$('div.popup-loader').remove();
				$(data).appendTo('body');
				inBlock();
			}
		});
	}
}

/* скрываем флеш-баннеры при откртом окне регионов */
function hideshowBanners() {

	var banners = $('#ad9972ce,#ad897665,#aa36007e,#a30d27cc,#ab9b7a49,#a30d27cc');

	if (banners.attr("class") != "novisible")
	{
		banners.addClass('novisible');
		$('a.moreRegion').addClass('active');
	}
	else{
		banners.removeAttr('class');
		$('a.moreRegion').removeClass('active');
	}
}

function inBlock () {
	$(document).keydown(function(e){
		$('div.fullRegionList, div#TB_overlay').hide();
		hideshowBanners();
	});

	$('a.closeRegionBlock, div#TB_overlay, div.r-linkBlock a').click(function() {
		$('div.fullRegionList, div#TB_overlay').hide();
		hideshowBanners();
	});

	var hoverLink = $('ul.regionCol a');
	hoverLink.bind("mouseover", function() {
		$('span.ft-activeRegion').text($(this).text());
	});
}

/* Профиль
----------------------------
*/
var startingVal = '';
var sel1_old; var sel2_old; var sel3_old; var sel4_old;
var allParams = $('#b-pay input:checkbox, #b-delivery input, #b-geo input, #b-more input');

function changeProfile () {
	var startingParams = new Array();
	var profLinks = $('#l-pay, #l-delivery, #l-geo, #l-more');
	var profBlocks = $('#b-pay, #b-delivery, #b-geo, #b-more');

	sel1_old = $('#obrZakStart option:selected').attr('value');
	sel2_old = $('#obrZakFinish option:selected').attr('value');
	sel3_old = $('#delivZakStart option:selected').attr('value');
	sel4_old = $('#delivZakFinish option:selected').attr('value');

	/* Всплывающие подсказки */
	profileHelp(profLinks,'profHelp');

	/* Определение начального состояния фильтра */
	var actRegion = 0;
	if ($('#i-1150-1').attr('checked'))
	{
		actRegion = 1;
	}

	$('#alltowns').removeAttr('disabled');
	if ($('#alltowns option:selected').val() != 0)
	{
		$('#othertown').removeAttr('disabled');
	}

	/* Выбор способа оплаты */
	$('#b-pay input:checkbox').click(function() {
		var checkedFields = $('#b-pay input[type=checkbox]:checked');
		if (checkedFields.length > 0)
		{
			$('#i-1633-0').attr('checked','checked').removeAttr('disabled');
		}
		else {
			$('#i-1633-1').attr('checked','checked');
			$('#i-1633-0').attr('disabled','disabled');
		}
	});

	$('#i-1633-1').click(function() {
		$('#b-pay input[type=checkbox]:checked').removeAttr('checked');
		$('#i-1633-0').attr('disabled','disabled');
	});


	/* Выбор регионов */
	$('#alltowns').change(function() {
		if ($(this).val() != 0)
		{
			$('#othertown').attr('checked','checked').removeAttr('disabled');
			$('#othertown').attr('value', $(this).val());
		}
		else {
			$('#othertown').attr('disabled','disabled');
			$('#i-1150-1').attr('checked','checked');
		}
	});

	/* Выбор времени обработки и доставки заказов */
	$('.b-moreBlockL input:checkbox, .b-moreBlockL select').click(function() {
		var moreSelectedValsL = $('.b-moreBlockL input[type=checkbox]:checked, .b-moreBlockL select option[value != "0"][value != "2359"]:selected');

		if (moreSelectedValsL.length > 0)
		{
			$('#i-1630-0').attr('checked','checked').removeAttr('disabled');
			$('.b-moreBlockL table, .b-moreBlockL label, #obrZakStart, #obrZakFinish');
		}
		else {
			$('#i-1630-1').attr('checked','checked');
			$('#i-1630-0').attr('disabled','disabled');
			$('.b-moreBlockL table, .b-moreBlockL label, #obrZakStart, #obrZakFinish');
		}
	});
	$('#i-1630-1').click(function() {
		var moreSelectedValsL = $('.b-moreBlockL input[type=checkbox]:checked');

		$('.b-moreBlockL table, .b-moreBlockL label, #obrZakStart, #obrZakFinish');

		$(this).attr('checked','checked');
		$('#i-1630-0').attr('disabled','disabled');
		moreSelectedValsL.removeAttr('checked');
		$('#obrZakStart option[value = "0"]').attr('selected','selected');
		$('#obrZakFinish option[value = "2359"]').attr('selected','selected');
	});


	$('.b-moreBlockR input:checkbox, .b-moreBlockR select').click(function() {
		var moreSelectedValsR = $('.b-moreBlockR input[type=checkbox]:checked, .b-moreBlockR select option[value != "0"][value != "2359"]:selected');

		if (moreSelectedValsR.length > 0)
		{
			$('#i-1153-0').attr('checked','checked').removeAttr('disabled');
			$('.b-moreBlockR table, .b-moreBlockR label, #delivZakStart, #delivZakFinish');
		}
		else {
			$('#i-1153-1').attr('checked','checked');
			$('#i-1153-0').attr('disabled','disabled');
			$('.b-moreBlockR table, .b-moreBlockR label, #delivZakStart, #delivZakFinish');
		}
	});
	$('#i-1153-1').click(function() {
		var moreSelectedValsR = $('.b-moreBlockR input[type=checkbox]:checked');

		$('.b-moreBlockR table, .b-moreBlockR label, #delivZakStart, #delivZakFinish');

		$(this).attr('checked','checked');
		$('#i-1153-0').attr('disabled','disabled');
		moreSelectedValsR.removeAttr('checked');
		$('#delivZakStart option[value = "0"]').attr('selected','selected');
		$('#delivZakFinish option[value = "2359"]').attr('selected','selected');
	});


	/* Открытие закрытие блоков фильтра */
	profLinks.click(function () {
		var profBlocksVisInp = $("#b-pay:visible input[type = checkbox]:checked, #b-delivery:visible input[value != '-1']:checked, #b-geo:visible input[value!=-1]:checked, #b-more:visible input[type = checkbox]:checked, #b-more:visible select[value != 0][value != 2359]");
		var profBlocksVis = $('#b-pay:visible, #b-delivery:visible, #b-geo:visible, #b-more:visible');
		var pla = $('.profItemLinkAct');

		$('.profHelp').hide();

		if ($(this).attr('class') != 'profItemLinkAct')
		{
			if (profBlocksVisInp.length > 0)
			{
				pla.attr('class','profItemLinkSel');
			}
			else {
				pla.attr('class','profItemLink');
			}

			profBlocksVis.hide();

			$(this).attr('class','profItemLinkAct');
			$(this).next('div').show().bgiframe();
			$('#TB_overlay2').show();
		}
		else {
			if (profBlocksVisInp.length > 0)
			{
				pla.attr('class','profItemLinkSel');
			}
			else {
				pla.attr('class','profItemLink');
			}
			profBlocksVis.hide();
			$('#TB_overlay2').hide();
		}
		return false;
	});

	$('#TB_overlay2, .profClose').click(function() {
		var profBlocksVisInp = $("#b-pay:visible input[type = checkbox]:checked, #b-delivery:visible input[value != '-1']:checked, #b-geo:visible input[value!=-1]:checked, #b-more:visible input[type = checkbox]:checked, #b-more:visible select[value != 0][value != 2359]");
		var profBlocksVis = $('#b-pay:visible, #b-delivery:visible, #b-geo:visible, #b-more:visible');
		var pla = $('.profItemLinkAct');

		if (profBlocksVisInp.length > 0)
		{
			pla.attr('class','profItemLinkSel');
		}
		else {
			pla.attr('class','profItemLink');
		}
		profBlocksVis.hide();
		$('#TB_overlay2').hide();

		return false;
	});
};

/* Всплывающие подсказки */
function profileHelp(target_items, name) {
	$(target_items).each(function(i){

		$("body").append("<div class='"+name+"' id='"+name+i+"' style='display:none;'><iframe frameborder='no'></iframe><p></p></div>");

		$(this).removeAttr("title").bind("mouseenter",function(kmouse){
			var th=$(this);
			var my_tooltip = $("#"+name+i);

			if ($(this).attr('class') == 'profItemLinkAct')
			{
				return false;
			}
			t = setTimeout(function() {
				switch (th.attr('id'))
				{
				case ('l-pay'):
					var values = '';
					$('#b-pay input[type=checkbox]:checked').each(function() {
						values = values+$('label[for*='+$(this).attr('id')+']').text()+'<br />';
					});
					if ($('#b-pay input[type=checkbox]:checked').length == 0)
					{
						values = values+'Любой способ'
					}
					$('#profHelp0 p').html(values);
					break;
				case ('l-delivery'):
					var values = '';
					$('#b-delivery input:checked').each(function() {
						values = values+$('label[for*='+$(this).attr('id')+']').text()+'<br />';
					});
					if ($('#b-delivery input:checked').length == 0)
					{
						values = values+'Любое значение'
					}
					$('#profHelp1 p').html(values);
					break;
				case ('l-geo'):
					var values = '';
					if ($('#othertown').attr('checked'))
					{
						values = $('#alltowns option:selected').text();
					}
					else {
						values = $('label[for*='+$('#b-geo input:checked').attr('id')+']').text();
					}
					$('#profHelp2 p').html(values);
					break;
				case ('l-more'):
					var values = '';
					var test = ['пн','вт','ср','чт','пт','сб','вс'];

					values = 'Время обработки заказов: <br />&nbsp;&nbsp;';

					var a=0;

					$('.b-moreBlockL input:checkbox').each(function(i) {
						if ($(this).attr('checked'))
						{
							values = values+test[i]+', ';
							a++;
						}
					});
					if (a==0)
					{
						values = values+'любой день';
					}
					values=values+'<br />&nbsp;&nbsp; с '+$('#obrZakStart option:selected').text()+' до '+$('#obrZakFinish option:selected').text()+'<br />Время доставки заказов: <br />&nbsp;&nbsp;';

					var b=0;

					$('.b-moreBlockR input:checkbox').each(function(i) {
						if ($(this).attr('checked'))
						{
							values = values+test[i]+', ';
							b++;
						}
					});
					if (b==0)
					{
						values = values+'любой день';
					}
					values=values+'<br />&nbsp;&nbsp; с '+$('#delivZakStart option:selected').text()+' до '+$('#delivZakFinish option:selected').text();
					$('#profHelp3 p').html(values);
					break;
				};

				my_tooltip.css({left:kmouse.pageX+5, top:kmouse.pageY+5});
				my_tooltip.css({opacity:1, display:"none"}).fadeIn(200)
			},1000)
		}).mouseout(function(){
			$('.profHelp:visible').fadeOut(200);
			clearTimeout(t);
			
		});
	});
};

function resetFilter(prof1, prof2, prof3) {
	$('.profMenu input[value="0"], .profMenu input[value="-1"]:not(#i-1632-1, #i-1150-1), #alltowns').attr('disabled','disabled');

	//$('.profMenu select[value="0"], .profMenu select[value="2359"]')

	var sel1 = $('#obrZakStart');
	var sel2 = $('#obrZakFinish');
	var sel3 = $('#delivZakStart');
	var sel4 = $('#delivZakFinish');

	if ((sel1.val() == '0') && (sel1_old == '0'))
	{
		sel1.attr('disabled','disabled');
	}
	if ((sel2.val() == '2359') && (sel2_old == '2359'))
	{
		sel2.attr('disabled','disabled');
	}
	if ((sel3.val() == '0') && (sel3_old == '0'))
	{
		sel3.attr('disabled','disabled');
	}
	if ((sel4.val() == '2359') && (sel4_old == '2359'))
	{
		sel4.attr('disabled','disabled');
	}
	if (prof1 == 1)
	{
		if ($('#b-pay input[type = checkbox]:checked').length == 0)
		{
			$('#i-1633-1').removeAttr('disabled');
		}
	}
	if (prof2 == 1)
	{
		var clearL = $('<input type="hidden" name="eshop_prof_1630" value="-1" />');

		if ($('.b-moreBlockL input[type = checkbox]:checked').length == 0)
		{
			$('#i-1630-1').removeAttr('disabled');
			$('#profileForm').append(clearL);
		}
	}
	if (prof3 == 1)
	{
		var clearR = $('<input type="hidden" name="eshop_prof_1153" value="-1" />');

		if ($('.b-moreBlockR input[type = checkbox]:checked').length == 0)
		{
			$('#i-1153-1').removeAttr('disabled');
			$('#profileForm').append(clearR);
		}
	}
};

function checkDays() {
	var daysL = $('.b-moreBlockL .daysTable input:checked').length;
	var daysR = $('.b-moreBlockR .daysTable input:checked').length;
	var clearL = $('<input type="hidden" name="eshop_prof_1630" value="-1" />');
	var clearR = $('<input type="hidden" name="eshop_prof_1153" value="-1" />');

	if (daysL == 0)
	{
		$('#profileForm').append(clearL);
	}
	if (daysR == 0)
	{
		$('#profileForm').append(clearR);
	}
};


/* var countChecked = 0;
function changeButton() {
	switch($(this)[0].tagName) {
		case 'INPUT' :
			if($(this).attr('checked')) {
				countChecked++;
			}
			else {
				countChecked--;
			}
			break;
		case 'SELECT' :
			if(($(this).val() != '0') && ($(this).val() != '2359')) {
				countChecked++;
			}
			else {
				countChecked--;
			}
			break;
	}
	
	if(countChecked) {
		$('#submitProfile').attr('src','/pics/profbutton_act.gif').removeAttr('disabled');
	}
	else {
		//$('#submitProfile').attr('src','/pics/profbutton_noact.gif').attr('disabled','disabled');
	}
};
*/

/*function changeButton(startMassiv) {
	var resMassiv = new Array();
	var comp = startMassiv.concat(resMassiv);

	$('#b-pay input:checkbox, #b-delivery input, #b-geo input, #b-more input:checkbox').click(function() {
		var count = 0;
		for (i=0; i<comp.length; i++)
		{
			if (comp[i] == $(this).attr('id'))
			{
				count++;
				delete comp[i];
			}
		}
		if (count == 0)
		{
			comp.push($(this).attr('id'));
		}
	});

	$('#l-more').click(function() {

		var a = '';
		var a2 = '';

		for( var item in comp){
			a = a+'  '+comp[item];
		}
		alert(a);
		alert('первоначальный');
		for( var item2 in startMassiv) {
			a2 = a2+'  '+startMassiv[item2];
		}
		alert(a2);
	});
};*/


/* Плагин для перекрытия селектов ie6 */
(function($){

$.fn.bgIframe = $.fn.bgiframe = function(s) {
	// This is only for IE6
	if ( $.browser.msie && parseInt($.browser.version) <= 6 ) {
		s = $.extend({
			top     : 'auto', // auto == .currentStyle.borderTopWidth
			left    : 'auto', // auto == .currentStyle.borderLeftWidth
			width   : 'auto', // auto == offsetWidth
			height  : 'auto', // auto == offsetHeight
			opacity : true,
			src     : 'javascript:false;'
		}, s || {});
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
		               'style="display:block;position:absolute;z-index:-1;'+
			               (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
					       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
					       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
					       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
					'"/>';
		return this.each(function() {
			if ($('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};

// Add browser.version if it doesn't exist
if (!$.browser.version)
	$.browser.version = navigator.userAgent.toLowerCase().match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1];

})(jQuery);



/*
-------------------- Сравнение
*/

/* Изменение ссылки на странице моделей */
function addCompare(curLink) {
	var thisLink = $('#add_'+curLink);
	var thisHideLink = $('#added_'+curLink);

	$.get(thisLink.attr('href'), {}, function(data) {
		if (data == 0)
		{
			$('#add_2_'+curLink).hide(); $('#add_2b_'+curLink).hide();
			thisHideLink.show(); $('#added_b'+curLink).show();
		}
	});
};

/* Изменение ссылки на странице моделей */
function delCompare(curLink) {
	var thisLink = $('#del_'+curLink);
	var thisHideLink = $('#add_2_'+curLink);

	$.get(thisLink.attr('href'), {}, function(data) {
		if (data == 0)
		{
			$('#added_'+curLink).hide(); $('#added_b'+curLink).hide();
			thisHideLink.show(); $('#add_2b_'+curLink).show();
		}
	});
};


/* Страница сравнения */

/* Удаление типа сравнения */
function removeCompareCat(curCat) {
	var thisCat = $('#'+curCat);
	$.get(thisCat.attr('href'), {}, function(data) {
		if (data == 0)
		{
			thisCat.parent().remove();
		}
	});
};

/* Удаление активного типа сравнения */
function removeCompareActiveCat(curCat) {
	var thisCat = $('#'+curCat);
	$.get(thisCat.attr('href'), {}, function(data) {
		if (data == 0)
		{
			document.location='/list/?action=view&list_type=c';
		}
	});
};

function remove1CompareActiveCat(curCat, lastCat) {
	var thisCat = $('#'+curCat);
	$.get(thisCat.attr('href'), {}, function(data) {
		if (data == 0)
		{
			document.location='/list/?action=view&list_type=c&last_ess_id='+lastCat;
		}
	});
};

function removeCompareAllCat(lastCat) {
	var lastId = $('#compRemoveAll');
	$.get(lastId.attr('href'), {}, function(data) {
		if (data == 0)
		{
			document.location='/list/?action=view&list_type=c&last_ess_id='+lastCat;
		}
	});
};

/* Удаление модели*/
function removeCompareModel(curCat, curEss) {
	var thisCat = $('#'+curCat);
	$.get(thisCat.attr('href'), {}, function(data) {
		if (data == 0)
		{
			document.location='/list/?action=view&list_type=c&ess_id='+curEss;
		}
	});
};



function easypay_tooltip() {
	var link = $('.ep2');
	var block = $('.b-easypay');
	var close = $('.closeeas');
	block_links = $('.b-easypay a');

	link.bind("mouseenter",function(kmouse){
		t = setTimeout(function(){
			$("#TB_overlay2").show();
			block.css({left:kmouse.pageX-80, top:kmouse.pageY+10});
			block.css({opacity:1, display:"none"}).fadeIn(200);
			hide_all_banners();
		},1000)
	}).click(function(){
		$("#TB_overlay2").show();
		block.css({opacity:1, display:"none"}).fadeIn(200);
		hide_all_banners();
		return false;
	}).click(function(kmouse){
		clearTimeout(t);
		block.css({left:kmouse.pageX-80, top:kmouse.pageY+10});
	}).mouseout(function(){
		clearTimeout(t);
	});

	close.click(function() {
		clearTimeout(t);
		block.fadeOut(200);
		$("#TB_overlay2").hide();
		hide_all_banners();
		return false;
	});

	block_links.click(function() {
		block.hide();
		$("#TB_overlay2").hide();
		hide_all_banners();
	});

	return false;
}

function hide_all_banners() {
	$('.rightcol iframe[id != a0009f3b], .centcol iframe').toggleClass("novisible");
}


function fast_search() {
	var linksArray = new Array();
	var links_search = $('.modelListLevel2 a');

	links_search.each(function(i) {
		linksArray[i] = $(this);
	});

	$('#fast_search_line').keyup(function(e) {

		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}

		var list;
		var cur_val = $(this).val();
		var regexp = new RegExp(cur_val, 'ig');

		var list = '';

		for (i=0;i<linksArray.length ;i++ ) {
			if ( linksArray[i].text().search(regexp) >= 0) {
				list = list+'<li><a href="'+linksArray[i].attr('href')+'" title="Перейти в раздел">'+linksArray[i].text()+'</a></li>';
			}
		};

		var catsBlock = '<ul id="fsearchResults">'+list+'</ul>';
		
		if ($('#fsearchResults') && (keycode != 40) && (keycode != 38) && (keycode != 13))
		{
			$('#fsearchResults').remove();
			$('#fast_search_line').css('background','url(../pics/fsearch_arrow_r.gif) 350px center no-repeat');
			$('#TB_overlay2').hide();

			if (($('#fast_search_line').val() != '') && (list != ''))
			{
				$('#fast_search_line').css('background','url(../pics/fsearch_arrow_b.gif) 350px center no-repeat');
				$('#fast_search_line').after(catsBlock);
				$('#TB_overlay2').show();
			}
		}
		else {
			if (keycode == 40)
			{
				if ($('#fsearchResults a.sel').length == 0)
				{
					$('#fsearchResults a:first').addClass('sel');
				}
				else {
					var tmp = $('#fsearchResults a.sel').parent().next('li').children('a');
					$('#fsearchResults a.sel').removeClass('sel');
					tmp.addClass('sel');
				}
				$('#fast_search_line').val($('#fsearchResults a.sel').text());
			}
			if (keycode == 38)
			{
				if ($('#fsearchResults a.sel').length == 0)
				{
					$('#fsearchResults a:last').addClass('sel');
				}
				else {
					var tmp = $('#fsearchResults a.sel').parent().prev('li').children('a');
					$('#fsearchResults a.sel').removeClass('sel');
					tmp.addClass('sel');
				}
				$('#fast_search_line').val($('#fsearchResults a.sel').text());
			}
			if (keycode == 13)
			{
				//alert('gogogo');
				document.location= $('#fsearchResults a.sel').attr('href');
				return false;
			}
		}

		if(keycode == 27) {
			remove_fast_search();
		}


		return false;

	});
}


function remove_fast_search() {
	$('#fsearchResults').remove();
	$('#fast_search_line').css('background','url(../pics/fsearch_arrow_r.gif) 350px center no-repeat');
	$("#TB_overlay2").hide();
}


/* Проверка формы подбора кредита*/
function chech_creditform(crform) {
		var error = 0;
		
		if(crform.kreditFormSum.value == '') {
			error = 1;
			alert('Пожалуйста, заполните сумму кредита!');
			return false;
		} 
			
		if(crform.kreditFormSrok.value == '') {
			error = 1;
			alert('Пожалуйста, заполните срок кредита!');
			return false;
			} 

		if (error != 1 ) {
			$.get('/credit_log.php');
			crform.submit();
			tb_remove();
		}
		
		
	}