var subnet_mask = new Array(0, 128, 192, 224, 240, 248, 252, 254, 255);
var name_word = new Array('#', '*', '/', ',', ';', '"', "'");

var msg = new Array("The IP Address entered is invalid",	//INVALID_IP_ADDRESS
					"The IP Address cannot be zero.",	//ZERO_IP_ADDRESS
					"IP Address",	//IP_ADDRESS_DESC
					"The Subnet Mask entered is invalid",	//INVALID_MASK_ADDRESS
					"The Subnet Mask cannot be zero",	//ZERO_MASK_ADDRESS
					"Subnet Mask",	//MASK_ADDRESS_DESC
					"The Gateway IP Address entered is invalid",	//INVALID_GATEWAY_ADDRESS
					"The Gateway IP Address cannot be zero",	//ZERO_GATEWAY_ADDRESS
					"Gateway IP Address",	//GATEWAY_ADDRESS_DESC
					"The IP Address and the Gateway IP Address are not in the same subnet",	//NOT_SAME_DOMAIN
					"The Starting IP Address entered is invalid.",	//INVALID_START_IP
					"Please enter another Starting IP Address",	//ZERO_START_IP
					"Starting IP Address",	//START_IP_DESC
					"The LAN IP Address and the Start IP Address are not in the same subnet",	//START_INVALID_DOMAIN
					"The Ending IP Address entered is invalid.",	//INVALID_END_IP
					"Please enter another Ending IP Address",	//ZERO_END_IP
					"Ending IP Address",	//END_IP_DESC
					"The LAN IP Address and the End IP Address are not in the same subnet",	//END_INVALID_DOMAIN
					"The Primary DNS Address entered is invalid",	//INVALID_DNS_ADDRESS
					"The Primary DNS Address cannot be zero",	//ZERO_DNS_ADDRESS
					"Primary DNS Address",	//DNS_ADDRESS_DESC
					"The SSID field cannot be blank",	//SSID_EMPTY_ERROR					
					"WEP cannot be disabled when the Authentication type is set to Shared Key",	//AUTH_TYPE_ERROR
					"The length of the Passphrase must be at least 8 characters",	//PSK_LENGTH_ERROR
					"The Confirmed Passphrase does not match the Passphrase",	//PSK_MATCH_ERROR
					"The Confirmed Password does not match the New Password",	//MATCH_PWD_ERROR
					"The selected WEP key field cannot be blank",	//WEP_KEY_EMPTY
					"Please enter another Key",	//WIZARD_KEY_EMPTY
					"Quit setup wizard and discard settings?",	//QUIT_WIZARD
					"The legal characters for a MAC Address are 0~9, A~F, or a~f",	//MAC_ADDRESS_ERROR	 																	
					"The Ending IP Address must be greater than the Starting IP Address",	//IP_RANGE_ERROR
					"The Secondary DNS Address entered is invalid",	//INVALID_SEC_DNS_ADDRESS
					"The Secondary DNS Address cannot be zero",	//ZERO_SEC_DNS_ADDRESS
					"Secondary DNS Address",	//SEC_DNS_ADDRESS_DESC
					"The confirmed password does not match the new Admin password",	//ADMIN_PASS_ERROR
					"The confirmed password does not match the new User password",	//USER_PASS_ERROR
					"Please enter another Server Name",	//DDNS_SERVER_ERROR
					"Please enter another Host Name",	//DDNS_HOST_ERROR
					"Please enter another User Name",	//DDNS_USER_ERROR
					"Please enter another Password",	//DDNS_PASS_ERROR
					"Restore to Factory Default Settings?",	//RESTORE_DEFAULT
					"Are you sure you want to reboot the router?",	//REBOOT_ROUTER
					"Load settings from a saved configuration file?",	//LOAD_SETTING
					"Please select a saved configuration file to upload",	//LOAD_FILE_ERROR
					"Only the Admin account can download the settings",	//DOWNLOAD_SETTING_ERROR
					"Please enter either a Host Name or an IP Address",	//PING_IP_ERROR
					"Please enter another SMTP Server or IP Address",	//SMTP_SERVER_ERROR
					"Please enter a valid email Address",	//EMAIL_ADDRESS_ERROR
					"Are you sure that you want to delete this Virtual Server Rule?",	//DEL_SERVER_MSG
					"Are you sure that you want to delete this Application Rule",	//DEL_APPLICATION_MSG
					"Are you sure that you want to delete this Filter?",	//DEL_FILTER_MSG
					"Are you sure that you want to delete this Route?",	//DEL_ROUTE_MSG
					"Are you sure that you want to delete this MAC Address?",	//DEL_MAC_MSG
					"Are you sure that you want to delete this Keyword?",	//DEL_KEYWORD_MSG
					"Are you sure that you want to delete this Domain?",	//DEL_DOMAIN_MSG
					"Are you sure that you want to delete this Entry?",	//DEL_ENTRY_MSG
					"Are you sure that you want to delete this DHCP Reservation?",	//DEL_STATIC_DHCP_MSG
					"Please enter another name",	//NAME_ERROR
					"Please enter a Trigger Port number",	//TRIGGER_PORT_ERROR
					"Please enter a Firewall Port number",	//PUBLIC_PORT_ERROR
					"Please enter another Private Port number",	//PRIVATE_PORT_ERROR
					"Please enter a Private IP Address.",	//PRIVATE_IP_ERROR
					"Please enter another port number",	//PORT_ERROR
					"Please select a Keyword to delete",	//DEL_KEYWORD_ERROR
					"The Keyword entered already exists in the list",	//SAME_KEYWORD_ERROR
					"Please enter another Keyword",	//KEYWORD_ERROR
					"Unable to add another Keyword",	//ADD_KEYWORD_ERROR
					"Please select a Blocked Domain to delete",	//DEL_BLOCK_DOMAIN_ERROR
					"Please select a Permitted Domain to delete",	//DEL_PERMIT_DOMAIN_ERROR
					"The Domain entered already exists in the list of Blocked Domains",	//SAME_BLOCK_DOMAIN
					"Please enter another Blocked Domain",	//BLOCK_DOMAIN_ERROR
					"Unable to add another Blocked Domain",	//ADD_BLOCK_DOMAIN_ERROR
					"The Domain entered already exists in the list of Permitted Domains",	//SAME_PERMIT_DOMAIN
					"Please enter another Permitted Domain",	//PERMIT_DOMAIN_ERROR
					"Unable to add another Permitted Domain",	//ADD_PERMIT_DOMAIN_ERROR
					"Please select a Firmware file to upgrade the router.",	//FIRMWARE_UPGRADE_ERROR
					"Please enter another Domain",	//DOMAIN_ERROR
					"Unable to add another Control Domains",	//ADD_CONTROL_DOMAIN_ERROR
					"Please select a Control Domain to delete",	//DEL_CONTROL_DOMAIN_ERROR
					"Please enter at least one Control Domain",	//CONTROL_DOMAIN_ERROR
					"The RADIUS Server 1 IP Address entered is invalid",	//INVALID_RADIUS_SERVER1_IP
					"The RADIUS Server 1 IP Address cannot be zero",	//ZERO_RADIUS_SERVER1_IP
					"RADIUS Server 1 IP Address",	//RADIUS_SERVER1_IP_DESC
					"The RADIUS Server 2 IP Address entered is invalid",	//INVALID_RADIUS_SERVER2_IP
					"The RADIUS Server 2 IP Address cannot be zero",	//ZERO_RADIUS_SERVER2_IP
					"RADIUS Server 2 IP Address",	//RADIUS_SERVER2_IP_DESC
					"The IP Address entered is invalid (IP Range: 1~254)",	//INVALID_STATIC_DHCP_IP
					"Please enter another IP Address",	//ZERO_STATIC_DHCP_IP
					"Please enter another Name",	//STATIC_DHCP_NAME
					"The Server IP Address entered is invalid",	//INVALID_SERVER_IP
					"The Server IP Address cannot be zero",	//ZERO_SERVER_IP
					"Server IP Address",	//SERVER_IP_DESC
					"The Passwords entered do not match",	//MATCH_WIZARD_PWD_ERROR
					"The Source Start IP Address entered is invalid",	//INVALID_SOURCE_START_IP
					"The Source Start IP Address cannot be zero",	//ZERO_SOURCE_START_IP
					"Source Start IP Address",	//SOURCE_START_IP_DESC
					"The Source End IP Address entered is invalid",	//INVALID_SOURCE_END_IP
					"The Source End IP Address cannot be zero",	//ZERO_SOURCE_END_IP
					"Source End IP Address",	//SOURCE_END_IP_DESC
					"The Destination Start IP Address entered is invalid",	//INVALID_DEST_START_IP
					"The Destination Start IP Address cannot be zero",	//ZERO_DEST_START_IP
					"Destination Start IP Address",	//DEST_START_IP_DESC
					"The Destination End IP Address entered is invalid",	//INVALID_DEST_END_IP
					"The Destination End IP Address cannot be zero",	//ZERO_DEST_END_IP
					"Destination End IP Address",	//DEST_END_IP_DESC
					"The length of the Passphrase must be between 8 and 63 characters",	//PSK_OVER_LEN
					"Reset JumpStart?",	//RESET_JUMPSTAR
					"Are you sure that you want to delete this rule?",	//DEL_RULE_MSG
					"Are you sure that you want to delete this schedule?",	// DEL_SCHEDULE_MSG
					"Unable to add another schedule",			// ADD_SCHEDULE_ERROR
					"Schedule Name can not empty",	//SCHEDULE_NAME_ERROR
					"Schedule Name can not enter all space",	//SCHEDULE_NAME_SPACE_ERROR
					"The Start Time cannot be greater than the End Time",	//	TIME_RANGE_ERROR
					"Please select a machine first",		// SELECT_MACHINE_ERROR
					"Please select an Application Name first",	// SELECT_APPLICATION_ERROR
					"Please select a Computer Name first",		// SELECT_COMPUTER_ERROR
					"Please enter another Wireless Security Password",	// SECURITY_PWD_ERROR
					"The URL/Domain entered is already in the list",		//	DUPLICATE_URL_ERROR
					"Login Name error",  //LOGIN_NAME_ERROR
					"Login Password error", //LOGIN_PASS_ERROR
					"The Ending IP address must be greater than the Starting IP address.", //IP_ORDER_ERROR
					"The Ending Port must be greater than the Starting Port.", //PORT_RANGE_ERROR
					"Are you sure you want to upgrade the firmware?",	//UPGRADE_FIRMWARE
					"To configure X.509, please go to \"Certificates\" under \"ADVANCED\"",	//X509_CONFIGURE
					"To configure XAuth, please go to \"User Group\" under \"ADVANCED\"",	//XAUTH_CONFIGURE
					" is invalid. The legal characters can not enter # * , ; ' / ''"	//LEGAL_NAME
				);
