function CheckIPDomain(passForm)
{
	if(passForm.static_route_ipaddr_4.value != '0')
	{
		if(passForm.static_route_netmask_1.value != '255' || passForm.static_route_netmask_2.value != '255' || passForm.static_route_netmask_3.value != '255' || passForm.static_route_netmask_4.value != '255')
		{
			alert(mavis_str(Alert_Msg_66));
			//alert('Netmask must be 255.255.255.255!');
			passForm.static_route_netmask_1.focus();
			return false;			
		}
	}
	else
	{
	  if(passForm.static_route_ipaddr_4.value != '0' && passForm.static_route_netmask_4.value == '0') 
		{
			alert(mavis_str(Alert_Msg_67)); 
			//alert('Fourth IP address must be 0');
			passForm.static_route_ipaddr_4.focus();
			return false;
		}
	  if(passForm.static_route_ipaddr_3.value != '0' && passForm.static_route_netmask_3.value == '0') 
		{
			alert(mavis_str(Alert_Msg_68)); 
			//alert('Third IP address be 0');
			passForm.static_route_ipaddr_3.focus();			
			return false;			
		}		
	  if(passForm.static_route_ipaddr_2.value != '0' && passForm.static_route_netmask_2.value == '0') 
		{
			alert(mavis_str(Alert_Msg_69)); 
			//alert('Second IP address be 0');
			passForm.static_route_ipaddr_2.focus();	
			return false;					
		}		
		
		if(passForm.static_route_ipaddr_4.value == '0' && passForm.static_route_netmask_4.value != '0') 
		{
			 alert(mavis_str(Alert_Msg_70));  
			//alert('Fourth netmask must be 0');
			passForm.static_route_netmask_4.focus();
			return false;
		}
	  if(passForm.static_route_ipaddr_3.value == '0' && passForm.static_route_netmask_3.value != '0') 
		{
			  alert(mavis_str(Alert_Msg_71));  
			//alert('Third netmask must be 0');
			passForm.static_route_netmask_3.focus();			
			return false;			
		}		
	  if(passForm.static_route_ipaddr_2.value == '0' && passForm.static_route_netmask_2.value != '0') 
		{
			alert(mavis_str(Alert_Msg_72));
			//alert('Second netmask must be 0');
			passForm.static_route_netmask_2.focus();	
			return false;					
		}		

		if(passForm.static_route_ipaddr_2.value == '0' && passForm.static_route_ipaddr_3.value != '0' && passForm.static_route_ipaddr_4.value == '0')
		{
			alert(mavis_str(Alert_Msg_73));
			//alert('Please check your data!');
			passForm.static_route_ipaddr_3.focus();	
			return false;			
		}
		
	}
	return true;
}

function SpiltIP(IPAddress,SegmentSeq)
{
	var	DotPos_1 = 0;
	var	DotPos_2 = 0;
	var	DotPos_3 = 0;
	var	StartPos = 0;
	var	EndPos = 0;
	var	SegmentIP = '';

	for ( iln = 0 ; iln < IPAddress.length ; iln++ ) {
      		ch = IPAddress.charAt(iln).toLowerCase();

      		if (( ch == '.' ) && ( DotPos_1 == 0 ) && ( DotPos_2 == 0 ) && ( DotPos_3 == 0 )) {
      			DotPos_1 = iln;
      		} else if (( ch == '.' ) && ( DotPos_1 != 0 ) && ( DotPos_2 == 0 ) && ( DotPos_3 == 0 )) {
      			DotPos_2 = iln;
      		} else if (( ch == '.' ) && ( DotPos_1 != 0 ) && ( DotPos_2 != 0 ) && ( DotPos_3 == 0 )) {
      			DotPos_3 = iln;
      			break;
      		}
	}

	if ( SegmentSeq == 1 ) {
		StartPos = 0;
		EndPos = DotPos_1;
	} else if ( SegmentSeq == 2 ) {
		StartPos = DotPos_1 + 1;
		EndPos = DotPos_2;
	} else if ( SegmentSeq == 3 ) {
		StartPos = DotPos_2 + 1;
		EndPos = DotPos_3;
	} else if ( SegmentSeq == 4 ) {
		StartPos = DotPos_3 + 1;
		EndPos = IPAddress.length;
	}

	for ( iln = StartPos ; iln < EndPos ; iln++ ) {
      		ch = IPAddress.charAt(iln).toLowerCase();
		SegmentIP = SegmentIP + ch;
	}

	return SegmentIP;
}

