function showsubmenu(id){
	submenu=document.getElementById('s'+id);
	for(i=1;i<=5;i++){
		if(i==id){
			submenu.style.display="block";
		} else{
			document.getElementById('s'+i).style.display="none";
		}
	}
}

function SetActiveTab(tab)
{
	var listElement = tab.parentNode.parentNode;
	var arTabs = listElement.getElementsByTagName("LI");

	//Hide
	for (var i = 0; i < arTabs.length; i++)
	{
		arTabs[i].className = "";
		var tabBody = document.getElementById(arTabs[i].id + "-body");
		if (tabBody)
			tabBody.style.display = "none";
	}

	//Show
	var tabBody = document.getElementById(tab.parentNode.id + "-body");
	if (tabBody)
	{
		tab.parentNode.className = "active";
		tab.blur();
		tabBody.style.display = "block";
	}
}

function SetPrintCSS(isPrint)
{
	var link;

	if (document.getElementsByTagName)
		link = document.getElementsByTagName('link');
	else if (document.all)
		link = document.all.tags('link');
	else
		return;

	for (var index=0; index < link.length; index++)
	{
		if (link[index].title != 'print')
			continue;

		if (isPrint)
		{
			link[index].disabled = false;
			link[index].rel = "stylesheet";
		}
		else
		{
			link[index].disabled = true;
			link[index].rel = "alternate stylesheet";
		}
	}
}

var jsPublicForms =
{
	SetFieldValue: function(id, value)
	{
		var field = document.getElementById(id);
		if(field)
		{
			field.value = value;
		}
	}
}

var jsPublicFilters =
{
	SetCookie: function(Name, Value, ArrName)
	{
		if(ArrName)
			document.cookie = ArrName + "[" + Name + "]=" + Value + "; path=/;";
		else
			document.cookie = Name + "=" + Value + "; path=/;";
	},
	
	ShowHide: function(id, action)
	{
		var filter = document.getElementById(id);
		if(filter)
		{
			if(filter.style.display == "none" || "show" == action)
			{
				filter.style.display = "block";
				jsPublicFilters.SetCookie(id,"on","PublicFilters");
			}
			else
			{
				filter.style.display = "none";
				jsPublicFilters.SetCookie(id,"off","PublicFilters");
			}
		}
	},
	
	GetCookie: function (Name, ArrName) 
	{
		if(ArrName)
			var prefix = ArrName + "[" + Name + "]=";
		else
			var prefix = Name + "=";
		var cookieStartIndex = document.cookie.indexOf(prefix);
		if (cookieStartIndex == -1) 
			return null;
		var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
		if (cookieEndIndex == -1) 
			cookieEndIndex = document.cookie.length;
		return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
	}
}

var jsPublicTabController =
{
	SetTabCookieId: function(TabSec, TabId)
	{
		document.cookie = "BxTabs[" + TabSec + "]=" + TabId + "; path=/;";
	},
	
	SetTabCookieIdUnload: function()
	{
		//no more then 2 tablists
		for(i=0;i<2;i++)
		{
			var tab_ul = document.getElementById('tab-list-id'+i);
			if(tab_ul)
			{
				tab_li = tab_ul.getElementsByTagName('LI');
				for(j=0;j<tab_li.length;j++)
				{
					if(tab_li[j].className == 'active')
					{
						tab_a = tab_li[j].getElementsByTagName('A');
						tab_a[0].onclick();
					}
				}
			}
			else
				break;
		}
	},

	TabToTabAnchor: function(TabId)
	{
		tab = document.getElementById(TabId);
		if(tab)
		{
			tab_a = tab.getElementsByTagName('A');
			tab_a[0].onclick();
			SetActiveTab(tab_a[0]);
		}
	}
}

window.onbeforeunload = jsPublicTabController.SetTabCookieIdUnload;

//change load window
if (window.jsAjaxUtil)
{
	// show ajax visuality
	jsAjaxUtil.ShowLocalWaitWindow = function (TID, cont, bShadow)
	{
		if (typeof cont == 'string' || typeof cont == 'object' && cont.constructor == String)
			var obContainerNode = document.getElementById(cont);
		else
			var obContainerNode = cont;
		
		if (obContainerNode.getBoundingClientRect)
		{
			var obRect = obContainerNode.getBoundingClientRect();
			var obWndSize = jsAjaxUtil.GetWindowSize();

			var arContainerPos = {
				left: obRect.left + obWndSize.scrollLeft, 
				top: obRect.top + obWndSize.scrollTop, 
				right: obRect.right + obWndSize.scrollLeft, 
				bottom: obRect.bottom + obWndSize.scrollTop
			};
		}
		else
			var arContainerPos = jsAjaxUtil.GetRealPos(obContainerNode);
		
		var container_id = obContainerNode.id;
		
		if (!arContainerPos) return;
		
		if (null == bShadow) bShadow = true;
		
		if (bShadow)
		{
			var obWaitShadow = document.body.appendChild(document.createElement('DIV'));
			obWaitShadow.id = 'waitshadow_' + container_id + '_' + TID;
			obWaitShadow.className = 'waitwindowlocalshadow';
			obWaitShadow.style.top = (arContainerPos.top - 5) + 'px';
			obWaitShadow.style.left = (arContainerPos.left - 5) + 'px';
			obWaitShadow.style.height = (arContainerPos.bottom - arContainerPos.top + 10) + 'px';
			obWaitShadow.style.width = (arContainerPos.right - arContainerPos.left + 10) + 'px';
		}
		
		var obWaitMessage = document.body.appendChild(document.createElement('DIV'));
		obWaitMessage.id = 'wait_' + container_id + '_' + TID;
		obWaitMessage.className = 'waitwindow';
		
		var div_top = arContainerPos.top + 5;
		if (div_top < document.body.scrollTop) div_top = document.body.scrollTop + 5;
		
		obWaitMessage.style.top = div_top + 'px';
		obWaitMessage.style.left = (arContainerPos.left + 5) + 'px';
		obWaitMessage.innerHTML = 'Загрузка...';
		
		if(jsAjaxUtil.IsIE())
		{
			var frame = document.createElement("IFRAME");
			frame.src = "javascript:''";
			frame.id = 'waitframe_' + container_id + '_' + TID;
			frame.className = "waitwindow";
			frame.style.width = obWaitMessage.offsetWidth + "px";
			frame.style.height = obWaitMessage.offsetHeight + "px";
			frame.style.left = obWaitMessage.style.left;
			frame.style.top = obWaitMessage.style.top;
			document.body.appendChild(frame);
		}
		
		function __Close(e)
		{
			if (!e) e = window.event
			if (!e) return;
			if (e.keyCode == 27)
			{
				jsAjaxUtil.CloseLocalWaitWindow(TID, cont);
				jsEvent.removeEvent(document, 'keypress', __Close);
			}
		}
		
		jsEvent.addEvent(document, 'keypress', __Close);
	}
}



if (document.location.hash == '#print')
	SetPrintCSS(true); 

if (document.location.hash.indexOf("#tab-") != -1)
{
	var selectedTabID = document.location.hash.substr(5,document.location.hash.length-10);
	window.onload = function() 
	{
		var tab = document.getElementById("tab-" + selectedTabID);

		if (tab && tab.childNodes[0])
			SetActiveTab(tab.childNodes[0]);
	};
}
