// --- browser sniffer ---------------------------------------------------------
// Browser Sniffer
// sniffer_version = "1.1"
var so_agt=navigator.userAgent.toLowerCase();
var so_appVer = navigator.appVersion.toLowerCase();

// *** BROWSER VERSION 
var so_is_minor = parseFloat(so_appVer);
var so_is_major = parseInt(so_is_minor);

var so_iePos  = so_appVer.indexOf('msie');
if (so_iePos !=-1) {
   so_is_minor = parseFloat(so_appVer.substring(so_iePos+5,so_appVer.indexOf(';',so_iePos)));
   so_is_major = parseInt(so_is_minor);
}              

var so_is_getElementById   = (document.getElementById) ? "true" : "false";
var so_is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
var so_is_documentElement = (document.documentElement) ? "true" : "false";

var so_is_nav  = ((so_agt.indexOf('mozilla')!=-1) && 
                  (so_agt.indexOf('spoofer')==-1) && 
									(so_agt.indexOf('compatible') == -1) && 
									(so_agt.indexOf('opera')==-1) && 
									(so_agt.indexOf('webtv')==-1) && 
									(so_agt.indexOf('hotjava')==-1));

if ((navigator.vendor) && 
    ((navigator.vendor=="Netscape6") || 
		(navigator.vendor=="Netscape")) && 
		(so_is_nav)) 
{
	so_is_major = parseInt(navigator.vendorSub);
  so_is_minor = parseFloat(navigator.vendorSub);
}

var so_is_nav4 = (so_is_nav && 
                  (so_is_major == 4));
var so_is_nav4up 	= (so_is_nav && 
                     so_is_minor >= 4); 
var so_is_navonly	= (so_is_nav && 
                     ((so_agt.indexOf(";nav") != -1) || 
                     (so_agt.indexOf("; nav") != -1)) );
var so_is_nav6up 	= (so_is_nav && 
                     so_is_minor >= 6);
var so_is_nav5up 	= (so_is_nav && 
                     so_is_minor >= 5);
var so_is_nav7up 	= (so_is_nav && 
                     so_is_minor >= 7);
var so_is_ie   	= ((so_iePos!=-1));
var so_is_ie4   	= (so_is_ie && 
                     so_is_major == 4);
var so_is_ie4up 	= (so_is_ie && 
                     so_is_minor >= 4);
var so_is_ie5up 	= (so_is_ie && 
                     so_is_minor >= 5);
var is_firefox	= ((so_agt.indexOf("firefox") != -1));
//var so_is_ie5_5  	= (so_is_ie && (so_is_major == 4) && (so_agt.indexOf("msie 5.5") !=-1));
//Modified check for IE 5.5 because based on above expression minor would 5.5 and major would be 5
var so_is_ie5_5  	= (so_is_ie && 
                     so_agt.indexOf("msie 5.5") !=-1);
var so_is_ie6up 	= (so_is_ie && 
                     so_is_minor >= 6);

// *** PLATFORM 
var so_is_win   		= ((so_agt.indexOf("win")!=-1) || 
                       (so_agt.indexOf("16bit")!=-1));
var so_is_win95 		= ((so_agt.indexOf("win95")!=-1) || 
                       (so_agt.indexOf("windows 95")!=-1));
var so_is_winme 		= ((so_agt.indexOf("win 9x 4.90")!=-1));  
var so_is_win2k 		= ((so_agt.indexOf("windows nt 5.0")!=-1) || 
                       (so_agt.indexOf("windows 2000")!=-1));
var so_is_winxp 		= ((so_agt.indexOf("windows nt 5.1")!=-1) || 
                       (so_agt.indexOf("windows xp")!=-1));
var so_is_winxp_sp2 	= ((so_is_winxp) && 
                         (so_agt.indexOf("sv1")!=-1));	//Currently only works in IE
var so_is_win98 		= ((so_agt.indexOf("win98")!=-1) || 
                       (so_agt.indexOf("windows 98")!=-1));
