var myDLM;
var myUser = '';

var logcount = 0;

var logMessages = new Array();
var initLogs = 0;
var isW3C = ((document.getElementByID) ? true : false); // Exp 5+, NS6+, KHTML(Safari, Konqueror)

// Error Constants
var ERR_APPLET_TAG = '-2147185688';
var ERR_OBJECT_TAG = '-2147185687';
var ERR_CONTROL_LOAD = '-2147185686';
var ERR_APPLET_PERMISSIONS = '-2147186688';

var REDIRECT_PAGE = 'download-redirect';

function downloadZinio(cmd, arg, noReaderURL, unsuppBrowserURL, unsuppOsURL, user, uid)
{	
	myUser = uid;

	if (! myDLM)
	{
		myDLM = new DLM();
		myDLM.acquireVersion();
	}

	if (uid && myDLM.uid)
	{
		if (uid.toUpperCase() != myDLM.uid.toUpperCase())
		{
			DLMRedirect();
			return;
		}
	}

	if (myDLM.brwType == 'mac')
	{
		return;
	}
	else if (myDLM.brwType == 'unsuppOS')
	{
		document.location.href = unsuppOsURL;
	}
	else if (myDLM.brwType == 'unsuppBrowser')
	{
		DLMRedirect();
	}
	else
	{	
		if (myDLM.DLMValid())
		{
			var rv = 1;
			cmd = cmd.toLowerCase();
			if (cmd == 'tickle')
			{
				rv = myDLM.tickleDLM();
			}
			else if (cmd == 'push')
			{
				rv = myDLM.pushContent(arg);
			}
			else if (cmd == 'pushlist')
			{
				rv = myDLM.pushContentList(arg);
			}
			else if (cmd == 'sniff')
			{
				myDLM.sniff(arg);
			}
			else
			{
				//window.alert('invalid or no cmd given.	Cmd = "' + cmd + '"');
			}
			return rv;
		}
		else
		{
			// Redirect will execute in 8 seconds.
			window.setTimeout('DLMRedirect()', 8000);
		}
	}
}

function DLMRedirect() {
	document.location.href = REDIRECT_PAGE;
}

function rdrStatus(require, dmCurrent, rdCurrent)
{
	if (! myDLM)
	{
		myDLM = new DLM();
		myDLM.acquireVersion();
	}
	myDLM.verifyReader(require, dmCurrent, rdCurrent);
}
function chkBrowser() {


	var agt=navigator.userAgent.toLowerCase();
	var plt=navigator.platform.toLowerCase();

	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	var is_win95 = (agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1);

	var is_winnt4 =
			(agt.indexOf("winnt4")!=-1)				||
			(agt.indexOf('windows nt4')!=-1)	||
			(agt.indexOf('windows nt 4')!=-1) ||
			(agt.indexOf("winnt3")!=-1)				||
			(agt.indexOf('windows nt3')!=-1)	||
			(agt.indexOf('windows nt 3')!=-1);

	var is_win32 =
		(is_winnt4) ||
		(agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1) ||
		(agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1) ||
		(agt.indexOf("win2k")!=-1) || (agt.indexOf("windows 2000")!=-1) ||
		(agt.indexOf("win9x")!=-1) || (agt.indexOf("windows 2000")!=-1) ||
		((is_major >= 4) && (navigator.platform == "Win32")) ||
		(agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1);

	var is_mac = (agt.indexOf("mac") != -1
			|| agt.indexOf("apple") != -1
			|| plt.indexOf("mac") != -1
			|| plt.indexOf("ppc") != -1);

	var isW3C = ((document.getElementByID) ? true : false); // Exp 5+, NS6+, KHTML(Safari, Konqueror)

	result = 'unsuppBrowser';

	if (is_mac)
	{
		return "mac";
	}

	if (is_win32 == false || is_win95==true)
	{
		return 'unsuppOS';
	}

	if (agt.indexOf("msie") != -1)
	{
		if (is_major < 4)
		{
			result = 'ie3';
		}
		else if (agt.indexOf("msie 7.0") > 0
				|| agt.indexOf("msie 6.0") > 0
				|| agt.indexOf("msie 5.5") > 0)
		{
			result = 'ie5up';			
		}
		else if ((is_major == 4) && (agt.indexOf("msie 5.0")==-1))
		{
			//return 'ie4'; // but ie4 is unsupported
		}
		else if (agt.indexOf("opera") == -1)
		{
			result = 'ie5up';
		}
	}
	else
	{
		if (agt.indexOf('opera') != -1)
		{
			result = 'opera';
		}
		else if (agt.indexOf('webtv') != -1)
		{
			result = 'webtv';
		}
		else
		{
			// Note: Opera and WebTV spoof Navigator.
			var is_nav = ((agt.indexOf('mozilla')!=-1)
					   && (agt.indexOf('compatible') == -1));

			if (is_nav == true)
			{
				if (is_minor >= 4.06 && is_minor < 5.00)
				{
					result = 'netscape4';
				}
				else if (is_minor >= 5.00)
				{
					//result = 'netscape6';
				}
			}
		}

	}
	return result;
}

