var evtn_record_next_index = 0;   //�ثe�Ĥ@���� �s�W�����X
var evtn_record_edit_index = 0;
var evtn_max_number = 10;         //�ثeCTA���w�}�X�̤j�Ӽ�
var delete_check_arr = [];
existschedulerule=new Array(
"")
for(var a=0;a<63;a++)
{
delete_check_arr[a] = 0;
}
/*
Add/Delete/Edit external server
evtn_account_next_index => �n���J C_WEBUI_VPNPPTPACC_RECORD_RULE ���U�@�� index �ΨӰO��Ū��CSID �o����
evtn_record_next_index => �U�@���� index  ���Ĥ@�Ӫťժ�CSID
by kent
*/
var evtn_account_csid = [];
var evtn_event_csid = [];
var evtn_descrip_csid = [];
var evtn_hanlder_csid = [];
var evtn_response_csid = [];
var evtn_timesche_csid = [];
var evtn_enable_csid = [];
evtn_account_csid.push("N00202AE0");
evtn_event_csid.push("S003B4000");
evtn_descrip_csid.push("S003B4300");
evtn_hanlder_csid.push("S003B4100");
evtn_response_csid.push("S003B4A00");
evtn_timesche_csid.push("N003B4400");
evtn_enable_csid.push("N003B4200");
evtn_account_csid.push("N00202AE1");
evtn_event_csid.push("S003B4001");
evtn_descrip_csid.push("S003B4301");
evtn_hanlder_csid.push("S003B4101");
evtn_response_csid.push("S003B4A01");
evtn_timesche_csid.push("N003B4401");
evtn_enable_csid.push("N003B4201");
evtn_account_csid.push("N00202AE2");
evtn_event_csid.push("S003B4002");
evtn_descrip_csid.push("S003B4302");
evtn_hanlder_csid.push("S003B4102");
evtn_response_csid.push("S003B4A02");
evtn_timesche_csid.push("N003B4402");
evtn_enable_csid.push("N003B4202");
evtn_account_csid.push("N00202AE3");
evtn_event_csid.push("S003B4003");
evtn_descrip_csid.push("S003B4303");
evtn_hanlder_csid.push("S003B4103");
evtn_response_csid.push("S003B4A03");
evtn_timesche_csid.push("N003B4403");
evtn_enable_csid.push("N003B4203");
evtn_account_csid.push("N00202AE4");
evtn_event_csid.push("S003B4004");
evtn_descrip_csid.push("S003B4304");
evtn_hanlder_csid.push("S003B4104");
evtn_response_csid.push("S003B4A04");
evtn_timesche_csid.push("N003B4404");
evtn_enable_csid.push("N003B4204");
evtn_account_csid.push("N00202AE5");
evtn_event_csid.push("S003B4005");
evtn_descrip_csid.push("S003B4305");
evtn_hanlder_csid.push("S003B4105");
evtn_response_csid.push("S003B4A05");
evtn_timesche_csid.push("N003B4405");
evtn_enable_csid.push("N003B4205");
evtn_account_csid.push("N00202AE6");
evtn_event_csid.push("S003B4006");
evtn_descrip_csid.push("S003B4306");
evtn_hanlder_csid.push("S003B4106");
evtn_response_csid.push("S003B4A06");
evtn_timesche_csid.push("N003B4406");
evtn_enable_csid.push("N003B4206");
evtn_account_csid.push("N00202AE7");
evtn_event_csid.push("S003B4007");
evtn_descrip_csid.push("S003B4307");
evtn_hanlder_csid.push("S003B4107");
evtn_response_csid.push("S003B4A07");
evtn_timesche_csid.push("N003B4407");
evtn_enable_csid.push("N003B4207");
evtn_account_csid.push("N00202AE8");
evtn_event_csid.push("S003B4008");
evtn_descrip_csid.push("S003B4308");
evtn_hanlder_csid.push("S003B4108");
evtn_response_csid.push("S003B4A08");
evtn_timesche_csid.push("N003B4408");
evtn_enable_csid.push("N003B4208");
evtn_account_csid.push("N00202AE9");
evtn_event_csid.push("S003B4009");
evtn_descrip_csid.push("S003B4309");
evtn_hanlder_csid.push("S003B4109");
evtn_response_csid.push("S003B4A09");
evtn_timesche_csid.push("N003B4409");
evtn_enable_csid.push("N003B4209");
function sw_s_Nhanlder(obj){
swids("s_Nhanlderdigitaloutput",((document.getElementById('c_hanlderN_DigitalOutput')!=null)&&(document.getElementById('c_hanlderN_DigitalOutput').checked)));
swids("s_Nhanldersyslog",((document.getElementById('c_hanlderN_Syslog')!=null)&&(document.getElementById('c_hanlderN_Syslog').checked)));
swids("s_Nhanlderemailalert",((document.getElementById('c_hanlderN_EmailAlert')!=null)&&(document.getElementById('c_hanlderN_EmailAlert').checked)));
swids("s_Nhanldermodbus",((document.getElementById('c_hanlderN_Modbus')!=null)&&(document.getElementById('c_hanlderN_Modbus').checked)));
}
function swNsubfunc(obj,tp){
if(tp =="e"){
swids("s_eventdi-1",(obj.value =='DI-1'));
swids("s_eventdi-2",(obj.value =='DI-2'));
swids("s_eventdigitalinput",(obj.value =='DigitalInput'));
swids("s_eventpowerchange",(obj.value =='PowerChange'));
swids("s_eventwan",(obj.value =='WAN'));
swids("s_eventlanvlan",(obj.value =='LANVLAN'));
swids("s_eventwifi",(obj.value =='WiFi'));
swids("s_eventddns",(obj.value =='DDNS'));
swids("s_eventadministration",(obj.value =='Administration'));
swids("s_eventmodbus_n",(obj.value =='Modbus'));
swids("s_eventdatausage",(obj.value =='DataUsage'));
}
else if(tp =="r"){
swids("s_responsesms",(obj.value =='SMS'));
swids("s_responsedo",(obj.value =='DO'));
swids("s_responsembus",(obj.value =='Modbus'));
}
}
function add_edit_evtn_account(type,edit_arr_index,edit_csid_index)
{
var add_edit_table = document.getElementById("add_edit_table_n");
var obj_save = document.getElementById("_wary_99");
var add_button = document.getElementById("add_save_button_N");
var edit_button = document.getElementById("edit_save_button_N");
var evtn_event = document.getElementById("s_evtn");
var evtn_descrip = document.getElementById("t_descrip");
var evtn_hanlder = document.getElementById("h_hanlder");
var evtn_timesche = document.getElementById("s_timesche");
var evtn_checked = document.getElementById("c_evtnenable");
var hanlder_clr = document.getElementsByName("na_Nhanlders");
var anchor = document.getElementById("_a_anchor_evtN");
if(type == 'add')
{
if(evtn_account_next_index == evtn_max_number)
{
alert("rule can't more than "+evtn_max_number);
return false;
}
evtn_event.value = evtn_event.options[0].value;
swNsubfunc(evtn_event,'e')
evtn_descrip.value = "";    //Description
evtn_hanlder.value = "";
clrHanlders_N()  //�M�� Hanlders
evtn_timesche.value = 0;    //Time Schedule
evtn_checked.checked = true;
}
else
{
var str_evt1 = evtn_event_arr[edit_arr_index]       // @SMS|3dsdsfdfs
var str_evt2 = get_splitmark_N(str_evt1,'|','0')      // @SMS
var str_evt3 = get_splitmark_N(str_evt2,'@','1')      // SMS
var str_evt4 = "s_Nevent_";  //id = s_Nevent_di-1
if(str_evt3 == "LAN&VLAN"){ str_evt3 = "LANVLAN" }
else if(str_evt3 == "Digital Input"){ str_evt3 = "DigitalInput" }
else if(str_evt3 == "Power Change"){ str_evt3 = "PowerChange" }
else if(str_evt3 == "Data Usage"){ str_evt3 = "DataUsage" }
evtn_event.value = str_evt3  //SMS
swNsubfunc(evtn_event,'e')
if(document.getElementById(str_evt4+str_evt3.toLowerCase())!=null){
var obj_evt1 = document.getElementById(str_evt4+str_evt3.toLowerCase()); //id=s_Nevent_sms
obj_evt1.value = encodeURI(get_splitmark_N(str_evt1,'|','1')) //3dsdsfdfs
if(str_evt3 == "DataUsage"){  //@Data Usage|1|4
obj_DUg = document.getElementById("t_Nevent_datausage")
obj_DUg.value = get_splitmark_N(str_evt1,'|','2')
}
}
evtn_descrip.value = evtn_descrip_arr[edit_arr_index]
var str_hanlder1 = evtn_hanlder_arr[edit_arr_index];  // @DO|0@Syslog|1@SNMP Trap@EmailAlert|0@Modbus|0
var ary_hanlder1 = str_hanlder1.split('@')  // [1]DO|0 [2]Syslog|1 [3]SNMP Trap [4]EmailAlert|0@Modbus|0
var str_hanlder2 = "c_hanlderN_"    //document.getElementById("c_hanlderN_DigitalOutput")
var ary_hanlder2 = [];
clrHanlders_N()  //�M�� Hanlders
for(kt=1;kt<ary_hanlder1.length;kt++){
var str_kt1 = ary_hanlder1[kt]  //[1]DO|0 [2]Syslog|1
var str_kt2 = get_splitmark_N(str_kt1,'|','0') //DO
if(str_kt2 == "SNMP Trap"){ str_kt2 = "SNMPTrap" }
else if(str_kt2 == "Email Alert"){ str_kt2 = "EmailAlert" }
else if(str_kt2 == "Digital Output"){ str_kt2 = "DigitalOutput" }
var obj_kt1 = document.getElementById(str_hanlder2+str_kt2)
obj_kt1.checked = true;     // --- ���ĳQ���� Hanlders �� checkbox ---
if( swhanlders != '1'){    //# swhanlders = 0  for 9r5_App_EvtMgmt_notify ; #swhanlders = 1  for 9b7_App_MApp_RemoteMgmt
sw_s_Nhanlder(obj_kt1);   // --- }Q?_ select or checkbox  span  ---
}
if(str_kt1.indexOf('|')!=-1){ //[1]DigitalOutput|0 [2]Syslog|1
var obj_kt2 = document.getElementById("s_"+obj_kt1.id)// id='s_c_hanlderN_DigitalOutput'
var sw1 = get_splitmark_N(str_kt1,'|','1')  //[1]DigitalOutput|0
if(str_kt2 == "Syslog"){ obj_kt2.checked = (sw1 == "1")?true:false ; }
else { obj_kt2.value = sw1 }
}
}
evtn_timesche.value = evtn_timesche_arr[edit_arr_index]
evtn_checked.checked = (evtn_enable_arr[edit_arr_index] == 1)?"checked":"";
evtn_record_edit_index = edit_csid_index;
}
add_edit_table.style.display = "";
add_button.style.display = (type == "add")?"":"none";
edit_button.style.display = (type == "add")?"none":"";
obj_save.style.display = "none"
anchor.click();
}
function getaddEvent_N(val0){ //str3 = @DI-1|On--> Off
var str1 = val0.toLowerCase();//val0=SNMPTrap
var str2 = "s_Nevent_"+str1;  // id='s_Nevent_snmptrap'
var str3 = ""//@SNMP Trap|TrapMsg
var obj1 = eval("document.getElementById('"+str2+"')")
var obj2 = document.getElementById("s_evtn")
for(a=0;a<obj2.length;a++){
if(obj2.options[a].value==val0){
str3 = escape(obj2.options[a].text) ;
break;
}
}
if((obj1!=null)&&(str3 == "Data%20Usage")){
obj11 =document.getElementById("t_Nevent_datausage")
str3 = "@"+str3+"|"+obj1.value+"|"+obj11.value ;
}
else if(obj1!=null){ str3 = "@"+str3+"|"+obj1.value ; }
return str3
}
function getadd_hanlders_N(){
var str1 = "c_hanlderN_";
var str2 = "s_";
var strx = ""   //@WAN|LTE-1 Reconnect|LTE-2 LTE@WiFi|2.4G WiFi On@.....
var hanlders_save = document.getElementsByName("na_Nhanlders");
for(var g=0;g<hanlders_save.length;g++){
if(hanlders_save[g].checked){
var str5 = hanlders_save[g].id //c_hanlderN_DigitalOutput
var str3 = get_splitmark_N(str5,'c_hanlderN_','1');  //DO
var str4 = str2 + str5; // s_c_hanlderN_DigitalOutput
var obj1 = document.getElementById(str4); // s_c_hanlderN_DigitalOutput
if(str3 == "SNMPTrap"){ str3 = "SNMP Trap" }
else if(str3 == "EmailAlert"){ str3 = "Email Alert" }
else if(str3 == "DigitalOutput"){ str3 = "Digital Output" }
strx += "@"+str3;
if(obj1 != null){
if(str3 == "Syslog"){ strx += "|" + ((obj1.checked)?1:0) }
else { strx += "|"+obj1.value }
}
}
}
return strx
}
function save_evtn(type,obj)
{
var add_evtn = get_encode_value("s_evtn");
var add_descrip = get_encode_value("t_descrip");
var add_hanlders = get_encode_value("h_hanlder");
var add_s_timesche = get_encode_value("s_timesche");
var add_checked = document.getElementById("c_evtnenable").checked;
var add_enable = (add_checked)?1:0;
var index = (type == 'add')?evtn_record_next_index:evtn_record_edit_index;
var account_str = "hide.htm?";
var str_message = "";
var iframe = document.getElementById("iframeH");
var str_hanlders_N = "";
saveResult()
if(add_evtn == "")
{
str_message = (add_evtn == "")?"Name can not be empty":"Signal Active Time can not be empty";
alert(str_message);
return false;
}
if(add_descrip == "")
{
str_message = "Description can not be empty";
alert(str_message);
return false;
}
if(!chkForm())
{
return false;
}
str_hanlders_N = getadd_hanlders_N();
if(str_hanlders_N == ""){
alert("Action is invalid");
return false;
}
if(type == 'add')
{
account_str += evtn_account_csid[evtn_account_next_index]+"="+(index+1)+"&";
}
account_str += evtn_event_csid[index]+"="+getaddEvent_N(add_evtn);
account_str += "&"+evtn_descrip_csid[index]+"="+add_descrip;
account_str += "&"+evtn_hanlder_csid[index]+"="+str_hanlders_N;
account_str += "&"+evtn_timesche_csid[index]+"="+add_s_timesche;
account_str += "&"+evtn_enable_csid[index]+"="+add_enable;
account_str += "&N803B0001=1&N80420715=1"
iframe.src = account_str+'&csrftok='+get_csrf_token();
setTimeout("show_evtn_list();saveResult('9999')",2000);
swids("add_edit_table_n",false);
}
function save_evtn1(type,obj){// for paggy test
var add_evtn = get_encode_value("s_evtn");
}
function del_evtm_N()
{
var tmp_del = document.getElementsByName("evtm_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<evtn_account_index.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(evtn_account_index[r] == del_arr[n])
{
evtn_account_index[r] = "";
}
}
}
for(var a=0;a<evtn_account_csid.length;a++)
{
if(evtn_account_index[a] != "")
{
sent_str += (sent_str == "hide.htm?")?evtn_account_csid[new_index]+"="+evtn_account_index[a]:"&"+evtn_account_csid[new_index]+"="+evtn_account_index[a];
new_index++;
}
}
for(var c=new_index;c<evtn_account_csid.length;c++)
{
sent_str += (sent_str == "hide.htm?")?evtn_account_csid[c]+"=":"&"+evtn_account_csid[c]+"=";
}
for(var x=0;x<del_arr.length;x++)
{
var xx = del_arr[x]-1;
sent_str += (sent_str == "hide.htm?")?evtn_descrip_csid[xx]+"=":"&"+evtn_descrip_csid[xx]+"=";
sent_str += "&"+evtn_enable_csid[xx]+"=0";
}
iframe.src = sent_str+'&csrftok='+get_csrf_token();
setTimeout("show_evtn_list()",2000);
}
function get_encode_value(id)
{
var obj = document.getElementById(id);
return (obj != null)?encodeURIComponent(obj.value):"";
}
function clrHanlders_N(){
var hanlder_clr = document.getElementsByName("na_Nhanlders");
for(var t=0;t<hanlder_clr.length;t++){//---  �����Ҧ��Q������ checkbox ---
hanlder_clr[t].checked = false ;
sw_s_Nhanlder(hanlder_clr[t])
}
}
function get_splitmark_N(xx,tp,aryEix){
var str1 =xx;
if(str1.indexOf(tp)!=-1){
var ary_x = str1.split(tp)  // @SMS|3dsdsfdfs.split('|') or @SMS.split('@')
return ary_x[aryEix]
}
else { return str1 ; }
}
function displayschesel(){
for(k=0;k<existschedulerule.length-1;k++)
{
sches=existschedulerule[k].split(" : ")
dw("<option value="+sches[0]+" id='s_schesel_"+k+"'>("+sches[0]+") "+sches[1])
}
}