function checkSecuritySettings()
{
  if ((navigator.userAgent.indexOf("Opera")!=-1)||(navigator.userAgent.indexOf("MSIE")==-1)||(window.opera)) alert ("This page can only be viewed with Microsoft Internet Explorer");

  var pObjDoc;

  try
  {
    pObjDoc=new ActiveXObject("Microsoft.XMLDOM");
    if (pObjDoc.load('http://spb.com/ext/benchmark/devices/iPAQ3600.xml'))
       return true;
  }
  catch (e)
  {
    try
    {
      pObjDoc=document.implementation.createDocument("","",null);
      pObjDoc.async="false";
      if (pObjDoc.load('http://spb.com/ext/benchmark/devices/iPAQ3600.xml'))
             return true;
    }
    catch (e)
    {
      return false;
    }
  } 
  return true;
}

/////////////////////////////////////////////////
// DeviceBenchmarkHeader

function DeviceBenchmarkHeader(strName, strDate)
{
  this.m_strName = strName ? strName : "";
  this.m_strDate = strDate ? strDate : "";
}

/////////////////////////////////////////////////
// DeviceParser

function DeviceParser(strXML, strURL)
{
  this.m_strXML = strXML ? strXML : null;
  this.m_strURL = strURL ? strURL : null;
  this.m_pNext = null;
  this.m_bSelected = true;
  this.m_pHeader = new DeviceBenchmarkHeader("", "");
  this.m_bOk = null;
  this.m_pObjDoc = null;
  this.m_pChain = null;
  this.State = _DeviceParser_State;
  this.Run = _DeviceParser_Run;
  this.Finish = _DeviceParser_Finish;

  if (this.m_strXML == "")
    this.m_strXML = null;

  if (this.m_strURL == "")
    this.m_strURL = null;

  if (this.m_strXML != null)
    this.m_strURL = null;

  if (this.m_strURL != null)
    this.m_strXML = null;

  if (this.m_strXML != null)
    this.m_strXML = this.m_strXML.replace(/^\-\s*</g, "<");  // replace "- <" with " <" to handle copy/paste from IE
}

var g_pCurParser = null;

function ParserState()
{
  if (g_pCurParser)
    g_pCurParser.State();
}

function _DeviceParser_State()
{
  if (this.m_bOk != null || !this.m_pObjDoc)
    return;

  if (this.m_pObjDoc.readyState != 4)
    return;

  do {
/*
  if (this.m_pObjDoc.parseError != 0)
    break;
*/
  this.Finish(true);
  return;

  } while (false);

  this.Finish(false);
}

function _DeviceParser_Run()
{
  g_pCurParser = null;

  if (!this.m_bSelected)
  {
    if (this.m_pNext)
      this.m_pNext.Run();
    else if (this.m_pChain)
      this.m_pChain.Finish();

    return;
  }

  if (this.m_strXML != null)
  {
    this.m_bOk = null;

    try
    {
     this.m_pObjDoc = new ActiveXObject("Microsoft.XMLDOM");
    }
    catch (e)
    {
     this.m_pObjDoc = document.implementation.createDocument("","",null);
     this.m_pObjDoc.async="false";
    }


    if (this.m_pObjDoc.loadXML(this.m_strXML))
    {
      this.Finish(true);
      return;
    }
  }

  if (this.m_strURL != null)
  {
    g_pCurParser = this;
    this.m_bOk = null;
    
    try
    {
     this.m_pObjDoc = new ActiveXObject("Microsoft.XMLDOM");
    }
    catch (e)
    {
     this.m_pObjDoc = document.implementation.createDocument("","",null);
     this.m_pObjDoc.async="false";
    }
    
    this.m_pObjDoc.onreadystatechange = ParserState;

    if (this.m_pObjDoc.load(this.m_strURL))
      return;
  }

  this.Finish(false);
}

