/*Copyright 2003-2007 Maven Networks, Inc.  All rights reserved.*/
XMLUtils = new Object();
XMLUtils.findNodes =
function (domNode, xpath) {
  var theResult = new Array();
  if (domNode)
    theResult = this.doFindNodes(domNode, xpath, false);
  return theResult;
};
XMLUtils.findNode =
function (domNode, xpath) {
  var theResult = null;
  if (domNode)
    theResult = this.doFindNodes(domNode, xpath, true);
  return theResult;
};
XMLUtils.serializeNode =
function (domNode) {
  var theResult = "";
  if (domNode) {
    if (domNode.innerHTML)
      theResult = domNode.innerHTML;
    else if (window.XMLSerializer) {
      theResult = (new XMLSerializer()).serializeToString(domNode);
    }
    else {
      theResult = domNode.xml;
    }
  }
  return theResult;
};
XMLUtils.textualizeNode =
function (domNode) {
  var theText = "";
  if (domNode) {
    if (this.mIsWin32IE)
      theText = this.textualizeNodeWin32IE(domNode);
    else
      theText = this.textualizeNodeOther(domNode);
  }
  return theText;
};
XMLUtils.getDomDocument =
function () {
  var domDocument = null;
  if (this.mIsWin32IE) {
    if (!this.mIEDOMVersion) 
      this.mIEDOMVersion = this.findActiveXProgID(["Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"]); // removed "Msxml2.DOMDocument.5.0" for IE 7, 
    if (this.mIEDOMVersion) {
      domDocument = new ActiveXObject(this.mIEDOMVersion);
      domDocument.setProperty("SelectionLanguage", "XPath");
    }
  }
  else {
    try {
      domDocument = document.implementation.createDocument("", "", null);
    } catch (e) {}
  }
  return domDocument;
};
XMLUtils.parseXMLFromString =
function (xmlString) {
  var domDocument = null;
  if (this.mIsWin32IE) {
    domDocument = this.getDomDocument();
    domDocument.validateOnParse = false;
    domDocument.loadXML(xmlString);
  }
  else {
    domDocument = (new DOMParser()).parseFromString(xmlString, "text/xml");
  }
  return domDocument;
};
XMLUtils.getXMLHttpRequest =
function () {
  var request = null;
  if (window.XMLHttpRequest) {
    request = new XMLHttpRequest();
  }
  else {
    if (!this.mIEXMLVersion)
      this.mIEXMLVersion = this.findActiveXProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
    if (this.mIEXMLVersion)
      request = new ActiveXObject(this.mIEXMLVersion);
  }
  return request;
};
XMLUtils.setXMLNamespaces =
function (xmlDom, additionalNamespaces) {
  if (xmlDom) {
    if (!additionalNamespaces)
      additionalNamespaces = "";
    var namespaces = XMLUtils.mXMLNamespaces;
    for (var prefix in namespaces)
      additionalNamespaces += " xmlns:" + prefix + "='" + namespaces[prefix] + "'";
    var ownerDoc = ((xmlDom.nodeType != 9) ? xmlDom.ownerDocument : xmlDom);
    try {
      ownerDoc.setProperty("SelectionNamespaces", additionalNamespaces);
    } catch (e) { }
  }
}
XMLUtils.getAttributeNS =
function (domNode, namespaceURI, attributeName) {
  var attribute = null;
  if (domNode) {
    if (this.mIsSafari) {
      if (this.mXMLNamespaces[namespaceURI])
        namespaceURI = this.mXMLNamespaces[namespaceURI];
      attribute = domNode.getAttributeNS(namespaceURI, attributeName);
    }
    else
      attribute = domNode.getAttribute(namespaceURI + ":" + attributeName);
  }
  return attribute;
}
XMLUtils.setAttributeNS =
function (domNode, namespaceURI, attributeName, attributeValue) {
  if (domNode) {
    if (this.mIsSafari) {
      if (this.mXMLNamespaces[namespaceURI])
        namespaceURI = this.mXMLNamespaces[namespaceURI];
      domNode.setAttributeNS(namespaceURI, attributeName, attributeValue);
    }
    else
      attribute = domNode.setAttribute(namespaceURI + ":" + attributeName, attributeValue);
  }
}
XMLUtils.mXMLNamespaces = {app: "http://www.maven.net/mms/application", xsi: "http://www.w3.org/2001/XMLSchema-instance"};
XMLUtils.mIsOSX = (navigator.userAgent.indexOf("Mac") != -1);
XMLUtils.mIsSafari = ((navigator.userAgent.indexOf("Safari") != -1) || (navigator.userAgent.indexOf("AppleWebKit") != -1));
XMLUtils.mIsGecko = (!XMLUtils.mIsSafari && (navigator.product == "Gecko"));
XMLUtils.mIsWin32IE = (navigator.userAgent.indexOf("MSIE") != -1);
XMLUtils.mIEXMLVersion = null;
XMLUtils.mIEDOMVersion = null;
XMLUtils.doFindNodes =
function (domNode, xpath, oneNode) {
  var theResult;
  if (this.mIsWin32IE) {
    theResult = this.doFindNodesWin32IE(domNode, xpath, oneNode);
  }
  else if (this.mIsGecko) {
    theResult = this.doFindNodesGecko(domNode, xpath, oneNode);
  }
  else {
    theResult = this.doFindNodesOther(domNode, xpath, oneNode);
  }
  return theResult;
};
XMLUtils.doFindNodesWin32IE =
function (domNode, xpath, oneNode) {
  var theResult = null;
  if (oneNode)
    theResult = domNode.selectSingleNode(xpath);
  else
    theResult = domNode.selectNodes(xpath);
  return theResult;
};
XMLUtils.doFindNodesGecko =
function (domNode, xpath, oneNode) {
  var theResult = null;
  var ownerDoc = ((domNode.nodeType != 9) ? domNode.ownerDocument : domNode);
  try {
    var oResult = ownerDoc.evaluate(xpath, domNode,
                ownerDoc.createNSResolver(ownerDoc.documentElement),
                XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    if (oneNode) {
      if (oResult.snapshotLength > 0)
        theResult = oResult.snapshotItem(0);
    }
    else {
      theResult = new Array();
      for (var i = 0; i < oResult.snapshotLength; i++)
        theResult.push(oResult.snapshotItem(i));
    }
  } catch (e) {} // do nothing
  return theResult;
};
XMLUtils.doFindNodesOther =
function (domNode, xpath, oneNode) {
  var theResult = null;
  if (xpath.charAt(0) == "/") {
    if (domNode.nodeType != 9)
      domNode = domNode.ownerDocument;
    xpath = xpath.substring(1);
  }
  var nodeList = new Array();
  if (domNode) {
    nodeList = this.doFindNodesOtherRecursion(domNode, xpath, oneNode);
  }
  if (oneNode) {
    if (nodeList.length > 0)
      theResult = nodeList[0];
  }
  else
    theResult = nodeList;
  return theResult;
};
XMLUtils.doFindNodesOtherRecursion =
function (domNode, xpath, oneNode) {
  var nodeList = new Array();
  var anyDescendent = false;
  if (xpath.charAt(0) == "/") {
    anyDescendent = true;
    xpath = xpath.substring(1);
  }
  var targetNodeName = "";
  var nextSlash = xpath.indexOf("/");
  if (nextSlash == -1) {
    targetNodeName = xpath;
    xpath = "";
  }
  else {
    targetNodeName = xpath.substring(0, nextSlash);
    xpath = xpath.substring(nextSlash + 1);
  }
  var matchingNodes;
  var namespaceSep = targetNodeName.indexOf(":");
  var indexSep = targetNodeName.indexOf("[");
  var indexNum = -1;
  if (indexSep != -1) {
    indexNum = parseInt(targetNodeName.substring(indexSep + 1), 10);
    if (isNaN(indexNum))
      indexNum = -1;
    else
      indexNum--;
    targetNodeName = targetNodeName.substring(0, indexSep);
  }
  if (namespaceSep != -1) {
    var namespaceURI = targetNodeName.substring(0, namespaceSep);
    if (this.mXMLNamespaces[namespaceURI])
      namespaceURI = this.mXMLNamespaces[namespaceURI];
    matchingNodes = domNode.getElementsByTagNameNS(namespaceURI, targetNodeName.substring(namespaceSep + 1));
  }
  else
    matchingNodes = domNode.getElementsByTagName(targetNodeName);
  var aNode;
  var matchingParentNodes = new Array();
  if (anyDescendent)
    matchingParentNodes = matchingNodes;
  else {
    for (var i = 0; i < matchingNodes.length; i++) {
      aNode = matchingNodes[i];
      if (aNode.parentNode == domNode)
        matchingParentNodes.push(aNode);
    }
  }
  var constrainedNodes = new Array();
  if (indexNum >= 0) {
    if (!anyDescendent) {
      if (indexNum < matchingParentNodes.length)
        constrainedNodes.push(matchingParentNodes[indexNum])
    }
    else {
      var parentNodes = new Array();
      var foundParent = false;
      var i, j, aNode, aParentNode;
      for (i = 0; i < matchingParentNodes.length; i++) {
        aNode = matchingParentNodes[i];
        foundParent = false;
        for (j = 0; j < parentNodes.length; j++) {
          aParentNode = parentNodes[j];
          if (aParentNode.node == aNode.parentNode) {
            aParentNode.elems.push(aNode);
            foundParent = true;
            break;
          }
        }
        if (!foundParent) {
          parentNodes.push({node: aNode.parentNode, elems: [aNode]});
        }
      }
      var elems;
      for (i = 0; i < parentNodes.length; i++) {
        elems = parentNodes[i].elems;
        if (indexNum < elems.length)
          constrainedNodes.push(elems[indexNum]);
      }
    }
  }
  else
    constrainedNodes = matchingParentNodes;
  if (xpath != "") {
    for (var i = 0; i < constrainedNodes.length; i++) {
      subNodeList = this.doFindNodesOtherRecursion(constrainedNodes[i], xpath, oneNode);
      // if we found any nodes, add them to our array
      if (subNodeList.length > 0) {
        if (oneNode) {
          nodeList.push(subNodeList[0]);
          break;
        }
        else {
          for (j = 0; j < subNodeList.length; j++) {
            nodeList.push(subNodeList[j]);
          }
        }
      }
    }
  }
  else {
    if (oneNode)
      nodeList.push(constrainedNodes[0]);
    else
      nodeList = constrainedNodes;
  }
  return nodeList;
};
XMLUtils.textualizeNodeWin32IE =
function (domNode) {
  return domNode.text;
};
XMLUtils.textualizeNodeOther =
function (domNode) {
  var theText = "";
  var nodes = domNode.childNodes;
  var node, nodeType;
  for (var i = 0; i < nodes.length; i++) {
    node = nodes[i];
    nodeType = node.nodeType;
    if ((nodeType == 3) || (nodeType == 4)) {
      theText += node.data;
    }
    else if ((nodeType == 1) || (nodeType == 9) || (nodeType == 11)) {
      theText += this.textualizeNodeOther(node);
    }
  }
  return theText;
};
XMLUtils.findActiveXProgID =
function (progIDArray) {
  var theProgID = "";
  var axObj;
  for (var i = 0; i < progIDArray.length; i++) {
    try {
      axObj = new ActiveXObject(progIDArray[i]);
      theProgID = progIDArray[i];
      break;
    } catch (e) {}
  }
  return theProgID;
};
/*Copyright 2003-2007 Maven Networks, Inc.  All rights reserved.*/
FlashXMLUtils = new function () {
  var mSelf = this;
  var mFlashControl = null;
  var mInitialized = false;
  var mReadyCallbacks = new Array();
  var mRequests = new Object();
  var mUniqueId = 0;
  var mPostUrl = "";
  var mDisabled = false;
  mSelf.isReady = false;
  mSelf.isEnabled = false;
  mSelf.initialize =
  function (pPostUrlToken) {
    if (arguments.length > 0) {
      this.initializePostUrl(pPostUrlToken);
      if (!this.getPostUrl()) {
        mDisabled = true;
        return;
      }
    }
    if (typeof(SWFObject) != "undefined") {
      if (!PlatformUtils.isFlash8Up) {
        Utils.installFlash("9");
      }
      else {
        var swfobjectPath = getScriptLocation("swfobject.js");
        if (swfobjectPath) {
          mSelf.isEnabled = true;
          var fo = new FlashObject(swfobjectPath + "FlashXML.swf", "FlashXML", "1", "1", "8", "#000000");
          fo.skipDetect = true;
          fo.addParam("play", "false");
          fo.addParam("menu", "false");
          fo.addParam("scriptAccess", "always");
          fo.write(document.getElementsByTagName("body")[0]);
          mFlashControl = document.getElementById("FlashXML");
        }
        else {
        }
      }
    }
    else {
    }
  };
  mSelf.registerReadyCallback =
  function (readyCallbackFn) {
    if (mInitialized || mDisabled) {
      fireDelayedCallback(readyCallbackFn);
    }
    else {
      mReadyCallbacks.push(readyCallbackFn);
    }
  };
  mSelf.initializePostUrl =
  function (pToken) {
    var postHostInfo = mSelf.getPostHostInfo(pToken);
    if (postHostInfo) {
      mPostUrl = postHostInfo + document.location.pathname;
      mPostUrl = mPostUrl.substring(0, mPostUrl.lastIndexOf(pToken));
    }
  };
  mSelf.getPostHostInfo =
  function (pToken) {
    var postHostInfo = "";
    var reqobj = XMLUtils.getXMLHttpRequest();
    if (!reqobj) {
      alert('Giving up :( Cannot create an XMLHTTP instance');
      return false;
    }
    var serverUrl = document.location.href;
    serverUrl = serverUrl.substring(0, serverUrl.lastIndexOf(pToken));
    try {
      reqobj.open ("GET", serverUrl + '/mms/config', false);
      reqobj.send(null);
    } catch (e) {}
    var responseXML = reqobj.responseXML;
    XMLUtils.setXMLNamespaces(responseXML);
    var respNode = XMLUtils.findNode(responseXML, 'app:Response');
    if (respNode) {
      postHostInfo = respNode.getAttribute("postHostInfo");
      if (!postHostInfo)
        postHostInfo = "";
    }
    return postHostInfo;
  }
  mSelf.getPostUrl =
  function () {
    return mPostUrl;
  };
  mSelf.encodeHeaders =
  function (headersArr) {
    var headersString = "";
    var aHeaderPair;
    for (var i = 0; i < headersArr.length; i++) {
      aHeaderPair = headersArr[i];
      if (aHeaderPair[0])
        headersString += escape(aHeaderPair[0]) + ":" + escape(aHeaderPair[1]) + ",";
    }
    if (headersString)
      headersString = headersString.substring(0, headersString.length - 1);
    return headersString;
  }
  mSelf.sendHttpRequest =
  function (url, callbackFn, postData, contentType, requestHeaders) {
    if (mInitialized) {
      var uniqueId = getNextUniqueId();
      var newFlashXml = new FlashXMLHttpRequest();
      mRequests[uniqueId] = { callbackFn: callbackFn,
                              request: newFlashXml };
      if (!postData)
        postData = null;
      if (!contentType)
        contentType = null;
      if (!requestHeaders)
        requestHeaders = null;
      mFlashControl.sendHttpRequest(uniqueId, url, postData, contentType, requestHeaders);
      return newFlashXml;
    }
  };
  mSelf.FlashXMLCallback =
  function (uniqueId, xmlData, successful) {
    xmlData = unescape(xmlData);
    var requestBits = mRequests[uniqueId];
    delete mRequests[uniqueId];
    var request = requestBits.request;
    request.readyState = 4;
    request.responseText = xmlData;
    if (successful) {
      request.responseXML = XMLUtils.parseXMLFromString(xmlData);
    }
    request.status = (successful ? 200 : 500);
    fireDelayedCallback(requestBits.callbackFn, request);
    delete requestBits;
  };
  mSelf.FlashXMLInitialized =
  function () {
    mInitialized = true;
    mSelf.isReady = true;
    for (var i = 0; i < mReadyCallbacks.length; i++)
      fireDelayedCallback(mReadyCallbacks[i]);
    mReadyCallbacks.length = 0;
  }
  function getNextUniqueId () {
    mUniqueId++;
    return "" + mUniqueId;
  }
  function fireDelayedCallback(callbackFn, arg1) {
    if (callbackFn) {
      setTimeout( function () { try {
            callbackFn(arg1);
          } catch (e) {
            var a = 0;
          } }, 0);
    }
  }
  function getScriptLocation (pathName) {
    var scripts = document.getElementsByTagName('script');
    var path = '';
    for (var i = 0; i < scripts.length; i++) {
      var src = scripts[i].src;
      var name = src.substring(src.length - pathName.length);
      if (name == pathName) {
        path = src.substring(0, src.length - pathName.length);
        break;
      }
    }
    return path;
  }
  function FlashXMLHttpRequest () {
    var self = this;
    self.readyState = 1;
    self.responseText = "";
    self.responseXML = null;
    self.status = 0;
    self.statusText = "";
    self.abort = function () {
    };
    self.getAllResponseHeaders = function () {
      return "";
    };
    self.getResponseHeader = function (headerLabel) {
      return "";
    };
  }
};

/*Copyright 2003-2007 Maven Networks, Inc.  All rights reserved.*/
function initializeMMS (applicationId, pageDepth, windowName, notificationCallback, baseURL) {
  return new MMSManager(applicationId, pageDepth, windowName, notificationCallback, baseURL);
}
function MMSManager (applicationId, pageDepth, windowName, notificationCallback, baseURL) {
  // Member Variables
  this.mApplicationID = applicationId;
  this.mPageDepth = pageDepth;
  this.mWindowName = windowName;
  this.mNotificationCallback = notificationCallback;
  this.mReleasePackagePollTimer = null;
  this.mReleasePackages = new Object();
  this.mCurrentRPSequenceNumbers = new Object();
  this.mDefaultHostPrefix = "";
  this.mDefaultPostHostPrefix = "";
  this.mDefaultReleasePackageName = "";
  this.mDefaultReleasePackageVersion = "";
  this.mAsyncRequests = new Object();
  this.calculateDefaults(baseURL ? baseURL : document.location.href);
  this.startReleasePackagePoll();
}
MMSManager.prototype.K_DEFAULT_OFFLINE_POLL_INTERVAL = 60 * 60 * 1000; // 60 minutes
MMSManager.prototype.K_DEFAULT_RELEASE_POLL_INTERVAL = 60 * 60 * 1000; // 60 minutes
MMSManager.prototype.K_DEFAULT_RETRY_INTERVAL = 10 * 60 * 1000; // 10 minutes
MMSManager.prototype.K_SERVICE_TYPE_ROOTS = "roots/";
MMSManager.prototype.K_SERVICE_TYPE_QUERIES = "queries/";
MMSManager.prototype.K_SERVICE_TYPE_SITE = "site/";
MMSManager.prototype.K_SERVICE_TYPE_FILES = "hashFiles/";
MMSManager.prototype.K_SERVICE_TYPE_EVENTS = "events/";
MMSManager.prototype.K_SERVICE_TYPE_SOURCES = "sources/";
MMSManager.prototype.K_CURRENT_PREFIX = "current/";
MMSManager.prototype.K_PERSISTENT_COOKIE_NAME = "_maven_MMS";
MMSManager.prototype.getReleasePackageVersion =
function (name, version) {
  if (!name)
    name = "";
  if (!version)
    version = "";
  if (!name)
    name = this.mDefaultReleasePackageName;
  if (!version && (name == this.mDefaultReleasePackageName))
    version = this.mDefaultReleasePackageVersion;
  new MMSReleasePackageVersion(this, name, version);
  this.mReleasePackages[name] = true;
};
MMSManager.prototype.getVersionList =
function (name) {
  this.internalGetVersionList(name, null);
};
MMSManager.prototype.sendRequest =
function (requestObject) {
  return this.internalSendRequest(requestObject, "C", null);
};
MMSManager.prototype.mOSXClientSupportEnabled = true;
MMSManager.prototype.mIsOSX = (navigator.userAgent.indexOf("Mac") != -1);
MMSManager.prototype.mIsSafari = ((navigator.userAgent.indexOf("Safari") != -1) || (navigator.userAgent.indexOf("AppleWebKit") != -1));
MMSManager.prototype.mIsWin32IE = (navigator.userAgent.indexOf("MSIE") != -1);
MMSManager.prototype.dispatchNotification =
function (notificationName, param1) {
  if (this.mNotificationCallback) {
    try {
      this.mNotificationCallback(notificationName, param1);
    } catch (e) {
      this.delayThrow(e, "Error dispatching notification " + notificationName + ": " + e.message);
    }
  }
};
MMSManager.prototype.calculateDefaults =
function (baseURL) {
  var href = baseURL;
  var curURL = href;
  var queryLoc = curURL.indexOf("?");
  if (queryLoc >= 0)
    curURL = curURL.substring(0, queryLoc);
  var nextSlash;
  for (var i = 0; i < this.mPageDepth + 1; i++) {
    nextSlash = curURL.lastIndexOf("/");
    if (nextSlash != -1)
      curURL = curURL.substring(0, nextSlash);
  }
  var elems = new Array();
  for (i = 2; i >= 0; i--) {
    nextSlash = curURL.lastIndexOf("/");
    if (nextSlash != -1) {
      elems[i] = curURL.substring(nextSlash + 1);
      curURL = curURL.substring(0, nextSlash);
    }
  }
  this.mDefaultHostPrefix = curURL + "/";
  if (typeof FlashXMLUtils != "undefined" && FlashXMLUtils.isEnabled) {
    var postHostInfo = FlashXMLUtils.getPostHostInfo('/rt/');
    if (postHostInfo) {
      var host = document.location.host;
      var iLoc = this.mDefaultHostPrefix.indexOf(host) + host.length;
      this.mDefaultPostHostPrefix = postHostInfo + this.mDefaultHostPrefix.substring(iLoc);
    }
  }
  var currentFirst = false;
  if (elems[0] == "current") {
    currentFirst = true;
    this.mDefaultReleasePackageName = elems[2];
    this.mDefaultReleasePackageVersion = "";
  }
  else if (elems[0] == "site") {
    this.mDefaultReleasePackageName = elems[1];
    this.mDefaultReleasePackageVersion = elems[2];
    if (this.mDefaultReleasePackageVersion == "current")
      this.mDefaultReleasePackageVersion = "";
  }
};
MMSManager.prototype.getBaseURL =
function () {
  return this.mDefaultHostPrefix;
};
MMSManager.prototype.buildURL =
function (hostPrefix, serviceType, releaseName, releaseVersion) {
  var url = "";
  switch (serviceType) {
    case this.K_SERVICE_TYPE_EVENTS:
      url = hostPrefix;
      break;
    case this.K_SERVICE_TYPE_ROOTS:
      url = (hostPrefix ? hostPrefix : this.mDefaultHostPrefix) +
            this.K_CURRENT_PREFIX +
            serviceType +
            releaseName + "/";
      break;
    case this.K_SERVICE_TYPE_FILES:
      url = (hostPrefix ? hostPrefix : this.mDefaultHostPrefix) +
            serviceType +
            releaseName + "/" +
            this.K_CURRENT_PREFIX;
      break;
    case this.K_SERVICE_TYPE_QUERIES:
    case this.K_SERVICE_TYPE_SITE:
    case this.K_SERVICE_TYPE_SOURCES:
      url = (hostPrefix ? hostPrefix : this.mDefaultHostPrefix) +
            serviceType +
            releaseName + "/" +
            (releaseVersion ? releaseVersion + "/" : this.K_CURRENT_PREFIX);
      break;
  }
  return url;
};
MMSManager.prototype.buildRootsURL =
function (xmlFile) {
  return this.buildURL("", this.K_SERVICE_TYPE_ROOTS, this.mDefaultReleasePackageName, "") + xmlFile;
};
MMSManager.prototype.sendHttpRequest =
function (url, callbackObject, postDataDom) {
  var newDom = null;
  var callbackFn = function (newDom) {
                      try { newDom.responseXML.setProperty("SelectionLanguage", "XPath"); } catch (e) {}
                      callbackObject.httpRequestComplete(url, newDom.responseXML, postDataDom ? postDataDom : null, newDom);
                    }
  var requestString = "";
  if (postDataDom)
    requestString = XMLUtils.serializeNode(postDataDom);
  if (postDataDom && this.mDefaultPostHostPrefix) {
    newDom = FlashXMLUtils.sendHttpRequest(url, callbackFn, requestString);
  }
  else {
    newDom = XMLUtils.getXMLHttpRequest();
    newDom.onreadystatechange = function () {
                          if (newDom.readyState == 4) {
                            setTimeout( function () {
                                          callbackFn(newDom);
                                        }, 0);
                          }
                        };
    try {
      if (postDataDom) {
        newDom.open("POST", url, true);
        newDom.send(requestString);
      }
      else {
        newDom.open("GET", url, true);
        newDom.send(null);
      }
    } catch (e) {
      this.delayThrow(e, "Error sending XML HTTP Request to " + url + ": " + e.message);
    }
  }
  return newDom;
};
MMSManager.prototype.checkDomForErrors =
function (domObject) {
  return (!domObject ||
          (domObject.firstChild && (domObject.firstChild.nodeName == "parsererror")) ||
          (this.mIsSafari && domObject.firstChild && domObject.firstChild.firstChild && (domObject.firstChild.firstChild.nodeName == "parsererror")));
};
MMSManager.prototype.internalGetVersionList =
function (name, callbackObject) {
  if (!name)
    name = this.mDefaultReleasePackageName;
  // create a new version list object and let it do the right thing when it's done
  new MMSReleasePackageVersionList(this, name, callbackObject);
};
MMSManager.prototype.isOSX =
function () {
  return this.mIsOSX;
};
MMSManager.prototype.startReleasePackagePoll =
function () {
  // if the timer isn't going, set it
  if (!this.mReleasePackagePollTimer) {
    var self = this;
    this.mReleasePackagePollTimer = this.startRepeatingTimer(function () {
                                          self.doReleasePackagePoll();
                                        },
                                        this.K_DEFAULT_RELEASE_POLL_INTERVAL);
  }
};
MMSManager.prototype.doReleasePackagePoll =
function () {
  var releasePackages = this.mReleasePackages;
  for (var rpName in releasePackages) {
    this.internalGetVersionList(rpName, this);
  }
};
MMSManager.prototype.onReleasePackageVersionList =
function (rpVersionList, sendMessage) {
  var rpName = rpVersionList.name;
  var newSequenceNumber = rpVersionList.getSequenceNumber();
  var noOldSequenceNumber = (typeof(this.mCurrentRPSequenceNumbers[rpName]) == "undefined");
  if (noOldSequenceNumber || (newSequenceNumber > this.mCurrentRPSequenceNumbers[rpName])) {
    this.mCurrentRPSequenceNumbers[rpName] = newSequenceNumber;
    if (!noOldSequenceNumber)
      sendMessage = true;
  }
  if (sendMessage)
    this.dispatchNotification("onReleasePackageVersionList", rpVersionList);
};
MMSManager.prototype.startRepeatingTimer =
function (callbackFn, interval) {
  setTimeout(callbackFn, 0);
  return setInterval(callbackFn, interval);
};
MMSManager.prototype.httpRequestComplete =
function (url, domObject, postDataDom, requestObject) {
};
MMSManager.prototype.pathsafeEscape =
function (inputString) {
  var escapedString = escape(inputString);
  return escapedString.replace(/\//g, "%2f");
};
MMSManager.prototype.delayThrow =
function (error, modifiedMessage) {
  if (modifiedMessage) {
    error.message = modifiedMessage;
    error.description = modifiedMessage;
  }
  setTimeout( function () { throw(error); }, 0);
};
function MMSReleasePackageVersionList (mmsManager, name, callbackObject, versionList) {
  this.mmsManager = mmsManager;
  this.name = name;
  this.currentVersion = "";
  this.versions = new Array();
  this.hasError = false;
  this.error = "";
  this.mSequenceNumber = 0;
  this.mCallbackObject = callbackObject;
  if (arguments.length == 4) {
    if (versionList) {
      this.name = versionList.name;
      this.currentVersion = versionList.currentVersion;
      this.versions = versionList.versions;
      this.mSequenceNumber = versionList.sequenceNumber;
    }
    else {
      this.hasError = true;
      this.error = "No version list cached in client.";
    }
    var self = this;
    setTimeout(function () { self.dispatchNotification(); }, 0);
  }
  else
    this.downloadVersionListing();
}
MMSReleasePackageVersionList.prototype.downloadVersionListing =
function () {
  var mmsMan = this.mmsManager;
  mmsMan.sendHttpRequest(mmsMan.buildRootsURL("versionListing.xml"), this);
};
MMSReleasePackageVersionList.prototype.httpRequestComplete =
function (url, domObject) {
  var mmsMan = this.mmsManager;
  if (mmsMan.checkDomForErrors(domObject)) {
    this.hasError = true;
    this.error = "Error downloading version list: XML DOM could not be parsed.";
  }
  else {
    var releaseVersionsNode = XMLUtils.findNode(domObject, "/releaseVersions");
    if (releaseVersionsNode) {
      this.currentVersion = releaseVersionsNode.getAttribute("currentVersion");
      var sequenceNumber = parseInt(releaseVersionsNode.getAttribute("sequence"), 10);
      if (!isNaN(sequenceNumber)) {
        this.mSequenceNumber = sequenceNumber;
      }
      var releaseVersions = XMLUtils.findNodes(releaseVersionsNode, "releaseVersion");
      for (var i = 0; i < releaseVersions.length; i++) {
        this.versions[i] = releaseVersions[i].getAttribute("version");
      }
    }
    else {
      this.hasError = true;
      this.error = "Error downloading version list: missing releaseVersions node in XML.";
    }
  }
  this.dispatchNotification();
};
MMSReleasePackageVersionList.prototype.dispatchNotification =
function () {
  var sendMessage = false;
  var mmsMan = this.mmsManager;
  if (!this.mCallbackObject) {
    sendMessage = true;
  }
  if (this.mCallbackObject && (this.mCallbackObject != mmsMan)) {
    this.mCallbackObject.onReleasePackageVersionList(this);
  }
  mmsMan.onReleasePackageVersionList(this, sendMessage);
};
MMSReleasePackageVersionList.prototype.getSequenceNumber =
function () {
  return this.mSequenceNumber;
};
function MMSReleasePackageVersion (mmsManager, name, version, error) {
  this.mmsManager = mmsManager;
  this.name = name;
  this.version = version;
  this.hasError = false;
  this.error = "";
  this.mSourcesDescriptorUrl = "";
  this.mHostPrefixes = new Object();
  this.mSendEventImageCache = new Array();
  this.mRPVersionList = null;
  this.mInstallParams = "";
  this.mAppUniqueId = "";
  this.mContinueReleasePackage = false;
  this.mRPVersionList = null;
  this.mDefaultQueryRetryCount = 0;
  this.mSourcesPollTimer = null;
  this.mSourcesComplete = false;
  var complete = false;
  if (error) {
    this.hasError = true;
    this.error = error;
    complete = true;
  }
  else if (!version) {
    this.getVersionList(true);
  }
  else if (!this.mSourcesComplete) {
    this.getSourcesUrl();
  }
  else {
    complete = true;
  }
  if (complete) {
    var self = this;
    setTimeout(function () { self.dispatchNotification(); }, 0);
  }
}
MMSReleasePackageVersion.prototype.sendEvent =
function (dcsId, params) {
  if (!params)
    params = [];
  this.doSendEvent(dcsId, params);
};
MMSReleasePackageVersion.prototype.executeQuery =
function (context, queryName, outputFormat, params) {
  if (!params)
    params = [];
  this.doExecuteQuery(context, queryName, outputFormat, params, false);
};
MMSReleasePackageVersion.prototype.K_HOST_TYPE_WWW = "mav_www";
MMSReleasePackageVersion.prototype.K_HOST_TYPE_WEBSITE_HASHFILES = "mav_website_hashFiles";
MMSReleasePackageVersion.prototype.K_HOST_TYPE_EVENTS = "mav_events";
MMSReleasePackageVersion.prototype.buildURL =
function (serviceType, hostId) {
  var hostPrefix = "";
  var mmsMan = this.mmsManager;
  if (hostId && this.mHostPrefixes[hostId])
    hostPrefix = this.mHostPrefixes[hostId];
  else {
    hostId = "";
    switch (serviceType) {
      case mmsMan.K_SERVICE_TYPE_ROOTS:
      case mmsMan.K_SERVICE_TYPE_QUERIES:
      case mmsMan.K_SERVICE_TYPE_SOURCES:
        break;
      case mmsMan.K_SERVICE_TYPE_SITE:
        hostId = this.K_HOST_TYPE_WWW;
        break;
      case mmsMan.K_SERVICE_TYPE_FILES:
        // website, so use stream files
        hostId = this.K_HOST_TYPE_WEBSITE_HASHFILES;
        break;
      case mmsMan.K_SERVICE_TYPE_EVENTS:
        hostId = this.K_HOST_TYPE_EVENTS;
        break;
    }
    if (hostId && this.mHostPrefixes[hostId])
      hostPrefix = this.mHostPrefixes[hostId];
  }
  return mmsMan.buildURL(hostPrefix, serviceType, this.name, this.version);
};
MMSReleasePackageVersion.prototype.getBaseURL =
function () {
  var url = "";
  url = this.mmsManager.getBaseURL();
  return url;
};
MMSReleasePackageVersion.prototype.getVersionList =
function (continueReleasePackage) {
  if (!continueReleasePackage)
    continueReleasePackage = false;
  this.mContinueReleasePackage = continueReleasePackage;
  this.mmsManager.internalGetVersionList(name, this);
};
MMSReleasePackageVersion.prototype.getDefaultQuery =
function () {
  this.internalExecuteQuery("MMSReleasePackageVersion-getReleaseSpec", "getReleaseSpec", "published");
};
MMSReleasePackageVersion.prototype.getSourcesUrl =
function () {
  var mmsMan = this.mmsManager;
  var theURL = this.buildURL(mmsMan.K_SERVICE_TYPE_SOURCES) + "sourcesPointer.xml";
  mmsMan.sendHttpRequest(theURL, this);
};
MMSReleasePackageVersion.prototype.downloadSourcesFile =
function () {
  this.mmsManager.sendHttpRequest(this.mSourcesDescriptorUrl, this);
};
MMSReleasePackageVersion.prototype.startSourcesPoll =
function () {
  if (!this.mSourcesPollTimer) {
    var self = this;
    this.mSourcesPollTimer = setInterval(function () {
                                          self.downloadSourcesFile();
                                        },
                                        this.mmsManager.K_DEFAULT_RELEASE_POLL_INTERVAL);
  }
};
MMSReleasePackageVersion.prototype.onReleasePackageVersionList =
function (rpVersionList) {
  this.mRPVersionList = rpVersionList;
  if (this.mContinueReleasePackage) {
    this.mContinueReleasePackage = false;
    this.version = rpVersionList.currentVersion;
    this.getSourcesUrl();
  }
  else {
    this.completeInstallInfo();
  }
};
MMSReleasePackageVersion.prototype.onQueryResult =
function (queryResult) {
  var mmsMan = this.mmsManager;
  var complete = true;
  if (queryResult.hasError) {
    complete = false;
    this.mDefaultQueryRetryCount++;
    if ((this.mDefaultQueryRetryCount % 3) == 0) {
      var self = this;
      setTimeout( function () { self.getDefaultQuery(); }, mmsMan.K_DEFAULT_RETRY_INTERVAL);
    }
    else
      this.getDefaultQuery();
  }
  else {
    var releaseSpec = XMLUtils.findNode(queryResult.result, "/app:QueryResults/app:results/app:Object");
    if (releaseSpec) {
      var baseUrl = mmsMan.getBaseURL();
      baseUrl = baseUrl.substring(0, baseUrl.indexOf("/", baseUrl.indexOf("/", baseUrl.indexOf("/") + 1) + 1));
      this.mSourcesDescriptorUrl = baseUrl + releaseSpec.getAttribute("sourcesDescriptorPath");
    }
    if (!this.isAppConnected() && this.mSourcesDescriptorUrl) {
      mmsMan.sendHttpRequest(this.mSourcesDescriptorUrl, this);
      complete = false;
    }
  }
  if (complete)
    this.dispatchNotification();
};
MMSReleasePackageVersion.prototype.httpRequestComplete =
function (url, domObject) {
  var mmsMan = this.mmsManager;
  if (url == this.mSourcesDescriptorUrl) {
    if (mmsMan.checkDomForErrors(domObject)) {
      this.hasError = true;
      this.error = "Error retrieving Release Package from server: sources XML DOM could not be parsed.";
    }
    else {
      XMLUtils.setXMLNamespaces(domObject);
    }
    this.loadSources(domObject);
  }
  else {
    var complete = true;
    if (mmsMan.checkDomForErrors(domObject)) {
      this.hasError = true;
      this.error = "Error retrieving Release Package from server: sources service XML DOM could not be parsed.";
    }
    else {
      var sources = XMLUtils.findNode(domObject, "/sources");
      if (sources) {
        var baseUrl = mmsMan.getBaseURL();
        baseUrl = baseUrl.substring(0, baseUrl.indexOf("/", baseUrl.indexOf("/", baseUrl.indexOf("/") + 1) + 1));
        this.mSourcesDescriptorUrl = baseUrl + sources.getAttribute("url");
        this.downloadSourcesFile();
        complete = false;
      }
      else {
        this.hasError = true;
        this.error = "Error retrieving Release Package from server: sources service XML missing sources node.";
      }
    }
    if (complete)
      this.dispatchNotification();
  }
};
MMSReleasePackageVersion.prototype.loadSources =
function (domObject) {
  if (domObject) {
    var hostSelectors = XMLUtils.findNodes(domObject, "/sources/hostSelector");
    var name, baseURL, hostSelector, hostNode;
    if (hostSelectors.length > 0) {
      this.mHostPrefixes = new Object();
      for (var i = 0; i < hostSelectors.length; i++) {
        hostSelector = hostSelectors[i];
        name = hostSelector.getAttribute("name");
        hostNode = XMLUtils.findNode(hostSelector, "host");
        if (name && hostNode) {
          baseURL = hostNode.getAttribute("baseURL");
          if (baseURL)
            this.mHostPrefixes[name] = baseURL;
        }
      }
    }
  }
  if (!this.mSourcesComplete) {
    this.mSourcesComplete = true;
    this.startSourcesPoll();
    this.dispatchNotification();
  }
};
MMSReleasePackageVersion.prototype.internalExecuteQuery =
function (context, queryName, outputFormat, params) {
  if (!params)
    params = [];
  this.doExecuteQuery(context, queryName, outputFormat, params, true);
};
MMSReleasePackageVersion.prototype.doExecuteQuery =
function (context, queryName, outputFormat, params, internalRequest) {
  new MMSQueryResult(this, context, queryName, outputFormat, params, internalRequest);
};
MMSReleasePackageVersion.prototype.doSendEvent =
function (dcsId, params) {
  if (!params)
    params = [];
  var mmsMan = this.mmsManager;
  var url = this.buildURL(mmsMan.K_SERVICE_TYPE_EVENTS);
  if (url) {
    url += dcsId + "/dcs.gif";
    var queryString = "";
    var paramsByName = new Object();
    var paramName, paramValue;
    for (var i=0; i + 1 < params.length; i+=2) {
      paramName = params[i];
      paramValue = params[i + 1];
      paramsByName[paramName] = paramValue;
      queryString += "&" + paramName + "=" + escape(paramValue);
    }
    if (!paramsByName["dcsuri"])
      queryString += "&dcsuri=";
    if (!paramsByName["dcsdat"])
      queryString += "&dcsdat=" + (new Date()).valueOf();
    if (!paramsByName["dcsref"])
      queryString += "&dcsref=";
    if (!paramsByName["cust_type"])
      queryString += "&cust_type=streaming";
    url += "?" + queryString.substring(1);
    var newImg;
    var imageCache = this.mSendEventImageCache;
    if (imageCache.length > 0)
      newImg = imageCache.pop();
    else {
      newImg = document.createElement("img");
      newImg.onload = newImg.onerror = function() { imageCache.push(newImg); };
    }
    newImg.src = url;
  }
};
MMSReleasePackageVersion.prototype.mmsNotification =
function (notificationObj) {
  var notificationName = notificationObj.notificationName;
  switch (notificationName) {
    case "onQuery":
      new MMSQueryResult(this, notificationObj.params);
      break;
  }
};
MMSReleasePackageVersion.prototype.dispatchNotification =
function () {
  this.mmsManager.dispatchNotification("onReleasePackageVersion", this);
};
function MMSQueryResult (rpVersion, context, queryName, outputFormat, params, internalRequest) {
  this.releasePackageVersion = rpVersion;
  this.context = "";
  this.queryName = "";
  this.outputFormat = "";
  this.params = null;
  this.result = null;
  this.hasError = false;
  this.error = "";
  this.mInternalRequest = false;
  if (arguments.length == 2) {
    var params = context;
    this.context = params.context;
    this.queryName = params.queryName;
    this.outputFormat = params.outputFormat;
    this.params = params.params;
    var result = params.result;
    if (result) {
      this.result = XMLUtils.parseXMLFromString(result);
      XMLUtils.setXMLNamespaces(this.result);
    }
    this.hasError = params.hasError;
    this.error = params.error;
    this.mInternalRequest = params.internalRequest;
    this.dispatchNotification();
  }
  else {
    this.context = context;
    this.queryName = queryName;
    this.outputFormat = outputFormat;
    this.params = params;
    this.mInternalRequest = internalRequest;
    this.downloadQuery();
  }
}
MMSQueryResult.prototype.downloadQuery =
function () {
  var mmsMan = this.releasePackageVersion.mmsManager;
  var queryURL = this.releasePackageVersion.buildURL(mmsMan.K_SERVICE_TYPE_QUERIES);
  queryURL += mmsMan.pathsafeEscape(this.queryName) + "/";
  queryURL += mmsMan.pathsafeEscape(this.outputFormat) + "/";
  var params = this.params;
  for (var i = 0; i < params.length; i++)
    queryURL += mmsMan.pathsafeEscape(params[i]) + "/";
  queryURL += "result.xml";
  mmsMan.sendHttpRequest(queryURL, this);
};
MMSQueryResult.prototype.httpRequestComplete =
function (url, domObject) {
  var mmsMan = this.releasePackageVersion.mmsManager;
  if (mmsMan.checkDomForErrors(domObject)) {
    this.hasError = true;
    this.error = "Error retrieving Query from server: XML DOM could not be parsed.";
  }
  else {
    this.result = domObject;
    XMLUtils.setXMLNamespaces(this.result);
  }
  this.dispatchNotification();
};
MMSQueryResult.prototype.dispatchNotification =
function () {
  if (this.mInternalRequest) {
    this.releasePackageVersion.onQueryResult(this);
  }
  else {
    this.releasePackageVersion.mmsManager.dispatchNotification("onQueryResult", this);
  }
};