var INVALID_IP_ADDRESS = 0;
var ZERO_IP_ADDRESS = 1;
var IP_ADDRESS_DESC = 2;
var INVALID_MASK_ADDRESS = 3;
var ZERO_MASK_ADDRESS = 4;
var MASK_ADDRESS_DESC = 5;
var INVALID_GATEWAY_ADDRESS = 6;
var ZERO_GATEWAY_ADDRESS = 7;
var GATEWAY_ADDRESS_DESC = 8;
var NOT_SAME_DOMAIN = 9;
var INVALID_START_IP = 10;
var ZERO_START_IP = 11;
var START_IP_DESC = 12;
var START_INVALID_DOMAIN = 13;
var INVALID_END_IP = 14;
var ZERO_END_IP = 15;
var END_IP_DESC = 16;
var END_INVALID_DOMAIN = 17;
var INVALID_DNS_ADDRESS = 18;
var ZERO_DNS_ADDRESS = 19;
var DNS_ADDRESS_DESC = 20;
var SSID_EMPTY_ERROR = 21;
var AUTH_TYPE_ERROR = 22;
var PSK_LENGTH_ERROR = 23;
var PSK_MATCH_ERROR = 24;
var MATCH_PWD_ERROR = 25;
var WEP_KEY_EMPTY = 26;
var WIZARD_KEY_EMPTY = 27;
var QUIT_WIZARD = 28;
var MAC_ADDRESS_ERROR = 29;
var IP_RANGE_ERROR = 30;
var INVALID_SEC_DNS_ADDRESS = 31;
var ZERO_SEC_DNS_ADDRESS = 32;
var SEC_DNS_ADDRESS_DESC = 33;
var ADMIN_PASS_ERROR = 34;
var USER_PASS_ERROR = 35;
var DDNS_SERVER_ERROR = 36;
var DDNS_HOST_ERROR = 37;
var DDNS_USER_ERROR = 38;
var DDNS_PASS_ERROR = 39;
var RESTORE_DEFAULT = 40;
var REBOOT_ROUTER = 41;
var LOAD_SETTING = 42;
var LOAD_FILE_ERROR = 43;
var DOWNLOAD_SETTING_ERROR = 44;
var PING_IP_ERROR = 45;
var SMTP_SERVER_ERROR = 46;
var EMAIL_ADDRESS_ERROR = 47;
var DEL_SERVER_MSG = 48;
var DEL_APPLICATION_MSG = 49;
var DEL_FILTER_MSG = 50;
var DEL_ROUTE_MSG = 51;
var DEL_MAC_MSG = 52;
var DEL_KEYWORD_MSG = 53;
var DEL_DOMAIN_MSG = 54;
var DEL_ENTRY_MSG = 55;
var DEL_STATIC_DHCP_MSG = 56;
var NAME_ERROR = 57;
var TRIGGER_PORT_ERROR = 58;
var PUBLIC_PORT_ERROR = 59;
var PRIVATE_PORT_ERROR = 60;
var PRIVATE_IP_ERROR = 61;
var PORT_ERROR = 62;
var DEL_KEYWORD_ERROR = 63;
var SAME_KEYWORD_ERROR = 64;
var KEYWORD_ERROR = 65;
var ADD_KEYWORD_ERROR = 66;
var DEL_BLOCK_DOMAIN_ERROR = 67;
var DEL_PERMIT_DOMAIN_ERROR = 68;
var SAME_BLOCK_DOMAIN = 69;
var BLOCK_DOMAIN_ERROR = 70;
var ADD_BLOCK_DOMAIN_ERROR = 71;
var SAME_PERMIT_DOMAIN = 72;
var PERMIT_DOMAIN_ERROR = 73;
var ADD_PERMIT_DOMAIN_ERROR = 74;
var FIRMWARE_UPGRADE_ERROR = 75;
var DOMAIN_ERROR = 76;
var ADD_CONTROL_DOMAIN_ERROR = 77;
var DEL_CONTROL_DOMAIN_ERROR = 78;
var CONTROL_DOMAIN_ERROR = 79;
var INVALID_RADIUS_SERVER1_IP = 80;
var ZERO_RADIUS_SERVER1_IP = 81;
var RADIUS_SERVER1_IP_DESC = 82;
var INVALID_RADIUS_SERVER2_IP = 83;
var ZERO_RADIUS_SERVER2_IP = 84;
var RADIUS_SERVER2_IP_DESC = 85;
var INVALID_STATIC_DHCP_IP = 86;
var ZERO_STATIC_DHCP_IP = 87;
var STATIC_DHCP_NAME = 88;
var INVALID_SERVER_IP = 89;
var ZERO_SERVER_IP = 90;
var SERVER_IP_DESC = 91;
var MATCH_WIZARD_PWD_ERROR = 92;
var INVALID_SOURCE_START_IP = 93;
var ZERO_SOURCE_START_IP = 94;
var SOURCE_START_IP_DESC = 95;
var INVALID_SOURCE_END_IP = 96;
var ZERO_SOURCE_END_IP = 97;
var SOURCE_END_IP_DESC = 98;
var INVALID_DEST_START_IP = 99;
var ZERO_DEST_START_IP = 100;
var DEST_START_IP_DESC = 101;
var INVALID_DEST_END_IP = 102;
var ZERO_DEST_END_IP = 103;
var DEST_END_IP_DESC = 104;
var PSK_OVER_LEN = 105;
var RESET_JUMPSTAR = 106;
var DEL_RULE_MSG = 107;
var DEL_SCHEDULE_MSG = 108;
var ADD_SCHEDULE_ERROR = 109;
var SCHEDULE_NAME_ERROR = 110;
var SCHEDULE_NAME_SPACE_ERROR = 111;
var TIME_RANGE_ERROR = 112;
var SELECT_MACHINE_ERROR = 113;
var SELECT_APPLICATION_ERROR = 114;
var SELECT_COMPUTER_ERROR = 115;
var SECURITY_PWD_ERROR = 116;
var DUPLICATE_URL_ERROR = 117;
var LOGIN_NAME_ERROR = 118;
var LOGIN_PASS_ERROR = 119;
var IP_ORDER_ERROR = 120;
var PORT_RANGE_ERROR = 121;
var UPGRADE_FIRMWARE = 122;
var X509_CONFIGURE = 123;
var XAUTH_CONFIGURE = 124;
var LEGAL_NAME = 125;

/** for check_address() using **/
var radius1_msg = new Array("The Radius Server 1 IP address is an invalid address.",	// INVALID_IP
						       "The Radius Server 1 IP address can not be zero.",	// ZERO_IP
						       "The 1st address of Radius Server 1 IP address must be an integer.",	// FIRST_IP_ERROR
						       "The 2nd address of Radius Server 1 IP address must be an integer.",	// SECOND_IP_ERROR
						       "The 3rd address of Radius Server 1 IP address must be an integer.",	// THIRD_IP_ERROR
						       "The 4th address of Radius Server 1 IP address must be an integer.",	// FOURTH_IP_ERROR
						       "The 1st range of Radius Server 1 IP address must be between",			// FIRST_RANGE_ERROR
						       "The 2nd range of Radius Server 1 IP address must be between",			// SECOND_RANGE_ERROR
						       "The 3rd range of Radius Server 1 IP address must be between",			// THIRD_RANGE_ERROR
						       "The 4th range of Radius Server 1 IP address must be between",			// FOURTH_RANGE_ERROR
						       "The port of Radius Server 1 is invalid.",	// RADIUS_SERVER_PORT_ERROR
						       "The Shared Secret of Radius Server 1 can not be empty." // RADIUS_SERVER_SECRET_ERROR
						      );

