11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)/*
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) * Binary Ajax 0.1.5
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) * Copyright (c) 2008 Jacob Seidelin, cupboy@gmail.com, http://blog.nihilogic.dk/
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) * MIT License [http://www.opensource.org/licenses/mit-license.php]
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) */
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)var BinaryFile = function(strData, iDataOffset, iDataLength) {
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  var data = strData;
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  var dataOffset = iDataOffset || 0;
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  var dataLength = 0;
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.getRawData = function() {
151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return data;
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  if (typeof strData == "string") {
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    dataLength = iDataLength || data.length;
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    this.getByteAt = function(iOffset) {
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return data.charCodeAt(iOffset + dataOffset) & 0xFF;
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  } else if (typeof strData == "unknown") {
251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    dataLength = iDataLength || IEBinary_getLength(data);
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    this.getByteAt = function(iOffset) {
281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return IEBinary_getByteAt(data, iOffset + dataOffset);
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.getLength = function() {
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return dataLength;
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.getSByteAt = function(iOffset) {
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    var iByte = this.getByteAt(iOffset);
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (iByte > 127)
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return iByte - 256;
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    else
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return iByte;
421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.getShortAt = function(iOffset, bBigEndian) {
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    var iShort = bBigEndian ?
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      (this.getByteAt(iOffset) << 8) + this.getByteAt(iOffset + 1)
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      : (this.getByteAt(iOffset + 1) << 8) + this.getByteAt(iOffset)
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (iShort < 0) iShort += 65536;
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return iShort;
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.getSShortAt = function(iOffset, bBigEndian) {
521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    var iUShort = this.getShortAt(iOffset, bBigEndian);
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (iUShort > 32767)
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return iUShort - 65536;
551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    else
561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return iUShort;
571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.getLongAt = function(iOffset, bBigEndian) {
591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    var iByte1 = this.getByteAt(iOffset),
601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      iByte2 = this.getByteAt(iOffset + 1),
611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      iByte3 = this.getByteAt(iOffset + 2),
621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      iByte4 = this.getByteAt(iOffset + 3);
631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    var iLong = bBigEndian ?
651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      (((((iByte1 << 8) + iByte2) << 8) + iByte3) << 8) + iByte4
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      : (((((iByte4 << 8) + iByte3) << 8) + iByte2) << 8) + iByte1;
671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (iLong < 0) iLong += 4294967296;
681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return iLong;
691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.getSLongAt = function(iOffset, bBigEndian) {
711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    var iULong = this.getLongAt(iOffset, bBigEndian);
721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (iULong > 2147483647)
731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return iULong - 4294967296;
741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    else
751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      return iULong;
761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.getStringAt = function(iOffset, iLength) {
781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    var aStr = [];
791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    for (var i=iOffset,j=0;i<iOffset+iLength;i++,j++) {
801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      aStr[j] = String.fromCharCode(this.getByteAt(i));
811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return aStr.join("");
831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.getCharAt = function(iOffset) {
861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return String.fromCharCode(this.getByteAt(iOffset));
871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.toBase64 = function() {
891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return window.btoa(data);
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  this.fromBase64 = function(strBase64) {
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    data = window.atob(strBase64);
931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)var BinaryAjax = (function() {
981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  function createRequest() {
1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    var oHTTP = null;
1011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (window.XMLHttpRequest) {
1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      oHTTP = new XMLHttpRequest();
1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    } else if (window.ActiveXObject) {
1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return oHTTP;
1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  function getHead(strURL, fncCallback, fncError) {
1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    var oHTTP = createRequest();
1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (oHTTP) {
1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (fncCallback) {
1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        if (typeof(oHTTP.onload) != "undefined") {
1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          oHTTP.onload = function() {
1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            if (oHTTP.status == "200") {
1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              fncCallback(this);
1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            } else {
1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              if (fncError) fncError();
1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            }
1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            oHTTP = null;
1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          };
1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        } else {
1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          oHTTP.onreadystatechange = function() {
1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            if (oHTTP.readyState == 4) {
1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              if (oHTTP.status == "200") {
1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                fncCallback(this);
1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              } else {
1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                if (fncError) fncError();
1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              }
1301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              oHTTP = null;
1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            }
1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          };
1331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        }
1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      }
1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      oHTTP.open("HEAD", strURL, true);
1361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      oHTTP.send(null);
1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    } else {
1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (fncError) fncError();
1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
1401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  function sendRequest(strURL, fncCallback, fncError, aRange, bAcceptRanges, iFileSize) {
1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    var oHTTP = createRequest();
1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (oHTTP) {
1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      var iDataOffset = 0;
1471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (aRange && !bAcceptRanges) {
1481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        iDataOffset = aRange[0];
1491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      }
1501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      var iDataLen = 0;
1511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (aRange) {
1521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        iDataLen = aRange[1]-aRange[0]+1;
1531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      }
1541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (fncCallback) {
1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        if (typeof(oHTTP.onload) != "undefined") {
1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          oHTTP.onload = function() {
1581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            if (oHTTP.status == "200" || oHTTP.status == "206") {
1601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              this.binaryResponse = new BinaryFile(this.responseText, iDataOffset, iDataLen);
1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              this.fileSize = iFileSize || this.getResponseHeader("Content-Length");
1621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              fncCallback(this);
1631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            } else {
1641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              if (fncError) fncError();
1651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            }
1661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            oHTTP = null;
1671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          };
1681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        } else {
1691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          oHTTP.onreadystatechange = function() {
1701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            if (oHTTP.readyState == 4) {
1711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              if (oHTTP.status == "200" || oHTTP.status == "206") {
1721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                this.binaryResponse = new BinaryFile(oHTTP.responseBody, iDataOffset, iDataLen);
1731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                this.fileSize = iFileSize || this.getResponseHeader("Content-Length");
1741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                fncCallback(this);
1751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              } else {
1761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                if (fncError) fncError();
1771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              }
1781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)              oHTTP = null;
1791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            }
1801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          };
1811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        }
1821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      }
1831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      oHTTP.open("GET", strURL, true);
1841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (oHTTP.overrideMimeType) oHTTP.overrideMimeType('text/plain; charset=x-user-defined');
1861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (aRange && bAcceptRanges) {
1881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        oHTTP.setRequestHeader("Range", "bytes=" + aRange[0] + "-" + aRange[1]);
1891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      }
1901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      oHTTP.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 1970 00:00:00 GMT");
1921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      oHTTP.send(null);
1941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    } else {
1951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (fncError) fncError();
1961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
1971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return function(strURL, fncCallback, fncError, aRange) {
2001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (aRange) {
2021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      getHead(
2031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        strURL,
2041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        function(oHTTP) {
2051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          var iLength = parseInt(oHTTP.getResponseHeader("Content-Length"),10);
2061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          var strAcceptRanges = oHTTP.getResponseHeader("Accept-Ranges");
2071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          var iStart, iEnd;
2091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          iStart = aRange[0];
2101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          if (aRange[0] < 0)
2111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)            iStart += iLength;
2121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          iEnd = iStart + aRange[1] - 1;
2131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)          sendRequest(strURL, fncCallback, fncError, [iStart, iEnd], (strAcceptRanges == "bytes"), iLength);
2151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        }
2161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      );
2171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    } else {
2191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      sendRequest(strURL, fncCallback, fncError);
2201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    }
2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
2221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}());
2241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)document.write(
2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  "<script type='text/vbscript'>\r\n"
2281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  + "Function IEBinary_getByteAt(strBinary, iOffset)\r\n"
2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  + "	IEBinary_getByteAt = AscB(MidB(strBinary,iOffset+1,1))\r\n"
2301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  + "End Function\r\n"
2311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  + "Function IEBinary_getLength(strBinary)\r\n"
2321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  + "	IEBinary_getLength = LenB(strBinary)\r\n"
2331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  + "End Function\r\n"
2341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  + "</script>\r\n"
2351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles));
236