function initbody(){
	objcont = $('#content_allmainview');
	objtabs = $('#tabs_title');
	menubadge = hongbadge = menutopid = {};//角标数组
	resizewh();
	$(window).resize(resizewh);
	clickhome();
	if(show_key!='')jm.setJmstr(jm.base64decode(show_key));
	var a = $("li[pmenuid]");
	a.click(function(){
		if(js.ajaxbool)return;
		a.removeClass('topactive');
		loadmenu(this);
	});
	loadmenu($("li[pmenuid]")[0]);
	if(typeof(FormData)=='undefined'){
		js.msg('msg','您的浏览器太低了无法达到想要的预览效果<br>建议使用IE10+，Firefox，Chrome等高级点的',60);
	}
	if(get('indexuserl')){
		var ddsata=[{
			name:'<i class="icon-cog"></i> 个人设置',num:'grcog','icon':'cog',url:'system,geren,cog',names:'个人设置'
		},{
			name:'<i class="icon-bell"></i> 提醒信息',num:'todo','icon':'bell',url:'system,geren,todo',names:'提醒信息'
		},{
			name:'<i class="icon-picture"></i> 修改头像',num:'face','icon':'picture'
		},{
			name:'<i class="icon-laptop"></i> 旧版首页',num:'jiu','icon':'laptop'
		},{
			name:'<i class="icon-certificate"></i> 新版首页1',num:'jiu1','icon':'laptop'
		},{
			name:'<i class="icon-user"></i> 帐号('+adminuser+')',num:'user'
		}];
		if(js.request('afrom')=='')ddsata.push({name:'<i class="icon-signout"></i> 退出',num:'exit'});
		$('#indexuserl').rockmenu({
			width:150,top:get('tabsindexm').offsetHeight,
			data:ddsata,
			itemsclick:function(d){
				if(d.num=='exit'){
					js.confirm('确定要退出系统吗？',function(bn){
						if(bn=='yes')js.location('?m=login&a=exit');
					});
					return;
				}
				if(d.num=='face'){
					editfacechang(adminid, adminname);
					return;
				}
				if(d.num=='jiu'){
					js.location('?m=index');
					return;
				}
				if(d.num=='jiu1'){
					js.location('?a=home');
					return;
				}
				if(d.num=='user')return;
				addtabs({num:d.num,url:d.url,name:d.names,icons:d.icon});
			}
		});
	}
	$('#reordershla').click(function(){
		$('#mainleft').toggle();
		resizewh();
	});
	_addbodykey();
	$('#indesearchmenu').click(function(){
		_searchmenus();
	});
	
	function _loadjsurl(){
		js.importjs('web/res/mode/echarts/echarts.common.min.js');
	}
	setTimeout(_loadjsurl,100);
	
	//禁止后退
	$(document.body).keydown(function(e){
		var lxs = e.target.nodeName.toLowerCase();
		var bo  = (lxs=='input' || lxs=='textarea');
		if(e.keyCode==8 && !bo)return false;
	});
	try{
		history.pushState(null, null, document.URL);
		window.addEventListener('popstate', function (){
			history.pushState(null, null, document.URL);
		});
	}catch(e){}
	
	js.addbody('topdimenu', 'hide', 'topdimenu',showmenuhide);
	$('#zhuind03').click(function(){
		showmenunew();
		return false;
	});
	$('#moretabs').click(function(){
		showmoretabs(this);
		return false;
	});
}


