intv="13";
swintv="3";
fover="0";
dprofiles=new Array()
div_id=new Array(
"_0x20" //Static IP Address
,"_0x00" //Dynamic IP Address
,"_0x40"      //PPP over Ethernet
,"_0x60"      //PPTP
,"_0x80"      //L2TP
,"_0x10"      //3G
,"_0x11"      //iBurst
,"_0x50,ipmode,ipmode_ipoa,adslitems"      //PPPoA
,"_0x02" //Bridge WAN type
,"_0x13"      //Wireless ISP
,"")
div_idadsl=new Array(
"_0x20,ipmode,adslitems" //,_0x101+backup3gs //Static IP Address
,"_0x20,ipmode_ipoa,adslitems" //,_0x101+backup3gs //IP over ATM
,"_0x40,ses0,adslitems"  //,_0x101+backup3gs //PPP over Ethernet/Multisession PPPoE
,"_0x50,adslitems" //,_0x101+backup3gs  //PPP over ATM
,"_0x02,adslitems" //Bridge WAN type
,"_0x60"//,_0x101,adslitems"+backup3gs      //PPTP
,"_0x80"//,_0x101,adslitems"+backup3gs      //L2TP
,"_0x00" //Dynamic IP Address
,"_0x11" //iBurst
,"")
var ALL_INDEX=[];
var ALL_INDEXV=[];
wifi_mode1="0";
csid_wifi_mode1="N00190008";
csid_wlapcli_enable1="N00320001";
wifi_mode2="0";
csid_wifi_mode2="N00440008";
csid_wlapcli_enable2="N00450001";
var have3g=0;
function setPW(ff)
{
mult_type=document.getElementById('multi_wtype').value;
if(location.pathname=="/primx.htm"){
pptp_pw=document.getElementById('pptppw');
if(pptp_pw.value=="*****") { pptp_pw.name="ignorethis"};
l2tp_pw=document.getElementById('l2tppw');
if(l2tp_pw.value=="*****") { l2tp_pw.name="ignorethis"};
wtpppoe_pw=document.getElementById('pppoepw');
if(wtpppoe_pw.value=="*****") { wtpppoe_pw.name="ignorethis"};
wtpppoa_pw=document.getElementById('pppoapw');
if(wtpppoa_pw.value=="*****") { wtpppoa_pw.name="ignorethis"};
wt3g_pw=document.getElementById('w3gpw');
if(wt3g_pw.value=="*****") { wt3g_pw.name="ignorethis"};
if(document.getElementById('h_3g_pin_bf').value!=document.getElementById('t_3g_pin_0').value){
document.getElementById('alter_3g_pin').disabled=false;
}
} else if(location.pathname=="/primx_sim.htm"){
wt3ga_pw=document.getElementById('w3gpwa');
if(wt3ga_pw.value=="*****") { wt3ga_pw.name="ignorethis"};
wt3gb_pw=document.getElementById('w3gpwb');
if(wt3gb_pw.value=="*****") { wt3gb_pw.name="ignorethis"};
if((document.getElementById('h_3g_pin_bf_a').value!=document.getElementById('t_3g_pin_a').value)||
(document.getElementById('h_3g_pin_bf_b').value!=document.getElementById('t_3g_pin_b').value)){
document.getElementById('alter_3g_pin').disabled=false;
}
}
if(document.getElementById("Nwanx").value==0){
if(mult_type=="0x60"||mult_type=="0x80"){
document.getElementById('ipv6_enable').value=0;
document.getElementById('ipv6_enable').disabled=false;
document.getElementById("alter_ipv6").disabled=false;
}
}
if(mult_type=="0x10"){
/*3.when 3G,IP Passthrough*/
var ippass=document.getElementById('c_ip_passthrough');
var ippass2=document.getElementById('h_ippass2');
var fix_mac=document.getElementById('t_fix_mac');
var fix_mac2=document.getElementById('h_fix_mac2');
var sdmz_mode=document.getElementById('h_sdmz_mode');
if(ippass.checked){
if(confirm(GetElmCont('prim_0',"Enable IP Passthrough will disable NAT. Do you agree?"))){
chk3gBridge(true);
if(have3g == 2 && ippass2.value == 1) {
if(fix_mac.value ==""&&fix_mac2.value ==""){ alert("Must input at least one Fixed MAC!"); return false}
sdmz_mode.value=(fix_mac.value ==""||fix_mac2.value =="")?2:1;
}else{
sdmz_mode.value=(fix_mac.value=="")?0:1;
}
}else{
chk3gBridge(false);
if(have3g == 2 && ippass2.value == 1) {
sdmz_mode.value=(fix_mac2.value =="")?0:1;
}
}
}else{
if(have3g == 2 && ippass2.value == 1) {
sdmz_mode.value=(fix_mac2.value =="")?0:1;
}
document.getElementById('set_sdmz').innerHTML="";
}
var now_ippassv=(ippass.checked)?"1":"0";
if(ippassv!=now_ippassv){
document.getElementById('alter_admz').disabled=false;
}
}
if(location.pathname=="/primx.htm"){
if(swintv=="2"){ //ADSL(PVC0 or PVC1~PVC7)
vpi_num=document.getElementById('t_vpi_number_0').value;
vci_num=document.getElementById('t_vci_number_0').value;
if(vpi_num==""||vci_num==""){
alert(GetElmCont('prim_0',"VPI and VCI number can not be null!"))
return false;
}
}
var localwth = document.getElementById("localwth");
if (localwth) mult_type=localwth.value;
if (mult_type=="0x20" || mult_type=="0x52"){
if (document.getElementById("t_static_ip_0").value==""){
alert(GetElmCont('wiz22_0','WAN IP Address is invalid!'));
return false;
}
} else if (mult_type=="0x40"){
if (document.getElementById("pppoe_user").value==""){
alert(GetElmCont('wiz22_0','PPPoE Account is invalid!'));
return false;
}
if (document.getElementById("pppoepw").value==""){
alert(GetElmCont('wiz22_0','PPPoE Password is invalid!'));
return false;
}
} else if (mult_type=="0x50"){
if (document.getElementById("pppoa_user").value==""){
alert(GetElmCont('wiz22_0','PPPoA Account is invalid!'));
return false;
}
if (document.getElementById("pppoapw").value==""){
alert(GetElmCont('wiz22_0','PPPoA Password is invalid!'));
return false;
}
} else if (mult_type=="0x60"){
if (document.getElementById("s_pptp_phase1_type_0").value==1&&document.getElementById("t_pptp_ip_0").value==""){
alert(GetElmCont('wiz22_0','WAN IP Address is invalid!'));
return false;
}
if (document.getElementById("t_pptp_pns_server_0").value==""){
alert(GetElmCont('wiz22_0','Server IP Address / Name is invalid!'));
return false;
}
if (document.getElementById("t_pptp_user_0").value==""){
alert(GetElmCont('wiz22_0','PPTP Account is invalid!'));
return false;
}
if (document.getElementById("pptppw").value==""){
alert(GetElmCont('wiz22_0','PPTP Password is invalid!'));
return false;
}
} else if (mult_type=="0x80"){
if (document.getElementById("s_l2tp_phase1_type_0").value==1&&document.getElementById("t_l2tp_ip_0").value==""){
alert(GetElmCont('wiz22_0','WAN IP Address is invalid!'));
return false;
}
if (document.getElementById("t_l2tp_lns_server_0").value==""){
alert(GetElmCont('wiz22_0','Server IP Address / Name is invalid!'));
return false;
}
if (document.getElementById("t_l2tp_user_0").value==""){
alert(GetElmCont('wiz22_0','L2TP Account is invalid!'));
return false;
}
if (document.getElementById("l2tppw").value==""){
alert(GetElmCont('wiz22_0','L2TP Password is invalid!'));
return false;
}
}
if(mult_type=="0x40"&&document.getElementById("_ipdu").style.display=="")
return chkipv6(ff);
else return true;
}
roaming_alert();
return true;
}
function chkipv6(fm)
{
ipals=GetElmCont("prim_0","Would you like to configure IPv6? Please click OK to proceed.")
if(fm.PPPoE_dualstack.checked){
if (confirm(ipals)){
fm.action="/ipv6.htm"
}else{
return true;
}
}
return true;
}
function chk3gBridge(bridgechk){
document.getElementById('c_ip_passthrough').checked=(bridgechk)?true:false;
document.getElementById('h_ippass').value=(bridgechk)?1:0;
if(bridgechk){
document.getElementById('h_3g_nat_disable').value=1;
document.getElementById('h_wanalias').value=0;
}
if(!bridgechk){document.getElementById('set_sdmz').innerHTML="";}
}
function DisplayMenu(idd,idx,fromAry)
{
ary=new Array();
ary=ary.concat((arguments.length>1)?fromAry:div_id);
hideAllDiv(ary)
if(idd=="0x50"){dielm("s_0x40","e_0x40",false);dielm("s_0x50","e_0x50",true);}
else {dielm("s_0x50","e_0x50",false);dielm("s_0x40","e_0x40",true);}
if(arguments.length>1){
if(ary[idx].indexOf(',')==-1)
{
dwt=ary[idx]
}
else
{
dis=ary[idx].split(',')
dwt=dis[0]
for(d1=1;d1<dis.length;d1++)
{ swDiv(dis[d1],1);}
}
swDiv(dwt,1)
} else {
swDiv("_"+idd,true)
}
}
function chgwt_multi(sel,fm,ary)
{
fm=sel.form
if(arguments.length==3)DisplayMenu(sel.value,sel.selectedIndex,ary)
else DisplayMenu(sel.selectedIndex)
wanipmd=document.getElementById('wanipmode')
wanipmd_ipoa=document.getElementById('wanipmode_ipoa')
if(sel.selectedIndex==0){
if(wanipmd!=null){
swipmode(wanipmd)
document.getElementById('localwth').value=wanipmd.value
}
}
else if(sel.selectedIndex==1){
if(wanipmd_ipoa!=null){
swipmode(wanipmd_ipoa)
document.getElementById('localwth').value=wanipmd_ipoa.value
}
}
else
{
swid('ipmode',false,'ipmode_ipoa',false)
if(document.getElementById('localwth')) document.getElementById('localwth').value=sel.value
}
}
function diid(divs,tf)
{
ddiv=document.getElementById(divs)
if(ddiv!=null)
{
ddiv.disabled=!tf;
ddiv.style.display=(tf)?'':'none';
}
}
function diids(divs,tf)
{
ddiv=document.getElementById(divs)
if(ddiv!=null)
{
ddiv.disabled=!tf;
}
}
function sethidden(ffm)
{
wmodule=(document.getElementById('wmodulev').value==1)?"":"2";
wband=eval("wopband"+wmodule);
apcl = document.getElementById('ap_channel'+wmodule);
aphtextcl = document.getElementById('ap_ht_extcha'+wmodule);
apcl.value = document.getElementById('channel'+wmodule).value;
apcl.disabled=false;
document.getElementById('apcli'+wmodule).disabled=false;
document.getElementById('apcli'+wmodule).value=1;
if(wband == "0"){
aphtextcl.value=(parseInt(document.getElementById('extcl'+wmodule).value) > parseInt(apcl.value))?1:0;
aphtextcl.disabled=false;
}
var encryv=document.getElementById('encry'+wmodule).value;
if(encryv==1){    //WEP
document.getElementById('wispauth'+wmodule).value=document.getElementById('wep_auth').value;
tp=document.getElementById('wep_keyidradio').value;
document.getElementById('keyidradio'+wmodule).value=document.getElementById('wep_keyidradio').value;
document.getElementById('keytype'+wmodule+'_'+tp).value=document.getElementById('wep_keytype'+tp).value;
document.getElementById('wepkey'+wmodule+'_'+tp).disabled=false;
document.getElementById('wepkey'+wmodule+'_'+tp).value=document.getElementById('t_wepkey'+tp).value;
}else if(encryv!=0){   //TKIP,AES
document.getElementById('pskey'+wmodule).disabled=false;
document.getElementById('pskey'+wmodule).value=document.getElementById('wep_pskey').value;
}
if(swm_wifi_ntype){
wifi_bridge = document.getElementById('h_wifi_bridge');
wifi_nat = document.getElementById('h_wifi_nat');
ntype = document.getElementById('s_ntype');
if(ntype.value == 2){
alert(GetElmCont("prim_0","If Bridge Mode is enabled, DHCP service,NAT and Network Monitoring will disable and will change connection control mode to Connect Manually."));
wifi_bridge.value=1;
wifi_nat.value=1;
}else{
wifi_bridge.value=0;
wifi_nat.value=ntype.value;
}
}
setWifi(wmodule) //scan->apply跟html save時都要送這些alter
return true
}
function setWifi(wmodule)
{
var div_obj =  document.getElementById("d_hidden_element");
var alter_str = "";
if(wmodule=="2"){
alter_str+="<input typt='hidden' name='N80460001' value='1'>"
alter_str+="<input typt='hidden' name='N80440002' value='1'>"
} else {
alter_str+="<input typt='hidden' name='N801C0001' value='1'>"
alter_str+="<input typt='hidden' name='N80190002' value='1'>"
}
f=document.forms[0];
f.Nscanap.value = 1;
div_obj.innerHTML = alter_str;
}
function dielm(estart,eend,sw)
{
ffm=document.forms[0]
flag=sw;
cc=0;
for(o=0;o<ffm.length;o++)
{
if(ffm.elements[o]==document.getElementById(estart))
{flag=!sw;cc=1;}
if(ffm.elements[o]==document.getElementById(eend))
{flag=sw;cc=2;}
if((cc>0)&&(cc<3))ffm.elements[o].disabled=flag
if(cc==2)break;
}
}
function chgwi()
{
document.getElementById("wandetail_wanx").style.display=""
if(swintv=="2"){ //ADSL(PVC0 or PVC1~PVC7)
chgwt_multi(document.getElementById('multi_wtype'),1,div_idadsl);
}else{
DisplayMenu(document.getElementById('multi_wtype').value)
}
}
function chk3gautobk(v)
{
/*若是Failover時會將
(1)Connection Control隱藏，值寫成Auto
(2)Network Monitoring disable，因為failover需要Network Monitoring Enable才會生效
主wan及備wan都要
在Connection Control下拉選擇Auto時，會將Network Monitoring Enable
*/
lwt=document.getElementById('multi_wtype')
hid_idletime=false
if(swintv=="2"){ //ADSL
if(lwt.selectedIndex==0){ //Ethernet Over ATM with NAT
if(v==1){
document.getElementById('h_wanchk').value=0;
document.getElementById('c_wanchk').checked=false;
vwan_switch('c_wanchk',false,'fover')
}
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x00').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('dhcp_cc').style.display="none";
}
swid('dhcp_idletime',document.getElementById('ct_0x00').value!=1)
}
else if(lwt.selectedIndex==1) //IP over ATM
{
if(v==1){
document.getElementById('h_wanchk').value=0;
document.getElementById('c_wanchk').checked=false;
vwan_switch('c_wanchk',false,'fover')
}
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x00').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('dhcp_cc').style.display="none";
}
swid('dhcp_idletime',document.getElementById('ct_0x00').value!=1)
}
else if(lwt.selectedIndex==2) //PPP over Ethernet
{
if(v==1){
document.getElementById('h_wanchk').value=0;
document.getElementById('c_wanchk').checked=false;
vwan_switch('c_wanchk',false,'fover')
}
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x40').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('pppoe_cc').style.display="none";
}
swid('pppoe_idletime',document.getElementById('ct_0x40').value!=1)
}
else if(lwt.selectedIndex==3) //PPP over ATM
{
if(v==1){
document.getElementById('h_wanchk').value=0;
document.getElementById('c_wanchk').checked=false;
vwan_switch('c_wanchk',false,'fover')
}
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x50').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('pppoa_cc').style.display="none";
}
swid('pppoa_idletime',document.getElementById('ct_0x50').value!=1)
}
}
else if(swintv=="1"){ //Ethernet
if(lwt.value=="0x00"){ //Dynamic
if(v==1){
document.getElementById('h_wanchk').value=0;
document.getElementById('c_wanchk').checked=false;
vwan_switch('c_wanchk',false,'fover')
}
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x00').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('dhcp_cc').style.display="none";
}
swid('dhcp_idletime',document.getElementById('ct_0x00').value!=1)
}
else if(lwt.value=="0x20"){ //Static
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('c_wanchk').disabled=true;
}
}
else if(lwt.value=="0x40"){ //PPPoE
if(v==1){
document.getElementById('h_wanchk').value=0;
document.getElementById('c_wanchk').checked=false;
vwan_switch('c_wanchk',false,'fover')
}
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x40').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('pppoe_cc').style.display="none";
}
swid('pppoe_idletime',document.getElementById('ct_0x40').value!=1)
}
else if(lwt.value=="0x60"){ //PPTP
if(v==1){
document.getElementById('h_wanchk').value=0;
document.getElementById('c_wanchk').checked=false;
vwan_switch('c_wanchk',false,'fover')
}
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x60').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('pptp_cc').style.display="none";
}
swid('pptp_idletime',document.getElementById('ct_0x60').value!=1)
}
else if(lwt.value=="0x80"){ //L2TP
if(v==1){
document.getElementById('h_wanchk').value=0;
document.getElementById('c_wanchk').checked=false;
vwan_switch('c_wanchk',false,'fover')
}
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x80').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('l2tp_cc').style.display="none";
}
swid('l2tp_idletime',document.getElementById('ct_0x80').value!=1)
}
}else if(swintv=="3"){ //3G 1, 3G 2
if(v==1){
document.getElementById('h_wanchk').value=0;
document.getElementById('c_wanchk').checked=false;
vwan_switch('c_wanchk',false,'fover')
}
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x10').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('3g_cc').style.display="none";
}
swid('maxitime',document.getElementById('ct_0x10').value!=1)
}else if(swintv=="4"){//WISP
if(v==1){
document.getElementById('h_wanchk').value=0;
document.getElementById('c_wanchk').checked=false;
vwan_switch('c_wanchk',false,'fover')
}
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x13').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('wisp_cc').style.display="none";
}
swid('wisp_idletime',document.getElementById('ct_0x13').value!=1)
}
/*else if(intv==15){ //Dial Up
if(document.getElementById('failover_value').value>0){ //Failover
document.getElementById('ct_0x90').value=1
document.getElementById('c_wanchk').disabled=true;
document.getElementById('dial_cc').style.display="none";
}
swid('dial_idletime',document.getElementById('ct_0x90').value!=1)
}*/
}
function setselix(oid,ix)
{
div=document.getElementById(oid)
if(div!=null)div.selectedIndex=ix
}
function undoact(types)
{
divwi=document.getElementById('wi')
if(divwi!=null) chgwi()
if(location.pathname=="/primx.htm"){
showtsel(cseled)
setselix('countrysel',cseled)
setselix('telecomsel',tseled)
setselix('networksel',nseled)
}
if(location.pathname=="/primx_sim.htm"){
setselix('countrysel_sima',cseled_sima)
setselix('telecomsel_sima',tseled_sima)
setselix('networksel_sima',nseled_sima)
setselix('countrysel_simb',cseled_simb)
setselix('telecomsel_simb',tseled_simb)
setselix('networksel_simb',nseled_simb)
}
}
function swipmode(sw)
{
dyn=(arguments.length>1)?(arguments[1]):(sw.selectedIndex==1)
swid('_0x20',!dyn)  //Static IP
swid('_0x00',dyn)   //Dynamic IP
swid('adslitems',true)
document.getElementById('multi_wtype').options[0].value=sw.value;
document.getElementById('localwth').value=sw.value;
}
function swip_ppp_multi(){
fs=document.forms[0];
ppv=(fs.N00050E0E.value==0)?"none":""
l2v=(fs.N00062E0D.value==0)?"none":""
document.getElementById('pp1').style.display=document.getElementById('pp2').style.display=document.getElementById('pp3').style.display=ppv
document.getElementById('l21').style.display=document.getElementById('l22').style.display=document.getElementById('l23').style.display=l2v
}
function chg_pppoecc(t){
if(document.getElementById('failover_value').value==0){ //No Failover
if(t.checked){
document.getElementById('pppoe_cc').style.display="none"
document.forms[0].N00900309.disabled=false;
}
else{
document.getElementById('pppoe_cc').style.display=""
document.forms[0].N00900309.disabled=true;
}
}
}
function chg_pppoacc(t){
if(document.getElementById('failover_value').value==0){ //No Failover
if(t.checked){
document.getElementById('pppoa_cc').style.display="none"
}
else document.getElementById('pppoa_cc').style.display=""
}
}
function setigmp(s){
igmpface="";
nowface="13";
if(s.selectedIndex=="0"){ //Disable
document.getElementById('igmp_proxy').style.display='none';
if(igmpface==nowface){
document.getElementById('igmp_version').value='';
document.getElementById('igmp_snoop').value=0;
document.getElementById('igmp_interface').value='';
document.getElementById('igmp_enable').value='';
}else{
document.getElementById('igmp_version').disabled=true;
document.getElementById('igmp_snoop').disabled=true;
document.getElementById('igmp_interface').disabled=true;
document.getElementById('igmp_enable').disabled=true;
}
}else{
document.getElementById('igmp_proxy').style.display='';
document.getElementById('igmp_version').value=s.value;
document.getElementById('igmp_snoop').value=1;
document.getElementById('igmp_interface').value=nowface;
document.getElementById('igmp_version').disabled=false;
document.getElementById('igmp_snoop').disabled=false;
document.getElementById('igmp_interface').disabled=false;
document.getElementById('igmp_enable').disabled=false;
}
}
function set_target(){
for(i=1;i<3;i++){
document.getElementById("t_fover_ping"+i).style.display=(document.getElementById("s_target"+i).value==4)?"":"none";
document.getElementById("t_fover_ping"+i).disabled=(document.getElementById("s_target"+i).value==4)?false:true;
}
}
function chk_target(){
icmp_enable=document.getElementById("r_fover_chk_1").checked
clear_valchk(document.getElementById("t_fover_ping1"));
clear_valchk(document.getElementById("t_fover_ping2"));
if(icmp_enable){
if(document.getElementById("s_target1").value==4)  showmsg(document.getElementById("t_fover_ping1"),(document.getElementById("t_fover_ping1").value!=''&&chkI(document.getElementById("t_fover_ping1"),'l')));
if(document.getElementById("s_target2").value==4)  showmsg(document.getElementById("t_fover_ping2"),(document.getElementById("t_fover_ping2").value!=''&&chkI(document.getElementById("t_fover_ping2"),'l')));
}else{
if(document.getElementById("s_target1").value==4)  showmsg(document.getElementById("t_fover_ping1"),(document.getElementById("t_fover_ping1").value!=''));
if(document.getElementById("s_target2").value==4)  showmsg(document.getElementById("t_fover_ping2"),(document.getElementById("t_fover_ping2").value!=''));
}
}
function chgsport(num){
l2tp_sportv=document.getElementById("s_l2tp_sport").value;
if(!num){
document.getElementById("t_l2tp_sport").value=(l2tp_sportv!=1)?l2tp_sportv:0;
document.getElementById("h_l2tp_sport").value=(l2tp_sportv!=1)?l2tp_sportv:0;
}
document.getElementById("t_l2tp_sport").disabled=(l2tp_sportv!=1)?true:false;
document.getElementById("h_l2tp_sport").disabled=(l2tp_sportv!=1)?false:true;
}
function dis_wanip2nd()
{
document.getElementById('wanip_2nd').disabled=(document.getElementById('c_wanalias_enable').checked)?false:true
if(document.getElementById('c_wanalias_enable').checked){
chkI(document.getElementById('wanip_2nd'),'l',GetElmCont('prim_0','WAN IP Alias'))
}
else clear_valchk(document.getElementById('wanip_2nd'))
}
function set_ip_pass(type)
{
if(type=="fst") type=(document.getElementById('h_ippass').value==1)?"chk":"fst";
document.getElementById('t_fix_mac').disabled=(document.getElementById('c_ip_passthrough').checked)?false:true;
if(type=="chk"){
if(document.getElementById('c_ip_passthrough').checked){
}
else clear_valchk(document.getElementById('t_fix_mac'))
document.getElementById('c_3g_nat_disable').checked=(document.getElementById('c_ip_passthrough').checked)?false:true;
document.getElementById('c_3g_nat_disable').disabled=(document.getElementById('c_ip_passthrough').checked)?true:false;
document.getElementById('h_3g_nat_disable').value=(document.getElementById('c_ip_passthrough').checked)?1:0;
WAlias=(document.getElementById('h_wanalias').value==1)?true:false
document.getElementById('c_wanalias_enable').checked=(document.getElementById('c_ip_passthrough').checked)?false:WAlias;
dis_wanip2nd()
document.getElementById('c_wanalias_enable').disabled=(document.getElementById('c_ip_passthrough').checked)?true:false;
}
}
function swWANx(wanx)
{
_Nwanif=(ALL_INDEXV[wanx]==99)?0:(ALL_INDEXV[wanx]-1);
_pvc="";
if(_Nwanif==5) _pvc=0; if(_Nwanif==6)  _pvc=16; if(_Nwanif==7)  _pvc=32;  if(_Nwanif==8)  _pvc=48;
if(_Nwanif==9) _pvc=64; if(_Nwanif==10) _pvc=80; if(_Nwanif==11) _pvc=96; if(_Nwanif==12) _pvc=112;
if (ALL_INDEXV[wanx]==99){ //是否為Local-Ethernet
go_url="/prim.htm?Nwanif=0&Nwanx="+wanx+"&Nsw=1";
}else if (ALL_INDEXV[wanx]==14&&swm_dualsim1==true){  //代表3G1+Dualsim
go_url="/primx_sim.htm?Nwanif="+_Nwanif+"&Nwanx="+wanx+"&Npvc="+_pvc+"&Nsw=1";
}else if (ALL_INDEXV[wanx]==15&&swm_phy_3g_4g2>0&&swm_dualsim2==true){  //代表3G2+Dualsim
go_url="/primx_sim.htm?Nwanif="+_Nwanif+"&Nwanx="+wanx+"&Npvc="+_pvc+"&Nsw=1";
}else if (ALL_INDEXV[wanx]==16||(ALL_INDEXV[wanx]==15&&swm_phy_wisp2>0)){  //代表WISP
go_url="/primx_wisp.htm?Nwanif="+_Nwanif+"&Nwanx="+wanx+"&Npvc="+_pvc+"&Nsw=1";
}
else{
go_url="/primx.htm?Nwanif="+_Nwanif+"&Nwanx="+wanx+"&Npvc="+_pvc+"&Nsw=1";
}
setTimeout("GURL('"+go_url+"')",500);
}
var fover=[];
fover.push(GetElmCont("wary_0","Disable"))
fover.push(GetElmCont("phy_0","Always on"))
fover.push(GetElmCont("phy_0","Failover"))
fover.push(GetElmCont("phy_0","Failover"))  //for seamless failover, value=3
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 swWanList()
{
var sw_phy="";
var sw_faover="";
var sw_wtype="";
var nwansckd ="";
var wtype="";
var w1=0;
var w2=0;
var nwansckd ="";
var div = document.getElementById("d_wan_list");
table_str = "<table width=100% border=0 align=center cellpadding=0 cellspacing=0 class='staball'>"
table_str += "<tr>";
table_str += "<th width='14%'><span id='_phy_0'>Interface Name</span></th>";
table_str += "<th width='15%'><span id='_sta_0'>Physical Interface</span></th>";
table_str += "<th width='15%'><span id='_phy_0'>Operation Mode</span></th>";
table_str += "<th width='16%'><span id='_sta_0'>WAN Type</span></th>";
table_str += "<th width='5%'><span id='_sta_0'>Action</span></th>";
table_str += "</tr>";
wiface="14";
sw_phy=swName_idx[wiface];
if(wiface=="14"||(wiface=="15" && swm_phy_3g_4g2>0)) { have3g+=1; }
sw_faover=fover[1];
wtype="0x00000010";
if(wtype=="0xFFFFFFFF")  wtype="0x00000000";
sw_wtype=wantype[wtype];
ALL_INDEX.push("N00010600");
ALL_INDEXV.push("14");
table_str += "<tr><td>WAN-1</td>";
table_str += "<td><div >"+sw_phy+"&nbsp;</div>";
table_str += "</td>";
table_str += "<td><div>"+sw_faover+"&nbsp;</div></td>";
table_str += "<td><div>"+sw_wtype+"&nbsp;</td>";
isEidt=(sw_wtype==" - ")?"disabled":"";
table_str += "<td><input id='_wary_0' type=button value='Edit' onclick=\"swWANx('0')\" "+isEidt+"></td></tr>"
sw_phy=" - ";
sw_faover=GetElmCont("wary_0","Disable")
if(1==0) { nwansckd += "2" }
else {
nwansckd += "-2"
}
sw_wtype=" - ";
ALL_INDEX.push("N00010601");
ALL_INDEXV.push("0");
table_str += "<tr><td>WAN-2</td>";
table_str += "<td><div >"+sw_phy+"&nbsp;</div>";
table_str += "</td>";
table_str += "<td><div>"+sw_faover+"&nbsp;</div></td>";
table_str += "<td><div>"+sw_wtype+"&nbsp;</td>";
isEidt=(sw_wtype==" - ")?"disabled":"";
table_str += "<td><input id='_wary_0' type=button value='Edit' onclick=\"swWANx('1')\" "+isEidt+"></td></tr>"
table_str += "</table>"
div.innerHTML = table_str;
}
var sim_arr=new Array();
if(location.pathname=="/primx.htm"){
sim_arr[0]='a';
}else if(location.pathname=="/primx_sim.htm"){
sim_arr[0]='a';
sim_arr[1]='b';
}
var band_type=new Array('2g','3g','3g','4g','4g');
var band_typeid=new Array('2g','3gf','3gt','4gf','4gt');
var work_blist_arr_2g=new Array();
var work_blist_arr_3gf=new Array();
var work_blist_arr_3gt=new Array();
var work_blist_arr_4gf=new Array();
var work_blist_arr_4gt=new Array();
/*
sim_arr決定要做sima還是sima,simb都做
因為3g,4g記錄分二個csid，讀取234g動作是一樣的 所以用band_type，長度決定做幾次
band_type記錄要放的div
band_typeid記錄要放的csid
讀取方式
(1)把234g能顯示的band的csid值轉為二進位
(2)存成陣列後再反轉，方便顯示band幾
順便把陣列存到work_blist_arr_2g 裡，方便最後存檔時知道是有幾個band及順序
存檔時是從最後一個開始記，等於再反回來，方便轉成十進位，再存到對應的csid
*/
function swBandList(){
for(i=0;i< sim_arr.length;i++){
var type = sim_arr[i];
/*CTA H21 remove
var set_bandchk=(document.getElementById('band_single').value==1)?"onclick=\"set_bandchk(this,'"+type+"');\"":"";
for(j=0;j< band_type.length;j++){
var sw_div="";
var band=band_typeid[j];
var band_arr=eval("band_arr_"+band);
bandv=parseInt(document.getElementById("band_"+band).value);
bandv=bandv.toString(2);
bandv_arr=bandv.split("");
bandv_arr=bandv_arr.reverse();
if(band=='2g') work_blist_arr_2g=bandv_arr.slice();
if(band=='3gf') work_blist_arr_3gf=bandv_arr.slice();
if(band=='3gt') work_blist_arr_3gt=bandv_arr.slice();
if(band=='4gf') work_blist_arr_4gf=bandv_arr.slice();
if(band=='4gt') work_blist_arr_4gt=bandv_arr.slice();
sbandv=parseInt(document.getElementById("band_"+band+"_"+type).value);
sbandv=sbandv.toString(2);
sbandv_arr=sbandv.split("");
sbandv_arr=sbandv_arr.reverse();
for(k=0;k< bandv_arr.length;k++){
if(bandv_arr[k]==1){
var bandchk=(sbandv_arr[k]==1)?"checked":"";
sw_div+="<br><input type='checkbox' id='c_b"+band+"_"+type+"_"+k+"' name=blist_"+type+" "+set_bandchk+" "+bandchk+">"+band_arr[k];
}
}
document.getElementById("sw_blist_"+band_type[j]+"_"+type).innerHTML+=sw_div;
}
*/
chgband(type,1);
}
}
/*
for 3G Network Type chagne
0:Auto-2G,3G,4G
1:2G Only-2G
2:2G Prefer-2G,3G,4G
3:3G Only-3G
4:3G Prefer-2G,3G,4G
5:LTE Only-4G
Network Type依CSID顯示(2G Only,2G Prefer...等)等於1時不顯示，預設為0
num存在代表是第一次進入頁面
*/
function chgband(type,num){
var objSelect=document.getElementById('s_ntype_'+type)
var swLTE=0;
var sw3G=0;
var sw2G=0;
/*CTA H21 remove
var ntype=document.getElementById('s_ntype_'+type).value;
var bselect=document.getElementById('s_bselect_'+type).value;
if(objSelect.length == 0){  //Network Type is empty
document.getElementById('sw_blist_2g_'+type).style.display="none";
document.getElementById('sw_blist_3g_'+type).style.display="none";
document.getElementById('sw_blist_4g_'+type).style.display="none";
}else{
document.getElementById('sw_blist_2g_'+type).style.display=(ntype!=2&&ntype!=5&&sw2G!=2)?"":"none";
document.getElementById('sw_blist_3g_'+type).style.display=(ntype!=1&&ntype!=5&&sw3G!=2)?"":"none";
document.getElementById('sw_blist_4g_'+type).style.display=(ntype!=1&&ntype!=2&&swLTE!=1)?"":"none";
}
chkobj_disaled('blist_'+type,(bselect==0));
*/
}
function chkobj_disaled(obj,chk)
{
var tmp_disabled = document.getElementsByName(obj);
var bsingle = document.getElementById('band_single').value;
for(var t=0;t<tmp_disabled.length;t++)
{
tmp_disabled[t].disabled=chk;
if(chk) tmp_disabled[t].checked=true;
else if(bsingle==1) {tmp_disabled[t].checked=chk;}
}
}
function set_bandchk(obj,type){
if(obj.checked){
chkobj_disaled('blist_'+type,false)
obj.checked=true;
}
}
function saveBandList(){
for(i=0;i< sim_arr.length;i++){
var type = sim_arr[i];
var ntype=document.getElementById('s_ntype_'+type).value;
var bselect=document.getElementById('s_bselect_'+type).value;
var use_band_type=[];
var use_band_name=[];
var chk_use_2g=0;
var chk_use_3g=0;
var chk_use_4g=0;
var chk_list_2g=0;
var chk_list_3g=0;
var chk_list_4g=0;
var message = GetElmCont("prim_0","Please choose Band Lists.");
if(ntype!=2&&ntype!=5){
use_band_type.push('2g');
use_band_name.push('2g');
}
if(ntype!=1&&ntype!=5){
use_band_type.push('3gf');
use_band_type.push('3gt');
use_band_name.push('3g');
use_band_name.push('3g');
}
if(ntype!=1&&ntype!=2){
use_band_type.push('4gf');
use_band_type.push('4gt');
use_band_name.push('4g');
use_band_name.push('4g');
}
for(j=0;j< use_band_type.length;j++){
var sband_arr=eval('work_blist_arr_'+use_band_type[j])
var use_band="";
var chk_use=0;
var chk_list=0;
var save_band=document.getElementById("band_"+use_band_type[j]+"_"+type);
var bandv=document.getElementById("band_"+use_band_type[j]).value;
if(bandv!=""&&bandv!="0"){  //band list值不為空白且不為0時  chk_list+1
for(k=sband_arr.length-1;k>=0 ;k--){
if(sband_arr[k]==1){
band_enable=document.getElementById("c_b"+use_band_type[j]+"_"+type+"_"+k);
use_band+=(band_enable.checked)?"1":"0";
if(band_enable.checked) chk_use+=1;
}else{
use_band+="0";
}
}
chk_list+=1;
}
if(use_band!=""){
use_band=parseInt(use_band,2)
save_band.value=use_band;
}
if(use_band_name[j]=='2g') {
chk_list_2g+=chk_list;
chk_use_2g+=chk_use;
}
if(use_band_name[j]=='3g') {
chk_list_3g+=chk_list;
chk_use_3g+=chk_use;
}
if(use_band_name[j]=='4g') {
chk_list_4g+=chk_list;
chk_use_4g+=chk_use;
}
}
for(l=0;l< use_band_name.length;l++){
chk_list=eval('chk_list_'+use_band_name[l]);
chk_use=eval('chk_use_'+use_band_name[l]);
if(chk_list!=0&&chk_use==0){
alert(message);
return false;
}
}
}
return true;
}
function sw3gipmode(type)
{
var ipmode=document.getElementById('s_ipmode_sim'+type);
var ipadr=document.getElementById('t_ip_sim'+type);
var ipsmask=document.getElementById('s_ipsmask_sim'+type);
var ipgw=document.getElementById('t_gateway_sim'+type);
var tr_ipadr=document.getElementById('tr_ipadr_sim'+type);
var tr_ipsmask=document.getElementById('tr_ipsmask_sim'+type);
var tr_ipgw=document.getElementById('tr_ipgw_sim'+type);
ipadr.disabled=(ipmode.value==0)?true:false;
ipsmask.disabled=(ipmode.value==0)?true:false;
ipgw.disabled=(ipmode.value==0)?true:false;
tr_ipadr.style.display =(ipmode.value==0)?"none":"";
tr_ipsmask.style.display =(ipmode.value==0)?"none":"";
tr_ipgw.style.display =(ipmode.value==0)?"none":"";
if(ipmode.value==0){
clear_valchk(ipadr);
clear_valchk(ipgw);
}else{
chkI(ipadr,'a');
chkI(ipgw,'a');
}
}
existschedulerule=new Array(
"")
function displayschesel()
{
fm=document.forms[0]
sobj=fm.N001E2220
clrsel(sobj,1)
for(k=0;k<existschedulerule.length-1;k++)
{
sches=existschedulerule[k].split(" : ")
stexts=((sches[0]=="")?sches[1]:("("+sches[0]+") "+sches[1]))
pushselopt(sobj,stexts,sches[0])
if(sches[0]=="0")sobj.selectedIndex=k+1
}
}
function setsche(val)
{
schenoid=document.getElementById("scheno")
if(schenoid!=null)
{
schenoid.selectedIndex=findSelectIndex(schenoid,val)
}
}
var ipv6v="0";
function setiptype(){
var s_3g_simV = document.getElementById("s_3g_sim").value;
var c_ipv6 =  document.getElementById("ipv6_enable");
c_ipv6.disabled = true;
var s_ip_typev = 0;
var send_enable_a = false;
var send_enable_b = false;
for(var i=0;i<apn_profile_listA_iptype.length;i++){
if((apn_profile_listA_iptype[i]!=0)&&apn_profile_listA_enable[i]==1){
send_enable_a = true;
}
}
for(var i=0;i<apn_profile_listA_iptype.length;i++){
if((apn_profile_listB_iptype[i]!=0)&&apn_profile_listB_enable[i]==1){
send_enable_b = true;
}
}
if(s_3g_simV == 3){//SIM-A Only
var s_auto_apn_a_v = document.getElementById("s_auto_apn_a").value;
var s_ip_typea_v =  document.getElementById("s_ip_type_a").value;
if(s_auto_apn_a_v == 2){//APN Profile List
s_ip_typev = send_enable_a;
}else{//Auto-detection or Manual-configuration
s_ip_typev = s_ip_typea_v;
}
}else if(s_3g_simV == 4){//SIM-B Only
var s_auto_apn_b_v = document.getElementById("s_auto_apn_b").value;
var s_ip_typeb_v =  document.getElementById("s_ip_type_b").value;
if(s_auto_apn_b_v == 2){
s_ip_typev = send_enable_b;
}else{
s_ip_typev = s_ip_typeb_v;
}
}else{//SIM-A First || SIM-B First
var s_auto_apn_a_v = document.getElementById("s_auto_apn_a").value;
var s_auto_apn_b_v = document.getElementById("s_auto_apn_b").value;
var s_ip_typea_v =  document.getElementById("s_ip_type_a").value;
var s_ip_typeb_v =  document.getElementById("s_ip_type_b").value;
var check_sima = (s_auto_apn_a_v==2)?send_enable_a:s_ip_typea_v;
var check_simb = (s_auto_apn_b_v==2)?send_enable_b:s_ip_typeb_v;
s_ip_typev = check_sima | check_simb;
}
if(s_ip_typev == 0 && ipv6v == "1"){
c_ipv6.value = 0;
c_ipv6.disabled = false;
}
if(s_ip_typev != 0 && ipv6v == "0"){
c_ipv6.value = 1;
c_ipv6.disabled = false;
}
}
function ip_type(){
mult_type=document.getElementById('multi_wtype').value;
if(mult_type=="0x10") {setiptype();}
return true;
}