var radius2_msg = new Array("The Radius Server 2 IP address is an invalid address.",	// INVALID_IP
						       "The Radius Server 2 IP address can not be zero.",	// ZERO_IP
						       "The 1st address of Radius Server 2 IP address must be an integer.",	// FIRST_IP_ERROR
						       "The 2nd address of Radius Server 2 IP address must be an integer.",	// SECOND_IP_ERROR
						       "The 3rd address of Radius Server 2 IP address must be an integer.",	// THIRD_IP_ERROR
						       "The 4th address of Radius Server 2 IP address must be an integer.",	// FOURTH_IP_ERROR
						       "The 1st range of Radius Server 2 IP address must be between",			// FIRST_RANGE_ERROR
						       "The 2nd range of Radius Server 2 IP address must be between",			// SECOND_RANGE_ERROR
						       "The 3rd range of Radius Server 2 IP address must be between",			// THIRD_RANGE_ERROR
						       "The 4th range of Radius Server 2 IP address must be between",			// FOURTH_RANGE_ERROR
						       "The port of Radius Server 2 is invalid.",	// RADIUS_SERVER_PORT_ERROR
						       "The Shared Secret of Radius Server 2 can not be empty." // RADIUS_SERVER_SECRET_ERROR
						      );

var ip_addr_msg = new Array("The IP address is an invalid address.",	// INVALID_IP
						       "The IP address can not be zero.",	// ZERO_IP
						       "The 1st address of IP address must be an integer.",	// FIRST_IP_ERROR
						       "The 2nd address of IP address must be an integer.",	// SECOND_IP_ERROR
						       "The 3rd address of IP address must be an integer.",	// THIRD_IP_ERROR
						       "The 4th address of IP address must be an integer.",	// FOURTH_IP_ERROR
						       "The 1st range of IP address must be between",			// FIRST_RANGE_ERROR
						       "The 2nd range of IP address must be between",			// SECOND_RANGE_ERROR
						       "The 3rd range of IP address must be between",			// THIRD_RANGE_ERROR
						       "The 4th range of IP address must be between"			// FOURTH_RANGE_ERROR
						      );

var subnet_mask_msg = new Array("The Subnet Mask is an invalid address.",	// INVALID_IP
						           "The Subnet Mask can not be zero.",	// ZERO_IP
						           "The 1st address of Subnet Mask must be an integer.",	// FIRST_IP_ERROR
						    	   "The 2nd address of Subnet Mask must be an integer.",	// SECOND_IP_ERROR
						    	   "The 3rd address of Subnet Mask must be an integer.",	// THIRD_IP_ERROR
						    	   "The 4th address of Subnet Mask must be an integer.",	// FOURTH_IP_ERROR
						    	   "The 1st range of Subnet Mask must be 128, 192, 224, 240, 248, 252, 254, 255.",			// FIRST_RANGE_ERROR
						    	   "The 2nd range of Subnet Mask must be 0, 128, 192, 224, 240, 248, 252, 254, 255.",			// SECOND_RANGE_ERROR
						    	   "The 3rd range of Subnet Mask must be 0, 128, 192, 224, 240, 248, 252, 254, 255.",			// THIRD_RANGE_ERROR
						    	   "The 4th range of Subnet Mask must be 0, 128, 192, 224, 240, 248, 252."			// FOURTH_RANGE_ERROR
						          );

var gateway_msg = new Array("The Gateway address is an invalid address.",	// INVALID_IP
						       "The Gateway address can not be zero.",	// ZERO_IP
						       "The 1st address of Gateway address must be an integer.",	// FIRST_IP_ERROR
						       "The 2nd address of Gateway address must be an integer.",	// SECOND_IP_ERROR
						       "The 3rd address of Gateway address must be an integer.",	// THIRD_IP_ERROR
						       "The 4th address of Gateway address must be an integer.",	// FOURTH_IP_ERROR
						       "The 1st range of Gateway address must be between",			// FIRST_RANGE_ERROR
						       "The 2nd range of Gateway address must be between",			// SECOND_RANGE_ERROR
						       "The 3rd range of Gateway address must be between",			// THIRD_RANGE_ERROR
						       "The 4th range of Gateway address must be between"			// FOURTH_RANGE_ERROR
						       );

var start_ip_addr_msg = new Array("The Start IP address is an invalid address.",	// INVALID_IP
						    		 "The Start IP address can not be zero.",	// ZERO_IP
						    		 "The 1st address of Start IP address must be an integer.",	// FIRST_IP_ERROR
						    		 "The 2nd address of Start IP address must be an integer.",	// SECOND_IP_ERROR
						    		 "The 3rd address of Start IP address must be an integer.",	// THIRD_IP_ERROR
						    		 "The 4th address of Start IP address must be an integer.",	// FOURTH_IP_ERROR
						      		 "The 1st range of Start IP address must be between",			// FIRST_RANGE_ERROR
						    		 "The 2nd range of Start IP address must be between",			// SECOND_RANGE_ERROR
						    		 "The 3rd range of Start IP address must be between",			// THIRD_RANGE_ERROR
						    		 "The 4th range of Start IP address must be between"			// FOURTH_RANGE_ERROR
						    	    );

var end_ip_addr_msg = new Array("The End IP address is an invalid address.",	// INVALID_IP
						    	   "The End IP address can not be zero.",	// ZERO_IP
						    	   "The 1st address of End IP address must be an integer.",	// FIRST_IP_ERROR
						    	   "The 2nd address of End IP address must be an integer.",	// SECOND_IP_ERROR
						    	   "The 3rd address of End IP address must be an integer.",	// THIRD_IP_ERROR
						    	   "The 4th address of End IP address must be an integer.",	// FOURTH_IP_ERROR
						    	   "The 1st range of End IP address must be between",			// FIRST_RANGE_ERROR
						    	   "The 2nd range of End IP address must be between",			// SECOND_RANGE_ERROR
						    	   "The 3rd range of End IP address must be between",			// THIRD_RANGE_ERROR
						    	   "The 4th range of End IP address must be between"			// FOURTH_RANGE_ERROR
						    	   );

var static_ip_addr_msg = new Array("The static IP address is an invalid address.",	// INVALID_IP
						    		 "The static IP address can not be zero.",	// ZERO_IP
						    		 "The 1st address of static IP address must be an integer.",	// FIRST_IP_ERROR
						    		 "The 2nd address of static IP address must be an integer.",	// SECOND_IP_ERROR
						    		 "The 3rd address of static IP address must be an integer.",	// THIRD_IP_ERROR
						    		 "The 4th address of static IP address must be an integer.",	// FOURTH_IP_ERROR
						      		 "The 1st range of static IP address must be between",			// FIRST_RANGE_ERROR
						    		 "The 2nd range of static IP address must be between",			// SECOND_RANGE_ERROR
						    		 "The 3rd range of static IP address must be between",			// THIRD_RANGE_ERROR
						    		 "The 4th range of static IP address must be between"			// FOURTH_RANGE_ERROR
						    	    );
						    	    
var src_ip_msg = new Array("The Source IP address is an invalid address.",	// INVALID_IP
							     	"The Source IP address can not be zero.",	// ZERO_IP
							     	"The 1st address of Source IP address must be an integer.",	// FIRST_IP_ERROR
							     	"The 2nd address of Source IP address must be an integer.",	// SECOND_IP_ERROR
							     	"The 3rd address of Source IP address must be an integer.",	// THIRD_IP_ERROR
							     	"The 4th address of Source IP address must be an integer.",	// FOURTH_IP_ERROR
							     	"The 1st range of Source IP address must be between",			// FIRST_RANGE_ERROR
							     	"The 2nd range of Source IP address must be between",			// SECOND_RANGE_ERROR
							     	"The 3rd range of Source IP address must be between",			// THIRD_RANGE_ERROR
							     	"The 4th range of Source IP address must be between"			// FOURTH_RANGE_ERROR
							     	);

var src_start_ip_msg = new Array("The Source Start IP address is an invalid address.",	// INVALID_IP
							     	"The Source Start IP address can not be zero.",	// ZERO_IP
							     	"The 1st address of Source Start IP address must be an integer.",	// FIRST_IP_ERROR
							     	"The 2nd address of Source Start IP address must be an integer.",	// SECOND_IP_ERROR
							     	"The 3rd address of Source Start IP address must be an integer.",	// THIRD_IP_ERROR
							     	"The 4th address of Source Start IP address must be an integer.",	// FOURTH_IP_ERROR
							     	"The 1st range of Source Start IP address must be between",			// FIRST_RANGE_ERROR
							     	"The 2nd range of Source Start IP address must be between",			// SECOND_RANGE_ERROR
							     	"The 3rd range of Source Start IP address must be between",			// THIRD_RANGE_ERROR
							     	"The 4th range of Source Start IP address must be between"			// FOURTH_RANGE_ERROR
							     	);

var src_end_ip_msg = new Array("The Source End IP address is an invalid address.",	// INVALID_IP
						       	  "The Source End IP address can not be zero.",	// ZERO_IP
						       	  "The 1st address of Source End IP address must be an integer.",	// FIRST_IP_ERROR
						       	  "The 2nd address of Source End IP address must be an integer.",	// SECOND_IP_ERROR
						          "The 3rd address of Source End IP address must be an integer.",	// THIRD_IP_ERROR
						          "The 4th address of Source End IP address must be an integer.",	// FOURTH_IP_ERROR
						          "The 1st range of Source End IP address must be between",			// FIRST_RANGE_ERROR
						          "The 2nd range of Source End IP address must be between",			// SECOND_RANGE_ERROR
						          "The 3rd range of Source End IP address must be between",			// THIRD_RANGE_ERROR
						          "The 4th range of Source End IP address must be between"			// FOURTH_RANGE_ERROR
						         );

