var doprofile_record_next_index = 0;   //�ثe�Ĥ@���� �s�W�����X
var doprofile_record_edit_index = 0;
var doprofile_max_number = 10;         //�ثeCTA���w�}�X�̤j�Ӽ�
var doprofile_count =0;
var delete_check_arr = [];
for(var a=0;a<63;a++)
{
delete_check_arr[a] = 0;
}
/*
Add/Delete/Edit external server
doprofile_account_next_index => �n���J C_WEBUI_VPNPPTPACC_RECORD_RULE ���U�@�� index �ΨӰO��Ū��CSID �o����
doprofile_record_next_index => �U�@���� index  ���Ĥ@�Ӫťժ�CSID
by kent
*/
var doprofile_account_csid = [];
var doprofile_name_csid = [];
var doprofile_desc_csid = [];
var doprofile_source_csid = [];
var doprofile_normallvl_csid = [];
var doprofile_acttime_csid = [];
var doprofile_repeat_csid = [];    //Repeat
var doprofile_repcoun_csid = [];    //Rep_Counter
var doprofile_dutycyc_csid = [];   //Duty Cycle
var doprofile_enable_csid = [];
doprofile_account_csid.push("N0020121E");
doprofile_name_csid.push("S003B8800");
doprofile_desc_csid.push("S003BB400");
doprofile_source_csid.push("N003B8900");
doprofile_normallvl_csid.push("N003B8A00");
doprofile_acttime_csid.push("N003B8B00");
doprofile_repeat_csid.push("N003B8C00");    //Repeat
doprofile_repcoun_csid.push("N003B8E00");   //Rep_Counter
doprofile_dutycyc_csid.push("N003B8D00");   //Duty Cycle
doprofile_enable_csid.push("N003BA300");
doprofile_account_csid.push("N0020121F");
doprofile_name_csid.push("S003B8801");
doprofile_desc_csid.push("S003BB401");
doprofile_source_csid.push("N003B8901");
doprofile_normallvl_csid.push("N003B8A01");
doprofile_acttime_csid.push("N003B8B01");
doprofile_repeat_csid.push("N003B8C01");    //Repeat
doprofile_repcoun_csid.push("N003B8E01");   //Rep_Counter
doprofile_dutycyc_csid.push("N003B8D01");   //Duty Cycle
doprofile_enable_csid.push("N003BA301");
doprofile_account_csid.push("N00201220");
doprofile_name_csid.push("S003B8802");
doprofile_desc_csid.push("S003BB402");
doprofile_source_csid.push("N003B8902");
doprofile_normallvl_csid.push("N003B8A02");
doprofile_acttime_csid.push("N003B8B02");
doprofile_repeat_csid.push("N003B8C02");    //Repeat
doprofile_repcoun_csid.push("N003B8E02");   //Rep_Counter
doprofile_dutycyc_csid.push("N003B8D02");   //Duty Cycle
doprofile_enable_csid.push("N003BA302");
doprofile_account_csid.push("N00201221");
doprofile_name_csid.push("S003B8803");
doprofile_desc_csid.push("S003BB403");
doprofile_source_csid.push("N003B8903");
doprofile_normallvl_csid.push("N003B8A03");
doprofile_acttime_csid.push("N003B8B03");
doprofile_repeat_csid.push("N003B8C03");    //Repeat
doprofile_repcoun_csid.push("N003B8E03");   //Rep_Counter
doprofile_dutycyc_csid.push("N003B8D03");   //Duty Cycle
doprofile_enable_csid.push("N003BA303");
doprofile_account_csid.push("N00201222");
doprofile_name_csid.push("S003B8804");
doprofile_desc_csid.push("S003BB404");
doprofile_source_csid.push("N003B8904");
doprofile_normallvl_csid.push("N003B8A04");
doprofile_acttime_csid.push("N003B8B04");
doprofile_repeat_csid.push("N003B8C04");    //Repeat
doprofile_repcoun_csid.push("N003B8E04");   //Rep_Counter
doprofile_dutycyc_csid.push("N003B8D04");   //Duty Cycle
doprofile_enable_csid.push("N003BA304");
doprofile_account_csid.push("N00201223");
doprofile_name_csid.push("S003B8805");
doprofile_desc_csid.push("S003BB405");
doprofile_source_csid.push("N003B8905");
doprofile_normallvl_csid.push("N003B8A05");
doprofile_acttime_csid.push("N003B8B05");
doprofile_repeat_csid.push("N003B8C05");    //Repeat
doprofile_repcoun_csid.push("N003B8E05");   //Rep_Counter
doprofile_dutycyc_csid.push("N003B8D05");   //Duty Cycle
doprofile_enable_csid.push("N003BA305");
doprofile_account_csid.push("N00201224");
doprofile_name_csid.push("S003B8806");
doprofile_desc_csid.push("S003BB406");
doprofile_source_csid.push("N003B8906");
doprofile_normallvl_csid.push("N003B8A06");
doprofile_acttime_csid.push("N003B8B06");
doprofile_repeat_csid.push("N003B8C06");    //Repeat
doprofile_repcoun_csid.push("N003B8E06");   //Rep_Counter
doprofile_dutycyc_csid.push("N003B8D06");   //Duty Cycle
doprofile_enable_csid.push("N003BA306");
doprofile_account_csid.push("N00201225");
doprofile_name_csid.push("S003B8807");
doprofile_desc_csid.push("S003BB407");
doprofile_source_csid.push("N003B8907");
doprofile_normallvl_csid.push("N003B8A07");
doprofile_acttime_csid.push("N003B8B07");
doprofile_repeat_csid.push("N003B8C07");    //Repeat
doprofile_repcoun_csid.push("N003B8E07");   //Rep_Counter
doprofile_dutycyc_csid.push("N003B8D07");   //Duty Cycle
doprofile_enable_csid.push("N003BA307");
doprofile_account_csid.push("N00201226");
doprofile_name_csid.push("S003B8808");
doprofile_desc_csid.push("S003BB408");
doprofile_source_csid.push("N003B8908");
doprofile_normallvl_csid.push("N003B8A08");
doprofile_acttime_csid.push("N003B8B08");
doprofile_repeat_csid.push("N003B8C08");    //Repeat
doprofile_repcoun_csid.push("N003B8E08");   //Rep_Counter
doprofile_dutycyc_csid.push("N003B8D08");   //Duty Cycle
doprofile_enable_csid.push("N003BA308");
doprofile_account_csid.push("N00201227");
doprofile_name_csid.push("S003B8809");
doprofile_desc_csid.push("S003BB409");
doprofile_source_csid.push("N003B8909");
doprofile_normallvl_csid.push("N003B8A09");
doprofile_acttime_csid.push("N003B8B09");
doprofile_repeat_csid.push("N003B8C09");    //Repeat
doprofile_repcoun_csid.push("N003B8E09");   //Rep_Counter
doprofile_dutycyc_csid.push("N003B8D09");   //Duty Cycle
doprofile_enable_csid.push("N003BA309");
function SWdorepcoun(obj){
var obj1 = document.getElementById("t_dorepcoun");
obj1.disabled = (!obj.checked)
}
function add_edit_doprofile_account(type,edit_arr_index,edit_csid_index)
{
var add_edit_table = document.getElementById("add_edit_table1");
var add_button = document.getElementById("add_save_button1");
var edit_button = document.getElementById("edit_save_button1");
var doprofile_name = document.getElementById("t_doname");
var doprofile_desc = document.getElementById("t_dodesc");
var doprofile_source = document.getElementById("t_dosource");
var doprofile_normallvl = document.getElementById("t_donormallvl");
var doprofile_acttime = document.getElementById("t_doacttime");
var doprofile_checked1 = document.getElementById("c_dorepeat"); //Repeat
var doprofile_t_repcoun = document.getElementById("t_dorepcoun");  //Rep_Counter
var doprofile_dutycyc = document.getElementById("t_dodutycyc"); //Duty Cycle
var doprofile_checked = document.getElementById("c_doenable");
var anchor = document.getElementById("_a_anchor_do");
if(type == 'add')
{
if(doprofile_account_next_index == doprofile_max_number)
{
alert("rule can't more than "+doprofile_max_number);
return false;
}
doprofile_name.value = "";
doprofile_desc.value = "";
doprofile_source.value = 1;
doprofile_normallvl.value = 0;
doprofile_acttime.value = 10;
doprofile_checked1.checked = false; //Repeat
doprofile_t_repcoun.value = 0;  //Rep_Counter
doprofile_dutycyc.value = "";      //Duty Cycle
doprofile_checked.checked = true;
}
else
{
doprofile_name.value = doprofile_name_arr[edit_arr_index];
doprofile_desc.value = doprofile_desp_arr[edit_arr_index];
doprofile_source.value = doprofile_source_arr[edit_arr_index];
doprofile_normallvl.value = doprofile_normallvl_arr[edit_arr_index];
doprofile_acttime.value = parseInt(doprofile_acttime_arr[edit_arr_index]);
doprofile_checked1.checked = (doprofile_repeat_arr[edit_arr_index] == 1)?"checked":"";//Repeat
doprofile_t_repcoun.value = parseInt(doprofile_repcoun_arr[edit_arr_index]);    //Rep_Counter
doprofile_dutycyc.value = parseInt(doprofile_dutycyc_arr[edit_arr_index]);            //Duty Cycle
doprofile_checked.checked = (doprofile_enable_arr[edit_arr_index] == 1)?"checked":"";
doprofile_record_edit_index = edit_csid_index;
}
SWdorepcoun(doprofile_checked1);
sw_configtab(add_edit_table)
add_edit_table.style.display = "";
add_button.style.display = (type == "add")?"":"none";
edit_button.style.display = (type == "add")?"none":"";
anchor.click();
chkN(doprofile_acttime,'c','10-10000');
}
function save_doprofile(type,obj)
{
var add_name = get_encode_value("t_doname");
var add_desc = get_encode_value("t_dodesc");
var add_source = get_encode_value("t_dosource");
var add_normallvl = get_encode_value("t_donormallvl");
var add_acttime = get_encode_value("t_doacttime");
var add_checked1 = document.getElementById("c_dorepeat").checked; //Repeat
var add_repcoun = get_encode_value("t_dorepcoun"); //Rep_Counter
var add_dutycyc = get_encode_value("t_dodutycyc"); //Duty Cycle
var add_checked = document.getElementById("c_doenable").checked;
var add_enable = (add_checked)?1:0;
var add_enable1 = (add_checked1)?1:0;
var index = (type == 'add')?doprofile_record_next_index:doprofile_record_edit_index;
var account_str = "hide.htm?";
var str_message = "";
var iframe = document.getElementById("iframeH");
saveResult();
if(add_name == "" || add_dutycyc == "")
{
str_message = (add_name == "")?"Name can not be empty":"Duty Cycle can not be empty";
alert(str_message);
return false;
}
if(add_desc=="") {alert(GetElmCont("_0","Description can not be empty"));return false;}
if(!chkForm())
{
return false;
}
if(type == 'add')
{
account_str += doprofile_account_csid[doprofile_account_next_index]+"="+(index+1)+"&";
}
account_str += doprofile_name_csid[index]+"="+add_name;
account_str += "&"+doprofile_desc_csid[index]+"="+add_desc;
account_str += "&"+doprofile_source_csid[index]+"="+add_source;
account_str += "&"+doprofile_normallvl_csid[index]+"="+add_normallvl;
account_str += "&"+doprofile_acttime_csid[index]+"="+add_acttime;
account_str += "&"+doprofile_repeat_csid[index]+"="+add_enable1;//Repeat
account_str += "&"+doprofile_repcoun_csid[index]+"="+add_repcoun;//Rep_Counter
account_str += "&"+doprofile_dutycyc_csid[index]+"="+add_dutycyc;//Duty Cycle
account_str += "&"+doprofile_enable_csid[index]+"="+add_enable;
account_str += "&N803B0001=1&N80420715=1"
iframe.src = account_str+"&csrftok="+get_csrf_token();
setTimeout("show_doprofile_list();saveResult('9999')",2000);
swids("add_edit_table1",false);
}
function del_doprofile()
{
var tmp_del = document.getElementsByName("doprofile_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<doprofile_account_index.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(doprofile_account_index[r] == del_arr[n])
{
doprofile_account_index[r] = "";
}
}
}
for(var a=0;a<doprofile_account_csid.length;a++)
{
if(doprofile_account_index[a] != "")
{
sent_str += (sent_str == "hide.htm?")?doprofile_account_csid[new_index]+"="+doprofile_account_index[a]:"&"+doprofile_account_csid[new_index]+"="+doprofile_account_index[a];
new_index++;
}
}
for(var c=new_index;c<doprofile_account_csid.length;c++)
{
sent_str += (sent_str == "hide.htm?")?doprofile_account_csid[c]+"=":"&"+doprofile_account_csid[c]+"=";
}
for(var x=0;x<del_arr.length;x++)
{
var xx = del_arr[x]-1;
sent_str += (sent_str == "hide.htm?")?doprofile_name_csid[xx]+"=":"&"+doprofile_name_csid[xx]+"=";
sent_str += "&"+doprofile_enable_csid[xx]+"=0";
}
sent_str += "&N803B0001=1&N80420715=1"
iframe.src = sent_str+"&csrftok="+get_csrf_token();
setTimeout("show_doprofile_list();saveResult('9999')",2000);
}
function get_encode_value(id)
{
var obj = document.getElementById(id);
return (obj != null)?encodeURIComponent(obj.value):"";
}