//document.write("<script src=\"/htm-webaxy/javascript/jquery-1.2.3.js\"><\/script>");
//alert(window.objBody);
mainLoad();
//runEventsOnDOMLoaded();
function mainLoad(){
//	if(window.objBody){return false;}
	minMargin=10;
	hide_delay=600;
	objHead = document.getElementsByTagName('head')[0];
	objBody = document.body;
	webaxyURL= document.getElementById('scriptRequire').attributes.getNamedItem('webaxyURL').value;
	PageLoaded=false;
	dateObj = new Date();
	dt=dateObj.getYear()+''+dateObj.getMonth()+''+dateObj.getDate();
	//alert(objBody);
	//------------- click Admin -----------------
	editAlow = '', alowToEdit = 0;
	clickadmin='';
	if (document.cookie.length > 0) { // if there are any cookies
		var search =  "clickadmin=";
		offset = document.cookie.indexOf(search);
		if (offset != -1) { // if cookie exists 
			offset += search.length ;  // set index of beginning of value
			end = document.cookie.indexOf(";", offset); // set index of end of cookie value
			if (end == -1) 
				end = document.cookie.length;
			clickadmin= unescape(document.cookie.substring(offset, end));
			if (clickadmin != "")
				alowToEdit = 1;
		}
	}
	//---------------------------------------------------
	objCSS = objHead.appendChild(document.createElement('link'));
	objCSS.id = 'xmlMenuBaseStyle';
	objCSS.rel = 'stylesheet';
	objCSS.href = webaxyURL+'/xmlMenu/xmlMenu.css';
	objCSS.type = 'text/css';
	
	subMenuDivObj=document.createElement("div");
	subMenuDivObj.setAttribute('id', 'subMenu');
	subMenuDivObj.id= 'subMenu';
	
	//--------   add subMenuDivObj to body when DOM is loaded ----
	preDOMonload = window.__onDOMLoad;
	window.__onDOMLoad = function() {
		preDOMonload();
		objBody.insertBefore(subMenuDivObj, objBody.firstChild);
//		//#--------------    for debaging    --------------------------
//		debagDiv=document.createElement("div");
//		debagDiv.setAttribute('id', 'debugDiv');
//		objBody.appendChild(debagDiv);
//		//#------------------------------------------------------------
	
	}
	//-------------------------------------------------------------------------------------

}

