var mssid_11a = new Array(9)
var mssid_11g = new Array(9)
var MSSID_MAX_NUM = parseInt("7");
var Master_Auth_Level_11a = parseInt("0");
var Master_Auth_Level_11g = parseInt("1");
var APMode_State = parseInt("1");
var SuperMode_State= parseInt("0");
var Auth_Switch= parseInt("0");
/* Following value is for checking whether Keys, Radius Server Settings or Group Key Update Interval have been changed or not. */
var Check_MSSID_Auth_State= parseInt("0");
var MSSIDAuthList   = new Array("None","Open System","Shared Key","Both",
                 "WPA-Enterprise","WPA-Personal","WPA2-Enterprise","WPA2-Personal","WPA-Auto-Enterprise","WPA-Auto-Personal", "802.1x");

function initialElementState()
{
	AdjustMSSIDHeight();
    /*{ mark by John 2005.10.13 for Firefox checkbox bug --start-- */
    /*If SecondSSIDState checked and gray, reload page will un-checked */
    if(VLAN != null)
    {
        if(VLAN.checked == true)
            SecondSSIDState.checked = true;
    }
    /*} mark by John 2005.10.13 -- end -- */     
    Check_Original_Values(Check_MSSID_Auth_State);
    Check_Secondary_State();
    Change_Key_Type_Or_Size();
    MS_Band.disabled=true;
}

function AdjustMSSIDHeight()
{
	var PageHeight = new Array(595, 650, 705);
	if(navigator.appName =="Microsoft Internet Explorer")
	{
		for(var i=0; i<3; i++)
			PageHeight[i] = PageHeight[i]-30;
	}
	
	if(Security.options[Security.selectedIndex].text == MSSIDAuthList[0] || Security.options[Security.selectedIndex].text == MSSIDAuthList[1] || Security.options[Security.selectedIndex].text == MSSIDAuthList[2] || Security.options[Security.selectedIndex].text == MSSIDAuthList[3])
		parent.ifrMain.height =PageHeight[0];
	else if(Security.options[Security.selectedIndex].text == MSSIDAuthList[5] || Security.options[Security.selectedIndex].text == MSSIDAuthList[7] || Security.options[Security.selectedIndex].text == MSSIDAuthList[9])
		parent.ifrMain.height =PageHeight[0];
	else if(Security.options[Security.selectedIndex].text == MSSIDAuthList[4] || Security.options[Security.selectedIndex].text == MSSIDAuthList[6] || Security.options[Security.selectedIndex].text == MSSIDAuthList[8])
		parent.ifrMain.height =PageHeight[1];
	else
		parent.ifrMain.height =PageHeight[2];
}

