function initialElementState()
{
	Check_Primary_Vlan_Tag();

  for(var i=1; i<4; i++)
  {
  	Check_Secondary_State(i);
  	//Change_Authentication(i);
  	Change_Key_Type_Or_Size(i);
  }
  //for(var j=1; j<4; j++) Change_Key_Type_Or_Size(j);
}

function Check_Primary_Vlan_Tag(arg)
{
	if (VlanState != null && VlanState.checked == true)
	{
		// change 11a or 11g vlan tag
		if(arg != undefined)
		{
			if (VLanID_11a[0] != null) VLanID_11a[0].value = arg;
			if (VLanID_11g[0] != null) VLanID_11g[0].value = arg;
		}
	  else //check vlan state
		{
			if (VLanID_11a[0] != null && VLanID_11g[0] != null)
			  VLanID_11a[0].value = VLanID_11g[0].value;

			for(i=0; i<4; i++)
			{
				if (VLanID_11a[i] != null) VLanID_11a[i].disabled = false;
				if (VLanID_11g[i] != null) VLanID_11g[i].disabled = false;
			}
		}
	}
  else if (VlanState != null && VlanState.checked == false)
  {
  	for(i=0; i<4; i++)
		{
			if (VLanID_11a[i] != null) VLanID_11a[i].disabled = true;
			if (VLanID_11g[i] != null) VLanID_11g[i].disabled = true;
		}
  }
}

function Change_Authentication(idx)
{
	// 11a
	if (Security_11a[idx] != null)
  {
  	if (SecondState_11a[idx] != null && SecondState_11a[idx].checked == false)
  	{
  		if (KeyType_11a[idx] != null)  KeyType_11a[idx].disabled = true;
      if (KeySize_11a[idx] != null)  KeySize_11a[idx].disabled = true;
	    if (KeyIndex_11a[idx] != null) KeyIndex_11a[idx].disabled = true;
	    if (KeySet_11a[idx] != null)   KeySet_11a[idx].disabled = true;
	  }
	  else
		{
  	  if (Security_11a[idx].selectedIndex == 0) // none security
	    {
	      if (KeyType_11a[idx] != null)  KeyType_11a[idx].disabled = true;
        if (KeySize_11a[idx] != null)  KeySize_11a[idx].disabled = true;
	      if (KeyIndex_11a[idx] != null) KeyIndex_11a[idx].disabled = true;
	      if (KeySet_11a[idx] != null)   KeySet_11a[idx].disabled = true;
	    }
	    else
	    {
		    if (KeyType_11a[idx] != null)  KeyType_11a[idx].disabled = false;
  	    if (KeySize_11a[idx] != null)  KeySize_11a[idx].disabled = false;
	      if (KeyIndex_11a[idx] != null) KeyIndex_11a[idx].disabled = false;
	      if (KeySet_11a[idx] != null)   KeySet_11a[idx].disabled = false;
	    }
	  }
	}

  // 11g
  if (Security_11g[idx] != null)
  {
  	if (SecondState_11g[idx] != null && SecondState_11g[idx].checked == false)
  	{
  		if (KeyType_11g[idx] != null)  KeyType_11g[idx].disabled = true;
      if (KeySize_11g[idx] != null)  KeySize_11g[idx].disabled = true;
	    if (KeyIndex_11g[idx] != null) KeyIndex_11g[idx].disabled = true;
	    if (KeySet_11g[idx] != null)   KeySet_11g[idx].disabled = true;
    }
    else
  	{
  		if (Security_11g[idx].selectedIndex == 0) // none security
	    {
	      if (KeyType_11g[idx] != null)  KeyType_11g[idx].disabled = true;
        if (KeySize_11g[idx] != null)  KeySize_11g[idx].disabled = true;
	      if (KeyIndex_11g[idx] != null) KeyIndex_11g[idx].disabled = true;
	      if (KeySet_11g[idx] != null)   KeySet_11g[idx].disabled = true;
	    }
      else
	    {
		    if (KeyType_11g[idx] != null)  KeyType_11g[idx].disabled = false;
  	    if (KeySize_11g[idx] != null)  KeySize_11g[idx].disabled = false;
	      if (KeyIndex_11g[idx] != null) KeyIndex_11g[idx].disabled = false;
	      if (KeySet_11g[idx] != null)   KeySet_11g[idx].disabled = false;
	    }
	  }
	}
}

