//Закрытие слоев с подсказками
function hideDiv(classDiv, classDivIn, this_obj) {
	$("." + classDiv).each(function(){
		if(this_obj.target.className.search(classDivIn)==-1 && $(this).css("display")=="block")
			$(this).css({"display":"none"});
	});
};

//Вставка/удаление тэгов в поле
function insertTagsInField(tag_name, id)
{
	str_relations = $("#" + id).val();

	mas_relations = str_relations.split(";");

	var insert = true;
	for(i=0;i<mas_relations.length-1;i++)
	{
		if(mas_relations[i]==tag_name)
			insert = false;
	}

	if(insert==true)
	{
		new_val = str_relations + tag_name + ";";
		$("#" + id).val(new_val);
	}
	else
	{
		new_str_relations = new String("");

		for(i=0;i<mas_relations.length-1;i++)
		{
			if(mas_relations[i]!=tag_name)
				new_str_relations = new_str_relations + mas_relations[i] + ";";
		}

		$("#" + id).val(new_str_relations);
	}
}

//Изменение стиля тэга
function editStyleTag(text_id, div_id)
{
	str = $("#" + text_id).val();

	if(str!="")
	{
		mas = str.split(";");

	    $("#" + div_id + " a").each(function() {
	       obj = $(this);

	        $.each(mas, function(i, n) {
	        	if(obj.text()==n)
	        	{
	        		if(obj.attr('class')=="uncheck")
					{
						obj.removeClass("uncheck");
						obj.addClass("check");
					}
	        	}
	        });
	    });
	}
}

//Добавление стиля тэга ( + вставка значения Вставка/удаление тэгов в поле)
function addStyleTag(div_id)
{
	$("#" + div_id + " a").each(function() {
		$(this).click(function(){
			if($(this).attr('class')=="check")
			{
				$(this).removeClass("check");
				$(this).addClass("uncheck");
			}
			else if($(this).attr('class')=="check hover")
			{
				$(this).removeClass("check hover");
				$(this).addClass("uncheck");
			}
			else if($(this).attr('class')=="uncheck")
			{
				$(this).removeClass("uncheck");
				$(this).addClass("check");
			}
			else if($(this).attr('class')=="uncheck hover")
			{
				$(this).removeClass("uncheck hover");
				$(this).addClass("check");
			}

			insertTagsInField($(this).text(), "relations");

			return false;
		});
	});
}

//Создание выпадающей подсказки на событие клика мыши
function getPromptOnClick(obj_id, obj_i_id, prompt_name, is_str) //obj_id - category1, obj_i_id - i_id, prompt_name - category_p
{
	$('#' + obj_id).click(function (e) {
			
		//установка ширины поля с выпадающей подсказкой
		if(navigator.appName=="Netscape")
			$('#' + prompt_name + $(this).attr(obj_i_id)).width('272px');
		else
			$('#' + prompt_name + $(this).attr(obj_i_id)).width('272px');
			
		if(is_str==1)
		{
			size_block_cat = $(".block_cat").size();

			if(size_block_cat!=0)
			{
				str = new String();
				for(k=1;k<=size_block_cat;k++)
				{
					if($("#category" + k).val()!="")
						str = str + "'" + $("#category" + k).val() + "'" + ";";
				}
				str = str.substring(0, str.length-1);
			}
			else
				str = "";
		}
		else
			str = "";

		if($(this).attr('value')==null)
			$('#' + prompt_name + $(this).attr(obj_i_id)).load('/basis/sec/' + prompt_name + '/', {letter:'NO', i_id:$(this).attr(obj_i_id), cat_id:str}, function() {
				$('.block_cat a').each(function() {
					$(this).click(function() {
						setFlagConsist("formRoomOrg", 0, "room_org_sub");
					});
				});
			});
		else
			$('#' + prompt_name + $(this).attr(obj_i_id)).load('/basis/sec/' + prompt_name + '/', {letter:$(this).attr('value'), i_id:$(this).attr(obj_i_id), cat_id:str}, function() {
				$('.block_cat a').each(function() {
					$(this).click(function() {
						setFlagConsist("formRoomOrg", 0, "room_org_sub");
					});
				});
			});
	});
}

//Создание выпадающей подсказки на событие нажатия клавиши
function getPromptOnKeyup(obj_id, promt_id, obj_a_id, id, promt_in_id, is_str, prompt_name, obj_i_id) //obj_id - category1, promt_id - podsk_word1, obj_a_id - a_id, id - id1, promt_in_id - podsk_in1, prompt_name - category_p, obj_i_id - i_id
{
	$('#' + obj_id).keyup(function (e) {
		//установка ширины поля с выпадающей подсказкой
		if(navigator.appName=="Netscape")
			$('#' + prompt_name + $(this).attr(obj_i_id)).width('272px');
		else
			$('#' + prompt_name + $(this).attr(obj_i_id)).width('272px');
									
		if(e.which==40)
		{
			class_search = 0;

			$('.' + promt_id + ' a').each(function () {
				if($(this).attr('class')=='search')
				{
					this_id = new Number($(this).attr(obj_a_id));
					next_id = new Number();
					next_id = this_id + 1;

					if($('#' + id + next_id).attr('tag_name')!=null)
					{
						$(this).removeClass('search');
						$(this).addClass('unsearch');

						$('#' + id + next_id).removeClass('unsearch');
						$('#' + id + next_id).addClass('search');

						$('#' + obj_id).val($('#' + id + next_id).attr('tag_name'));

						class_search = 1;
					}

					return false;
				}
			});

			if(class_search==0)
			{
				size_podsk_word = $('.' + promt_id).size();

				if($('#' + id + size_podsk_word).attr('class')=='search')
				{
					$('#' + id + size_podsk_word).removeClass('search');
					$('#' + id + size_podsk_word).addClass('unsearch');
				}

				$('#' + id + '1').removeClass('unsearch');
				$('#' + id + '1').addClass('search');

				$('#' + obj_id).val($('#' + id + '1').attr('tag_name'));
			}
		}
		else if(e.which==38)
		{
			class_search = 0;

			$('.' + promt_id + ' a').each(function () {
				if($(this).attr('class')=='search')
				{
					this_id = new Number($(this).attr(obj_a_id));
					prev_id = new Number();
					prev_id = this_id - 1;

					if($('#' + id + prev_id).attr('tag_name')!=null)
					{
						$(this).removeClass('search');
						$(this).addClass('unsearch');

						$('#' + id + prev_id).removeClass('unsearch');
						$('#' + id + prev_id).addClass('search');

						$('#' + obj_id).val($('#' + id + prev_id).attr('tag_name'));

						class_search = 1;
					}

					return false;
				}
			});

			if(class_search==0)
			{
				size_podsk_word = $('.' + promt_id).size();

				if($('#' + id + '1').attr('class')=='search')
				{
					$('#' + id + '1').removeClass('search');
					$('#' + id + '1').addClass('unsearch');
				}

				$('#' + id + size_podsk_word).removeClass('unsearch');
				$('#' + id + size_podsk_word).addClass('search');

				$('#' + obj_id).val($('#' + id + size_podsk_word).attr('tag_name'));
			}
		}
		else if(e.which==13)
		{
			$('#' + promt_in_id).css({'display':'none'});
		}
		else
		{
			if(is_str==1)
			{
				size_block_cat = $(".block_cat").size();

				if(size_block_cat!=0)
				{
					str = new String();
					for(i=1;i<=size_block_cat;i++)
					{
						if($('#category' + i).val()!="")
							str = str + "'" + $('#category' + i).val() + "'" + ";";
					}
					str = str.substring(0, str.length-1);
				}
				else
					str = "";
			}
			else
				str = "";

			$('#' + prompt_name + $(this).attr(obj_i_id)).load('/basis/sec/' + prompt_name + '/', {letter:$(this).attr('value'), i_id:$(this).attr(obj_i_id), cat_id:str}, function() {
				$('.block_cat a').each(function() {
					$(this).click(function() {
						setFlagConsist("formRoomOrg", 0, "room_org_sub");
					});
				});
			});
		}
	});
}