function Check_Secondary_State()
{
	if(SecondSSIDState != null)
	{
        if(SecondSSIDState.checked == false)
        {
            if (Band_Both != null)
                Band_Both.disabled = true;
            if (Band_11a != null)
                Band_11a.disabled = true;
            if (Band_11g != null)
                Band_11g.disabled = true;
            if (MS_Band != null)
                MS_Band.disabled = true;
            if (MS_MSSIDIdx != null)
                MS_MSSIDIdx.disabled = true;
            if (MSSID != null)
                MSSID.disabled = true;
            if (MSSIDBroadcast != null)
                MSSIDBroadcast.disabled = true;
            if (Security != null)
                Security.disabled = true;
            if (KeyType != null)
                KeyType.disabled = true;
            if (KeySize != null)
                KeySize.disabled = true;
            if (KeyIndex != null)
                KeyIndex.disabled = true;
            if (KeySet != null)
                KeySet.disabled = true;
            if (Cipher != null)
                Cipher.disabled = true;
            if (GKUI != null)
                GKUI.disabled = true;
            if (RadiusServer != null)
                RadiusServer.disabled = true;
            if (RadiusPort != null)
                RadiusPort.disabled = true;
            if (RadiusSecret != null)
                RadiusSecret.disabled = true;
            if (PassPhrase != null)
                PassPhrase.disabled = true;  
            if (SubmitSSID != null)
                SubmitSSID.disabled = true;
       }
       else
       {
            if (Band_Both != null)
                Band_Both.disabled = false;
            if (Band_11a != null)
                Band_11a.disabled = false;
            if (Band_11g != null)
                Band_11g.disabled = false;
            
            if (MS_Band != null)
            {
                if(Band_11a != null || Band_11g != null)
                {
                    if(Band_11a.checked==true || Band_11g.checked==true)
                        MS_Band.disabled = true;
                }
                else
                    MS_Band.disabled = false;
            }
            if (MS_MSSIDIdx != null)
                MS_MSSIDIdx.disabled = false;      
            if (MS_MSSIDIdx.selectedIndex==0)
            {            
                if (MSSID != null)
                    MSSID.disabled = true;
                if (MSSIDBroadcast != null)
                    MSSIDBroadcast.disabled = true;
                if (Security != null)
                    Security.disabled = true;
                if (KeyType != null)
                    KeyType.disabled = true;
                if (KeySize != null)
                    KeySize.disabled = true;
                if (KeyIndex != null)
                    KeyIndex.disabled = true;
                if (KeySet != null)
                    KeySet.disabled = true;
                
                if (Cipher != null)
                    Cipher.disabled = true;
                if (GKUI != null)
                    GKUI.disabled = true;
            
                if (RadiusServer != null)
                    RadiusServer.disabled = true;
                if (RadiusPort != null)
                    RadiusPort.disabled = true;
                if (RadiusSecret != null)
                    RadiusSecret.disabled = true;
            
                if (PassPhrase != null)
                    PassPhrase.disabled = true;                
            }
            else
            {
                if (MSSID != null)
                    MSSID.disabled = false;
                if (MSSIDBroadcast != null)
                    MSSIDBroadcast.disabled = false;
                if (Security != null)
                {
                  /*  if((MS_Band.selectedIndex==0 && Master_Auth_Level_11a >= 4) || (MS_Band.selectedIndex==1 && Master_Auth_Level_11g >= 4))
                    {
                        Security.selectedIndex = 0;
                        Security.disabled = true;
                    }
                    else*/
                    Security.disabled = false;
                    Change_Authentication();
                }
            }
            if (SubmitSSID != null)
                SubmitSSID.disabled = false;
        }
        
    }

    if(VLAN != null)
    {
        if(VLAN.checked == false)
        {
            if (VLanID != null)
                VLanID.disabled = true;
        }
        else
        {
            if(SecondSSIDState != null && SecondSSIDState.checked == true)
	            SecondSSIDState.disabled = true;
            if (VLanID != null)
                VLanID.disabled = false;
            if (SubmitSSID != null)
                SubmitSSID.disabled = false;
            if (Band_11a != null)
                Band_11a.disabled = true;
            if (Band_11g != null)
                Band_11g.disabled = true;
        }
    }
    
/* close a band for only 11g device */
 //   if (MS_Band != null)
 //       MS_Band.disabled = true;
}

function VLAN_State()
{
    if(VLAN.checked == true)
        return 1;
    else
        return 0;
}

function MSSID_Display()
{
    if(SecondSSIDState.checked == true)
    {
        if(APMode_State!=0 && SuperMode_State!=0)
            alert("If you enable Multi-SSID, \nSuper Mode will be disabled and WDS Mode will be set to AP Mode!");
        else if(APMode_State!=0)
            alert("If you enable Multi-SSID, \nWDS Mode will be set to AP Mode!");
        else if(SuperMode_State!=0)
            alert("If you enable Multi-SSID, \nSuper Mode will be disabled!");
    }
    
    VLAN_Index=VLAN_State();
    
    /* 0: decide by get-value;    1: close;    2: both open;    3: 11a open    4: 11g open;*/
    if(SecondSSIDState.checked == false)
        location.href = "aMSSIDSetting.htm?" + MS_Band.selectedIndex +","+ MS_MSSIDIdx.selectedIndex +",1," + VLAN_Index;
    else
        location.href = "aMSSIDSetting.htm?" + MS_Band.selectedIndex +","+ MS_MSSIDIdx.selectedIndex +",4," + VLAN_Index;
}

