var prev_comment = 0;

// ����� �� �����������
function cr(comment_id)
{
	if (prev_comment && prev_comment != comment_id)
	{
		document.getElementById(prev_comment).style.display = 'none';
	}

	var div = document.getElementById(comment_id);
	
	if (div.style.display != 'block')
	{
		div.style.display = 'block';
	}
	else
	{
		div.style.display = 'none';
	}

	prev_comment = comment_id;
}

var temp_ChildId = '';
var temp_CurrenElementId = '';
var menu_timeout_id = 0;
var filter_timeout_id = 0;

// ���������� ��������� ���� �� ����
function TopMenuOver(CurrenElementId, ChildId)
{
	clearTimeout(menu_timeout_id);

	if (temp_CurrenElementId != ''
	&& temp_CurrenElementId != CurrenElementId)
	{
		var oTemp_ChildId = document.getElementById(temp_ChildId);

		if (oTemp_ChildId)
		{
			oTemp_ChildId.style.display = "none";
		}
	}

	temp_ChildId = ChildId;
	temp_CurrenElementId = CurrenElementId;

	if (CurrenElementId == undefined)
	{
		return false;
	}

	if (ChildId != '')
	{
		var oChildId = document.getElementById(ChildId);

		if (oChildId)
		{
			oChildId.style.display = "block";
			//oChildId.style.opacity = 0.4;
			//	oChildId.style.filter = 'alpha(opacity=100, style=1, finishopacity=60)';
			//oChildId.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0, style=0)";
		}
	}
}

// ���������� �������� ���� � ����
function TopMenuOut(CurrenElementId, ChildId)
{
	if (CurrenElementId == undefined)
	{
		return false;
	}

	if (ChildId != '')
	{
		var oChildId = document.getElementById(ChildId);
		if (oChildId)
		{
			menu_timeout_id = setTimeout(function (){oChildId.style.display = "none"}, 300);
		}
	}
}

// ������� ��������� ������ ��� AddIntoCart
function callbackfunction_AddIntoCart(responseJS)
{
	// ��������� ������
	sended_request = false;
	
	if (typeof responseJS != 'undefined')
	{
		// ������.
		if (typeof responseJS.cart != 'undefined')
		{
			var little_cart = document.getElementById('little_cart');
			
			if (little_cart)
			{
				// �������� ������� SPAN ��� IE, � ������� �������� ����� + ������.
				// ���� ����� <script> �� ����� ������, ��������� IE �� ������ SCRIPT
				var span = document.createElement("span");
				span.style.display = 'none';
				span.innerHTML = "Stupid IE. " + responseJS.cart;

				runScripts(span.getElementsByTagName('SCRIPT'));
				
				little_cart.innerHTML = responseJS.cart;
			}
			else
			{
				alert('������! ������� ������� �� �������');
			}
		}
	}
}

function AddIntoCart(shop_path, item_id, item_count)
{
	//location.href = shop_path + 'cart/?ajax_add_item_id=' + item_id + '&count=' + item_count;
	cmsrequest = shop_path + 'cart/?ajax_add_item_id=' + item_id + '&count=' + item_count;
	
	// ���������� ������ backend-�
	sendRequest(cmsrequest, 'get', callbackfunction_AddIntoCart);
	
	return false;
}

// ������� ��������� ������ ��� CheckBlogUrl
function callbackfunction_CheckBlogUrl(responseJS)
{
	// ��������� ������
	sended_request = false;

	if (typeof responseJS != 'undefined')
	{
		// ������.
		if (typeof responseJS.check_url_result != 'undefined')
		{
			var check_url = document.getElementById('check_url');

			if (responseJS.check_url_result == 0)
			{
				check_url.className = 'error';
				html = '����� �����.';
			}
			else
			{
				check_url.className = 'green';
				html = '����� ��������.';
			}

			if (check_url)
			{
				check_url.innerHTML = html;
			}
			else
			{
				alert('������! ���� ��� ������ ����������� ������� �� ������');
			}
		}
	}
}

function CheckBlogUrl(blog_path, blog_url, parent_id, id)
{
	cmsrequest = blog_path + '?ajax_check_blog_url=' + blog_url + '&group_parent_id=' + parent_id + '&group_id=' + id;

	var check_url = document.getElementById('check_url');

	if (check_url)
	{
		check_url.innerHTML = '<img src="/hostcmsfiles/images/ajax_loader_mini.gif"/>';
	}

	// ���������� ������ backend-�
	sendBackgroundRequest(cmsrequest, 'get', callbackfunction_CheckBlogUrl);	

	return false;
}

// ��������� ��� ������ ���� ������� ��� checkbox'�� ���������.
function SelectAllItemsByPrefix(ASelect, prefix)
{
	element_array = document.getElementsByTagName("input");
	if (element_array.length > 0)
	{
		for (var i = 0; i < element_array.length; i++)
		{
			if (element_array[i].name.search(prefix) != -1)
			{
				// ������������� checked
				element_array[i].checked = ASelect;
			}
		}

	}
}

if (document.images)
{	
    var img = new Object();

    img["tl_angle_pull_down"] = new Image();	
    img["tl_angle_pull_down"].src = '/images/tl_angle_pull_down.png';

    img["tr_angle_pull_down"] = new Image();	
    img["tr_angle_pull_down"].src = '/images/tr_angle_pull_down.png';

    img["bl_angle_pull_down"] = new Image();	
    img["bl_angle_pull_down"].src = '/images/bl_angle_pull_down.png';

    img["br_angle_pull_down"] = new Image();	
    img["br_angle_pull_down"].src = '/images/br_angle_pull_down.png';
    
    img["ajax_loader_min"] = new Image();	
    img["ajax_loader_min"].src = '/hostcmsfiles/images/ajax_loader_mini.gif';

}



$(document).ready(function() {
	$("ul.dropdown li").hover(function() {
		$(this).addClass("hover");
		$('> .dir',this).addClass("open");
		$('ul:first',this).css('visibility', 'visible');
	}, function() {
		$(this).removeClass("hover");
		$('.open',this).removeClass("open");
		$('ul:first',this).css('visibility', 'hidden');
	});

});