function _searchmenus(){
	js.prompt('搜索菜单','请输入搜索菜单名：',function(jg,txt){
		if(jg=='yes' && txt){
			$('#menulisttop').html('搜索结果');
			$('#menulist').html('<div style="padding:30px;" align="center"><img src="images/mloading.gif"></div>');
			js.ajax(js.getajaxurl('getmenusou','index'),{key:txt}, function(da){
				showmenula(da);
			},'post,json');
		}
	});
}
var loadmenuci=0;
function loadmenu(o){
	var o1 = $(o),id,s1,ico;
	o1.addClass('topactive');id = o1.attr('pmenuid');ico = o1.attr('icon');
	if(!id)return;
	loadmenuci++;
	s1 = o.title;
	if(ico)s1='<i class="icon-'+ico+'"></i> '+s1+'';
	$('#menulisttop').html(s1);
	showmenupid = id;
	showmenuhide();
	$('#menulist').html('<div style="padding:30px;" align="center"><img src="images/mloading.gif"></div>');
	js.ajax(js.getajaxurl('getmenu','index'),{pid:id,loadci:loadmenuci}, function(da){
		if(da.menutopid)menutopid=da.menutopid;
		showmenula(da.menuarr);
	},'get,json');
}
function showmenula(a){
	menuarr = a;
	var i,s='',j,k,child,hhild,css1,to,sid,o;
	hongbadge={};
	for(i=0; i<a.length; i++){
		o   = a[i];
		css1='border-radius:0px;border-left:none;border-right:none;cursor:pointer;TEXT-DECORATION:none';
		s+='<a onClick="clickmenu(this,'+i+',-1,-1)" style="'+css1+'"><i class="icon-'+o.icons+'"></i> '+o.name+'';
		if(o.bh && o.stotal==0)s+=' <span class="badge" badge="'+o.bh+'" style="float:none;display:none;background:red;color:white"></span>';
		if(o.stotal>0)s+='<font color="red" id="hongdian_'+o.num+'" style="display:none">●</font><span style="float:right" id="menu_down_isons_'+o.num+'" class="icon-caret-down"></span>';
		s+='</a>';
		if(o.stotal>0){
			child = o.children;
			for(j=0; j<child.length; j++){
				o = child[j];
				s+='<a downmenu="'+i+'_'+j+'" style="'+css1+';padding-left:30px;background:rgba(0,0,0,0.05);display:none" id="menu_list_'+o.num+'" onClick="clickmenu(this,'+i+','+j+',-1)"><i class="icon-'+o.icons+'"></i> '+o.name+'';
				if(o.bh){
					hongbadge[o.bh]=a[i].num;
					s+=' <span class="badge" badge="'+o.bh+'" style="float:none;display:none;background:red;color:white"></span>';
				}
				if(o.stotal>0)s+='<span style="float:right" id="menu_down_isons_'+o.num+'" class="icon-caret-down"></span>';
				s+='</a>';
				if(o.stotal>0){
					hhild = o.children;
					for(k=0; k<hhild.length; k++){
						o = hhild[k];
						s+='<a downmenu="'+i+'_'+j+'_'+k+'" style="'+css1+';padding-left:60px;background:rgba(0,0,0,0.02);display:none" id="menu_list_'+o.num+'" onClick="clickmenu(this,'+i+','+j+','+k+')"><i class="icon-'+o.icons+'"></i> '+o.name+'</a>';
					}
				}	
			}
		}
	}
	if(s=='')s='<div style="padding:30px;color:#cccccc" align="center">暂无</div>';
	$('#menulist').html(s);
	$('#menulist').perfectScrollbar('destroy');
	$('#menulist').perfectScrollbar();
	showmenubadge();
}
//显示角标处理
function showmenubadge(){
	var o,sid,to,tnu,tid,o1;
	$('li[pmenuid] font').remove();
	for(sid in menubadge){
		to = menubadge[sid];
		o = $('span[badge="'+sid+'"]');
		tnu= hongbadge[sid];
		if(o){if(to<=0){
			o.hide();
			if(tnu)$('#hongdian_'+tnu+'').hide();
		}else{
			o.show();o.html(to);
			if(tnu)$('#hongdian_'+tnu+'').show();
			tid= menutopid[sid];
			if(tid){
				o1 = $('li[pmenuid="'+tid+'"]');
				o1.find('font').remove();
				o1.append('<font color="red">●</font>');
			}
		}}
	}
	var lens = $('li[pmenuid] font').length;
	if(lens>0){$('#zhuhongdi').show();}else{$('#zhuhongdi').hide();}
}
function removetadge(num){
	if(typeof(menubadge[num])=='undefined')return;
	$('span[badge="'+num+'"]').hide();
	menubadge[num]=0;
	showmenubadge();
}

function opentixiang(){
	addtabs({num:'todo',url:'system,geren,todo',icons:'bell',name:'提醒信息'});
	return false;
}

function clickhome(){
	var ad = {num:'home',url:'home,index',icons:'home',name:'首页',hideclose:true};
	if(homeurl!='')ad.url= homeurl;
	if(homename!='')ad.name= homename;
	addtabs(ad);
	return false;
}
var fistwk=0;
function resizewh(){
	var _wl = 230;
	if(get('mainleft').style.display=='none')_wl=0;
	var w = winWb()-_wl;
	var h = winHb();
	viewwidth  = w; 
	viewheight = h-60;
	$('#indexcontent').css({width:''+viewwidth+'px',height:''+(viewheight)+'px'});
	$('#tabsindexm').css({width:''+viewwidth+'px'});
	$('#menulist').css({height:''+(viewheight-40)+'px'});
	viewheight-=25;
	_changhhhsv();
}

function clickmenu(o, i, j,k){
	var a = menuarr[i];
	if(j>-1)a=a.children[j];
	if(k>-1)a=a.children[k];
	var oi = a.stotal,dxu=''+i+'_';
	if(oi>0){
		$('#hongdian_'+a.num+'').hide();//隐藏红点
		if(j>-1){
			dxu+=''+j+'_';
			$('a[downmenu^="'+dxu+'"]').toggle();
		}
		var o1	= get('menu_down_isons_'+a.num+'');
		if(o1.className.indexOf('down')>0){
			o1.className='icon-caret-up';
			if(j==-1)$('a[downmenu^="'+dxu+'"]').show();
		}else{
			o1.className='icon-caret-down';
			if(j==-1)$('a[downmenu^="'+dxu+'"]').hide();
		}
	}else{
		addtabs(a);
	}
}

