/*
MSV 09.10.2006
Java-скрипты используемые в основном отображающем слое
*/

function auto_tag(tag_name) {
	if (window.attachEvent) {
		window.attachEvent("onload", function() {
			var el = document.getElementsByTagName(tag_name);
			set_auto_tag(el);
		});
	}
}

function set_auto_tag (el) {
	for (var i=0; i<el.length; i++) {
	    if (el[i].target == '_blank'){
			el[i].className+=" onw";
	    }
	}
} 

//auto_tag("A");

isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isMSIE=document.all && document.all.item //Microsoft Internet Explorer 4+
isNetscape4=document.layers //Netscape 4.*
isOpera=window.opera //Opera
isOpera5=isOpera && isDOM //Opera 5+
isMSIE5=isDOM && isMSIE && !isOpera //MSIE 5+
isMozilla=isNetscape6=isDOM && !isMSIE && !isOpera

var obj;

function getLayer(layerName, parentLayerName)
{
    if (isDOM)
    {
        return document.getElementById(layerName);
    }
    if (isMSIE)
    {
        return document.all[layerName];
    }
    if (isNetscape4)
    {
        return eval('document.layers[layerName]');
    }
    return false;
}


function showTooltip(e, what, xOffset, yOffset)
{
    mousex = e.clientX;
    mousey = e.clientY;
    pagexoff = 0;
    pageyoff = 0;

    xOffset=xOffset?xOffset:0;
    yOffset=yOffset?yOffset:0;

    if (isMSIE5)
    {
        pagexoff = document.body.scrollLeft;
        pageyoff = document.body.scrollTop;
    }
    else
    {
        pagexoff = window.pageXOffset;
        pageyoff = window.pageYOffset;
    }
    if (getLayer(what))
    {
        if (isNetscape4)
            obj = getLayer(what);
        else
            obj = getLayer(what).style;

        if (obj)
        {
            leftoff = mousex - pagexoff;
            obj.left = (mousex + pagexoff)+xOffset;

            topoff = mousey - pageyoff;
            obj.top = (mousey + pageyoff)+yOffset;


            if (isNetscape4)
                obj.visibility = 'show';
            else
                obj.visibility = 'visible';
        }
    }
    return true;
}

function hideTooltip()
{
    if (obj)
    {
        if (isNetscape4)
            obj.visibility = 'hide';
        else
            obj.visibility = 'hidden';
    }
    return true;
}

function hideTooltip(what)
{
    if (getLayer(what))
    {
        if (isNetscape4)
            obj = getLayer(what);
        else
            obj = getLayer(what).style;

        if (obj)
        {
            if (isNetscape4)
                obj.visibility = 'hide';
            else
                obj.visibility = 'hidden';
        }
    }
    return true;
}

function p(x, y, z) {
	for (a = 0; a < arguments.length; a++) {
		arguments[a] = arguments[a].split('');
		arguments[a] = arguments[a].reverse();
		arguments[a] = arguments[a].join('');
	}
	document.location.href = "mailto:" + x + "@" + y + "." + z;
}
function p_u(x, y, z) {
	c = arguments;
	for (b = 0; b < c.length; b++) {
        if (b == 3) continue;
		c[b] = c[b].split(',');
		c[b] = c[b].reverse();
		for (a = 0; a < c[b].length; a++)
			c[b][a] = String.fromCharCode(c[b][a] - 10);
		c[b] = c[b].join('');
	}
	document.location.href = "mailto:" + c[0] + "@" + c[1] + "." + c[2] + "?subject=" + c[3] + "";

}

var win = null;
function nwin(mypage,myname,w,h,scroll){LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;TopPosition = (screen.height) ? (screen.height-h)/2 : 0;settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}

