function checkOpMode(obj)
{
var opMode_value = document.getElementById("WOpMode").value;
var wlan_enable = document.getElementById("id_wlenable");
var ap_number = document.getElementById("id_apNum").value;
var wmode_value = document.getElementById("id_wmode").value;
var status = true;
if(wlan_enable.checked){          /** 當wireless enable 時，再進一步檢查 **/
status = chkkeylen(opMode_value);
var h_wlenable = document.getElementById("h_wlenable");
h_wlenable.value = 1;
var n_lazy_movev = document.getElementById("h_lazy_mode_check").value;
if((opMode_value != wmodev)||(n_lazy_movev != lazy_movev)){
document.forms[0].Nchgwmode.value=1
}
if(status){
var ch=document.getElementById("id_wchannel").value;
if(ch!=0) document.getElementById("auto_ch_0").checked=true;
document.getElementById("h_bscoexits").disabled=(ch==165)?false:true;
document.getElementById("h_vbw").disabled=(ch==165)?false:true;
document.getElementById("h_bw").disabled=(ch==165)?false:true;
if(opMode_value == "1" || opMode_value == "3" || opMode_value == "5"){
status = confirm(GetElmCont("wpa_0","Make sure that you want to save the setting, this feature will disable 'NAT' and WAN Port will act as another LAN Port."));
if(status){
if(opMode_value == "3"){			//WDS ONLY MODE
status = chkmacv();
}
else if(opMode_value == "5"){		//REPEATER MODE
saveWLANAPCLI();
}
else{								//AP ONLY MODE
if(ap_number==0) setauthency();
return status;
}
}
}
else{
if(opMode_value == "2"){				//WDS HYBRID MODE
if(ap_number==0) setauthency();
status = chkmacv();
}
else{									//AP ROUTER MODE
if(ap_number==0) setauthency();
return status;
}
}
}
else{
return status;
}
}
return status;
}
/*
set Authentication及Encryption
用isauth陣列記錄VAP2~VAPN的Authentication是否可使用
(1)isauth[i]="false"代表不可使用，直接設成Open+None
(2)isauth[i]="true"時判斷是否為11n only
11n only時，Encryption不能是WEP,TKIP,TKIP/AES
不為11n only時,WDS Hybrid Mode沒有TKIP/AES，若在WDS Hybrid Mode時，VAP2~VAPN設成TKIP/AES，直接設成TKIP
*/
function setauthency()
{
var opMode_value = document.getElementById("WOpMode").value;
var wmode_value = document.getElementById("id_wmode").value;
var div_obj =  document.getElementById("d_hidden_element");
var account_str = "";
var auth = document.getElementById('id_auth');
var encrytype = document.getElementById('id_encry');
var isauth=new Array();
for(i=0;i<bssidnum-1;i++){
for(j=0;j<auth.length;j++){
if (vapn_authv[i]==auth.options[j].value){
isauth[i]="true";
break;
}else{
isauth[i]="false";
}
}
}
for(i=0;i<bssidnum-1;i++){
if(isauth[i]=="true"){
if(wmode_value==6||wmode_value==11){ //11n only
if(vapn_encryv[i]==1) //WEP
account_str += "<input typt='hidden' name='"+vapn_encry[i]+"' value='0'>";
if(vapn_encryv[i]>=2&&vapn_encryv[i]!=3) //TKIP,TKIP/AES
account_str += "<input typt='hidden' name='"+vapn_encry[i]+"' value='3'>";
}else{
if(opMode_value==2&&vapn_encryv[i]==4){ //WDS Hybrid Mode +TKIP/AES
account_str += "<input typt='hidden' name='"+vapn_encry[i]+"' value='2'>";
}
}
}else{
account_str += "<input typt='hidden' name='"+vapn_auth[i]+"' value='0'>";
account_str += "<input typt='hidden' name='"+vapn_encry[i]+"' value='0'>";
}
}
div_obj.innerHTML = account_str;
}
/******************** WDS checking ********************/
function chkmac(mac)
{
var hexary = "0123456789ABCDEF";
if(mac.length != 17){
return false;
}
if(mac == "00:00:00:00:00:00"){
return false;
}
else if(mac.indexOf(":") == -1){	/** 無冒號分隔，錯誤 **/
return false;
}
else{
var macv = mac.split(":");
if(macv.length != 6){			/** 當不為6組數字，錯誤 **/
return false;
}
for(var m = 0; m < macv.length; m++){
var m1 = macv[m].substring(0,1).toUpperCase();	/** 每組數字的第一個字 **/
var m2 = macv[m].substring(1,2).toUpperCase();	/** 每組數字的第二個字 **/
if((hexary.indexOf(m1) == -1) || (hexary.indexOf(m2) == -1)){
return false;
}
}
return true;
}
}
function chkmacv()
{
var fm = document.forms[0];
var maclist = "";
for(var i = 0; i < macs.length - 1; i++){
eval("macfd=fm." + macs[i]);
var macfdv = macfd.value;
if(macfdv == ""){
continue;
}
else if(!chkmac(macfdv)){
alert(GetElmCont("commonAM_0","MAC address")+" "+(i+1)+"("+macfdv+") "+GetElmCont("commonAM_1"," is invalid!!"));
return false;
}
else{
maclist = maclist + macfdv+";";
}
}
document.getElementById("id_wdsmaclist").value = maclist.substring(0,maclist.length-1);	/** 去掉最後一個";" **/
return true;
}
function show_mac(show)
{
var opMode_value = document.getElementById("WOpMode").value;
if(document.getElementById("ap_list") != null)
{
document.getElementById("ap_list").style.display = (show.checked)?"none":"";
}
document.getElementById("div_WDS").style.display = (opMode_value==2&&!show.checked)?"":"none";
}
function reset_wiz(){
spanary=new Array()
}
function chkset(){
objchk=document.getElementById("id_max_stions").checked;
obj=document.getElementById("t_max_sta")
document.getElementById("max_sta").style.display=(objchk)?"":"none";
if(objchk){
showmsg(obj,obj.value!=''&&chkN(obj,'u','1-16','STA'))
obj.disabled=false;
}else{
clear_valchk(obj);
obj.disabled=true;
}
}
function chg_atuo(obj)
{
document.getElementById("auto_select").style.display=(obj.value==0)?"":"none";
}