﻿
var defaultMode = "show";
var GUID = Math.round(Math.random() * 2147483647);
var pageOpen = new Date();
var uexp = pageOpen.getTime() + (1000 * 60 * 60 * 24 * 365);
var thisUrl = "";
var thisReffer = "";
var arrayCount = 0;                               //参数数目
var urp = new Array();                             //来源参数名称
var urpv = new Array();                             //来源参数值
thisReffer = document.referrer;
thisUrl = getHref();

var modebox = document.getElementsByName("wm_mode");
if(modebox.length>0){
    defaultMode = modebox[0].value;
}

var hostKey = new Array();
var searchKey = new Array();
hostKey[0] = "google"; searchKey[0] = "q";
hostKey[1] = "yahoo"; searchKey[1] = "p";
hostKey[2] = "msn"; searchKey[2] = "q";
hostKey[3] = "aol"; searchKey[3] = "query";
hostKey[4] = "aol"; searchKey[4] = "encquery";
hostKey[5] = "lycos"; searchKey[5] = "query";
hostKey[6] = "ask"; searchKey[6] = "q";
hostKey[7] = "altavista"; searchKey[7] = "q";
hostKey[8] = "netscape"; searchKey[8] = "query";
hostKey[9] = "cnn"; searchKey[9] = "query";
hostKey[10] = "looksmart"; searchKey[10] = "qt";
hostKey[11] = "about"; searchKey[11] = "terms";
hostKey[12] = "mamma"; searchKey[12] = "query";
hostKey[13] = "alltheweb"; searchKey[13] = "q";
hostKey[14] = "gigablast"; searchKey[14] = "q";
hostKey[15] = "voila"; searchKey[15] = "rdata";
hostKey[16] = "virgilio"; searchKey[16] = "qs";
hostKey[17] = "live"; searchKey[17] = "q";
hostKey[18] = "baidu"; searchKey[18] = "wd";
hostKey[19] = "alice"; searchKey[19] = "qs";
hostKey[20] = "yandex"; searchKey[20] = "text";
hostKey[21] = "najdi"; searchKey[21] = "q";
hostKey[22] = "aol"; searchKey[22] = "q";
hostKey[23] = "club-internet"; searchKey[23] = "query";
hostKey[24] = "mama"; searchKey[24] = "query";
hostKey[25] = "seznam"; searchKey[25] = "q";
hostKey[26] = "search"; searchKey[26] = "q";
hostKey[27] = "wp"; searchKey[27] = "szukaj";
hostKey[28] = "onet"; searchKey[28] = "qt";
hostKey[29] = "netsprint"; searchKey[29] = "q";
hostKey[30] = "google.interia"; searchKey[30] = "q";
hostKey[31] = "szukacz"; searchKey[31] = "q";
hostKey[32] = "yam"; searchKey[32] = "k";
hostKey[33] = "pchome"; searchKey[33] = "q";
hostKey[34] = "kvasir"; searchKey[34] = "searchExpr";
hostKey[35] = "sesam"; searchKey[35] = "q";
hostKey[36] = "ozu"; searchKey[36] = "q";
hostKey[37] = "terra"; searchKey[37] = "query";
hostKey[38] = "nostrum"; searchKey[38] = "query";
hostKey[39] = "mynet"; searchKey[39] = "q";
hostKey[40] = "ekolay"; searchKey[40] = "q";
hostKey[41] = "search.ilse"; searchKey[41] = "search_for";
hostKey[42] = "sogou"; searchKey[42] = "query";
hostKey[43] = "yodao"; searchKey[43] = "q";

//将URL转换为地址和页面参数和参数值 参数uri为页面地址
function gethn(uri) {
    if (!uri || uri == "") return "";
    thisUrl = uri;
    var sub;
    //带参数
    if (thisUrl.indexOf("?") != -1) {
        var url = thisUrl.substring(0, thisUrl.indexOf("?"));
        var para = thisUrl.substring(thisUrl.indexOf("?") + 1, thisUrl.length);
        if (para.indexOf("#") != -1) {
            para = para.substring(0, para.indexOf("#"));
        }
        while (para.length > 0) {
            if (para.indexOf("&") == -1) {
                urp[arrayCount] = para.substring(0, para.indexOf("=")) + "=" + para.substring(para.indexOf("=") + 1, para.length);
                urpv[arrayCount] = para.substring(para.indexOf("=") + 1, para.length);
                break;
            }
            sub = para.substring(0, para.indexOf("&"));
            urp[arrayCount] = sub.substring(0, sub.indexOf("=")) + "=" + sub.substring(sub.indexOf("=") + 1, sub.length);
            urpv[arrayCount] = sub.substring(sub.indexOf("=") + 1, sub.length);
            
            para = para.substring(para.indexOf("&") + 1, para.length);
            
            arrayCount++;
        }
        return url;
    }
    else
        return thisUrl;
}