/*
 *	Reader Installer Code -------------------------------------------------
 */

var brw, player, ether;

function getDocID(line)
{
	if (line)
	{
		var idx = line.indexOf("&DocID=");
		if (idx != -1)
		{
			idx += 7;
			var idx2 = line.indexOf("&", idx);
			if (idx2 == -1)
			{
				return line.substr(idx);
			}
			else
			{
				return line.substring(idx, idx2);
			}
		}
	}
	return "-1";
}

function startInstall(installerCmdLine)
{
		if (! ether)
		{
			idxLog(2);
			return -1;
		}
		idxLog(5);

		var docid = getDocID(installerCmdLine);
		if (docid == '-1')
		{
			idxLog(9);
		}
		else
		{
			idxLog(8, docid);
		}

		ether.LegacyMode=true;
		ether.CommandLine=installerCmdLine
		ether.Play();
		return 1;
}

function calcDownloadSize() {
	var intDldSizeKB = ether.GetDownloadSize() / 1024;

	if ((intDldSizeKB / 1024)  < 1)
		strDldSize = 'Download size: ' + Math.round(intDldSizeKB * 100) / 100 + ' Kb';
	else
		strDldSize = 'Download size: ' + Math.round(intDldSizeKB / 10.24) / 100 + ' MB';
	return strDldSize;
}

/* This function is inititated by the onload attribute in the body tag.  It
triggers the appropriate course of action based on the browser detected. */

function parseUserName(arglist)
{
	var start= arglist.indexOf("&username=");
	var end  = arglist.indexOf("&", start + 10);
	myUser = arglist.substring(start + 10, end);
}

var spaces = "";
var spacecount = 0;

function errorPage(msg, url, lno)
{
	document.location.href='./GetReader?action=error';
	idxLog(10, "[ " + msg + " ] at line " + lno);
	return true;
}

function StartUp(pathArg, setupUrl)
{

	onError=errorPage;

	parseUserName(setupUrl);

	idxLog(6);

	if (! myDLM)
	{
		myDLM = new DLM();
		myDLM.acquireVersion();
	}

	if (spacecount >= 14)
	{
		spacecount = 0;
		spaces = "";
	}
	else
	{
		spacecount ++;
		spaces = "	 " + spaces;
	}

	if (myDLM.isIE())
	{
		if (!document.all['playerIE'])
		{
			objError(ERR_OBJECT_TAG);
			document.location.href='./GetReader?action=error';
			return;
		}
		player = document.all['playerIE'];
	}
	else if (myDLM.isN4())
	{
		if (!document.SetupPlayer)
		{
			objError(ERR_APPLET_TAG);
			document.location.href='./GetReader?action=error';
			return;
		}
		player = document.SetupPlayer;
	}
	else
	{
		if (myDLM.brwType == 'unsuppOS')
		{
			window.location.href = "./uos?ctrl=playerinstall";
			return;
		}
		else if (myDLM.brwType == 'unsuppBrowser')
		{
			window.location.href = "./ubr?ctrl=playerinstall";
			return;
		}
		else
		{
			window.location.href= "./ubr?ctrl=br+is+" + myDLM.brwType;
		}
		return;
	}

	writeCommentText("Loading page, please wait...");
	scriptPlayer(pathArg);

	if (startInstall(setupUrl) > 0)
	{
		document.location.href='./GetReader?action=ok';
	}
	else
	{
		document.location.href='./GetReader?action=error';
	}
}