var dst_ip_msg = new Array("The Destination IP address is an invalid address.",	// INVALID_IP
							      	"The Destination IP address can not be zero.",	// ZERO_IP
							     	"The 1st address of Destination IP address must be an integer.",	// FIRST_IP_ERROR
							     	"The 2nd address of Destination IP address must be an integer.",	// SECOND_IP_ERROR
							     	"The 3rd address of Destination IP address must be an integer.",	// THIRD_IP_ERROR
							     	"The 4th address of Destination IP address must be an integer.",	// FOURTH_IP_ERROR
							     	"The 1st range of Destination IP address must be between",			// FIRST_RANGE_ERROR
							     	"The 2nd range of Destination IP address must be between",			// SECOND_RANGE_ERROR
							     	"The 3rd range of Destination IP address must be between",			// THIRD_RANGE_ERROR
							     	"The 4th range of Destination IP address must be between"			// FOURTH_RANGE_ERROR
							     	);

var dst_start_ip_msg = new Array("The Destination Start IP address is an invalid address.",	// INVALID_IP
							      	"The Destination Start IP address can not be zero.",	// ZERO_IP
							     	"The 1st address of Destination Start IP address must be an integer.",	// FIRST_IP_ERROR
							     	"The 2nd address of Destination Start IP address must be an integer.",	// SECOND_IP_ERROR
							     	"The 3rd address of Destination Start IP address must be an integer.",	// THIRD_IP_ERROR
							     	"The 4th address of Destination Start IP address must be an integer.",	// FOURTH_IP_ERROR
							     	"The 1st range of Destination Start IP address must be between",			// FIRST_RANGE_ERROR
							     	"The 2nd range of Destination Start IP address must be between",			// SECOND_RANGE_ERROR
							     	"The 3rd range of Destination Start IP address must be between",			// THIRD_RANGE_ERROR
							     	"The 4th range of Destination Start IP address must be between"			// FOURTH_RANGE_ERROR
							     	);

var dst_end_ip_msg = new Array("The Destination End IP address is an invalid address.",	// INVALID_IP
						       	  "The Destination End IP address can not be zero.",	// ZERO_IP
						          "The 1st address of Destination End IP address must be an integer.",	// FIRST_IP_ERROR
						       	  "The 2nd address of Destination End IP address must be an integer.",	// SECOND_IP_ERROR
						          "The 3rd address of Destination End IP address must be an integer.",	// THIRD_IP_ERROR
						          "The 4th address of Destination End IP address must be an integer.",	// FOURTH_IP_ERROR
						          "The 1st range of Destination End IP address must be between",			// FIRST_RANGE_ERROR
						          "The 2nd range of Destination End IP address must be between",			// SECOND_RANGE_ERROR
						          "The 3rd range of Destination End IP address must be between",			// THIRD_RANGE_ERROR
						          "The 4th range of Destination End IP address must be between"			// FOURTH_RANGE_ERROR
						         );

var dns_server_msg = new Array("The DNS Server is an invalid address.",	// INVALID_IP
						          "The DNS Server can not be zero.",	// ZERO_IP
						          "The 1st address of DNS Server must be an integer.",	// FIRST_IP_ERROR
						          "The 2nd address of DNS Server must be an integer.",	// SECOND_IP_ERROR
						          "The 3rd address of DNS Server must be an integer.",	// THIRD_IP_ERROR
						          "The 4th address of DNS Server must be an integer.",	// FOURTH_IP_ERROR
						          "The 1st range of DNS Server must be between",			// FIRST_RANGE_ERROR
						          "The 2nd range of DNS Server must be between",			// SECOND_RANGE_ERROR
						          "The 3rd range of DNS Server must be between",			// THIRD_RANGE_ERROR
						          "The 4th range of DNS Server must be between"			// FOURTH_RANGE_ERROR
						         );

var primary_dns_msg = new Array("The Primary DNS Address is an invalid address.",	// INVALID_IP
						           "The Primary DNS Address can not be zero.",	// ZERO_IP
						           "The 1st address of Primary DNS Address must be an integer.",	// FIRST_IP_ERROR
						           "The 2nd address of Primary DNS Address must be an integer.",	// SECOND_IP_ERROR
						           "The 3rd address of Primary DNS Address must be an integer.",	// THIRD_IP_ERROR
						           "The 4th address of Primary DNS Address must be an integer.",	// FOURTH_IP_ERROR
						           "The 1st range of Primary DNS Address must be between",			// FIRST_RANGE_ERROR
						           "The 2nd range of Primary DNS Address must be between",			// SECOND_RANGE_ERROR
						           "The 3rd range of Primary DNS Address must be between",			// THIRD_RANGE_ERROR
						           "The 4th range of Primary DNS Address must be between"			// FOURTH_RANGE_ERROR
						           );

var second_dns_msg = new Array("The Secondary DNS Address is an invalid address.",	// INVALID_IP
						       	  "The Secondary DNS Address can not be zero.",	// ZERO_IP
						          "The 1st address of Secondary DNS Address must be an integer.",	// FIRST_IP_ERROR
						          "The 2nd address of Secondary DNS Address must be an integer.",	// SECOND_IP_ERROR
						          "The 3rd address of Secondary DNS Address must be an integer.",	// THIRD_IP_ERROR
						          "The 4th address of Secondary DNS Address must be an integer.",	// FOURTH_IP_ERROR
						          "The 1st range of Secondary DNS Address must be between",			// FIRST_RANGE_ERROR
						          "The 2nd range of Secondary DNS Address must be between",			// SECOND_RANGE_ERROR
						          "The 3rd range of Secondary DNS Address must be between",			// THIRD_RANGE_ERROR
						          "The 4th range of Secondary DNS Address must be between"			// FOURTH_RANGE_ERROR
						          );

var dns1_addr_msg = new Array("The DNS Server 1 is an invalid address.",	// INVALID_IP
						         "The DNS Server 1 can not be zero.",	// ZERO_IP
						         "The 1st address of DNS Server 1 must be an integer.",	// FIRST_IP_ERROR
						         "The 2nd address of DNS Server 1 must be an integer.",	// SECOND_IP_ERROR
						         "The 3rd address of DNS Server 1 must be an integer.",	// THIRD_IP_ERROR
						         "The 4th address of DNS Server 1 must be an integer.",	// FOURTH_IP_ERROR
						         "The 1st range of DNS Server 1 must be between",			// FIRST_RANGE_ERROR
						         "The 2nd range of DNS Server 1 must be between",			// SECOND_RANGE_ERROR
						         "The 3rd range of DNS Server 1 must be between",			// THIRD_RANGE_ERROR
						         "The 4th range of DNS Server 1 must be between"			// FOURTH_RANGE_ERROR
						         );

var dns2_addr_msg = new Array("The DNS Server 2 is an invalid address.",	// INVALID_IP
						       	 "The DNS Server 2 can not be zero.",	// ZERO_IP
						         "The 1st address of DNS Server 2 must be an integer.",	// FIRST_IP_ERROR
						         "The 2nd address of DNS Server 2 must be an integer.",	// SECOND_IP_ERROR
						         "The 3rd address of DNS Server 2 must be an integer.",	// THIRD_IP_ERROR
						         "The 4th address of DNS Server 2 must be an integer.",	// FOURTH_IP_ERROR
						         "The 1st range of DNS Server 2 must be between",			// FIRST_RANGE_ERROR
						         "The 2nd range of DNS Server 2 must be between",			// SECOND_RANGE_ERROR
						         "The 3rd range of DNS Server 2 must be between",			// THIRD_RANGE_ERROR
						         "The 4th range of DNS Server 2 must be between"			// FOURTH_RANGE_ERROR
						        );

var dns3_addr_msg = new Array("The DNS Server 3 is an invalid address.",	// INVALID_IP
						         "The DNS Server 3 can not be zero.",	// ZERO_IP
						         "The 1st address of DNS Server 3 must be an integer.",	// FIRST_IP_ERROR
						         "The 2nd address of DNS Server 3 must be an integer.",	// SECOND_IP_ERROR
						         "The 3rd address of DNS Server 3 must be an integer.",	// THIRD_IP_ERROR
						         "The 4th address of DNS Server 3 must be an integer.",	// FOURTH_IP_ERROR
						         "The 1st range of DNS Server 3 must be between",			// FIRST_RANGE_ERROR
						         "The 2nd range of DNS Server 3 must be between",			// SECOND_RANGE_ERROR
						         "The 3rd range of DNS Server 3 must be between",			// THIRD_RANGE_ERROR
						         "The 4th range of DNS Server 3 must be between"			// FOURTH_RANGE_ERROR
						         );