function Change_VLAN()
{
    VLAN_Index=VLAN_State();
    if(SecondSSIDState.checked == true)
    {
        if(VLAN.checked == false)
        {
            SecondSSIDState.disabled = false;
            if (VLanID != null)
                VLanID.disabled = true;
            if (Band_11a != null)
                Band_11a.disabled = false;
            if (Band_11g != null)
                Band_11g.disabled = false;
        }
        else
        {
//            SecondSSIDState.disabled = true;         
//            if (VLanID != null)
//                VLanID.disabled = false;
            location.href = "aMSSIDSetting.htm?" + MS_Band.selectedIndex +","+ MS_MSSIDIdx.selectedIndex +",4," + VLAN_Index;
        }
    }
    else
    {
        if(VLAN.checked == false)
            location.href = "aMSSIDSetting.htm?" + MS_Band.selectedIndex +","+ MS_MSSIDIdx.selectedIndex +",1," + VLAN_Index;
        else
        {
            if(APMode_State!=0 && SuperMode_State!=0)
                alert("If you enable Multi-SSID, \nSuper Mode will be disabled and AP Mode will be set to 'Access Point'!");
            else if(APMode_State!=0)
                alert("If you enable Multi-SSID, \nAP Mode will be set to 'Access Point'!");
            else if(SuperMode_State!=0)
                alert("If you enable Multi-SSID, \nSuper Mode will be disabled!");
            
            location.href = "aMSSIDSetting.htm?" + MS_Band.selectedIndex +","+ MS_MSSIDIdx.selectedIndex +",4," + VLAN_Index;
        }
    }
}

function Change_Band_Switch()
{
    VLAN_Index=VLAN_State();
    if(Band_Both.checked ==true)
        location.href = "aMSSIDSetting.htm?0,"+ MS_MSSIDIdx.selectedIndex +",2," + VLAN_Index;
    else if(Band_11a.checked ==true)
        location.href = "aMSSIDSetting.htm?0,"+ MS_MSSIDIdx.selectedIndex +",3," + VLAN_Index;
    else if(Band_11g.checked ==true)
        location.href = "aMSSIDSetting.htm?1,"+ MS_MSSIDIdx.selectedIndex +",4," + VLAN_Index;
}

