

var dateObj = new Date();
//检查是否登录
function check_login(){
	var flag = -1;
	var dateObj = new Date();
	var url_tmp = "/test";
	try{
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: url_tmp, //请求的处理数据 
		  async: false,
		  cache:false,
		  success:function(data,aa) {
			  flag = data.code;
		  },
		  error:function(data,aa) {
			  flag = data.code;
		  }
		});
	}catch(e){}
    if(flag == 0){
		return true;
	}else if(flag == -1){
		if(getcookie("loginflag") == 1){
			return true;
		}
	}else if(flag == 600){
		alert("请重新登录！");
		window.location = "/index.html";
	}
	return false;
}
function checkeddata(data){
	try{
		if(data.code == 600){
			alert("请重新登录！");
			window.location = "/index.html";
		}
	}catch(e){
		
	}
}
//登录
function login(){
	//？？？？？？？？？？？
}
function getmac(){
	var macstr = {"black":[],"white":[]};
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/getwhite", //请求的处理数据 
		  async: false,
		  cache:false,
		  success: function(data) {	
			  if(data.code==0){
				  macstr.white = data.maclist;
			  }
		  } 
		});
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/getblack", //请求的处理数据 
		  async: false,
		  cache:false,
		  success: function(data) {	
			  if(data.code==0){
				  macstr.black = data.maclist;
			  }
		  } 
		});
	return macstr;
}
//mac处理
function setmac(actionname,val,remark){
	var flag;
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/"+actionname, //请求的处理数据 
		  data: {"mac":val,"remark":remark},
		  async: false,
		  success: function(data) {	
			  checkeddata(data);
			  flag = data;
		  } 
		});
	return flag;
}
//退出登录
function login_out(){
	delcookie('loginflag');
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/logout", //请求的处理数据 
		  async: false,
		  cache:false,
		  success: function(data) {	
		  } 
		});
	 window.location = "/index.html";
}
//获取服务端系统状态信息
function get_system_info(){	
	var system_info;
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/qbacstat?t="+dateObj.getTime(), //请求的处理数据 
		  async: false,
		  success: function(data) {	
			  if(data.code == 0){
				  system_info = data;
				  system_info.currtime = system_info.currtime + 28800;
			  }else{
				  window.location = "/index.html";
			  }
		  } 
		});
	return system_info;
}
//获取网吧的用户数
function get_cyber_user(cyber_id,callfun){
	var user_cnt = 0;
	var interface_url_tmp = BASE64.encode(interface_url + "bac/get_cyber_user_cnt?cyber_id="+cyber_id);

	var user_cnt = "";
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/proxy?url="+interface_url_tmp+"&t="+dateObj.getTime(), //请求的处理数据 
		  success: function(data) {
			  checkeddata(data);
			  user_cnt = eval(data.responseText);
			  if(callfun=='initusernum'){
				  initusernum(user_cnt);
			  }else{
				  eval(callfun+'('+user_cnt.send_cnt+','+user_cnt.receive_cnt+','+user_cnt.back_cnt+','+user_cnt.user_cnt+')');
			  }
		  },
		  error: function(data){
			  checkeddata(data);
			  user_cnt = eval(data.responseText);
			  if(callfun=='initusernum'){
				  initusernum(user_cnt);
			  }else{
				  eval(callfun+'('+user_cnt.send_cnt+','+user_cnt.receive_cnt+','+user_cnt.back_cnt+','+user_cnt.user_cnt+')');
			  }
		  }
		});
	
}

if( typeof(sitetype) == 'undefined'){
	var sitetype=1;
}

//初始化左侧菜单
function init_menu(){
	var behavior=sitetype==1?'behavioral':'behavioral-tenant';
	var page_behavior=sitetype==1?'behavioral.html':'behavioral-tenant.html';
	var menu_obj = [{"actype":"bac,xac","id":"home-page","title":"首页","src":"home-page.html","subid":"1"},
	                {"actype":"xac","id":"equipment-setting","title":"基本设置","src":"equipment-setting.html","subid":"10"},
	                {"actype":"bac,xac","id":"cyberinfo","title":"场所信息","src":"cyberinfo.html","subid":"9"},
					{"actype":"bac,xac","id":"flow-control","title":"流量控制","src":"flow-control.html","subid":"2"},					
					{"actype":"bac,xac","id":behavior,"title":"上网行为控制","src":page_behavior,"subid":"3"},
					{"actype":"bac,xac","id":"msg","title":"消息推送","src":"msg.html","subid":"4"},
					{"actype":"bac,xac","id":"portal-setting-new","title":"Portal页设置","src":"portal-setting-new.html","subid":"5"},
					{"actype":"bac,xac","id":"bw-list","title":"黑白名单设置","src":"bw-list.html","subid":"6"},
					{"actype":"bac,xac","id":"system-info","title":"设备信息","src":"system-info.html","subid":"7"},					
					{"actype":"bac,xac","id":"password-setting","title":"密码管理","src":"password-setting.html","subid":"8"}];
	var menu_str = "";
	var classname = "";
	var li_id = getcookie("menu_cur_id");
	var file_name = get_file_name(window.location.href);
	if(li_id == "" || (li_id != file_name && file_name != "msg-list")){
		li_id = file_name;
	}
	var actypestr="bac";
	if(typeof(acmodelobj) ==='undefined' || typeof(acmodelobj.actype)==='undefined' || acmodelobj.actype === 0){
		actypestr="bac"; 
	}else if(acmodelobj.actype === 1){
		actypestr="xac"; 
	}
	for(key in menu_obj){
		if(menu_obj[key].actype.indexOf(actypestr) >= 0){
			classname = "";
			if(li_id == menu_obj[key].id){
				classname = ' class="act"';
			}
			menu_str += '<li id="'+menu_obj[key].id+'"'+classname+'><i class="arr"></i><a href="'+menu_obj[key].src+'" class="sub'+menu_obj[key].subid+'" onclick="addcookie(\'menu_cur_id\',\''+menu_obj[key].id+'\',0);return true;">'+menu_obj[key].title+'</a></li>';
		}
	}
	$("#ul_menu").html(menu_str);
	$(".loginArea").html('admin &nbsp;&nbsp;<span class="loginBtn" onclick="login_out();">退出</span>');
}

