function InitMenu(){
	var bar = menuBar.childNodes;  
	/*alert("length: " + bar.length);
	for(var x=0; x < bar.length; x++){ 
		alert("classname " + x + " : " + bar[x].className);
		var attrs = eval(bar[x].attributes);
		if(bar[x].className == "bar" && attrs){
				var m = eval(attrs.menu);
				alert("m: " + m.value);
				var menuObj = document.getElementById(m);
				//if(menuObj) alert("object name: " + menuObj.value); else alert("found Nothing");
				document.getElementById(m.value).style.color = "red";
				alert(document.getElementById(m.value).style.color);
		}
	}*/
	for(var i=0; i < bar.length; i++){ 
		if(bar[i].className == "bar"){
	    	//var menu=eval(bar[i].menu);
			var attrs = eval(bar[i].attributes);
			var menu = document.getElementById(attrs.menu.value);
			menu.style.visibility = "hidden";
	    	//var style = menu.getAttribute("style");
			//var visibility = style.getAttribute("visibility") = "hidden";
			
			if(menu.getAttribute("cmd") != null){
				bar[i].onclick = new Function("Do("+menu.id+")");
			} 
	    	bar[i].onmouseover = new Function("ShowMenu("+bar[i].id+")");
	    	var Items = menu.childNodes;
	    	for(var j=0; j<Items.length; j++){
				if(Items[j].className == "menuItem") {
		        	var menuItem = eval(Items[j].id);
					if (menuItem.menu != null){ 
		        	menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>";
		        	//var tmp = eval(menuItem.id+"_Arrow")
		        	// tmp.style.pixelLeft = menu.getBoundingClientRect().Right
		        	//- tmp.offsetWidth - 15
		        	FindSubMenu(menuItem.menu);
					}
			        if(menuItem.getAttribute("cmd") != null){
			        	menuItem.onclick = new Function("Do("+menuItem.id+")");
			        } 
			        menuItem.onmouseover = new Function("highlight("+Items[j].id+")");
					menuItem.onmouseout = new Function("deselect ( this )");
				}    
		   }
	   }
   }
}

function FindSubMenu(subMenu){
   var menu=eval(subMenu);
   var Items = menu.children;
          
   for(var j=0; j<Items.length; j++){
      menu.style.visibility = "hidden";
      var menuItem = eval(Items[j].id);
              
      if(menuItem.menu!= null){
          menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>";
          // var tmp = eval(menuItem.id+"_Arrow")
         //tmp.style.pixelLeft = 35 
         //menuItem.getBoundingClientRect().right -          tmp.offsetWidth - 15;
         FindSubMenu(menuItem.menu);
      }

      if(menuItem.cmd != null){
         menuItem.onclick = new Function("Do("+menuItem.id+")");
      } 
      menuItem.onmouseover = new Function("highlight("+Items[j].id+")");
   }  
}
 
function ShowMenu(obj){
	var atts = obj.attributes;
	
    HideMenu(menuBar);
    var menu = eval(obj.menu);
    var bar = eval(obj.id);
    bar.className="barOver";
    document.getElementById(atts.menu.value).style.visibility = "visible";
	var pixTop, pixLeft;
	if(obj.getBoundingClientRect){
		//IE enabled
		pixTop = obj.getBoundingClientRect().top + obj.offsetHeight + Bdy.scrollTop;
		pixLeft = obj.getBoundingClientRect().left + Bdy.scrollLeft;
	}
	else {
		//firefox / mozilla enabled
		pixTop = document.getBoxObjectFor(obj).y + obj.offsetHeight;
		pixLeft = document.getBoxObjectFor(obj).x + Bdy.scrollLeft;
	}
	//document.getElementById(atts.menu.value).style.pixelTop = pixTop;
	//document.getElementById(atts.menu.value).style.pixelLeft = pixLeft;
	document.getElementById(atts.menu.value).style.left = pixLeft + "px";
	document.getElementById(atts.menu.value).style.top = pixTop + "px";
}
   
function highlight(obj){
   	var PElement = document.getElementById(obj.parentNode.getAttribute("id"));
     
   	if(PElement.hasChildNodes() == true){
    	var Elements = PElement.childNodes;
    	for(var i=0; i<Elements.length; i++){
			if(Elements[i].className == "menuItem") {
        		TE = eval(Elements[i].id);
        		TE.className = "menuItem";
			}
    	}
	} 
	obj.className="ItemMouseOver";
	window.defaultStatus = obj.title;
	ShowSubMenu(obj);
}
   
function Do(obj){	
	var cmd = obj.getAttribute("cmd");	
	//window.navigate(cmd);
	location.href="http://www.crestcompliance.com" + cmd;
}
   
function HideMenu(obj){
	if(obj.hasChildNodes()){  
    	var child = obj.childNodes;              
		for(var j =0; j<child.length; j++){
			if(child[j].className == null)continue;
			//alert("child menu: " + child[j].menu + " class: " + child[j].className);
        	if (child[j].className=="barOver"){
        		var bar = eval(child[j].id);
            	bar.className = "Bar";
         	}
			//var attbs = document.getElementById(child[j].id).getAttribute("menu");
			//alert("menu attr: " + attbs);
         	if(document.getElementById(child[j].id).getAttribute("menu") != null){
	         	var childMenu = document.getElementById(document.getElementById(child[j].id).getAttribute("menu"));
	            if(childMenu.hasChildNodes())  HideMenu(childMenu);
	        	childMenu.style.visibility = "hidden";
			}
		}         
	}
}

function ShowSubMenu(obj){
     PMenu = eval(obj.parentNode.id);
     HideMenu(PMenu);

     if(obj.menu != null){
        var menu = eval(obj.menu);
        menu.style.visibility = "visible";
		if(obj.getBoundingClientRect){
			alert("ie");
        	menu.style.pixelTop =  obj.getBoundingClientRect().top + Bdy.scrollTop;
       		menu.style.pixelLeft = obj.getBoundingClientRect().right + Bdy.scrollLeft;
        	if(menu.getBoundingClientRect().right > window.screen.availWidth )
        		menu.style.pixelLeft = obj.getBoundingClientRect().left - menu.offsetWidth;
		}
		else {
			alert("firefox");
			menu.style.pixelTop =  document.getBoxObjectFor(menu).y + Bdy.scrollTop;
       		menu.style.pixelLeft = document.getBoxObjectFor(menu).x + Bdy.scrollLeft;
        	if(document.getBoxObjectFor(menu).x > window.screen.availWidth )
        		menu.style.pixelLeft = document.getBoxObjectFor(menu).x - menu.offsetWidth;
		}
    }
}

function deselect(obj){ obj.className = "menuItem"; }

function swap (id){
	var field = document.getElementById(id);
	if(field == null) { alert("NULL OBJECT"); return true; }
	/*var foregroundColor = field.style.color;
	var backgroundColor = field.style.background;
	alert("colors: " + foregroundColor + " " + backgroundColor);
	field.style.background = foregroundColor;
	field.style.color = backgroundColor;*/
	if(field.className == "green") field.className = "invertGreen";
	else field.className = "green";
	return true;
}