function Check_Secondary_State(idx)
{
	// check 11a
	if(SecondState_11a[idx] != null)
	{
		if(SecondState_11a[idx].checked == false)
  	{
  		if (MSSID_11a[idx] != null)    MSSID_11a[idx].disabled = true;
  		if (Security_11a[idx] != null) Security_11a[idx].disabled = true;
  		//if (KeyType_11a[idx] != null)  KeyType_11a[idx].disabled = true;
      //if (KeySize_11a[idx] != null)  KeySize_11a[idx].disabled = true;
	    //if (KeyIndex_11a[idx] != null) KeyIndex_11a[idx].disabled = true;
	    //if (KeySet_11a[idx] != null)   KeySet_11a[idx].disabled = true;
    }
    else
  	{
  		if (MSSID_11a[idx] != null)    MSSID_11a[idx].disabled = false;
  		/* When primary ssid has authentication wpa-eap or wpa-psk,
         the secondary ssid must change authentication to none. */
  		if(Security_11a[0] != null && Security_11a[0].selectedIndex >= 3)
  		{
  			if (Security_11a[idx] != null) Security_11a[idx].selectedIndex = 0;
  			if (Security_11a[idx] != null) Security_11a[idx].disabled = true;
  			//if (KeyType_11a[idx] != null)  KeyType_11a[idx].disabled = true;
        //if (KeySize_11a[idx] != null)  KeySize_11a[idx].disabled = true;
	      //if (KeyIndex_11a[idx] != null) KeyIndex_11a[idx].disabled = true;
	      //if (KeySet_11a[idx] != null)   KeySet_11a[idx].disabled = true;
  	  }
  	  else if (Security_11a[0] != null && Security_11a[0].selectedIndex < 3)
  	  {
  	  	if (Security_11a[idx] != null)
  	  	{
  	  		Security_11a[idx].disabled = false;
  	  		/*
  	  		if (Security_11a[idx].selectedIndex == 0) // none security
	        {
	          if (KeyType_11a[idx] != null)  KeyType_11a[idx].disabled = true;
            if (KeySize_11a[idx] != null)  KeySize_11a[idx].disabled = true;
	          if (KeyIndex_11a[idx] != null) KeyIndex_11a[idx].disabled = true;
	          if (KeySet_11a[idx] != null)   KeySet_11a[idx].disabled = true;
	        }
	        else
	        {
		        if (KeyType_11a[idx] != null)  KeyType_11a[idx].disabled = false;
  	        if (KeySize_11a[idx] != null)  KeySize_11a[idx].disabled = false;
	          if (KeyIndex_11a[idx] != null) KeyIndex_11a[idx].disabled = false;
	          if (KeySet_11a[idx] != null)   KeySet_11a[idx].disabled = false;
	        }*/
  	  	}
  	  }
  	}
  }

  // check 11g
  if(SecondState_11g[idx] != null)
	{
		if(SecondState_11g[idx].checked == false)
  	{
  		if (MSSID_11g[idx] != null)    MSSID_11g[idx].disabled = true;
  		if (Security_11g[idx] != null) Security_11g[idx].disabled = true;
  		//if (KeyType_11g[idx] != null)  KeyType_11g[idx].disabled = true;
      //if (KeySize_11g[idx] != null)  KeySize_11g[idx].disabled = true;
	    //if (KeyIndex_11g[idx] != null) KeyIndex_11g[idx].disabled = true;
	    //if (KeySet_11g[idx] != null)   KeySet_11g[idx].disabled = true;
    }
    else
  	{
  		if (MSSID_11g[idx] != null)    MSSID_11g[idx].disabled = false;
  		/* When primary ssid has authentication wpa-eap or wpa-psk,
         the secondary ssid must change authentication to none. */
      if (Security_11g[0] != null && Security_11g[0].selectedIndex >= 3)
      {
      	if (Security_11g[idx] != null) Security_11g[idx].selectedIndex = 0;
      	if (Security_11g[idx] != null) Security_11g[idx].disabled = true;
      	//if (KeyType_11g[idx] != null)  KeyType_11g[idx].disabled = true;
        //if (KeySize_11g[idx] != null)  KeySize_11g[idx].disabled = true;
	      //if (KeyIndex_11g[idx] != null) KeyIndex_11g[idx].disabled = true;
	      //if (KeySet_11g[idx] != null)   KeySet_11g[idx].disabled = true;
      }
      else if (Security_11g[0] != null && Security_11g[0].selectedIndex < 3)
      {
  		  if (Security_11g[idx] != null)
  		  {
  		  	Security_11g[idx].disabled = false;
  		  	/*
  		  	if (Security_11g[idx].selectedIndex == 0) // none security
	        {
	          if (KeyType_11g[idx] != null)  KeyType_11g[idx].disabled = true;
            if (KeySize_11g[idx] != null)  KeySize_11g[idx].disabled = true;
	          if (KeyIndex_11g[idx] != null) KeyIndex_11g[idx].disabled = true;
	          if (KeySet_11g[idx] != null)   KeySet_11g[idx].disabled = true;
	        }
          else
	        {
		        if (KeyType_11g[idx] != null)  KeyType_11g[idx].disabled = false;
  	        if (KeySize_11g[idx] != null)  KeySize_11g[idx].disabled = false;
	          if (KeyIndex_11g[idx] != null) KeyIndex_11g[idx].disabled = false;
	          if (KeySet_11g[idx] != null)   KeySet_11g[idx].disabled = false;
	        }*/
  		  }
  		}
  	}
  }
  Change_Authentication(idx);
}

