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_W_sel(sel0 , sel1 , sel2){
/* (sel2 != null) == for edit page
sel0: Name ; sel1: id
*/
arrw=Interfc_info(1) //arrw[0] = Wan1 ; arrw[1] = Wan2 ;arrw[2] = Wan3
str0 ="<select name="+sel0+" id="+sel1+">"
for(o=0;o<arrw.length;o++){
if((sel2!= null)&&((o+1) == sel2)&&(arrw[o] != "0")) { str0+="<option value='' selected>WAN"+(o+1)+"</option>" }
else if((sel2!= null)&&((o+1) == sel2)) { str0+="<option value='"+(o+1)+"' selected>WAN"+(o+1)+"</option>" }
else if(arrw[o] == "0") { str0+="<option value='"+(o+1)+"'>WAN"+(o+1)+"</option>" }
}
str0+="</select>"
return str0
}
function chk_save()
{
var id_arr = new Array("t_l2tp_cli_tunlname_0","t_l2tp_cli_user_0","p_l2tp_cli_password_0","peerip");
var alert_message = new Array(GetElmCont("stavpn_0","Tunnel Name"),GetElmCont("wary_0","User Name"),GetElmCont("wary_0","Password"),GetElmCont("pptps_0","Remote LNS IP/FQDN"));
var gl2tp_cwan = document.getElementById("s_l2tp_cli_wan");
var peer_id = document.getElementById("peerip").value;
var str_message = "";
var tmp_str = "";
var obj_opmode = document.getElementById("opmode_failover")
for(var a=0;a<id_arr.length;a++)
{
tmp_str = document.getElementById(id_arr[a]).value;
if(tmp_str == "")
{
str_message += (str_message == "")?alert_message[a]:" , "+alert_message[a];
}
}
if(str_message != ""){
str_message += GetElmCont("vpn1_0"," can not be empty.");
alert(str_message);
return false;
}
else if(!Interfc_bfsmit(gl2tp_cwan)){ return false; }  // ck Interface
if(obj_opmode.value == 1){ // PPTP/L2TP client :tunnel�Q�אּfailover�A�hconnect type�ݳ]��manual
var cnecttp_obj =(document.getElementById('h_pptp_cli_connect_type_0') != null)?document.getElementById('h_pptp_cli_connect_type_0'):document.getElementById('h_l2tp_cli_connect_type_0') ;
cnecttp_obj.value = 2 ;
}
return chkIPsecX(); //set L2TP over IPsec
}
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 chg_LCP(value)
{
document.getElementById("t_l2tp_cli_lcp_interval_0").disabled = (value == 1)?false:true;
document.getElementById("t_l2tp_cli_lcp_failure_0").disabled = (value == 1)?false:true;
}
function swkey(s){
document.getElementById("ipsec_tun_ike_preshare_key_0").disabled = (s)?false:true;
document.getElementById("show_prekey").disabled = (s)?false:true;
document.getElementById("show_prekey").checked = false;
document.getElementById("ipsec_tun_ike_preshare_key_0").type = "password";
}
function swInterfc1(obj){
gswan = document.getElementById("s_l2tp_cli_wan");
gswan.disabled = ((typeof(obj) == 'object')&&(obj.value == 2))?true:false;
}
var ipseclist_inx_ov = new Array(
""
,"1"
,""
,""
,""
,""
,""
,""
,""
,""
,""
,""
,""
,""
,""
,""
,""
)
var ipseclist_csid_ov = new Array(
""
,"N00202001"
,"N00202002"
,"N00202003"
,"N00202004"
,"N00202005"
,"N00202006"
,"N00202007"
,"N00202008"
,"N00202009"
,"N0020200A"
,"N0020200B"
,"N0020200C"
,"N0020200D"
,"N0020200E"
,"N0020200F"
,"N00202010"
)
var ipsecN_csid_ov = new Array(
""
,"S00700101"
,"S00700102"
,"S00700103"
,"S00700104"
,"S00700105"
,"S00700106"
,"S00700107"
,"S00700108"
,"S00700109"
,"S0070010A"
,"S0070010B"
,"S0070010C"
,"S0070010D"
,"S0070010E"
,"S0070010F"
,"S00700110"
)
var ipsecfull_csid_ov = new Array(
""
,"N00709F01"
,"N00709F02"
,"N00709F03"
,"N00709F04"
,"N00709F05"
,"N00709F06"
,"N00709F07"
,"N00709F08"
,"N00709F09"
,"N00709F0A"
,"N00709F0B"
,"N00709F0C"
,"N00709F0D"
,"N00709F0E"
,"N00709F0F"
,"N00709F10"
)
var ipsecEN_csid_ov = new Array(
""
,"N00700201"
,"N00700202"
,"N00700203"
,"N00700204"
,"N00700205"
,"N00700206"
,"N00700207"
,"N00700208"
,"N00700209"
,"N0070020A"
,"N0070020B"
,"N0070020C"
,"N0070020D"
,"N0070020E"
,"N0070020F"
,"N00700210"
)
var l2tp_cli_ovipsec_csid = new Array(
"N00063B00",
"N00063B01",
"N00063B02",
"N00063B03",
"N00063B04",
"N00063B05",
"N00063B06",
"N00063B07",
"N00063B08",
""
)
var l2tp_cli_ovipsec_xxx = new Array(
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
""
)
var IPsec_info = new Array(
"N00700F00|0","N00706200|1","N00707500|1","N?|0"
,"N00705100|1","N00704A00|3","N00700010|1"
,"N00700070|1","N00700200|1"
,"S00700100|123","N00709E00|0","S00706000|14400","S00707300|14400"
,"N00701000|0"
,"S00700800|"
,"N00706400|7","N00706500|2","N00706600|2","N00706300|1"
,"N00706800|7","N00706900|1","N00706A00|2","N00706700|1"
,"N00706C00|1","N00706D00|2","N00706E00|2","N00706B00|1"
,"N00707000|2","N00707100|2","N00707200|2","N00706F00|1"
,"N00707700|7","N00707800|2","N00705400|0","N00707600|1"
,"N00707A00|7","N00707B00|1","N00707900|1"
,"N00707D00|1","N00707E00|2","N00707C00|1"
,"N00708000|2","N00708100|2","N00707F00|1"
,"S00705500|","S00705800|","N00705900|0"
,"N00705C00|0","N00705200|0","N0070AE00|0"
,"N00700300|0","N00709E00|0"
)
function chkIPsecX(){
/*
id="dynhide1" ; $C_IPSEC_TUN_IKE_ENCAP value=3    //type="hidden"
document.getElementById('enipsec')        //L2TP over IPsec's checkbox
(&C_L2TP_OVER_IPSEC_ENABLE)               //L2TP over IPsec's CSID
document.getElementById('c_l2tps_enable') //L2TP Server's checkbox
var o_ipsec_type = ($C_IPSEC_TYPE);       //type="hidden"
var o_ipsec_nat_traver = ($C_IPSEC_NAT_TRAVERSAL); //type="hidden"
id="dynhide" ; ($C_IPSEC_TUN_EN)          //type="hidden"
var o_ipsecindx = false;
for(s=0;s<ipseclist_inx_ov.length;s++){ //array=$C_WEBUI_VPNLIST_RECORD_RULE
if(ipseclist_inx_ov[s]=='0'){o_ipsecindx = true ;break}
(&C_IPSEC_TUN_IKE_CMD)	        //type="hidden"
(&C_IPSEC_TUN_IKE_PFS_GROUP)  	//type="hidden"
(&C_IPSEC_TUN_NAME[%Ntid])  	  //type="hidden"
(&C_IPSEC_TUN_IKE_P1_KEYLIFE_SEC[%Ntid]) //type="hidden" ;Phase1 Key Life Time
(&C_IPSEC_TUN_IKE_P2_KEYLIFE_SEC[%Ntid]) //type="hidden" ;Phase2 Key Life Time
if{
�쥻if + IPsec �n�P�B�]�w�� Info �����b array , IPsec_info.
}
else{
if(!o_ipsecindx){f.SC_IPSEC_TUN_NAME[%Ntid.value = "";}  //Tunnel Name
disabled "C_L2TP_CLI_OVER_IPSEC_ENABLE[%i]"
}
*/
f=document.forms[0]
gpeerip = document.getElementById("peerip")
gsl2tp_wan = document.getElementById("s_l2tp_cli_wan")
obj1 = document.getElementById('enipsec')
genipsec = obj1.checked
gh_enipsec = document.getElementById('h_enipsec')
tunnel_sw=document.getElementById('c_l2tp_cli_user_enable').checked
var o_ipsecindx = false;
var str0 ="";
/*
Ex : L2TP over IPsec enabled : Server -> IPSec0(DynamicVPN)
L2TP over IPsec enabled :  L2TP Client rule0 -> IPSec1
:                           :
L2TP over IPsec enabled :  L2TP Client rule5 -> IPSec6
*/
for(s=1;s<ipseclist_inx_ov.length;s++){
//    alert("del 0h?="+(ipseclist_inx_ov[s]==0'0')+" ,ipseclist_inx_ov[s]="+ipseclist_inx_ov[s] )
if(ipseclist_inx_ov[s]=='0'){ o_ipsecindx = true ;break }
else if(ipseclist_inx_ov[s]==''){ o_ipsecindx = s ;break }
}
if(genipsec && tunnel_sw){
for(a=0;a<IPsec_info.length;a++){
arry0 = IPsec_info[a].split("|")
if("S00700800" == arry0[0]){ arry0[1] = gpeerip.value }
if("N00701000" == arry0[0]){ arry0[1] = (parseInt(gsl2tp_wan.value) -1) }
str0 +="<input type='hidden' name='"+arry0[0]+"' value="+arry0[1]+">"
}
if(typeof(o_ipsecindx) == "number"){
str0 +="<input type='hidden' name='"+ipseclist_csid_ov[o_ipsecindx]+"' value=0>"
}
}
else{
obj1.disabled = true;
gh_enipsec.value = 0;
var oh_enipsec = ("0" != "0")
var del_str = '';
if((typeof(o_ipsecindx) != "number") && oh_enipsec){
str0 +="<input type='hidden' name='S00700100' value=''>"
str0 +="<input type='hidden' name='N00700200' value='0'>"
str0 +="<input type='hidden' name='N80700002' value='1'>"
for(q=1;q<ipseclist_inx_ov.length;q++){
if(ipseclist_inx_ov[q]=='0'){ ipseclist_inx_ov[q] = "" ;break }
}
for(q=1;q<ipseclist_inx_ov.length;q++){
if(ipseclist_inx_ov[q]!=''){ del_str += ipseclist_inx_ov[q]+"|"; }
}
arry1 = del_str.split("|")
for(q=1;q<ipseclist_inx_ov.length;q++){
_q = q-1;
if(q < arry1.length){
ipseclist_inx_ov[q] = arry1[_q];
}
else { ipseclist_inx_ov[q] = '' ;}
}
for(q=1;q<ipseclist_inx_ov.length;q++){
str0 +="<input type='hidden' name='"+ipseclist_csid_ov[q]+"' value='"+ipseclist_inx_ov[q]+"'>"
}
}
}
document.getElementById('l2tp_ov').innerHTML= str0 ;
var l2tp_preshare_key = document.getElementById("ipsec_tun_ike_preshare_key_0").value;
if((genipsec)&&(l2tp_preshare_key == "")){
alert(GetElmCont("valChk_0","Preshared Key is invalid."))
return false;
}
return true;
}
function L2TPovIPsec_info(retp,arr0){ //del L2TP over IPsec all item
/*
arry1 = darr0 = del_str -L2TP_ov_IPsec_en_rule_index_arry
arr0 = arrV = ipseclist_inx_ov
arr1 = arrcsid = ipseclist_csid_ov
ipsecN_csid_ov
*/
var str = str0 = str1 = str2 = str3 = str4 ="";
var del_str = '';
var darr0 = arr0;  //must be L2tp index arry
for(q=1;q<ipseclist_inx_ov.length;q++){
for(var n=0;n<darr0.length;n++){
if(ipseclist_inx_ov[q] == darr0[n]){ ipseclist_inx_ov[q] = "" ; }
}
}
for(q=1;q<ipseclist_inx_ov.length;q++){
if(ipseclist_inx_ov[q]!=''){ del_str += ipseclist_inx_ov[q]+"|"; }
}
arry1 = del_str.split("|") // �d�blist ,�w�Ƨ� ,�w�����ťդ���
for(q=1;q<ipseclist_inx_ov.length;q++){
_q = q-1;
if(q < arry1.length){
ipseclist_inx_ov[q] = arry1[_q];
}
else { ipseclist_inx_ov[q] = '' ;}
}
if(retp == 0){
for(var r=0;r<darr0.length;r++){
var cli_ovipsec_index = parseInt(darr0[r])-1;
str0 += "&"+l2tp_cli_ovipsec_csid[cli_ovipsec_index]+"=0";
}
}
else if(retp == 1){
for(var r=0;r<darr0.length;r++){
var cli_ovipsec_index = parseInt(darr0[r])-1;
str0 +="<input type='hidden' name='"+l2tp_cli_ovipsec_csid[cli_ovipsec_index]+"' value='0'>"
}
}
if(retp == 0){
for(q=1;q<ipseclist_inx_ov.length;q++){
str1 += "&"+ipseclist_csid_ov[q]+"="+ipseclist_inx_ov[q]
}
}
else if(retp == 1){
for(q=1;q<ipseclist_inx_ov.length;q++){
str1 +="<input type='hidden' name='"+ipseclist_csid_ov[q]+"' value='"+ipseclist_inx_ov[q]+"'>"
}
}
if(retp == 0){
for(q=0;q<darr0.length;q++){
vv = darr0[q]
str2 +="&"+ipsecN_csid_ov[vv]+"=";
}
}
else if(retp == 1){
for(q=0;q<darr0.length;q++){
vv = darr0[q]
str2 +="<input type='hidden' name='"+ipsecN_csid_ov[vv]+"' value=''>"
}
}
if(retp == 0){
for(q=0;q<darr0.length;q++){
vv = darr0[q]
str3 +="&"+ipsecEN_csid_ov[vv]+"=0";
}
}
else if(retp == 1){
for(q=0;q<darr0.length;q++){
vv = darr0[q]
str3 +="<input type='hidden' name='"+ipsecEN_csid_ov[vv]+"' value='0'>"
}
}
if(retp == 0){
str4 +="&N80700002=1";
}
else if(retp == 1){
str4 +="<input type='hidden' name='N80700002' value='1'>"
}
str = str0+str1+str2+str3+str4
return str
}