var prev_comment = 0;

//Функция сообщения о добавлении в корзину
function gotocart(text){
	var dialogbox = document.getElementById('dialog_box');
	
	if(text == 'yes'){
		dialogbox.style.visibility = "hidden";
		location.href = "http://www.matrasmax.ru/shop/cart/";
	}
	else
		dialogbox.style.visibility = "hidden";
}

function dialog(){
	var dialogbox = document.getElementById('dialog_box');
	dialogbox.style.visibility = "visible";		//Показываем сообщение о том, что товар добавлен в корзину	
}


function formsubmit(){
	var f = document.forms.TForm;
	f.submit();
}

function sendform(){
	var f = document.getElementById('TForm');
	if (!f) formsubmit();
	else f.submit();
}

// Ответ на комментарий
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')
		{
			html = responseJS.cart;

			var little_cart = document.getElementById('little_cart');
			
			if (little_cart)
			{
				little_cart.innerHTML = html;
				dialog();
			}
			else
			{
				alert('Ошибка! Краткая корзина не найдена');
			}
		}
	}
}

function AddIntoCart(shop_path, item_id, item_count, is_bonus, color)
{
	//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 + '&bonus=' + is_bonus;
	// Отправляем запрос backend-у
	//sendRequest(cmsrequest, 'get', callbackfunction_AddIntoCart);
	//return false;

        cmsrequest = shop_path + 'cart_cl/?action=add&item_id=' + item_id + '&count=' + item_count + '&bonus=' + is_bonus;
        if (color) cmsrequest += '&color=' + color.replace(' ','+');
        return show_cart(cmsrequest);
}

// Установка или снятие всех флажков для checkbox'ов элементов.
function SelectAllItems(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';
}

function ShowTextWindow(title, text, w, h) {
  var popup = window.open('', "popup", "menubar=no, width="+w+", height="+h+", toolbar=no, status=no, scrollbars=1");
  popup.document.open();
  popup.document.writeln("<html><head><title>"+title+"</title><meta http-equiv=\"Content-Language\" content=\"ru\"/><meta content=\"text/html; charset=windows-1251\" http-equiv=\"Content-Type\"/></head><body style=\"color: #333; font-family: Arial; font-size: 78%;\">"+text+"</body></html>");
  popup.focus();
}
