var expandFirstItemAutomatically = false;	// Expand first menu item automatically ?
var initMenuIdToExpand = false;	// Id of menu item that should be initially expanded. the id is defined in the <li> tag.
var expandMenuItemByUrl = true;	// Menu will automatically expand by url - i.e. if the href of the menu item is in the current location, it will expand

var initialMenuItemAlwaysExpanded = true;

var dhtmlgoodies_slmenuObj;
var divToScroll = false;
var ulToScroll = false;	
var divCounter = 1;
var otherDivsToScroll = new Array();
var divToHide = false;
var parentDivToHide = new Array();
var ulToHide = false;
var offsetOpera = 0;
if(navigator.userAgent.indexOf('Opera')>=0)offsetOpera=1;	
var slideMenuHeightOfCurrentBox = 0;
var objectsToExpand = new Array();
var initExpandIndex = 0;
var alwaysExpanedItems = new Array();

//写菜单
function showmenu() {
document.write("<div id='side_menu'>");
document.write("<ul id='nav'>");
document.write("<li><a href='/index.html'>首页</a></li>");
document.write("<li><a href='#'>电话实名</a></li>");
document.write("<ul id='sub1'>");
document.write("<li><a href='/shiming/about_sm.shtml'>关于实名</a></li>");
document.write("<li><a href='/shiming/qy_sm.shtml'>企业实名</a></li>");
document.write("<li><a href='/shiming/gr_sm.shtml'>个人实名</a></li>");
//document.write("<li><a href='/shiming/mf_sm.shtml'>个人免费体验实名</a></li>");
document.write("<li><a href='/shiming/sm_using.shtml'>功能应用</a></li>");
document.write("<li><a href='/shiming/case.shtml'>成功案例</a></li>");
document.write("<li><a href='/shiming/clients.shtml'>典型客户</a></li>");
document.write("</ul>");
document.write("<li><a href='#'>实名注册</a></li>");
document.write("<ul id='sub2'>");
document.write("<li><a href='/customer2/unauth/domain/search/search_add.jsp'>正式实名注册</a></li>");
//document.write("<li><a href='/customer2/unauth/domain/search/person_add.jsp'>个人免费体验</a></li>");
document.write("<li><a href='/customer2/unauth/login/user-login.jsp'>实名管理登录</a></li>");
document.write("</ul>");
document.write("<li><a href='#'>实名通话</a></li>");
document.write("<ul id='sub2'>");
//document.write("<li><a href='/recall/about_recall.shtml'>呼叫通话服务</a></li>");
document.write("<li><a href='/recall/phone_recall.shtml'>电话呼叫</a></li>");
//document.write("<li><a href='/recall/sms_recall.shtml'>短信呼叫</a></li>");
document.write("<li><a href='/recall/web_recall.shtml'>网络呼叫</a></li>");
document.write("<li><a href='/recall/recall_using.shtml'>应用体验</a></li>");
document.write("</ul>");
document.write("<li><a href='#'>代理招商</a></li>");
document.write("<ul id='sub3'>");
document.write("<li><a href='/agents/agreement.shtml'>代理政策</a></li>");
document.write("<li><a href='/agents/agents.shtml'>市场宣传</a></li>");
document.write("<li><a href='/agents/zs.shtml'>招商加盟</a></li>");
document.write("<li><a href='/agents/agc.shtml'>代理咨询</a></li>");
document.write("<li><a href='/agents/agent_map.shtml'>代理分布</a></li>");
document.write("<li><a href='/agents/agent_cadre.shtml'>销售精英查询</a></li>");
document.write("<li><a href='/customer2/unauth/login/agent-login.jsp'>代理商登录</a></li>");
document.write("</ul>");
document.write("<li><a href='#'>客户服务</a></li>");
document.write("<ul id='sub4'>");
document.write("<li><a href='/service/servicers.shtml'>服务方式</a></li>");
document.write("<li><a href='/service/help.shtml'>使用帮助</a></li>");
document.write("<li><a href='/service/faq.shtml'>常见问题</a></li>");
document.write("<li><a href='/service/user_getpass.shtml'>忘记密码</a></li>");
//document.write("<li><a href='/service/servktdq.shtml'>开通地区</a></li>");
document.write("<li><a href='/service/servdownload.shtml'>文档下载</a></li>");
document.write("</ul>");
document.write("<li><a href='#'>中国总机</a></li>");
document.write("<ul id='sub5'>");
document.write("<li><a href='/aboutus/about_us.shtml'>关于我们</a></li>");
document.write("<li><a href='/aboutus/news.shtml'>总机动态</a></li>");
document.write("<li><a href='/aboutus/zhaopin.shtml'>人员招聘</a></li>");
document.write("<li><a href='/aboutus/background.shtml'>投资关系</a></li>");
document.write("<li><a href='/aboutus/cooperates.shtml'>联盟合作</a></li>");
document.write("<li><a href='/aboutus/site_map.shtml'>网站地图</a></li>");
document.write("<li><a href='/aboutus/touch_us.shtml'>联系我们</a></li>");
document.write("</ul>");
document.write("</ul>");
document.write("</div>");

initSlideDownMenu();

}
	
