//Copyright 2004 Thomas Sapiano.  All rights reserved.
//
//*************************************************************
//* Javascript code used to validate the WT-1 configuration   *
//* form to make it as easy to use as possible.               *
//*************************************************************
//


//Functions that are called to enable/disable controls as
//  options are switched on the form.  This simplifies things
//  for the user so that they don't waste time filling out 
//  useless fields.
function switchMode(val)
{
	if(val == "1")
	{
		document.form1.WvLanChannel.disabled=false;
	}
	else
	{
		document.form1.WvLanChannel.disabled=true;
	}
}

function switchWEP(val)
{
	if(val)
	{
		document.form1.WvLanWepKey.disabled=false;
	}
	else
	{
		document.form1.WvLanWepKey.disabled=true;
	}
}

function switchDHCP(val)
{
	document.form1.LocalIpAddress.disabled = val;
	document.form1.SubnetMask.disabled = val;
	document.form1.IsGatewayUse.disabled = val;
	document.form1.IsDnsUse.disabled = val;

	if(!val)
	{
		switchGW(document.form1.IsGatewayUse.checked);
		switchDNS(document.form1.IsDnsUse.checked);
	}
	else
	{
		document.form1.GatewayIpAddress.disabled = true;
		document.form1.DnsIpAddress.disabled = true;
	}
}

function switchGW(val)
{
	document.form1.GatewayIpAddress.disabled = !val;
}

function switchDNS(val)
{
	document.form1.DnsIpAddress.disabled = !val;
}

function switchProxy(val)
{
	document.form1.FtpProxyIpAddress.disabled = !val;
	document.form1.FtpProxyPortNumber.disabled = !val;
}


//Validate the data entered into the WEP key field and make sure that
//  it is valid.  This is something that is commonly confused so it
//  is best to point it out right away.
function checkWepKey()
{
    if(document.form1.WvLanIsWepOn.checked)
    {
	sval = document.form1.WvLanWepKey.value;
	val = document.form1.WvLanWepKey.value.length;
	if(val != 5 && val != 10 && val != 13 && val != 26)
	{
		alert("The WEP key that you have entered has an invalid number of digits.  If you are entering the value in hexadecimal notation, there should be 10 (64-bit) or 26 (128-bit) digits.  In ASCII notation there should be 5 (64-bit) or 13 (128-bit) characters.  Please check your entry.");
		return false;
	}
	else if(val == 5 || val == 13)
	{
		validcharacters = "0123456789abcdefABCDEF";
		//Scan to make sure that hexadecimal entry is valid
		for(i=0;i<val;i++)
		{
			if(validcharacters.indexOf(sval.charAt(i)) == -1)
			{
				alert("The WEP key that you entered contains invalid characters!  Keys that are 5 or 13 digits should be hexadecimal digits and may only contain the characters 0-9 and A-F.  Please check your settings.");
				return false;
			}
		}
		
	}
    }
    return true;
}

//Disable elements as necessary for default configuration.  This is done
//  in Javascript so that the controls will not be locked out in browsers
//  that do not have support for scripting.
function initializeForm(val)
{
	document.form1.WvLanChannel.disabled=val;
	document.form1.WvLanWepKey.disabled=val;
	document.form1.LocalIpAddress.disabled=val;
	document.form1.SubnetMask.disabled=val;
	document.form1.IsGatewayUse.disabled=val;
	document.form1.GatewayIpAddress.disabled=val;
	document.form1.IsDnsUse.disabled=val;
	document.form1.DnsIpAddress.disabled=val;
	document.form1.FtpProxyIpAddress.disabled=val;
	document.form1.FtpProxyPortNumber.disabled=val;
}