//Copyright (c) 2000 Microsoft Corporation.  All rights reserved.
//<script>

var g_fDownloadError = false;
var g_fInstalling = false;
var g_fOffline = false;
var g_dwError = 0;
var g_szEMVer='6,0,4208,0';

function onCbClick(szCmd)
{
	switch(szCmd.toUpperCase())
	{
		case "SAVE":
			document.OptionsPageForm.submit();
			break;
		case "HELP":
			LaunchHelp();
		break;
	}
}

function openChangePassword()
{
	var objLocation	=	window.location;
	var szServer	=	objLocation.host;
	var szClose		=	g_szUserBase + "/?Cmd=close";
	var szURL		=	"https://" + szServer + "/iisadmpwd/aexp2b.htr?" + szClose;
	var szOpts		=	"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=355,height=350";
	window.open(szURL,0,szOpts)
}

function hideMediaTools( fHide )
{
	var objs = document.all.downloadMediaCab;
	if( null != objs )
	{
		for( var i = 0; i < objs.length; i++ )
		{
			var obj = objs[i];
			obj.style.display = (fHide) ? "none" : "";
		}
	}
	if( fHide )
	{
		var obj = document.all["idToolbar"];
		if( null != obj )
			obj.scrollIntoView(true);
	}
	
}

function download_MediaTools()
{
	if( !g_fInstalling )
	{
		g_fDownloadError = false;
		activeSetup.BaseUrl = g_szVirtualRoot+'/cabs/'+g_szAcceptLang;
		// Gets new CIF from site
		activeSetup.SetCIFFile("EmInst.cab","EmInst.cif");
	}
}

function EmInstallUI()
{
	if( oClientCaps.isComponentInstalled("{6E767503-024A-11D3-9D47-00C04F68AC7D}", "ComponentID", g_szEMVer))
	{
		hideMediaTools( true );
	}
}

function errorHandler(message, url, line)
{
	alert( message );
    return true;        // don't show real error message
}
window.onerror = errorHandler;

function window.onload()
{
	EmInstallUI();
} 

function NeedDxmedia()
{
   var szOS = navigator.userAgent;
   return  ((szOS.indexOf("Windows 95") > -1) ||
            (szOS.indexOf("Windows NT;") > -1) ||
            (szOS.indexOf("Windows NT)") > -1));
}

function InstallStateChange(newstate,substate)
{
	if( !InstallStateChange._oneShot && (newstate==3) )
	{
		InstallStateChange._oneShot = true;
                var szSection = "EMEDIA";
                if (NeedDxmedia())
                {
                     szSection += "_DX";
                }
                retSet = activeSetup.SetAction(szSection, 1);
		activeSetup.ProcessComponents(4);
	}
	if( 2 == newstate )
	{
		g_fInstalling = true;
	}
	
}
InstallStateChange._oneShot = false;

function download_Stop( Lresult, szText, Lstatus )
{
	g_fInstalling = false;
	if( g_fDownloadError || (0 > Lresult) )
	{
		// Pass back URLMON error code if component failed.

		// Canceled.
		if( (-2147467260 == g_dwError) || (-2147467260 == Lresult) )
		{
			g_dwError = 2;
		}
		// D/L failure component.
		else if( -2146697210 == g_dwError )
		{
			alert( L_szDLFail + " " + L_szProductUpdates );
			g_dwError = g_dwError;
		}
		// D/L failure - engine
		else if( -2146697210 == Lresult )
		{
			if( g_fOffline )
			{
				alert( L_szOfflineAlert + "\n\n" + L_szOfflineAlert2 );
			}
			else
			{
				alert( L_szDLFail + " " + L_szProductUpdates );
			}
			g_dwError = Lresult;
		}
		// Server offline
		else if( (-2146697211 == g_dwError) || (-2146697211 == Lresult))
		{
			alert( L_szServerError + " " + L_szIBusy + " " + L_szNotConnected );
			g_dwError = ( 0 > g_dwError ) ? g_dwError : Lresult;
		}
		// JIT reg key munged.
		else if( (-2146697208 == g_dwError) || (-2146697208 == Lresult) )
		{
			if( g_fOffline )
			{
				alert( L_szOfflineAlert + "\n\n" + L_szOfflineAlert2 );
			}
			else
			{
				alert( L_szServerError + " " + L_szProductUpdates );
			}
			g_dwError = ( 0 > g_dwError ) ? g_dwError : Lresult;
		}
		// Install failure.
		else if( (-2147467259 == g_dwError) || (-2147467259 == Lresult) )
		{
			if( g_fAdminError )
			{
				// No Admin rights.
				alert( L_szInstallFail + " " + L_szAdminRights );
			}
			else
			{
				alert( L_szInstallFail + " " + L_szProductUpdates ) ;
			}
			g_dwError = ( 0 > g_dwError ) ? g_dwError : Lresult;
		}
		// Cert refused / failed
		else if( (-2146762748 == g_dwError) || (-2146762748 == Lresult) )
		{
			alert( L_szCertRefuse + " " + L_szProductUpdates );
			g_dwError = ( 0 > g_dwError ) ? g_dwError : Lresult;
		}
		// Security set to HIGH
		else if( (-2146762485 == g_dwError) || (-2146762485 == Lresult) )
		{
			alert( L_szSecurityHigh + " " + L_szSecurityHigh1  + " " + L_szSecurityHigh2 + " " + L_szSecurityHigh3);
			g_dwError = ( 0 > g_dwError ) ? g_dwError : Lresult;
		}
		// General D/L error
		else if( ("-21466972" == (g_dwError + " ").substring(0,9)) ||
				 ("-21466972" == (Lresult + " ").substring(0,9)) )
		{
			alert( L_szDLFail + " " + L_szIBusy + " " + L_szNotConnected );
			g_dwError = ( 0 > g_dwError ) ? g_dwError : Lresult;
		}
		else
		{
			if( g_fAdminError )
			{
				alert( L_szInstallFail + " " + L_szAdminRights );
			}
			else
			{
				alert( L_szUnknownError + " " + L_szProductUpdates );
			}
			g_dwError = ( 0 > g_dwError ) ? g_dwError : Lresult;
		}
		hideMediaTools( false );
	}
	else
	{
		hideMediaTools( true );
		g_dwError = 0;
	}
}

function download_StopComponent( ComponentId, Lresult, Phase, FriendlyName, Status )
{
	if( 0 > Lresult )
	{
		g_fDownloadError = true;
		g_dwError = Lresult;
		if( -2147024891 == Lresult )
		{
			g_fAdminError = true;
		}
	}
}

