<html>
   <head>
      <meta HTTP-EQUIV='Pragma' CONTENT='no-cache'>
      <link rel="stylesheet" href='stylemain.css' type='text/css'>
         <link rel="stylesheet" href='colors.css' type='text/css'>
            <script language="javascript" src="util.js"></script>
	     <script type="text/javascript" src="lang/b28n.js"></script>
	     <script language="javascript"><%ejGetOther(forbidHTMLCode)%></script>
            <script language="javascript">
<!-- hide
var interfaceInfo = '<%ejGetOther(wanInterfaceInfo, route)%>';
var interfaces = interfaceInfo.split('|');
var gtwyIfcs = '<%ejGetOther(sysInfo, gtwyIfcs)%>'; if (gtwyIfcs == '&nbsp') gtwyIfcs = '';

var enblIP6 = '<%ejGetOther(sysInfo, enblIPv6)%>';
var intfInfo6 = '<%ejGetOther(wanInterfaceInfo, route6)%>';
var intf6 = intfInfo6.split('|');
var gtwy6Ifc = '<%ejGetOther(sysInfo, dfltGw6Ifc)%>'; if (gtwy6Ifc == '&nbsp') gtwy6Ifc = '';

var obj1Items = '<%ejGetObject(MDMOID_DEV2_IP_INTERFACE)%>';
var obj1Rows = numOfRow(obj1Items);
var IPv6EnabledArray = getColFromList(obj1Items, 'IPv4Enable');
var IPv4EnabledArray = getColFromList(obj1Items, 'IPv6Enable');
var upstream = getColFromList(obj1Items, 'X_BROADCOM_COM_Upstream');


var enblIpVer4 = '0';

function initTranslation() {
	var idArray = new Array("rtDftGwTitle", "rtDftGwTips", "rtDftGwSelectIfc", "rtDftGwAvailableIfc", "buttonApplySave", "rtDftGwTODO", "rtDftGwSelected", "rtDftGwNOConfigInterface");
	setAllIdValue(idArray);
}

function disableRtdefalutInfo() {
   with ( document.forms[0] ) {
      for(i=0; i < obj1Rows; i++)
      {
           if(IPv4EnabledArray[i] == '1')
           enblIpVer4 = '1';
      }

      if(enblIpVer4 == '1')
      {
          selGtwyIfcs.disabled = 0;
          availIfcs.disabled = 0;
      }
     else
     {
          selGtwyIfcs.disabled = 1;
          availIfcs.disabled = 1;
     }
   }
}
function btnApply() {
   var loc = 'rtdefaultcfg.cgi?';
   var enblIpVer = '0';
   with (document.forms[0]) {
       var loc;
       var tempList = '';
	 if(enblIpVer4 == '1')
         {   
               for (i = 0; i < selGtwyIfcs.length; i++) {
	   	       if (i > 0)
		  	tempList += ',';
                     tempList += selGtwyIfcs.options[i].value;
               }

	       if (tempList == '') {
	   	    alert(_("rtDftGwAlert"));
		    return;
	        }

	   
	       loc += 'defaultGatewayList=' + tempList;
       } 
       if (enblIP6 == '1') {
           for(i=0; i < obj1Rows; i++)
           {
               if(IPv6EnabledArray[i] == '1')
                   enblIpVer = '1';
           }

           if(enblIpVer != '0')
           {
               var idx6 = wanIf6.selectedIndex;
               var ifc6 = wanIf6.options[idx6].value;
			   if(enblIpVer4 == '1')
                   loc += '&dfltGw6Ifc=' + ifc6;
			   else
                   loc += 'dfltGw6Ifc=' + ifc6;
           }

       }
   }
   
   loc += '&sessionKey=<%ejGetOther(sessionKey)%>';
   var code = 'location="' + loc + '"';
   eval(code);
}


function hideGw6Info(hide) {
   var status = '';

   if ( hide == 1 )
      status = 'none';
   if (document.getElementById)  // DOM3 = IE5, NS6
      document.getElementById('gw6Info').style.display = status;
   else {
      if (document.layers == false) // IE4
         document.all.gw6Info.style.display = status;
   }
}

function frmLoad() {
   var enblIpVer = '0';

	initTranslation();	
  with ( document.forms[0] ) {
    if (enblIP6 == '1')
    	{
    	  for(i=0; i < obj1Rows; i++)
    	  {
    	      if(IPv6EnabledArray[i] == '1')
    	          enblIpVer = '1';
    	  }

    	  if(enblIpVer == '0')
		  hideGw6Info(1);
    	  else
		  hideGw6Info(0);
    	}
    else
       hideGw6Info(1);
	disableRtdefalutInfo();
  }
}