function getSearchInfo() {
    if (thisReffer == "") return "";
    var i = 0, h, k;
    if ((i = thisReffer.indexOf("://")) < 0) return "";
    h = thisReffer.substring(i + 3, thisReffer.length);
    if (h.indexOf("/") > -1) {
        h = h.substring(0, h.indexOf("/"));
    }
    for (var ii = 0; ii < hostKey.length; ii++) {
        if (h.toLowerCase().indexOf(hostKey[ii].toLowerCase()) > -1) {
            if ((i = thisReffer.indexOf("?" + searchKey[ii] + "=")) > -1 || (i = thisReffer.indexOf("&" + searchKey[ii] + "=")) > -1) {
                k = thisReffer.substring(i + searchKey[ii].length + 2, thisReffer.length);
                if ((i = k.indexOf("&")) > -1) k = k.substring(0, i);
                return "engine=" + _uEC(hostKey[ii]) + "&" + "key=" + _uEC(k);
            }
        }
    }
    return "";
}
function _uEC(s) {
    var n = "";
    if (!s || s == "") return "";
    for (var i = 0; i < s.length; i++) { if (s.charAt(i) == " ") n += "+"; else n += s.charAt(i); }
    return n;
}
//获得域名
function getHostName(url) {
    url = url.substring(url.indexOf('://') + 3, url.length);
    url = url.substring(0, url.indexOf("/"));
    return url;
}
//--------------------------设置异步传输-----------------------------------
function createXMLHttpRequest() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHttp");
    }
}
//-----------------------获得当前地址-----------------------------
function getHref() {
    return document.location.href;
}
//删除Cookie
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function getCheckUrl() {
    var url_ret = gethn(location.href);
    if (urp.length > 0) {
        urp.sort();
        url_ret = url_ret + "?";
        for (var i = 0; i < urp.length; i++) {
            if (i == 0) {
                url_ret = url_ret + urp[i];
            }
            else {
                url_ret = url_ret + "&" + urp[i];
            }
        }
    }
    return url_ret;
}
//设定Cookie值
function setCookie(name, value)
{
    var expdate = new Date();
    var argv = setCookie.arguments;
    var argc = setCookie.arguments.length;
    var expires = 15768000;
    var path = (argc > 3) ? argv[3] : "/";
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;

    if (expires != null) {
        //设置过期时间
        expdate.setTime(uexp);
        document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expdate.toGMTString()))
          + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain))
          + ((secure == true) ? "; secure=" : "");
    }
}

//获得Cookie的值
function getCookie(fname) {
    var name, value;
    var cookies = new Object();
    var beginning, middle, end;

    beginning = 0;
    while (beginning < document.cookie.length) {
        middle = document.cookie.indexOf("=", beginning);
        end = document.cookie.indexOf(";", beginning);

        if (end == -1) {
            end = document.cookie.length;
        }
        if ((middle > end) || (middle == -1)) {
            name = document.cookie.substring(beginning, end);
            value = "";
        }
        else {
            name = document.cookie.substring(beginning, middle);
            value = document.cookie.substring(middle + 1, end);
        }
        if (name == fname) {
            return unescape(value);
        }
        beginning = end + 2;
    }
    return "";
}
function getCookiesStr() {
    var str = "guid=" + getCookie("guid") + "&s_guid=" + getCookie("s_guid") + "&last_visit=" + getCookie("last_visit");
    str += "&popup=" + getCookie("popup") + "&sendform=" + getCookie("sendform") + "&score=" + getCookie("score");
    str += "&lastscore=" + getCookie("lastscore");
    return str;
}
var getInfo_script = document.createElement("script");
var gourl = "http://smart2008.webmining.com.cn/Mining.aspx?";
gourl += "url=" + escape(getCheckUrl()) + "&ref=" + escape(thisReffer);
var visiturl = gourl + "&" + getCookiesStr();
var searchengine = getSearchInfo();
if (searchengine.length > 0) {
    visiturl += "&" + searchengine;
}
visiturl += "&time=" + Math.random() + "&type=visit&mode=" + defaultMode;
getInfo_script.language = "javascript";
getInfo_script.type = "text/javascript";
getInfo_script.id = "_onloadret";
getInfo_script.src = visiturl;
addHTML(getInfo_script);

setTimeout("callTimer()", 15000);
function addHTML(element) {
    document.body.appendChild(element);
}
function addHead(element) {
    document.getElementsByTagName('head')[0].appendChild(element);
}
function callServerScript(query) {
    query += "&rnd=" + Math.random();
    var img = new Image();
    img.style.display = "none";
    document.body.appendChild(img);
    img.src = query;
}

function callTimer() {
    var timer_script = document.createElement("script");
    var timerurl = gourl + "&" + getCookiesStr();
    var searchengine = getSearchInfo();
    if (searchengine.length > 0) {
        timerurl += "&" + searchengine;
    }
    timerurl += "&time=" + Math.random() + "&type=time";
    var _script = document.createElement("script");
    _script.language = "javascript";
    _script.type = "text/javascript";
    _script.id = "_onloadtimer";
    _script.src = timerurl;
    addHTML(_script);
}
function callformer() {
    var former_script = document.createElement("script");
    var formerurl = gourl + "&" + getCookiesStr();
    var searchengine = getSearchInfo();
    if (searchengine.length > 0) {
        formerurl += "&" + searchengine;
    }
    formerurl += "&time=" + Math.random() + "&type=submitform";
    former_script.language = "javascript";
    former_script.type = "text/javascript";
    former_script.id = "_onloadformer";
    former_script.src = formerurl;
    addHTML(former_script);
}
function callJumper(target) {
    callformer();
    pop.close();
    window.open(target);
}