function Change_Key_Type_Or_Size(idx)
{
	// 11a
	if (KeyType_11a[idx] != null)
	{
		if (KeyType_11a[idx].selectedIndex == 0) // Hex
	  {
		  if (KeySize_11a[idx] != null)
		  {
		  	if (KeySize_11a[idx].selectedIndex == 0) //64 bits
		    {
		      if (KeySet_11a[idx] != null)
		      {
		    	  KeySet_11a[idx].maxLength = 10;
		    	  //KeySet_11a[idx].value = "**********";
		    	  //KeySet_11a[idx].select();
		      }
		    }
		    else if (KeySize_11a[idx].selectedIndex == 1) //128 bits
		    {
		      if (KeySet_11a[idx] != null)
		      {
		      	KeySet_11a[idx].maxLength = 26;
		      	//KeySet_11a[idx].value = "**************************";
		      	//KeySet_11a[idx].select();
		      }
		    }
		    else if (KeySize_11a[idx].selectedIndex == 2) //152 bits
		    {
		      if (KeySet_11a[idx] != null)
		      {
		      	KeySet_11a[idx].maxLength = 32;
		      	//KeySet_11a[idx].value = "********************************";
		      	//KeySet_11a[idx].select();
		      }
		    }
	    }
	  }
	  else // ASCII
	  {
		  if (KeySize_11a[idx] != null)
		  {
		  	if (KeySize_11a[idx].selectedIndex == 0) //64 bits
		    {
		      if (KeySet_11a[idx] != null)
		      {
		      	KeySet_11a[idx].maxLength = 5;
		      	//KeySet_11a[idx].value = "";
		      	//KeySet_11a[idx].focus();
		      }
		    }
		    else if (KeySize_11a[idx].selectedIndex == 1) //128 bits
		    {
		      if (KeySet_11a[idx] != null)
		      {
		      	KeySet_11a[idx].maxLength = 13;
		      	//KeySet_11a[idx].value = "";
		      	//KeySet_11a[idx].focus();
		      }
		    }
		    else if (KeySize_11a[idx].selectedIndex == 2) //152 bits
		    {
		      if (KeySet_11a[idx] != null)
		      {
		       	KeySet_11a[idx].maxLength = 16;
		      	//KeySet_11a[idx].value = "";
		      	//KeySet_11a[idx].focus();
		      }
		    }
		  }
	  }
	}

	// 11g
	if (KeyType_11g[idx] != null)
	{
		if(KeyType_11g[idx].selectedIndex == 0) // Hex
	  {
		  if (KeySize_11g[idx] != null)
		  {
		  	if (KeySize_11g[idx].selectedIndex == 0) //64 bits
		    {
		      if (KeySet_11g[idx] != null)
		      {
		  	    KeySet_11g[idx].maxLength = 10;
		  	    //KeySet_11g[idx].value = "**********";
		  	    //KeySet_11g[idx].select();
		      }
		    }
		    else if (KeySize_11g[idx].selectedIndex == 1) //128 bits
		    {
		      if (KeySet_11g[idx] != null)
		      {
		  	    KeySet_11g[idx].maxLength = 26;
		  	    //KeySet_11g[idx].value = "**************************";
		  	    //KeySet_11g[idx].select();
		      }
		    }
		    else if (KeySize_11g[idx].selectedIndex == 2) //152 bits
		    {
		      if (KeySet_11g[idx] != null)
		      {
		  	    KeySet_11g[idx].maxLength = 32;
		  	    //KeySet_11g[idx].value = "********************************";
		  	    //KeySet_11g[idx].select();
		      }
		    }
	    }
	  }
	  else // ASCII
	  {
		  if (KeySize_11g[idx] != null)
		  {
		  	if (KeySize_11g[idx].selectedIndex == 0) //64 bits
		    {
		      if (KeySet_11g[idx] != null)
		      {
		  	    KeySet_11g[idx].maxLength = 5;
		  	    //KeySet_11g[idx].value = "";
		  	    //KeySet_11g[idx].focus();
		      }
		    }
		    else if (KeySize_11g[idx].selectedIndex == 1) //128 bits
		    {
		      if (KeySet_11g[idx] != null)
		      {
		  	    KeySet_11g[idx].maxLength = 13;
		  	    //KeySet_11g[idx].value = "";
		  	    //KeySet_11g[idx].focus();
		      }
		    }
		    else if (KeySize_11g[idx].selectedIndex == 2) //152 bits
		    {
		      if (KeySet_11g[idx] != null)
		      {
		  	    KeySet_11g[idx].maxLength = 16;
		  	    //KeySet_11g[idx].value = "";
		  	    //KeySet_11g[idx].focus();
		      }
		    }
	    }
    }
  }
}

