
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function menu_highlight(mhid,mhclass,mhtag,mrelpage){
	
	// Find menu by one of fourth ways
	
	function noe(){return true;}
	window.onerror = noe;
	
	if(mhid != null){
		// by id
		if(mhtag != null){
			// parent
			var menuobj1 = document.getElementById(mhid);
			var menuobj3 = menuobj1.getElementsByTagName("ul");
			var menuobj4 = menuobj3[0];
			
			mhid = mhid+"ah";
			menuobj4.id = mhid;
		}else{
			// ul

		}
	}else if (mhclass != null){
		// by class
		if(mhtag != null){
			// parent
			var menuobj1 = getElementsByClass(mhclass,null,mhtag);
			var menuobj2 = menuobj1[0];
			var menuobj3 = menuobj2.getElementsByTagName("ul");
			var menuobj4 = menuobj3[0];
		}else{
			// ul
			var menuobj1 = getElementsByClass(mhclass,null,"ul");
			var menuobj4 = menuobj1[0];
		}
		mhid = "highlmenu";
		menuobj4.id = mhid;
		
	}

	// Run highlight script
	
	preparemenu(mhid,mrelpage);
	
	//alert("aaa" + menuobj.innerHTML);
	
	
}

function firstlvlstyling(obj){
	// To add class for item with sub levels
	obj.firstChild.className = "hasDropdown";
}

function secondlvlstyling(obj){

}

function thirdlvlstyling(obj){

}



// Array indexOf function for IE
if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}

function preparemenu(menuid,mrelpage){
	
	// get active page adress
	

	var pageurl = window.location.href;

	// read menu
	
	var menuobj = document.getElementById(menuid);	
	// if JS enabled close sublists
	menuobj.className = "jsworking";
	
	var node = menuobj.getElementsByTagName("LI");
	
	// arrays for menu data
	var arr2 = new Array();
	var arr1 = new Array();
	
	// parse menu
	for (i=0; i<node.length; i++) {
		var parentid = node[i].parentNode.parentNode.id;
		if(node[i].parentNode.id == menuid){
			// first level
			arr2[i] = "s";
			node[i].id = i;
			firstlvlstyling(node[i]);
		}else if(arr2[parentid] == "s"){
			// second level
			arr2[i] = node[i].parentNode.parentNode.id;
			node[i].id = i;
			secondlvlstyling(node[i]);
		}else{
			// other levels
			arr2[i] = node[i].parentNode.parentNode.id;
			node[i].id = i;
			thirdlvlstyling(node[i]);
		}
		arr1[i] = node[i].firstChild.href;
		node[i].onmouseover=function()
        {

			this.className = this.className + " openlistie6";

        }
		node[i].onmouseout=function()
        {

			this.className = this.className.replace("openlistie6", "");
			

        }

	}
	
 /////////////////// relpage
	
	var kur = pageurl.substring(8).search("/");
	kur = kur + 8 + 1;
	
	
	var pageurl2 = pageurl.substring(kur);
	var pageurl3 = pageurl.substring(0,kur);
	if(mrelpage[pageurl2]){
	if(mrelpage[pageurl2].length > 3){
	
		pageurl = pageurl3 + mrelpage[pageurl2];
	
	}
	}
	
	
	// search for active menu node
	var activenodeid = arr1.indexOf(pageurl);
	if (activenodeid >= 0){
		// active node found
		
		var activenodeobj = document.getElementById(activenodeid);

		// set active

		if(arr2[activenodeid] == "s"){
			// active node in first level
			
			activenodeobj.firstChild.className = "firstlvlactive";
			// show sub list
			var actlist = activenodeobj.getElementsByTagName("UL");
			if(actlist.length > 0){
				actlist[0].className = "openlist";
			}
		}else if(arr2[arr2[activenodeid]] == "s"){
			// active node in second level
			activenodeobj.firstChild.className = "sublvlactive";
			// activate parent node
			document.getElementById(arr2[activenodeid]).firstChild.className = "firstlvlactive";
			// show parent sub list
			var actlist = activenodeobj.getElementsByTagName("UL");
			if(actlist.length > 0){
				actlist[0].className = "openlist";
			}
			// show sub list
			var actlist2 = document.getElementById(arr2[activenodeid]).getElementsByTagName("UL");
			if(actlist2.length > 0){
				actlist2[0].className = "openlist";
			}
		}else{
			// active node in third level
			activenodeobj.firstChild.className = "sublvlactive";
			// activate(open) parent node
			document.getElementById(arr2[activenodeid]).firstChild.className = "sublvlopen";
			// activate parent parent node
			document.getElementById(arr2[arr2[activenodeid]]).firstChild.className = "firstlvlactive";
			
			// show sub list
			var actlist = activenodeobj.getElementsByTagName("UL");
			if(actlist.length > 0){
				actlist[0].className = "openlist";
			}
			// show parent sub list
			var actlist2 = document.getElementById(arr2[activenodeid]).getElementsByTagName("UL");
			if(actlist2.length > 0){
				actlist2[0].className = "openlist";
			}
			// show parent parent sub list
			var actlist3 = document.getElementById(arr2[arr2[activenodeid]]).getElementsByTagName("UL");
			if(actlist3.length > 0){
				actlist3[0].className = "openlist";
			}
		}
	}
}