//修改密码
function update_pwd(oldpwd,newpwd1,newpwd2){
	if($.trim(oldpwd) == ""){
		return 1;
	}
	if($.trim(newpwd1) == "" || newpwd1.length<6 || newpwd1.length>16){
		return 2;
	}
	if($.trim(newpwd2) == "" || newpwd2.length<6 || newpwd2.length>16){
		return 3;
	}
    if(newpwd1 != newpwd2){
		return 4;
	}
	var flag = -1;
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/updatepwd?t="+dateObj.getTime(), //请求的处理数据 
		  data: {"old":oldpwd,"new":newpwd2},
		  async: false,
		  success: function(data) {	
			  checkeddata(data);
			  if(data.code == 0){
				  flag = 0;
			  }
		  } 
		});
	return flag;
}
//手机终端信息
function stainfos(){
	var statdata;
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/stainfos?t="+dateObj.getTime(), //请求的处理数据 
		  async: false,
		  success: function(data) {	
			  statdata = data;
		  } 
		});
	return statdata;
}
//踢出手机终端
function kicksta(macval){
	var statdata;
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/kicksta?t="+dateObj.getTime(), //请求的处理数据 
		  data: {"sta":macval},
		  async: false,
		  success: function(data) {	
			  checkeddata(data);
			  statdata = data;
		  } 
		});
	return statdata;
}
//设置上行下行速率
function flowctrl(urate,drate,sur,sdr){
	var flowctrlval;
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/flowctrl?t="+dateObj.getTime(), //请求的处理数据 
		  data: {"urate":urate,"drate":drate,"sur":sur,"sdr":sdr},
		  async: false,
		  success: function(data) {
			  checkeddata(data);
			  flowctrlval = data;
		  } 
		});
	return flowctrlval;
}
//反馈
function feedback(cyber_id,content){
	content = $.trim(content);
	if(content.length <=5 || content == "请输入要反馈的问题"){
		alert("请输入要反馈的问题！");
		return false;
	}
	var interface_url_tmp = BASE64.encode(interface_url + "bac/feedback?cyber_id="+cyber_id+"&content="+encodeURI(content));
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/proxy?url="+interface_url_tmp+"&t="+dateObj.getTime(), //请求的处理数据 
		  success: function(data) {
			  checkeddata(data);
			  if(data == 0){
				  alert("反馈成功！");
			  }else{
				  alert("反馈失败！");
			  }			  
		  },
		  error: function(data){
			  checkeddata(data);
			  if(data == 0){
				  alert("反馈成功！");
			  }else{
				  alert("反馈失败！");
			  }	
		  }
		});	
	getfeedback(cyber_id);
}
function getfeedback(cyber_id){
	var feedbacklist;
	var interface_url_tmp = BASE64.encode(interface_url + "bac/getfeedback?cyber_id="+cyber_id);
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/proxy?url="+interface_url_tmp+"&t="+dateObj.getTime(), //请求的处理数据 
		  success: function(data) {
			  var listobj = data;
			  var feedbackstr = "<dt>反馈历史</dt>";
			  for(key in listobj){
				feedbackstr = feedbackstr + "<dd>"+listobj[key].submit_time+"  "+listobj[key].question+"</dd>";		
				  }
			  $("#feedbackhistory").html(feedbackstr);		  
		  },
		  error: function(data){
			  var listobj = data;
			  var feedbackstr = "<dt>反馈历史</dt>";
			  for(key in listobj){
				  feedbackstr = feedbackstr + "<dd>"+listobj[key].submit_time+"  "+listobj[key].question+"</dd>";		
			  }
			  $("#feedbackhistory").html(feedbackstr);		  
		  }
		});
}
function getusers(cyber_id,pagecnttmp){
	var interface_url_tmp = BASE64.encode(interface_url + "bac/getusers?cyber_id="+cyber_id);
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: "/proxy?url="+interface_url_tmp+"&t="+dateObj.getTime(), //请求的处理数据 
		  success: function(data) {
			  initpage(data);
		  },
		  error: function(data){
			  initpage(data);
		  }
		});
}
function initsystem(){
	//判断登录状态
	if(check_login()){
		
	}else{
		window.location = "/index.html";
	}
}

setInterval(function() {
	var flag = -1;
	var dateObj = new Date();
	var url_tmp = "/test";
	try{
	$.ajax({ //这里使用到Jquery的ajax方法
		  type: "GET", 
		  dataType: "json", //json
		  url: url_tmp, //请求的处理数据 
		  cache:false,
		  success:function(data,aa) {
			  if(data.code == 600){
					alert("请重新登录！");
					window.location = "/index.html";
			  } 
		  },
		  error:function(data,aa) {
			  if(data.code == 600){
					alert("请重新登录！");
					window.location = "/index.html";
			  } 
		  }
		});
	}catch(e){}
}, 5000);

