(function(){var e,t,n,r,a,i,o,s,c,u,l,d,g,p,f,m,v,h,I,E,x,S,w=[].slice;x={localStorage:this.localStorage?!0:!1,postMessage:this.postMessage?!0:!1},x.localStorage||(this.localStorage={setItem:function(){},getItem:function(){},removeItem:function(){}},this.sessionStorage={setItem:function(){},getItem:function(){},removeItem:function(){}}),i=this.localStorage,u=this.sessionStorage,S=function(){var e,t,n;return e=(new Date).getTime(),t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n=t.replace(/[xy]/g,function(t){var n;return n=(e+16*Math.random())%16|0,e=Math.floor(e/16),"x"===t?n.toString(16):(7&n|8).toString(16)}),n.replace(/-/g,"").toUpperCase()},t={get:function(e){var t,n;return n="(^|;)\\s*"+e+"=([^;\\s]*)",t=document.cookie.match(new RegExp(n)),t&&t.length>=3?decodeURIComponent(t[2]):null},set:function(e,t,n,r,a,i){var o,s,c,u,l;return n&&(o=new Date,o.setTime(o.getTime()+864e5*n)),c=n?"; expires="+o.toGMTString():"",u="; path="+(a||"/"),s=r?"; domain="+r:"",l=i?"; secure":"",document.cookie=e+"="+encodeURIComponent(t)+c+u+s+l},remove:function(e,n,r){return t.set(e,"",-1,n,r)}},m=function(e){return"[object Object]"===Object.prototype.toString.call(e)},g=Array.prototype.every,g||(g=function(e){var t,n,r,a;for(n=!0,r=0,a=this.length;a>r;r++)if(t=this[r],!e(t))return!1;return n}),p=function(){var e,t,n,r;n=arguments[0],t=2<=arguments.length?w.call(arguments,1):[];for(e in n)r=n[e],n[e]=r;return t.forEach(function(t){var a;a=[];for(e in t)r=t[e],a.push(n[e]=r);return a}),n},E={API_PATH:"http://rd.gdatacube.net/dc/html5/sync",PROXY:"http://rd.gdatacube.net/dc/html5/whoami",CLIENT_KEY:"dcagent_client_id",VERSION_NUMBER:"6",appId:"",deviceId:"",accountId:"",channel:"",appVer:"",interval:10,initialized:!1,loginTime:0,timer:0},l={max:100,count:0,excludes:[],isReportAllowed:function(e){var t;return l.countl.max&&(e.data.errors=e.data.errors.slice(0,100)),c=e.data;for(t in c)a=c[t],"number"==typeof a&&(n[t]=String(a));return n=p({headers:f.getBaseSettings()},e.data),E.debug?E.debug(E.API_PATH,n):(i=new XMLHttpRequest,i.timeout=3e4,i.open("POST",E.API_PATH,!0),i.setRequestHeader("Content-Type","text/plain; charset=UTF-8"),r=Date.now(),i.onreadystatechange=function(t){var n,a,i;return a=this.status>=200&&this.status<300,4===this.readyState?(n=Date.now()-r,i=a&&"success"===this.responseText,i?(h.succ=1,h.fail=0,h.total=n):(h.fail+=1,h.succ=0,h.total+=n),d.updateEvents({eventid:s,labelmap:JSON.stringify(h),duration:"1"}),i?"function"==typeof e.success?e.success(t):void 0:"function"==typeof e.fail?e.fail(t):void 0):void 0},i.ontimeout=function(){return h.fail+=1,h.succ=0,h.total+=elapsed,d.updateEvents({eventid:s,labelmap:JSON.stringify(h),duration:"1"})},i.send(JSON.stringify(n)))}},a="dcagent_client_events",r="dcagent_client_errors",o="dcagent_parent_id",e="dcagent_create_time",c="dcagent_login_time",d={getEvents:function(){return function(){var e;return e=i.getItem(a),e?JSON.parse(e):[]}}(this),getErrors:function(){return function(){var e;return e=i.getItem(r),e?JSON.parse(e):[]}}(this),updateEvents:function(){return function(e,t){var n,r,o,s;if(null==t&&(t=!0),n=d.getEvents(),Array.isArray(e))for(o=0,s=e.length;s>o;o++)r=e[o],n.push(r);else n.push(e);return x.localStorage&&t?i.setItem(a,JSON.stringify(n.slice(0,l.max))):I({data:{events:n}})}}(this),updateErrors:function(){return function(e){var t,n,a,o;if(t=d.getErrors(),Array.isArray(e))for(a=0,o=e.length;o>a;a++)n=e[a],t.push(n);else t.push(e);return x.localStorage?i.setItem(r,JSON.stringify(t.slice(0,l.max))):I({data:{errors:t}})}}(this),clear:function(){return function(){return i.removeItem(a),i.removeItem(r)}}(this)},f={set:function(e,n){return null==n&&(n=S()),localStorage.setItem(e,n),t.set(e,n,365),n},get:function(e){return localStorage.getItem(e)||t.get(e)},getBaseSettings:function(){var t;if(!E.appId)throw new Error("InitError: missing appId");if(!E.accountId)throw new Error("AccountError: unknown accountId");if(!E.deviceId)throw new Error("DeviceError: unknown device");return t=parseInt((Date.now()-E.loginTime)/1e3)||1,{appid:E.appId,accountid:E.accountId,uid:E.deviceId,appver:E.appVer,ver:E.VERSION_NUMBER,referer:document.referrer||"",screen:""+(parseInt(screen.width)||0)+"*"+(parseInt(screen.height)||0),logintime:String(parseInt(E.loginTime/1e3)),onlinetime:String(t),crtime:f.get(e)||"",domain:document.domain}},reportOnline:function(e,t,n){var r,a,i;return i={data:{online:{}}},i.data.events=e||[],i.data.errors=t||[],n&&(i.data.reg=n),a=d.getEvents(),r=d.getErrors(),(a.length||r.length)&&(d.clear(),i.data.events=i.data.events.concat(a),i.data.errors=i.data.errors.concat(r),i.data.fail=function(){return d.updateErrors(r),d.updateEvents(a)}),I(i)},injectErrorEvent:function(e){return function(){return e.addEventListener("error",function(e){var t,n,r,a,i;try{if(l.isReportAllowed(e.filename))return l.count+=1,r={},n=["colno","filename","lineno","message"],n.forEach(function(t){return r[t]=e[t]||"0"}),r.stack=(null!=(a=e.error)?a.stack:void 0)||"",r.type=(null!=(i=e.error)?i.name:void 0)||"Error",r.timestamp=parseInt(e.timeStamp/1e3),d.updateErrors(r)}catch(o){return t=o,console.log(t)}},!1)}}(this),appendUID:function(e){var t,n,r,a,i;return r=location.hash,t="!"+e,r?(i=/![0-9A-Z]{32,128}/gi,n=r.match(i),n?(a=n[0].slice(1),e===a||f.get(o)||(E.parentId=a,f.set(o,a)),location.href=location.href.replace(i,t)):location.href+=t):location.href+="#"+t},getServerUID:function(t){var n,r,a;return x.postMessage?(n=function(r){var a;return 0===E.PROXY.indexOf(r.origin)?(a=JSON.parse(r.data),f.set(e,a.crtime),t(a.id),window.removeEventListener("message",n,!1)):void 0},window.addEventListener("message",n,!1),r=document.createElement("iframe"),r.style.display="none",r.src=""+E.PROXY,r.onload=function(){return this.onload=null,this.parentNode.removeChild(this)},a=function(){return document.body.appendChild(r)},document.body?a():document.addEventListener("DOMContentLoaded",a,!1)):t(S())},sendPV:function(e,t){var n,r;return null==e&&(e=location.pathname+location.search),n={page:encodeURIComponent(e),optime:parseInt(E.initializedOn/1e3),ottime:parseInt(Date.now()/1e3),lttime:parseInt(E.loginTime/1e3)},r=[{eventid:"_DESelf_PV",labelmap:JSON.stringify(n),duration:"1"}],f.reportOnline(r,null,t)}},n={version:E.VERSION_NUMBER,init:function(e){var t,n,r,a;if(e.errorReport!==!1&&(e.excludes&&(l.excludes=l.excludes.concat(e.excludes)),f.injectErrorEvent()),E.initialized)throw new Error("InitError: initialized already");if(!e.appId)throw new Error("InitError: missing argument appId");return n=["appId","accountId","appVer"],n.forEach(function(t){return E[t]=e[t]||""}),t=f.get(E.CLIENT_KEY),a=function(t){var n,a;return f.set(E.CLIENT_KEY,t),E.deviceId=t,E.accountId||(E.accountId=t),E.debug=e.debug,n=u.getItem(c),n||(n=Date.now(),u.setItem(c,n)),E.loginTime=n,E.interval=parseFloat(e.interval||E.interval),E.timer=setInterval(f.reportOnline,1e3*Math.max(10,E.interval)),E.virus=e.virus===!1?0:1,E.virus&&f.appendUID(t),E.initializedOn=Date.now(),E.initialized=!0,r&&(a={isact:r,isreg:1},E.parentId&&(a.parentid=E.parentId),x.localStorage||(a.localstorage=1)),f.sendPV(null,a)},r=t?0:1,t?a(t):f.getServerUID(a)},onEvent:function(e,t,n){var r,a,i;if(null==t&&(t=0),!e)throw new Error("ArgumentError: missing eventId");if(m(n)){for(a in n)i=n[a],n[a]=encodeURIComponent(i);r=JSON.stringify(n)}else r="";return d.updateEvents({eventid:e,duration:String(t),labelmap:r})},onPageView:function(e){return f.sendPV(e)}},this.DCAgent=n}).call(this);