function Check_Vlan_Tag()
{
	for(i=0; i<4; i++)
  {
  	if (VLanID_11a[i] != null)
  	{
  		if (isNaN(VLanID_11a[i].value) || VLanID_11a[i].value < 1 || VLanID_11a[i].value > 4095)
  	  {
  	  	if (i == 0) alert("The 11a Master SSID's ID is invalid.\n The range of ID is 1 to 4095.");
  	    else alert("The 11a Guest SSID"+i+"'s ID is invalid.\n The range of ID is 1 to 4095.");
  	    return false;
  	  }
  	}

  	if (VLanID_11g[i] != null)
  	{
  		if (isNaN(VLanID_11g[i].value) || VLanID_11g[i].value < 1 || VLanID_11g[i].value > 4095)
  	  {
  	  	if (i == 0) alert("The 11g Master SSID's ID is invalid.\n The range of ID is 1 to 4095.");
  	    else alert("The 11g Guest SSID"+i+"'s ID is invalid.\n The range of ID is 1 to 4095.");
  	    return false;
  	  }
  	}
  }
  return true;
}

function Change_Key_Index(band,idx)
{
	var pki = 0;
  var ski = 0;

	if (band == 0) // 11a
	{
		pki = KeyIndex_11a[0];
		ski = parseFloat(KeyIndex_11a[idx].options[KeyIndex_11a[idx].selectedIndex].text);

    if (Security_11a[0].selectedIndex > 0)
    {
    	if (SecondState_11a[idx].checked == true && Security_11a[idx].selectedIndex > 0)
		  if (ski == pki)
		  {
		    alert("The 11a Guest SSID"+idx+"'s key index is same as Master SSID.");
		    return false;
		  }
		}

		for(i=1; i<4; i++)
		{
			if (i != idx)
			{
				if (SecondState_11a[idx].checked == true && Security_11a[idx].selectedIndex > 0)
				if (SecondState_11a[i].checked == true && Security_11a[i].selectedIndex > 0)
				{
				  if (ski == parseFloat(KeyIndex_11a[i].options[KeyIndex_11a[i].selectedIndex].text))
				  {
				    alert("The 11a Guest SSID"+idx+"'s key index is same as Guest SSID"+i+".");
				    return false;
				  }
				}
			}
		}
		return true;
	}
  else // 11g
	{
		pki = KeyIndex_11g[0];
		ski = parseFloat(KeyIndex_11g[idx].options[KeyIndex_11g[idx].selectedIndex].text);

    if (Security_11g[0].selectedIndex > 0)
    {
    	if (SecondState_11g[idx].checked == true && Security_11g[idx].selectedIndex > 0)
		  if (ski == pki)
		  {
		    alert("The 11g Guest SSID"+idx+"'s key index is same as Master SSID.");
		    return false;
		  }
		}

		for(i=1; i<4; i++)
		{
			if (i != idx)
			{
				if (SecondState_11g[idx].checked == true && Security_11g[idx].selectedIndex > 0)
				if (SecondState_11g[i].checked == true && Security_11g[i].selectedIndex > 0)
				{
				  if (ski == parseFloat(KeyIndex_11g[i].options[KeyIndex_11g[i].selectedIndex].text))
				  {
				    alert("The 11g Guest SSID"+idx+"'s key index is same as Guest SSID"+i+".");
				    return false;
				  }
				}
			}
		}
		return true;
	}
}