//Очищение текстовых полей видов товаров и брендов при изменении категории
function setValNull()
{
	cvals = "";			  
	$('.block_cat input').each(function() {
		cvals = cvals + "'" + $(this).val() + "'" + ";";
	});
		  
	$('#loadPermitHidden').load('/basis/sec/category_p/', {setNull:1, cvals:cvals}, function() {
		$('.block_goo input').each(function() {	
			hidden_goo_val = $('#hidden_goo').val();
	
			if(hidden_goo_val.indexOf("|" + $(this).val() + "|")==-1)
				$(this).val("");
		});
		$('.block_bra input').each(function() {	
			hidden_bra_val = $('#hidden_bra').val();
	
			if(hidden_bra_val.indexOf("|" + $(this).val() + "|")==-1)
				$(this).val("");
		});	
	});
}

//Формирование тэгов-ссылок для предварительного просмотра
function createTagsLink(id)
{
	text = '';
	$('#' + id + ' input').each(function() {
		if($(this).val()!="")
			text = text + "<a href='#' onclick='return false;'>" + $(this).val() + "</a>, ";
	});	
	
	return text;
}

//Использовать адрес компании	
function comAddress(id)
{
	if(id!="")
	{
		$('#' + id).click(function() {
			if($(this).attr('do')==1)  
			{
				if($(this).attr('class')=="shop_act")
				{
					$(this).removeClass('shop_act');
					$(this).addClass('shop_deact');
					
					$('#address' + $(this).attr('addr_id')).val("");
				}
				else
				{
					$(this).removeClass('shop_deact');
					$(this).addClass('shop_act');
					
					$('#address' + $(this).attr('addr_id')).val($(this).attr('caddress'));
				}
				
				return false;
			}
			else
				return false;
		});
	}
}

// Флаг корректности заполнения полей
function setFlagConsist(form_id, id, sub_id)
{
	this_flag = 1;
	this_false = 0;
	for(j=1;j<=$('#' + form_id + ' input').size();j++)
	{
		if($('#inp' + j).attr('flag')==0)
		{
			this_flag = 0;
			if(j==id)
				this_false = 1;
		}
	}
	
	// Проверка категорий на пустоту
	if($(".block_cat").size()!=0)
	{
		val_flag = 0;
		
		$('.block_cat input').each(function() {
			if($(this).val()!="")
				val_flag = 1;
		});
	}
	else
		val_flag = 1;
		
	// Проверка числа-капчи
	if($('#check_number').size()!=0)
	{
		if($('#check_number').attr('flag')==0)
		{
			this_flag = 0;
			if(id=="check_number")
				this_false = 1;
		}
	}
	
	if(this_flag==1 && val_flag==1)
		$('#' + sub_id).attr('disabled', false);
	else
		$('#' + sub_id).attr('disabled', true);
		
	if(this_false==1)
		$('#dop' + id).css("height","27px");
	else
		$('#dop' + id).css("height","0px");	
}

//Установка активности/неактивности текстового поля
function setEnOrDis(id, removeClass, addClass, disabled)
{
	$('#' + id).removeClass(removeClass);
	$('#' + id).addClass(addClass);
	$('#' + id).attr('disabled',disabled);	
}

function fieldForTypeD()
{
	//------------max %---------------
	$('#inp2').attr('nocheck', '0');
	
	if($('#inp2').val()!="" && $('#inp2').val().match(/[^0-9]/i)==null)
		$('#inp2').attr('flag', '1');
	else
		$('#inp2').attr('flag', '0');
	
	setFlagConsist("formRoomOrg", 2, "room_org_sub");
	$('#dop2').css("height","0px");
	
	$('#star_max_p').css('visibility','visible');
	//--------------------------------
	
	//------------min %---------------
	$('#inp3').attr('nocheck', '0');
	
	if($('#inp3').val().match(/[^0-9]/i)==null)
		$('#inp3').attr('flag', '1');
	else
		$('#inp3').attr('flag', '0');
	
	setFlagConsist("formRoomOrg", 3, "room_org_sub");
	$('#dop3').css("height","0px");
	//--------------------------------
	
	//---------min %, max %-----------
	setEnOrDis('inp3', 'textbox_dis', 'textbox', false);
	setEnOrDis('inp2', 'textbox_dis', 'textbox', false);
	//--------------------------------
	
	//----------description-----------
	$('#star_des').css('visibility','hidden');
	//--------------------------------
}

function fieldForTypeS()
{
	//------------max %---------------
	$('#inp2').val("");
	$('#inp2').attr('nocheck', '1');
	$('#font2').text("");
	$('#inp2').attr('flag', '1');
	
	setFlagConsist("formRoomOrg", 2, "room_org_sub");
	
	$('#star_max_p').css('visibility','hidden');
	//--------------------------------
	
	//------------min %---------------
	$('#inp3').val("");
	$('#inp3').attr('nocheck', '1');
	$('#font3').text("");
	$('#inp3').attr('flag', '1');
	
	setFlagConsist("formRoomOrg", 3, "room_org_sub");
	//--------------------------------
	
	//---------min %, max %-----------
	setEnOrDis('inp3', 'textbox', 'textbox_dis', true);
	setEnOrDis('inp2', 'textbox', 'textbox_dis', true);
	//--------------------------------
	
	//----------description-----------
	$('#star_des').css('visibility','visible');
	//--------------------------------
}

