// CSME.PRO [  Encode in UTF-8  Without BOM ] [ ☺ ]

function menu_init() {
	var p = getScriptNode();
	if (p) {
	
			var currentDisplay = getCSSProp(p,"display");
			p.style.display = "block";
			var p_childNodes_length = p.childNodes.length;
			for(var i=0; i<p_childNodes_length; i++) if (p.childNodes[i].tagName=="UL") {
				var p_childNodes_a_length = p.childNodes[i].getElementsByTagName("A").length;
				for(var n=0; n<p_childNodes_a_length; n++) {
					var a1 = p.childNodes[i].getElementsByTagName("A")[n];
					if(p.id != 0) {
						a1.parentNode.parentNode.style.width = getCSSProp(a1,"width");
						a1.parentNode.style.width = getCSSProp(a1,"width");
					}
					}
				menu_init_rec(p.childNodes[i]);
				}
			p.style.display = currentDisplay;
		}
	}
	
function menu_init_rec(li) {
	var a = null;
	var ul = null;
	var li_childNodes_length = li.childNodes.length;
	for(var i=0; i<li_childNodes_length; i++) {
		switch ( li.childNodes[i].tagName ) {
			case "LI":
				// li.childNodes[i].style.zIndex = parseInt(li.style.zIndex) + 1;
				menu_init_rec(li.childNodes[i]);
				break;
			case "A":
				a = li.childNodes[i];
				break;
			case "UL":
				ul = li.childNodes[i];
				if (getCSSProp(ul,"left") == "auto" && getCSSProp(ul,"right") == "auto" ) {
					ul.style[( getCSSProp(ul,"direction") == "rtl" ? "right" : "left" )] = 0;
					ul.style.top = "30px";
					}
				// ul.style.zIndex = parseInt(li.style.zIndex) + 1;
				li.onmouseover = function () {
					// li.style.zIndex = parseInt(li.style.zIndex) + 1;
				//	ul.style.visibility = "visible";
					ul.style.display = "block";
					};
				li.onmouseout = function () {
					// li.style.zIndex = parseInt(li.style.zIndex) - 1;
				//	ul.style.visibility = "hidden";
					ul.style.display = "none";
					};	
				menu_init_rec(li.childNodes[i]);
				break;
			}
		}
		
	}
	
function menu_selector(container,menuId,menuClass) {
	var container_childNodes_length = container.childNodes.length;
	for(var i=0; i<container_childNodes_length; i++) {
		var o = container.childNodes[i];
		if ( o.className) if ( o.className.indexOf(menuClass) != -1  ) {
			//o.style.display = ( o.id == menuId ? 'block' : 'none' );
			o.style.display = 'none';
			}
		}
	gid(menuId).style.display = "block";
	}
	
function menu_display(o) {
	if (getCSSProp(o,"display") == "none") {
		o.style.display = "block";
		} else {
		o.style.display = "none";
		}
	}
	
// -----------------------------------------------------------------------------------------------------------------------------------