var syslog_server_msg = new Array("The Syslog Server is an invalid address.",	// INVALID_IP
								    "The Syslog Server can not be zero.",	// ZERO_IP
								    "The 1st address of Syslog Server must be an integer.",	// FIRST_IP_ERROR
								    "The 2nd address of Syslog Server must be an integer.",	// SECOND_IP_ERROR
								    "The 3rd address of Syslog Server must be an integer.",	// THIRD_IP_ERROR
								    "The 4th address of Syslog Server must be an integer.",	// FOURTH_IP_ERROR
								    "The 1st range of Syslog Server must be between",			// FIRST_RANGE_ERROR
								    "The 2nd range of Syslog Server must be between",			// SECOND_RANGE_ERROR
								    "The 3rd range of Syslog Server must be between",			// THIRD_RANGE_ERROR
								    "The 4th range of Syslog Server must be between"			// FOURTH_RANGE_ERROR
								    );

var http_form_ip_addr_msg = new Array("The From IP address is an invalid address in the HTTP section.",	// INVALID_IP
						    			 "The From IP address can not be zero in the HTTP section..",	// ZERO_IP
						    			 "The 1st address of From IP address must be an integer in the HTTP section..",	// FIRST_IP_ERROR
						    			 "The 2nd address of From IP address must be an integer in the HTTP section..",	// SECOND_IP_ERROR
						    			 "The 3rd address of From IP address must be an integer in the HTTP section..",	// THIRD_IP_ERROR
						     			 "The 4th address of From IP address must be an integer in the HTTP section..",	// FOURTH_IP_ERROR
						    			 "The 1st range of From IP address must be between 1 to 254 in the HTTP section..",			// FIRST_RANGE_ERROR
						    			 "The 2nd range of From IP address must be between 0 to 255 in the HTTP section..",			// SECOND_RANGE_ERROR
						    			 "The 3rd range of From IP address must be between 0 to 255 in the HTTP section..",			// THIRD_RANGE_ERROR
						    			 "The 4th range of From IP address must be between 1 to 254 in the HTTP section.."			// FOURTH_RANGE_ERROR
						    			 );

var http_to_ip_addr_msg = new Array("The To IP address is an invalid address in the HTTP section.",	// INVALID_IP
						    		   "The To IP address can not be zero in the HTTP section..",	// ZERO_IP
						    		   "The 1st address of To IP address must be an integer in the HTTP section..",	// FIRST_IP_ERROR
						    		   "The 2nd address of To IP address must be an integer in the HTTP section..",	// SECOND_IP_ERROR
						    		   "The 3rd address of To IP address must be an integer in the HTTP section..",	// THIRD_IP_ERROR
						    		   "The 4th address of To IP address must be an integer in the HTTP section..",	// FOURTH_IP_ERROR
						    		   "The 1st range of To IP address must be between 1 to 254 in the HTTP section..",			// FIRST_RANGE_ERROR
						    		   "The 2nd range of To IP address must be between 0 to 255 in the HTTP section..",			// SECOND_RANGE_ERROR
						    		   "The 3rd range of To IP address must be between 0 to 255 in the HTTP section..",			// THIRD_RANGE_ERROR
						    		   "The 4th range of To IP address must be between 1 to 254 in the HTTP section.."			// FOURTH_RANGE_ERROR
						    		   );

var allow_form_ip_addr_msg = new Array("The From IP address is an invalid address in the Allow to Ping WAN port section.",	// INVALID_IP
						    			  "The From IP address can not be zero in the Allow to Ping WAN port section..",	// ZERO_IP
						    			  "The 1st address of From IP address must be an integer in the Allow to Ping WAN port section..",	// FIRST_IP_ERROR
						    			  "The 2nd address of From IP address must be an integer in the Allow to Ping WAN port section..",	// SECOND_IP_ERROR
						    			  "The 3rd address of From IP address must be an integer in the Allow to Ping WAN port section..",	// THIRD_IP_ERROR
						    			  "The 4th address of From IP address must be an integer in the Allow to Ping WAN port section..",	// FOURTH_IP_ERROR
						    			  "The 1st range of From IP address must be between 1 to 254 in the Allow to Ping WAN port section..",			// FIRST_RANGE_ERROR
						    			  "The 2nd range of From IP address must be between 0 to 255 in the Allow to Ping WAN port section..",			// SECOND_RANGE_ERROR
						    			  "The 3rd range of From IP address must be between 0 to 255 in the Allow to Ping WAN port section..",			// THIRD_RANGE_ERROR
						    			  "The 4th range of From IP address must be between 1 to 254 in the Allow to Ping WAN port section.."			// FOURTH_RANGE_ERROR
						    			  );

var allow_to_ip_addr_msg = new Array("The To IP address is an invalid address in the Allow to Ping WAN port section.",	// INVALID_IP
						    			"The To IP address can not be zero in the Allow to Ping WAN port section..",	// ZERO_IP
						    			"The 1st address of To IP address must be an integer in the Allow to Ping WAN port section..",	// FIRST_IP_ERROR
						    			"The 2nd address of To IP address must be an integer in the Allow to Ping WAN port section..",	// SECOND_IP_ERROR
						    			"The 3rd address of To IP address must be an integer in the Allow to Ping WAN port section..",	// THIRD_IP_ERROR
						    			"The 4th address of To IP address must be an integer in the Allow to Ping WAN port section..",	// FOURTH_IP_ERROR
						    			"The 1st range of To IP address must be between 1 to 254 in the Allow to Ping WAN port section..",			// FIRST_RANGE_ERROR
						    			"The 2nd range of To IP address must be between 0 to 255 in the Allow to Ping WAN port section..",			// SECOND_RANGE_ERROR
						    			"The 3rd range of To IP address must be between 0 to 255 in the Allow to Ping WAN port section..",			// THIRD_RANGE_ERROR
						    			"The 4th range of To IP address must be between 1 to 254 in the Allow to Ping WAN port section.."			// FOURTH_RANGE_ERROR
						    			);
						    			
var INVALID_IP = 0;
var ZERO_IP = 1;
var FIRST_IP_ERROR = 2;
var SECOND_IP_ERROR = 3;
var THIRD_IP_ERROR = 4;
var FOURTH_IP_ERROR = 5;
var FIRST_RANGE_ERROR = 6;
var SECOND_RANGE_ERROR = 7;
var THIRD_RANGE_ERROR = 8;
var FOURTH_RANGE_ERROR = 9;
var RADIUS_SERVER_PORT_ERROR = 10;	// for radius server
var RADIUS_SERVER_SECRET_ERROR = 11; // for radius server
/** the end of check_address() using **/

var default_rule = new Array(new rule_obj("FTP", "TCP", 21, 21),
							 new rule_obj("HTTP", "TCP", 80, 80),
							 new rule_obj("HTTPS", "TCP", 443, 443),
							 new rule_obj("DNS", "UDP", 53, 53),
							 new rule_obj("SMTP", "TCP", 25, 25),
							 new rule_obj("POP3", "TCP", 110, 110),
							 new rule_obj("Telnet", "TCP", 23, 23),
							 new rule_obj("IPSec", "UDP", 500, 500),
							 new rule_obj("PPTP", "TCP", 1723, 1723),
							 new rule_obj("NetMeeting", "TCP", 1720, 1720),
							 new rule_obj("DCS-1000", "TCP", 80, 80),
							 new rule_obj("DCS-2000 DCS-5300", "TCP", 800, 800),
							 new rule_obj("i2eye", "TCP", 1720, 1720),
							 new rule_obj("DCS-3120", "TCP", 3120, 3120)
						  );

var default_appl = new Array(new appl_obj("Battle.net", "TCP", "6112", "TCP", "6112"),
							 new appl_obj("Dialpad", "TCP", "7175", "TCP", "51200-51201,51210"),
							 new appl_obj("ICU II", "TCP", "2019", "TCP", "2000-2038,2050-2051,2069,2085,3010-3030"),
							 new appl_obj("MSN Gaming Zone", "TCP", "47624", "TCP", "2300-2400,28800-29000"),
							 new appl_obj("PC-to-Phone", "TCP", "12053", "TCP", "12120,12122,24150-24220"),
							 new appl_obj("Quick Time 4", "TCP", "554", "TCP", "6970-6999")
							);

function rule_obj(name, prot, public_port, private_port){	
	this.name = name;
	this.prot = prot;		// TCP, UDP
	this.public_port = public_port;
	this.private_port = private_port;
}

function appl_obj(name, trigger_prot, trigger_port, public_prot, public_port){
	this.name = name;
	this.trigger_prot = trigger_prot;		// TCP, UDP
	this.trigger_port = trigger_port;
	this.public_prot = public_prot;
	this.public_port = public_port;
}
							
function get_by_id(id){
	with(document){
		return getElementById(id);
	}
}

function get_by_name(name){
	with(document){
		return getElementsByName(name);
	}
}	

function send_submit(which_form){
	get_by_id(which_form).submit();
}

function addr_obj(addr, e_msg, allow_zero, is_network){
	this.addr = addr;
	this.e_msg = e_msg;
	this.allow_zero = allow_zero;
	this.is_network = is_network;
}

function varible_obj(var_value, desc, min, max, is_even){	
	this.var_value = var_value;
	this.desc = desc;
	this.min = min;
	this.max = max;		
	this.is_even = is_even;		
}

function raidus_obj(ip, port, secret, number){	
	this.ip = ip;
	this.port = port;
	this.secret = secret;
	this.number = number;		
}