// Присвоение стилей выделенной/закрытой скидке
function changeClassesForAction(this_lid, suffRmClass, suffAddClass)
{
	// Присвоение стилей выделенной/закрытой скидке верхней части блока
	$("#gl" + this_lid + " .action_top div:eq(0)").removeClass('actionsList-tl' + suffRmClass);
	$("#gl" + this_lid + " .action_top div:eq(0)").addClass('actionsList-tl' + suffAddClass);
	
	$("#gl" + this_lid + " .action_top div:eq(1)").removeClass('actionsList-tlogo' + suffRmClass);
	$("#gl" + this_lid + " .action_top div:eq(1)").addClass('actionsList-tlogo' + suffAddClass);
	
	$("#gl" + this_lid + " .action_top div:eq(2)").removeClass('actionsList-tm' + suffRmClass);
	$("#gl" + this_lid + " .action_top div:eq(2)").addClass('actionsList-tm' + suffAddClass);
	
	$("#gl" + this_lid + " .action_top div:eq(3)").removeClass('actionsList-tbody' + suffRmClass);
	$("#gl" + this_lid + " .action_top div:eq(3)").addClass('actionsList-tbody' + suffAddClass);
	
	$("#gl" + this_lid + " .action_top div:eq(4)").removeClass('actionsList-tr' + suffRmClass);
	$("#gl" + this_lid + " .action_top div:eq(4)").addClass('actionsList-tr' + suffAddClass);
	
	// Присвоение стилей выделенной/закрытой скидке средней части блока
	$("#action" + this_lid).removeClass('actions_list' + suffRmClass);
	$("#action" + this_lid).addClass('actions_list' + suffAddClass);
	
	// Присвоение стилей выделенной/закрытой скидке нижней части блока
	$("#gl" + this_lid + " .action_bottom div:eq(0)").removeClass('actionsList-bl' + suffRmClass);
	$("#gl" + this_lid + " .action_bottom div:eq(0)").addClass('actionsList-bl' + suffAddClass);
	
	$("#gl" + this_lid + " .action_bottom div:eq(1)").removeClass('actionsList-blogo' + suffRmClass);
	$("#gl" + this_lid + " .action_bottom div:eq(1)").addClass('actionsList-blogo' + suffAddClass);
	
	$("#gl" + this_lid + " .action_bottom div:eq(2)").removeClass('actionsList-bm' + suffRmClass);
	$("#gl" + this_lid + " .action_bottom div:eq(2)").addClass('actionsList-bm' + suffAddClass);
	
	$("#gl" + this_lid + " .action_bottom div:eq(3)").removeClass('actionsList-bbody' + suffRmClass);
	$("#gl" + this_lid + " .action_bottom div:eq(3)").addClass('actionsList-bbody' + suffAddClass);
	
	$("#gl" + this_lid + " .action_bottom div:eq(4)").removeClass('actionsList-br' + suffRmClass);
	$("#gl" + this_lid + " .action_bottom div:eq(4)").addClass('actionsList-br' + suffAddClass);
}

// Подгрузка полного описания скидки
function loadTotalAction(this_lid, this_action_id, is_scrolling)
{
	$('#action_total' + this_lid).load("/prev_total/", {action_id:this_action_id,words:$('#list_actions').attr('words')}, function() {																																												
		$('#action_total_in' + this_action_id).animate({height: "show"}, 500, function() {
			// Закрывается короткое описание скидки
			$('#action_short' + this_lid).css("display","none");
			
			loadActionsByTags();
			loadPageOfCompany();
			
			// Карты
			getAllYMaps();
			
			if(is_scrolling != 0)
			{
				ourScrollTop = $("#gl" + this_lid).offset().top - 10;
				$('html, body').animate({scrollTop: ourScrollTop}, 300);
			}
		});
	});
}

// Подсветка скидок
function hightLight(list_actions_id)
{
	$('.general_list').each(function() {
		if(list_actions_id!=0 && $('#' + list_actions_id).attr('aid')==$(this).attr('lid'))
			openConcreteAction(list_actions_id);

		$(this).click(function() {
			this_lid = $(this).attr('lid');
			this_action_id = $('#action_total' + this_lid).attr('action_id');
			
			asHtml = $('#action_short' + this_lid).html();
			asLoaderTop = Math.floor($("#action" + this_lid).height()/2);
			asOverlay = '<div class="actionShort-overlay"></div><div class="actionShort-loader" style="top: ' + asLoaderTop + 'px;"></div>';

			if($('#action_total' + this_lid).attr("vis")==0)
			{
				$('#action_total' + this_lid).attr("vis", "1");
				$('#action_short' + this_lid).html(asHtml + asOverlay);
				
				// Присвоение стилей выделенной скидке
				changeClassesForAction(this_lid, "", "-s");
				
				// Подгрузка полного описания скидки
				loadTotalAction(this_lid, this_action_id, 0);
			}
			else
			{
				$('#action_total' + this_lid).attr("vis", "0");
				asOverlay_length = asOverlay.length;
				
				$('#action_short' + this_lid).html(asHtml.substr(0, asHtml.length-asOverlay_length));
				$('#action_short' + this_lid).css("display","block");
				$('#action_total_in' + this_action_id).css("display","none");
				
				// Присвоение стилей закрытой скидке
				changeClassesForAction(this_lid, "-s", "");
			}

			return false;
		});
	});	
}

// Раскрывание конкретной скидки в списке
function openConcreteAction(id)
{
	if($('#' + id).attr('aid')!=0)
	{
		this_lid = $('#' + id).attr('aid');
		this_action_id = $('#action_total' + this_lid).attr('action_id');
		
		asHtml = $('#action_short' + this_lid).html();
		asLoaderTop = Math.floor($("#action" + this_lid).height()/2);
		asOverlay = '<div class="actionShort-overlay"></div><div class="actionShort-loader" style="top: ' + asLoaderTop + 'px;"></div>';
		
		//document.documentElement.scrollTop = document.getElementById('action' + this_lid).offsetTop - 20;
		
		$('#action_total' + this_lid).attr("vis", "1");
		$('#action_short' + this_lid).html(asHtml + asOverlay);
				
		// Присвоение стилей выделенной скидке
		changeClassesForAction(this_lid, "", "-s");
		
		// Подгрузка полного описания скидки
		loadTotalAction(this_lid, this_action_id, 1);
	}
}

function showLoaderForPaging(list_obj_id, list_pages_id)
{
	list_obj_html = $('#' + list_obj_id).html();
	list_pages_html = $('#' + list_pages_id).html();
	list_obj_overlay = '<div class="paging-overlay"></div><div class="paging-loader"></div>';
	list_pages_overlay = '<div class="paging-overlay"></div>';
					   
	$('#' + list_obj_id).html(list_obj_html + list_obj_overlay);
	$('#' + list_pages_id).html(list_pages_html + list_pages_overlay);
	
	ourScrollTop = $('#search').offset().top - 15;
	
	if($('html, body').scrollTop() > ourScrollTop)
		$('html, body').animate({scrollTop: ourScrollTop}, 300);
}

