var email_record_next_index = 0;   //�ثe�Ĥ@���� �s�W�����X
var email_record_edit_index = 0;
var emailsvifi_MAX = 5;         //�ثeCTA���w�}�X�̤j�Ӽ�
var email_count =0;
var delete_check_arr = [];
for(var a=0;a<63;a++)
{
delete_check_arr[a] = 0;
}
/*
Add/Delete/Edit external server
email_account_next_index => �n���J C_WEBUI_VPNPPTPACC_RECORD_RULE ���U�@�� index �ΨӰO��Ū��CSID �o����
email_record_next_index => �U�@���� index  ���Ĥ@�Ӫťժ�CSID
by kent
*/
var email_account_csid = [];
var email_sver_csid = [];
var email_add_csid = [];
var email_enable_csid = [];
email_account_csid.push("N002012B1");
email_sver_csid.push("N003B6500");
email_add_csid.push("S003B6600");
email_enable_csid.push("N003BA100");
email_account_csid.push("N002012B2");
email_sver_csid.push("N003B6501");
email_add_csid.push("S003B6601");
email_enable_csid.push("N003BA101");
email_account_csid.push("N002012B3");
email_sver_csid.push("N003B6502");
email_add_csid.push("S003B6602");
email_enable_csid.push("N003BA102");
email_account_csid.push("N002012B4");
email_sver_csid.push("N003B6503");
email_add_csid.push("S003B6603");
email_enable_csid.push("N003BA103");
email_account_csid.push("N002012B5");
email_sver_csid.push("N003B6504");
email_add_csid.push("S003B6604");
email_enable_csid.push("N003BA104");
function add_edit_emailservc(type,edit_arr_index,edit_csid_index)
{
var add_edit_tbemail = document.getElementById("add_edit_tbemail");
var add_button = document.getElementById("add_save_buttonemail");
var edit_button = document.getElementById("edit_save_buttonmail");
var email_sver = document.getElementById("t_emailsver");
var email_add = document.getElementById("t_emailadd");
var email_checked = document.getElementById("c_enable_email");

var anchor = document.getElementById("_a_anchor_email");
if(type == 'add')
{
if(email_account_next_index == emailsvifi_MAX)
{
alert("rule can't more than "+emailsvifi_MAX);
return false;
}
email_sver.value = 0;
email_add.value = "";
email_checked.checked = true;
}
else
{
email_sver.value = email_server_arr[edit_arr_index];
email_add.value = email_add_arr[edit_arr_index];
email_checked.checked = (email_enable_arr[edit_arr_index] == 1)?"checked":"";
email_record_edit_index = edit_csid_index;
}
sw_configtab(add_edit_tbemail);
add_edit_tbemail.style.display = "";
add_button.style.display = (type == "add")?"":"none";
edit_button.style.display = (type == "add")?"none":"";
anchor.click();
}
function save_emailservc(type,obj)
{
var add_emailsver = get_encode_value("t_emailsver");
var add_emailadd = get_encode_value("t_emailadd");
var add_checked = document.getElementById("c_enable_email").checked;
var add_enable = (add_checked)?1:0;
var index = (type == 'add')?email_record_next_index:email_record_edit_index;
var account_str = "hide.htm?";
var str_message = "";
var iframe = document.getElementById("iframeH");
saveResult();
if(((add_emailsver == "0")||(add_emailadd ==""))&&(add_checked))
{
str_message = GetElmCont("_0","Email Server is invalid!")
alert(str_message);
return false;
}
if(!chkForm())
{
return false;
}
if(type == 'add')
{
account_str += email_account_csid[email_account_next_index]+"="+(index+1)+"&";
}
account_str += email_sver_csid[index]+"="+add_emailsver;
account_str += "&"+email_add_csid[index]+"="+add_emailadd;
account_str += "&"+email_enable_csid[index]+"="+add_enable;
account_str += "&N803B0001=1&N80420715=1"
iframe.src = account_str+"&csrftok="+get_csrf_token();
setTimeout("show_emailservc_list();saveResult('9999')",2000);
swids("add_edit_tbemail",false);
}
function del_emailservc()
{
var tmp_del = document.getElementsByName("email_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<email_account_index.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(email_account_index[r] == del_arr[n])
{
email_account_index[r] = "";
}
}
}
for(var a=0;a<email_account_csid.length;a++)
{
if(email_account_index[a] != "")
{
sent_str += (sent_str == "hide.htm?")?email_account_csid[new_index]+"="+email_account_index[a]:"&"+email_account_csid[new_index]+"="+email_account_index[a];
new_index++;
}
}
for(var c=new_index;c<email_account_csid.length;c++)
{
sent_str += (sent_str == "hide.htm?")?email_account_csid[c]+"=":"&"+email_account_csid[c]+"=";
}
for(var x=0;x<del_arr.length;x++)
{
var xx = del_arr[x]-1;
sent_str += (sent_str == "hide.htm?")?email_add_csid[xx]+"=":"&"+email_add_csid[xx]+"=";
sent_str += "&"+email_enable_csid[xx]+"=0";
}
sent_str += "&N803B0001=1&N80420715=1"
iframe.src = sent_str+"&csrftok="+get_csrf_token();
setTimeout("show_emailservc_list();saveResult('9999')",2000);
}
function get_encode_value(id)
{
var obj = document.getElementById(id);
return (obj != null)?encodeURIComponent(obj.value):"";
}
function get_emailserver_op(ids,selval){
var select = document.getElementById(ids);
var option = new Option("--- Option ---",0);
var select_value = parseInt(selval);
select.innerHTML = "";
select.add(option);
for(var a=0;a<external_server_account_index.length;a++)
{
var enable = parseInt(external_enable_arr[a]);
if(external_name_arr[a] != "" && external_type_arr[a] == 1 && enable)
{
option = new Option(external_name_arr[a],external_server_account_index[a]);
select.add(option);
}
}
}