function Change_Authentication()
{
    if (Security != null)
    {
        if (Security.options[Security.selectedIndex].text==MSSIDAuthList[0])
        {
            if (KeyType != null)
                KeyType.disabled = true;
            if (KeySize != null)
                KeySize.disabled = true;
            if (KeyIndex != null)
                KeyIndex.disabled = true;
            if (KeySet != null)
                KeySet.disabled = true;
                

            if (Cipher != null)
                Cipher.disabled = true;
            if (GKUI != null)
                GKUI.disabled = true;
            
            if (RadiusServer != null)
                RadiusServer.disabled = true;
            if (RadiusPort != null)
                RadiusPort.disabled = true;
            if (RadiusSecret != null)
                RadiusSecret.disabled = true;
            
            if (PassPhrase != null)
                PassPhrase.disabled = true;
        }
        else if(Security.options[Security.selectedIndex].text==MSSIDAuthList[1] || Security.options[Security.selectedIndex].text==MSSIDAuthList[2] || Security.options[Security.selectedIndex].text==MSSIDAuthList[3])
        {
            if (KeyType != null)
                KeyType.disabled = false;
            if (KeySize != null)
                KeySize.disabled = false;
            if (KeyIndex != null)
                KeyIndex.disabled = false;
            if (KeySet != null)
                KeySet.disabled = false; 
                
                
            if (Cipher != null)
                Cipher.disabled = true;
            if (GKUI != null)
                GKUI.disabled = true;
            
            if (RadiusServer != null)
                RadiusServer.disabled = true;
            if (RadiusPort != null)
                RadiusPort.disabled = true;
            if (RadiusSecret != null)
                RadiusSecret.disabled = true;
            
            if (PassPhrase != null)
                PassPhrase.disabled = true;                   
        }
        else if(Security.options[Security.selectedIndex].text==MSSIDAuthList[4]|| Security.options[Security.selectedIndex].text==MSSIDAuthList[6] || Security.options[Security.selectedIndex].text==MSSIDAuthList[8])
        {
            if (KeyType != null)
                KeyType.disabled = true;
            if (KeySize != null)
                KeySize.disabled = true;
            if (KeyIndex != null)
                KeyIndex.disabled = true;
            if (KeySet != null)
                KeySet.disabled = true; 
                
                
            if (Cipher != null)
                Cipher.disabled = false;
            if (GKUI != null)
                GKUI.disabled = true;
            
            if (RadiusServer != null)
                RadiusServer.disabled = true;
            if (RadiusPort != null)
                RadiusPort.disabled = true;
            if (RadiusSecret != null)
                RadiusSecret.disabled = true;
            
            if (PassPhrase != null)
                PassPhrase.disabled = true;                   
        }
        else if(Security.options[Security.selectedIndex].text==MSSIDAuthList[5] || Security.options[Security.selectedIndex].text==MSSIDAuthList[7] || Security.options[Security.selectedIndex].text==MSSIDAuthList[9])
        {
            if (KeyType != null)
                KeyType.disabled = true;
            if (KeySize != null)
                KeySize.disabled = true;
            if (KeyIndex != null)
                KeyIndex.disabled = true;
            if (KeySet != null)
                KeySet.disabled = true; 
                
                
            if (Cipher != null)
                Cipher.disabled = false;
            if (GKUI != null)
                GKUI.disabled = false;
            
            if (RadiusServer != null)
                RadiusServer.disabled = true;
            if (RadiusPort != null)
                RadiusPort.disabled = true;
            if (RadiusSecret != null)
                RadiusSecret.disabled = true;
            
            if (PassPhrase != null)
                PassPhrase.disabled = false;                   
        }
    }
}


function Change_Key_Type_Or_Size()
{
	if (KeyType != null)
	{
		if (KeyType.selectedIndex == 0) // Hex
	  {
		  if (KeySize != null)
		  {
		  	if (KeySize.selectedIndex == 0) //64 bits
		    {
		      if (KeySet != null)
		      {
		    	  KeySet.maxLength = 10;
		      }
		    }
		    else if (KeySize.selectedIndex == 1) //128 bits
		    {
		      if (KeySet != null)
		      {
		      	KeySet.maxLength = 26;
		      }
		    }
		    else if (KeySize.selectedIndex == 2) //152 bits
		    {
		      if (KeySet != null)
		      {
		      	KeySet.maxLength = 32;
		      }
		    }
	    }
	  }
	  else // ASCII
	  {
		  if (KeySize != null)
		  {
		  	if (KeySize.selectedIndex == 0) //64 bits
		    {
		      if (KeySet != null)
		      {
		      	KeySet.maxLength = 5;
		      }
		    }
		    else if (KeySize.selectedIndex == 1) //128 bits
		    {
		      if (KeySet != null)
		      {
		      	KeySet.maxLength = 13;
		      }
		    }
		    else if (KeySize.selectedIndex == 2) //152 bits
		    {
		      if (KeySet != null)
		      {
		       	KeySet.maxLength = 16;
		      }
		    }
		  }
	  }
	}
}
function Change_MSSID_Index()
{
    VLAN_Index=VLAN_State();
/*    if(Band_Both.checked==true) //both
        location.href = "aMSSIDSetting.htm?" + MS_Band.selectedIndex +","+ MS_MSSIDIdx.selectedIndex +",2," + VLAN_Index;
    else if(Band_11a.checked==true) //11a
        location.href = "aMSSIDSetting.htm?" + MS_Band.selectedIndex +","+ MS_MSSIDIdx.selectedIndex +",3," + VLAN_Index;
    else if(Band_11g.checked==true) //11g*/
        location.href = "aMSSIDSetting.htm?" + MS_Band.selectedIndex +","+ MS_MSSIDIdx.selectedIndex +",4," + VLAN_Index;
}