var so_is_winnt 		= ((so_agt.indexOf("winnt")!=-1) || 
                       (so_agt.indexOf("windows nt")!=-1));
var so_is_win32 		= (so_is_win95 || 
                       so_is_winnt || 
											 so_is_win98 || 
											 ((so_is_major >= 4) && 
											 (navigator.platform == "Win32")) || 
											 (so_agt.indexOf("win32")!=-1) || 
											 (so_agt.indexOf("32bit")!=-1));
var so_is_mac   		= (so_agt.indexOf("mac")!=-1);
var so_is_vista			= ((so_agt.indexOf("vista")!=-1) ||
						(so_agt.indexOf("windows nt 6.0")!=-1));
						
//document.write("navigator user agent = :dsm " + so_agt);
// --- speed optimizer helper code ---------------------------------------------
var so_cookie_speed;
var so_speed_verified = false;
var so_is_wireless = false;
var so_activex_deployed = false;
var so_return_to_content = '';
var so_startOptimizationProcess = false;

function getCookieValue( name, keyname )
{
	var nameEQ = name + "=";
	var keynameEQ = keyname + "=";
	
	var cookies = document.cookie.split(';');
	
	for(var i = 0; i < cookies.length; i++)
	{
		var cookie = cookies[i];
		
		while (cookie.charAt(0) == ' ') 
		{
			cookie = cookie.substring(1, cookie.length);
		}
		
		if (cookie.indexOf(nameEQ) == 0) 
		{
			var decoded_cookie = unescape(cookie.substring(nameEQ.length,cookie.length));
			var dc_kv_pairs = decoded_cookie.split('&');

			for (var j = 0; j < dc_kv_pairs.length; j++)
			{
				if (dc_kv_pairs[j].indexOf(keynameEQ) == 0)
				{
					return dc_kv_pairs[j].substring(keynameEQ.length, dc_kv_pairs[j].length);
				}
			}
		}
	}
	return null;
}

function setCookie( name, value, days )
{
	if( days || days != 0 )
	{
		var date = new Date();
		date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
		var expires = "; expires=" + date.toGMTString();
	}
	else 
	{
		var expires = "";
	}
	document.cookie = name + "=" + escape( value ) + expires + "; path=/";
}

function removeAlpha( theString )
{
	return theString.replace(/\D/g, "");
}

// --- speed optimizer code ----------------------------------------------------
function switchContent( theDiv, theContent )
{
	document.getElementById( theDiv ).innerHTML = '';
	document.getElementById( theDiv ).innerHTML = theContent;
	if( so_is_wireless && document.getElementById("wireless") != null )
	{
		document.getElementById("wireless").innerHTML = "WIRELESS ";
	}
	if( document.getElementById("what") != null )
	{
		if( !so_is_win && !so_is_ie6up )
		{
			document.getElementById("what").innerHTML = "Platform and Browser ";
		}
		else if( !so_is_ie6up )
		{
			document.getElementById("what").innerHTML = "Browser ";
		}
		else if( !so_is_win )
		{
			document.getElementById("what").innerHTML = "Platform ";
		}
	}
}

function startOptimizer()
{
	var temp = '10M/2M'; //dsm hard code default value
	setCookie( 'user_profile', 'linespeed=' + temp, 1);
	if (so_startOptimizationProcess)
	{
		try
		{
			so_is_wireless = IsAdapterWireless();
			so_cookie_speed = getCookieValue( 'user_profile', 'linespeed' );     
			var result = IsOptimized( so_cookie_speed );
			
			switch( result )
			{
				case 1:
					switchContent( 'so_content', is_optimized );
					break;
				case -1:
					switchContent( 'so_content', not_optimized );
					break;
				case -2:
					switchContent('so_content', activex_error);
					break;
				case -3:
					switchContent( 'so_content', speed_unknown );
					break;
				case -4:
					switchContent('so_content', activex_error);
					break;
			}
		}
		catch (e)
		{
			// we ignore the error... as we already redirected to the ActiveX Error page
		}
	}
}