function Check_SSID(band,idx)
{
	var i = 1;
	var ssid = "";

	if (band == 0)
	{
		for(i=1; i<4; i++)
		{
			ssid = MSSID_11a[i];
      if(ssid != null)
	    {
		    if(ssid.value == "")
		    {
			    alert("Please input SSID in 11a Guest SSID"+i+".");
			    //ssid.value="";
			    //ssid.focus();
			    return false;
		    }

		    if(ssid.value != "")
  	    {
  		    if(ssid.value.indexOf(" ") == 0)
  	      {
  	  	    alert("The first character can't be blank in 11a Guest SSID"+i+".");
  	  	    //ssid.value = "";
  	  	    //ssid.focus();
  	  	    return false;
  	      }
  	    }
  	  }
		}

		if (SecondState_11a[idx].checked == true)
		{
		  if (MSSID_11a[idx].value == MSSID_11a[0].value)
		  {
		  	alert("The 11a Guest SSID"+idx+"'s SSID is same as Master SSID.");
		  	return false;
		  }

		  for(i=1; i<4; i++)
		  {
		  	if (SecondState_11a[i].checked == true)
		  	{
		  		if (i != idx)
		  		{
		  			if (MSSID_11a[idx].value == MSSID_11a[i].value)
		  			{
		  				alert("The 11a Guest SSID"+idx+"'s SSID is same as Guest SSID"+i+".");
		  				return false;
		  			}
		  		}
		  	}
		  }
		  return true;
	  }
	  else
	  	return true;
	}
  else
	{
		for(i=1; i<4; i++)
		{
			ssid = MSSID_11g[i];
      if(ssid != null)
	    {
		    if(ssid.value == "")
		    {
			    alert("Please input SSID in 11g Guest SSID"+i+".");
			    //ssid.value="";
			    //ssid.focus();
			    return false;
		    }

		    if(ssid.value != "")
  	    {
  		    if(ssid.value.indexOf(" ") == 0)
  	      {
  	  	    alert("The first character can't be blank in 11g Guest SSID"+i+".");
  	  	    //ssid.value = "";
  	  	    //ssid.focus();
  	  	    return false;
  	      }
  	    }
  	  }
		}

		if (SecondState_11g[idx].checked == true)
		{
		  if (MSSID_11g[idx].value == MSSID_11g[0].value)
		  {
		  	alert("The 11g Guest SSID"+idx+"'s SSID is same as Master SSID.");
		  	return false;
		  }

		  for(i=1; i<4; i++)
		  {
		  	if (SecondState_11g[i].checked == true)
		  	{
		  		if (i != idx)
		  		{
		  			if (MSSID_11g[idx].value == MSSID_11g[i].value)
		  			{
		  				alert("The 11g Guest SSID"+idx+"'s SSID is same as Guest SSID"+i+".");
		  				return false;
		  			}
		  		}
		  	}
		  }
		  return true;
	  }
	  else
	  	return true;
	}
}