function Change_Band()
{
    VLAN_Index=VLAN_State();
    location.href = "aMSSIDSetting.htm?" + MS_Band.selectedIndex +","+ MS_MSSIDIdx.selectedIndex +",2," + VLAN_Index;
}

/* Because all mssid altogether use four keys, therefore this function changed uselessly.*/
/*function Check_Key_Index()
{
    var idx = MS_MSSIDIdx.selectedIndex;


    if (KeyIndex != null)
    {
        if (MS_Band.selectedIndex == 0)
        {
            for(var i=0; i<4 ;i++)
            {
                if (!(isNaN(KeyIndexLoc_11a[i])) && (KeyIndexLoc_11a[i]>=0 && KeyIndexLoc_11a[i]<=MSSID_MAX_NUM))
                {
                    
                    if(KeyIndex.selectedIndex == i)
                    {
                        if (KeyIndexLoc_11a[i]==0)
                        {
                            alert("The 11a Multi-SSID"+idx+"'s key index is same as Primary SSID.");
                            return false;
                        }
                        else if (KeyIndexLoc_11a[i] != idx)
                        {
                            alert("The 11a Multi-SSID"+idx+"'s key index is same as SSID"+KeyIndexLoc_11a[i]+".");
                            return false;
                        }
                    }
                        
                }
            }
            return true;
        }
        else
        {
            for(var i=0; i<4 ;i++)
            {
                if (!isNaN(KeyIndexLoc_11g[i]) && (KeyIndexLoc_11g[i]>=0 && KeyIndexLoc_11g[i]<=MSSID_MAX_NUM))
                {
                    if(KeyIndex.selectedIndex == i)
                    {
                        if (KeyIndexLoc_11g[i]==0)
                        {
                            alert("The 11g Multi-SSID"+idx+"'s key index is same as Primary SSID.");
                            return false;
                        }
                        else if (KeyIndexLoc_11g[i] != idx)
                        {
                            alert("The 11g Multi-SSID"+idx+"'s key index is same as SSID"+KeyIndexLoc_11g[i]+".");
                            return false;
                        }
                    }
                        
                }
            }
            return true;
        }
    }
}*/

function Check_Key()
{
	var idx = MS_MSSIDIdx.selectedIndex +1;
	var field = "";
	var key = "";

	field = KeySet;
	key = field.value;
    if (KeyType.selectedIndex == 0) // Hex
	{
		switch(KeySize.selectedIndex)
		{
		    case 0: // 64 bits
			    if (key.length != 10)
			    {
				  	alert("Please input 10 Hexadecimal digits in Multi-SSID"+idx+"!");
				  	field.value = "";
				  	return false;
				}
				else
				{
				  	if(!HexCheck2(key))
				  	{
                        alert("Please input hexadecimal digits in Multi-SSID"+idx+"!");
                        field.value = "";
                        return false;
		    	  	}
				}
				break;
			case 1: // 128 bits
			    if (key.length != 26)
				{
				  	alert("Please input 26 Hexadecimal digits in Multi-SSID"+idx+"!");
				  	field.value = "";
				  	return false;
				}
				else
				{
				  	if(!HexCheck2(key))
				  	{
                        alert("Please input hexadecimal digits in Multi-SSID"+idx+"!");
                        field.value = "";
                        return false;
				  	}
				}
				break;
			case 2: // 152 bits
			    if (key.length != 32)
				{
				  	alert("Please input 32 Hexadecimal digits in Multi-SSID"+idx+"!");
				 	field.value = "";
				  	return false;
				}
				else
				{
				    if(!HexCheck2(key))
				  	{
                        alert("Please input hexadecimal digits in Multi-SSID"+idx+"!");
                        field.value = "";
                        return false;
				  	}
				}
				break;
		}
		return true;
    }
	else // ASCII
	{
	    switch(KeySize.selectedIndex)
		{
	    	case 0: // 64 bits
		        if (key.length != 5)
				{
				  	alert("Please input 5 characters in Multi-SSID"+idx+"!");
				  	field.value = "";
				  	return false;
				}
				else
				{
				  	if(!ASCIICheck(key))
				  	{
                        alert("The key has invalid character in Multi-SSID"+idx+".\nPlease input again!");
                        field.value = "";
                        return false;
				  	}
				    else
				    {
				    	field.maxLength = 10;
				  	    field.value = ASCIIToHex(key);
					}
				}
				break;
			case 1: // 128 bits
			    if (key.length != 13)
				{
				  	alert("Please input 13 characters in Multi-SSID"+idx+"!");
				  	field.value = "";
				  	return false;
				}
				else
				{
				  	if(!ASCIICheck(key))
				  	{
                        alert("The key has invalid character in Multi-SSID"+idx+".\nPlease input again!");
                        field.value = "";
                        return false;
				  	}
				  	else
				  	{
				  		field.maxLength = 26;
				  	    field.value = ASCIIToHex(key);
					}
				}
				break;
			case 2: // 152 bits
			    if (key.length != 16)
			    {
				  	alert("Please input 16 characters in Multi-SSID"+idx+"!");
				  	field.value = "";
				  	return false;
				}
				else
				{
				  	if(!ASCIICheck(key))
				  	{
                        alert("The key has invalid character in Multi-SSID"+idx+".\nPlease input again!");
                        field.value = "";
                        return false;
				  	}
				    else
				    {
				    	field.maxLength = 32;
				    	field.value = ASCIIToHex(key);
					}
				}
				break;
		}
		return true;
	}
}