function popMenusToShow()
{
	var obj = divToScroll;
	var endArray = new Array();
	while(obj && obj.tagName!='BODY'){
		if(obj.tagName=='DIV' && obj.id.indexOf('slideDiv')>=0){
			var objFound = -1;
			for(var no=0;no<otherDivsToScroll.length;no++){
				if(otherDivsToScroll[no]==obj){
					objFound = no;		
				}					
			}	
			if(objFound>=0){
				otherDivsToScroll.splice(objFound,1);	
			}		
		}	
		obj = obj.parentNode;
	}	
}

function showSubMenu(e,inputObj)
{

	if(this && this.tagName)inputObj = this.parentNode;
	if(inputObj && inputObj.tagName=='LI'){
		divToScroll = inputObj.getElementsByTagName('DIV')[0];
		for(var no=0;no<otherDivsToScroll.length;no++){
			if(otherDivsToScroll[no]==divToScroll)return;
		}			
	}
	hidingInProcess = false;
	if(otherDivsToScroll.length>0){
		if(divToScroll){				
			if(otherDivsToScroll.length>0){
				popMenusToShow();
			}
			if(otherDivsToScroll.length>0){	
				autoHideMenus();
				hidingInProcess = true;
			}
		}	
	}		
	if(divToScroll && !hidingInProcess){
		divToScroll.style.display='';
		otherDivsToScroll.length = 0;
		otherDivToScroll = divToScroll.parentNode;
		otherDivsToScroll.push(divToScroll);	
		while(otherDivToScroll && otherDivToScroll.tagName!='BODY'){
			if(otherDivToScroll.tagName=='DIV' && otherDivToScroll.id.indexOf('slideDiv')>=0){
				otherDivsToScroll.push(otherDivToScroll);
									
			}
			otherDivToScroll = otherDivToScroll.parentNode;
		}			
		ulToScroll = divToScroll.getElementsByTagName('UL')[0];
		if(divToScroll.style.height.replace('px','')/1<=1)scrollDownSub();
	}	
	

}



function autoHideMenus()
{
	if(otherDivsToScroll.length>0){
		divToHide = otherDivsToScroll[otherDivsToScroll.length-1];
		parentDivToHide.length=0;
		var obj = divToHide.parentNode.parentNode.parentNode;
		while(obj && obj.tagName=='DIV'){			
			if(obj.id.indexOf('slideDiv')>=0)parentDivToHide.push(obj);
			obj = obj.parentNode.parentNode.parentNode;
		}
		var tmpHeight = (divToHide.style.height.replace('px','')/1 - slideMenuHeightOfCurrentBox);
		if(tmpHeight<0)tmpHeight=0;
		if(slideMenuHeightOfCurrentBox)divToHide.style.height = tmpHeight  + 'px';
		ulToHide = divToHide.getElementsByTagName('UL')[0];
		slideMenuHeightOfCurrentBox = ulToHide.offsetHeight;
		scrollUpMenu();		
	}else{
		slideMenuHeightOfCurrentBox = 0;
		showSubMenu();			
	}
}


function scrollUpMenu()
{

	var height = divToHide.offsetHeight;
	height-=15;
	if(height<0)height=0;
	divToHide.style.height = height + 'px';

	for(var no=0;no<parentDivToHide.length;no++){	
		parentDivToHide[no].style.height = parentDivToHide[no].getElementsByTagName('UL')[0].offsetHeight + 'px';
	}
	if(height>0){
		setTimeout('scrollUpMenu()',5);
	}else{
		divToHide.style.display='none';
		otherDivsToScroll.length = otherDivsToScroll.length-1;
		autoHideMenus();			
	}
}	

function scrollDownSub()
{
	if(divToScroll){			
		var height = divToScroll.offsetHeight/1;
		var offsetMove =Math.min(15,(ulToScroll.offsetHeight - height));
		height = height +offsetMove ;
		divToScroll.style.height = height + 'px';

		for(var no=1;no<otherDivsToScroll.length;no++){
			var tmpHeight = otherDivsToScroll[no].offsetHeight/1 + offsetMove;
			otherDivsToScroll[no].style.height = tmpHeight + 'px';
		}			
		if(height<ulToScroll.offsetHeight)setTimeout('scrollDownSub()',5); else {
			divToScroll = false;
			ulToScroll = false;
			if(objectsToExpand.length>0 && initExpandIndex<(objectsToExpand.length-1)){
				initExpandIndex++;
				
				showSubMenu(false,objectsToExpand[initExpandIndex]);
			}
		}
	}
}
	
