//Проверка типа браузера и размеров экрана
var ie=ns=op=false;

if (navigator.userAgent.indexOf ("Opera") != -1) {op=true;}
else if (navigator.userAgent.indexOf ("MSIE") != -1) {ie=true;}
else if (navigator.userAgent.indexOf ("Netscape") != -1 ||
         navigator.userAgent.indexOf ("Gecko") != -1 ||
         navigator.userAgent.indexOf ("Mozilla") != -1 ||
         navigator.userAgent.indexOf ("Firefox") != -1) {ns=true;}

function getDocumentWidth() {
	return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollWidth : document.documentElement.scrollWidth, getViewportWidth());
}

function getViewportWidth() {
	return ((document.compatMode || ie || ns) && !op) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth : (document.parentWindow || document.defaultView).innerWidth;
}

function getDocumentHeight() {
	return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, getViewportHeight());
}
 
function getViewportHeight() {
	return ((document.compatMode || ie || ns) && !op) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}

function deletePopUp(popUpId) {
	var container = document.getElementById(popUpId);
	document.body.removeChild(container);
}

function createPopUp(mouseEvent, width, height, message) {
    var posx = 0;
    var posy = 0;
    if (!mouseEvent) var mouseEvent = window.event;
    if (mouseEvent.pageX || mouseEvent.pageY)
    {
        posx = mouseEvent.pageX;
        posy = mouseEvent.pageY;
    }
    else if (mouseEvent.clientX || mouseEvent.clientY)
    {
        posx = mouseEvent.clientX + document.body.scrollLeft;
        posy = mouseEvent.clientY + document.body.scrollTop;
    }
	
	var container = document.createElement('div');
	container.id = 'popupContainer';
	container.style.position = 'absolute';
	container.style.border = '1px solid #AAAAAA';
	container.style.backgroundColor = '#CCCCCC';
	container.style.width = parseInt(width) + 'px';
	container.style.height = parseInt(height) + 'px';
	container.style.top = posy + 'px';
	container.style.left = parseInt(getViewportWidth()/2 - width/2) + 'px';
	container.innerHTML = message;
	document.body.appendChild(container);
	setInterval("deletePopUp('popupContainer')", 3000);
}

function showCartPopUp() {
	alert('Товар добавлен в корзину\n     Спасибо!');
//	setTimeout("createPopUp(event, 100, 50, '<p>Товар дбавлен в корзину.</p><p>Спасибо!</p>');", 1000);
}


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')
		{
			html = responseJS.cart;

			var little_cart = document.getElementById('little_cart');
			
			if (little_cart)
			{
				little_cart.innerHTML = html;
				showCartPopUp();
			}
			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;
}

// Установка или снятие всех флажков для 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 showMovieWin(extension, title, src, width, height)
{
	window.open('/_baner/movie.php?extension='+extension+'&title='+title+'&src='+src+'&width='+width+'&height='+(extension == 'wmv' ? height+70 : height), '_blank', 'width='+width+', height='+(extension == 'wmv' ? height+70 : height)+', left=200, top=300');
}