function scriptPlayer(strSetupURL)
{
	// Catch player initialize error
	if ((!player) || (typeof(player.LastError) != "number"))
	{
		playerError(ERR_CONTROL_LOAD);
		return;
	}
	else
	{
		if (player.LastError != 0)
		{
			playerError(player.LastError);
			return;
		}
	}

	// Open the setup
	ether = player.Open(strSetupURL);

	// Catch player open error
	if (!ether)
	{
		playerError(player.LastError);
		return;
	}

	// App not installed, set TargetDir and setup type
	if (!ether.IsInstalled())
	{
		var strTargetDir = ether.GetTextSub("PROGRAMFILES") + ether.ProductName;
		ether.SetTargetDir(strTargetDir);
		ether.SetSetupType("Typical");
	}

	var strDldSize = calcDownloadSize();
	writeCommentText(strDldSize);
}

function objError(nErrNum)
{
	idxLog(7, 'Error loading ISPlayer on browser.  (Error code ' + nErrNum + ')');
}

function playerError(nErrNum)
{
	strErrMsg = '(player) Unable to start setup.	Error code ';
	if (nErrNum == ERR_CONTROL_LOAD)
	{
		strErrMsg = '(player) Cannot load setup control.	Permissions?	Error code ';
	}
	else if (nErrNum == ERR_APPLET_PERMISSIONS)
	{
		strErrMsg = '(player) Cannot run setup applet.	Permissions?	Error code ';
	}
	idxLog(7, strErrMsg + nErrNum);
}

/*
 *	End of Reader Installer Code -------------------------------------------------
 */

/*
 * Browser writing functions
 */
function writeCommentText(msg)
{
	window.status = msg;
}

function writeText(pageLocation, msg)
{
	if (document.all || isW3C)
	{
		pageLocation = "ms" + pageLocation;
		_writeHere = isW3C ? document.getElementById(pageLocation) : document.all[pageLocation];
		if (_writeHere)
		{
			_writeHere.innerHTML = msg;
		}
	}
	else if (document.layers)
	{
		pageLocation = "ns" + pageLocation;
		if (document.layers[pageLocation])
		{
			document.layers[pageLocation].document.write(msg);
			document.layers[pageLocation].document.close();
		}
	}
}


function idxLog(idx, errmsg)
{
	if (initLogs == 0)
	{
		logMessages[0] = new LogMessage('server: Tickling DLM', 'OK');
		logMessages[1] = new LogMessage('server: Pushing Content', 'OK');
		logMessages[2] = new LogMessage('server: IS Player Not Loaded', 'ERR');
		logMessages[3] = new LogMessage('server: Retrying Installation', 'OK');
		logMessages[4] = new LogMessage('server: No Retry', 'ERR');
		logMessages[5] = new LogMessage('server: IS Player Loaded; commencing installation', 'OK');
		logMessages[6] = new LogMessage('server: Clicked DownloadNow button', 'OK');
		logMessages[7] = new LogMessage('server: IS Player error code ', 'ERR');
		logMessages[8] = new LogMessage('server: Pushed DocID', 'OK');
		logMessages[9] = new LogMessage('server: No DocID pushed', 'OK');
		logMessages[10] = new LogMessage('server: JavascriptError', 'OK');
		initLogs = 1;
	}

	if (errmsg)
	{
		logMessages[idx].errorMsg(errmsg);
	}
	else
	{
		logMessages[idx].writeMsg();
	}
}

function writeLogMsg(logUrl, retimg, msg, version, resp, brw, user, agent, platform)
{
	var imgname = logUrl + '?obfc=' + logcount;

		if (retimg)
		{
			imgname += '&img=true';
		}
		imgname +=
		  '&msg='+ escape(msg)
		+ '&ver='+ escape(version)
		+ '&rc='+ escape(resp)
		+ '&brw='+ escape(brw)
		+ '&xuserid='+ escape(user)
		+ '&agt='+ escape(agent)
		+ '&plat=' + escape(platform);

	if (document.images && document.images["msg"])
	{
		document.images["msg"].src = imgname;
	}
	logcount++;
}

/*
 * OnLoad functions ---------------
 */