function initSubItems(inputObj,currentDepth)
{		
	divCounter++;		
	var div = document.createElement('DIV');	// Creating new div		
	div.style.overflow = 'hidden';	
	div.style.position = 'relative';
	div.style.display='none';
	div.style.height = '1px';
	div.id = 'slideDiv' + divCounter;
	div.className = 'slideMenuDiv' + currentDepth;		
	inputObj.parentNode.appendChild(div);	// Appending DIV as child element of <LI> that is parent of input <UL>		
	div.appendChild(inputObj);	// Appending <UL> to the div
	var menuItem = inputObj.getElementsByTagName('LI')[0];
	while(menuItem){
		if(menuItem.tagName=='LI'){
			var aTag = menuItem.getElementsByTagName('A')[0];
			aTag.className='slMenuItem_depth'+currentDepth;	
			var subUl = menuItem.getElementsByTagName('UL');
			if(subUl.length>0){
				initSubItems(subUl[0],currentDepth+1);					
			}
			aTag.onclick = showSubMenu;				
		}			
		menuItem = menuItem.nextSibling;						
	}		
}

function initSlideDownMenu()
{
	dhtmlgoodies_slmenuObj = document.getElementById('side_menu');
	dhtmlgoodies_slmenuObj.style.visibility='visible';
	var mainUl = dhtmlgoodies_slmenuObj.getElementsByTagName('UL')[0];		
	var mainMenuItem = mainUl.getElementsByTagName('LI')[0];
	mainItemCounter = 1;
	while(mainMenuItem){			
		if(mainMenuItem.tagName=='LI'){
			var aTag = mainMenuItem.getElementsByTagName('A')[0];
			aTag.className='slMenuItem_depth1';	
			var subUl = mainMenuItem.getElementsByTagName('UL');
			if(subUl.length>0){
				mainMenuItem.id = 'mainMenuItem' + mainItemCounter;
				initSubItems(subUl[0],2);
				aTag.onclick = showSubMenu;
				aTag.href = 'javascript:void(null)';
				mainItemCounter++;
			}				
		}			
		mainMenuItem = mainMenuItem.nextSibling;	
	}		
	
	if(location.search.indexOf('mainMenuItemToSlide')>=0){
		var items = location.search.split('&');
		for(var no=0;no<items.length;no++){
			if(items[no].indexOf('mainMenuItemToSlide')>=0){
				values = items[no].split('=');
				showSubMenu(false,document.getElementById('mainMenuItem' + values[1]));	
				initMenuIdToExpand = false;				
			}
		}			
	}else if(expandFirstItemAutomatically>0){
		if(document.getElementById('mainMenuItem' + expandFirstItemAutomatically)){
			showSubMenu(false,document.getElementById('mainMenuItem' + expandFirstItemAutomatically));
			initMenuIdToExpand = false;
		}
	}

	if(expandMenuItemByUrl)
	{
		var aTags = dhtmlgoodies_slmenuObj.getElementsByTagName('A');
		for(var no=0;no<aTags.length;no++){
			var hrefToCheckOn = aTags[no].href;	
			if(location.href.indexOf(hrefToCheckOn)>=0 && hrefToCheckOn.indexOf('#')<hrefToCheckOn.length-1){
				initMenuIdToExpand = false;
				var obj = aTags[no].parentNode;
				while(obj && obj.id!='side_menu'){
					if(obj.tagName=='LI'){							
						var subUl = obj.getElementsByTagName('UL');
						if(initialMenuItemAlwaysExpanded)alwaysExpanedItems[obj.parentNode] = true;
						if(subUl.length>0){								
							objectsToExpand.unshift(obj);
						}
					}
					obj = obj.parentNode;	
				}
				showSubMenu(false,objectsToExpand[0]);
				break;					
			}			
		}
	}
			
	if(initMenuIdToExpand)
	{
		objectsToExpand = new Array();
		var obj = document.getElementById(initMenuIdToExpand)
		while(obj && obj.id!='side_menu'){
			if(obj.tagName=='LI'){
				var subUl = obj.getElementsByTagName('UL');
				if(initialMenuItemAlwaysExpanded)alwaysExpanedItems[obj.parentNode] = true;
				if(subUl.length>0){						
					objectsToExpand.unshift(obj);
				}
			}
			obj = obj.parentNode;	
		}
		
		showSubMenu(false,objectsToExpand[0]);

	}
		
}