var xml_mac="macauth.xml?rc=";
var mac_count = 0;
var mac_count_search = 0;
var mac_row_count=32;
var max_number=64;
var vlan_enable_v=new Array(
"1",
"1",
"1",
"")
var vlan_name_v=new Array(
"LAN",
"",
"",
"")
function swmacList(Nbtn)
{
var filterv = $("#s_type").val();
var t_filter = $("#t_filter").val();
var t=new Date();
document.getElementById("button_p").innerHTML="<input type=\"button\" id=\"_syslogd_0\" name=btnPre_mac value=\"Previous\" onclick=\"setPage('mac',2,2)\" disabled>";
document.getElementById("button_n").innerHTML="<input type=\"button\" id=\"_wary_0\" name=btnNext_mac value=\"Next\" onclick=\"setPage('mac',1,2)\" disabled>";
if(filterv == 0) xmlDoc=loadXMLDocs("macauthlist.xml?rc=");
else xmlDoc=loadXMLDocs(xml_mac+"&Nmode="+filterv+"&Sdescript="+t_filter);
if(xmlDoc==null)return;
var table_str2 = "";
var ary_index=0;
var chk_add = 0;
sw_mac_list=[];
mac_count_search=0;
x=xmlDoc.getElementsByTagName("row");
for (i = 0; i < max_number ; i++)
{
var xml_index= xml_getvalue(xmlDoc,"rule_index",i);
var nickname= xml_getvalue(xmlDoc,"nickname",i);
var name= xml_getvalue(xmlDoc,"name",i);
var pwd= xml_getvalue(xmlDoc,"pwd",i);
if(name != "" && name !="00:00:00:00:00:00")
{
++mac_count_search;
table_str2 += "<tr align=center>";
table_str2 += "<td>"+(i+1)+"</td>";
table_str2 += "<td>";
table_str2 += "<span id='sw_nname_"+(i+1)+"'>"+nickname+"</span>";
table_str2 += "</td>";
table_str2 += "<td id='sw_name_"+(i+1)+"'>"+name+"</td>";
table_str2 += "<td>";
table_str2 += "<span id='sw_pwd_"+(i+1)+"'>"+pwd+"</span>";
table_str2 += "</td>";
table_str2 += "<td align=left>";
table_str2 += "<input type='button' id='_wary_0' value='"+GetElmCont("wary_0","Edit")+"' onclick='List_Edit("+(i+1)+",1,"+xml_index+")' style='margin-left:3px'>";
table_str2 += "<input type='hidden' id='h_search' value='1'>";
table_str2 += "<input type='checkbox' id='c_edit_"+(i+1)+"' style='display:none'>";
table_str2 += "<input type='checkbox' id='c_del_"+(i+1)+"' name='_del' value='"+xml_index+"'>"+GetElmCont("wary_0","Select");
table_str2 += "</td>";
chk_add =  chk_add + 1;
sw_mac_list[ary_index] = table_str2;
if(chk_add == mac_row_count){
table_str2 = "";
chk_add = 0;
ary_index = ary_index + 1;
}
}
}
Ncmd=document.getElementById("Nmaccmd");
last_Ncmdv=0;
if(sw_mac_list.length>0){
last_Ncmdv=sw_mac_list.length-1;
}
if(Ncmd.value>last_Ncmdv){
Ncmd.value = 0;
}
setPage("mac",0,2)
}
function setFilterMac(val,Nbtn,edit_idx)
{
var chk=0;
var filterv = "";
var t_filter = "";
var Sfilter="";
var Sfilterv="";
var Ntype=0;
if(val==0){
filterv = $("#s_type").val();
t_filter = $("#t_filter").val();
document.getElementById("h_stype").value=filterv;
document.getElementById("h_tfilter").value=t_filter;
}else{
filterv = $("#h_stype").val();
t_filter = $("#h_tfilter").val();
}
if(filterv==0){ //None
Sfilter="";
Sfilterv="";
Ntype=0;
chk=1;
xml_mac="macauthlist.xml?rc=";
}else{
Sfilter=filterv;
Sfilterv=t_filter;
Ntype=1;
chk=1;
}
if(chk==1){
$.ajax({
url:xml_mac+"&Nmode="+filterv+"&Sdescript="+Sfilterv,
type: 'GET',
dataType: 'xml',
error: function(xml){
},
success: function(xml){
swList(Nbtn,edit_idx);
}
})
}
}
function List_delete()
{
var f=document.forms[0];
var div_obj =  document.getElementById("d_hidden_element");
var account_str = "";
var iframe = document.getElementById("hide");
var checkbox = document.getElementsByName("_del");
var checkbox_length = document.getElementsByName("_del").length;
for(var a=checkbox_length-1;a>=0;a--)
{
if(checkbox[a].checked)
{
chk_idx = checkbox[a].value;
nickname_arr.splice(chk_idx,1);
name_arr.splice(chk_idx,1);
pwd_arr.splice(chk_idx,1);
}
}
for(var x = 0;x < mac_count;x++)
{
var nickname_value = (nickname_arr[x] != undefined)?nickname_arr[x]:"";
var name_value = (name_arr[x] != undefined)?name_arr[x]:"";
var pwd_value = (pwd_arr[x] != undefined)?pwd_arr[x]:"";
account_str += "<input typt='text' name='"+nickname_csid_arr[x]+"' value='"+nickname_value+"'>";
account_str += "<input typt='text' name='"+name_csid_arr[x]+"' value='"+name_value+"'>";
account_str += "<input typt='text' name='"+pwd_csid_arr[x]+"' value='"+pwd_value+"'>";
}
div_obj.innerHTML = account_str;
f.submit();
}
function swList(Nbtn,edit_idx)
{
if(Nbtn==1){
var edit_num=document.getElementById("h_edit_num");
var del_num = document.getElementById("h_del_num")
if(edit_num.value==0&&del_num.value==0){
swmacList(Nbtn);
}
}
if(Nbtn==2){
swmacList(Nbtn);
}
}
function setPage(type,val,mod)
{
f = document.forms[0];
Ncmd=parseInt(document.getElementById("N"+type+"cmd").value);
row_count=eval(type+"_row_count"); //�C�����ܦ���
use_count=eval(type+"_count"); //�ثe�ϥμ�
if(val==0){
}else if(val==1){ //Next
Ncmd=Ncmd+1;
}else{
Ncmd=Ncmd-1;
}
document.getElementById("N"+type+"cmd").value=Ncmd;
page_end=parseInt(Ncmd)*row_count+row_count;
eval("f.btnPre_"+type+".disabled=(Ncmd==0)?true:false");
if(mod==1) eval("f.btnNext_"+type+".disabled=(use_count<=page_end||use_count==0)?true:false");
else eval("f.btnNext_"+type+".disabled=(mac_count_search<=page_end||mac_count_search==0)?true:false");
sw_lists(type,Ncmd)
}
function sw_lists(type,val){
if(type=="mac"){
var table = $("#authlist");
var table_count = $("#authlist tr").length;
var edit_num=document.getElementById("h_edit_num");
var del_num = document.getElementById("h_del_num")
edit_num.value=0;
del_num.value=0;
for(var a=table_count-1;a>0;a--)
{
$("#authlist tr").eq(a).remove();
}
table.append(sw_mac_list[val]);
}
}