function _DeviceParser_Finish(bOk)
{
  g_pCurParser = null;

  this.m_bOk = false;

  do {

  if (!bOk)
    break;

  if (!this.m_pObjDoc)
    break;

  var pRootSec = null;
  var pHeaderSec = null;
  var pNameSec = null;
  var pDateSec = null;

  if (!(pRootSec = this.m_pObjDoc.documentElement))
    break;

  if (!(pHeaderSec = pRootSec.selectSingleNode("info")))
    break;

  if (!(pNameSec = pHeaderSec.selectSingleNode("device-name")))
  {
    if (!(pNameSec = pHeaderSec.selectSingleNode("platform-name")))
      break;
  }

  pDateSec = pHeaderSec.selectSingleNode("start-date");

  this.m_bOk = true;
  this.m_pHeader.m_strName = pNameSec.text;
  this.m_pHeader.m_strDate = pDateSec ? pDateSec.text : "";

  } while (false);  

  if (this.m_pObjDoc)
    this.m_pObjDoc.onreadystatechange = new Function();

  if (!this.m_bOk)
    this.m_pObjDoc = null;

  if (this.m_pNext)
    this.m_pNext.Run();
  else if (this.m_pChain)
    this.m_pChain.Finish();
}

/////////////////////////////////////////////////
// DeviceParsersChain

var DPS_NOT_STARTED = 0;
var DPS_IN_PROGRESS = 1;
var DPS_FINISHED = 2;

function DeviceParsersChain(fCallOnFinish, pInfoPtr)
{
  this.m_pHead = null;
  this.m_pTail = null;
  this.m_nState = DPS_NOT_STARTED;
  this.m_fCallOnFinish = fCallOnFinish ? fCallOnFinish : null;
  this.m_pInfoPtr = pInfoPtr ? pInfoPtr : null;
  this.AddXML = _DeviceParsersChain_AddXML;
  this.AddURL = _DeviceParsersChain_AddURL;
  this.Add = _DeviceParsersChain_Add;
  this.Run = _DeviceParsersChain_Run;
  this.Delete = _DeviceParsersChain_Delete;
  this.GetSelectedCount = _DeviceParsersChain_GetSelectedCount;
  this.Finish = _DeviceParsersChain_Finish;
}

function _DeviceParsersChain_GetSelectedCount()
{
  var nCount = 0;
  var p = this.m_pHead.m_pNext;

  while (p)
  {
    if (p.m_bSelected)
      nCount++;

    p = p.m_pNext;
  }

  return nCount;
}

function _DeviceParsersChain_AddXML(strXML)
{
  if (this.m_nState == DPS_IN_PROGRESS)
    return false;

  if (strXML == null || strXML == "")
    return false;

  return this.Add(new DeviceParser(strXML, null));
}

function _DeviceParsersChain_AddURL(strURL)
{
  if (this.m_nState == DPS_IN_PROGRESS)
    return false;

  if (strURL == null || strURL == "")
    return false;

  return this.Add(new DeviceParser(null, strURL));
}

function _DeviceParsersChain_Add(pDeviceParser)
{
  if (this.m_nState == DPS_IN_PROGRESS)
    return false;

  if (pDeviceParser == null)
    return false;

  pDeviceParser.m_pChain = this;

  if (!this.m_pTail)
    this.m_pHead = pDeviceParser;
  else
    this.m_pTail.m_pNext = pDeviceParser;

  this.m_pTail = pDeviceParser;
  this.m_pTail.m_pNext = null;

  return true;
}

function _DeviceParsersChain_Finish()
{
  this.m_nState = DPS_FINISHED;

  if (this.m_fCallOnFinish)
    this.m_fCallOnFinish(this.m_pInfoPtr);
}

function _DeviceParsersChain_Run()
{
  if (this.m_nState == DPS_IN_PROGRESS)
    return;

  if (!this.m_pHead)
    return;

  this.m_nState = DPS_IN_PROGRESS;
  this.m_pHead.Run();
}

function _DeviceParsersChain_Delete(nID)
{
  if (this.m_nState == DPS_IN_PROGRESS)
    return;

  if (!this.m_pHead)
    return;

  var p = this.m_pHead;

  while (p && p.m_pNext)
  {
    if (p.m_pNext.m_nID != null && p.m_pNext.m_nID == nID)
    {
      if (p == this.m_pHead)
      {
        this.m_pHead = null;
        this.m_pTail = null;
      }
      else
      {
        if (!p.m_pNext.m_pNext)
          this.m_pTail = p;

        p.m_pNext = p.m_pNext.m_pNext;
      }

      return;
    }

    p = p.m_pNext;
  }
}