//#------------------------------------------------------------
function initMenu(divID, xmlPath, verticalMenu, more, stylePath){
	var divObj=document.getElementById(divID);
	divObj.timer=divID;
	if(verticalMenu && (verticalMenu==1 || verticalMenu=='v' || verticalMenu=='vertical') ){divObj.verticalMenu=1;}
	if(stylePath && stylePath.search(/\.css$/) !=-1){divObj.stylePath=stylePath;}
	if(more){divObj.more=1;}else{divObj.more=0;}
	if(xmlPath.search(/\?/) != -1){c='&';}else{c='?';}
	LoadXMLobject(divObj, xmlPath+''+c+'rnd='+dt );
//	LoadXMLobject(divObj, xmlPath);
}
//#------------------------------------------------------------
function LoadXMLobject(div, filePath, postMode, postVars, async){
	if(arguments.length!=5){async=true;}
	var xmlDoc='';
	
	if(window.XMLHttpRequest){xmlDoc = new XMLHttpRequest();}
	else{	xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");}

	xmlDoc.open(postMode=='POST'?"POST":"GET",filePath, async);
	if(postMode){xmlDoc.setRequestHeader('Content-type','application/x-www-form-urlencoded');}
	xmlDoc.onreadystatechange= waitLoadFunction;
	xmlDoc.send(null||postVars);
	
	function waitLoadFunction(){
		if (xmlDoc.readyState == 4){//alert(xmlDoc.status);
			if (xmlDoc.status == 200){//alert('responseXML='+xmlDoc.responseXML);
				var preDOMonload = window.__onDOMLoad;
				window.__onDOMLoad = function() {
					preDOMonload();
					buildMenu(div, xmlDoc.responseXML);
				}
				if(!div.more){checkDOMandRun();}
			}
			else if(xmlDoc.status == 404){alert('Error 404: file not exist');}
			else if(xmlDoc.status == 405){alert('Error 405: The requested method is not allowed');}
		}
		else{
			div.innerHTML='<b></b>';
		}
	}
}
//#------------------------------------------------------------
function buildMenu(div, xmlObj){
//	alert('run buildMenu');
	var topMenuElement=xmlObj.getElementsByTagName('menu')[0]
	var mID=topMenuElement.attributes.getNamedItem('id').value;
	var mID_original=mID;
	mID=mID+(div.verticalMenu?'v':'');
	topMenuElement.setAttribute('id', mID);
	var allBorderR=topMenuElement.attributes.getNamedItem('borderR')?topMenuElement.attributes.getNamedItem('borderR').value:'';
	var allBorderL=topMenuElement.attributes.getNamedItem('borderL')?topMenuElement.attributes.getNamedItem('borderL').value:'';
	var allBullet=topMenuElement.attributes.getNamedItem('bullet')?topMenuElement.attributes.getNamedItem('bullet').value:'';
	
	var mainMenuBullet=topMenuElement.attributes.getNamedItem('bulletBwMenu')?topMenuElement.attributes.getNamedItem('bulletBwMenu').value:'';
	var removeFirstBullet=topMenuElement.attributes.getNamedItem('removeFirstBullet')?topMenuElement.attributes.getNamedItem('removeFirstBullet').value:'';
	
	var HTMLbefore=topMenuElement.attributes.getNamedItem('HTMLbefore')?topMenuElement.attributes.getNamedItem('HTMLbefore').value:'';
	var HTMLafter=topMenuElement.attributes.getNamedItem('HTMLafter')?topMenuElement.attributes.getNamedItem('HTMLafter').value:'';
	var menuSurround = document.createElement('div');
	menuSurround.setAttribute('id', 'surround'+mID);
	menuSurround.className='surroundDIV';
	menuSurround.innerHTML=decodeXML(HTMLbefore)+'<XMLMENU/>'+decodeXML(HTMLafter);
	
	div.innerHTML='';
	div.setAttribute('menuId', mID);
//	div.style.height='auto';
	div.setAttribute('style', '');
	div.className='menuDiv '+mID+'menuDiv';
	
	var menuTable=document.createElement("table");
	menuTable.setAttribute('id', mID);
	menuTable.setAttribute('cellSpacing', '0');
	menuTable.setAttribute('cellPadding', '0');
	menuTable.dir=topMenuElement.attributes.getNamedItem('dir').value;
	menuTable.previsible=mID
	menuTable.timer='';
	menuTable.tStatus=0;
	menuTable.className='menuBar '+mID+'menuBar';
//////	menuTable.onmouseout= new Function("hideMenu('"+mID+"')");
//////	menuTable.onmouseover= new Function("unhideMenu('"+mID+"')");
	
	var newRow=menuTable.insertRow(0);
	var itemCell = newRow.insertCell(0);
//	itemCell.setAttribute('noWrap', '-1');
	var addText=topMenuElement.attributes.getNamedItem('name')?document.createTextNode(topMenuElement.attributes.getNamedItem('name').value):'';
	itemCell.appendChild(addText);
	
	if (alowToEdit == 1){
		var imgA=document.createElement("img");
//		imgA.onclick=new Function("openMenuAdmin('"+mID+"');");//function fom cilck admin on page
		imgA.setAttribute('menuId', mID_original);
		imgA.setAttribute('src', ""+webaxyURL+"/click/pagedit.gif");
		imgA.setAttribute('title', "Menu Administration");
		imgA.className='menuClickAdminImg';
		imgA.style.cursor='pointer';
		itemCell.appendChild(imgA);
	}
	
	for (var child = topMenuElement.firstChild; child != null; child = child.nextSibling){
		if(child.nodeType==1){//alert(child.attributes.getNamedItem('name').value);
			if(child.nodeName=='MenuItem'){
				var thisItemId=child.attributes.getNamedItem('id').value;
				var thisItemCSSid=thisItemId.replace(/\./g,'_');
				if(div.verticalMenu){newRow=menuTable.insertRow(-1);}
				
				if (mainMenuBullet && ((removeFirstBullet == 'false' && newRow.cells.length == 1) || (newRow.cells.length > 1))) {
					var itemCell1 = newRow.insertCell(newRow.cells.length);//add a cell at the end
					if( mainMenuBullet.search(/^http:/) !=-1 ){
							addText=document.createElement("img");
							addText.setAttribute('src', mainMenuBullet);
							//addText.className='bullets';
					}
					else{
						addText=document.createTextNode(bullet);
					}
					itemCell1.appendChild(addText);
				}				
				
				var itemCell = newRow.insertCell(newRow.cells.length);//add a cell at the end
				itemCell.align="center";
					var itemTable=document.createElement("table");
					itemTable.setAttribute('menuId', mID);
					itemTable.setAttribute('itemId', thisItemId);
					itemTable.setAttribute('menuLevel', '0');
					if(div.verticalMenu){itemTable.setAttribute('vertical', '1');}
					itemTable.setAttribute('cellSpacing', '0');
					itemTable.className='menuBar '+mID+'menuBar allItems '+mID+'allItems '+mID+'mainMenu '+mID+'item'+thisItemCSSid;
					itemTable.setAttribute('itemClass', 'menuBar '+mID+'menuBar allItems '+mID+'mainMenu '+mID+'allItems '+mID+'item'+thisItemCSSid);
					itemTable.setAttribute('itemOverClass', "menuBar "+mID+"menuBar allItems "+mID+"mainMenu "+mID+"allItems allItemsOver "+mID+"allItemsOver "+mID+"item"+thisItemCSSid+"Over");
//////					if(div.verticalMenu){
//////						itemTable.onmouseover= new Function(
//////							"this.className='menuBar "+mID+"menuBar allItems "+mID+"allItems "+mID+"item"+thisItemCSSid+" allItemsOver "+mID+"allItemsOver "+mID+"item"+thisItemCSSid+"Over'; "+
//////							"showSubMenu(this, '"+topMenuElement.attributes.getNamedItem('id').value+"', '"+thisItemCSSid+"');"
//////						);
//////					}
//////					else{
//////						itemTable.onmouseover= new Function(
//////							"this.className='menuBar "+mID+"menuBar allItems "+mID+"allItems "+mID+"item"+thisItemCSSid+" allItemsOver "+mID+"allItemsOver "+mID+"item"+thisItemCSSid+"Over'; "+
//////							"showMenu(this, '"+topMenuElement.attributes.getNamedItem('id').value+"', '"+thisItemCSSid+"');"
//////						);
//////					}
//////					itemTable.onmouseout= new Function("this.className='menuBar "+mID+"menuBar allItems "+mID+"allItems "+mID+"item"+thisItemCSSid+"';")

						var tr=itemTable.insertRow(0);
						var newCell = tr.insertCell(0);
						if(! child.attributes.getNamedItem('borderL')){child.setAttribute("borderL", child.parentNode.attributes.getNamedItem('borderL').value);}
						borderL=child.attributes.getNamedItem('borderL').value;
						if(! child.attributes.getNamedItem('borderR')){child.setAttribute("borderR", child.parentNode.attributes.getNamedItem('borderR').value);}
						borderR=child.attributes.getNamedItem('borderR').value;
						if(! child.attributes.getNamedItem('bullet')){child.setAttribute("bullet", child.parentNode.attributes.getNamedItem('bullet').value);}
						bullet=child.attributes.getNamedItem('bullet').value;
						if(! child.attributes.getNamedItem('recursive')){child.setAttribute("recursive", 'false')}
						recursive=child.attributes.getNamedItem('recursive').value;
						
						var tr=itemTable.insertRow(0);
						var newCell = tr.insertCell(0);
						if( borderL.search(/^http:/) !=-1 ){
							addText=document.createElement("img");
							addText.setAttribute('src', borderL);
						}
						else{addText=document.createTextNode(borderL);}
						newCell.appendChild(addText);
						
						newCell = tr.insertCell(-1);
						if( bullet.search(/^http:/) !=-1 ){
							addText=document.createElement("img");
							addText.setAttribute('src', bullet);
							addText.className='bullets';
						}
						else{addText=document.createTextNode(bullet);}
						newCell.appendChild(addText);
						
						newCell = tr.insertCell(-1);
//						newCell.setAttribute('noWrap', '-1');
						newCell.style.width='100%';
						if(child.attributes.getNamedItem('name') ){
							if(child.attributes.getNamedItem('name').value.search(/^http:/) !=-1){
								addText=document.createElement("img");
								addText.setAttribute('src', child.attributes.getNamedItem('name').value);
							}
							else{addText=document.createTextNode(child.attributes.getNamedItem('name').value);}
						}
						else{addText=document.createTextNode('');}
						newCell.appendChild(addText);
						
						newCell = tr.insertCell(-1);
						if( borderR.search(/^http:/) !=-1 ){
							addText=document.createElement("img");
							addText.setAttribute('src', borderR);
						}
						else{addText=document.createTextNode(borderR);}
						newCell.appendChild(addText);
						
				var link='#';
				if(child.attributes.getNamedItem('link')){//build click on menu item
					link=child.attributes.getNamedItem('link').value;
				}
				var target=child.attributes.getNamedItem('target')?child.attributes.getNamedItem('target').value:'';
				var itemLink=document.createElement("a");
				itemLink.setAttribute('href', link);
				itemLink.setAttribute('target', target);
				itemTable=insertLinksInTable(itemLink,itemTable);
				
				itemCell.appendChild(itemTable);
				if(child.hasChildNodes()){// create submenu
					createSubMenu(child, mID, child.attributes.getNamedItem('id').value, 1, recursive, mID + 'item' + thisItemCSSid, mID + 'item' + thisItemCSSid+ 'Over');
				}
			}
			else if(child.nodeName=='menuCSS'){//Load Style for menu
				if(div.stylePath){//load external style from file
					var objCSS = objHead.appendChild(document.createElement('link'));
					objCSS.id = 'style'+mID;
					objCSS.rel = 'stylesheet';
					objCSS.href = div.stylePath;
					objCSS.type = 'text/css';
				}
				else{buildCSS(child, mID);}
			}
		}
//		div.appendChild(menuTable);
	}
	div.appendChild(menuTable);
	
//	newMenuView=insertInTo(menuSurround, div); // insert menu in to surround html
//	div.appendChild(newMenuView);
	
	menuParent=div.parentNode;
	menuParent.appendChild(insertInTo(menuSurround, div))
}
//#------------------------------------------------------------
function insertLinksInTable(linkObj, tableObj){
//	var menuId=tableObj.getAttribute('menuId');
//	var itemId=tableObj.getAttribute('itemId');
	var tableClass=tableObj.getAttribute('itemClass');
	for (var c=0; c<tableObj.rows[0].cells.length; c++){
//		alert(tableObj.rows[0].cells[c].firstChild);
		var newLink=linkObj.cloneNode(true);
//		newLink.className='allItems '+menuId+'allItems '+menuId+'item'+itemId;
		newLink.className=tableClass;
		newLink.style.border='0px';
		newLink.style.backgroundImage='none';
      	newLink.appendChild(tableObj.rows[0].cells[c].firstChild);
//      alert(newLink.innerHTML);
//      tableObj.rows[0].cells[c].removeChild(tableObj.rows[0].cells[c].firstChild);
      tableObj.rows[0].cells[c].appendChild(newLink);
    }
//    alert(tableObj);
	return tableObj;
}
//#------------------------------------------------------------
function insertInTo(node, menuDiv) {
	for (var child = node.firstChild; child != null; child = child.nextSibling){
		if(child.nodeName =='XMLMENU'){
//			child.parentNode.replaceChild(menuDiv.firstChild, child);
			child.parentNode.replaceChild(menuDiv, child);
		}
		else if(child.hasChildNodes()){insertInTo(child, menuDiv);}
	}
	return node;
}
//#------------------------------------------------------------
function decodeXML(txt){
	var txt= new String(txt);
    txt = txt.replace(/&amp;/g, '&');
    txt = txt.replace(/&lt;/g, '<');
    txt = txt.replace(/&gt;/g, '>');
    txt = txt.replace(/&apos;/g, "'");
    txt = txt.replace(/&quot;/g, '"');
return txt;
}
//#------------------------------------------------------------
function createSubMenu(xmlObj, menuID, submenuID, submenuLevel, recursive, recursiveMenuID, recursiveMenuIDOver){
	var submenuLevel = submenuLevel;
	var submenuSCCid=submenuID.replace(/\./g,'_');
//	alert('createSubMenu xmlObj='+xmlObj+'; menuID='+menuID );
	var div=document.createElement("div");
	div.setAttribute('menuId', menuID);
	div.setAttribute('id', menuID+"."+submenuID);
	div.className='subMenuDiv';
//////	div.onmouseout= new Function("hideMenu('"+menuID+"')");
//////	div.onmouseover= new Function("unhideMenu('"+menuID+"')");
	
	var submenuTable=document.createElement("table");
	submenuTable.setAttribute('cellSpacing', '0');
	submenuTable.setAttribute('cellPadding', '0');
	submenuTable.className='menuBar subMenu '+menuID+'subMenu subMenu'+submenuLevel+' '+menuID+'subMenu'+submenuLevel+'';
	
	for (var child = xmlObj.firstChild; child != null; child = child.nextSibling){
		if(child.nodeType==1){
			var thisItemId=child.attributes.getNamedItem('id').value;
			var thisItemCSSid=thisItemId.replace(/\./g,'_');
			
			var itemCell=submenuTable.insertRow(-1).insertCell(0);
//			itemCell.align="center";
			var itemTable=document.createElement("table");
			itemTable.setAttribute('menuId', menuID);
			itemTable.setAttribute('itemId', thisItemId);
			itemTable.setAttribute('menuLevel', submenuLevel);
			itemTable.setAttribute('cellSpacing', '0');
			var recursiveMenuIDSCC = '';
			var recursiveMenuIDSCCOver = '';
			if (recursive == 'true') {
				 // ((child.attributes.getNamedItem('recursive') && child.attributes.getNamedItem('recursive').value != 'true') ||
				 //  !child.attributes.getNamedItem('recursive'))) {				
					recursiveMenuIDSCC = recursiveMenuID.replace(/\./g,'_');
					recursiveMenuIDSCCOver = recursiveMenuIDOver.replace(/\./g,'_');
					//alert('createSubMenu:'+submenuID+' '+recursiveMenuID+' scc:'+recursiveMenuIDSCC);
					
			}
			
			itemTable.className='menuBar '+menuID+'menuBar subMenu '+menuID+'subMenu allItems '+menuID+'allItems '+recursiveMenuIDSCC+' subMenu'+submenuLevel+' '+menuID+'subMenu'+submenuLevel+' '+menuID+'item'+thisItemCSSid;
			//alert(thisItemCSSid+':'+itemTable.className);
			itemTable.setAttribute('itemClass','menuBar '+menuID+'menuBar subMenu '+menuID+'subMenu allItems '+menuID+'allItems '+recursiveMenuIDSCC+' subMenu'+submenuLevel+' '+menuID+'subMenu'+submenuLevel+' '+menuID+'item'+thisItemCSSid);
			itemTable.setAttribute('itemOverClass', menuID+"subMenuOver "+menuID+"subMenuOver"+submenuLevel+" menuBar "+menuID+"menuBar subMenu "+menuID+"subMenu allItems "+menuID+"allItems subMenu"+submenuLevel+" "+menuID+"subMenu"+submenuLevel+" allItemsOver "+menuID+"allItemsOver "+menuID+"item"+thisItemCSSid+"Over "+recursiveMenuIDSCCOver);

//			alert('menuBar subMenu allItems item'+menuID+' item'+submenuID+' subMenu'+submenuLevel+' item'+child.attributes.getNamedItem('id').value);
//			if(child.hasChildNodes()){
//////				itemTable.onmouseover= new Function(
//////				"this.className='  menuBar "+menuID+"menuBar subMenu "+menuID+"subMenu allItems "+menuID+"allItems "+menuID+"item"+submenuSCCid+" subMenu"+submenuLevel+" "+menuID+"subMenu"+submenuLevel+" "+menuID+"item"+thisItemCSSid+ " allItemsOver "+menuID+"allItemsOver "+menuID+"item"+thisItemCSSid+"Over  '; "
//////				+"showSubMenu(this, '"+menuID+"', '"+child.attributes.getNamedItem('id').value+"');"
//////				);
//////				itemTable.onmouseout= new Function("this.className='menuBar "+menuID+"menuBar subMenu "+menuID+"subMenu allItems "+menuID+"allItems "+menuID+"item"+submenuSCCid+" subMenu"+submenuLevel+" "+menuID+"subMenu"+submenuLevel+" "+menuID+"item"+thisItemCSSid+"';");
//			}
			
//			if(child.attributes.getNamedItem('link')){//build click on menu item
//				var link=child.attributes.getNamedItem('link').value;
//				var paramValue=link.match(/^([^\?]*)(\?)?(.*)?$/);
//				paramValue[1]=paramValue[1].replace(/\/$/,'');
//				var target=child.attributes.getNamedItem('target')?child.attributes.getNamedItem('target').value:'';
//				var method=child.attributes.getNamedItem('method')?child.attributes.getNamedItem('method').value:'';
//				itemTable.setAttribute('mLink', paramValue[1]);
//				itemTable.setAttribute('mParamValue', paramValue[3]);
//				itemTable.setAttribute('mTarget', target);
//				itemTable.setAttribute('mMethod', method);
////////				itemTable.onclick=new Function(" clickMenuGo('"+paramValue[1]+"', '"+paramValue[3]+"', '"+target+"', '"+method+"');");
//			}
			
				if(! child.attributes.getNamedItem('borderL')){child.setAttribute("borderL", child.parentNode.attributes.getNamedItem('borderL').value);}
				borderL=child.attributes.getNamedItem('borderL').value;
				if(! child.attributes.getNamedItem('borderR')){child.setAttribute("borderR", child.parentNode.attributes.getNamedItem('borderR').value);}
				borderR=child.attributes.getNamedItem('borderR').value;
				if(! child.attributes.getNamedItem('bullet')){child.setAttribute("bullet", child.parentNode.attributes.getNamedItem('bullet').value);}
				bullet=child.attributes.getNamedItem('bullet').value;
				if(! child.attributes.getNamedItem('recursive')){child.setAttribute("recursive", 'false')}
				else if (child.attributes.getNamedItem('recursive').value == 'true') {
						recursive=child.attributes.getNamedItem('recursive').value;
						recursiveMenuID = recursiveMenuID + ' ' + menuID+'item'+thisItemId;
						recursiveMenuIDSCCOver = recursiveMenuIDSCCOver + ' ' + menuID+'item'+thisItemId+'Over ' + menuID+'subMenuOver'+submenuLevel;
				}
				//alert('recursiveMenuID:'+recursiveMenuID+' recursive'+recursive);
					
				var tr=itemTable.insertRow(0);
				var newCell = tr.insertCell(0);
				
				if( borderL.search(/^http:/) !=-1 ){
					addText=document.createElement("img");
					addText.setAttribute('src', borderL);
				}
				else{	addText=document.createTextNode(borderL);}
				newCell.appendChild(addText);
				
				newCell = tr.insertCell(-1);
				if( bullet.search(/^http:/) !=-1 ){
					addText=document.createElement("img");
					addText.setAttribute('src', bullet);
					addText.className='bullets';
				}
				else{
					addText=document.createTextNode(bullet);
				}
				newCell.appendChild(addText);
				
				newCell = tr.insertCell(-1);
//				newCell.setAttribute('noWrap', '-1');
				newCell.style.width='100%';
				if(child.attributes.getNamedItem('name') ){
					if(child.attributes.getNamedItem('name').value.search(/^http:/) !=-1){
						addText=document.createElement("img");
						addText.setAttribute('src', child.attributes.getNamedItem('name').value);
					}
					else{
						addText=document.createTextNode(child.attributes.getNamedItem('name').value);
					}
				}
				else{
					addText=document.createTextNode('');
				}
//				addText=document.createTextNode(child.attributes.getNamedItem('name')?child.attributes.getNamedItem('name').value:'');
				newCell.appendChild(addText);
				
				newCell = tr.insertCell(-1);
				if( borderR.search(/^http:/) !=-1 ){
					addText=document.createElement("img");
					addText.setAttribute('src', borderR);
				}
				else{	addText=document.createTextNode(borderR);}
				newCell.appendChild(addText);
			
			var link='#';
			if(child.attributes.getNamedItem('link')){//build click on menu item
				link=child.attributes.getNamedItem('link').value;
			}
			var target=child.attributes.getNamedItem('target')?child.attributes.getNamedItem('target').value:'';
			var itemLink=document.createElement("a");
			itemLink.className='itemLink';
			itemLink.setAttribute('href', link);
			itemLink.setAttribute('target', target);
			itemTable=insertLinksInTable(itemLink,itemTable);
			
			itemCell.appendChild(itemTable);
			if(child.hasChildNodes()){
				createSubMenu(child, menuID, child.attributes.getNamedItem('id').value, submenuLevel+1, recursive, recursiveMenuID, recursiveMenuIDSCCOver);
			}
		}
	}
	div.appendChild(submenuTable);
	document.getElementById('subMenu').appendChild(document.createTextNode("\n"));
	document.getElementById('subMenu').appendChild(div);
//	alert(document.getElementById('subMenu').innerHTML);
}
//#--------------------------------------------------------------------------------------------------------------------------------------------------
function showElement(el,bolVisible){
	objStyle=document.getElementById(el).style;
	if(bolVisible){objStyle.visibility = "visible";}
	else{	objStyle.visibility = "hidden";}
}
//#------------------------------------------------------------

function getBounds(el){ // return absolute left top width height of object
	var Left = el.offsetLeft;
	var Top = el.offsetTop;
	var parent = el;
	while (parent = parent.offsetParent){
		Left += parent.offsetLeft;
		Top += parent.offsetTop;
	}
//	alert('left: '+Left+', top: '+Top+', width: '+el.offsetWidth+', height: '+el.offsetHeight);
	return {left: Left, top: Top, width: el.offsetWidth, height: el.offsetHeight};
}
//-----------------------------------------------------------

function hidePrevious(menuID, m){
	var previousVisible=getPreviousVisible(menuID);
	var cur =menuID+'.'+m;
//	debugView('prev='+previousVisible+'; cur='+cur+';');
//	if(previousVisible == cur || !previousVisible || (eval("previousVisible.search(/^"+cur+"\\D/)") !=-1) ){return;}
	if(previousVisible == cur || !previousVisible){return;}
//	debugView( eval("cur.search(/^"+previousVisible+"\\D/)") );
	
	if(previousVisible == menuID){return;}
	while((eval("cur.search(/^"+previousVisible+"\\D/)") ==-1)){
		try{showElement(previousVisible, 0);}catch(e){;}
		lastD=previousVisible.match(/\d+$/);
		lastIDX=previousVisible.lastIndexOf(lastD);
		if(lastIDX > 0) lastIDX--;
		previousVisible=previousVisible.substring(0,lastIDX);
	}
}

function getPreviousVisible(menuID){
//	debugView('getPreviousVisible for ID:'+menuID+';');
	if(menuID){return document.getElementById(menuID).getAttribute('previsible');}
	else{return 0;}
}

function setPreviousVisible(menuID, m){
	document.getElementById(menuID).setAttribute('previsible', menuID+'.'+m);
//	document.getElementById(menuID).previsible= menuID+'.'+m;
}

function showMenu(cur_el, menuID, m) { // cur_el -> curient element object, m ->menu for view
//	alert('cur_el='+cur_el+', menuID='+menuID+', m='+m);
	try{
		divObj=document.getElementById(''+menuID+'.'+m);
		var thisObjBounds=getBounds(cur_el);
		if( (document.getElementById(menuID).dir =='rtl') && (thisObjBounds.left-divObj.offsetWidth+thisObjBounds.width > minMargin) ){
				divObj.style.left = thisObjBounds.left-divObj.offsetWidth+thisObjBounds.width+"px";
				divObj.dir ='rtl';
				divObj.firstChild.style.left = divObj.style.left;
		}
		else{
			divObj.style.left = thisObjBounds.left+"px";
			divObj.dir ='ltr';
		}
		divObj.style.top =  thisObjBounds.top+thisObjBounds.height+0+"px";
		showElement(menuID+'.'+m, true);
	}catch(e){;}
	hidePrevious(menuID, m);
	setPreviousVisible(menuID, m);
}
//--------------
function showSubMenu(cur_el, menuID, m) {
//	debugView('cur_el='+cur_el+', menuID='+menuID+', m='+m);
//	alert(cur_el.parentNode.parentNode.parentNode.parentNode.parentNode.dir);
//	alert(document.getElementById(getPreviousVisible(menuID)).dir);
	
	divObj=document.getElementById(''+menuID+'.'+m);
	if(divObj){
		var thisObjBounds=getBounds(cur_el);
//		var parentDir=document.getElementById(getPreviousVisible(menuID)).dir;
		var parentDir=cur_el.parentNode.parentNode.parentNode.parentNode.parentNode.dir;
		
//		alert('parentDir='+parentDir+';');
		if(parentDir !='rtl' && parentDir !='ltr'){
			if( (document.getElementById(menuID).dir =='rtl') && (thisObjBounds.left-divObj.offsetWidth+thisObjBounds.width > minMargin) ){
				divObj.dir ='rtl'; parentDir ='rtl';
			}
			else{
				divObj.dir ='ltr'; parentDir ='ltr';
			}
		}
		
		if( parentDir =='rtl' ){
			divObj.style.left = thisObjBounds.left-divObj.offsetWidth+"px";
		}
		else{
			divObj.style.left = thisObjBounds.left+thisObjBounds.width+0+"px";
		}
		divObj.dir=parentDir;
		divObj.style.top =  thisObjBounds.top+"px";
		
		showElement(menuID+'.'+m, true);
	}
	hidePrevious(menuID, m);
	setPreviousVisible(menuID, m);
}

//----------------------------------------------------
function hideMenu(mID){ //Hide menu with delay
	var menu=document.getElementById(mID);
	if(menu.tStatus==1){// hide menu
		hidePrevious(mID, '');
	}
	else{ // Start timer for hide menu
		menu.timer=setTimeout("hideMenu('"+mID+"')",hide_delay);
		menu.tStatus=1; // Timer is work
	}
}
function unhideMenu(mID) { // Stop timer and don't hide menu 
	var menu=document.getElementById(mID);
	if (menu.tStatus==1) { // If timer working
		clearTimeout(menu.timer);
		menu.tStatus=0;
	}
}
//#------------------------------------------------------------
function buildCSS(CSS_xmlNODE, mID){
	var styles = document.createElement('style');
	styles.setAttribute('type', 'text/css');
	objHead.appendChild(styles);
	var thisStyleSheet = document.styleSheets[document.styleSheets.length-1];

	var StyleRule=CSS_xmlNODE.firstChild;
	while (StyleRule){
		if(StyleRule.nodeType==1){
			var ruleName=mID+''+StyleRule.attributes.getNamedItem('name').value;
			ruleName='.'+ruleName.replace(/\./g,'_');
			var ruleValues='';
			if(StyleRule.hasChildNodes()){
				for(var rulesNod=StyleRule.firstChild; rulesNod != null; rulesNod=rulesNod.nextSibling){
					if(rulesNod.nodeType==1){ruleValues +=rulesNod.attributes.getNamedItem('name').value+': '+rulesNod.attributes.getNamedItem('value').value+';';}
				}
			}
//			alert('ruleName='+ruleName+'; ruleValues='+ruleValues+';');
			if( thisStyleSheet.insertRule ){//Mozilla & Opera add rule to the end of style
				thisStyleSheet.insertRule( ruleName+' { '+ruleValues+' }', thisStyleSheet.cssRules.length);
			}
			else if( thisStyleSheet.addRule ){// IE add rule to the end of style
				thisStyleSheet.addRule(ruleName, ruleValues);
			}
			//---------------   FIX for A styles in page --------
			if( (ruleName.search(/over/i) !=-1) || (ruleName.search(/item/i) !=-1) || (ruleName.search(/menuBar/i) !=-1) || (ruleName.search(/subMenu/i) !=-1) ){
				if( thisStyleSheet.insertRule ){//Mozilla & Opera add rule to the end of style
					//alert('ruleName='+ruleName+'; ruleValues='+ruleValues+';');
					thisStyleSheet.insertRule( ruleName+':link { '+ruleValues+' }', thisStyleSheet.cssRules.length);
					thisStyleSheet.insertRule( ruleName+':hover { '+ruleValues+' }', thisStyleSheet.cssRules.length);
					thisStyleSheet.insertRule( ruleName+':visited { '+ruleValues+' }', thisStyleSheet.cssRules.length);
					
				}
				else if( thisStyleSheet.addRule ){// IE add rule to the end of style
					thisStyleSheet.addRule(ruleName+':link', ruleValues);
					thisStyleSheet.addRule(ruleName+':hover', ruleValues);
					thisStyleSheet.addRule(ruleName+':visited', ruleValues);
					
				}
			}
			/*else if(ruleName.search(/item/i) !=-1){
				if( thisStyleSheet.insertRule ){//Mozilla & Opera add rule to the end of style
					thisStyleSheet.insertRule( ruleName+':link { '+ruleValues+' }', thisStyleSheet.cssRules.length);
					thisStyleSheet.insertRule( ruleName+':hover { '+ruleValues+' }', thisStyleSheet.cssRules.length);
					thisStyleSheet.insertRule( ruleName+':visited { '+ruleValues+' }', thisStyleSheet.cssRules.length);
				}
				else if( thisStyleSheet.addRule ){// IE add rule to the end of style
					thisStyleSheet.addRule(ruleName+':link', ruleValues);
					thisStyleSheet.addRule(ruleName+':hover', ruleValues);
					thisStyleSheet.addRule(ruleName+':visited', ruleValues);
				}
			}*/
			//------------------------------------------------
		}StyleRule=StyleRule.nextSibling;
	}
}
//---------------------------------------------------------------------------------------------
function __onDOMLoad(){;}

//#------------------------------------------------------------
function checkDOMandRun(){
	var preDOMonload = window.__onDOMLoad;
	window.__onDOMLoad = function() {
		preDOMonload();
		if(navigator.appVersion.indexOf("MSIE")!=-1 && window.noMenuTrick!=1){
			setTimeout("document.body.innerHTML+='';", 500);
		}
		setTimeout("MNav.init();", 700);
	}
/* for Mozilla/Firefox/Opera 9 */
if (document.addEventListener) {//alert('Mozilla/Firefox/Opera 9');
   try{ document.addEventListener("DOMContentLoaded", __onDOMLoad(), false);}
   catch(e){}
//	return ;
}
//#------------------------------------------------------------
/* for Internet Explorer */
else if(navigator.appVersion.indexOf("MSIE")!=-1 && window == top ){// If IE is used and is not in a frame	
	//based on http://javascript.nwbox.com/IEContentLoaded/
	var d = window.document, done = false,
	// only fire once
	init = function () {
		if (!done) {
			done = true;
			__onDOMLoad();
		}
	};
	// polling for no errors
	(function () {
		try {
			// throws errors until after ondocumentready
			d.documentElement.doScroll('left');
		} catch (e) {
			setTimeout(arguments.callee, 50);
			return;
		}
		// no errors, fire
		init();
	})();
	// trying to always fire before onload
	d.onreadystatechange = function() {
		if (d.readyState == 'complete') {
			d.onreadystatechange = null;
			init();
		}
	};
//return;
}
//#------------------------------------------------------------

/* for Safari */
else if (/WebKit/i.test(navigator.userAgent)) {
//	alert('Safari');
    var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
		    clearInterval(_timer);
		    __onDOMLoad(); // call to init
		}
    }, 10);
