(function(r){var h=new function(){this.Response=function(c,b,a,f){this.isBusy=f;this.hasError=c;this.error=b;this.reader=a;this.getTypeString=function(){return"dataStream.Response"}};this.Error=function(c,b,a){this.errorMessage=c;this.errorCode=b;this.innerError=a;this.getTypeString=function(){return"dataStream.Error"}};this.RequestError=function(c,b){this.requestStatus=c;this.requestStatusText=b;this.getTypeString=function(){return"dataStream.RequestError"}};this.DataReader=function(c){this.offset=
0;this.decodedData=t.decode(c);this.getTypeString=function(){return"dataStream.DataReader"};this.getByteLength=function(){return this.decodedData.length};this.readSINT=function(){var b=s(this.decodedData.substr(this.offset,1),1);this.offset+=1;return b};this.readINT=function(){var b=s(this.decodedData.substr(this.offset,2),2);this.offset+=2;return b};this.readDINT=function(){var b=s(this.decodedData.substr(this.offset,4),4);this.offset+=4;return b};this.readBYTE=function(){var b=g(this.decodedData.substr(this.offset,
1),1);this.offset+=1;return b};this.readWORD=function(){var b=g(this.decodedData.substr(this.offset,2),2);this.offset+=2;return b};this.readDWORD=function(){var b=g(this.decodedData.substr(this.offset,4),4);this.offset+=4;return b};this.readBOOL=function(){var b=this.decodedData.substr(this.offset,1).charCodeAt(0);this.offset+=1;return b};this.readString=function(b){if(isNaN(b))throw'Parameter "length" has to be a valid number.';var a=this.decodedData.substr(this.offset,b);this.offset+=b;return a};
this.readStringZero=function(b){if(isNaN(b))throw'Parameter "length" has to be a valid number.';var a=b;-1<this.decodedData.search("\x00")&&(a=this.decodedData.search("\x00"));a=this.decodedData.substr(this.offset,a);this.offset+=b;return a};this.readREAL=function(){var b=[];b[0]=g(this.decodedData.substr(this.offset+0,1),1);b[1]=g(this.decodedData.substr(this.offset+1,1),1);b[2]=g(this.decodedData.substr(this.offset+2,1),1);b[3]=g(this.decodedData.substr(this.offset+3,1),1);var a=[];a[0]=m(b[0]);
a[1]=m(b[1]);a[2]=m(b[2]);a[3]=m(b[3]);b=u(a[3]+a[2]+a[1]+a[0],h.TcAdsDataTypes.REAL);this.offset+=4;return b};this.readLREAL=function(){var b=[];b[0]=g(this.decodedData.substr(this.offset+0,1),1);b[1]=g(this.decodedData.substr(this.offset+1,1),1);b[2]=g(this.decodedData.substr(this.offset+2,1),1);b[3]=g(this.decodedData.substr(this.offset+3,1),1);b[4]=g(this.decodedData.substr(this.offset+4,1),1);b[5]=g(this.decodedData.substr(this.offset+5,1),1);b[6]=g(this.decodedData.substr(this.offset+6,1),1);
b[7]=g(this.decodedData.substr(this.offset+7,1),1);var a=[];a[0]=m(b[0]);a[1]=m(b[1]);a[2]=m(b[2]);a[3]=m(b[3]);a[4]=m(b[4]);a[5]=m(b[5]);a[6]=m(b[6]);a[7]=m(b[7]);b=u(a[7]+a[6]+a[5]+a[4]+a[3]+a[2]+a[1]+a[0],h.TcAdsDataTypes.LREAL);this.offset+=8;return b}};this.DataWriter=function(){this.getTypeString=function(){return"dataStream.DataWriter"};this.getBase64EncodedData=function(){return t.encode(r(c))};this.writeSINT=function(a){c=b(a,h.TcAdsDataTypes.Integer,1,c)};this.writeINT=function(a){c=b(a,
h.TcAdsDataTypes.Integer,2,c)};this.writeDINT=function(a){c=b(a,h.TcAdsDataTypes.Integer,4,c)};this.writeBYTE=function(a){c=b(a,h.TcAdsDataTypes.UnsignedInteger,1,c)};this.writeWORD=function(a){c=b(a,h.TcAdsDataTypes.UnsignedInteger,2,c)};this.writeDWORD=function(a){c=b(a,h.TcAdsDataTypes.UnsignedInteger,4,c)};this.writeBOOL=function(a){c=b(a,h.TcAdsDataTypes.BOOL,1,c)};this.writeString=function(a,f){c=b(a,h.TcAdsDataTypes.String,f,c)};this.writeREAL=function(a){c=b(a,h.TcAdsDataTypes.REAL,4,c)};
this.writeLREAL=function(a){c=b(a,h.TcAdsDataTypes.LREAL,8,c)};var c=[],b=function(a,b,c,e){var d=e.length;if(b==h.TcAdsDataTypes.String){for(b=0;b<a.length;b++)e[d++]=a.charCodeAt(b);for(;b<c;b++)e[d++]=0}else b==h.TcAdsDataTypes.BOOL?e[d++]=a:b==h.TcAdsDataTypes.Integer||b==h.TcAdsDataTypes.UnsignedInteger?1==c?e[d++]=q(parseInt(a>>0,10)):2==c?(a=parseInt(a),e[d++]=q(parseInt(a>>0,10)),e[d++]=q(parseInt(a>>8,10))):4==c&&(a=parseInt(a),isNaN(a)&&(a=0),e[d++]=q(parseInt(a>>0,10)),e[d++]=q(parseInt(a>>
8,10)),e[d++]=q(parseInt(a>>16,10)),e[d++]=q(parseInt(a>>24,10))):b==h.TcAdsDataTypes.REAL?(a=v(a,b),c=[],c[0]=a.substring(0,8),c[1]=a.substring(8,16),c[2]=a.substring(16,24),c[3]=a.substring(24,32),e[d++]=p(c[3]),e[d++]=p(c[2]),e[d++]=p(c[1]),e[d++]=p(c[0])):b==h.TcAdsDataTypes.LREAL&&(a=v(a,b),c=[],c[0]=a.substring(0,8),c[1]=a.substring(8,16),c[2]=a.substring(16,24),c[3]=a.substring(24,32),c[4]=a.substring(32,40),c[5]=a.substring(40,48),c[6]=a.substring(48,56),c[7]=a.substring(56,64),e[d++]=p(c[7]),
e[d++]=p(c[6]),e[d++]=p(c[5]),e[d++]=p(c[4]),e[d++]=p(c[3]),e[d++]=p(c[2]),e[d++]=p(c[1]),e[d++]=p(c[0]));return e}};this.TcAdsDataTypes={String:0,BOOL:1,Integer:2,UnsignedInteger:3,LREAL:4,REAL:5};var r=function(c){for(var b="",a=0;a<c.length;a++)b+=String.fromCharCode(c[a]&255);return b},t=new function(){return{encode:function(c){for(var b="",a,f,h,e,d,k,n=0;n<c.length;)a=c.charCodeAt(n++),f=c.charCodeAt(n++),h=c.charCodeAt(n++),e=a>>2,a=((a&3)<<4)+(f>>4),d=((f&15)<<2)+(h>>6),k=h&63,isNaN(f)?d=
k=64:isNaN(h)&&(k=64),b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(e)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(a)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(d)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(k);return b},decode:function(c){for(var b="",a,f,h,e,d,k=0;k<c.length;)a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(c.charAt(k++)),f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(c.charAt(k++)),
e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(c.charAt(k++)),d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(c.charAt(k++)),a=(a<<2)+(f>>4),f=((f&15)<<4)+(e>>2),h=((e&3)<<6)+d,b+=String.fromCharCode(a),64!=e&&(b+=String.fromCharCode(f)),64!=d&&(b+=String.fromCharCode(h));return b}}},v=function(c,b){var a=0,f=0,g=0;switch(b){case h.TcAdsDataTypes.LREAL:a=11;f=52;g=1023;break;default:a=8,f=23,g=127}var e=0<=c?0:1,d=0,k,n;if(0<c||0>c){n=2>
c&&-2<c?-1:1;for(k=0;1>d||2<d;++k)d=Math.pow(-1,e)*c/Math.pow(2,n*k);k--}else k=g,n=-1;g=(g+n*k).toString(2);for(k=g.length;k<a;k++)g="0"+g;n=a=0;var l="",d=d-1;for(k=1;k<f+1;k++)n=a+1/Math.pow(2,k),n<=d?(a=n,l+="1"):l+="0";return e+g+l},u=function(c,b){var a=!0,f=!0,g=!0,e="",d,k,n;c.charAt(0);switch(b){case h.TcAdsDataTypes.LREAL:d=11;k=52;n=1023;break;default:d=8,k=23,n=127}for(var l=1;l<=d;l++)e+=c.charAt(l),"0"!=c.charAt(l)&&(a=!1),"1"!=c.charAt(l)&&(g=!1);for(var m="",l=d+1;l<=d+k;l++)m+=c.charAt(l),
"0"!=c.charAt(l)&&(f=!1);if(a&&f)return 0;if(g&&f)return Infinity;if(g&&f)return NaN;a=p(e)-n;for(l=f=0;l<m.length;++l)f+=parseInt(m.charAt(l))*Math.pow(2,-(l+1));f+=1;return Math.pow(-1,c.charAt(0))*f*Math.pow(2,a)},q=function(c){return parseInt(c,10)&255},m=function(c){var b="",a=0;do b+=1==Math.floor(c%2)?"1":"0",c/=2,a++;while(8>a);return b=b.split("").reverse().join("")},p=function(c){for(var b=0,a=0;a<c.length;++a)"1"==c.charAt(a)&&(b+=Math.pow(2,c.length-a-1));return b},g=function(c,b){var a=
0;4==b?a=(c.charCodeAt(3)<<24|c.charCodeAt(2)<<16|c.charCodeAt(1)<<8|c.charCodeAt(0))>>>0:2==b?a=(c.charCodeAt(1)<<8|c.charCodeAt(0))>>>0:1==b&&(a=c.charCodeAt(0)>>>0);return a},s=function(c,b){var a=0;4==b?a=c.charCodeAt(3)<<24|c.charCodeAt(2)<<16|c.charCodeAt(1)<<8|c.charCodeAt(0):2==b?(a=c.charCodeAt(1)<<8|c.charCodeAt(0),a=32768==(a&32768)?a|4294934528:a&32767):1==b&&(a=c.charCodeAt(0),a=128==(a&128)?a|4294967168:a&127);return a}};r.dataStream=h})(window);
