(function(){window.uTouch=uTouch={_startTime:new Date().getTime(),_pageID:-1,_sessionID:-1,_logData:new String(""),_alignment:"middle",_oldEvent:{type:""},_events:[],_logUrl:new String("http://www.toract.com/log/log.gif"),_confUrl:new String("http://www.toract.com/config/?callback=abc"),_clientUrl:"http://www.toract.com/client/start_client.js",_timer:null,_interval:4000,_frequency:0.25,_useClick:false,_useStop:false,_useKey:false,_useScroll:false,_useMove:false,_processor:function(a,b){return b},setProcessor:function(a){this._processor=a||this._processor},_getTimeStamp:function(){return new Date().getTime()-this._startTime},init:function(){var b=this;if(b._isRunning){return}else{b._isRunning=true}if(b.getUrlParam(location.href,"_r_ubw_client")){b.stop();b.startClient();return}var a="";if(window._utouch_id){a="&mid="+_utouch_id}if(!url){var url=(window.encodeURIComponent(location.href));}this.callback(this._confUrl+a+"&url="+url,"abc",function(d){if(d.data&&d.data.isLog){b._pageID=d.data.mid;b._sessionID=d.data.ssid;b.inspect();b.persist();b.log("&cmd=open"+b._getPageInfo());var c=d.data.fns;b._useClick=c.heat;b._useKey=c.key;b._useStop=c.hover;b._useMove=c.select}})},getUrlParam:function(f,e){var c={};if(f.indexOf("?")!=-1){f=f.substring(1).split("?")[1];f=f.split("&");for(var d=0;d<f.length;d++){var b=f[d].split("=");c[b[0]]=b[1]}}return c[e]},_getPageInfo:function(){return new String("&ref=")+encodeURIComponent(document.referrer)+"&px="+window.screen.width+"*"+window.screen.height},callback:function(c,b,h){var g="utf-8";if(/MSIE/.test(window.navigator.userAgent)){var f=document.createDocumentFragment(),a=f.createElement("script");a.charset=g;f[b]=function(){h&&h.apply(null,arguments);f=a=a.onreadystatechange=f[b]=null};a.onreadystatechange=function(){if(a.readyState=="loaded"){f=a=a.onreadystatechange=f[b]=null}};a.src=c;f.appendChild(a)}else{var d=document.createElement("iframe");d.style.display="none";d.callback=function(){h&&h.apply(null,arguments);d.callback=d.errorcallback=null;d.src="about:blank",d.parentNode.removeChild(d),d=null};d.errorcallback=function(){d.callback=d.errorcallback=null;d.src="about:blank",d.parentNode.removeChild(d),d=null};try{document.body.appendChild(d);d.contentWindow.document.write('<script type="text/javascript">function '+b+'() { window.frameElement.callback.apply(null, arguments); }<\/script><script type="text/javascript" src="'+c+'" charset="'+g+'"><\/script><script type="text/javascript">window.setTimeout("try { window.frameElement.errorcallback(); } catch (exp) {}", 1)<\/script>');d.contentWindow.document.close()}catch(e){}}},stop:function(){this.log=function(){}},startClient:function(){var a=document.createElement("script");a.src=this._clientUrl;document.body.appendChild(a)},_logi:0,log:function(d,c){var b=document.createElement("img");b.src=this._logUrl+"?seq="+(this._logi++)+"&mid="+this._pageID+"&sid="+this._sessionID+d;var a=false;b.onerror=b.onload=b.onreadystatechange=function(){if(!a&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){a=true;document.body.removeChild(b)}};document.body.appendChild(b);if(c){var e=new Date();while(new Date()-e<100){}}},_pushLogData:function(a){var b=a.type+"*"+a.path.join("")+"*"+(a.x||"").toString()+"*"+(a.y||"").toString()+"*"+a.timestamp.toString()+"*"+(a.custom||"").toString()+"!";if((this._logData+b).length>1900){return false}else{this._logData+=b;return true}},persist:function(){var a=this;this._timer=window.setInterval(function(){var e=a._events;a._events=[];var d=0;var h=parseInt(1000/a._frequency);var g=[];while(d<e.length){g.push(e[d]);if(e[d].type=="k"){var b=e[d];while(d+1<e.length&&e[d+1].type=="k"){if(e[d+1].timestamp-b.timestamp<h){}else{g.push(e[d+1]);b=e[d+1]}d++}}else{if(e[d].type=="s"){var c=e[d];while(d+1<e.length&&e[d+1].type=="s"){if(e[d+1].timestamp-c.timestamp<h*2){}else{g.push(e[d+1]);c=e[d+1]}d++}}else{if(e[d].type=="m"){var c=e[d];while(d+1<e.length&&e[d+1].type=="m"){if(e[d+1].timestamp-c.timestamp<h*2){}else{g.push(e[d+1]);c=e[d+1]}d++}}else{if(d>1&&e[d-1].type=="k"){var j=g[g.length-1];if(j.type=="k"&&(j.x!=e[d-1].x||j.y!=e[d-1].y)){var i=g.pop();g.push(e[d-1]);g.push(i)}}if(d>1&&e[d-1].type=="s"){var j=g[g.length-1];if(j.type=="s"&&(j.x!=e[d-1].x||j.y!=e[d-1].y)){var i=g.pop();g.push(e[d-1]);g.push(i)}}if(d>1&&e[d-1].type=="m"){var j=g[g.length-1];if(j.type=="m"&&(j.x!=e[d-1].x||j.y!=e[d-1].y)){var i=g.pop();g.push(e[d-1]);g.push(i)}}}}}d++}d=0;while(d<g.length){if(a._pushLogData(g[d])){d++}else{a.log("&data="+a._logData);a._logData=""}}},this._interval)},record:function(c,d){var a=this.getEvent(d,this);var h=this.getEventXY(a);var f=this.getEventTarget(a);var e={x:h.x,y:h.y,type:c,path:this.getElementPath(f),timestamp:this._getTimeStamp()};if(!this.isValidEvent(e)){return}e=this._processor(a,e);this._events.push(e);var g=this._oldEvent.timestamp||0;var b=e.timestamp-g;if(b>=3000&&b<=30000&&this._useStop){this._events.push({x:e.x,y:e.y,type:"h",path:e.path,timestamp:b})}this._oldEvent=e},getEventTarget:function(a){return a.target||a.srcElement},getEvent:function(b,a){if(b){return b}else{if(a){if(a.document){return a.document.parentWindow.event}if(a.parentWindow){return a.parentWindow.event}}}return window.event||null},listen:(function(){if(document.addEventListener){return function(b,a,c){b.addEventListener(a,c,true)}}else{if(document.attachEvent){return function(b,a,c){b.attachEvent("on"+a,c)}}}})(),getEventXY:function(g){var f=this.getEventTarget(g);function d(j){var e=document;if(j){e=j.document||j.ownerDocument||(j.window||j.defaultView)&&j||document}return e}function c(k,n){var m=k,l=d(n);var j=("pageX" in m)?m.pageX:(m.clientX+(l.documentElement.scrollLeft||l.body.scrollLeft)-2);var o=("pageY" in m)?m.pageY:(m.clientY+(l.documentElement.scrollTop||l.body.scrollTop)-2);return{x:j,y:o}}function i(j){var k=j.offsetTop;var e=j.offsetLeft;while(j=j.offsetParent){k+=j.offsetTop;e+=j.offsetLeft}return{x:e,y:k}}var h=c(g,f);var a=i(f);var b={x:h.x-a.x,y:h.y-a.y};return b},isValidEvent:function(a){if(this._oldEvent.timeStamp){if(a.timeStamp-(this._oldEvent.timeStamp||-1)<50){return false}if(a.path==this._oldEvent.path&&(Math.pow(a.x-this._oldEvent.x,2)+Math.pow(a.y-this._oldEvent.y,2))<100){return false}return true}else{return true}},getCustom:function(a){if(a&&a.getAttribute){return a.getAttribute("data-utouch")}else{return""}},inspect:function(){try{var b=this;var c=false;b.listen(document,"click",function(d){if(!b._useClick){return}b.record("c",d)});b.listen(document,"dblclick",function(d){if(!b._useClick){return}b.record("l",d)});b.listen(document,"focus",function(d){if(b.getEventTarget(b.getEvent)==document.body){b.record("f",d)}});b.listen(document,"mousemove",function(d){if(!c||!b._useMove){return}b.record("m",d)});b.listen(document,"mousedown",function(d){if(!b._useClick){return}b.record("d",d);c=true});b.listen(document,"mouseup",function(d){if(!b._useClick){return}b.record("u",d);c=false});b.listen(window,"beforeunload",function(d){window.clearInterval(b._timer);b.persist();if(b._logData.length&&b._logData.length>0){b.log("&cmd=end&data="+b._logData,true)}});b.listen(document,"keydown",function(d){if(!b._useKey){return}b.record("k",d)});b.listen(document,"scroll",function(d){if(!b._useScroll){return}b.record("s",d)})}catch(a){}},getElementPath:function(c,d){d=d||[];if(c==document||c==document.body||(c.tagName&&c.tagName.toUpperCase()=="HTML")){return d}if(c.getAttribute&&c.getAttribute("id")!=""&&c.getAttribute("id")!=null){d.push(c.nodeName.toLowerCase()+"."+c.getAttribute("id"));return d}if(c.parentNode&&c.parentNode.tagName.toUpperCase()!="BODY"){d=uTouch.getElementPath(c.parentNode,d)}if(c.previousSibling){var b=1;var a=c.previousSibling;do{if(a.nodeType==1&&a.nodeName==c.nodeName){b++}a=a.previousSibling}while(a)}if(c.nodeType==1){d.push("~"+(b>1?b:1)+c.nodeName.toLowerCase())}return d}};uTouch.init()})();