function doActiveXError()
{
	if ( getCookieValue('speedoptimizer', 'axerror') != 'true' )
	{
		setCookie( 'speedoptimizer', 'axerror=true', 0);
	}
	switchContent('so_content', activex_error);
}

function doOptimize( speed )
{
	if ( Optimize( speed ) )
	{
		var str = 'Your system\'s settings were optimized.';
		if( so_is_winme  || so_is_win98 )
		{
			str = str +	'\n\nThis update will take effect once the system is restarted.';
		}
		switchContent( 'so_content', optimize_success );
		setCookie( 'optimizer', 'optimized=true', 1000 );
	}
	else
	{
		switchContent( 'so_content', optimize_failure );
	}
}

function doRestoreBackup()
{
	if( RestoreBackup() )
	{
		var str = 'Your system\'s settings were restored.';
		if( so_is_winme  || so_is_win98 )
		{
			str = str +	'\n\nThis update will take effect once the system is restarted.';
		}
		switchContent( 'so_content', restore_success );
		setCookie( 'optimizer', 'optimized=false', 1000 );
	}
	else
	{
		switchContent( 'so_content', restore_failure );
	}
}

function doTCPIP_MTU()
{
	if ( so_return_to_content != '' )
	{
		switchContent( 'so_content', so_return_to_content );
		so_return_to_content = '';
	} 
	else 
	{ 
		switchContent( 'so_content', app_entry );
	}
}

function doStartApp()
{
	so_speed_verified = false;
	so_startOptimizationProcess = true;
	if( !so_activex_deployed )
	{
		so_activex_deployed = true;
		switchContent( 'ax', ax_object );
	}
	else
	{
		startOptimizer();
	}
}

function doSSOLogin()
{
	var ssoLoginUrl = 'https://sso.verizon.net/ssowebapp/VOLPortalLogin?ActualTarget=';
	var actualUrl = escape(location.href);
	location.href = ssoLoginUrl + actualUrl;
}

function IsOptimized( speed )
{
	var ACTIVEX_ERROR = -4;
	var UNKNOWN_SPEED = -3;
	var NO_PERMISSION = -2;
	var NOT_OPTIMIZED = -1;
	var OPTIMIZED 	  = 1;
	var DOWNLOAD_SPEED	= 0;
	var UPLOAD_SPEED 	= 1;
	
		
	var temp = speed.split('/');
	
		if (vzTCPConfig.IsAdmin())
		{
			if (vzTCPConfig.SetConnectionSpeed(removeAlpha(temp[DOWNLOAD_SPEED]), removeAlpha(temp[UPLOAD_SPEED])) == 1)
			{
				return vzTCPConfig.IsConfigured();
			}
		}
		else
		{
			// IsAdmin
			return NO_PERMISSION;
		}
}

function Optimize( speed )
{
	var DOWNLOAD_SPEED	= 0;
	var UPLOAD_SPEED 		= 1;
	
	if (speed != undefined && 
			speed != '')
	{
		var temp = speed.split('/');
		
		if (temp.length == 2)
		{
			if (vzTCPConfig.IsAdmin())
			{
				if (vzTCPConfig.SetConnectionSpeed(removeAlpha(temp[DOWNLOAD_SPEED]), removeAlpha(temp[UPLOAD_SPEED])) == 1)
				{
					try
					{
						result = vzTCPConfig.ConfigureTCP(0, 0, 0);
					}
					catch( error )
					{
						result = 0;
					}
					if (result == 1)
					{
						return true;
					}
					else
					{
						return false;
					}
				}
			}
			else
			{
				// IsAdmin
				return false;
			}
		}
		else
		{
			// temp.length
			return false;
		}
	}
	else
	{
		// undefined or ''
		return false;
	}
}