// Пэйджинг скидок/акций
function paging()
{
	$('#paging a').each(function() {
		$(this).click(function() {
			showLoaderForPaging("list_actions", "list_pages");

			$('#list_pages').attr('page_now',$(this).attr('value'));
			
			var loadArgLa = {};
			var loadArgLp = {};
			
			loadArgLa.page_type = loadArgLp.page_type = $('#list_actions').attr('page_type');
			loadArgLa.str_start = loadArgLp.page_now = $('#list_pages').attr('page_now');
			loadArgLp.count_action = $('#list_pages').attr('count_action');
			
			if(loadArgLa.page_type=="sec")
			{
				loadArgLa.cid = loadArgLp.cid = $('#list_actions').attr('cid');
				loadArgLa.sec = $('#list_actions').attr('sec');
			}
			else if(loadArgLa.page_type=="tags")
				loadArgLa.tags = $('#list_actions').attr('tags');
			else if(loadArgLa.page_type=="words")
				loadArgLa.words = $('#list_actions').attr('words');
		
			$('#list_actions').load("/actions/", loadArgLa, function()
			{
				hightLight(0); 
				loadActionsByTags();

				$('#list_pages').load("/pages/", loadArgLp, function() {
					paging();
				});
			});

			return false;
		});
	});
}

// Пэйджинг новостей
function paging_objects()
{
	$("#pages_place_holder a").each(function () {
		$(this).click(function () {
			showLoaderForPaging("news_place_holder", "pages_place_holder");
								
			$("#news_place_holder").load("/news_d/", {pid:$(this).attr('value'), ncid:$("#news_place_holder").attr("ncid"), page_type:$("#news_place_holder").attr("page_type")});
			$("#pages_place_holder").load("/pages_d/", {pid:$(this).attr('value'), ncid:$("#news_place_holder").attr("ncid"), page_type:$("#news_place_holder").attr("page_type")}, function() {
				paging_objects();
			});
			
			return false;
		});
	});
}

function loadActionsByTags()
{
	$('.action-tags a').each(function() {
		$(this).unbind('click');
		$(this).click(function() {
			window.location.href = $(this).attr('href');
			return false;
		});
	});
}

function loadPageOfCompany()
{
	$('.action-announce a').each(function() {
		$(this).unbind('click');
		$(this).click(function() {
			window.open($(this).attr('href'));
			return false;
		});
	});
	
	$('.shop-table-title a').each(function() {
		$(this).unbind('click');
		$(this).click(function() {
			window.open($(this).attr('href'));
			return false;
		});
	});
}

function loadPageOfRedact()
{
	$('.lk-redact-button a').each(function() {
		$(this).click(function() {
			if($(this).attr('text_for_user')!=null)
			{
				if(confirm("Вы уверенны, что хотите удалить данную " + $(this).attr('text_for_user') + "?"))
					window.location.href = $(this).attr('href');
				
				return false;
			}
			else
			{
				window.location.href = $(this).attr('href');
				return false;
			}
		});
	});
}

// Подгрузка блока "Отправить сообщение о модерации/немодерации"
function loadTextModeration()
{
	if($("#type_d").attr("checked")==true)
		type_action = "d";
	else if($("#type_s").attr("checked")==true)
		type_action = "s";
	
	if($("#moderated").attr("checked")==true)
		type_moderation = "mod";
	else
		type_moderation = "nomod";
		
	$("#textModeration").load('/basis/sec/textModeration/', {type_action:type_action,type_moderation:type_moderation,user_fio:$("#isMailModeration").attr("user_fio"),name_action:$("#inp1").val(),mes_email:$("#isMailModeration").attr("mes_email"),mes_phone:$("#isMailModeration").attr("mes_phone")});
}

// Проверка описания скидки/акции на пустоту. Если описание не пустое, то происходит submit формы.
function isSubmitForm()
{
	if($('#type_s').attr("checked")==true)	
	{
		var checkEditor = FCKeditorAPI.GetInstance("FCKeditor_description"); 
		var checkValue = checkEditor.GetXHTML();
		
		if(checkValue=="")
			alert('Для акции поле "Описание" является обязательным.');
		else
			$('#formRoomOrg').submit();
	}
	else
		$('#formRoomOrg').submit();
}

// Проверка числа-капчи
function doCheckNumber()
{
	$('#fontcheck_number').load('/reg_p/', {id: 'check_number', value: $('#check_number').val(), check_value: $('#check_number').attr('check_value'), data: $('#check_number').attr('name')}, function() {
		$('#check_number').attr('flag', $('#flag_imgcheck_number').attr('flag'));
		setFlagConsist("formRoomOrg", "check_number", "room_org_sub");
	});
}

// Показать Яндекс.Карты
function getYMaps(obj)
{
	if($('#bid1').size()!=0)
		$('#bid1').css("visibility","hidden");
		
	if($('#bid2').size()!=0)
		$('#bid2').css("visibility","hidden");
		
	if($('#bid3').size()!=0)
		$('#bid3').css("visibility","hidden");
					   
	$('body').prepend('<div id="underMap" class="under_map" onClick="closeYMap(); closeAllYMap(); return false;"></div>');
	
	var YMapsHeight = 430;
	var YMapsWidth = 808;
	
	if($.browser.opera)
		var YMapsMarginTop = Math.round((window.innerHeight - YMapsHeight)/2) + $(window).scrollTop();
	else
		var YMapsMarginTop = Math.round(($(window).height() - YMapsHeight)/2) + $(window).scrollTop();

	var closeMapMarginTop = YMapsMarginTop - 26;
	
	var YMapsMarginLeft = Math.round(($(window).width() - YMapsWidth)/2);
	var closeMapMarginLeft = YMapsMarginLeft + YMapsWidth - 69;
	
	$('body').prepend('<div id="YMapsID" class="ymaps_id" style="position: absolute; top: ' + YMapsMarginTop + 'px; left: ' + YMapsMarginLeft + 'px; z-index: 2001; width: ' + YMapsWidth + 'px; height: ' + YMapsHeight + 'px;"></div>');
	
	$('body').prepend('<div id="closeMap" onClick="closeYMap(); closeAllYMap(); return false;" class="close_map" style="position: absolute; top: ' + closeMapMarginTop + 'px; left: ' + closeMapMarginLeft + 'px; z-index: 2001;">Закрыть&nbsp;</div>');

	showYMap(obj.attr("center"), obj.attr("address"), obj.attr("phones"));
}

// Карты
function getAllYMaps()
{
	$(".shop_address").each(function() {
		$(this).unbind('click');
		$(this).click(function() {
			if($(this).attr("type")=="ya")
				getYMaps($(this));
			else if($(this).attr("type")=="2gis")
				window.open($(this).attr('link2gis'));
				
			return false;
		});
	});
	
	$(".addres_ya").each(function() {
		$(this).unbind('click');
		$(this).click(function() {
			getYMaps($(this));

			return false;
		});
	});
	
	$(".addres_2gis").each(function() {
		$(this).unbind('click');
		$(this).click(function() {
			window.open($(this).attr('href'));

			return false;
		});
	});
}