function btnRemove() {
   with ( document.forms[0] ) {
      var arrSelected = new Array();
      var count = 0;
      for ( i = 0; i < selGtwyIfcs.options.length; i++ ) {
         if ( selGtwyIfcs.options[i].selected == true ) {
            arrSelected[count] = selGtwyIfcs.options[i].value;
         }
         count++;
      }
      var x = 0;
      for (i = 0; i < selGtwyIfcs.options.length; i++) {
         for (x = 0; x < arrSelected.length; x++) {
            if (selGtwyIfcs.options[i].value == arrSelected[x]) {
               varOpt = new Option(selGtwyIfcs.options[i].text, selGtwyIfcs.options[i].value);
               availIfcs.options[availIfcs.length] = varOpt;
               selGtwyIfcs.options[i] = null;
            }
         }
      }
   }
}

function btnAdd() {
   with ( document.forms[0] ) {
      var arrSelected = new Array();
      var count = 0;
      for ( i = 0; i < availIfcs.options.length; i++ ) {
         if ( availIfcs.options[i].selected == true ) {
            arrSelected[count] = availIfcs.options[i].value;
         }
         count++;
      }
      var x = 0;
      for (i = 0; i < availIfcs.options.length; i++) {
         for (x = 0; x < arrSelected.length; x++) {
            if (availIfcs.options[i].value == arrSelected[x]) {
               varOpt = new Option(availIfcs.options[i].text, availIfcs.options[i].value);
               selGtwyIfcs.options[selGtwyIfcs.length] = varOpt;
               availIfcs.options[i] = null;
            }
         }
      }
   }
}



// done hiding -->
</script>
   </head>
   <body onLoad='frmLoad()'>
      <blockquote>
         <form>
            <P>
           <b id='rtDftGwTitle'>Routing -- Default Gateway</b><br><br><br>
                          <span id='rtDftGwTips'>Default gateway interface list can have multiple WAN interfaces served as system default gateways but only one will be used according to
                          the priority with the first being the highest and the last one the lowest priority if the WAN interface is connected.  Priority order can be changed
                          by removing all and adding them back in again.</span>
	        </P>
			<br>
            <table border="0" cellpadding="0" cellspacing="0">
               <tr>
                  <td width="150" id='rtDftGwSelectIfc'><b>Selected Default Gateway Interfaces</b></td>
                  <td width="100"></td>
                  <td width="150"><b id='rtDftGwAvailableIfc'>Available Routed WAN Interfaces</b></td>
               </tr>
               <tr><td colspan="3">&nbsp;</td></tr>
               <tr>
                  <td>
                      <select multiple name="selGtwyIfcs" size="10" style="width: 100">
                      
<script language="javascript">
<!-- hide
{
   	var i = 0;
	var gtwyIfcsList;

	gtwyIfcsList = gtwyIfcs.split(',');

	for (i = 0; i < gtwyIfcsList.length; i++) 
 	   document.writeln("  <option value='" +gtwyIfcsList[i] + "'>"+ gtwyIfcsList[i]);
}
// done hiding -->
</script>

                      
                      </select>
                   </td>
                  <td>
                     <table border="0" cellpadding="0" cellspacing="5">
                        <tr><td>
                           <input type="button" value="->" onClick="btnRemove()" style="width: 30; height: 30">
                        </td></tr>
                        <tr><td>
                           <input type="button" value="<-" onClick="btnAdd()" style="width: 30; height: 30">
                        </td></tr>
                     </table>
                  </td>
                  <td>
                      <select multiple name="availIfcs" size="10" style="width: 100">

<script language="javascript">
<!-- hide
{
   var i;

   for (i = 0; i < interfaces.length; i++) {
      if (interfaces[i] != "") {
        var names = interfaces[i].split('/');
        if (gtwyIfcs.search(names[1]) == -1)
          document.writeln("  <option value='" + names[1] + "'>" + names[1]);
      }		
   }
}
// done hiding -->
</script>



                        </select></td>
                  </tr>
               </table>
               <br>
            <br>
            <div id='gw6Info'>
            <P id="rtDftGwTODO">Select a preferred wan interface as the system default IPv6 gateway.<br></P>
               <table>
                  <tr>
                     <td id="rtDftGwSelected">Selected WAN Interface</td>
                     <td><select name='wanIf6'>
                           <script language="javascript">
<!-- hide
{
   var i = 0;
   var names = intf6[i].split('/');
	
   if (names == '') {
      document.write("  <option value='&nbsp' selected id='rtDftGwNOConfigInterface'>NO CONFIGURED INTERFACE");
//TODO: IPV6     alert('No configured IPv6 WAN interface existed for system default IPv6 gateway.');
   }
   else {
      for ( i = 0; i < intf6.length; i++ ) {
         names = intf6[i].split('/');
         if ( names[1] == gtwy6Ifc )
            document.write("  <option value='" + names[1] + "' selected>");
         else
            document.write("  <option value='" + names[1] + "'>");
         document.writeln(intf6[i]);
      }
   }
}

// done hiding -->
</script>
                        </select></td>
                  </tr>
              </table><br><br>
            </div>
            <p align="center">
               <input type='button' onClick='btnApply()' value='Apply/Save' id='buttonApplySave'>
         </form>
      </blockquote>
   </body>
</html>