var gSafeOnload = new Array();

function addLoadFunction(f)
{
	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4 = (((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false);

	IE45Mac = (  (document.all) && (isMac)
						&& ((navigator.appVersion.indexOf("MSIE 4.") != -1) ? true : false));
	isW3C = (document.getElementByID) ? true : false // Exp 5+, NS6+, KHTML(Safari, Konqueror)

	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SafeOnload;
		gSafeOnload[gSafeOnload.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SafeOnload)
		{
			gSafeOnload[0] = window.onload;
			window.onload = SafeOnload;
		}
		gSafeOnload[gSafeOnload.length] = f;
	}
	else
	{
		window.onload = f;
	}
}

function SafeOnload()
{
	for (var i=0;i<gSafeOnload.length;i++)
		gSafeOnload[i]();
}

function statbrw(pre)
{
	var val = checkAttrs();
	if (pre != val)
	{
		var hdr = 15;
		var cv = '' + hdr + '.' + val;
		//alert("cookie set, pre = " + pre + ", val = " + val);
		var exp = new Date();
		exp.setTime(exp.getTime() + 1800000);
		setCookie("bc", cv, exp, "/", false, false);

		//alert("Set cookie, value = " + document.cookie);
	}
	else
	{
		//alert("cookie not set, pre = " + pre + ", val = " + val);
	}
	//alert("Cookies = " + document.cookie);
}


function checkAttrs()
{
	var val = 2;
	if (testCookies()) val += 1;
	if (testActiveX()) val += 4;
	if (testJava())		 val += 8;
	return val;
}

function testActiveX()
{
	if (document.all && chkBrowser()=='ie5up')
	{
		return true;
		//onError=null;
		//CheckActiveX();
		//return (ActiveX == 1);
	}
	return false;
}

function testCookies()
{
	if(document.cookie != '') { return true; }
	document.cookie = 'cookies=yes';
	return (document.cookie.indexOf('cookies=yes') != -1);
}

function testJava()
{
	return navigator.javaEnabled();
}

function showButton()
{
	modButton(true);
}

function modButton(showIt)
{
	if (document.all || isW3C)
	{
		_msg = isW3C ? document.getElementByID('thePreMessage') : document.all.thePreMessage;
		_btn = isW3C ? document.getElementByID('theButton') : document.all.theButton;

		if (_msg && _btn)
		{
			_msg.style.visibility = (showIt ? "hidden" : "visible");
			_btn.style.visibility = (showIt ? "visible" : "hidden");
		}
	}
	else if (document.layers)
	{
		if (document.layers['thePreMessage'] && document.layers['theButton'])
		{
			document.layers['thePreMessage'].visibility=(showIt ? "hide" : "show");
			document.layers['theButton'].visibility=(showIt ? "show" : "hide");
		}
	}
}

function hideButton()
{
	modButton(false);
}

function cj()
{
	deleteCookie('cj');
	document.cookie='cj=1;PATH=/';
}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function getCookieVal(offset) {
		 var endstr = document.cookie.indexOf (";", offset);
		 if (endstr == -1)
				 endstr = document.cookie.length;
		 return unescape(document.cookie.substring(offset, endstr));
}

function deleteCookie(name,path,domain)
{
	if (getCookie(name))
	{
		 document.cookie = name + "=" +
			 ((path) ? "; path=" + path : "") +
			 ((domain) ? "; domain=" + domain : "") +
			 "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/* -----------------------------------
 */

/*
 * Version object
 */

function versionObj(verStr)
{
	if (! verStr)
	{
		this.versionNum = "0,0,0,0";
	}
	else
	{
		this.versionNum = "" + verStr;
	}

	this.pversion = this.versionNum.replace(/\,/g, '.');

	var vv = this.versionNum.split(",");

	this.major		= vv[0];
	this.minor		= vv[1];
	this.subminor = vv[2];
	this.build		= vv[3];
}

function LogMessage(msg, stat)
{
	this.message = msg;
	this.status = stat;

	if (! myDLM)
	{
		myDLM = new DLM();
		myDLM.acquireVersion();
	}

	this.url = './logmsg';
	this.sendImg = true;
	this.agent = navigator.userAgent;
	this.platform = navigator.platform;
	this.brwType = myDLM.brwType;
	this.version = myDLM.DMVersion.versionNum;

	this.writeMsg = LOG_writeMsg;
	this.errorMsg = LOG_errMsg;
}

function LOG_writeMsg()
{
	writeLogMsg(
		this.url,
		this.sendImg,
		this.message,
		this.version,
		this.status,
		this.brwType,
		myUser,
		this.agent,
		this.platform);
}

function LOG_errMsg(ermsg)
{
	writeLogMsg(
		this.url,
		this.sendImg,
		this.message + ' ' + ermsg,
		this.version,
		this.status,
		this.brwType,
		myUser,
		this.agent,
		this.platform);
}



/*
 * DM Control Object
 */
function DLM()
{
	this.brwType = chkBrowser();

	this.dmCtrlWritten = false;
	this.ctrlName="DLMCtrl";
	this.MSctrlHandle='<OBJECT ID="'
		+ this.ctrlName
		+ '" CLASSID="CLSID:BD2EA4B4-B214-49CF-9A07-D9115059DD71" WIDTH="0" HEIGHT="0"></OBJECT>';

	this.DMVersion = new versionObj('0,0,0,0');
	this.RDVersion = new versionObj('0,0,0,0');
	this.InsType = '';
	this.CSID = '';
	this.BRID = '';
	this.email = '';
	this.uid = '';

	this.hasExFunctions = false;

	this.tickleDLM		 = DLM_tickleDLM;
	this.pushContent	 = DLM_pushContent;
	this.pushContentList = DLM_pushContentList;
	this.acquireVersion  = DLM_acquireVersion;
	this.DLMValid		 = DLM_Valid;
	this.writeControl	 = DLM_writeDMControlHandle;
	this.sniff			 = DLM_sniff;
	this.getControl		 = DLM_getControl;
	this.verifyReader	 = DLM_verifyReader;

	this.isIE			 = DLM_isIE;
	this.isN4			 = DLM_isN4;
	this.isN6			 = DLM_isN6;
	this.isOpera		 = DLM_isOpera;
	this.brwValid		 = DLM_brwValid;



	this.writeControl();
	this.dlmCtrl = this.getControl();
}

	function DLM_brwValid()
	{
		return (this.isIE() || this.isN4());
	}

	function DLM_isIE()
	{
		return (this.brwType == 'ie5up');
	}

	function DLM_isN4()
	{
		return (this.brwType == 'netscape4');
	}

	function DLM_isN6()
	{
		return (this.brwType == 'netscape6');
	}

	function DLM_isOpera()
	{
		return (this.brwType == 'opera');
	}

	function DLM_Valid()
	{
		if (this.isN4())
		{
			var obj = document.embeds['DLMCtrl'];
			return (obj && obj.ZDLMIsValid());
		}
		if (this.isIE())
		{
			return (this.dlmCtrl && this.dlmCtrl.DLMIsValid);
		}
		else
		{
			return false;
		}
	}

	function DLM_tickleDLM()
	{
		var rv = 1;
		idxLog(0);

		try
		{
			if (this.dlmCtrl)
			{
				if (this.isN4())
				{
					if (this.hasExFunctions)
					{
						rv = this.dlmCtrl.TickleDLMEx();
					}
					else
					{
						this.dlmCtrl.TickleDLM();
					}
				} else if (this.isIE()) {
					if (this.hasExFunctions)
					{
						rv = this.dlmCtrl.TickleDLMEx();
					}
					else
					{
						this.dlmCtrl.TickleDLM();
					}
				}
			}
			else
			{
				return -1;
			}		
		}
		
		catch (e) {
			idxLog(0, 'Exception occurred');
			DLMRedirect();			
		}
		
		return rv;
	}

	function DLM_pushContentList(args)
	{
		idxLog(1, 'List');
		var myArr = args;
		rv = 0;

		try 
		{
			for (ii=0; ii<myArr.length; ii++)
			{
				rv = this.pushContent(myArr[ii]);
				if (rv == -1)
				{
					break;
				}
			}
		}
		
		catch (e)
		{
			idxLog(1, 'Exception occurred');
			DLMRedirect();			
		}
		
		return rv;
	}

	function DLM_pushContent(args)
	{
		idxLog(1);
		var rv = 1;

		try
		{
			if (this.dlmCtrl)
			{
				if (this.isN4())
				{
					if (this.hasExFunctions)
					{
						rv = this.dlmCtrl.PushContentUrlEx(args);
					}
					else
					{
						this.dlmCtrl.PushContentUrl(args);
					}
				} else if (this.isIE()) {
					if (this.hasExFunctions)
					{
						rv = this.dlmCtrl.PushContentUrlEx(args);
					}
					else
					{
						this.dlmCtrl.PushContentUrl(args);
					}
				}
			}
			else
			{
				return -1;
			}
		}
		
		catch (e)
		{
			idxLog(1, 'Exception occurred');
			DLMRedirect();			
		}
		
		return rv;
	}


	function DLM_acquireVersion()
	{
		var dv = '0,0,0,0';
		var rv = '0,0,0,0';
		if (this.isN4())
		{
			var obj = document.embeds['DLMCtrl'];
			if (obj && obj.ZDLMIsValid())
			{
				if (this.dlmCtrl.ZDLMVersion)
				{
					dv = this.dlmCtrl.ZDLMVersion();
					rv = this.dlmCtrl.ZReaderVersion();
					var vo = new versionObj(dv);
					if (vo.build >= 357)
					{
						this.InsType = this.dlmCtrl.InsType();
						this.BRID = this.dlmCtrl.BRID();
						this.CSID = this.dlmCtrl.CSID();
						this.email= this.dlmCtrl.EMailCG();
						this.uid  = this.dlmCtrl.Username();
					}
				}
				else
				{
					dv = '1,0,0,1';
					rv = '1,0,0,1';
				}
			}
		}
		else if (this.isIE())
		{
			var obj = document.all['DLMCtrl'];
			if (obj && obj.DLMIsValid)
			{
				if (this.dlmCtrl.ZDLMVersion)
				{
					dv = this.dlmCtrl.ZDLMVersion;
					rv = this.dlmCtrl.ZReaderVersion;
				}
				else
				{
					dv = '1,0,0,1';
					rv = '1,0,0,1';
				}
				if (this.dlmCtrl.CSID)
				{
					this.InsType = this.dlmCtrl.InsType;
					this.BRID    = this.dlmCtrl.BRID;
					this.CSID    = this.dlmCtrl.CSID;
					this.email   = this.dlmCtrl.EMailCG;
					this.uid     = this.dlmCtrl.Username;
				}
			}
		}

		if ((!rv || rv == '') && dv == '1,0,0,258')
		{
			rv = dv;
		}

		this.DMVersion = new versionObj(dv);
		this.RDVersion = new versionObj(rv);

		if (this.DMVersion.build > 258) this.hasExFunctions = true;
	}

	function DLM_writeDMControlHandle()
	{
		if (! this.dmCtrlWritten)
		{
			this.dmCtrlWritten = true;
			/*
			if (this.isN4())
			{
				return;
			}
			else if (this.isIE() && testActiveX())
			{
				writeText('obj', this.MSctrlHandle);
			}
			*/
		}
	}

	function DLM_getControl()
	{
		if (this.isN4())
		{
			return document.DLMCtrl;
		}
		else if (this.isIE())
		{
			return document.DLMCtrl;
		}
	}

	function DLM_sniff()
	{
		try
		{
	    	var cv = this.DMVersion.pversion
				+ "+" + this.RDVersion.pversion
				+ "+" + this.InsType
				+ "+" + this.CSID
				+ "+" + this.BRID
				+ "+" + this.uid;

			var exp = new Date();
			exp.setTime(exp.getTime() + 1800000);
			setCookie("rv", cv, exp, false, false, false);
		}
		
		catch (e)
		{
			DLMRedirect();		
		}
	}

	function DLM_verifyReader(require, xu, dmCurrent, rdCurrent)
	{
		this.writeControl('DLMCtrl', this.brwType);

		if ( true
			||	require == 1
			|| (this.uid != xu)
			|| (this.DLMValid()
				&& (   dmCurrent != this.DMVersion.versionNum
					|| rdCurrent != this.RDVersion.versionNum))
			|| (! this.DLMValid() && (dmCurrent != '0,0,0,0' || rdCurrent != '0,0,0,0')))
		{
			this.sniff();
		}
	}

