var rs =
{
  popup: true,
  usersicon: false,
  appserverhost: "app.readspeaker.com",
  version: "09",
  defaultvalue: "wordsent",
  defaultsurvive: 360000000,
  bmindex: 1,
  sentbmindex: 0,
  seltexttimes: 0,
  seltextcleanuptimes: 0,
  startofsentence: 1,
  inc: 0,
  start: null,
  stop: null,
  readid: null,
  restorehtml: null,
  newhtml: "",
  startOffset: null,
  endOffset: null,
  selectedString: "",
  selhtml: "",
  selectedWordsRange: new Array(),
  oldwordhl: null,
  oldsenthl: null,
  oldwordhlclass: null,
  oldsenthlclass: null,
  oldSelhtml: "",
  firstrun: 1,
  selectedRange: null,
  selectedRangeColor: null,
  activeselection: false,
  activeselectionIE: false,
  mouse_x_pos: null,
  mouse_y_pos: null,
  keepRSicon: 0,
  softCleanup: false,
  rs_time: null,
  globalcount: null,
  oldrscall: null,
  listenButtonExists: false,
  lastWordsRange: null,
  noSelection: false,
  oldsentcol: null,
  oldwordcol: null,
  oldsentrange: null,
  oldwordrange: null,
  convertSpeed: function (a)
  {
    switch (a)
    {
    case "slow":
      return "75";
      break;
    case "medium":
      return "100";
      break;
    case "fast":
      return "130";
      break;
    default:
      return "100";
      break
    }
  },
  issuePOST: function (a, c)
  {
    rs.globalcount++;
    if (!document.getElementById("postiframe1") || !document.getElementById("postiframe2"))
    {
      var g = null;
      var f = null;
      if (document.selection)
      {
        g = document.createElement('<iframe name="postiframe1">');
        f = document.createElement('<iframe name="postiframe2">')
      }
      else
      {
        g = document.createElement("iframe");
        f = document.createElement("iframe");
        g.name = "postiframe1";
        f.name = "postiframe2"
      }
      g.setAttribute("id", "postiframe1");
      g.setAttribute("style", "display: none; position: absolute;");
      g.style.display = "none";
      f.setAttribute("id", "postiframe2");
      f.setAttribute("style", "display: none; position: absolute;");
      f.style.display = "none";
      var d = document.getElementsByTagName("body");
      var o = null;
      if (d.length > 0)
      {
        var o = d.item(0)
      }
      if (o)
      {
        o.appendChild(g);
        o.appendChild(f)
      }
      else
      {
        return
      }
    }
    a = a + "&output=audiolink";
    var h = document.createElement("form");
    h.target = "postiframe" + rs.globalcount;
    h.method = "post";
    var n = a.split("?");
    var m = Math.random();
    h.action = "https://" + rs.appserverhost + "/enterprise/iframeproxy.php?randid=" + m;
    var l = n[1].split("&");
    var k;
    for (k = 0; k < l.length; k++)
    {
      var e = l[k].split("=");
      var p = document.createElement("input");
      p.setAttribute("name", unescape(e[0]));
      p.setAttribute("value", unescape(e[1]));
      h.appendChild(p)
    }
    var p = document.createElement("input");
    p.setAttribute("name", "selectedhtml_base64");
    p.setAttribute("value", rs.base64Encode(c));
    h.appendChild(p);
    document.body.appendChild(h);
    h.submit();
    document.body.removeChild(h);
    return "https://" + rs.appserverhost + "/enterprise/iframeproxy.php?listen=1&randid=" + m
  },
  readpage: function (k, d)
  {
    rs.lastWordsRange = null;
    rs.globalcount = 0;
    if (rs.selectedRangeColor && rs.selectedRangeColor != null && rs.selectedRange && rs.selectedRange != null)
    {
      rs.selectedRange.execCommand("backcolor", 0, rs.selectedRangeColor)
    }
    var c = k.match(/readid=[^&]+/gi);
    rs.readid = c[0].replace("readid=", "");
    if (rs.restorehtml == null && rs.readid != null)
    {
      var e = document.getElementById(rs.readid);
      if (e != null)
      {
        rs.restorehtml = e.innerHTML
      }
    }
    if (document.getElementById("rs_selimg"))
    {
      rs.keepRSicon = 0;
      rs.setIconVisivilty()
    }
    if (rs.selectedString.length > 0 || rs.selhtml.length > 0)
    {
      rs.softCleanup = true
    }
    else
    {
      rs.softCleanup = false;
      rs.cleanup()
    }
    var g = rs.convertSpeed(rs.loadSettings("ReadSpeakerHLspeed"));
    var h = rs.loadSettings("ReadSpeakerHL");
    if (h == "")
    {
      h = rs.defaultvalue
    }
    var b = "mp3";
    if (h != "none")
    {
      b = "flv"
    }
    if (rs.selectedString.length > 0 || rs.selhtml.length > 0)
    {
      rs.activeselection = true;
      if (rs.selectedString.length > 0)
      {
        rs.selhtml = rs.selectRange()
      }
      rs.oldrscall = k;
      var a = escape(rs.issuePOST(k + "&audioformat=" + b + "&sync=user&embhlv=" + rs.version + "&speed=" + g, rs.selhtml))
    }
    else
    {
      rs.noSelection = true;
      rs.activeselection = false;
      var a = escape(k + "&audioformat=" + b + "&sync=" + h + "&embhlv=" + rs.version + "&speed=" + g);
      rs.oldSelhtml = "";
      rs.oldrscall = null
    }
    if (rs.selhtml.length > 0)
    {
      rs.oldSelhtml = rs.selhtml
    }
    if (rs.softCleanup)
    {
      rs.cleanup()
    }
    the_player = "<table style='border:1px solid #aeaeae; font-size: 10px;'><tr><td>";
    the_player += "<object type='application/x-shockwave-flash' data='https://media.readspeaker.com/flash/readspeaker20.swf?" + b + "=" + a + "&autoplay=1&rskin=bump&time_format=ms&rskin=bump&text_play=Play&text_pause=Pause&text_stop=Stop&text_vol=Volume' style='height:20px; width:250px; float:left'>";
    the_player += "<param name='movie' value='https://media.readspeaker.com/flash/readspeaker20.swf?" + b + "=" + a + "&autoplay=1&rskin=bump&time_format=ms&rskin=bump&text_play=Play&text_pause=Pause&text_stop=Stop&text_vol=Volume'>";
    the_player += "<param name='quality' value='high'><param name='autostart' value='true'>";
    the_player += "<param name='allowScriptAccess' value='always'><param name='bgcolor' value='#FFFFFF'>";
    the_player += "<param name='loop' value='false'></object>";
    the_html = "<div id='bottomlinks'> <a id='rsSaveBtn' style='border:0px' href='" + k + "&embhlv=" + rs.version + "' onclick='if(rs.oldrscall==null) {return true;}else {var sl=rs.issuePOST(rs.oldrscall+\"&sync=user&embhlv=" + rs.version + "\", rs.oldSelhtml);this.href=sl;return true;}' target='rs'>Kein Ton?</a> </div>";
    the_html += "<div id='controls'></div>";
    the_html += "</td><td style='vertical-align: top;'><a href='#' class='img-link' style='padding-top:5px;padding-right:5px;float:right' onclick='rs.closepage(\"" + d + "\");return false'><img id='closebr' src='https://media.readspeaker.com/images/wr/close.gif' border='0' alt='Player schlie&szlig;en' title='Player schlie&szlig;en'></a></td></tr></table>";
    var f = document.getElementById(d);
    if (f)
    {
      f.innerHTML = the_player + the_html;
      f.style.display = "block"
    }
    rs.selectedString = "";
    rs.selhtml = ""
  },
  closepage: function (b)
  {
    var a = document.getElementById(b);
    if (a)
    {
      a.innerHTML = "";
      a.style.display = "none"
    }
    if (rs.selectedRangeColor && rs.selectedRangeColor != null && rs.selectedRange && rs.selectedRange != null)
    {
      rs.selectedRange.execCommand("backcolor", 0, rs.selectedRangeColor)
    }
    rs.lastWordsRange = null;
    if (!rs.softCleanup)
    {
      rs.selectedRange = null
    }
    setTimeout("rs.cleanup();rs.activeselection=false;", 10);
    if (rs.noSelection)
    {
      var a = null;
      if (rs.readid != null)
      {
        a = document.getElementById(rs.readid)
      }
      if (a != null && rs.restorehtml != null)
      {
        a.innerHTML = rs.restorehtml;
        rs.restorehtml = null;
        rs.readid = null
      }
      rs.noSelection = false
    }
  },
  rshlexit: function ()
  {
    if (rs.selectedRangeColor && rs.selectedRangeColor != null && rs.selectedRange && rs.selectedRange != null)
    {
      rs.selectedRange.execCommand("backcolor", 0, rs.selectedRangeColor)
    }
    rs.lastWordsRange = null;
    if (!rs.softCleanup)
    {
      rs.selectedRange = null
    }
    setTimeout("rs.cleanup()", 100)
  },
  saveSettings: function (name, content, lifetime)
  {
    lifetime = parseInt(eval(lifetime));
    if (lifetime + "" == "NaN")
    {
      tmpdate = ""
    }
    else
    {
      var thedate = new Date();
      thedate.setTime(thedate.getTime() + lifetime);
      thedate = thedate.toGMTString();
      tmpdate = "; expires=" + thedate
    }
    document.cookie = name + "=" + escape(content) + tmpdate
  },
  loadSettings: function (a)
  {
    ckarr = document.cookie;
    cks = ckarr.split("; ");
    for (i = 0; i < cks.length; i++)
    {
      cknameval = cks[i].split("=");
      for (j = 0; j < cknameval.length; j++)
      {
        if (cknameval[j] == a)
        {
          return unescape(cknameval[j + 1])
        }
      }
    }
    return ""
  },
  setstyle: function (b)
  {
    if (b.indexOf("icon") > -1)
    {
      rs.saveSettings("ReadSpeakerHLicon", b, rs.defaultsurvive)
    }
    else
    {
      if (b == "slow" || b == "medium" || b == "fast")
      {
        rs.saveSettings("ReadSpeakerHLspeed", b, rs.defaultsurvive)
      }
      else
      {
        rs.saveSettings("ReadSpeakerHL", b, rs.defaultsurvive)
      }
    }
    var a = document.getElementById("controls");
    if (a != null)
    {
      a.innerHTML = ""
    }
  },
  showcontrols: function (b, c)
  {
    var a = document.getElementById("controls");
    if (a != null && a.innerHTML != "")
    {
      a.innerHTML = "";
      a.style.display = "none";
      return false
    }
    var e = rs.loadSettings("ReadSpeakerHL");
    var f = rs.loadSettings("ReadSpeakerHLicon");
    var d = rs.loadSettings("ReadSpeakerHLspeed");
    if (e == "")
    {
      e = rs.defaultvalue
    }
    if (f == "")
    {
      if (rs.popup)
      {
        f = "iconon"
      }
      else
      {
        f = "iconoff"
      }
    }
    if (d == "")
    {
      d = "medium"
    }
    thestring = "<div id='rspopup'><fieldset class='rs_block'><legend>Highlighting optionen</legend><ul>";
    thestring += "<li class=";
    if (e == "wordsent")
    {
      thestring += "'rs_active'"
    }
    thestring += "><a href='#' onclick='rs.setstyle(\"wordsent\"); rs.selhtml=rs.oldSelhtml;rs.readpage(\"" + b + '","' + c + "\");rs.softCleanup=false;return false;'>Wort und satz</a></li>";
    thestring += "<li class=";
    if (e == "sent")
    {
      thestring += "'rs_active'"
    }
    thestring += "><a href='#' onclick='rs.setstyle(\"sent\"); rs.selhtml=rs.oldSelhtml;rs.readpage(\"" + b + '","' + c + "\");rs.softCleanup=false;return false;'>Nur satz</a></li>";
    thestring += "<li class=";
    if (e == "word")
    {
      thestring += "rs_active"
    }
    thestring += "><a href='#' onclick='rs.setstyle(\"word\"); rs.selhtml=rs.oldSelhtml;rs.readpage(\"" + b + '","' + c + "\");rs.softCleanup=false;return false;'>Nur sort</a></li>";
    thestring += "<li class=";
    if (e == "none")
    {
      thestring += "rs_active"
    }
    thestring += "><a href='#' onclick='rs.setstyle(\"none\"); rs.selhtml=rs.oldSelhtml;rs.readpage(\"" + b + '","' + c + "\");rs.softCleanup=false;return false;'>Kein highlighting</a></li>";
    thestring += "</ul></fieldset><fieldset class='rs_block'><legend>Popup-Taste</legend><ul>";
    thestring += "<li class=";
    if (f == "iconon")
    {
      thestring += "rs_active "
    }
    thestring += "><a href='#' onclick='rs.popup=true;rs.setstyle(\"iconon\");rs.selhtml=rs.oldSelhtml;rs.readpage(\"" + b + '","' + c + "\");rs.softCleanup=false;return false;'>Anzeigen</a></li>";
    thestring += "<li class=";
    if (f == "iconoff")
    {
      thestring += "rs_active "
    }
    thestring += "><a href='#' onclick='rs.popup=false;rs.setstyle(\"iconoff\");rs.selhtml=rs.oldSelhtml;rs.readpage(\"" + b + '","' + c + "\");rs.softCleanup=false;return false;'>Ausblenden</a></li>";
    thestring += "</ul></fieldset><fieldset class='rs_block'><legend>Geschwindigkeit</legend><ul>";
    thestring += "<li class=";
    if (d == "slow")
    {
      thestring += "rs_active "
    }
    thestring += "><a href='#' onclick='rs.setstyle(\"slow\");rs.selhtml=rs.oldSelhtml;rs.readpage(\"" + b + '","' + c + "\");rs.softCleanup=false;return false;'>Langsam</a></li>";
    thestring += "<li class=";
    if (d == "medium")
    {
      thestring += "rs_active "
    }
    thestring += "><a href='#' onclick='rs.setstyle(\"medium\");rs.selhtml=rs.oldSelhtml;rs.readpage(\"" + b + '","' + c + "\");rs.softCleanup=false;return false;'>Mittel</a></li>";
    thestring += "<li class=";
    if (d == "fast")
    {
      thestring += "rs_active "
    }
    thestring += "><a href='#' onclick='rs.setstyle(\"fast\");rs.selhtml=rs.oldSelhtml;rs.readpage(\"" + b + '","' + c + "\");rs.softCleanup=false;return false;'>Hoch</a></li>";
    thestring += "</ul></fieldset></div><div style='clear: both;'></div>";
    var a = document.getElementById("controls");
    if (a != null)
    {
      a.style.display = "block";
      a.innerHTML = thestring
    }
  },
  copyselected: function (a)
  {
    if (!a)
    {
      var a = window.event
    }
    rs.getMouseXY(a);
    setTimeout("rs.getSelectedHTML()", 50);
    return true
  },
  createRspeakIcon: function ()
  {
    if (rs.mouse_x_pos && rs.mouse_y_pos && rs.selectedString.length > 0)
    {
      if (!document.getElementById("rs_selimg"))
      {
        var h = null;
        var o = document.getElementsByTagName("A");
        var b = new Array();
        for (var f = 0; f < o.length; f++)
        {
          b[f] = o[f]
        }
        for (var e = 0; e < b.length; e++)
        {
          if (b[e].getAttribute("href") && b[e].getAttribute("href").indexOf(rs.appserverhost + "/cgi-bin/rsent") != -1 && b[e].id != "rsSaveBtn")
          {
            rs.listenButtonExists = true;
            if (!rs.usersicon && b[e].getElementsByTagName("img").length > 0)
            {
              h = b[e].getElementsByTagName("img")[0].src
            }
            for (var g = 0; g < b[e].attributes.length; g++)
            {
              if (b[e].attributes[g].nodeName.toLowerCase() == "href")
              {
                var a = b[e].attributes[g].nodeValue
              }
              else
              {
                if (b[e].attributes[g].nodeName.toLowerCase() == "onclick")
                {
                  var n = b[e].attributes[g].nodeValue
                }
              }
            }
            break
          }
        }
        if (rs.listenButtonExists)
        {
          var l = document.createElement("img");
          if (rs.usersicon || !h)
          {
            h = "https://media.readspeaker.com/images/buttons/listen_icons/icon_16px.gif"
          }
          l.setAttribute("src", h);
          l.style.border = "none";
          l.setAttribute("alt", "Markierten Text vorlesen");
          l.setAttribute("title", "Markierten Text vorlesen");
          var m = document.createElement("a");
          m.setAttribute("id", "rs_selimg");
          m.setAttribute("href", a);
          m.setAttribute("onclick", "rs.keepRSicon=0; rs.setIconVisivilty();" + n);
          m.setAttribute("onmouseover", "rs.keepRSicon=1");
          m.setAttribute("onmouseout", "rs.keepRSicon=0;hideRSIcon();");
          m.style.border = "1px solid #000";
          m.style.position = "absolute";
          m.style.zIndex = "100";
          m.style.padding = "5px";
          m.style.background = "#fff";
          m.onclick = new Function(n);
          m.onmouseover = new Function("rs.keepRSicon=1");
          m.onmouseout = new Function("rs.keepRSicon=0;rs.hideRSIcon();");
          m.appendChild(l);
          var c = document.createDocumentFragment();
          c.appendChild(m);
          document.body.appendChild(c)
        }
      }
      if (rs.listenButtonExists)
      {
        var p = document.getElementById("rs_selimg");
        p.style.top = rs.mouse_y_pos + "px";
        p.style.left = rs.mouse_x_pos + "px";
        var d = rs.loadSettings("ReadSpeakerHLicon");
        if (d == "")
        {
          if (rs.popup)
          {
            d = "iconon"
          }
          else
          {
            d = "iconoff"
          }
        }
        if (d == "iconoff")
        {
          p.style.display = "none"
        }
        else
        {
          p.style.display = "inline"
        }
        rs.hideRSIcon()
      }
    }
  },
  hideRSIcon: function ()
  {
    if (rs.rs_time)
    {
      clearTimeout(rs.rs_time)
    }
    rs.rs_time = setTimeout("rs.setIconVisivilty()", 2500)
  },
  setIconVisivilty: function ()
  {
    if (rs.keepRSicon == 0)
    {
      document.getElementById("rs_selimg").style.display = "none";
      rs.rs_time = null
    }
  },
  getMouseXY: function (a)
  {
    if (a.pageX || a.pageY)
    {
      rs.mouse_x_pos = a.pageX + 15;
      rs.mouse_y_pos = a.pageY - 41
    }
    else
    {
      if (a.clientX || a.clientY)
      {
        rs.mouse_x_pos = a.clientX + document.body.scrollLeft + document.documentElement.scrollLeft + 15;
        rs.mouse_y_pos = a.clientY + document.body.scrollTop + document.documentElement.scrollTop - 41
      }
    }
    return true
  },
  getSelectedHTML: function ()
  {
    rs.selectedString = "";
    var b = undefined;
    var a = undefined;
    if (window.getSelection)
    {
      a = window.getSelection();
      if (!a.isCollapsed)
      {
        if (a.getRangeAt)
        {
          b = a.getRangeAt(0)
        }
        else
        {
          b = document.createRange();
          b.setStart(a.anchorNode, a.anchorOffset);
          b.setEnd(a.focusNode, a.focusOffset)
        }
        if (b)
        {
          DOM = b.cloneContents();
          object = document.createElement("div");
          object.appendChild(DOM.cloneNode(true));
          rs.selectedString = object.innerHTML
        }
        else
        {
          rs.selectedString = a
        }
      }
    }
    else
    {
      if (document.selection)
      {
        a = document.selection;
        b = a.createRange();
        if (b && b.htmlText)
        {
          rs.selectedString = b.htmlText
        }
        else
        {
          if (b && b.text)
          {
            rs.selectedString = b.text
          }
        }
      }
      else
      {
        if (document.getSelection)
        {
          rs.selectedString = document.getSelection()
        }
      }
    }
    rs.createRspeakIcon()
  },
  cleanup: function ()
  {
    if (rs.oldwordrange != null)
    {
      rs.oldwordrange.execCommand("backcolor", 0, rs.oldwordcol);
      rs.oldwordrange = null
    }
    if (rs.oldsentrange != null)
    {
      rs.oldsentrange.execCommand("backcolor", 0, rs.oldsentcol);
      rs.oldsentrange = null
    }
    if (rs.softCleanup)
    {
      if (rs.oldsenthl)
      {
        for (var b = 0; b < rs.oldsenthl.length; b++)
        {
          rs.oldsenthl[b].className = rs.oldsenthlclass[b]
        }
      }
      var c = document.getElementsByTagName("RS:SPAN");
      for (b = c.length - 1; b > -1; b--)
      {
        c[b].className = c[b].className.replace("sync_sent_highlighted", "");
        c[b].className = c[b].className.replace("sync_word_highlighted", "")
      }
      var c = document.getElementsByTagName("XYZ:SPAN");
      for (b = c.length - 1; b > -1; b--)
      {
        c[b].className = c[b].className.replace("sync_sent_highlighted", "");
        c[b].className = c[b].className.replace("sync_word_highlighted", "")
      }
    }
    if (rs.activeselection)
    {
      if (rs.oldwordhl)
      {
        rs.oldwordhl.className = rs.oldwordhlclass
      }
      if (rs.oldsenthl)
      {
        for (var b = 0; b < rs.oldsenthl.length; b++)
        {
          rs.oldsenthl[b].className = rs.oldsenthlclass[b]
        }
      }
      for (rs.seltextcleanuptimes = 0; rs.seltextcleanuptimes < rs.seltexttimes; rs.seltextcleanuptimes++)
      {
        rs.cleanUpSpans(" cj" + rs.seltextcleanuptimes);
        rs.cleanUpSpans(" ck" + rs.seltextcleanuptimes);
        rs.cleanUpSpans(" cl" + rs.seltextcleanuptimes)
      }
      rs.cleanUpSpans(" cja");
      rs.cleanUpSpans(" cjb")
    }
    else
    {
      if (!rs.activeselection && rs.noSelection)
      {
        var a = null;
        if (rs.readid != null)
        {
          a = document.getElementById(rs.readid)
        }
        if (a != null && rs.restorehtml != null)
        {
          a.innerHTML = rs.restorehtml
        }
        rs.noSelection = false
      }
    }
  },
  rshlsetContent: function (a)
  {
    rs.newhtml += a
  },
  rshlsetId: function (a)
  {
    rs.readid = a
  },
  rshlinit: function ()
  {
    if (rs.activeselection)
    {
      rs.firstrun = 1;
      if (document.selection)
      {
        document.selection.empty()
      }
      else
      {
        rs.identifyElementsReplacementNode(document.body)
      }
      rs.newhtml = ""
    }
    else
    {
      var a = null;
      if (rs.readid != null)
      {
        a = document.getElementById(rs.readid)
      }
      if (a != null)
      {
        a.innerHTML = rs.newhtml;
        rs.newhtml = ""
      }
    }
  },
  rshlsync: function (d, f)
  {
    var a = rs.loadSettings("ReadSpeakerHL");
    if (rs.activeselection)
    {
      if (document.selection)
      {
        if (rs.firstrun == 1)
        {
          rs.firstrun = 0;
          if (rs.selectedRange != null && a == "wordsent" || a == "sent" || a == "")
          {
            rs.selectedRange.execCommand("backcolor", 0, "#beffd6")
          }
        }
        if (a == "wordsent" || a == "word" || a == "")
        {
          if (rs.lastWordsRange)
          {
            if (a == "wordsent" || a == "")
            {
              rs.lastWordsRange.execCommand("backcolor", 0, "#beffd6")
            }
            else
            {
              rs.lastWordsRange.execCommand("backcolor", 0, rs.selectedRangeColor)
            }
          }
          rs.selectedWordsRange[f].execCommand("backcolor", 0, "#a4cbff")
        }
        rs.lastWordsRange = rs.selectedWordsRange[f]
      }
      else
      {
        var e = rs.selectedWordsRange["sync" + f];
        if (e.className.replace("word", "") != e.className)
        {
          if (rs.oldwordhl)
          {
            rs.oldwordhl.className = rs.oldwordhlclass
          }
          rs.oldwordhl = e;
          rs.oldwordhlclass = e.className;
          if (a == "wordsent" || a == "word" || a == "")
          {
            e.className = "sync_word_highlighted"
          }
        }
        if (rs.firstrun == 1)
        {
          rs.firstrun = 0;
          if (a == "wordsent" || a == "sent" || a == "")
          {
            var b = rs.returnClassArraySubstring("ffsent" + rs.seltexttimes + " ");
            rs.oldsenthl = new Array();
            rs.oldsenthlclass = new Array();
            for (var c = 0; c < b.length; c++)
            {
              rs.oldsenthl[c] = b[c];
              rs.oldsenthlclass[c] = rs.oldsenthl[c].className;
              b[c].className = "sync_sent_highlighted"
            }
          }
        }
      }
    }
    else
    {
      if (document.selection)
      {
        var e = document.getElementById("sync" + f);
        if (e && e.className == "sync_sent")
        {
          if (rs.oldwordrange != null)
          {
            rs.oldwordrange.execCommand("backcolor", 0, rs.oldwordcol)
          }
          if (rs.oldsentrange != null)
          {
            rs.oldsentrange.execCommand("backcolor", 0, rs.oldsentcol)
          }
          rs.oldsentrange = document.body.createTextRange();
          rs.oldsentrange.moveToElementText(e);
          if (rs.oldsentrange != null)
          {
            rs.oldsentcol = rs.oldsentrange.queryCommandValue("backcolor")
          }
          if (rs.oldsentrange != null)
          {
            rs.oldsentrange.execCommand("backcolor", 0, "#beffd6")
          }
        }
        else
        {
          if (e && e.className == "sync_word")
          {
            if (rs.oldwordrange != null)
            {
              rs.oldwordrange.execCommand("backcolor", 0, null)
            }
            rs.oldwordrange = document.body.createTextRange();
            rs.oldwordrange.moveToElementText(e);
            if (rs.oldwordrange != null)
            {
            }
            if (rs.oldwordrange != null)
            {
              rs.oldwordrange.execCommand("backcolor", 0, "#a4cbff")
            }
          }
        }
      }
      else
      {
        var e = document.getElementById("sync" + f);
        if (e && e.className == "sync_sent")
        {
          if (rs.oldsenthl)
          {
            rs.oldsenthl.className = "sync_sent"
          }
          rs.oldsenthl = e;
          e.className = "sync_sent_highlighted"
        }
        else
        {
          if (e && e.className == "sync_word")
          {
            if (rs.oldwordhl)
            {
              rs.oldwordhl.className = "sync_word"
            }
            rs.oldwordhl = e;
            e.className = "sync_word_highlighted"
          }
        }
      }
    }
  },
  base64Char: function (a)
  {
    if (a < 26)
    {
      return String.fromCharCode(a + "A".charCodeAt(0))
    }
    else
    {
      if (a < 52)
      {
        return String.fromCharCode(a + "a".charCodeAt(0) - 26)
      }
      else
      {
        if (a < 62)
        {
          return String.fromCharCode(a + "0".charCodeAt(0) - 52)
        }
        else
        {
          if (a == 62)
          {
            return "+"
          }
          else
          {
            if (a == 63)
            {
              return "/"
            }
            else
            {
              return String.fromCharCode(0)
            }
          }
        }
      }
    }
  },
  base64Encode: function (f)
  {
    newdata = encodeURIComponent(f);
    var g = 0;
    var e = 0;
    var b = [];
    for (; g < newdata.length; g++)
    {
      if (newdata.charCodeAt(g) != "%".charCodeAt(0))
      {
        b[e] = newdata.charCodeAt(g)
      }
      else
      {
        b[e] = parseInt("0x" + newdata.charAt(g + 1) + "" + newdata.charAt(g + 2));
        g = g + 2
      }
      e++
    }
    var l = b.length;
    var c = 4 * parseInt((l + 2) / 3);
    var h = new String();
    var k = parseInt(l / 3);
    var a;
    var d = l - 3 * k;
    g = 0;
    for (; g < 3 * k; g += 3)
    {
      a = rs.base64Char(b[g] >> 2);
      h += a;
      a = rs.base64Char(((b[g] & 3) << 4) | (b[g + 1] >> 4));
      h += a;
      a = rs.base64Char(((b[g + 1] & 15) << 2) | (b[g + 2] >> 6));
      h += a;
      a = rs.base64Char(b[g + 2] & 63);
      h += a
    }
    if (d == 1)
    {
      h += rs.base64Char(b[g] >> 2);
      h += rs.base64Char((b[g] & 3) << 4);
      h += "=";
      h += "="
    }
    if (d == 2)
    {
      h += rs.base64Char(b[g] >> 2);
      h += rs.base64Char(((b[g] & 3) << 4) | (b[g + 1] >> 4));
      h += rs.base64Char((b[g + 1] & 15) << 2);
      h += "="
    }
    return h
  },
  selectRange: function ()
  {
    rs.seltexttimes++;
    if (document.selection)
    {
      rs.selectedRange = document.selection.createRange().duplicate();
      rs.selectedRangeColor = rs.selectedRange.queryCommandValue("backcolor");
      return rs.selectRangeIE(rs.selectedRange, -1)
    }
    else
    {
      var a = "";
      var b = window.getSelection().getRangeAt(0);
      rs.start = b.startContainer;
      rs.stop = b.endContainer;
      rs.startOffset = rs.modifyOffsetStartOfWord(rs.start, b.startOffset);
      rs.endOffset = rs.modifyOffsetEndOfWord(rs.stop, b.endOffset);
      rs.bmindex++;
      rs.sentbmindex = rs.bmindex;
      rs.bmindex++;
      rs.startofsentence = 1;
      a = rs.rangeMarkupGecko(b.commonAncestorContainer);
      window.getSelection().removeAllRanges();
      rs.cleanup();
      return (a)
    }
  },
  selectRangeIE: function (m)
  {
    var p = m.duplicate();
    m.moveStart("word", -1);
    m.moveStart("word", 1);
    if (!p.isEqual(m))
    {
      m.moveStart("word", -1)
    }
    p = m.duplicate();
    m.moveEnd("word", 1);
    m.moveEnd("word", -1);
    if (!p.isEqual(m))
    {
      m.moveEnd("word", 1)
    }
    var l = m.duplicate();
    var q = 0;
    var t = "";
    var n = m;
    var w = 1;
    var k = m.parentElement();
    var u = 0;
    l.collapse();
    var a = l.duplicate();
    a.collapse(false);
    var g = 0;
    while (m.inRange(l))
    {
      g++;
      q++;
      if (q > 10000)
      {
        break
      }
      l.collapse(false);
      l.expand("word", 1);
      var h = "";
      var b = "";
      var s = l.duplicate();
      s.collapse(false);
      a.collapse(false);
      if (a.compareEndPoints("StartToStart", s) == 0 && a.compareEndPoints("EndToEnd", s) == 0)
      {
        u++;
        if (u < 2)
        {
          l.move("character", 1)
        }
        else
        {
          if (u < 4)
          {
            l.move("character", 2)
          }
          else
          {
            if (u < 6)
            {
              l.move("word", 1)
            }
            else
            {
              if (u < 8)
              {
                l.move("word", 2)
              }
              else
              {
                if (u < 10)
                {
                  l.move("sentence", 1)
                }
                else
                {
                  if (u < 12)
                  {
                    l.move("sentence", 2)
                  }
                  else
                  {
                    break
                  }
                }
              }
            }
          }
        }
        l.collapse(false)
      }
      else
      {
        u = 0;
        if (g == -1)
        {
          return l
        }
        rs.selectedWordsRange[g] = l.duplicate();
        var r = l.text;
        var f = l.htmlText;
        l.collapse(false);
        var e = rs.iterateParentTree(l.parentElement(), n.parentElement(), k, 0);
        var c = rs.iterateParentTree(n.parentElement(), l.parentElement(), k, 0);
        var v = l.parentElement();
        for (var o = 0; o < e && o < 20; o++)
        {
          if (!v.className.match("sync_"))
          {
            h = v.outerHTML.match("<[^>]*>")[0] + h
          }
          v = v.parentElement
        }
        var v = n.parentElement();
        for (var o = 0; o < c && o < 20; o++)
        {
          if (!v.className.match("sync_"))
          {
            b += "</" + v.tagName + ">"
          }
          v = v.parentElement
        }
        n = l.duplicate();
        if (w)
        {
          t += h;
          w = 0
        }
        else
        {
          t += b + h
        }
        if (f.replace("sync_sent_highlighted", "") != "")
        {
          t += "<span class='sync_user' id='sync" + g + "'>" + r + "</span>"
        }
        l.collapse(false);
        l.expand("character");
        a = l.duplicate()
      }
    }
    t += "<!-- f -->";
    var c = rs.iterateParentTree(n.parentElement(), document.body, k, 0);
    var v = n.parentElement();
    for (var o = 0; o < c; o++)
    {
      if (!v.className.match("sync_"))
      {
        t += "</" + v.tagName + ">"
      }
      v = v.parentElement
    }
    l.collapse();
    return (t)
  },
  iterateParentTree: function (b, d, f, a)
  {
    var e = d;
    while (e != null)
    {
      if (b == f)
      {
        return a
      }
      else
      {
        if (b == e)
        {
          return a
        }
      }
      e = e.parentElement
    }
    a++;
    return rs.iterateParentTree(b.parentElement, d, f, a)
  },
  rangeMarkupGecko: function (c)
  {
    rs.firstrun = 1;
    var e = "";
    if (c.nodeType == 3)
    {
      e += rs.markup(c)
    }
    else
    {
      var b;
      var a = "";
      if (c.hasChildNodes())
      {
        for (b = 0; b < c.childNodes.length; b++)
        {
          var f = c.childNodes.item(b);
          if (f == rs.start)
          {
            rs.inc = 1
          }
          if (c == rs.start && b == rs.startOffset)
          {
            rs.inc = 1
          }
          a += rs.rangeMarkupGecko(c.childNodes.item(b));
          if (c == rs.stop && b == rs.endOffset)
          {
            rs.inc = 0;
            break
          }
          if (f == rs.stop)
          {
            rs.inc = 0;
            break
          }
        }
      }
      if (rs.inc && (!c.className || (c.className.replace("sync") == c.parentNode.className && c.id.replace("sync") == c.parentNode.id)))
      {
        var d = document.createElement("div");
        d.appendChild(c.cloneNode(true));
        tempdivtag = d.innerHTML.match("<[^>]*>");
        if (tempdivtag != null && tempdivtag.length > 0)
        {
          e += tempdivtag[0];
          e += a;
          e += "</" + c.nodeName + ">"
        }
        else
        {
          e += a
        }
      }
      else
      {
        e += a
      }
      if (c.hasChildNodes())
      {
        for (b = 0; b < c.childNodes.length; b++)
        {
          if (c == rs.stop && b == rs.endOffset)
          {
            rs.inc = 0;
            break
          }
          if (f == rs.stop)
          {
            rs.inc = 0;
            break
          }
        }
      }
    }
    return e.replace(/xyz:span/g, "span")
  },
  markup: function (d)
  {
    var f = "";
    var b;
    var e = "";
    var g = "";
    var a = d.nodeValue;
    if ((d == rs.start && rs.startOffset != -1) && (d == rs.stop && rs.endOffset != -1))
    {
      e = d.nodeValue.substring(0, rs.startOffset);
      a = d.nodeValue.substring(rs.startOffset, rs.endOffset);
      g = d.nodeValue.substring(rs.endOffset);
      rs.inc = 1
    }
    else
    {
      if (d == rs.start && rs.startOffset != -1)
      {
        e = d.nodeValue.substring(0, rs.startOffset);
        a = d.nodeValue.substring(rs.startOffset);
        rs.inc = 1
      }
      else
      {
        if (d == rs.stop && rs.endOffset != -1)
        {
          a = d.nodeValue.substring(0, rs.endOffset);
          g = d.nodeValue.substring(rs.endOffset);
          rs.inc = 1
        }
      }
    }
    if (!rs.inc)
    {
      return ""
    }
    f = rs.markupSentences(rs.htmlencode(a), null);
    if (d == rs.stop && rs.endOffset != -1)
    {
      rs.inc = 0
    }
    if (d.parentNode != null && a != "")
    {
      var c = rs.createreplacementnode(e + f + g, getComputedStyle(d.parentNode, null));
      d.parentNode.insertBefore(c, d);
      d.parentNode.removeChild(d)
    }
    return f
  },
  markupSentences: function (c)
  {
    var a = rs.splitString(c, ",.!");
    if (!a)
    {
      return ""
    }
    var d = "";
    var e = new Array();
    for (var b = 0; b < a.length; b++)
    {
      d += "<xyz:span class=' ffsent" + rs.seltexttimes + " cj" + rs.seltexttimes + "' ";
      d += "id='sync" + (rs.sentbmindex) + "'";
      rs.startofsentence = 0;
      d += ">";
      d += rs.markupWords(a[b]);
      d += "</xyz:span>"
    }
    return d
  },
  markupWords: function (c)
  {
    var d = rs.splitString(c, " ");
    if (!d)
    {
      return ""
    }
    var b = "";
    var e = new Array();
    for (var a = 0; a < d.length; a++)
    {
      b += "<xyz:span class='sync_user word ck" + rs.seltexttimes + "'";
      b += " id='sync" + (rs.bmindex++) + "'";
      b += ">";
      b += (d[a]);
      b += "</xyz:span>"
    }
    return b
  },
  htmlencode: function (b)
  {
    var c = document.createElement("div");
    var a = document.createTextNode(b);
    c.appendChild(a);
    return c.innerHTML
  },
  identifyElementsReplacementNode: function (b)
  {
    if (b.tagName && b.tagName == "XYZ:SPAN" && b.id)
    {
      rs.selectedWordsRange[b.id] = b
    }
    if (b.hasChildNodes())
    {
      for (var a = 0; a < b.childNodes.length; a++)
      {
        var c = b.childNodes.item(a);
        rs.identifyElementsReplacementNode(c)
      }
    }
  },
  createreplacementnode: function (c, a)
  {
    var b = document.createElement("xyz:span");
    b.innerHTML = c;
    b.setAttribute("class", "synctemp cl" + rs.seltexttimes);
    return b
  },
  modifyOffsetStartOfWord: function (a, b)
  {
    while (a.nodeValue && b != 0 && (a.nodeValue.substring(b - 1, b) != " " && a.nodeValue.substring(b - 1, b) != "."))
    {
      b--
    }
    return b
  },
  modifyOffsetEndOfWord: function (a, b)
  {
    while (a.nodeValue && b != a.nodeValue.length && (a.nodeValue.substring(b - 1, b) != " " && a.nodeValue.substring(b - 1, b) != "."))
    {
      b++
    }
    return b
  },
  returnClassArraySubstring: function (b)
  {
    var c = document.getElementsByTagName("*");
    var d = 0;
    var a = new Array();
    for (i = 0; i < c.length; i++)
    {
      if (c[i].className.replace(b, "") != c[i].className)
      {
        a[d] = c[i];
        d++
      }
    }
    return a
  },
  cleanUpSpans: function (b)
  {
    var c = document.getElementsByTagName("SPAN");
    var a;
    for (i = c.length - 1; i > -1; i--)
    {
      if (c[i].className.indexOf(b) > -1)
      {
        a = document.createDocumentFragment();
        for (j = 0; j < c[i].childNodes.length; j++)
        {
          a.appendChild(c[i].childNodes[j].cloneNode(true))
        }
        c[i].parentNode.replaceChild(a, c[i])
      }
    }
    var c = document.getElementsByTagName("XYZ:SPAN");
    var a;
    for (i = c.length - 1; i > -1; i--)
    {
      if (c[i].className.indexOf(b) > -1)
      {
        a = document.createDocumentFragment();
        for (j = 0; j < c[i].childNodes.length; j++)
        {
          a.appendChild(c[i].childNodes[j].cloneNode(true))
        }
        c[i].parentNode.replaceChild(a, c[i])
      }
    }
  },
  splitString: function (e, d)
  {
    var a = new Array("");
    var b = 0;
    for (var c = 0; c < e.length; c++)
    {
      if (d.indexOf(e[c]) == -1)
      {
        a[b] += e[c]
      }
      else
      {
        a[b] += e[c];
        while (e[c + 1] && d.indexOf(e[c]) != -1)
        {
          a.push(e[c + 1]);
          c++;
          b++
        }
      }
    }
    return a
  }
};
/*
if (document.addEventListener)
{
  document.addEventListener("mouseup", rs.copyselected, false);
  document.addEventListener("keyup", rs.copyselected, false)
}
else
{
  if (document.attachEvent)
  {
    document.attachEvent("onmouseup", rs.copyselected);
    document.attachEvent("onkeyup", rs.copyselected)
  }
  else
  {
    document.onmouseup = rs.copyselected;
    document.onkeyup = rs.copyselected
  }
}
*/
function readpage(a, b)
{
  rs.readpage(a, b)
}

