Scanner=function(type){
	// private fields
	var m_EulaKey=(type.toLowerCase()=='sandbox'?'vBeta':'v1');
	var m_ScannerLocation=(type.toLowerCase()=='sandbox'?'sandbox':'scanner');
	var m_ClassId=(type.toLowerCase()=='sandbox'?'CLSID:3860DD98-0549-4d50-AA72-5D17D200EE10':'CLSID:5ED80217-570B-4DA9-BF44-BE107C0EC166');

	// public methods
	this.Install=function(){
		m_TestingForControl=false;
		var codeBase;
		if(g_CodeBase.toLowerCase().indexOf('wlscctrl2.cab')>-1 && DocumentProperties.GetLocationHREF().toLowerCase().indexOf('reinstall=true')>-1){
			codeBase=g_CodeBase.substring(0,g_CodeBase.indexOf('=')+1)+'99999';}
		else{
			codeBase=g_CodeBase;}
		var object={
			Id:"ObjControl",
			CodeBase:codeBase,
			ClassId:m_ClassId,
			OnError:"InstallError()",
			Params:[
				{Name:"Locale",Value:g_LangMark},
				{Name:"WebServerUrl",Value:g_CatalogUrl}]}
		if(Browser.OS=='Win2K'){
			object.OnError='m_Error=true;window.parent.InstallError()';
			// ready state may fire before the control completes its own downloads
			object.OnReadyState='if (!m_Error){setTimeout(function(){window.parent.InstallComplete()},5000)}';
			var b=document.createElement('iframe');
			b.style.position='absolute';
			b.style.left=b.style.top='-1000px';
			b.id='iframeInstall';
			document.body.appendChild(b);
			var iframe=window.frames('iframeInstall');
			iframe.document.write('');
			iframe.document.close();
			iframe.document.write('<script type="text/javascript">m_Error=false;</script>'+Utils.ObjectToString(object));
		}
		else{
			$('ObjControl').outerHTML=Utils.ObjectToString(object);}}

	this.LaunchScanner = function(center, globalPath, page, useQuerystring, popup)
	{
		var goback;
		var location;
		var querystring='';
		var scannerLocation;
		if (center==null||center==''){
			center=ScannerToLoad;
			if (center=='undefined'){
				center='default';
				GoBackPage=Utils.GetGlobalPath()+'/default.htm';}
			goback=GoBackPage;}
		else{
			try{
				goback=GoBackPage;}
			catch(e){
				goback=Utils.GetGlobalPathFullWithQuery();}}
		if (globalPath==''){
			location=Utils.GetGlobalPath()+'/'+m_ScannerLocation+'/';}
		else{
			location=globalPath+'/'+m_ScannerLocation+'/';}
		scannerLocation=location+center+'_'+page+'.htm';
		if(useQuerystring){
			querystring='?scanner='+center+'&goback='+Utils.UrlEncode(goback);}
		// double check that the eula is accepted
		if (GetSubkey('Eula',m_EulaKey)==''){
			DocumentProperties.SetLocationHREF(location+'eula.htm'+querystring);}
		else{
			m_TestingForControl=true;
			var object={
				Id:"ObjControl",
				CodeBase:g_CodeBase.substring(g_CodeBase.indexOf('#')),
				ClassId:m_ClassId,
				OnError:"TFCFailure('"+location+"','"+querystring+"');",
				OnReadyState:"TFCSuccess("+popup+",'"+scannerLocation+"');",
				Params:[
					{Name:"Locale",Value:g_LangMark}]}
			$('ObjControl').outerHTML=Utils.ObjectToString(object);}}

}

// these need to be outside the object since there
// is no Scanner instance when they are called
var m_TFCError=false;
var m_TestingForControl=false;
var m_AppEventHandled=null;

function TFCSuccess(popup, scannerLocation)
{
	if (!m_TFCError)
	{
		Utils.ResetScannerControl();
		if ((Browser.OS == 'Vista' || Browser.OS == 'Win7') && m_AppEventHandled == null)
		{
			setTimeout('TFCSuccess(' + popup + ',"' + scannerLocation + '");', 200);
		}
		else
		{
			if (popup)
			{
				OpenWindow(scannerLocation, 'scanner', 'a1OnlineScan');
				try
				{
					if (GoBackPage)
					{
						setTimeout("window.navigate('" + GoBackPage + "')", 1000);
					}
				}
				catch(e) {}
			}
			else
			{
				DocumentProperties.SetLocationHREF(scannerLocation);
			}
		}
	}
}

function TFCFailure(location, querystring)
{
	m_TFCError = true;
	Utils.ResetScannerControl();
	DocumentProperties.SetLocationHREF(location + 'install.htm' + querystring);
}	