var coloebool = false;
function closetabs(num){
	tabsarr[num] = false;
	$('#content_'+num+'').remove();
	$('#tabs_'+num+'').remove();
	if(num == nowtabs.num){
		var now ='home',i,noux;
		for(i=opentabs.length-1;i>=0;i--){
			noux= opentabs[i];
			if(get('content_'+noux+'')){
				now = noux;
				break;
			}
		}
		changetabs(now);
	}
	coloebool = true;
	_changhhhsv();
	setTimeout('coloebool=false',10);
}

function closenowtabs(){
	var nu=nowtabs.num;
	if(nu=='home')return;
	closetabs(nu);
}

function nowtabssettext(srt,icos){
	var num=nowtabs.num;
	var txt = srt;
	tabsarr[num].name = srt;
	nowtabs.name = srt;
	if(!icos)icos=nowtabs.icons;
	if(icos)txt='<i class="icon-'+icos+'"></i>  '+txt+'';
	$('#tabs_'+num+' font').html(txt);
	_changhhhsv();
}

function changetabs(num,lx){
	if(coloebool)return;
	if(!lx)lx=0;
	$("div[temp='content']").hide();
	$("[temp='tabs']").removeClass();
	var bo = false;
	if(get('content_'+num+'')){
		$('#content_'+num+'').show();
		$('#tabs_'+num+'').addClass('active');
		nowtabs = tabsarr[num];
		if(typeof(nowtabs.onshow)=='function')nowtabs.onshow();
		bo = true;
	}
	opentabs.push(num);
	if(lx==0)_changhhhsv(num);
	return bo;
}
function _changhhhsv(num){
	var mwd = $('#tabsindexm').width();
	var obj = $('#tabs_title').find('li'),sw1=0;
	for(var i=0;i<obj.length;i++){
		if(obj[i].id!='moretabs')sw1+=obj[i].offsetWidth;
	}
	if(sw1>=mwd){
		$('#moretabs').show();
	}else{
		$('#moretabs').hide();
	}
}
function _changesrcool(lx){
	
}
function _pdleftirng(){
	
}

function addiframe(a){
	a.url = 'index,iframe,url='+jm.base64encode(a.url)+'';
	addtabs(a);
}


//选择卡右键
function tabsright(num,e){
	function _closeother(nu){
		var nus,d1;
		for(nus in tabsarr){
			d1 = tabsarr[nus];
			if(d1 && !d1.hideclose && nus!=nu)closetabs(nus);
		}
	}
	if(typeof(tabsrights)=='undefined')tabsrights=$.rockmenu({
		width:150,
		data:[],
		itemsclick:function(d){
			var lx = d.lx,num=d.num;
			if(lx==0)closetabs(num);
			if(lx==1){
				var d1 = tabsarr[num],s1=''+PROJECT+'/'+d1.urlpath+'';
				var s  = '['+d1.name+']页面地址是：'+s1+'<div style="word-wrap:break-word;">，在[系统→基础管理→菜单管理]设置URL地址为：'+d1.url+'';
				if(HOST=='127.0.0.1' || HOST=='localhost')s+='&nbsp;<a onclick="_openfile(\''+jm.base64encode(s1)+'\')" href="javascript:;">[打开]</a>';
				s+='</div>';
				js.alert(s);
			}
			if(lx==2)_closeother(num);
			if(lx==3)location.reload();
			if(lx==4)_opentabls(d.tobj);
		}
	});
	var to= tabsarr[num],d = [];
	if(!to.hideclose)d.push({'name':'关闭','num':num,lx:0});
	if(num==nowtabs.num)d.push({'name':'关闭其它页面','num':num,lx:2});
	if(admintype==1)d.push({'name':'查看页面地址','num':num,lx:1});
	if(homeurl=='' && to.id)d.push({'name':'新窗口打开',tobj:to,'num':num,lx:4});
	d.push({'name':'全部刷新','num':num,lx:3});
	tabsrights.setData(d);
	tabsrights.showAt(e.clientX,e.clientY+5);
}
function _opentabls(d){
	var url = '?homeurl='+jm.base64encode(d.url)+'&homename='+jm.base64encode(d.name)+'&menuid='+jm.base64encode(d.id)+'';
	window.open(url);
}

//开发时打开文件
function _openfile(s){
	js.ajax(js.getajaxurl('openfile','index'),{file:s},function(ds){
		if(ds!='ok')js.msg('msg', ds);
	},'get');
}

