//DevNote: constants in C++ CommonShp.h should be updated to match any changes in here
var _bMSR_PPC02 = 1;
var _bMSR_PPC03 = 2;
var _bMSR_TABLET = 4;
var _bMSR_DESKTOP = 8;
var _bMSR_WIN32 = 16;
var _bMSR_UNKNOWN = 32;
var _bMSR_RDR_NONE = 64;
var _bMSR_RDR_OLD = 128;
var _bMSR_RDR_CURR = 256;
var _bMSR_RDR_UNKNOWN = 512;
var _bMSR_BB_NONE = 1024;
var _bMSR_BB_OLD = 2048;
var _bMSR_BB_CURR = 4096;
var _bMSR_BB_UNKNOWN = 8192;

var _nMSR_State = 0;
var _szMSR_ReaderVer = "";
var _fMSR_NewAPI = false;

if (_fMSReaderInstalled)
{
  //If GetMSReaderVersion() returns 3 digits, the new dasshp.dll is installed
  _szMSR_ReaderVer = MSReaderWebShop_GetMSReaderVersion();
  _fMSR_NewAPI = (_szMSR_ReaderVer.indexOf('.') != _szMSR_ReaderVer.lastIndexOf('.'));
}

function jsGetPlatform()
{
  if (-1 != navigator.userAgent.indexOf("Windows CE"))
  {
	  if (-1 != navigator.userAgent.indexOf("MSIE 3.02"))
	    return _bMSR_PPC02;
	  else if (_nIE_Ver > 3)
	    return _bMSR_PPC03;
	}
  
  if (-1 != navigator.platform.indexOf("Win32"))
    return _bMSR_WIN32;
  else
    return _bMSR_UNKNOWN;
}

//Only called if old (prior to May 2003) dasshp.dll exists on user's machine.
//New dasshp.dll on client machine will not let the code get here.
function MSReaderWebShop_GetMSReaderStateOld()
{
  nState = jsGetPlatform();

  if (MSReaderWebShop_AnyActivation())
  {
    nState |= _bMSR_BB_OLD;
  }
  else
  {
    nState |= _bMSR_BB_NONE;
  }

  //Since we know they have an old dasshp.dll, we know for a fact that they either have
  //and old reader or NO reader on their machine.  This is because the New Reader will
  //always ship with the New Dasshp.dll
  if ("" == _szMSR_ReaderVer)
  {
    nState |= _bMSR_RDR_NONE;
  }
  else
  {
    nState |= _bMSR_RDR_UNKNOWN;
  }

  return nState;
}

//
//Return true if ANY activation of machine, even if it's an OLD one
//
function MSReaderWebShop_AnyActivation()
{
 if (!_fMSReaderInstalled)
  return false;

 if (_fIE)
 {
  if (0 == _MSReaderWebShop.IsMSReaderActivated())
   return false;
 } else
 {
  if (0 == document.MSReaderWebShop.IsMSReaderActivated())
   return false;
 }
 return true;
}


function MSReaderWebShop_GetMSReaderState()
{
  if (_fMSReaderInstalled)
  {
    if (_fMSR_NewAPI)
    {
      if (_fIE)
      {
        _nMSR_State = _MSReaderWebShop.GetMSReaderState();
      }
      else
      {
        _nMSR_State = document.MSReaderWebShop.GetMSReaderState();
      }
    }
    else
    {
      _nMSR_State = MSReaderWebShop_GetMSReaderStateOld();  
    }
  }
  else
  {
    _nMSR_State = jsGetPlatform();
    _nMSR_State |= (_bMSR_RDR_UNKNOWN | _bMSR_BB_UNKNOWN);
  }
} 

//Call GetReaderState when this script is included, this will ensure that _nMSR_State is set appropriately
MSReaderWebShop_GetMSReaderState();