

var ind=Array();

function add_Ingrid(id,price_code,fl,ssilce,ssilca_in,obj,img){
	img=document.getElementById(img);
	if(ssilca_in!=null)
		ssilca_in=document.getElementById(ssilca_in);
	tbl=document.getElementById("ingred_"+id+'_'+price_code);
	if(tbl!=null){
		if(fl==0 && ind[id][price_code]>0){
			if(ssilce!=null){
				ssilce.style.display='none';
				ssilca_in.style.display='block';
			}
			for(i=0;i<150;i++){
				var oRow = document.getElementById(id+'_'+price_code+'_'+i);
				if(oRow!=null){
					s = oRow.rowIndex;
					tbl.deleteRow(s);
					ind[id][price_code]--;
				}
			}
		}else{
			if(ssilce!=null){
				ssilce.style.display='none';
				ssilca_in.style.display='block';
			}
			if(obj!=null){
				var obj_o=obj;
				while (obj.tagName != 'TR') obj = obj.parentNode;
				var oRow = obj.parentNode.insertBefore(obj.cloneNode(true),obj);
				obj_o.style.display="none";
				img.style.display="inline";

				obj_o.src="/img/minus.gif";
				name= id+'_'+price_code+'_'+ind[id][price_code];
				obj_o.onClick="ingrid_Delete("+id+",'"+price_code+"','"+name+"');";
			}else
				ind[id][price_code]++;
		}
	}
}
function ingrid_Delete(id,price_code,tr)
{
	while (tr.tagName != 'TR') tr = tr.parentNode;
	if(tr!=null){
		var i = tr.rowIndex;
		tbl = document.getElementById("ingred_"+id+'_'+price_code);
		if(tbl!=null){
			tbl.deleteRow(i);
			ind[id][price_code]--;
		}
	}
}
function submit_pizza(act,form){
	if(form!=null){
/*
		te=document.getElementById(act_c);
		t=te.value;
				te.value=t;
*/
		form.submit();
	}

}

// Кроссбраузерная функция получения размеров экрана,
// используется в функции ShowLoadingScreen.
function getPageSize2()
{
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight)
	{
		// all except Explorer
		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth;
		}
		else
		{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{
		pageWidth = xScroll;
	}
	else
	{
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize;
}

// Получение информации о позиции скрола
function getScrollXY2()
{
	var scrOfX = 0, scrOfY = 0;

	if (typeof(window.pageYOffset ) == 'number' )
	{
		//Netscape
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop))
	{
		//DOM
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
	{
		//IE6
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}

	return [ scrOfX, scrOfY ];
}

//Отображение экрана загрузки AJAX.
//Для корректной работы необходимо, чтобы на форме присутствовал
function showLoader()
{
	var fade_div = document.getElementById('id_admin_forms_fade');

	if (fade_div == null)
	{
		// Создаем div
		var fade_div = document.createElement("div");
		var body = document.getElementsByTagName("body")[0];
		body.appendChild(fade_div);

		fade_div.id = "id_admin_forms_fade";

		fade_div.style.zIndex = 999;

		fade_div.className = "shadowed";

		fade_div.style.position = 'absolute';
		fade_div.style.left = '50%';
		fade_div.style.top = '50%';

		var fade_div_img = document.createElement("img");
		fade_div_img.id = 'id_fade_div_img';
		fade_div_img.src = '/img/fullsize-loading-spinner.gif';
		fade_div.appendChild(fade_div_img);


		// получаем ширину выпадающего блока и устанавливаем её для верхней и нижней границы
		groupChildElements = fade_div.children;

		if (groupChildElements != undefined)
		{
			for (i = 0; i < groupChildElements.length; i++)
			{
				if(groupChildElements[i].className == 'b' | groupChildElements[i].className == 't')
				{
					groupChildElements[i].style.width = fade_div.clientWidth + 'px';
				}

				if(groupChildElements[i].className == 'r' | groupChildElements[i].className == 'l')
				{
					groupChildElements[i].style.height = fade_div.clientHeight + 'px';
				}
			}
		}

		fade_div.style.display = 'none';
	}

	// Отображаем div
	fade_div.style.display = 'block';

	var arrayPageSize = getPageSize2();

	// 0 - pageWidth, 1 - pageHeight, 2 - windowWidth, 3 - windowHeight
	var arrayPageSize = getPageSize2();

	// 0 - scrOfX, 1 - scrOfY
	var arrayScrollXY = getScrollXY2();

	// Отображаем до определения размеров div-а
	var clientHeight = fade_div.clientHeight;
	fade_div.style.top = ((arrayPageSize[3] - clientHeight) / 2 + arrayScrollXY[1]) + 'px';

	var clientWidth = fade_div.clientWidth;
	fade_div.style.left = ((arrayPageSize[2] - clientWidth) / 2 + arrayScrollXY[0]) + 40 + 'px';
}

//Скрытие экрана загрузки AJAX.
function hideLoader()
{
	// Убераем затемнение.
	fade_div = document.getElementById('id_admin_forms_fade');

	if (typeof fade_div != 'undefined')
	{
		fade_div.style.display = "none";
	}
}


function AddIntoCart(shop_path, item_id, item_count)
{	showLoader();
	$.get(shop_path + 'cart/', {ajax_add_item_id: item_id, count: item_count}, function(data){
		$('#little_cart').html(data);
		hideLoader();
		$('#little_cart .tooltip_description').tooltip();
	});
	return false;
}