function ip4_obj(ip, min_range, max_range, e_msg1, e_msg2){	
	this.ip = ip;	
	this.min_range = min_range;
	this.max_range = max_range;		
	this.e_msg1 = msg[e_msg1];
	this.e_msg2 = msg[e_msg2];	
}

function set_application_option(){
	for (var i = 0; i < default_rule.length; i++){
		var temp_rule = default_rule[i];
		document.write("<option>" + temp_rule.name + "</option>");
	}
}

function set_special_appl_option(){
	for (var i = 0; i < default_appl.length; i++){
		var temp_appl = default_appl[i];
		document.write("<option>" + temp_appl.name + "</option>");
	}
}

//for check code
function check_hex(data){	
	data = data.toUpperCase();
	
	if (!(data >= 'A' && data <= 'F') && !(data >= '0' && data <= '9')){	
		return false;
	}	
	return true;
}

//check wep
function check_key(){
	var key;
	var wep_type = get_by_id("wep_type");
	var wep_key_len = parseInt(get_by_id("wep_key_len").value);
	var hex_len = wep_key_len * 2;

	if (wep_type.selectedIndex == 1 ){	
			if(wep_key_len == "5"){
					key = get_by_id("wep_64_key").value;
			}else{
					key = get_by_id("wep_128_key").value;
			}
			if (key == ""){
		    	alert(msg[WEP_KEY_EMPTY]);
					return false;
	    }else{
		    	if (key.length != wep_key_len && key.length != hex_len){
			    		alert("The Key is invalid. The Key must be " + wep_key_len + " characters or " + hex_len + " hexadecimal number.");
			    		return false;
		    	}else if(key.length == hex_len){
			      	for (var j = 0; j < key.length; j++){
			      		if (!check_hex(key.substring(j, j+1))){
			      			alert("Key is wrong, the legal characters are 0~9, A~F, or a~f.");
			      			return false;
			      		}
			      	}
			      	get_by_id("wlan0_wep_display").value = "hex";
		    	}else{
		    			get_by_id("wlan0_wep_display").value = "ascii";
		    	}
	    }
	}
	return true;
}

//check wizard wep key
function check_wizard_key(key){
	var wep_key_len = 13;
	var hex_len = wep_key_len * 2;

			if (key == ""){
		    	alert(msg[WEP_KEY_EMPTY]);
					return false;
	    }else{
		    	if (key.length != wep_key_len && key.length != hex_len){
			    		alert("The Key is invalid. The Key must be " + wep_key_len + " characters or " + hex_len + " hexadecimal number.");
			    		return false;
		    	}else if(key.length == hex_len){
			      	for (var j = 0; j < key.length; j++){
			      		if (!check_hex(key.substring(j, j+1))){
			      			alert("Key is wrong, the legal characters are 0~9, A~F, or a~f.");
			      			return false;
			      		}
			      	}
			      	get_by_id("asp_temp_47").value = "hex";
		    	}else{
		    			get_by_id("asp_temp_47").value = "ascii";
		    	}
	    }
	return true;
}


//check psk
function check_psk(psk_value){
	if (psk_value.length < 8){                   
		alert(msg[PSK_LENGTH_ERROR]);
		return false;
	}else if (psk_value.length > 63){
		// Modify at 2007/7/27 by Tony for allow to save 64bits HEX code
		for (var j = 0; j < psk_value.length; j++){
			if (!check_hex(psk_value.substring(j, j+1))){
				alert("The PSK should be HEX.");
				return false;
			}
		}
  }
  return true;         
}

function check_mac(mac){
    var temp_mac = mac.split(":");
    var error = true;
    
    if (temp_mac.length == 6){
	    for (var i = 0; i < 6; i++){        
	        var temp_str = temp_mac[i];
	        
	        if (temp_str == ""){
	            error = false;
	        }else{
							if (temp_str.length == 1){
								temp_str = "0" + temp_str;
							}				
	            if (!check_hex(temp_str.substring(0,1)) || !check_hex(temp_str.substring(1))){
	                error = false;
	            }
	        }
	        if (!error){
	            break;
	        }
	    }
		}else{
			error = false;
		}
	    return error;
}

function get_seq(index){
	var seq;
	
	switch(index){
		case 0:
			seq = "1st";
			break;
		case 1:
			seq = "2nd";
			break;
		case 2:
			seq = "3rd";
			break;
		case 3:
			seq = "4th";
			break;
	}
	return seq;
}

function check_varible(obj){	
	var temp_obj = (obj.var_value).split(" ");
	
	if (temp_obj == ""){
		alert(obj.desc + " cannot be left blank.");	
		return false;
	}else if (temp_obj.length > 1){
		alert("Please enter another " + obj.desc + " value.");
		return false;
	}else if (isNaN(obj.var_value)){
		alert(obj.desc + " must be a number.");
		return false;
	}else if (parseInt(obj.var_value) < obj.min || parseInt(obj.var_value) > obj.max){
		alert("The " + obj.desc + " value range is " + obj.min + " ~ " + obj.max + ".");
		return false;
	}else if (obj.is_even && (parseInt(obj.var_value) % 2 != 0)){
		alert(obj.desc + " must be an even number.");
		return false;
	}
	return true;
}

function check_integer(which_value, min, max){	
	var temp_obj = (which_value).split(" ");
	
	if (temp_obj == "" || temp_obj.length > 1 || isNaN(which_value)){	
		return false;
	}else if (parseInt(which_value, 10) < min || parseInt(which_value, 10) > max){
		return false;
	}
	return true;
}


//for check address
function check_ip4(ip4){
	var temp_ip = (ip4.ip).split(" ");
	
	if (ip4.ip == ""){
		alert(ip4.e_msg1);
		return false;
	}else if (isNaN(ip4.ip) || temp_ip.length > 1 || (temp_ip[0].length > 1 && temp_ip[0].substring(0,1) == "0") || parseInt(ip4.ip) < ip4.min_range || parseInt(ip4.ip) > ip4.max_range){
		alert(ip4.e_msg2);
		return false;
	}
	return true;
}

function check_ip_range(order, my_obj, mask){
	var which_ip = (my_obj.addr[order]).split(" ");
	var start, end;

	if (isNaN(which_ip) || which_ip == "" || which_ip.length > 1 || (which_ip[0].length > 1 && which_ip[0].substring(0,1) == "0")){	// if the address is invalid
		alert(my_obj.e_msg[FIRST_IP_ERROR + order]);
		return false;
	}
	
	if (order == 0){				// the checking range of 1st address
		start = 1;	
	}else{
		start = 0;				
	}
		
	if (mask[order] != 255){		
		if (parseInt(which_ip) >= 0 && parseInt(which_ip) <= 255){	
			end = (~mask[order]+256);				
			start = mask[order] & which_ip;	
			end += start;
		
			if (end > 255){
				end = 255;
			}
		}else{
			end = 255;
		}
	}else{
		end = 255;
	}
	
	if (order == 3){
		if ((mask[0] == 255) && (mask[1] == 255) && (mask[2] == 255)){
			start += 1;
			end -= 1;
		}else{								
			if (((mask[0] | (~my_obj.addr[0]+256)) == 255) && ((mask[1] | (~my_obj.addr[1]+256)) == 255) && ((mask[2] | (~my_obj.addr[2]+256)) == 255)){
				start += 1;
			}
			
			if (((mask[0] | my_obj.addr[0]) == 255) && ((mask[1] | my_obj.addr[1]) == 255) && ((mask[2] | my_obj.addr[2]) == 255)){			
				end -= 1;
			}				
		}
	}
		
	if (parseInt(which_ip) < start || parseInt(which_ip) > end){			
		alert(my_obj.e_msg[FIRST_RANGE_ERROR + order] + " " + start + " ~ " + end + ".");		
		return false;
	}
	
	return true;
}

function check_current_range(order, my_obj, checking_ip, mask){
	var which_ip = (my_obj.addr[order]).split(" ");
	var start, end;

	if (isNaN(which_ip) || which_ip == "" || which_ip.length > 1 || (which_ip[0].length > 1 && which_ip[0].substring(0,1) == "0")){	// if the address is invalid
		alert(my_obj.e_msg[FIRST_IP_ERROR + order]);
		return false;
	}
	
	if (order == 0){				// the checking range of 1st address
		start = 1;	
	}else{
		start = 0;				
	}
	
	if (mask[order] != 255){				
		if (parseInt(checking_ip[order]) >= 0 && parseInt(checking_ip[order]) <= 255){	
			end = (~mask[order]+256);				
			start = mask[order] & checking_ip[order];	
			end += start;
		
			if (end > 255){
				end = 255;
			}
		}else{
			end = 255;
		}
	}else{
		end = 255;
	}
	
	if (order == 3){
		if ((mask[0] == 255) && (mask[1] == 255) && (mask[2] == 255)){
			start += 1;
			end -= 1;
		}else{		
			if (((mask[0] | (~my_obj.addr[0]+256)) == 255) && ((mask[1] | (~my_obj.addr[1]+256)) == 255) && ((mask[2] | (~my_obj.addr[2]+256)) == 255)){
				start += 1;
			}
			
			if (((mask[0] | my_obj.addr[0]) == 255) && ((mask[1] | my_obj.addr[1]) == 255) && ((mask[2] | my_obj.addr[2]) == 255)){			
				end -= 1;
			}	
		}	
	}
		
	if (parseInt(which_ip) < start || parseInt(which_ip) > end){			
		alert(my_obj.e_msg[FIRST_RANGE_ERROR + order] + " " + start + " ~ " + end + ".");		
		return false;
	}
	
	return true;
}

