var gre_record_next_index = 0;
var gre_max_number = 32;
var gre_count =0;
/*
Add/Delete/Edit pptp client account
pptp_account_next_index => �n���J C_WEBUI_VPNPPTPACC_RECORD_RULE ���U�@�� index �ΨӰO��Ū��CSID �o����
next_index => �U�@�� account �� index  �� C_PPTPSERV_ACCOUNT_USER �Ĥ@�Ӫťժ�CSID
by kent
*/
var gre_record_csid = new Array(
"N00202140",
"N00202141",
"N00202142",
"N00202143",
"N00202144",
"N00202145",
"N00202146",
"N00202147",
"N00202148",
"N00202149",
"N0020214A",
"N0020214B",
"N0020214C",
"N0020214D",
"N0020214E",
"N0020214F",
"N00202150",
"N00202151",
"N00202152",
"N00202153",
"N00202154",
"N00202155",
"N00202156",
"N00202157",
"N00202158",
"N00202159",
"N0020215A",
"N0020215B",
"N0020215C",
"N0020215D",
"N0020215E",
"N0020215F",
""
)
var gre_record_index = new Array(
"1",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
)
var gre_tunlname_csid = new Array(
"S00710100",
"S00710101",
"S00710102",
"S00710103",
"S00710104",
"S00710105",
"S00710106",
"S00710107",
"S00710108",
"S00710109",
"S0071010A",
"S0071010B",
"S0071010C",
"S0071010D",
"S0071010E",
"S0071010F",
"S00710110",
"S00710111",
"S00710112",
"S00710113",
"S00710114",
"S00710115",
"S00710116",
"S00710117",
"S00710118",
"S00710119",
"S0071011A",
"S0071011B",
"S0071011C",
"S0071011D",
"S0071011E",
"S0071011F",
""
)
var gre_dmvpn_csid = new Array(
"N00711400",
"N00711401",
"N00711402",
"N00711403",
"N00711404",
"N00711405",
"N00711406",
"N00711407",
"N00711408",
"N00711409",
"N0071140A",
"N0071140B",
"N0071140C",
"N0071140D",
"N0071140E",
"N0071140F",
"N00711410",
"N00711411",
"N00711412",
"N00711413",
"N00711414",
"N00711415",
"N00711416",
"N00711417",
"N00711418",
"N00711419",
"N0071141A",
"N0071141B",
"N0071141C",
"N0071141D",
"N0071141E",
"N0071141F",
""
)
var gre_ruleEN_csid = new Array(
"N00710200",
"N00710201",
"N00710202",
"N00710203",
"N00710204",
"N00710205",
"N00710206",
"N00710207",
"N00710208",
"N00710209",
"N0071020A",
"N0071020B",
"N0071020C",
"N0071020D",
"N0071020E",
"N0071020F",
"N00710210",
"N00710211",
"N00710212",
"N00710213",
"N00710214",
"N00710215",
"N00710216",
"N00710217",
"N00710218",
"N00710219",
"N0071021A",
"N0071021B",
"N0071021C",
"N0071021D",
"N0071021E",
"N0071021F",
""
)
var gre_record_length = 0;
for(var g=0;g<gre_record_index.length;g++)
{
if(gre_record_index[g] == "")
{
gre_record_length = g;
break;
}
}
function Interfc_bfsmit(obj){
var disop_ix = "X"
for(a=0;a<obj.length;a++){
if(obj.options[a].value==''){ disop_ix = obj.options[a].value ;break; }
}
/*  alert("del ss1="+(!obj.disabled)
+" ,ss2="+(disop_ix != "X")
+" ,ss3="+(obj.value == disop_ix)
+" ,disop_ix='"+disop_ix+"'"
+" ,obj.value='"+obj.value+"'"
)
*/
if((!obj.disabled)&&(disop_ix != "X")&&(obj.value == disop_ix)){
alert(GetElmCont("gre_0","Interface has expired, please confirm again.")) ;
return false
}
return true
}
function Interfc_sel(sel0 , sel1 , sel2){
/* (sel2 != null) == for edit page
sel0: Name ; sel1: id
LAN and VLAN value �q30�}�l
*/
var p_nb0 = 30
arrw=Interfc_info(1)  //arrw[0] = Wan1 ; arrw[1] = Wan2 ;arrw[2] = Wan3 ;
arrVL=Interfc_info(0) //aryVL[0] = Lan ; aryVL[1] = VLan1 ; aryVL[2] = VLan2 ; aryVL[3] = VLan3
str0 ="<select name="+sel0+" id="+sel1+">"
for(o=0;o<arrw.length;o++){
/*if((sel2!= null)&&(o == sel2)&&(arrw[o] != "0")) { str0+="<option value='' selected>WAN"+(o+1)+"</option>" }
else */if((sel2!= null)&&(o == sel2)) { str0+="<option value='"+o+"' selected>WAN"+(o+1)+"</option>" }
else if(arrw[o] != "2") { str0+="<option value='"+o+"'>WAN"+(o+1)+"</option>" }
}
if((sel2!= null)&&(p_nb0 == sel2)) { str0+="<option id=_wiz_0 value='"+p_nb0+"' selected>LAN</option>" }
else {str0+="<option id=_wiz_0 value='"+p_nb0+"'>LAN</option>"}
for(w=1;w<arrVL.length;w++){
if((sel2!= null)&&((p_nb0+w) == sel2)&&(arrVL[w] == "0")) { str0+="<option value='' selected>VLan"+w+"</option>" }
else if((sel2!= null)&&((p_nb0+w) == sel2)) { str0+="<option value='"+(p_nb0+w)+"' selected>VLan"+w+"</option>" }
else if(arrVL[w] != "0") { str0+="<option value='"+(p_nb0+w)+"'>VLan"+w+"</option>" }
}
str0+="</select>"
return str0
}
function add_gre_account(obj){
if(gre_record_length != gre_max_number)
{
obj.form.action = "greadd.htm";
obj.form.Ntid.value = (gre_record_next_index+1);
obj.form.Ngrelen.value = gre_record_length;
obj.form.Nrule.value = gre_record_next_index;
obj.form.submit();
}
else
{
alert(GetElmCont("pptps_0","Rule could not be added anymore."));
}
}
function del_tunnel(){
var tmp_del = document.getElementsByName("gre_del");
var del_arr = new Array();
var index = 0;
var new_index = 0;
var sent_str ="gre.htm?";
for(var t=0;t<tmp_del.length;t++)
{
if(tmp_del[t].checked)
{
del_arr[index] = tmp_del[t].value;
index++;
}
}
if(del_arr.length == 0)
{
alert(GetElmCont("lb_0","Please choose one or more rule."));
return false;
}
for(var r=0;r<gre_record_index.length;r++)
{
for(var n=0;n<del_arr.length;n++)
{
if(gre_record_index[r] == del_arr[n])
{
gre_record_index[r] = "";
}
}
}
for(var a=0;a<gre_record_index.length;a++)
{
if(gre_record_index[a] != "")
{
sent_str += (sent_str == "gre.htm?")?gre_record_csid[new_index]+"="+gre_record_index[a]:"&"+gre_record_csid[new_index]+"="+gre_record_index[a];
new_index++;
}
}
for(var c=new_index;c<gre_record_csid.length-1;c++)
{
sent_str += (sent_str == "gre.htm?")?gre_record_csid[c]+"=":"&"+gre_record_csid[c]+"=";
}
for(var r=0;r<del_arr.length;r++)
{
var tunlname_index = del_arr[r]-1;
sent_str += "&"+gre_tunlname_csid[tunlname_index]+"=&"+gre_dmvpn_csid[tunlname_index]+"=0&"+gre_ruleEN_csid[tunlname_index]+"=0";
}
sent_str += "&_cce=0x80710001";
GURL(sent_str);
}
function clkdefgw(dgwck){
if(dgwck == 1)
{
}
else chkS(document.getElementById('t_subnet'),'s')
}
function swInterfc(obj){
gswan = document.getElementById("s_gre_wan");
gswan.disabled = ((typeof(obj) == 'object')&&(obj.value == 2))?true:false;
}
function ck_MaxTuns(){
var int0 = gre_record_length
gobj0 = document.getElementById('tunnelno')
if(gobj0.value < int0){
alert(GetElmCont("gre_0","Max. Tunnel value is invalid.")) ;
gobj0.focus();
return false;
}
return true;
}
function chk(f){
var gre_tname = document.getElementById('t_gre_tname').value;
var gre_tpeer_ip = document.getElementById('t_gre_peer_ip').value;
var gre_tkey = document.getElementById('t_gre_key').value;
var gre_tttl = document.getElementById('t_gre_ttl').value;
var gsgwan = document.getElementById('s_gre_wan');
var str_messge = "";
var id_arr = new Array("t_gre_tname","t_gre_peer_ip","t_gre_ttl")
var str_arr = new Array(GetElmCont("stavpn_0","Tunnel Name"),"Remote IP","TTL")
var tmp_vale = "";
if(!chkForm()) { return false }
if(!chksn()){ return false }  //ck Remote Subnet(Default Gateway/Remote Subnet)
if(!Interfc_bfsmit(gsgwan)){ return false }  // ck Interface
for(var a=0;a<id_arr.length;a++)
{
tmp_vale = document.getElementById(id_arr[a]).value;
if(tmp_vale == "")
{
str_messge += (str_messge == "")?str_arr[a]:" , "+str_arr[a];
}
}
if(str_messge != ""){
str_messge += GetElmCont("vpn1_0"," can not be empty");
alert(str_messge);
return false;
}
var checked = document.getElementById("c_keep_alive_en").checked;
var h_alive_ip = document.getElementById("h_gre_keep_alive_ip");
var alive_ip = document.getElementById("t_gre_keep_alive_ip").value;
var alive_fqdn = document.getElementById("t_gre_keep_alive_fqdn").value;
var select  = document.getElementById("s_keep_alive").value;
var str_message = "";
if(checked == true){
if((select == 0 && alive_ip == "")||(select == 1 && alive_fqdn == ""))
{
str_message = (select == 0)?GetElmCont("vpn1_0","Ping IP can not be empty."):GetElmCont("vpn1_0","Ping FQDN can not be empty.");
alert(str_message);
return false;
}
}
h_alive_ip.value = (select == 0)?alive_ip:alive_fqdn;
var glip = document.getElementById('t_gre_local_ip');
var glmask = document.getElementById('s_gre_local_ip_mask');
var chk = ((glip.value == "0.0.0.0")||(glip.value == ""));
if(!chk && (glmask.value == "0")){
alert(GetElmCont("_0","MASK is invalid!"));
return false;
}
glip.value = (glip.value == "")?"0.0.0.0":glip.value;
return true;
}
function chk_keep(value){
var alive_ip = document.getElementById("t_gre_keep_alive_ip");
var alive_fqdn = document.getElementById("t_gre_keep_alive_fqdn");
alive_ip.style.display = (value == 0)?"":"none";
alive_fqdn.style.display = (value == 1)?"":"none";
}
function swtun_fover(obj1){ //#--  Operation Mode/FailOver
gopfoved = document.getElementById("opmode_foved")
gopfailover = document.getElementById("opmode_failover")
if((ary_ipsecTN == null)&&(ary_pptpTN == null)&&(ary_l2tpTN == null)&&(ary_greTN == null)) {
for(var t=0;t<gopfailover.length;t++) {
if((gopfailover.value == 1)&&(gopfailover.options[t].value == 0))
{ gopfailover.options[t].selected = true }
if(gopfailover.options[t].value == 1){ gopfailover.options[t].disabled = true }
}
}
if(obj1.value == 1){ create_Tunty(); }
else { gopfoved.innerHTML = ""; }
}
function chkfover_sn(val){  //#--for GRE failover on�Ack failover���H��peer subnet
obj0 = document.getElementById("s_tun_type_failover")
ckary0 = ""   //  ipsec_Tsub
ckary1 = ""   //  pptpcli_Psub
ckary2 = ""   //  l2tp_Psub
ckary3 = ""   //  gre_Psub
if(obj0 != null ){
ckaryX = splits(eval("ckary"+obj0.value),";")
for(var q=0;q<ckaryX.length;q++){
val3=val.substring(0,val.lastIndexOf(".")+1)
ckaryX3=ckaryX[q].substring(0,ckaryX[q].lastIndexOf(".")+1)
if(val3 == ckaryX3){ return false }
}
}
return true
}