var sms_record_next_index = 0;   //�ثe�Ĥ@���� �s�W�����X
var sms_record_edit_index = 0;
var smsdifi_MAX = 5;         //�ثeCTA���w�}�X�̤j�Ӽ�
var sms_count =0;
var delete_check_arr = [];
for(var a=0;a<63;a++)
{
delete_check_arr[a] = 0;
}
/*
Add/Delete/Edit external server
sms_account_next_index => �n���J C_WEBUI_VPNPPTPACC_RECORD_RULE ���U�@�� index �ΨӰO��Ū��CSID �o����
sms_record_next_index => �U�@���� index  ���Ĥ@�Ӫťժ�CSID
by kent
*/
var sms_account_csid = [];
var sms_phnumber_csid = [];
var sms_desc_csid = [];
var sms_app_csid = [];
var sms_enable_csid = [];
sms_account_csid.push("N002012AC");
sms_phnumber_csid.push("S003B6000");
sms_desc_csid.push("S003BB200");
sms_app_csid.push("N003BB000");
sms_enable_csid.push("N003BA000");
sms_account_csid.push("N002012AD");
sms_phnumber_csid.push("S003B6001");
sms_desc_csid.push("S003BB201");
sms_app_csid.push("N003BB001");
sms_enable_csid.push("N003BA001");
sms_account_csid.push("N002012AE");
sms_phnumber_csid.push("S003B6002");
sms_desc_csid.push("S003BB202");
sms_app_csid.push("N003BB002");
sms_enable_csid.push("N003BA002");
sms_account_csid.push("N002012AF");
sms_phnumber_csid.push("S003B6003");
sms_desc_csid.push("S003BB203");
sms_app_csid.push("N003BB003");
sms_enable_csid.push("N003BA003");
sms_account_csid.push("N002012B0");
sms_phnumber_csid.push("S003B6004");
sms_desc_csid.push("S003BB204");
sms_app_csid.push("N003BB004");
sms_enable_csid.push("N003BA004");
function add_edit_sms_account(type,edit_arr_index,edit_csid_index)
{
var add_edit_tbsms = document.getElementById("add_edit_tbsms");
var add_button = document.getElementById("add_save_buttonsms");
var edit_button = document.getElementById("edit_save_buttonsms");
var sms_phnumber = document.getElementById("t_phnumber");
var sms_phdesc = document.getElementById("t_phdesc");
var sms_app = document.getElementById("t_app");
var sms_checked = document.getElementById("c_enable_sms");
var anchor = document.getElementById("_a_anchor_sms");
if(type == 'add')
{
if(sms_account_next_index == smsdifi_MAX)
{
alert("rule can't more than "+smsdifi_MAX);
return false;
}
sms_phnumber.value = "";
sms_app.value = 0;
edit_apptp(sms_app.value);
sms_phdesc.value = "";
sms_checked.checked = true;
}
else
{
sms_phnumber.value = sms_phnumber_arr[edit_arr_index];
sms_app.value = sms_app_arr[edit_arr_index];
edit_apptp(sms_app.value);
sms_phdesc.value = sms_phdesc_arr[edit_arr_index];
sms_checked.checked = (sms_enable_arr[edit_arr_index] == 1)?"checked":"";
sms_record_edit_index = edit_csid_index;
}
sw_configtab(add_edit_tbsms)
add_edit_tbsms.style.display = "";
add_button.style.display = (type == "add")?"":"none";
edit_button.style.display = (type == "add")?"none":"";
anchor.click();
}
function save_sms(type,obj)
{
var add_phnumber = get_encode_value("t_phnumber");
var add_phdesc = get_encode_value("t_phdesc");
var add_app = get_encode_value("t_app");
var add_checked = document.getElementById("c_enable_sms").checked;
var add_enable = (add_checked)?1:0;
var index = (type == 'add')?sms_record_next_index:sms_record_edit_index;
var account_str = "hide.htm?";
var str_message = "";
var iframe = document.getElementById("iframeH");
saveResult();
if((add_phnumber == "")&&(add_checked))
{
str_message = GetElmCont("_0","Phone Number can't empty!")
alert(str_message);
return false;
}
if((add_phdesc == "")&&(add_checked))
{
str_message = GetElmCont("_0","Phone Description can't empty!")
alert(str_message);
return false;
}
if((add_app =='0')&&(add_checked)) {
alert(GetElmCont("_0","Application is invalid."));
return false;
}
if(!chkForm())
{
return false;
}
if(type == 'add')
{
account_str += sms_account_csid[sms_account_next_index]+"="+(index+1)+"&";
}
account_str += sms_phnumber_csid[index]+"="+add_phnumber;
account_str += "&"+sms_desc_csid[index]+"="+add_phdesc;
account_str += "&"+sms_app_csid[index]+"="+add_app;
account_str += "&"+sms_enable_csid[index]+"="+add_enable;
account_str += "&N803B0001=1&N80420715=1"
iframe.src = account_str+"&csrftok="+get_csrf_token();
setTimeout("show_sms_list();saveResult('9999')",2000);
swids("add_edit_tbsms",false);
}
function del_sms_account()
{
var tmp_del = document.getElementsByName("sms_del");
var del_arr = new Array();
var index = 0;
var del_index =0;
var new_index = 0;
var sent_str ="hide.htm?";
var iframe = document.getElementById("iframeH");
var reset_del = "";
var show_message = 0;
var show_message_str = "";
for(var t=0;t<tmp_del.length;t++)
{
var index = (tmp_del[t].value-1);
if(tmp_del[t].checked)
{
del_arr[del_index] = tmp_del[t].value;  //del_arr[del_index] �n�R����item
del_index++;
}
}
if(del_arr.length == 0)
{
alert(GetElmCont("lb_0","Please choose one or more rule."));
return false;
}
for(var r=0;r<sms_account_index.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(sms_account_index[r] == del_arr[n])
{
sms_account_index[r] = "";
}
}
}
for(var a=0;a<sms_account_csid.length;a++)
{
if(sms_account_index[a] != "")
{
sent_str += (sent_str == "hide.htm?")?sms_account_csid[new_index]+"="+sms_account_index[a]:"&"+sms_account_csid[new_index]+"="+sms_account_index[a];
new_index++;
}
}
for(var c=new_index;c<sms_account_csid.length;c++)
{
sent_str += (sent_str == "hide.htm?")?sms_account_csid[c]+"=":"&"+sms_account_csid[c]+"=";
}
for(var x=0;x<del_arr.length;x++)
{
var xx = del_arr[x]-1;
sent_str += (sent_str == "hide.htm?")?sms_phnumber_csid[xx]+"=":"&"+sms_phnumber_csid[xx]+"=";
sent_str += "&"+sms_enable_csid[xx]+"=0";
}
sent_str += "&N803B0001=1&N80420715=1"
iframe.src = sent_str+"&csrftok="+get_csrf_token();
setTimeout("show_sms_list();saveResult('9999')",2000);
}
function edit_apptp(initx){
var obj1 = document.getElementById("t_app")
var obj2 = document.getElementById("c_app_EventT")
var obj3 = document.getElementById("c_app_NotifyH")
obj1.value = (initx=='')?'0':initx;
obj2.checked = ((obj1.value==1)||(obj1.value==3))?true:false;
obj3.checked = ((obj1.value==2)||(obj1.value==3))?true:false;
}
function get_encode_value(id)
{
var obj = document.getElementById(id);
return (obj != null)?encodeURIComponent(obj.value):"";
}
function swSecuritykey(){
var obj0 = document.getElementById("c_security_key_enable");
var obj1 = document.getElementById("t_security_key");
obj1.disabled = ((!obj0.checked)||(obj0.disabled));
}