var vwan = {
name:"vwan",               //��滨迂
swPagebtn: false,          //憿舐內����
useindex_ary: [],          //閮㗛��𤌍��滚歇雿輻鍂��index
next_index: 0,             //銝衤��贝�閮㗛���CSID雿滨蔭
max_number: 16,            //��憭找蝙�鍂�彍
count: 0,                  //�𤌍��滢蝙�鍂�彍
row_count: 16,             //瘥誯�憿舐內銵峕彍
list_ary: [],              //����憿舐內�批捆
table_str: "",
record_csid: []
}
vwan.table_str = "<table width=100% border=0 align=center cellpadding=0 cellspacing=0 class='staball'>"
vwan.table_str += "<tr class='staball_sum'>";
vwan.table_str += "<th width='3%'><span id='_0'>ID</span></th>";
vwan.table_str += "<th width='25%'><span id='_0'>Physical Interface</span></th>";
vwan.table_str += "<th width='25%'><span id='_0'>WAN Type</span></th>";
vwan.table_str += "<th width='20%'><span id='_wary_0'>Enable</span></th>";
vwan.table_str += "<th width='27%'><span id='_sta_0'>Actions</span></th>";
vwan.table_str += "</tr>";
function swPagebtn(obj){
var f = document.forms[0];
if(obj.swPagebtn){
var btnPre = document.getElementsByName("btnPre_"+obj.name)[0];
var btnNext = document.getElementsByName("btnNext_"+obj.name)[0];
btnPre.style.display = "";
btnNext.style.display = "";
} else {
obj.row_count = obj.max_number;
}
}
/*
Add/Delete/Edit
vwan_record_csid => 閬�憛怠�� C_WEBUI_VWAN_RECORD ��銝衤�蝑� index �鍂靘�閮㗛�霈���𥟟SID ����摨�
vwan.next_index => 銝衤�蝑��� index  �� C_VWAN_INDEX 蝚砌��讠征�蒾��CSID
*/
var vwan_indexv = [];
var vwan_wtypev = [];
var vwan_enablev = [];
var vwan_index_csid = [];
var vwan_wtype_csid= [];
var vwan_enable_csid = [];
var vwan_alter_csid = [];
var wantype = [];
wantype["0x00000000"] = GetElmCont("prim_0","Dynamic IP");
wantype["0x00000002"] = GetElmCont("wiz20_0","RFC 1483 Bridged");
wantype["0x00000010"] = GetElmCont("sta_0","3G/4G");
wantype["0x00000013"] = GetElmCont("wiz20_0","Uplink");
wantype["0x00000020"] = GetElmCont("sta_0","Static IP");
wantype["0x00000030"] = GetElmCont("wiz20_0","Ethernet over ATM with NAT");
wantype["0x00000031"] = GetElmCont("wiz20_0","Ethernet over ATM with NAT");
wantype["0x00000040"] = GetElmCont("sta_0","PPPoE");
wantype["0x00000043"] = GetElmCont("wiz20_0","PPPoE (ADSL)");
wantype["0x00000050"] = GetElmCont("wiz20_0","PPP over ATM");
wantype["0x00000051"] = GetElmCont("wiz20_0","IP over ATM");
wantype["0x00000052"] = GetElmCont("wiz20_0","IP over ATM");
wantype["0x00000060"] = GetElmCont("sta_0","PPTP");
wantype["0x00000080"] = GetElmCont("sta_0","L2TP");
wantype["0x00000090"] = GetElmCont("wiz20_0","Dial-up Network");
function setVWANList(){
var t=new Date()
var xml="vwan.xml?rc=";
xmlDoc=loadXMLDocs(xml+"&ZT="+t.getTime());
if(xmlDoc==null)return;
var table_str2 = "";
var ary_index=0;
var chk_add = 0;
var list_id=0;
vwan.list_ary=[""];
vwan.count=0;
var vwan_rule_index = xmlDoc.getElementsByTagName("vwan_record")[0].childNodes[0];
if(vwan_rule_index!=null){
vwan_rule_index=vwan_rule_index.nodeValue;
vwan.useindex_ary = vwan_rule_index.split(",");
for(i=0,len=vwan.useindex_ary.length;i<len;i++){
index = parseInt(vwan.useindex_ary[i]);
xml_index = (index-1);
list_id=list_id+1;
var vwan_index = xml_getvalue(xmlDoc,"vwan_index",xml_index);
var vwan_wtype = xml_getvalue(xmlDoc,"vwan_wtype",xml_index);
var vwan_enable = xml_getvalue(xmlDoc,"vwan_enable",xml_index);
var enable_check = "";
enable_check = (vwan_enable == 1)?"checked":"";
table_str2 += "<tr align='center' style='word-break:break-all'>";
table_str2 += "<td>"+list_id+"</td>";
table_str2 += "<td>"+swName_idx[vwan_index]+"&nbsp;</td>";
table_str2 += "<td>"+wantype[vwan_wtype]+"&nbsp;</td>";
table_str2 += "<td><input type='checkbox' name='vwan_rule' "+enable_check+" disabled>&nbsp;</td>"
button = "<input type='button' id='_wary_0' value='Edit' onclick=\"edit_account(vwan,"+xml_index+")\">";
button += "<input type='checkbox' name='vwan_del' value='"+(index)+"'><span id=_wary_0>Select</span>";
table_str2 += "<td align='center'>"+button+"</td>";
table_str2 += "</tr>";
chk_add =  chk_add + 1;
vwan.list_ary[ary_index] = table_str2;
if(chk_add == vwan.row_count){
table_str2 = "";
chk_add = 0;
ary_index = ary_index + 1;
}
}
}
for(var x=0;x<vwan.max_number;x++)
{
var vwan_indexvs = xml_getvalue(xmlDoc,"vwan_index",x);
vwan_indexv.push(vwan_indexvs);
var vwan_wtypevs = xml_getvalue(xmlDoc,"vwan_wtype",x);
vwan_wtypev .push(vwan_wtypevs);
var vwan_enablevs = xml_getvalue(xmlDoc,"vwan_enable",x);
vwan_enablev.push(vwan_enablevs);
var vwan_index_csidv = xml_getvalue(xmlDoc,"vwan_index_csid",x);
vwan_index_csid.push(vwan_index_csidv);
var vwan_wtype_csidv = xml_getvalue(xmlDoc,"vwan_wtype_csid",x);
vwan_wtype_csid.push(vwan_wtype_csidv);
var vwan_enable_csidv = xml_getvalue(xmlDoc,"vwan_enable_csid",x);
vwan_enable_csid.push(vwan_enable_csidv);
var vwan_alter_csidv = xml_getvalue(xmlDoc,"vwan_alter_csid",x);
vwan_alter_csid.push(vwan_alter_csidv);
}
vwan.record_csid = xml_getvalue(xmlDoc,"vwan_record_csid",0);
/*
count閮㗛��𤌍��滢蝙�鍂�彍
�銁�𤌍��滢蝙�鍂�彍撠𤩺䲰��憭找蝙�鍂�彍��嚗���0���𤌍��滢蝙�鍂�彍+1�縧�𪄳銝衤��贝�㗛���雿滨蔭
撖怠�next_index
*/
vwan.count = vwan.useindex_ary.length;
if(vwan.count < vwan.max_number){
for(var x=0;x<=vwan.count;x++)
{
var chk_idx = xml_getvalue(xmlDoc,"vwan_index",x);
if(chk_idx == "0" || chk_idx == "")
{
vwan.next_index = x;
break;
}
}
}
}
function add_account(obj,type)
{
var f = document.forms[0];
if(obj.count >= obj.max_number)
{
alert(GetElmCont("pptps_0","Rule could not be added anymore."));
}
else
{
document.getElementsByName("Nlen")[0].value = obj.count;
document.getElementsByName("Nrule")[0].value = obj.next_index;
show_conf("add");
}
}
function edit_account(obj,idx)
{
document.getElementsByName("Nrule")[0].value = idx;
show_conf("edit");
}
function show_conf(type){
var f = document.forms[0];
var s_wan = document.getElementById("s_wan");
var s_type = document.getElementById("s_type");
var c_rule = document.getElementById("c_rule_enable");
var Nrule = f.Nrule.value;
if(type=="add"){
s_wan.selectedIndex=0;
s_type.value="0x00000010";
c_rule.checked=false;
chgwan(1);
}else{
s_wan.value=vwan_indexv[Nrule];
s_type.value=vwan_wtypev[Nrule];
c_rule.checked=(vwan_enablev[Nrule]==1)?true:false;
}
swid("edit_tab",true);
swid("add_edit",(type=="add"));
swid("edit_edit",(type=="edit"));
swid("add_button",(type=="add"));
swid("edit_button",(type=="edit"));
}
function save_list(type,obj)
{
var s_wanv = document.getElementById("s_wan").value;
var s_typev = document.getElementById("s_type").value;
var c_rulev = (document.getElementById("c_rule_enable").checked)?1:0;
var account_str = "";
var use_index = parseInt(document.getElementsByName("Nrule")[0].value);
var div_obj =  document.getElementById("d_hidden_element");
account_str += "<input typt='text' name='"+vwan_index_csid[use_index]+"' value='"+s_wanv+"'>";
account_str += "<input typt='text' name='"+vwan_wtype_csid[use_index]+"' value='"+s_typev+"'>";
account_str += "<input typt='text' name='"+vwan_enable_csid[use_index]+"' value='"+c_rulev+"'>";
if(type == 'add'){
idxs=vwan.useindex_ary.toString();
idxs+=((idxs=="")?"":",")+(use_index+1);
account_str += "<input typt='hidden' name='"+ vwan.record_csid+"' value='"+idxs+"'>";
}
account_str += "<input typt='hidden' name='"+ vwan_alter_csid[use_index]+"' value='1'>";
div_obj.innerHTML = account_str;
if(!chkForm())return false
obj.form.submit();
}
function del_tunnel(obj)
{
var tmp_del = document.getElementsByName(obj.name+"_del");
var div_obj =  document.getElementById("d_hidden_element");
var record_index = obj.useindex_ary;
var record_csid = obj.record_csid;
var del_arr = [];
var index = 0;
var new_index = 0;
var sent_str ="";
var alter_str ="";
var f = document.forms[0];
for(var t=0;t<tmp_del.length;t++)
{
if(tmp_del[t].checked)
{
del_arr[index] = tmp_del[t].value;
index++;
}
}
if(del_arr.length == 0)
{
alert(GetElmCont("lb_0","Please choose one or more rule."));
return false;
}
for(var r=0;r<record_index.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(record_index[r] == del_arr[n])
{
record_index[r] = "";
}
}
}
var record_str="";
for(var a=0;a<record_index.length;a++)
{
if(record_index[a] != "")
{
record_str+=((record_str=="")?"":",")+record_index[a];
}
}
sent_str += "<input typt='hidden' name='"+ record_csid +"' value='"+record_str+"'>";
for(var r=0;r<del_arr.length;r++)
{
var tunlname_index = del_arr[r]-1;
if(obj.name=="vwan"){
sent_str += "<input typt='hidden' name='"+ vwan_index_csid[tunlname_index] +"' value=''>";
sent_str += "<input typt='hidden' name='"+ vwan_enable_csid[tunlname_index] +"' value='0'>";
alter_str += "<input typt='hidden' name='"+ vwan_alter_csid[tunlname_index] +"' value='1'>";
}
}
div_obj.innerHTML = sent_str + alter_str;
if(!chkForm())return false
f.submit();
}
function setPage(obj,val)
{
var Ncmd=parseInt(document.getElementById("Ncmd_"+obj.name).value);
var btnPre = document.getElementsByName("btnPre_"+obj.name)[0];
var btnNext = document.getElementsByName("btnNext_"+obj.name)[0];
var row_count=obj.row_count;
var use_count=obj.count;
if(val==0){
}else if(val==1){
Ncmd=Ncmd+1;
}else if(val==2){
Ncmd=Ncmd-1;
}else{
Ncmd=Math.ceil(use_count/row_count)-1;
}
document.getElementById("Ncmd_"+obj.name).value=Ncmd;
page_end=parseInt(Ncmd)*row_count+row_count;
btnPre.disabled=(Ncmd==0)?true:false;
btnNext.disabled=(use_count<=page_end||use_count==0)?true:false;
swList(obj,Ncmd)
}
function swList(obj,Ncmd){
var div = document.getElementById("sw_"+obj.name+"_list");
div.innerHTML = obj.table_str + obj.list_ary[Ncmd] + "</table>";
}