/**
*	添加选择卡
*/
function addtabs(a){
	var url = a.url,
		num	= a.num;
	if(isempt(url))return false;
	removetadge(num);
	if(url.indexOf('add,')==0){openinput(a.name,url.substr(4));return;}
	if(url.indexOf('open:')==0){window.open(url.substr(5));return;}
	if(url.indexOf('http')==0 || url.substr(0,1)=='?'){addiframe(a);return;}
	if(nowtabs && nowtabs.id && !a.id)a.id=nowtabs.id;
	nowtabs = a;
	if(changetabs(num))return true;

	var s = '<li temp="tabs" oncontextmenu="tabsright(\''+num+'\',event);return false;"; nowrap onclick="changetabs(\''+num+'\',1)" id="tabs_'+num+'" class="active"><font>';
	if(a.icons)s+='<i class="icon-'+a.icons+'"></i>  ';
	s+=a.name+'</font>';
	if(!a.hideclose)s+='<span onclick="closetabs(\''+num+'\')"><img src="images/del.png" width="12" height="12"></span>';
	s+='</li>';
	objtabs.append(s);
	_changhhhsv(num);
	_pdleftirng();
	
	var rand = js.getrand(),i,oi=2,
		ura	= url.split(','),
		dir	= ura[0],
		mode= ura[1];
	url =''+dir+'/'+mode+'/rock_'+mode+'';
	if(ura[2]){
		if(ura[2].indexOf('=')<0){
			oi=3;
			url+='_'+ura[2]+'';
		}
	}
	var urlpms= '';
	for(i=oi;i<ura.length;i++){
		var nus	= ura[i].split('=');
		urlpms += ",'"+nus[0]+"':'"+nus[1]+"'";
	}
	if(urlpms!='')urlpms = urlpms.substr(1);
	var bgs = '<div id="mainloaddiv" style="width:'+viewwidth+'px;height:'+viewheight+'px;overflow:hidden;background:#000000;color:white;filter:Alpha(opacity=20);opacity:0.2;z-index:3;position:absolute;left:0px;line-height:'+viewheight+'px;top:0px;" align="center"><img src="images/mloading.gif"  align="absmiddle">&nbsp;加载中...</div>';
	$('#indexcontent').append(bgs);
	a.urlpath = url+'.php';
	objcont.append('<div temp="content" style="margin:10px;" id="content_'+num+'"></div>');
	$.ajax({
		url:'?m=index&a=getshtml&surl='+jm.base64encode(url)+'&num='+num+'&menuname='+jm.base64encode(a.name)+'&urlpms='+jm.base64encode(urlpms)+'',
		type:'get',
		success: function(da){
			$('#mainloaddiv').remove();
			var s = da;
				s = s.replace(/\{rand\}/gi, rand);
				s = s.replace(/\{adminid\}/gi, adminid);
				s = s.replace(/\{adminname\}/gi, adminname);
				s = s.replace(/\{mode\}/gi, mode);
				s = s.replace(/\{dir\}/gi, dir);
				s = s.replace(/\{params\}/gi, "var params={"+urlpms+"};");
			var obja = $('#content_'+num+'');
			if(num!='home')s='<div style="background:white;overflow:auto;border-radius:5px"><div style="padding:10px">'+s+'</div></div>';
			obja.html(s);
		},
		error:function(){
			$('#mainloaddiv').remove();
			var s = 'Error:加载出错喽,'+url+'';
			$('#content_'+num+'').html(s);
		}
	});
	tabsarr[num] = a;
	return false;
}

//新增的
function showmenunew(){
	if(get('topdimenu').style.display!='none'){
		showmenuhide();
		return;
	}
	var o1 = $('#zhuind03');
	$('#topdimenu').show();
	var hei = $('#topdimenu').height();
	if(hei<450)hei=450;
	var offs = o1.offset();
	get('topdimenu').style.left=''+offs.left+'px';
	//o1.addClass('topactive1');
}
function showmenuhide(){
	//$('#zhuind03').removeClass('topactive1');
	$('#topdimenu').hide();
}
var showmoretabsobj=false;
function showmoretabs(o1){
	var da = [],nu,st1,d1;
	for(nu in tabsarr){
		d1 = tabsarr[nu];
		if(d1){
			st1 = d1.name;
			if(d1.icons)st1='<i class="icon-'+d1.icons+'"></i> '+st1+'';
			if(nu==nowtabs.num)st1='<b style="color:'+maincolor+'">'+st1+'</b>';
			da.push({num:nu,name:st1});
		}
	}
	if(!showmoretabsobj)showmoretabsobj=$(o1).rockmenu({
		width:150,top:get('tabsindexm').offsetHeight,
		data:da,
		itemsclick:function(d){
			changetabs(d.num);
		}
	});
	showmoretabsobj.setData(da);
	showmoretabsobj.showAt();
}