//    return;
}
//#------------------------------------------------------------
else{
/* for all other browsers */
//	alert('Other browsers');
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = function(){
			__onDOMLoad();
		}
	}
	else {
		window.onload = function(){
			if (oldonload) {oldonload();}
			__onDOMLoad();
		}
	}
}
//#------------------------------------------------------------
}


//#------------------------------------------------------------
var MNav = {
	init: function(){

		var allMenuDivs=getElementsByClassNameAndTagName('menuDiv', 'div');
		for(var i=0; i<allMenuDivs.length; i++){
			//for clickAdmin
				var allMenuClickAdminImg=getElementsByClassNameAndTagName('menuClickAdminImg', 'img', allMenuDivs[i]);
				if(allMenuClickAdminImg.length){allMenuClickAdminImg[0].onclick=new Function("openMenuAdmin('"+allMenuClickAdminImg[0].getAttribute('menuId')+"');");}
			//--------------------------------
			allMenuDivs[i].onmouseout=this.onMenuDivOut;
			allMenuDivs[i].onmouseover=this.onMenuDivOver;
			allMenuDivs[i].firstChild.onmouseover=this.onMenuOver;
			allMenuDivs[i].firstChild.onmouseout=this.onMenuOut;
			allMenuDivs[i].firstChild.onclick=this.onMenuItemClick;
		}
		var allSubMenuDiv=getElementsByClassNameAndTagName('subMenuDiv', 'div');
		for(var i=0; i<allSubMenuDiv.length; i++){
			allSubMenuDiv[i].onmouseout=this.onMenuDivOut;
			allSubMenuDiv[i].onmouseover=this.onMenuDivOver;
			allSubMenuDiv[i].firstChild.onmouseover=this.onMenuOver;
			allSubMenuDiv[i].firstChild.onmouseout=this.onMenuOut;
			allSubMenuDiv[i].firstChild.onclick=this.onMenuItemClick;
		}
	},
	onMenuDivOut: function(e) {
		var menuDiv=getEventTarget(e);
		while(menuDiv.nodeName.toLowerCase() != 'div' || (menuDiv.nodeType == 3) ){
			menuDiv=menuDiv.parentNode;
		}
//		debugView('hideMenu '+menuDiv.getAttribute('menuId')+';');
		if(menuDiv.getAttribute('menuId')){hideMenu(menuDiv.getAttribute('menuId'));}
		return true;
	},
	onMenuDivOver: function(e) {
		var menuDiv=getEventTarget(e);
		while(menuDiv.nodeName.toLowerCase() != 'div' || (menuDiv.nodeType == 3) ){
			menuDiv=menuDiv.parentNode;
		}
//		debugView('unhideMenu '+menuDiv.getAttribute('menuId')+';');
		if(menuDiv.getAttribute('menuId')){unhideMenu(menuDiv.getAttribute('menuId'));}
		return true;
	},
	onMenuOver: function(e) {
		var itemTable=getEventTarget(e);
		while(itemTable.nodeName.toLowerCase() != 'table' || (itemTable.nodeType == 3) ){
			itemTable=itemTable.parentNode;
		}
//		debugView('IN: '+itemTable.nodeName +'; HTML=<code>'+itemTable.innerHTML+'</code>; menuId='+itemTable.getAttribute('menuId')+'; itemId='+itemTable.getAttribute('itemId'));
		if(itemTable.getAttribute('menuId')){
			var mID=itemTable.getAttribute('menuId');
			var itemId=itemTable.getAttribute('itemId');
			var thisItemCSSid=itemId.replace(/\./g,'_');
//			setItemClassName(itemTable, "menuBar "+mID+"menuBar allItems "+mID+"allItems "+mID+"item"+thisItemCSSid+" allItemsOver "+mID+"allItemsOver "+mID+"item"+thisItemCSSid+"Over", "allItems "+mID+"allItems "+mID+"item"+thisItemCSSid+" allItemsOver "+mID+"allItemsOver "+mID+"item"+thisItemCSSid+"Over");
			setItemClassName(itemTable, itemTable.getAttribute('itemOverClass'), "allItems "+mID+"allItems "+mID+"item"+thisItemCSSid+" allItemsOver "+mID+"allItemsOver "+mID+"item"+thisItemCSSid+"Over");
			if( itemTable.getAttribute('vertical') || (itemTable.getAttribute('menuLevel') >0)){
				showSubMenu(itemTable, mID, itemId);
			}
			else{
				showMenu(itemTable, mID, itemId);
			}
		}
		return true;
	},
	onMenuOut: function(e) {
		var itemTable=getEventTarget(e);
		while(itemTable.nodeName.toLowerCase() != 'table' || (itemTable.nodeType == 3) ){
			itemTable=itemTable.parentNode;
		}
//		debugView('OUT: '+itemTable.nodeName +'; menuId='+itemTable.getAttribute('menuId')+'; itemId='+itemTable.getAttribute('itemId'));
		if(itemTable.getAttribute('menuId')){
			var mID=itemTable.getAttribute('menuId');
			var itemId=itemTable.getAttribute('itemId');
			var thisItemCSSid=itemId.replace(/\./g,'_');
//			setItemClassName(itemTable, "menuBar "+mID+"menuBar allItems "+mID+"allItems "+mID+"item"+thisItemCSSid, "allItems "+mID+"allItems "+mID+"item"+thisItemCSSid);
			setItemClassName(itemTable, itemTable.getAttribute('itemClass'), "allItems "+mID+"allItems "+mID+"item"+thisItemCSSid);
		}
		return true;
	},
	onMenuItemClick: function(e) {
		var itemTable=getEventTarget(e);
		while(itemTable.nodeName.toLowerCase() != 'table' || (itemTable.nodeType == 3) ){
			itemTable=itemTable.parentNode;
		}
//		debugView('CLICK: '+itemTable.nodeName +'; menuId='+itemTable.getAttribute('menuId')+'; itemId='+itemTable.getAttribute('itemId'));
		if(itemTable.getAttribute('menuId')){
			var td=itemTable.rows[0].cells[2];
			for (var c = 0;c < td.childNodes.length; c++) {
				if (td.childNodes[c].tagName && (td.childNodes[c].tagName.toLowerCase() == 'a')) {
					if (td.childNodes[c].click) {	// IE
						td.childNodes[c].click();
					}
					else {//FF
					}
				}
			}
		}
		return true;
	}
}
//#------------------------------------------------------------
function setItemClassName(itemTable, itemClassName, linksClassName){
//	debugView('setItemClassName:'+itemTable.outerHTML+', '+itemClassName+', '+linksClassName);
	itemTable.className=itemClassName;
	for (var c=0; c<itemTable.rows[0].cells.length; c++){
		if(itemTable.rows[0].cells[c].hasChildNodes() && itemTable.rows[0].cells[c].firstChild.nodeName.toLowerCase() == 'a'){
//			itemTable.rows[0].cells[c].firstChild.className=linksClassName;
			itemTable.rows[0].cells[c].firstChild.className=itemClassName;
		}
	}
}
//function setItemClassName(obj, itemClassName, linksClassName){
//	if (obj.tagName == "TABLE") {
//			obj.className = itemClassName;
//			for (var r = 0; r < obj.rows.length; r++) {
//				for (var c = 0; c < obj.rows[r].cells.length; c++) {
//					setItemClassName(obj.rows[r].cells[c], itemClassName, linksClassName);
//				}
//			}
//		}
//		else if (obj.tagName == "TD") {
//			for (var c = 0;c < obj.childNodes.length; c++) {
////				if (obj.childNodes[c].className && (obj.childNodes[c].className == (on ? classOff : classOn))) {
//					obj.childNodes[c].className = linksClassName;
////				}
//			}
//		}
//}
//#------------------------------------------------------------
function getEventTarget(e) {
	var e = e || window.event;
	targ = e.target || e.srcElement;
	while (targ.nodeType == 3) { // for  Safari 
		targ = targ.parentNode;
	}
	return targ;
}
//#------------------------------------------------------------
function getElementsByClassNameAndTagName(classname, tag, node){
	if(!node){node = document.getElementsByTagName("body")[0];}
	if(!tag){tag="*";}
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName(tag);
	for(var i=0; i<els.length; i++){
		if(re.test(els[i].className)){a.push(els[i]);}
//		if(els[i].className==classname){a.push(els[i]);}
	}
	return a;
}
//#------------------------------------------------------------
function debugView(str){
	document.getElementById('debugDiv').innerHTML=str.replace(/</g,'&lt;').replace(/\n/g,'<br>')+'<br>'+document.getElementById('debugDiv').innerHTML;
}