function Check_MSSID()
{
    var idx = MS_MSSIDIdx.selectedIndex;
    if (MSSID != null)
    {
        if (MSSID.value == "")
        {
            alert("Please input SSID.");
		    return false;
        }
        else if (MSSID.value.indexOf(" ") == 0)
  	    {
  	  	    alert("The first character can't be blank in SSID.");
  	  	    return false;
        }
        else
        {
            
            if (MS_Band.selectedIndex == 0)
            {
                for(var i=0; i<=MSSID_MAX_NUM ;i++)
                {
                    if (mssid_11a[i]!= null && mssid_11a[i]!="")
                    {
                        if (i==0 && MSSID.value == mssid_11a[i])
                        {
                            alert("The 11a Multi-SSID"+idx+"'s SSID is same as Primary SSID.");
                            return false;
                        }
                        else if(MSSID.value == mssid_11a[i] && mssid_11a[idx] != mssid_11a[i])
                        {
                            alert("The 11a Multi-SSID"+idx+"'s SSID is same as Multi-SSID"+i+".");
    		  				return false;
                        }
                    }
                    
                }
                return true;
            }
            else
            {
                for(var i=0; i<=MSSID_MAX_NUM ;i++)
                {
                    if (mssid_11g[i]!= null && mssid_11g[i]!="")
                    {
                        if (i==0 && MSSID.value == mssid_11g[i])
                        {
                            alert("The 11g Multi-SSID"+idx+"'s SSID is same as Primary SSID.");
                            return false;
                        }
                        else if(MSSID.value == mssid_11g[i] && mssid_11g[idx] != mssid_11g[i])
                        {
                            alert("The 11g Multi-SSID"+idx+"'s SSID is same as Multi-SSID"+i+".");
    		  				return false;
                        }
                    }
                }
                return true;
            }
        }
    }
}

function Check_VLanID()
{
    
    if(VLAN.checked == true)
    {
        if(VLanID.value == "")
        {
            alert("Please input VLAN ID!");
            VLanID.focus();
            return false;             
        }
        else if(VLanID.value<1 || VLanID.value>4094 || (isNaN(VLanID.value)))
        {
            alert("The VLAN ID is invalid .\n The range of Group ID is 1 to 4094.");
            VLanID.value = "";
            VLanID.focus();
            return false;
        }
    }
    return true;
}

