dom=(document.getElementById)? true : false;
nn4=(document.layers)? true : false;
ie4=(!dom && document.all)? true : false;
opera = (window.opera)? true : false;

var show_style = (nn4) ? 'show' : 'visible';
var hide_style = (nn4) ? 'hide' : 'hidden';

function get_layer(id) {
	return (dom) ? document.getElementById(id).style : ((ie4) ? document.all[id].style : ((nn4) ? document.layers[id] : null));
}

var budilnik=false;
function doMouseOut(){
	budilnik = setTimeout('repair()', 1000);
}

function repair() {
	if(seclevid) showMenu(seclevid);
	if(threelevid) showSubMenu(threelevid);
}

function doMouseOver(){
	if(budilnik)	clearTimeout(budilnik);
}

function showMenu(indx){
	if (!detect_array_element('menu'+indx,menuDivId))	return false;
	hideSub();
	hideSubSub();

	doMouseOver()
	detect_submenu_position(indx);
	layer = get_layer('menu'+indx);
	showLayer(layer);
}

//	показываем третий уровень
function showSubMenu(indx){
	if (!detect_array_element('sb'+indx,menuSubDivId)) return false;

	hideSubSub();
	doMouseOver()
	detect_subsubmenu_position(indx);
	layer = get_layer('sb'+indx);
	showLayer(layer);
}

function showLayer(layer){
	if(ie4){ 
		layer.pixelTop = positionY; 
//		layer.pixelLeft = positionX; 
		}
	else{ 
		layer.top = positionY; 
//		layer.left = positionX;
		}
	layer.visibility = show_style;
}


function detect_submenu_position(indx){
//	positionX = (nn4) ? realPositionX('mPos') : realPositionX('mPosDom'); positionX -= 0;
	positionY = (nn4) ? realPositionY('mPos') : realPositionY('mPosDom'); positionY += 0;
}
function detect_subsubmenu_position(indx){
	positionY = (nn4) ? realPositionY('mPos') : realPositionY('mPosDom'); positionY += 27;
}

function realPositionX(which){
	if (nn4) {
		pos = document.layers[which].pageX
	} else {
		var elem = (dom)? document.getElementById(which) : document.all[which];
		var pos = elem.offsetLeft;
		while (elem.offsetParent != null) {
		elem = elem.offsetParent;
		pos += elem.offsetLeft;
		}
	} return pos;
}

function realPositionY(which) {
	if (nn4) {
		pos = document.layers[which].pageY
	} else {
		var elem = (dom)? document.getElementById(which) : document.all[which];
		var pos = (elem.offsetTop>0)?elem.offsetTop-2:0;
		while (elem.offsetParent != null) {
		elem = elem.offsetParent;
		pos += elem.offsetTop;
		}
	} return pos;
}

function hideSub(){
	for(i=0;i<menuDivId.length;i++){
		layer = get_layer(menuDivId[i]);
		hideLayer(layer);
	}
}

function hideSubSub(){
	for(i=0;i<menuSubDivId.length;i++){
		layer = get_layer(menuSubDivId[i]);
		hideLayer(layer);
	}
}

function hideLayer(layer){
	layer.visibility = hide_style;
}

function detect_array_element(indx,array){
	var detect = false;
	for (i=0;i<array.length;i++ ){
		if (array[i]+''==indx){
			var detect = true;
		}
	}
	return detect;
}

function showPopupImgWindow(im,w,h,alt){
	imgwindow = window.open('',"_blank","resizable=yes,menubar=no,status=no,top=30,left=100;scrollbars=no,width="+w+",height="+h);
	imgwindow.document.open("text/html");
	imgwindow.document.writeln('<html><head><title>'+alt+'<\/title><\/head>');
	imgwindow.document.writeln('<body bgcolor=#ffffff marginwidth="0" marginheight="0" topmargin="0" leftmargin="0" onBlur="self.close();">');
	imgwindow.document.writeln('<div align="left"><a href="javascript:self:close();"><img src="'+im+'" width="'+w+'" height="'+h+'" alt="'+alt+'" border="0"></a></div><\/body><\/html>');
	imgwindow.focus();
}

function showPopupWindow(path,w,h){
	win = window.open(path,"_blank","resize=yes,resizable=yes,menubar=no,status=no,top=30,left=100,scrollbars=yes,width="+w+",height="+h);
	win.focus();
}

var tabCnt = 0;
function openTab(tab)	{
		for(ii=0;ii<tabCnt;ii++){
			if(document.getElementById('tab'+ii)){
				if (ii == tab){
					document.getElementById('tab'+ii).style.display = "";}
				else{
					document.getElementById('tab'+ii).style.display = "none";}
			}
		}
}

function getElementbyClass(ro, cln){
var tmp=new Array();
var inc=0;
for (i=0; i<ro.length; i++){
	if (ro[i].className==cln) tmp[inc++]=ro[i]}return tmp
}

// window.onload = function() {
function	mpopupl() {
	if (!document.getElementsByTagName) return false;
	var elms = document.getElementsByTagName('a');
	cl=getElementbyClass(elms, 'popup');
	for (var i = 0; i < cl.length; i++) {
		cl[i].onclick = function() {showPopupImgWindow(this.getAttribute("href"),this.getAttribute("w"),this.getAttribute("h"));return false;}
	}
}