function IsAdapterWireless()
{
	if (vzTCPConfig.IsAdmin())
	{
		if(vzTCPConfig.IsDefaultAdapterWireless() == 1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		// IsAdmin
		return false;
	}
}

function RestoreBackup()
{
	if (vzTCPConfig.IsAdmin())
	{
		if(vzTCPConfig.RestoreBackup() > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		// IsAdmin
		return false;
	}
}

var ax_object =
	'<object id="vzTCPConfig" ' +
	' onerror="doActiveXError();" ' +
	'	onreadystatechange="window.setTimeout(\'startOptimizer();\', 1000);" ' +
	'	classid="CLSID:8B7D2210-CC81-4F59-A486-4409FB485D4A" ' +
	'	codebase="http://www2.verizon.net/help/dsl_settings/include/vzTCPConfig.CAB#version=2,0,61009,1" ' +
	'	width="0" height="0">' +
	'</object>';

var wrong_browser_platform_mac = 
	'<div style="margin: 10px; padding: 10px; border: 2px solid #ff0000; font-weight: bold;">' +
	'The Speed Optimizer tool is incompatible with  Macintosh.  ' +
	'<a href="http://netservices.verizon.net/portal/link/help/item?linkflag=verizon&case=27244">Learn more</a> about using Broadband Tuner to optimize your connection speed while on a Mac. ' +
	'</div><br /><center><a href="http://www2.verizon.net/help/"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/back_to_dsl_help_topics_btn.gif" alt="Back To DSL Help Topics" width="150" height="18" border="0" /></a><br /></center>';

var wrong_browser_platform_vista = 
	'<div style="margin: 10px; padding: 10px; border: 2px solid #ff0000; font-weight: bold;">' +
	'We detected that you are using Windows Vista Operating Systems on your PC.  ' +
	'The Vista OS will optimize your connection for you.' +
	'  There is no need to use the Speed Optimizer tool.<br />' +
	'</div><br /><center><a href="http://www2.verizon.net/help/"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/back_to_dsl_help_topics_btn.gif" alt="Back To DSL Help Topics" width="150" height="18" border="0" /></a><br /></center>';

var wrong_browser_platform = 
	'<div style="margin: 10px; padding: 10px; border: 2px solid #ff0000; font-weight: bold;">' +
	'The functionality you are trying to access requires Internet Explorer version 6 or higher ' +
	'on a Windows PC. You are currently using a <span id="what" style="font-size: larger;"></span> ' +
	'that\'s not supported. Please use Internet Explorer, version 6 or higher on a Windows PC, to access this functionality.<br />' +
	'</div><br /><center><a href="http://www2.verizon.net/help/"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/back_to_dsl_help_topics_btn.gif" alt="Back To DSL Help Topics" width="150" height="18" border="0" /></a><br /></center>';

var app_entry =
	'	Are you tapping into the full power of your DSL connection? Use the Speed Optimizer tool to help you determine if certain ' +
	'	settings (<a href="#" onclick="switchContent( \'so_content\', tcpip_mtu ); so_return_to_content = app_entry; return false;">TCP/IP and MTU</a>) ' +
	'	on your system are tuned for optimal performance.<br />' +
	'	<br />' +
	' Note: You only need to run this optimizer if your Verizon High Speed Internet service speed is greater than 3MB/second.<br />' +
	'  If you are not sure, you can run the optimizer and the tool will notify you. <br />' +
	'   <br />' +
	'	Ready to see if setting changes can be made to optimize the speed and performance of your Internet connection?<br />' +
	'	<br />' +
	'	<b>To use the tool:</b><br />' +
	'	1. Click the <b>Optimize My Connection</b> button below.<br />' +
	'	2. Click <b>Yes</b>, if prompted, to install and run ActiveX controls.<br />' +
	'	3. Results and options will be displayed on the next page.<br />' +
	'	<br />' +
	'	<a href="#" onclick="doStartApp(); return false;"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/optimize_my_connection_btn.gif" alt="Optimize My Connection" width="150" height="18" border="0" /></a><br />' +
	'	<br />';

var tcpip_mtu =
	'	<b>What does the Speed Optimizer tool do?</b><br />' +
	'	There are several system parameters that can be altered on your PC in order to improve download speeds over the DSL network.<br />' +
	'	<br />' +
	'	The Speed Optimizer tool modifies your TCP/IP configuration to allow your system to receive data at a faster rate.<br />' +
	'	<br />' +
	'	<b>What is TCP/IP?</b><br />' +
	'	TCP/IP Stands for Transmission Control Protocol/Internet Protocol and allows your system to communicate with other networked' +
	'	computers over the Internet. The standard TCP/IP configuration is optimized for communications over small local networks.<br />' +
	'	<br />' +
	'	<b>Which parameters and settings does the Speed Optimizer modify?</b>' +
	'	<ol>' +
	'		<li>TCP 1323 Extensions - This parameter enables enhancements to the TCP/IP protocol that provide improved performance over ' +
	'			high speed connections.<br />' +
	'			<br /></li>' +
	'		<li>TCP Receive Window - This parameter specifies the number of bytes a sender (the source you are downloading from) may ' +
	'			transmit without receiving an acknowledgment. Modifying it determines the maximum size offered by the system.<br />' +
	'			<br /></li>' +
	'		<li>MTU (Maximum Transmission Units) - The MTU defines the largest single unit of data that can be transmitted over your ' +
	'			connection. The DSL network requires an MTU of 1492 bytes.<br />' +
	'			<br /></li>' +
	'	</ol>' +
	'	<a href="#" onclick="doTCPIP_MTU(); return false;"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/back_btn.gif" alt="Back" width="46" height="18" border="0" /></a><br />' +
	'	<br />';

var is_optimized = 
	'<b>Your system\'s <span id="wireless"></span> settings are already optimized for Verizon DSL Internet Service. There ' +
	'are no changes needed.</b><br />' +
	'<br />' +
	'<ul>' +
	'	<li>Please remember to run this tool on each system that you use to connect ' +
	'		to your DSL service</li>' +
	'	<li>If you connect to DSL from a system in both wired AND wireless configurations' +
	'		(such as with a laptop), please run the optimizer tool while connected in the' +
	'		wired configuration and while connected in the wireless configuration.' +
	'</ul>' +
	'Continue enjoying your blazing fast Verizon DSL Internet Service!<br /><br />' +
	'<a href="http://www2.verizon.net/help/"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/back_to_dsl_help_topics_btn.gif" alt="Back To DSL Help Topics" width="150" height="18" border="0" /></a><br /><br />' +
	'You also have the option of restoring the Microsoft Windows default settings by clicking the \'Next\' button.<br /><br />' +
	'<a href="#" onclick="switchContent( \'so_content\', restore_settings ); return false;"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/next_btn.gif" alt="Next" width="49" height="18" border="0" /></a><br />';
	
var restore_settings =
	'<b>Restore your system\'s optimized <span id="wireless"></span> settings to the Microsoft Windows default settings.</b><br />' +
	'However, doing so could result in slowing down your Internet connection speed. ' +
	'<span style="color: #ff0000; font-weight: bold;">We strongly recommend that you leave your settings in ' +
	'their current state.</span><br /><br />' +
	'<a href="#" onclick="doRestoreBackup(); return false;"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/restore_settings_btn.gif" alt="Restore Settings" width="116" height="18" border="0" /></a><br /><br />' +
	'<span style="font-size: smaller;">By clicking the restore settings button, you are granting Verizon permission to access and reset your PC\'s ' +
	'<a href="#" onclick="switchContent( \'so_content\', tcpip_mtu ); so_return_to_content = restore_settings; return false;">TCP/IP and MTU</a> ' +
	'settings back to the original Microsoft Windows default settings.</span><br />';

var not_optimized =
	'<b>Your system\'s <span id="wireless"></span> settings are not optimized for Verizon DSL Internet Service.</b><br />' +
	'<br />' +
	'To update your settings so that they are optimized for DSL, click the Update Now!* button.<br />' +
	'<br />' +
	'<a href="#" onclick="doOptimize( so_cookie_speed );"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/update_now_btn.gif" alt="Update Now!" width="89" height="18" border="0" /></a><br />' +
	'<br />' +
	'<span style="font-size: smaller;">*By clicking the Update Now! Button, you are granting Verizon permission to access and reconfigure' +
	'	your PC\'s <a href="#" onclick="switchContent( \'so_content\', tcpip_mtu ); so_return_to_content = not_optimized; return false;">TCP/IP and MTU</a> settings.</span><br />';

var optimize_failure =	
	'<b>Optimization of your current system settings failed.</b><br />' +
	'<br />' +
	'<a href="javascript:location.reload();"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/try_again.gif" alt="Try again &gt;" width="72" height="18" border="0" /></a><br />' +
	'<br />' +
	'<a href="http://www2.verizon.net/help/"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/back_to_dsl_help_topics_btn.gif" alt="Back To DSL Help Topics" width="150" height="18" border="0" /></a><br />';

var restore_failure =	
	'<b>Restoration of your current system settings failed.</b><br />' +
	'<br />' +
	'<a href="javascript:location.reload();"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/try_again.gif" alt="Try again &gt;" width="72" height="18" border="0" /></a><br />' +
	'<br />' +
	'<a href="http://www2.verizon.net/help/"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/back_to_dsl_help_topics_btn.gif" alt="Back To DSL Help Topics" width="150" height="18" border="0" /></a><br />';

var optimize_success =	
	'<b>Your system\'s <span id="wireless"></span> settings have been <i>optimized!</i></b><br />' +
	'Enjoy the blazing fast speed of DSL.<br />' +
	'<br />' +
	'<ul>' +
	'	<li>Please remember to run this tool on each system that you use to connect ' +
	'		to your DSL service</li>' +
	'	<li>If you connect to DSL from a system in both wired AND wireless configurations' +
	'		(such as with a laptop), please run the optimizer tool while connected in the' +
	'		wired configuration and while connected in the wireless configuration.' +
	'</ul>' +
	'<br />' +
	'<b>Please Note:</b><br />' +
	'These updates will take effect the next time you restart your system.<br /><br />' +
	'<a href="http://www2.verizon.net/help/"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/back_to_dsl_help_topics_btn.gif" alt="Back To DSL Help Topics" width="150" height="18" border="0" /></a><br />';

var restore_success =
	'<b>Your system\'s <span id="wireless"></span> settings have been <i>restored!</i></b><br />' +
	'<br />' +
	'<ul>' +
	'	<li>Please remember to run this tool on each system that you use to connect ' +
	'		to your DSL service</li>' +
	'	<li>If you connect to DSL from a system in both wired AND wireless configurations' +
	'		(such as with a laptop), please run the optimizer tool while connected in the' +
	'		wired configuration and while connected in the wireless configuration.' +
	'</ul>' +
	'<br />' +
	'<b>Please Note:</b><br />' +
	'These updates will take effect the next time you restart your system.<br /><br />' +
	'<a href="http://www2.verizon.net/help/"><img src="http://www2.verizon.net/help/dsl_settings/include/images/buttons/back_to_dsl_help_topics_btn.gif" alt="Back To DSL Help Topics" width="150" height="18" border="0" /></a><br />';

document.write('<div id="so_content"></div>');
document.write('<div id="ax"></div>');

document.write('<scr' + 'ipt type="text/javascript" src="http://www2.verizon.net/help/dsl_settings/include/activex_error.asp" /></scr' + 'ipt>');

if ( so_is_win && so_is_ie6up )
{
	if ( !so_is_vista )
	{
		switchContent( 'so_content', app_entry );
		if ( getCookieValue('speedoptimizer', 'axerror') == 'true' )
		{
			so_activex_deployed = true;
			switchContent( 'ax', ax_object );
		}
	}
	else
	{
		switchContent( 'so_content', wrong_browser_platform_vista );
	}
}
else
{
	if (so_is_mac)
	{
		switchContent( 'so_content', wrong_browser_platform_mac );
	}
	else
	{
		switchContent( 'so_content', wrong_browser_platform );
	}
}