$(document).ready(function() {
	// Развернуть таблицу статистики по баннеру в ЛК
	if($(".div_banner_tables").size()!=0)
	{
		$(".div_banner_tables").each(function() {
			$(this).click(function() {
				if($("#div_table" + $(this).attr("tid")).css("display")=="none")
				{
					$("#div_table_name" + $(this).attr("tid")).removeClass("banner_month_deact");
					$("#div_table_name" + $(this).attr("tid")).addClass("banner_month_act");
					
					$("#div_table" + $(this).attr("tid")).css("display","block");
				}
				else if($("#div_table" + $(this).attr("tid")).css("display")=="block")
				{
					$("#div_table_name" + $(this).attr("tid")).removeClass("banner_month_act");
					$("#div_table_name" + $(this).attr("tid")).addClass("banner_month_deact");
					
					$("#div_table" + $(this).attr("tid")).css("display","none");
				}
			});
		});
	}

	//Проверка на корректность заполнения полей в регистрации
	for(i=1;i<=$('#formReg input').size()-1;i++)
	{
		$('#inp' + i).keyup(function(e) {
			if($(this).attr('reg_id')!=4 && e.which!=9)
			{
				id_next = new Number($(this).attr('reg_id')) + 1;
				$('#inp' + id_next).attr('readonly',false);
			}
		});
		
		$('#inp' + i).blur(function() {
			if($(this).attr('readonly')==false)
			{
				id = $(this).attr('reg_id');
				$('#font' + id).load('/reg_p/', {id: id, value: $('#inp' + id).val(), data: $('#inp' + id).attr('name'), tag_id: 0, com_id: 0, dtype:'com'}, function() {
					$('#inp' + id).attr('flag', $('#flag_img' + id).attr('flag'));
                             
					this_flag = 1; 
					for(j=1;j<=id;j++)
					{
						if($('#inp' + j).attr('flag')==0)
							this_flag = 0; 
					} 
                             
					var id1 = new Number(id); 
					id1 = id1 + 1; 
                             
					if(this_flag==1)
					{
						$('#dop' + id).css("height","0px");
						$('#inp' + id1).attr('readonly', false); 
                                   
						if($('#inp' + id1).attr('class')=='textbox_f') 
						{
							$('#inp' + id1).removeClass('textbox_f'); 
							$('#inp' + id1).addClass('textbox_avt'); 
						}
						
						if(id==4)
							$('#reg_sub').attr('disabled', false);
					}
					else
					{
						$('#inp' + id).select();
						//$('#inp' + id).focus();
						$('#dop' + id).css("height","27px");
						
						for(j=id1;j<=$('#formReg input').size();j++) 
						{
							$('#flag_img' + j).attr('src', '/images/p.gif');
							$('#error_img' + j).text(''); 
							$('#error_img' + j).removeClass('error'); 
							$('#inp' + j).val(''); 
							$('#inp' + j).attr('readonly', true); 
                                         
							if($('#inp' + j).attr('class')=='textbox_avt')
							{
								$('#inp' + j).removeClass('textbox_avt'); 
								$('#inp' + j).addClass('textbox_f');
							}
							
							if($('#dop' + j).height()>0)
								$('#dop' + j).css("height","0px");
						}
						
						if($('#reg_sub').attr('disabled')==false)
							$('#reg_sub').attr('disabled', true);
					}
				});
			}
		});
		
		$('#inp4').keyup(function(e) {
			if(e.which!=16 && e.which!=17)
			{
				if($(this).val()=="")
				{
					$('#dop4').css("height","27px");
					$('#font4').load('/reg_p/', {id: 4, value: '', data: 'fio', tag_id: 0, com_id: 0});
					$('#reg_sub').attr('disabled', true);
				}
				else
				{
					$('#dop4').css("height","0px");
					$('#font4').load('/reg_p/', {id: 4, value: $(this).val(), data: 'fio', tag_id: 0, com_id: 0});
					$('#reg_sub').attr('disabled', false);
				}
			}
		});
            
		$('#inp' + i).click(function() {
			if($(this).attr('readonly')==true)
				$(this).blur();
		});
	}

	//Проверка на корректность заполнения полей в разделах ЛК
	for(i=1;i<=$('#formRoomOrg input').size();i++)
	{
		if($('#inp' + i).size()!=0)
		{
			$('#inp' + i).blur(function() {										
				id = $(this).attr('reg_id');
				
				if($('#inp' + id).attr('dtype')==null)
					dtype = 'com';
				else
					dtype = $('#inp' + id).attr('dtype');

				if($('#inp' + id).attr('nocheck')==null || $('#inp' + id).attr('nocheck')==0)
				{
					if($('#type_d').attr("checked")==true)
						start_type = "type_d";
					else if($('#type_s').attr("checked")==true)
						start_type = "type_s";
					
					$('#font' + id).load('/reg_p/', {id: id, value: $('#inp' + id).val(), data: $('#inp' + id).attr('name'), dtype: dtype, tag_id: $('#hidd_tag_id').val(), com_id: $('#hidd_com_id').val(), user_id: $('#hidd_user_id').val()}, function() {
						$('#inp' + id).attr('flag', $('#flag_img' + id).attr('flag'));
						
						setFlagConsist("formRoomOrg", id, "room_org_sub");
						
						if($('#type_d').attr("checked")==true)
						{
							if(start_type=="type_s")
								fieldForTypeD();
						}
						else if($('#type_s').attr("checked")==true)
						{
							if(start_type=="type_d")
								fieldForTypeS();
						}
					});
				}
			});
		}
	}
	
	//Проверка категорий на пустоту
	if($(".block_cat").size()!=0)
	{
		$('.block_cat input').each(function() {
			$(this).blur(function() {
				setFlagConsist("formRoomOrg", 0, "room_org_sub");
			});
		});
	}
	
	// Проверка числа-капчи
	if($("#check_number").size()!=0)
	{
		$('#check_number').keyup(function() {
			doCheckNumber();
		});
		
		$('#check_number').blur(function() {
			doCheckNumber();
		});
	}
	
	//-------------------------Удаление скидки в ЛК (предварительный вопрос)-------------------------
	if($(".del_lk").size()!=0)
	{
		$(".del_lk").each(function() {
			$(this).click(function() {
				if(confirm("Вы уверенны, что хотите удалить данную скидку/акцию?"))
				{
					window.location.href = $(this).attr('href');
					return false;
				}
				else
					return false;
			});
		});
	}
	//-----------------------------------------------------------------------------------------------
	
	//--------------------------------Кол-во символов footer_keywords--------------------------------
	$("#footer_keywords").keyup(function() {
		val_footer_keywords = $("#footer_keywords").val();
		length_footer_keywords = val_footer_keywords.length;
		ost_length_footer_keywords = 52 - length_footer_keywords;
		
		if(ost_length_footer_keywords<0)
		{
			val_footer_keywords = val_footer_keywords.substr(0,52);
			$("#footer_keywords").val(val_footer_keywords);
			$("#count_footer_keywords").text(0);
		}
		else
			$("#count_footer_keywords").text(ost_length_footer_keywords);
	});
	//-----------------------------------------------------------------------------------------------
	
	//---------------Подключение блока "Отправить сообщение о модерации/немодерации"-----------------
	
	$("#isMailModeration").click(function() {
		if($(this).attr("checked")==true)
		{
			loadTextModeration();
			$("#textModeration").css('display','block');
		}
		else
		{
			$("#textModeration").text("");
			$("#textModeration").css('display','none');
		}
	});
	
	$("#moderated").click(function() {
		if($("#isMailModeration").attr("checked")==true)
			loadTextModeration();
	});
	
	//-----------------------------------------------------------------------------------------------
	
	//----------------------Активация/деактивация select в зависимости от radio----------------------
	
	if($('.radio_select_list').size()!=0)
	{
		$('.radio_select_list').each(function() {
			if($(this).attr('checked')==false)
				$('#' + $(this).val()).attr('disabled',true);
				
			$(this).click(function() {
				$('#' + $(this).val()).attr('disabled',false);
				this_val = $(this).val();
				
				$('.radio_select_list').each(function() {
					if($(this).val()!=this_val)
					{
						if($(this).attr('checked')==false)
							$('#' + $(this).val()).attr('disabled',true);
					}
				});
			});
		});
	}
	
	//-----------------------------------------------------------------------------------------------
	
	$('#radio_goo0').click(function() {
		start_size = $('.block_goo').size();
									
		$('.block_goo').each(function(n) {
			del_id = start_size - n - 1;
					  
			if($('.block_goo').size()!=1)
				$('.block_goo:eq(' + del_id + ')').remove();
		});
		
		$('#goods1').val("");
		setEnOrDis('goods1', 'textbox', 'textbox_dis', true);
	});
	
	$('#radio_goo1').click(function() {
		setEnOrDis('goods1', 'textbox_dis', 'textbox', false);
	});
	
	$('#radio_bra0').click(function() {
		start_size = $('.block_bra').size();
									
		$('.block_bra').each(function(n) {
			del_id = start_size - n - 1;
									  
			if($('.block_bra').size()!=1)
				$('.block_bra:eq(' + del_id + ')').remove();
		});
		
		$('#brands1').val("");
		setEnOrDis('brands1', 'textbox', 'textbox_dis', true);
	});
	
	$('#radio_bra1').click(function() {
		setEnOrDis('brands1', 'textbox_dis', 'textbox', false);
	});
	
	$('#edit_pass').click(function() {
		$('#message_ep').css('display','none');
		$('#div_edit_p').css('display','block');
		$('#div_edit_p').load('/edit_p/', {user_id:$('#hidd_user_id').val()}, function() {
			$('#old_pass').focus();
		});
		return false;
	});
	
	$('.inp_http').focus(function() {
		if($(this).val()=="")
			$(this).val("http://");	
	});
	
	$('.inp_http').blur(function() {
		if($(this).val()=="http://")
			$(this).val("");	
	});

	if($("#div_tree_tags").size()!=0)
	{
		editStyleTag("relations", "div_tree_tags");
		addStyleTag("div_tree_tags");
	}

	if($('#preview_act').size()!=0)
	{
		$().click(function(e) {
			//Закрытие слоев с подсказками при клике на любой элемент документа
			hideDiv("cat_display", "podsk_word", e);
			hideDiv("bra_display", "podsk_word_b", e);
			hideDiv("goo_display", "podsk_word_g", e);
			
			// Вывод описания для предварительного просмотра
			var previewEditor = FCKeditorAPI.GetInstance("FCKeditor_description"); 
			var previewValue = previewEditor.GetXHTML();

			// Очищение форматирования текста (стилей), вставляемого в FCKeditor
			is_SetHTML = 0;
			
			// Замена стиля вырвнивания текста на выравнивание с помощью align
			if(previewValue.search(/style=("){0,1}('){0,1}(text-align:)( ){0,1}([^"|'|;]+)(;){0,1}("){0,1}('){0,1}/i)!=-1)
			{
				previewValue = previewValue.replace(/style=("){0,1}('){0,1}(text-align:)( ){0,1}([^"|'|;]+)(;){0,1}("){0,1}('){0,1}/gi, 'align="$5"');
				is_SetHTML = 1;
			}
			
			// Удаление из текста, скопированного из Word, выделения ссылки синим цветом
			if(previewValue.search(/<font color=("){0,1}('){0,1}#0000ff("){0,1}('){0,1}>/i)!=-1)
			{
				previewValue = previewValue.replace(/<font color=("){0,1}('){0,1}#0000ff("){0,1}('){0,1}>/gi, "");
				previewValue = previewValue.replace(/<\/font><\/a>/gi, "</a>");
				
				is_SetHTML = 1;
			}
			
			// Очищение style и font
			if(previewValue.search(/style=/i)!=-1 || previewValue.search(/<font/i)!=-1)
			{
				alert("Цвет и стиль шрифта описания скидки/акции будут заменены на стандартные.");
				
				previewValue = previewValue.replace(/style=("){0,1}('){0,1}([^"|']){0,}("){0,1}('){0,1}/gi, "");
				previewValue = previewValue.replace(/<font ([^>]){0,}>/gi, "");
				previewValue = previewValue.replace(/<\/font>/gi, "");
				
				is_SetHTML = 1;
			}

			if(is_SetHTML==1)
				previewEditor.SetHTML(previewValue);

			$(".action-announce").html(previewValue);
			
			// Формирование строки тэгов для предварительного просмотра
			new_text = '<span>Метки:</span> ' + createTagsLink('block_cat') + createTagsLink('block_goo') + createTagsLink('block_bra');
			
			if($('#shops').size()!=0)
			{
				$('#shops option').each(function() {
					if($(this).attr('value')==$('#shops').val())
						shop_name = $(this).attr('textval');
				});
			}
			else
				shop_name = "";
			
			$('.action-tags').html(new_text + "<a href='#' onclick='return false;'>" + shop_name + "</a>");
		});
	}
	
	// Очищение текстовых полей видов товаров и брендов при изменении категории
	if($('.block_cat input').size()!=0)
	{
		$('.block_cat input').each(function() {
			$(this).blur(function() {
				setValNull();
			});
		});
	}

	if($('#div_shops').size()!=0)
		$('#div_shops').load('/basis/sec/shops_p/', {com_id:$('#company_id').val(), selected:$('#hidd_shop_id').val()});

	$('#company_id').change(function() {
		$('#div_shops').load('/basis/sec/shops_p/', {com_id:$(this).val(), selected:0});
	});
	
	//Присваивание мест пользователю в личном кабинете организации
	if($('#div_shops_list').size()!=0)
	{
		$('#div_shops_list a').each(function() {
			$(this).click(function() {
				if($(this).attr('class')=="shop_act")
				{
					$(this).removeClass('shop_act');
					$(this).addClass('shop_deact');
				}
				else
				{
					$(this).removeClass('shop_deact');
					$(this).addClass('shop_act');
				}
				
				$('#shops_user').val('');
				$('#div_shops_list a').each(function() {
					if($(this).attr('class')=="shop_act")
						$('#shops_user').val($('#shops_user').val() + $(this).attr('id') + ";");	
				});
			});
		});
	}
	
	//Использовать адрес компании	
	if($('#block_shop a').size()!=0)
	{
		$('#block_shop a').each(function() {
			comAddress($(this).attr('id'));
		});
	}

	//-----------------------------------------------------------------

	if($(".block_cat").size()!=0)
	{
	    for(i=1;i<=$(".block_cat").size();i++)
	    {
	    	//Подсказки при поиске при событии клика мышки для категорий
	    	getPromptOnClick("category" + i, "i_id", "category_p", 0);
	    	//Подсказки при поиске при событии нажатия клавиши для категорий
	    	getPromptOnKeyup("category" + i, "podsk_word" + i, "a_id", "id" + i, "podsk_in" + i, 0, "category_p", "i_id");
	    }
	}

	if($(".block_goo").size()!=0)
	{
	    for(i=1;i<=$(".block_goo").size();i++)
	    {
	    	//Подсказки при поиске при событии клика мышки для видов товаров
	    	getPromptOnClick("goods" + i, "i_id_g", "goods_p", 1);
	    	//Подсказки при поиске при событии нажатия клавиши для видов товаров
	    	getPromptOnKeyup("goods" + i, "podsk_word_g" + i, "a_id_g", "id_g" + i, "podsk_in_g" + i, 1, "goods_p", "i_id_g");
	    }
	}

	if($(".block_bra").size()!=0)
	{
	    for(i=1;i<=$(".block_bra").size();i++)
	    {
	    	//Подсказки при поиске при событии клика мышки для брендов
	    	getPromptOnClick("brands" + i, "i_id_b", "brands_p", 1);
	    	//Подсказки при поиске при событии нажатия клавиши для брендов
	    	getPromptOnKeyup("brands" + i, "podsk_word_b" + i, "a_id_b", "id_b" + i, "podsk_in_b" + i, 1, "brands_p", "i_id_b");
	    }
	}

	//-----------------------------------------------------------------

	//Добавление новой категории
	$("#add_cat").click(function() {
		$("#block_cat .block_cat:first-child").clone().appendTo($("#block_cat"));
		id = $("#block_cat .block_cat").size();

		var z_index = $("#block_cat .block_cat:last-child div").css("z-index") - id;
		$("#block_cat .block_cat:last-child div").css({"z-index":z_index});

		$("#block_cat .block_cat:last-child #category1").val("");
		$("#block_cat .block_cat:last-child #category1").attr("name", "category[" + id + "]");
		$("#block_cat .block_cat:last-child #category1").attr("i_id", id);
		$("#block_cat .block_cat:last-child #category1").attr("id", "category" + id);

		$("#block_cat .block_cat:last-child #category_p1").attr("id", "category_p" + id);

		//Подсказки при поиске при событии клика мышки
		getPromptOnClick("category" + id, "i_id", "category_p", 0);

		//Подсказки при поиске при событии нажатия клавиши
		getPromptOnKeyup("category" + id, "podsk_word" + id, "a_id", "id" + id, "podsk_in" + id, 0, "category_p", "i_id");
		
		//Очищение текстовых полей видов товаров и брендов при изменении категории
		$('#category' + id).blur(function() {
			setValNull();
		});
	});

	//Добавление нового вида товара
	$("#add_goo").click(function() {
		if($('#radio_goo0').attr('checked')!=true)
		{
			$("#block_goo .block_goo:first-child").clone().appendTo($("#block_goo"));
			id = $("#block_goo .block_goo").size();
	
			var z_index = $("#block_goo .block_goo:last-child div").css("z-index") - id;
			$("#block_goo .block_goo:last-child div").css({"z-index":z_index});
	
			$("#block_goo .block_goo:last-child #goods1").val("");
			$("#block_goo .block_goo:last-child #goods1").attr("name", "goods[" + id + "]");
			$("#block_goo .block_goo:last-child #goods1").attr("i_id_g", id);
			$("#block_goo .block_goo:last-child #goods1").attr("id", "goods" + id);
	
			$("#block_goo .block_goo:last-child #goods_p1").attr("id", "goods_p" + id);
	
			//Подсказки при поиске при событии клика мышки
			getPromptOnClick("goods" + id, "i_id_g", "goods_p", 1);
	
			//Подсказки при поиске при событии нажатия клавиши
			getPromptOnKeyup("goods" + id, "podsk_word_g" + id, "a_id_g", "id_g" + id, "podsk_in_g" + id, 1, "goods_p", "i_id_g");
		}
	});

	//Добавление нового бренда
	$("#add_bra").click(function() {
		if($('#radio_bra0').attr('checked')!=true)
		{
			$("#block_bra .block_bra:first-child").clone().appendTo($("#block_bra"));
			id = $("#block_bra .block_bra").size();
	
			var z_index = $("#block_bra .block_bra:last-child div").css("z-index") - id;
			$("#block_bra .block_bra:last-child div").css({"z-index":z_index});
	
			$("#block_bra .block_bra:last-child #brands1").val("");
			$("#block_bra .block_bra:last-child #brands1").attr("name", "brands[" + id + "]");
			$("#block_bra .block_bra:last-child #brands1").attr("i_id_b", id);
			$("#block_bra .block_bra:last-child #brands1").attr("id", "brands" + id);
	
			$("#block_bra .block_bra:last-child #brands_p1").attr("id", "brands_p" + id);
	
			//Подсказки при поиске при событии клика мышки
			getPromptOnClick("brands" + id, "i_id_b", "brands_p", 1);
	
			//Подсказки при поиске при событии нажатия клавиши
			getPromptOnKeyup("brands" + id, "podsk_word_b" + id, "a_id_b", "id_b" + id, "podsk_in_b" + id, 1, "brands_p", "i_id_b");
		}
	});
	
	//Добавление контактов для места
	$("#add_shop").click(function() {
		$("#block_shop .block_shop:first-child").clone().appendTo($("#block_shop"));
		id = $("#block_shop .block_shop").size();

		$("#block_shop .block_shop:last-child #address1").val("");
		$("#block_shop .block_shop:last-child #address1").attr("name", "address[" + id + "]");
		$("#block_shop .block_shop:last-child #address1").attr("id", "address" + id);
		
		if($('#block_shop .block_shop:last-child #com_address1').attr('class')=="shop_act")
		{
			$('#block_shop .block_shop:last-child #com_address1').removeClass('shop_act');
			$('#block_shop .block_shop:last-child #com_address1').addClass('shop_deact');	
		}
		$("#block_shop .block_shop:last-child #com_address1").attr("addr_id", id);
		$("#block_shop .block_shop:last-child #com_address1").attr("id", "com_address" + id);
		
		$("#block_shop .block_shop:last-child #phones1").val("");
		$("#block_shop .block_shop:last-child #phones1").attr("name", "phones[" + id + "]");
		$("#block_shop .block_shop:last-child #phones1").attr("id", "phones" + id);
		
		if($("#block_shop .block_shop:last-child #addres_id1").size()!=0)
		{
			$("#block_shop .block_shop:last-child #addres_id1").val("0");
			$("#block_shop .block_shop:last-child #addres_id1").attr("name", "addres_id[" + id + "]");
			$("#block_shop .block_shop:last-child #addres_id1").attr("id", "addres_id" + id);
		}
		
		if($("#block_shop .block_shop:last-child #geo_point1").size()!=0)
		{
			$("#block_shop .block_shop:last-child #geo_point1").val("");
			$("#block_shop .block_shop:last-child #geo_point1").attr("name", "geo_point[" + id + "]");
			$("#block_shop .block_shop:last-child #geo_point1").attr("id", "geo_point" + id);
		}
		
		if($("#block_shop .block_shop:last-child #link_2gis1").size()!=0)
		{
			$("#block_shop .block_shop:last-child #link_2gis1").val("");
			$("#block_shop .block_shop:last-child #link_2gis1").attr("name", "link_2gis[" + id + "]");
			$("#block_shop .block_shop:last-child #link_2gis1").attr("id", "link_2gis" + id);
		}
		
		//Использовать адрес компании	
		comAddress('com_address' + id);
	});

	$("#del_cat").click(function() {
		if($("#block_cat .block_cat:last-child input").attr("id")!="category1")
		{
			$("#block_cat .block_cat:last-child").remove();
			
			//Очищение текстовых полей видов товаров и брендов при удалении категории
			setValNull();
		}
	});

	$("#del_goo").click(function() {
		if($('#radio_goo0').attr('checked')!=true)
		{
			if($("#block_goo .block_goo:last-child input").attr("id")!="goods1")
				$("#block_goo .block_goo:last-child").remove();
		}
	});

	$("#del_bra").click(function() {
		if($('#radio_bra0').attr('checked')!=true)
		{
			if($("#block_bra .block_bra:last-child input").attr("id")!="brands1")
				$("#block_bra .block_bra:last-child").remove();
		}
	});
	
	$("#del_shop").click(function() {
		if($("#block_shop .block_shop:last-child input").attr("id")!="phones1")
			$("#block_shop .block_shop:last-child").remove();
	});
	
	//---------------------Предварительный просмотр скидки---------------------
	if($('#preview_act').size() != 0)
	{
		if($('.action-shopInfo').size() != 0)
		{
			$('.action-shopInfo').load('/prev_shop/', {shop_id:$('#hidd_shop_id').val()}, function() {
				// Карты
				getAllYMaps();
			});
		}
		
		if($('.action-logo-m').size() != 0)
			$('.action-logo-m').load('/prev_logo/', {shop_id:$('#hidd_shop_id').val()});
			
		// Оформление текста для типа "Скидка"
		$('#type_d').click(function() {
			$('#inp2').val($('#font_percent_to').attr('val'));
			$('#inp3').val($('#font_percent_from').attr('val'));
			
			if($('#font_percent_from').attr('val') != "" && $('#font_percent_from').attr('val') != 0)
				$('#font_percent_from').html("от " + $('#font_percent_from').attr('val') + "%");
			
			if($('#font_percent_to').attr('val') != "" && $('#font_percent_to').attr('val') != 0)
				$('#font_percent_to').html("до " + $('#font_percent_to').attr('val') + "%");
			
			if($('#inp2').val() == 0)
				$(".action-type").html("0%");
			else
				$(".action-type").html($('#inp2').val() + "%");
				
			if($('.action-percent').css('display') == "none")
				$('.action-percent').css('display','block');
				
			fieldForTypeD();
		});
		
		// Оформление текста для типа "Акция"
		$('#type_s').click(function() {
			$(".action-type").html("АКЦИЯ!");
			$('#font_percent_to').html("");
			$('#font_percent_from').html("");
			
			if($('.action-percent').css('display') == "block")
				$('.action-percent').css('display','none');
				
			fieldForTypeS();
		});
		
		// Название
		$('#inp1').blur(function() {
			$("#lookAhead-name").html($(this).val());
		});
		
		// Процент от
		$('#inp3').blur(function() {
			if($(this).val() != "")
				$('#font_percent_from').html("от " + $(this).val() + "%");
			else
				$('#font_percent_from').html("");
				
			$('#font_percent_from').attr('val', $(this).val());
		});
		
		// Процент до
		$('#inp2').blur(function() {
			if($(this).val() != "")
			{
				$('#font_percent_to').html("до " + $(this).val() + "%");
				$(".action-type").html($(this).val() + "%");
			}
			else
			{
				$('#font_percent_to').html("");
				$(".action-type").html("0%");
			}
			
			$('#font_percent_to').attr('val', $(this).val());
		});
		
		// Теги
		if($('.action-tags a').size() != 0)
		{
			$('.action-tags a').each(function() {
				$(this).click(function() {
					return false;
				});
			});
		}
	}
	
	// Оформление даты или подгрузка магазина (в зависимости от select)
	if($('#preview_act select').size()!=0)
	{
		$('#preview_act select').each(function() {
			$(this).change(function() {
				if($(this).attr('id') != 'shops')
				{		
					$('#font_date_from').text("c " + $('#days1').val() + '.' + $('#months1').val() + '.' + $('#years1').val());
					$('#font_date_to').text("по " + $('#days2').val() + '.' + $('#months2').val() + '.' + $('#years2').val());
				}
				else
				{
					$('.action-shopInfo').load('/prev_shop/', {shop_id:$(this).val()}, function() {
						// Карты
						getAllYMaps();
					});
					$('.action-logo-m').load('/prev_logo/', {shop_id:$(this).val()});
				}
			});
		});
	}
	//-------------------------------------------------------------------------
	
	//--------------------------Подгрузка скидок/акций-------------------------
	
	// Для ЛК
	if($('#list_actions_on_room').size()!=0)
	{
		hightLight("list_actions_on_room");
		//loadActionsByTags();
		loadPageOfRedact();
		//openConcreteAction("list_actions_on_room"); перенесено во внутрь hightLight();
	}
	
	if($('#list_actions').size()!=0)
	{
		hightLight(0);
		loadActionsByTags();
		paging();
	}
	
	//-------------------------------------------------------------------------
	
	//--------------------Подгрузка новостей / постов блога--------------------
	
	// По клику на страницы
	paging_objects();
	
	//-------------------------------------------------------------------------

	// Карты
	$(".shop_address").each(function() {
		$(this).click(function() {
			if($(this).attr("type")=="ya")
				getYMaps($(this));
			else if($(this).attr("type")=="2gis")
				window.open($(this).attr('link2gis'));
				
			return false;
		});
	});
	
	$(".addres_ya").each(function() {
		$(this).click(function() {
			getYMaps($(this));
			
			return false;
		});
	});
});
