﻿// JScript 文件
// 仿照 woopra， 利用现有 CustomWebForm 项目，实现网页留存时间记录，网页访问客户端信息记录
function CustomWebFormTracker(AccessID){

        var pntr=false;
        var chat=false;

        var idle=false;
        var idle_timeout=20*1000;
        var last_action= new Date();
        var timeout=timeout=30*60*1000;

        var wx_static='http://www.slingit.com.cn/ReturnAccessInfoHandler.ashx?' + 'AccessID=' + AccessID;
        var wx_engine=false;

        var visitor_data=false;
        var event_data=false;

        //-----------------------------------------------------------------------------------------------------------------------
        //初始化类
        this.initialize=function(){

//            pntr=this;
//            last_action=new Date()

//            visitor_data=new Array();
//            event_data=new Array();

//            //读取 cookie,如果原先无 则创建新 cookie
//	        if(!this.readcookie('wooTracker')){
//                    this.createcookie('wooTracker', this.randomstring(), 10*1000);
//            }

//            //读取 cookie,如果原先无 则创建新 cookie    
//            if(!this.readcookie('sessionCookie')){
//                this.createcookie('sessionCookie', this.randomstring(), -1);
//            }

            //设置网址变量参数
//            if(document.location.protocol=="https:"){
//                wx_static="https://sec1.woopra.com";
//                wx_engine="https://sec1.woopra.com";
//            }else{
//                wx_static="http://static.woopra.com";
//                wx_engine='http://'+((location.hostname.indexOf('www.')<0)?location.hostname:location.hostname.substring(4))+'.woopra-ns.com';
//            }
//            wx_static='http://localhost:2735/TestWebForm/ReturnAccessInfoHandler.ashx?';
//            wx_engine='http://';


            
            //添加 鼠标动作 监视器
//            if(document.addEventListener){
//                document.addEventListener("mousedown",this.clicked,false);
//                document.addEventListener("mousemove",this.moved,false);
//            }
//            else{
//                document.attachEvent("onmousedown",this.clicked);
//                document.attachEvent("onmousemove",this.moved);
//            }

//            this.request(wx_static + '&Screen=' +screen.width + 'x' + screen.height);
              this.track();
        }
        //==============================================================================================================


       
   //判定不同浏览器类型
   this.getnavigatortoken=function(){
        if(window.opera || window.Opera){
            return 'O';
        }
        if(navigator.userAgent){
            return 'U';
        }
        return "X";
    }

    //返回浏览器语言
    this.getlantoken=function(){
        return (navigator.browserLanguage || navigator.language || "");
    }
   

    //向指定网站发送请求
    this.request=function(url){
        var script=document.createElement('script');
        script.type="text/javascript";
        script.src = url;
        document.getElementsByTagName('head')[0].appendChild(script);
    }


    //跟踪网页
this.track=function(){

        var date=new Date();

        var request=new Array();

//        request['sessioncookie']=this.readcookie('sessionCookie');
//        request['cookie']=this.readcookie('wooTracker');
//        request['browsertoken']=this.getnavigatortoken();
//        request['platformtoken']=navigator.platform;
//        request['language']=this.getlantoken();
        request['pagetitle']=document.title;
        request['referer']=document.referrer;
        request['screen']=screen.width + 'x' + screen.height;
        request['localtime']=date.getHours()+':'+date.getMinutes();


        var _k=false;

//        for (_k in visitor_data){
//            if(typeof visitor_data[_k]!='function'){
//                request['cv_'+_k]=visitor_data[_k];
//            }
//        }

//        for (_k in event_data){
//            if(typeof event_data[_k]!='function'){
//                request['ev_'+_k]=event_data[_k];
//            }
//        }

        //将 request 数组内容，转换成 URL 参数字符串形式
        var req_url="";
        for (_k in request){
            if(typeof request[_k]!='function'){
                req_url+="&"+_k+"="+encodeURIComponent(request[_k]);
            }
        }

        this.request(wx_static + '&Type=Initial' + req_url);
    }

    //Ping 网站地址
    this.ping=function(){
//        if(new Date()-last_action> timeout){
//            return;
//        }
//        var _mod = ((document.location.protocol=="https:")?'/woopras/ping.jsp?':'/ping/');
        
        //距离打开网页已过去多少秒时间
        var _second = Math.round((new Date()-last_action)/1000);
        var _url = wx_static + '&Type=Ping&Second=' + _second;
        this.request(_url);
    }

    this.clicked=function(e) {

        var cElem = (e.srcElement) ? e.srcElement : e.target;
        if(cElem.tagName == "A"){
            var link=cElem;
            var _download = link.pathname.match(/(?:doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)($|\&)/);
            if(_download){
                pntr.sendEvent("download",link.href);
                pntr.sleep(100);
            }
            if (!_download&&link.hostname != location.host && link.hostname.indexOf('javascript')==-1 && link.hostname!=''){
                pntr.sendEvent("exit",link.href);
                pntr.sleep(400);
            }
        }
    }

    this.moved=function(e) {
        last_action=new Date();
        if(idle==1){
            idle=0;
            this.woopra_event("status","0");
        }
    }

    this.checkidle=function(){
        if(idle==0 && (new Date()-last_action)> idle_timeout){
            idle=1;
            this.woopra_event("status","1");
        }
        setTimeout(function(){pntr.checkidle();},5 * 1000);
    }

}