function rshlsetContent(a)
{
  rs.rshlsetContent(a)
}

function rshlsetId(a)
{
  rs.rshlsetId(a)
}

function rshlinit()
{
  rs.rshlinit()
}

function rshlsync(a, b)
{
  rs.rshlsync(a, b)
}

function rshlexit()
{
  rs.rshlexit()
}
var thestylesheet = "<style type='text/css'> ";
thestylesheet += "#rspopup { position: absolute; z-index: 100; background: #fff; width: 350px; border-color: #a4cbff #aeaeae #aeaeae; border-right: 1px solid #aeaeae; border-style: solid; border-width: 1px; margin: 3px 3px 3px 0; font-size: 12px; font-family: Arial; padding: 3px; -moz-box-shadow: 0 7px 6px #999; -webkit-box-shadow: 0 7px 6px #999; -box-shadow: 0 7px 6px #999; }";
thestylesheet += ".rs_block {  float: left; margin: 0 3px 0 0; padding: 3px; border: 1px solid #ddd; width: 160px; }";
thestylesheet += ".rs_block legend { font-weight: bold; color: #000; }";
thestylesheet += ".rs_block ul { margin: 0; padding: 0; list-style: none; }";
thestylesheet += ".rs_block li { padding: 0; margin: 0; width: 100%; }";
thestylesheet += ".rs_block li a { display: block; padding: 5px 0 5px 20px; text-decoration: none; color: #000;}";
thestylesheet += ".rs_block li a:hover { background: #eee; }";
thestylesheet += ".rs_block li.rs_active { background-color: #A4CBFF; background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, rgb(144,192,240)), color-stop(0.79, rgb(229,237,255))); background-image: -moz-linear-gradient(center bottom, rgb(144,192,240) 0%, rgb(229,237,255) 79%); }";
thestylesheet += ".rs_block li.rs_active a, .rs_block li.rs_active a:hover { background: transparent url(https://media.readspeaker.com/images/enterprise/default/rs_arrow.gif) no-repeat scroll 10px center; }";
thestylesheet += "#bottomlinks { font-family:Arial;color:#333;font-size:11px; margin: 2px 0 1px 0;} #bottomlinks a {color:black;text-decoration : none;padding: 2px;} #bottomlinks a:hover {color:black;text-decoration : none;background-color: #a4cbff; }";
thestylesheet += "a.rs_settings { background: transparent url(https://media.readspeaker.com/images/enterprise/default/cog.png) no-repeat 1px 1px}";
thestylesheet += ".sync_word_highlighted { background-color: #a4cbff; }";
thestylesheet += ".sync_sent_highlighted { background-color: #beffd6; }";
thestylesheet += "</style>";
document.write(thestylesheet);
