<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 maxEntry = '<%ejGetOther(sysInfo, maxVrtSrvEntry)%>';
//var wanIpIfNameArray = new Array(<%ejGetOther(AncestorList, scVrtSrvIpIf)%>);
//var wanPppIfNameArray = new Array(<%ejGetOther(AncestorList, scVrtSrvPppIf)%>);
var curObjRows = 0;

var obj1Items = '<%ejGetObject(MDMOID_DEV2_NAT_PORT_MAPPING)%>';

var obj1Rows = numOfRow(obj1Items);
/* NOTICE: MDMOID_WAN_IP_CONN_PORTMAPPING is Type1/Type2 object, follow variables are arrays */
var portMappingEnabledArray = getColFromList(obj1Items, "Enable");
var externalPortArray = getColFromList(obj1Items, "ExternalPort");
var ExternalPortEndArray = getColFromList(obj1Items, "ExternalPortEndRange");
var internalPortArray = getColFromList(obj1Items, "InternalPort");
var portMappingProtocolArray = getColFromList(obj1Items, "Protocol");
var internalClientArray = getColFromList(obj1Items, "InternalClient");
var portMappingDescriptionArray = getColFromList(obj1Items, "Description");
var portMappingInterface = getColFromList(obj1Items, "Interface");
/*var loopbackEnabledArray = getColFromList(obj1Items, 'X_BROADCOM_COM_LanLoopbackEnabled');*/

var locationQuery='sessionKey=<%ejGetOther(sessionKey)%>';
var tmpinternalportend =0;


function initTranslation() {	
	var idArray = new Array("sevrtview_title","sevrtview_tips","sevrtview_tips1","sevrtview_serName","sevrtview_exterPortSt","sevrtview_exterPortEnd","sevrtview_proto","sevrtview_portStart",
		"sevrtview_portEnd","sevrtview_serIpAdd","sevrtview_wanInter","sevrtview_add","sevrtview_add1","sevrtview_remove","sevrtview_remove1","sevrtview_apply","sevrtview_apply1","sevrtview_loopback");
	setAllIdValue(idArray);
}

function frmLoad() {
	initTranslation();

}
function displayProtocol(protocol){
	if(protocol == 'TCP or UDP')
		document.writeln("<td class='tablesize'>&nbsp;TCP/UDP</td>");
	else
		document.writeln("<td class='tablesize'>&nbsp;"+ protocol +"</td>");	
}

function fillObj1Items(){
	var i;
	var porttmp=0;
	for(i=0; i < obj1Rows; i++){
		tmpinternalportend = parseInt(internalPortArray[i]) + parseInt(ExternalPortEndArray[i]) - parseInt(externalPortArray[i]);
		document.writeln("<tr>");
		document.writeln("<td class='tablesize'>&nbsp;"+ portMappingDescriptionArray[i] +"</td>");
		document.writeln("<td class='tablesize'>&nbsp;"+ externalPortArray[i] +"</td>");
		document.writeln("<td class='tablesize'>&nbsp;"+ ExternalPortEndArray[i] +"</td>");
		displayProtocol(portMappingProtocolArray[i]);
		document.writeln("<td class='tablesize'>&nbsp;"+ internalPortArray[i] +"</td>");
		document.writeln("<td class='tablesize'>&nbsp;"+ tmpinternalportend +"</td>");
		document.writeln("<td class='tablesize'>&nbsp;"+ internalClientArray[i] +"</td>");
		document.writeln("<td class='tablesize'>&nbsp;"+ portMappingInterface[i] +"</td>");
		///*if (loopbackEnabledArray[i] == 1)
		//{
		//	document.writeln("<td class='tablesize'>Enabled</td>");
		//}
		//else	*/
		{
			document.writeln("<td class='tablesize'>Disabled</td>");
		}		
		           document.writeln("<td align='center'><input type='checkbox' name='vsenbl' value='" 	
                           + internalClientArray[i] +"|"
                           + externalPortArray[i] +"|"
                           + ExternalPortEndArray[i] +"|"
                           + portMappingProtocolArray[i] +"|"
                           + internalPortArray[i] + "' ");
                   if(portMappingEnabledArray[i] == 1){
                           document.writeln(" checked></td>");
                   }
                   else{
                           document.writeln(" ></td>");
                   }
		document.writeln("<td align='center'><input type='checkbox' name='rml' value='"
			+ internalClientArray[i] +"|"
			+ externalPortArray[i] +"|"
			+ ExternalPortEndArray[i] +"|"
			+ portMappingProtocolArray[i] +"|"
			+ internalPortArray[i] + "|"
			+ tmpinternalportend + "' ></td>");
		document.writeln("</tr>");
		curObjRows++;
	}
}