function Check_Key(band,idx)
{
	var field = "";
	var key = "";

	if (band == 0)
	{
		field = KeySet_11a[idx];
	  key = field.value;
		if (SecondState_11a[idx].checked == true && Security_11a[idx].selectedIndex > 0)
		{
			if (KeyType_11a[idx].selectedIndex == 0) // Hex
			{
				switch(KeySize_11a[idx].selectedIndex)
				{
					case 0: // 64 bits
					  if (key.length != 10)
					  {
					  	alert("Please input 10 Hexadecimal digits in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!HexCheck2(key))
					  	{
                alert("Please input hexadecimal digits in Guest SSID"+idx+"!");
                field.value = "";
                return false;
					  	}
					  }
					  break;
					case 1: // 128 bits
					  if (key.length != 26)
					  {
					  	alert("Please input 26 Hexadecimal digits in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!HexCheck2(key))
					  	{
                alert("Please input hexadecimal digits in Guest SSID"+idx+"!");
                field.value = "";
                return false;
				  	}
					  }
					  break;
					case 2: // 152 bits
					  if (key.length != 32)
					  {
					  	alert("Please input 32 Hexadecimal digits in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!HexCheck2(key))
					  	{
                alert("Please input hexadecimal digits in Guest SSID"+idx+"!");
                field.value = "";
                return false;
					  	}
					  }
					  break;
				}
				return true;
			}
		  else // ASCII
			{
				switch(KeySize_11a[idx].selectedIndex)
				{
					case 0: // 64 bits
					  if (key.length != 5)
					  {
					  	alert("Please input 5 characters in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!ASCIICheck(key))
					  	{
                alert("The key has invalid character in Guest SSID"+idx+".\nPlease input again!");
                field.value = "";
                return false;
					  	}
					    else
					  	  field.value = ASCIIToHex(key);
					  }
					  break;
					case 1: // 128 bits
					  if (key.length != 13)
					  {
					  	alert("Please input 13 characters in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!ASCIICheck(key))
					  	{
                alert("The key has invalid character in Guest SSID"+idx+".\nPlease input again!");
                field.value = "";
                return false;
				  	  }
				  	  else
				  		  field.value = ASCIIToHex(key);
					  }
					  break;
					case 2: // 152 bits
					  if (key.length != 16)
					  {
					  	alert("Please input 16 characters in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!ASCIICheck(key))
					  	{
                alert("The key has invalid character in Guest SSID"+idx+".\nPlease input again!");
                field.value = "";
                return false;
					  	}
					    else
					    	field.value = ASCIIToHex(key);
					  }
					  break;
				}
				return true;
			}
		}
	  else
		  return true;
	}
  else
	{
		field = KeySet_11g[idx];
	  key = field.value;
		if (SecondState_11g[idx].checked == true && Security_11g[idx].selectedIndex > 0)
		{
			if (KeyType_11g[idx].selectedIndex == 0) // Hex
			{
				switch(KeySize_11g[idx].selectedIndex)
				{
					case 0: // 64 bits
					  if (key.length != 10)
					  {
					  	alert("Please input 10 Hexadecimal digits in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!HexCheck2(key))
					  	{
                alert("Please input hexadecimal digits in Guest SSID"+idx+"!");
                field.value = "";
                return false;
					  	}
					  }
					  break;
					case 1: // 128 bits
					  if (key.length != 26)
					  {
					  	alert("Please input 26 Hexadecimal digits in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!HexCheck2(key))
					  	{
                alert("Please input hexadecimal digits in Guest SSID"+idx+"!");
                field.value = "";
                return false;
				  	}
					  }
					  break;
					case 2: // 152 bits
					  if (key.length != 32)
					  {
					  	alert("Please input 32 Hexadecimal digits in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!HexCheck2(key))
					  	{
                alert("Please input hexadecimal digits in Guest SSID"+idx+"!");
                field.value = "";
                return false;
					  	}
					  }
					  break;
				}
				return true;
			}
		  else // ASCII
			{
				switch(KeySize_11g[idx].selectedIndex)
				{
					case 0: // 64 bits
					  if (key.length != 5)
					  {
					  	alert("Please input 5 characters in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!ASCIICheck(key))
					  	{
                alert("The key has invalid character in Guest SSID"+idx+".\nPlease input again!");
                field.value = "";
                return false;
					  	}
					    else
					  	  field.value = ASCIIToHex(key);
					  }
					  break;
					case 1: // 128 bits
					  if (key.length != 13)
					  {
					  	alert("Please input 13 characters in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!ASCIICheck(key))
					  	{
                alert("The key has invalid character in Guest SSID"+idx+".\nPlease input again!");
                field.value = "";
                return false;
				  	  }
				  	  else
				  		  field.value = ASCIIToHex(key);
					  }
					  break;
					case 2: // 152 bits
					  if (key.length != 16)
					  {
					  	alert("Please input 16 characters in Guest SSID"+idx+"!");
					  	field.value = "";
					  	return false;
					  }
					  else
					  {
					  	if(!ASCIICheck(key))
					  	{
                alert("The key has invalid character in Guest SSID"+idx+".\nPlease input again!");
                field.value = "";
                return false;
					  	}
					    else
					    	field.value = ASCIIToHex(key);
				  }
					  break;
				}
				return true;
			}
		}
	  else
		  return true;
	}
}

function MSSID_Submit()
{
	var k = 1;
	var invalid = 0;

  if(Check_Vlan_Tag())
  {
  	for(k=1; k<4; k++)
  	{
  		if (MSSID_11A_DISPLAY){if (!Check_SSID(0,k)) {invalid = 1; break;}}
  		if (MSSID_11G_DISPLAY){if (!Check_SSID(1,k)) {invalid = 1; break;}}
  		if (MSSID_11A_DISPLAY){if (!Change_Key_Index(0,k)) {invalid = 1; break;}}
  		if (MSSID_11G_DISPLAY){if (!Change_Key_Index(1,k)) {invalid = 1; break;}}
  		if (MSSID_11A_DISPLAY){if (!Check_Key(0,k)) {invalid = 1; break;}}
  		if (MSSID_11G_DISPLAY){if (!Check_Key(1,k)) {invalid = 1; break;}}
  	}

  	if (!invalid)
  	{
  		MSSID_11g[0].disabled = false;
     // document.forms[0].submit();
    }
  }
}
var Display_Multiple_SSID = parseInt("1");
var aidx = "0*0*0*";
var gidx = "0*0*0*";
aidx = aidx.substring(0,5).split("*");
gidx = gidx.substring(0,5).split("*");
// idx : start from 1.
function Primary_SSID_Check_Key_Index(band,idx)
{
	if (band == 0)
  {
    for(var i=0; i<3; i++)
    {
    	if(idx == aidx[i])
    	{
    		alert("The Master SSID's key index is same as 11a Guest SSID"+(i+1)+".");
    		return false;
    	}
    }
    return true;
  }
  else
	{
		for(var i=0; i<3; i++)
    {
    	if(idx == gidx[i])
    	{
    		alert("The Master SSID's key index is same as 11g Guest SSID"+(i+1)+".");
    		return false;
    	}
    }
    return true;
	}
}
