SecurityTypePage = new Array("WS_Wep.htm","WS_WPAPSK.htm","WPA2-Personal.htm","WPA2-Mixed.htm","WS_WPARadius.htm","WS_WPA2Radius.htm", "WS_Radius.htm","WS_None.htm");

// JavaScript Document
// Wireless Security 
// Jonathan -- 9/19/2003

function SSIDSelected(IndexValue)
{
	if ( IndexValue == "SSID1" ) 
		SSID_ID = 0;
    else if ( IndexValue == "SSID2" ) 
    	SSID_ID = 1;
    else if ( IndexValue == "SSID3" )
    	SSID_ID = 2;
    else if ( IndexValue == "SSID4" )
    	SSID_ID = 3;
    else 
    	SSID_ID = 0;	

	SecurityType = GetCurrFlashValue( "wl_security", SSID_ID );
	parent.SSIDAuthMode.location.href = SecurityTypePage[GetAuthModePageIndex(SecurityType)];
}
function WlanSecPage(SecurityType)
{
	//var SecurityType = '<%nvram_get("wl0_sec_mode");%>';
	self.SSIDAuthMode.location.href = SecurityTypePage[GetAuthModePageIndex(SecurityType)];
}
function WirelessSecurityType ( SecurityTypeMode )
{    if ( SecurityTypeMode == "psk" ) { window.location.href ="WS_WPAPSK.htm"; }
    else if ( SecurityTypeMode == "wparadius" ) { window.location.href ="WS_WPARadius.htm"; }
    else if ( SecurityTypeMode == "wpa2radius" ) { window.location.href ="WS_WPA2Radius.htm"; }
    else if ( SecurityTypeMode == "radius" ) { window.location.href ="WS_Radius.htm"; }    
    else if ( SecurityTypeMode == "wep" ) { window.location.href ="WS_Wep.htm"; }
    else if ( SecurityTypeMode == "none") { window.location.href ="WS_None.htm"; }
	else if ( SecurityTypeMode == "WPA2" ) { window.location.href ="WPA2-Personal.htm"; }
    else if ( SecurityTypeMode == "WPA1WPA2") { window.location.href ="WPA2-Mixed.htm"; }
    else { window.location.href ="WS_None.htm"; }
}
function GetAuthModePageIndex(AuthMode)
{
	var PageIndex;
	
	if ( AuthMode == "wep" )
	    PageIndex = 0;
	else if ( AuthMode == "psk" ) 
		PageIndex = 1;
	else if ( AuthMode == "WPA2" ) 
		PageIndex = 2;
	else if ( AuthMode == "WPA1WPA2" ) 
		PageIndex = 3;
    else if ( AuthMode == "wparadius" ) 
    	PageIndex = 4;
    else if ( AuthMode == "wpa2radius" ) 
    	PageIndex = 5;
    else if ( AuthMode == "radius" )
    	PageIndex = 6;
    else if ( AuthMode == "none" )
    	PageIndex = 7;
    else 
    	PageIndex = 7;

	return PageIndex;
}

function GetCurrFlashValue( Var_name, SSIDnum )
{
	var find_result = "";
	var stringall = "";
	var check0 = 0;			//Flag, if this string is blank or null, we will show to "" with webpage
	switch(Var_name)
	{
		case "wl_security":
			stringall = '<!--#set_get path="wireless/wl_security" -->' ;
		break;
		case "wl_encryp_type":
			stringall = '<!--#set_get path="wireless/wl_encryp_type" -->' ;
		break;
		case "wl_auth_mode":
			stringall = '<!--#set_get path="wireless/wl_auth_mode" -->' ;
		break;
		case "wl_key_id":
			stringall = '<!--#set_get path="wireless/wl_key_id" -->' ;
		break;
		case "wl_key1":
			stringall = '<!--#set_get path="wireless/wl_key1" -->' ;
			check0 = 1;
		break;
		case "wl_key2":
			stringall = '<!--#set_get path="wireless/wl_key2" -->' ;
			check0 = 1;
		break;
		case "wl_key3":
			stringall = '<!--#set_get path="wireless/wl_key3" -->' ;
			check0 = 1;
		break;
		case "wl_key4":
			stringall = '<!--#set_get path="wireless/wl_key4" -->' ;
			check0 = 1;
		break;
		case "wl_wpa_psk":
			stringall = '<!--#set_get path="wireless/wl_wpa_psk" -->' ;
			check0 = 1;
		break;
		case "wl_noforward_ssid":
			stringall = '<!--#set_get path="wireless/wl_noforward_ssid" -->' ;
		break;
	}

	stringArray = stringall.split(";");
	
	if ( (stringArray[SSIDnum].length==0) || (check0==1 && stringArray[SSIDnum]=='0') )
	{
//alert("Var_name is " + Var_name + ", value = "+ stringArray[SSIDnum] + ", find_result==\"\"");
		find_result = "";
	}
	else
		find_result = stringArray[SSIDnum];

//alert(Var_name+"'s find result is : "+ find_result);

	return find_result;
}

function SetCurrFlashValue( Var_name, SSIDnum, value)
{
	var bind_result = "";
	var stringall = "";
	var check0 = '0';
	switch(Var_name)
	{
		case "wl_security_all":
			stringall = '<!--#set_get path="wireless/wl_security" -->' ;
		break;
		case "wl_encryp_type_all":
			stringall = '<!--#set_get path="wireless/wl_encryp_type" -->' ;
		break;
		case "wl_auth_mode_all":
			stringall = '<!--#set_get path="wireless/wl_auth_mode" -->' ;
		break;
		case "wl_key_id_all":
			stringall = '<!--#set_get path="wireless/wl_key_id" -->' ;
		break;
		case "wl_key1_all":
			stringall = '<!--#set_get path="wireless/wl_key1" -->' ;
			check0 = 1;
		break;
		case "wl_key2_all":
			stringall = '<!--#set_get path="wireless/wl_key2" -->' ;
			check0 = 1;
		break;
		case "wl_key3_all":
			stringall = '<!--#set_get path="wireless/wl_key3" -->' ;
			check0 = 1;
		break;
		case "wl_key4_all":
			stringall = '<!--#set_get path="wireless/wl_key4" -->' ;
			check0 = 1;
		break;
		case "wl_wpa_psk_all":
			stringall = '<!--#set_get path="wireless/wl_wpa_psk" -->' ;
			check0 = 1;
		break;
		case "wl_ieee_8021x_all":
			stringall = '<!--#set_get path="wireless/wl_ieee_8021x" -->' ;
		break;
		case "wl_noforward_ssid_all":
			stringall = '<!--#set_get path="wireless/wl_noforward_ssid" -->' ;
		break;
	}
	
	if ( check0==1 && value.length==0 )
	{
//alert("Var_name = "+Var_name+", value = "+value+", set it to 0!");
		value = 0;
	}
	
//alert("Function value is "+ value);

	stringArray = stringall.split(";");
	for( i=0; i<4; i++ )
	{
		if ( i == SSIDnum )
			bind_result += value ;
		else
			bind_result += stringArray[i] ;

		if ( i < 3 )
			bind_result += ";"
	}
//alert(Var_name+"'s bind result is : "+ bind_result);

	return bind_result;
}

function GetSSIDName( SSIDnum )
{
	var get_result = "";
	var stringall = "";
	
	stringall = '<!--#set_get path="wireless/wl_ssid" -->' ;
	stringArray = stringall.split(";");
	
	if ( stringArray.length-1 < SSIDnum )
		get_result = "";
	else
		get_result = stringArray[SSIDnum];

	return get_result;
}