function Change_Auth_Switch()
{
    var cAuth_Switch;
    var Auth_Index;
        
    if (Security.options[Security.selectedIndex].text==MSSIDAuthList[0])
    {
        Auth_Index = 1;
        cAuth_Switch= 0;
    }
    else if (Security.options[Security.selectedIndex].text==MSSIDAuthList[1])
    {
        Auth_Index = 2;
        cAuth_Switch= 0;
    }
    else if (Security.options[Security.selectedIndex].text==MSSIDAuthList[2])
    {
        Auth_Index = 3;
        cAuth_Switch= 0;
    }
    else if (Security.options[Security.selectedIndex].text==MSSIDAuthList[3])
    {
        Auth_Index = 4;
        cAuth_Switch= 0;    
    }
    else if (Security.options[Security.selectedIndex].text==MSSIDAuthList[4])
    {
        Auth_Index = 5;
        cAuth_Switch= 1;
    }
    else if (Security.options[Security.selectedIndex].text==MSSIDAuthList[5])
    {
        Auth_Index = 6;
        cAuth_Switch= 2; 
    }
    else if (Security.options[Security.selectedIndex].text==MSSIDAuthList[6])
    {
        Auth_Index = 7;
        cAuth_Switch= 1;
    }
    else if (Security.options[Security.selectedIndex].text==MSSIDAuthList[7])
    {
        Auth_Index = 8;
        cAuth_Switch= 2; 
    }
    else if (Security.options[Security.selectedIndex].text==MSSIDAuthList[8])
    {
        Auth_Index = 9;
        cAuth_Switch= 1;    
    }
    else if (Security.options[Security.selectedIndex].text==MSSIDAuthList[9])
    {
        Auth_Index = 10;
        cAuth_Switch= 2;    
    }

   
    VLAN_Index=VLAN_State();

    if(cAuth_Switch != Auth_Switch)
    {
        SaveMSSID.value=2;
        document.forms[0].submit();
    }
    
    Change_Authentication();
}

function Check_GKUI()
{
  if(GKUI != null)
	{
		if(isNaN(GKUI.value) || GKUI.value < 300 || GKUI.value > 9999999)
		{
			alert( "The range of 'Group Key Update Interval' is 300 to 9999999.");
			GKUI.select();
			return false;
		}
		return true;
	}
	else
	  return true;
}

function Check_Radius()
{
  if(RadiusServer != null && !CheckIP(RadiusServer.value))
	{
		alert("The RADIUS server's IP is illegal.");
		RadiusServer.focus();
		RadiusServer.select();
		return false;
	}

	if(RadiusPort != null)
	{
		if(isNaN(RadiusPort.value) || RadiusPort.value < 1 || RadiusPort.value > 65535)
  	{
  		alert("The range of RADIUS Port is (1-65535)");
  		RadiusPort.focus();
			RadiusPort.select();
  		return false;
  	}
  }

	if(RadiusSecret != null && RadiusSecret.value.length >32)
	{
		alert("The secret is too long.\nThe length must be less than 32.");
		RadiusSecret.focus();
		RadiusSecret.select();
		return false;
	}

	return true;
}

function Check_PassPhrase()
{
  if(PassPhrase != null)
	{
		if(PassPhrase.value.length < 8 || PassPhrase.value.length > 63)
		{
			alert("The length of 'PassPhrase' must be 8 to 63.");
			PassPhrase.select();
			return false;
		}
	}
	return true;
}

function Check_Original_Values(kind)
{
    if(kind==1) //Set key at key index=n, but other ssid have same key index.
        alert("Key value is used by SSID!\nTo change Key value affects other SSID settings.")
    else if(kind==2)//Set Group Key Update Interval, but other ssid in formerly have set it.
        alert("Group Key Update Interval is used by SSID!\nTo change Group Key Update Interval affects other SSID settings.")    
    else if(kind==3)
        alert("To change authentication type of Primary SSID will change WPA-EAP of Secondary SSID to no security.");
	else if(kind==4)//Set 802.1x, but other ssid have hold 1 key.
        alert("Setting 802.1x Dynamic will use key slot 1.\nOther Multiple SSID which uses WEP Key 1 will be set to no security.");
    else if(kind==5)//Set WPA or PSK, but other ssid have hold 2,3 key.
        alert("WPA or PSK will use key slot 2 and 3.\nOther Multiple SSID which uses WEP Key 2 and 3 will be set to no security.");
}