function menu_tree_table(o,MenuIndent,fullWidth,icons,AjaxUrl) {
	var level = o.className;
	level = level.split("_");
	level = parseInt(level[1]);
	level = ( level > 0 ? level - 1 : 0 );					
	var level_indent = level * MenuIndent;
	var extraLinks = new Array();
	var extraLinksWidth = 0;
	
	var li1 = o.parentNode;
	li1.style.styleFloat = ( getCSSProp(li1,"direction") == "rtl" ? "right" : "left" );
	
	var inner_ul = null;
	var li1_childNodes_length = li1.childNodes.length;
	for(var i=0; i<li1_childNodes_length; i++) {
		switch(li1.childNodes[i].tagName) {
			case "UL":
				inner_ul = 	li1.childNodes[i];
				break;
			case "IMG":
				extraLinks[extraLinks.length] = li1.childNodes[i];
				extraLinksWidth += parseInt(getCSSProp(li1.childNodes[i],"width"));
				break;
			default:
				
				break;
			}
		}	

	var table1 = document.createElement("TABLE");
	table1.cellPadding = 0;
	table1.cellSpacing = 0;
	table1.style.width = o.style.width;

	var row = table1.insertRow(table1.rows.length);
	var cell1 = row.insertCell(row.cells.length);
	var cell2 = row.insertCell(row.cells.length);
	var cell3 = row.insertCell(row.cells.length);

	cell1.style.width = level_indent+"px";
	cell1.innerHTML = "";
	
	cell2.style.width = icons.collapse.width;
	var icon1 = document.createElement("IMG");
	icon1.border = "";
	cell2.appendChild(icon1);
	
	var w1 = parseInt(fullWidth) - parseInt(icons.collapse.width) - parseInt(level_indent) - parseInt(extraLinksWidth);
	if (w1<=0) w1 = 1;
	
	cell3.style.width = w1+"px";
	cell3.noWrap = true;
	o.style.width = cell3.style.width;
	
	var extraLinks_length = extraLinks.length;
	for(var ec=0; ec<extraLinks_length; ec++) {
		var ExtraCell = row.insertCell(row.cells.length);
		ExtraCell.appendChild(extraLinks[ec]);
		ExtraCell.style.width = getCSSProp(extraLinks[ec],"width")
		}
	
	if ( inner_ul != null ) {
		if (getCSSProp(inner_ul,"display") == "none") {
			icon1.src = icons.collapse.url;
			icon1.style.width = icons.collapse.width;
			icon1.style.height = icons.collapse.height;
			} else {
			icon1.src = icons.extended.url;
			icon1.style.width = icons.extended.width;
			icon1.style.height = icons.extended.height;			
			}
		
			
		icon1.onclick = function() {		
			if (getCSSProp(inner_ul,"display") == "none") {
				inner_ul.style.display = "block";
				icon1.src = icons.extended.url;
				icon1.style.width = icons.extended.width;
				icon1.style.height = icons.extended.height;	
				var AjaxAction = "";
				if ( AjaxUrl != "" ) {
					AjaxAction = AjaxUrl;
					AjaxAction = myReplace(AjaxAction,"{cs}",inner_ul.id);		
					AjaxAction = myReplace(AjaxAction,"{open}","1");	
					eval(AjaxAction);
					}				
				} else {
				inner_ul.style.display = "none";
				icon1.src = icons.collapse.url;
				icon1.style.width = icons.collapse.width;
				icon1.style.height = icons.collapse.height;	
				var AjaxAction = "";
				if ( AjaxUrl != "" ) {
					AjaxAction = AjaxUrl;
					AjaxAction = myReplace(AjaxAction,"{cs}",inner_ul.id);		
					AjaxAction = myReplace(AjaxAction,"{open}","0");		
					eval(AjaxAction);				
					}				
				}
			}
		li1.insertBefore(table1, inner_ul);
		} else {
		icon1.src = icons.lastleaf.url;
		icon1.style.width = icons.lastleaf.width;
		icon1.style.height = icons.lastleaf.height;			
		li1.insertBefore(table1, o);
		}

	cell3.appendChild(o);
	}

function menu_tree_init(ele,AjaxUrl) {

	var p = null;
	if ( ele == null ) {
		p = getScriptNode();
		} else {
		p = ele;
		}
		
	if (p) {
	
		if ( p.offsetWidth > 0 ) {
		
			var currentDisplay = getCSSProp(p,"display");
			p.style.display = "block";

			var indent1 = document.createElement("DIV");
			indent1.className = "indent";
			p.appendChild(indent1);
			var MenuIndent = parseInt(getCSSProp(indent1,"width"));
			p.removeChild(indent1);			
			
			var icons1 = new Object();
			icons1.collapse = GetBackgroundImageFromClass(p,"collapse");
			icons1.extended = GetBackgroundImageFromClass(p,"extended");
			icons1.lastleaf = GetBackgroundImageFromClass(p,"lastleaf");
			
			var p_childNodes_length = p.childNodes.length;
			for(var i=0; i<p_childNodes_length; i++) if (p.childNodes[i].tagName=="UL") {
				var p_childNodes_a_length = p.childNodes[i].getElementsByTagName("A").length;
				for(var n=0; n<p_childNodes_a_length; n++) {
					var a1 = p.childNodes[i].getElementsByTagName("A")[n];
					menu_tree_table(a1,MenuIndent,p.offsetWidth,icons1,AjaxUrl);
					}
				}

			p.style.display = currentDisplay;
			
			} else {
			setTimeout( function () { menu_tree_init(p,AjaxUrl); } , 10 );
			}
			
		}

	}

function GetBackgroundImageFromClass (parent,className) {
	var sp1 = new Object();
	var o1 = document.createElement("SPAN");
	o1.className = className;
	parent.appendChild(o1);
	sp1.width = getCSSProp(o1,"width");
	sp1.height = getCSSProp(o1,"height");
	sp1.url = getCSSProp(o1,"backgroundImage");
	parent.removeChild(o1);		
	sp1.url = sp1.url.replace(/url\("(.*?)"\)/,"$1");
	sp1.url = sp1.url.replace(/url\((.*?)\)/,"$1");	
	return sp1;
	}		