//Метод срабатывает при навигации курсора мышки поверх табуляции
function onTabHeaderOver(tabGroupId, selectedTabId, enabledStyle) {
	element = document.getElementById("tabs" + tabGroupId + "head" + selectedTabId);
	if (element.className == enabledStyle) {
		element.style.cursor = "default";
	} else {
		element.style.cursor = "hand";
	}
}
//Метод устанавливает текущую таб
function selectTab(tabGroupId, tabGroupSize, selectedTabId, enabledStyle, disabledStyle, errorStyle, tabKeyName, tabKeyValue) {
	// first unselect all tab in the tag groups.
	for (i=0;i<tabGroupSize;i++) {
		element = document.getElementById("tabs" + tabGroupId + "head" + i);
		if (element.classNameErrorStdLayout) {
			element.className = errorStyle;
			element.style.color = "";
		} else if (element.className == enabledStyle) {
			element.className = disabledStyle;
			element.style.color = "";
		} else if (element.className == errorStyle) {
			// do nothing more
		}

		document.getElementById("tabs" + tabGroupId + "tab" + i).style.display = "none";
	}
	if (document.getElementById("tabs" + tabGroupId + "head" + selectedTabId).className==errorStyle) {
		document.getElementById("tabs" + tabGroupId + "head" + selectedTabId).classNameErrorStdLayout = new Object();
	}
	document.getElementById("tabs" + tabGroupId + "head" + selectedTabId).className = enabledStyle;
	document.getElementById("tabs" + tabGroupId + "head" + selectedTabId).style.cursor = "default";
	document.getElementById("tabs" + tabGroupId + "tab" + selectedTabId).style.display = "";

	// update a cookie holding the name of the selected tab.
	if (tabKeyName!=null) {
//alert("tabKeyName="+tabKeyName+" tabKeyValue="+tabKeyValue);
		setTabCookie(tabKeyName, tabKeyValue);
	}
}

//Метот устанавливает печенье табуляции пользователю
function setTabCookie(name, value) {
	var cookie = getMenuCookie("selectedTab", "");
//alert("setTabCookie step1 cookie="+cookie);
	var start;
	var end;
	if (cookie=="undefined") cookie = "";
	if (cookie==null) cookie = "";
	if (cookie=="???") cookie = "";
	start = cookie.indexOf(name + "=");
	if (start==-1) {
		cookie = cookie + name + "=" + value + ";"
	} else {
		end = cookie.substring(start).indexOf(";");
		cookie = cookie.substring(0, start) + name + "=" + value + cookie.substring(start+end);
	}
//alert("setTabCookie step2 cookie="+cookie);
	setMenuCookie("selectedTab", cookie);
}

//Метод возвращает печенье пользователя
function getMenuCookie(name, suffix) {
//alert("document.cookie="+document.cookie);
//alert("getMenuCookie step1 name="+name+" suffix="+suffix);
	if (suffix==null) {
		suffix = "MENU";
	}
	var prefix = name + suffix + "=";
//alert("getMenuCookie prefix="+prefix);
	var cookieStartIndex = document.cookie.indexOf(prefix);
//alert("getMenuCookie cookieStartIndex="+cookieStartIndex);
	if (cookieStartIndex == -1) return "???";
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
//alert("getMenuCookie cookieEndIndex="+cookieEndIndex	);
	if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

//Метод устанавливает печенье  пользователю
function setMenuCookie(name, state) {
	if (name.indexOf("treeView")!=-1) {
		if (state=="show") {
			var cookie = getMenuCookie("treeView", "");
			if (cookie=="???") cookie = "_";
			cookie = cookie + name + "_";
			document.cookie = "treeView=" + escape(cookie);

		} else {
			var cookie = getMenuCookie("treeView", "");
			var begin = cookie.indexOf("_" + name + "_");
			if (cookie.length > begin + name.length + 2) {
				cookie = cookie.substring(0, begin+1) + cookie.substring(begin + 2 + name.length);
			} else {
				cookie = cookie.substring(0, begin+1);
			}
			document.cookie = "treeView=" + escape(cookie);
		}
	}
	if (name.indexOf("selectedTab")!=-1) {
//alert("cp="+getCookieContextPath());
		document.cookie = "selectedTab=" + escape(state) + getCookieContextPath();
//alert("document.cookie="+document.cookie);
	} else {
		var cookie = name + "MENU=" + escape(state);
		document.cookie = cookie;
	}
}

//Метод возвращает
function getCookieContextPath() {
	if (window.contextPath) {
		return "; path=" + window.contextPath;
	} else {
		return "";
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage()
{ //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
   	if ((x=MM_findObj(a[i]))!=null)
	{
		document.MM_sr[j++]=x;
		if(!x.oSrc) x.oSrc=x.src;
		x.src=a[i+2];
	}
}