function ChangeInterface(Interface)
{
	if ( Interface == 0 ) {
		document.forms[0].route_ifname.selectedIndex = 0;
	} else if ( Interface == 1 ) {
		document.forms[0].route_ifname.selectedIndex = 1;
	}
}

function AddName(passForm)
{
	var index = passForm.TableSequ.value;
	if(passForm.route_name.value=="") {
		alert("Please enter the route name!");
		return 0;
	}
	eval("passForm.static_route_name"+index).value=passForm.route_name.value;
	return 1;
}
//Add the entry in the routing table
function AddEntry(passForm)
{
		var index = passForm.TableSequ.value;
  	d = document.forms[0].static_route_ipaddr_1.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_ipaddr_1.value == "" ) || !(IPCheck(document.forms[0].static_route_ipaddr_1)) ) {
    	document.forms[0].static_route_ipaddr_1.value = 0;
		alert(mavis_str(Alert_Msg_75));
		//alert('First Destination LAN IP address value is out of range [0 - 255]');
		document.forms[0].static_route_ipaddr_1.focus();
    		return false;
  	}
  	
	d = document.forms[0].static_route_ipaddr_2.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_ipaddr_2.value == "" ) || !(IPCheck(document.forms[0].static_route_ipaddr_2)) ) {
    		document.forms[0].static_route_ipaddr_2.value = 0;
			alert(mavis_str(Alert_Msg_76));
		//alert('Second Destination LAN IP address value is out of range [0 - 255]');
		document.forms[0].static_route_ipaddr_2.focus();
    		return false;
  	}

	d = document.forms[0].static_route_ipaddr_3.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_ipaddr_3.value == "" ) || !(IPCheck(document.forms[0].static_route_ipaddr_3)) ) {
    		document.forms[0].static_route_ipaddr_3.value = 0;
		alert(mavis_str(Alert_Msg_77));
		//alert('Third Destination LAN IP address value is out of range [0 - 255]');
		document.forms[0].static_route_ipaddr_3.focus();
    		return false;
  	}

	d = document.forms[0].static_route_ipaddr_4.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_ipaddr_4.value == "" ) || !(IPCheck(document.forms[0].static_route_ipaddr_4)) ) {
    		document.forms[0].static_route_ipaddr_4.value = 0;
			alert(mavis_str(Alert_Msg_78));
		//alert('Fourth Destination LAN IP address value is out of range [0 - 255]');
		document.forms[0].static_route_ipaddr_4.focus();
    		return false;
  	}

  	d = document.forms[0].static_route_ipaddr_1.value + '.';
  	d = d + document.forms[0].static_route_ipaddr_2.value + '.';
  	d = d + document.forms[0].static_route_ipaddr_3.value + '.';
  	d = d + document.forms[0].static_route_ipaddr_4.value;
	eval("passForm.static_route_ipaddr"+index).value = d;


  	d = document.forms[0].static_route_netmask_1.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_netmask_1.value == "" ) || !(IPCheck(document.forms[0].static_route_netmask_1)) ) {
    		document.forms[0].static_route_netmask_1.value = 0;
			alert(mavis_str(Alert_Msg_79));
		//alert('First Subnet Mask value is out of range [0 - 255]');
		document.forms[0].static_route_netmask_1.focus();
    		return false;
  	}
  	
	d = document.forms[0].static_route_netmask_2.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_netmask_2.value == "" ) || !(IPCheck(document.forms[0].static_route_netmask_2)) ) {
    		document.forms[0].static_route_netmask_2.value = 0;
			alert(mavis_str(Alert_Msg_80));
		//alert('Second Subnet Mask value is out of range [0 - 255]');
		document.forms[0].static_route_netmask_2.focus();
    		return false;
  	}

	d = document.forms[0].static_route_netmask_3.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_netmask_3.value == "" ) || !(IPCheck(document.forms[0].static_route_netmask_3)) ) {
    		document.forms[0].static_route_netmask_3.value = 0;
			alert(mavis_str(Alert_Msg_81));
		//alert('Third Subnet Mask value is out of range [0 - 255]');
		document.forms[0].static_route_netmask_3.focus();
    		return false;
  	}

	d = document.forms[0].static_route_netmask_4.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_netmask_4.value == "" ) || !(IPCheck(document.forms[0].static_route_netmask_4)) ) {
    		document.forms[0].static_route_netmask_4.value = 0;
			alert(mavis_str(Alert_Msg_82));
		//alert('Fourth Subnet Mask value is out of range [0 - 255]');
		document.forms[0].static_route_netmask_4.focus();
    		return false;
  	}

  	d = document.forms[0].static_route_netmask_1.value + '.';
  	d = d + document.forms[0].static_route_netmask_2.value + '.';
  	d = d + document.forms[0].static_route_netmask_3.value + '.';
  	d = d + document.forms[0].static_route_netmask_4.value;
	eval("passForm.static_route_netmask"+index).value = d;

  	d = document.forms[0].static_route_gateway_1.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_gateway_1.value == "" ) || !(IPCheck(document.forms[0].static_route_gateway_1)) ) {
    		document.forms[0].static_route_gateway_1.value = 0;
		alert(mavis_str(Alert_Msg_83));
		//alert('First Default Gateway is out of range [0 - 255]');
		document.forms[0].static_route_gateway_1.focus();
    		return false;
  	}
  	
	d = document.forms[0].static_route_gateway_2.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_gateway_2.value == "" ) || !(IPCheck(document.forms[0].static_route_gateway_2)) ) {
    		document.forms[0].static_route_gateway_2.value = 0;
		alert(mavis_str(Alert_Msg_84));
		//alert('Second Default Gateway is out of range [0 - 255]');
		document.forms[0].static_route_gateway_2.focus();
    		return false;
  	}

	d = document.forms[0].static_route_gateway_3.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_gateway_3.value == "" ) || !(IPCheck(document.forms[0].static_route_gateway_3)) ) {
    		document.forms[0].static_route_gateway_3.value = 0;
			alert(mavis_str(Alert_Msg_85));
		//alert('Third Default Gateway is out of range [0 - 255]');
		document.forms[0].static_route_gateway_3.focus();
    		return false;
  	}

	d = document.forms[0].static_route_gateway_4.value;
  	if ( d>255 || d<0 || ( document.forms[0].static_route_gateway_4.value == "" ) || !(IPCheck(document.forms[0].static_route_gateway_4)) ) {
    		document.forms[0].static_route_gateway_4.value = 0;
			alert(mavis_str(Alert_Msg_86));
		//alert('Fourth Default Gateway is out of range [0 - 255]');
		document.forms[0].static_route_gateway_4.focus();
    		return false;
  	}
  	d = document.forms[0].static_route_gateway_1.value + '.';
  	d = d + document.forms[0].static_route_gateway_2.value + '.';
  	d = d + document.forms[0].static_route_gateway_3.value + '.';
  	d = d + document.forms[0].static_route_gateway_4.value;
	eval("passForm.static_route_gateway"+index).value = d;
	eval("passForm.static_route_ifname"+index).value = passForm.route_ifname.value;
	if (parseInt(document.forms[0].static_route_ipaddr_4.value,10)==0)
		eval("passForm.static_route_type"+index).value = "0";
	else
		eval("passForm.static_route_type"+index).value = "1";
		
	return 1;
}