function check_address(my_obj, mask_obj, ip_obj){
	var count_zero = 0;
	var count_bcast = 0;	
	var ip = my_obj.addr;
	var mask;
	
	if (my_obj.addr.length == 4){
		// check the ip is "0.0.0.0" or not
		for(var i = 0; i < ip.length; i++){
			if (ip[i] == "0"){
				count_zero++;			
			}				
		}

		if (!my_obj.allow_zero && count_zero == 4){	// if the ip is not allowed to be 0.0.0.0
			alert(my_obj.e_msg[ZERO_IP]);			// but we check the ip is 0.0.0.0
			return false;
		}else if (count_zero != 4){		// when IP is not 0.0.0.0, checking range. Otherwise no need to check		
			count_zero = 0;
				
			if (check_address.arguments.length >= 2 && mask_obj != null){
				mask = mask_obj.addr;
			}else{
				mask = new Array(255,255,255,0);
			}
						
			for(var i = 0; i < ip.length; i++){
				
				if (check_address.arguments.length == 3 && ip_obj != null){
					if (!check_current_range(i, my_obj, ip_obj.addr, mask)){
						return false;
					}
				}else{					
					if (!check_ip_range(i, my_obj, mask)){
						return false;
					}
				}
			}		
							
			for (var i = 0; i < 4; i++){	// check the IP address is a network address or a broadcast address																							
				if (((~mask[i] + 256) & ip[i]) == 0){	// (~mask[i] + 256) = reverse mask[i]
					count_zero++;						
				}
								
				if ((mask[i] | ip[i]) == 255){
					count_bcast++;
				}
			}
		
			if ((count_zero == 4 && !my_obj.is_network) || (count_bcast == 4)){
				alert(my_obj.e_msg[INVALID_IP]);			
				return false;
			}													
		}
	}else{	// if the length of ip is not correct, show invalid ip msg
		alert(my_obj.e_msg[INVALID_IP]);
		return false;
	}

	return true;
}

function check_network_address(my_obj, mask_obj){
	var count_zero = 0;
	var ip = my_obj.addr;
	var mask;
	var allow_cast = false;

	if (my_obj.addr.length == 4){
		// check the ip is "0.0.0.0" or not
		for(var i = 0; i < ip.length; i++){
			if (ip[i] == "0"){
				count_zero++;			
			}				
		}

		if (!my_obj.allow_zero && count_zero == 4){	// if the ip is not allowed to be 0.0.0.0
			alert(my_obj.e_msg[ZERO_IP]);			// but we check the ip is 0.0.0.0
			return false;
		}else if (count_zero != 4){		// when IP is not 0.0.0.0, checking range. Otherwise no need to check				
			mask = mask_obj.addr;
			for(var i = 0; i < mask.length; i++){
				if (mask[i] != "255"){
					if (ip[i] != (mask[i] & ip[i])){
						alert("The " + get_seq(i) + " range of IP address must be " + (mask[i] & ip[i]) + ".");
						return false;
					}
				}
			}		
		}
	}else{	// if the length of ip is not correct, show invalid ip msg
		alert(my_obj.e_msg[INVALID_IP]);
		return false;
	}

	return true;
}

function check_mask(my_mask){
	var temp_mask = my_mask.addr;

	if (temp_mask.length == 4){
		for (var i = 0; i < temp_mask.length; i++){
			var which_ip = temp_mask[i].split(" ");
			var mask = parseInt(temp_mask[i]);
			var in_range = false;
			var j = 0;

			if (isNaN(which_ip) || which_ip == "" || which_ip.length > 1 || (which_ip[0].length > 1 && which_ip[0].substring(0,1) == "0")){	// if the address is invalid
				alert(my_mask.e_msg[FIRST_IP_ERROR + i]);
				return false;
			}

			if (i == 0){	// when it's 1st address
				j = 1;		// the 1st address can't be 0
			}

			for (; j < subnet_mask.length; j++){
				if (mask == subnet_mask[j]){
					in_range = true;
					break;
				}else{
					in_range = false;
				}
			}

			if (!in_range){
				alert(my_mask.e_msg[FIRST_RANGE_ERROR + i]);
				return false;
			}

			if (i != 0 && mask != 0){ // when not the 1st range and the value is not 0
				if (parseInt(temp_mask[i-1]) != 255){  // check the previous value is 255 or not
					alert(my_mask.e_msg[INVALID_IP]);
					return false;
				}
			}

			if (i == 3 && (parseInt(mask) == 254 || parseInt(mask) == 255)){	// when the last mask address is 254, 255
				alert(my_mask.e_msg[FOURTH_RANGE_ERROR]);
				return false;
			}
		}
	}else{
		alert(my_mask.e_msg[INVALID_IP]);
		return false;
	}

	return true;
}

function check_domain(ip, mask, gateway){
	var temp_ip = ip.addr;
	var temp_mask = mask.addr;
	var temp_gateway = gateway.addr;
	var temp_str = "";
	
	for (var i = 0; i < 4; i++){
		temp_str += temp_gateway[i];
		
		if (i < 3){
			temp_str += ".";
		}
	}
	
	if (gateway.allow_zero && (temp_str == "0.0.0.0" || temp_str == "...")){
		return true;
	}

	for (var i = 0; i < temp_ip.length - 1; i++){
		if ((temp_ip[i] & temp_mask[i]) != (temp_gateway[i] & temp_mask[i])){
			return false;		// when not in the same subnet mask, return false
		}
	}

	return true;
}

function check_ip_data(vpn_data){
	//vpn wan net, vpn wan mask
	var temp;
	var temp_data = vpn_data.split(",");	
	var temp_net_obj, temp_mask_obj, temp_mask;
	for (var i=0; i<temp_data.length; i++){
		temp = temp_data[i].split("/");
		temp_net_obj = new addr_obj(temp[0].split("."), ip_addr_msg, true, true);
		if ((temp.length % 2) == 0){
			temp_mask = temp[1].split(".");
			if ((temp_mask.length != 1) || (parseInt(temp[1]) < 1) 
					|| (parseInt(temp[1]) > 31)) {
				alert("The range of Subnet Mask must be between 1 to 31.");
				return false;
			}
			/*
			if ((temp_mask.length != 4) && ((1 > parseInt(temp[1])) || (parseInt(temp[1]) > 31))){
				alert("The range of Subnet Mask must be between 1 to 31.");
				return false;
			}else if((temp_mask.length == 1) && ((1 < parseInt(temp[1])) || (parseInt(temp[1]) < 31))){
				temp_mask_obj = new addr_obj(bit2netmask(temp[1]).split("."), subnet_mask_msg, true, true);
			}else if(temp_mask.length == 4){
				temp_mask_obj = new addr_obj(temp[1].split("."), subnet_mask_msg, true, true);
				if (!check_mask(temp_mask_obj)){
					return false;
				}
			}
			if (!check_network_address(temp_net_obj, temp_mask_obj)){
				return false;
			}
			*/
		}else{
			if (!check_address(temp_net_obj)){
				return false;
			}/*else{
				alert("Please enter a Subnet Mask.");
				return false;
			}*/
		}
	}
	return true;
	
}

function check_lan_setting(ip, mask, gateway){
	if (!check_mask(mask)){
		return false;   // when subnet mask is not in the subnet mask range
	}else if (!check_address(ip, mask)){
		return false;		// when ip is invalid
	}else if (!check_address(gateway, mask, ip)){
		return false;	// when gateway is invalid
	}else if (!check_domain(ip, mask, gateway)){		// check if the ip and the gateway are in the same subnet mask or not
		alert(msg[NOT_SAME_DOMAIN]);
		return false;
	}
	return true;
}

function check_radius(radius){
	
	if (!check_address(radius.ip)){
		return false;
	}else if (!check_port(radius.port)){
        alert("The RADIUS Server " + radius.number + " Port entered is invalid");
        return false;
    }else if (radius.secret == ""){
        alert("The RADIUS Server " + radius.number + " Shared Secret cannot be zero");
        return false;               
	}
	
	return true;
}

function check_duplicate(obj, rule_max){
	for(var i = 1; i <= rule_max; i++){
		if(get_by_id(obj + i).value != ""){
			for (var j = i+1; j <= rule_max; j++){
				if(i != j && get_by_id(obj + i).value == get_by_id(obj + j).value){
					return false;
				}
			}
		}
	}
	return true;
}

function check_pwd(pwd1, pwd2){
	if (get_by_id(pwd1).value != get_by_id(pwd2).value){
		 alert(msg[MATCH_PWD_ERROR]);
		 return false;
	}
	return true;
}

function check_ssid(id){
	if (get_by_id(id).value == ""){
	    alert(msg[SSID_EMPTY_ERROR]);
	    return false;
	}
	return true;        
}

function check_port(port){
    var temp_port = port.split(" ");
    
    if (isNaN(port) || port == "" || temp_port.length > 1 
    		|| (parseInt(port) < 1 || parseInt(port) > 65534)){
        return false;
    }
    return true;
}

function check_pf_port(port){
    var temp_port = port.split(" ");
    
    if (isNaN(port) || port == "" || temp_port.length > 1 
    		|| (parseInt(port) < 1 || parseInt(port) > 65535)){
        return false;
    }
    return true;
}