function addClick() {
   var loc = 'scvrtsrv.html';
   var code = 'location="' + loc + '"';
   eval(code);
}

function saveapplyClick(ebl) {                                                                                
   var eblLst = '';

   if (ebl.length > 0)
      for (i = 0; i < ebl.length; i++) {
         if ( ebl[i].checked == true )
            eblLst += ebl[i].value + '|1,';
         else 
            eblLst += ebl[i].value + '|0,';
      }
   else if ( ebl.checked == true )
      eblLst += ebl.value + '|1';
   else
      eblLst += ebl.value + '|0';
                                                                                
   var loc = 'scvrtsrv.cmd?action=apply&eblLst=' + eblLst + '&' + locationQuery;
   var code = 'location="' + loc + '"';
   eval(code);
}

function removeClick(rml) {
   var lst = '';
   var rmlnum = 0;
   
   if (rml.length > 0){
      for (i = 0; i < rml.length; i++) {
         if ( rml[i].checked == true){
            lst += rml[i].value + ',';
            rmlnum++;
         }
      }
      if(rmlnum > 10){
         alert("Sorry. You could not remove more than 10 entries one time.");
         return;
      }
   }

   else if ( rml.checked == true )
      lst = rml.value;
   var loc = 'scvrtsrv.cmd?action=remove&rmLst=' + lst + '&' + locationQuery;
   var code = 'location="' + loc + '"';
   eval(code);
}


// done hiding -->
</script></head>
<body onLoad='frmLoad()'>
<blockquote> 
  <form>
    <b><span id='sevrtview_title'>NAT -- Virtual Servers Setup</span></b><br>
    <br><span id='sevrtview_tips'>Virtual Server allows you to direct incoming traffic from WAN side (identified by Protocol and External port) to the Internal server
    with private IP address on the LAN side. The Internal port is required only if the external port needs to be converted to a different 
    port number used by the server on the LAN side. A maximum</span> 
    <script language="javascript"> 
	<!-- hide 
		document.writeln("<b>" + maxEntry + "</b>");
	// done hiding -->
    </script>
      <span id='sevrtview_tips1'>entries can be configured.</span><br>
    <br>
    <center>
      <table border='1' cellpadding='2' cellspacing='0'>
        <tr> 
          <td class='hd' id='sevrtview_serName'>Server Name</td>
          <td class='hd' id='sevrtview_exterPortSt'>External Port Start</td>
          <td class='hd' id='sevrtview_exterPortEnd'>External Port End</td>
          <td class='hd' id='sevrtview_proto'>Protocol</td>
          <td class='hd' id='sevrtview_portStart'>Internal Port Start</td>
          <td class='hd' id='sevrtview_portEnd'>Internal Port End</td>
          <td class='hd' id='sevrtview_serIpAdd'>Server IP Address</td>
          <td class='hd' id='sevrtview_wanInter'>WAN Interface</td>
          <td class='hd' id='sevrtview_loopback'>LAN Loopback</td>
          <td class='hd'>Enable/Disable</td>          
          <td class='hd' id='sevrtview_remove'>Remove</td>
        </tr>
        <script language='javascript'>
        <!--hide
		fillObj1Items();
        //-->
        </script>
      </table>
      <br>
      <br>
        <script language="javascript"> 
        <!-- hide 
            if(curObjRows < parseInt(maxEntry)){
                document.writeln("<input type='button' onClick='addClick()' value='Add' id='sevrtview_add'>");
	     }else{
                document.writeln("<input type='button' onClick='addClick()' value='Add' disabled id='sevrtview_add1'>");
	     }
            if(curObjRows > 0){
                document.writeln("<input type='button' onClick='saveapplyClick(this.form.vsenbl)' value='Save/Apply' id='sevrtview_apply'>");
                document.writeln("<input type='button' onClick='removeClick(this.form.rml)' value='Remove' id='sevrtview_remove'>");
	     }else{
                document.writeln("<input type='button' onClick='saveapplyClick(this.form.vsenbl)' value='Save/Apply' disabled id='sevrtview_apply1'>");
                document.writeln("<input type='button' onClick='removeClick(this.form.rml)' value='Remove' disabled id='sevrtview_remove1'>");
	     }
        // done hiding -->
        </script>
    </center>
  </form>
</blockquote>
</body>
</html>