function RestoringEntry(passForm)
{
	var index = passForm.TableSequ.value;
	if (eval("passForm.static_route_name"+index).value == "")
		passForm.route_name.value = "";	
	else
		passForm.route_name.value = eval("passForm.static_route_name"+index).value;
	if (eval("passForm.static_route_ipaddr"+index).value=="")
	{
		passForm.static_route_ipaddr_1.value = 0;
		passForm.static_route_ipaddr_2.value = 0;
		passForm.static_route_ipaddr_3.value = 0;
		passForm.static_route_ipaddr_4.value = 0;
	}
	else
	{
		passForm.static_route_ipaddr_1.value = SpiltIP(eval("passForm.static_route_ipaddr"+index).value,1);
		passForm.static_route_ipaddr_2.value = SpiltIP(eval("passForm.static_route_ipaddr"+index).value,2);
		passForm.static_route_ipaddr_3.value = SpiltIP(eval("passForm.static_route_ipaddr"+index).value,3);
		passForm.static_route_ipaddr_4.value = SpiltIP(eval("passForm.static_route_ipaddr"+index).value,4);
	}
	if (eval("passForm.static_route_netmask"+index).value == "")
	{
		passForm.static_route_netmask_1.value = 0;
		passForm.static_route_netmask_2.value = 0;
		passForm.static_route_netmask_3.value = 0;
		passForm.static_route_netmask_4.value = 0;	
	}
	else
	{
		passForm.static_route_netmask_1.value = SpiltIP(eval("passForm.static_route_netmask"+index).value,1);
		passForm.static_route_netmask_2.value = SpiltIP(eval("passForm.static_route_netmask"+index).value,2);
		passForm.static_route_netmask_3.value = SpiltIP(eval("passForm.static_route_netmask"+index).value,3);
		passForm.static_route_netmask_4.value = SpiltIP(eval("passForm.static_route_netmask"+index).value,4);
	}
	if (eval("passForm.static_route_gateway"+index).value == "")    
	{
		passForm.static_route_gateway_1.value = 0;
		passForm.static_route_gateway_2.value = 0;
		passForm.static_route_gateway_3.value = 0;
		passForm.static_route_gateway_4.value = 0;
	
	}
	else
	{
		passForm.static_route_gateway_1.value = SpiltIP(eval("passForm.static_route_gateway"+index).value,1);
		passForm.static_route_gateway_2.value = SpiltIP(eval("passForm.static_route_gateway"+index).value,2);
		passForm.static_route_gateway_3.value = SpiltIP(eval("passForm.static_route_gateway"+index).value,3);
		passForm.static_route_gateway_4.value = SpiltIP(eval("passForm.static_route_gateway"+index).value,4);
	}
	ChangeInterface(eval("passForm.static_route_ifname"+index).value);
}

function DeleteEntry(passForm)
{
	var index = passForm.TableSequ.value;
	if ( window.confirm("Do you make sure to delete this entry ?") ) 
	{
		passForm.route_name.value="";
		passForm.static_route_ipaddr_1.value = '0';
		passForm.static_route_ipaddr_2.value = '0';
		passForm.static_route_ipaddr_3.value = '0';
		passForm.static_route_ipaddr_4.value = '0';
		passForm.static_route_netmask_1.value = '0';
		passForm.static_route_netmask_2.value = '0';
		passForm.static_route_netmask_3.value = '0';
		passForm.static_route_netmask_4.value = '0';
		passForm.static_route_gateway_1.value = '0';
		passForm.static_route_gateway_2.value = '0';
		passForm.static_route_gateway_3.value = '0';
		passForm.static_route_gateway_4.value = '0';		
		ChangeInterface("br0");
		eval("passForm.static_route_name"+index).value = "";
		eval("passForm.static_route_ipaddr"+index).value = "";
		eval("passForm.static_route_netmask"+index).value = "";
		eval("passForm.static_route_gateway"+index).value = "";
		eval("passForm.static_route_ifname"+index).value = "";
		eval("passForm.static_route_type"+index).value = "";
	}	
}