function change_color(table_name, row){
    var obj = get_by_id(table_name);
    for (var i = 1; i < obj.rows.length; i++){
        if (row == i){
            obj.rows[i].style.backgroundColor = "#FFFF00";
        }else{
            obj.rows[i].style.backgroundColor = "#FFFFFF";
        }
    }       
}

function change_multicolor(table_num, row){
		var obj;
    for (var i = 0; i < 3; i++){
	    obj = get_by_id("table" + i);
	    for (var j = 1; j < obj.rows.length; j++){
	        if (table_num == i && row == j){
	            obj.rows[j].style.backgroundColor = "#FFFF00";
	        }else{
	            obj.rows[j].style.backgroundColor = "#FFFFFF";
	        }
	    }
    }
    
}

function exit_wizard(){
    if (confirm(msg[QUIT_WIZARD])){
        window.close();
    }
}

function set_protocol(which_value, obj){
    for (var i = 0; i < 3; i++){    
        if (which_value == obj.options[i].value){
            obj.selectedIndex = i;
            break;
        }
    }
}

function set_schedule(data, index){ 
	var schd = get_by_name("schd");  
	
    if (data[index] == "0"){
        schd[0].checked = true;      
    }else{
        schd[1].checked = true;        
    }
    
    get_by_id("hour1").selectedIndex = data[index+1];
    get_by_id("min1").selectedIndex = data[index+2];
    get_by_id("am1").selectedIndex = data[index+3];
    get_by_id("hour2").selectedIndex = data[index+4];
    get_by_id("min2").selectedIndex = data[index+5];
    get_by_id("am2").selectedIndex = data[index+6];
    get_by_id("day1").selectedIndex = data[index+7];
    get_by_id("day2").selectedIndex = data[index+8];
}

function set_schedule_list(data, obj){
		
	for (var i = 0; i < obj.options.length; i++){
		if (data == obj.options[i].value){
			obj.selectedIndex = i;
			break;
		}
	}	
}

function get_schedule_idx(idx, count, temp){
		
	if(get_by_id("schedule" + idx).value != "Always"){
		for (var i = 0; i < get_by_id("schedule" + idx).options.length; i++){
			if (get_by_id("schedule" + idx).value == get_by_id("schedule" + idx).options[i].value){
				schedule_idx = parseInt(i)-1;
			}
		}	
	}else{
		schedule_idx = "Always"
	}
	temp.value += schedule_idx;

}

function set_schedule_option(){
	for (var i = 0; i < 24; i++){
		var temp_sch = get_by_id("schedule_rule" + i).value;
		var temp_data = temp_sch.split("/");	
		
		if (temp_data.length > 1){
			document.write("<option value='" + temp_data[0] + "'>" + temp_data[0] + "</option>");
		}else{
			break;
		}
	}
}

function set_schedule_option_2(){
	for (var i = 0; i < 24; i++){
		var temp_sch = get_by_id("schedule_rule" + i).value;
		var temp_data = temp_sch.split("/");	
		
		if (temp_data.length > 1){
			if (temp_data[0] == "Always")
				document.write("<option value='" + temp_data[0] + "'>" + temp_data[0] + "</option>");
			else
				document.write("<option value='" + i + "'>" + temp_data[0] + "</option>");
		}else{
			break;
		}
	}
}

function set_dhcp_list(){
	var temp_dhcp_list = get_by_id("dhcp_list").value.split(",");
	
	for (var i = 0; i < temp_dhcp_list.length; i++){	
		var temp_data = temp_dhcp_list[i].split("/");
		if(temp_data.length > 1){		
		document.write("<option value='" + temp_data[1] + "'>" + temp_data[0] + "</option>");	
		}
	}
}

function set_mac(mac){
	var temp_mac = mac.split(":");
	for (var i = 0; i < 6; i++){
		var obj = get_by_id("mac" + (i+1));
		obj.value = temp_mac[i];
	}
}

function get_row_data(obj, index){	
		
    try {
    	return obj.cells[index].childNodes[0].data;
    }catch(e) {
        return ("");
    }
}

function copy_application(index){
	var data;
	
	if (get_by_id("application" + index).selectedIndex > 0){
		data = default_rule[get_by_id("application" + index).selectedIndex - 1];		
		get_by_id("name" + index).value = data.name;
		get_by_id("public_port" + index).value = data.public_port;
		get_by_id("pubend_port" + index).value = "";
		get_by_id("private_port" + index).value = data.private_port;
		get_by_id("priend_port" + index).value = "";
		set_protocol(data.prot, get_by_id("protocol" + index));	
	}else{
		alert(msg[SELECT_APPLICATION_ERROR]);
	}		
}

function copy_special_appl(index){
	var name = get_by_id("name" + index);
	var trigger_port = get_by_id("trigger_port" + index);
	var trigger_type = get_by_id("trigger" + index);
	var public_port = get_by_id("public_port" + index);
	var public_type = get_by_id("public" + index);
	var application = get_by_id("application" + index);		
	var data;
	
	if (application.selectedIndex > 0){
		data = default_appl[application.selectedIndex - 1];
		name.value = data.name;		
		trigger_port.value = data.trigger_port;			
		public_port.value = data.public_port;				
		set_protocol(data.trigger_prot, trigger_type);   
		set_protocol(data.public_prot, public_type);    		
	}else{
		alert(msg[SELECT_APPLICATION_ERROR]);
	}
	
}

function copy_ip(index){

	if (get_by_id("ip_list" + index).selectedIndex > 0){
		get_by_id("ip" + index).value = get_by_id("ip_list" + index).options[get_by_id("ip_list" + index).selectedIndex].value;
	}else{
		alert(msg[SELECT_COMPUTER_ERROR]);
	}
}

function get_random_char(){
	var number_list = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var number = Math.round(Math.random()*62);
	
	return(number_list.substring(number, number + 1));
}

function generate_psk(key){
	var i = key.length;
	
	if (key.length < 8){
		for (; i < 8; i++){
			key += get_random_char();
		}
	}

	return key;
}

function create_wep_key128(passpharse, pharse_len){
    var pseed2 = "";
   	var md5_str = "";
   	var count;
   	
   	
    for(var i = 0; i < 64; i++){
        count = i % pharse_len;
        pseed2 += passpharse.substring(count, count+1);
    }
    
    md5_str = calcMD5(pseed2);   
    
    return md5_str.substring(0, 26).toUpperCase(); 
}

function Find_word(strOrg,strFind){
	var index = 0;
	index = strOrg.indexOf(strFind,index);
	if (index > -1){
		return true;
	}
	return false;
}

function check_legal_name(name){
	for(var i = 0; i < name_word.length; i++){
		if(Find_word(name, name_word[i]))
			return true;
	}
	return false;
}

function Add_zero(data){
	if(data < 10){
		data = "0"+ data;
	}
	return data;
}

function netmask2bit(mask){
	var ipstr = mask.split(".");
	var i, b, e = 0, bit = 0;

	for (i = 0; i < 4; i++) {
		for (b = 7;b >= 0; b--) {
			if ((ipstr[i] >> b) & 0x1) {
				if (e == 1)
					return -1; //illegal netmask
				bit++;
			} else
				e = 1;
		}
	}
	//alert("bit: " + bit);
	return bit;
}

function bit2netmask(bit){
	var i, c, b;
	ip = new Array(4);

	if (bit >= 32)
		return -1;
	for (i = 0; i < 4; i++) {
		for (c = 7, b = 0; c >= 0; c--){
			if (bit-- <= 0)
				break;
			b |= 1 << c;
		}
		ip[i] = b;
	}
	//alert("Netmask: " + ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3]);
	return ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3];
}

function ip2network(ip, mask){
	var temp_ip = ip.split(".");
	var temp_mask = mask.split(".");
	var temp_lan = (temp_ip[0] & temp_mask[0]);
	for (var i = 1; i < temp_ip.length; i++){
		temp_lan = temp_lan + "." + (temp_ip[i] & temp_mask[i]);
	}
	return temp_lan;
	
}

function ReplaceAll(strOrg,strFind,strReplace){
	var index = 0;
	while(strOrg.indexOf(strFind,index) != -1){
			strOrg = strOrg.replace(strFind,strReplace);
			index = strOrg.indexOf(strFind,index);
	}
	return strOrg;
} 

function check_schedule_rule(del_idx){
	var schedule_rule = (get_by_id("schedule_rule_list").value).split(",");
	var t = schedule_rule.length-1;
	for (var i=0; i<schedule_rule.length-1; i++){
		var rule = schedule_rule[i].split("=");
		if (rule[1] == del_idx){
			return false;
		}
	}
	return true;
}

/*Date Used, copy by Netgear*/
function getDaysInMonth(mon, year){
	var days;
	if (mon==1 || mon==3 || mon==5 || mon==7 || mon==8 || mon==10 || mon==12) 
		days=31;
	else if (mon==4 || mon==6 || mon==9 || mon==11) 
		days=30;
	else if (mon==2){
		if (isLeapYear(year)){
			 days=29;
		}else{
			 days=28; 
		}
	}
	return days;
}

function isLeapYear(Year){
	if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)){
		return true;
	}else{ 
		return false;
	}
}