function MSSID_Submit(reboot)
{
    SecondSSIDState.disabled = false;
    SaveMSSID.value=0;
    if (SecondSSIDState.checked == true)
    {
		if (MS_MSSIDIdx.selectedIndex==0)
		{
		    if ((VLAN.checked == true && Check_VLanID() == true) || VLAN.checked == false)
		        document.forms[0].submit();
		}
		else
		{
		    if (Check_MSSID() == true)
		    {
		        if (Security.selectedIndex > 0)
		        {
		            if(Security.options[Security.selectedIndex].text==MSSIDAuthList[1] || Security.options[Security.selectedIndex].text==MSSIDAuthList[2] || Security.options[Security.selectedIndex].text==MSSIDAuthList[3])
		            {
		                if (Check_Key() == true)
		                {
		                    if (VLAN.checked == true && Check_VLanID() == false)
		                    {}
		                    else
		                        document.forms[0].submit();
		                }
		            }
		            else if(Security.options[Security.selectedIndex].text==MSSIDAuthList[4] || Security.options[Security.selectedIndex].text==MSSIDAuthList[6] || Security.options[Security.selectedIndex].text==MSSIDAuthList[8])
		            {
		                if (Cipher != null)
		                    Cipher.disabled = false;
		                if (GKUI != null)
		                    GKUI.disabled = false;
		                
		                if (RadiusServer != null)
		                    RadiusServer.disabled = false;
		                if (RadiusPort != null)
		                    RadiusPort.disabled = false;
		                if (RadiusSecret != null)
		                    RadiusSecret.disabled = false;
		
		                if (Check_GKUI() ==true)
		                {
		                    if (Check_Radius() == true)
		                    {
		                        if (VLAN.checked == true && Check_VLanID() == false)
		                        {}
		                        else
		                            document.forms[0].submit();
		                    }
		                }
		            }
		            else if(Security.options[Security.selectedIndex].text==MSSIDAuthList[5] || Security.options[Security.selectedIndex].text==MSSIDAuthList[7] || Security.options[Security.selectedIndex].text==MSSIDAuthList[9])
		            {
		                if (Check_GKUI() ==true)
		                {
		                    if (Check_PassPhrase() == true)
		                    {
		                        if (VLAN.checked == true && Check_VLanID() == false)
		                        {}
		                        else
		                            document.forms[0].submit();
		                    }
		                }
		            }
		            
		        }
		        else
		        {
		            if (VLAN.checked == true && Check_VLanID() == false)
		            {}
		            else
		                document.forms[0].submit();
		        }
		    }
		}
    
    }
    else if (VLAN.checked == true)
    {

        if (MS_MSSIDIdx != null)
            MS_MSSIDIdx.disabled = false;

        if (Check_VLanID() == true)
            document.forms[0].submit();
    }
    else
    {
        if (MS_MSSIDIdx != null)
            MS_MSSIDIdx.disabled = false;
        SaveMSSID.value=1;
        document.forms[0].submit();        
    }
}

/*} mark by John 2005.3.09 */

/*call by Wireless.html to compare MSSID status and key index*/
var Display_Multiple_SSID = parseInt("1");
var MSSID_Status_11a = parseInt("0*");
var MSSID_Status_11g = parseInt("0*");
var aidx = "";
var gidx = "0*0*0*0*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<MSSID_MAX_NUM; i++)
        {
    	    if(idx == aidx[i])
    	    {
    		    alert("The Primary SSID's key index is same as 11a Multi-SSID"+(i+1)+".");
    		    return false;
    	    }
        }
        return true;
    }
    else
	{
		for(var i=0; i<3; i++)
        {
    	    if(idx == gidx[i])
    	    {
    		    alert("The Primary SSID's key index is same as 11g Multi-SSID"+(i+1)+".");
    		    return false;
    	    }
        }
        return true;
	}
}
