﻿/// <reference path="http://www.yoho.cn/js/jquery-1.4.min.js" />
function InsertAchievementTrace(webAddress) {
    var sCookie = getStatisticsCookie("YohoAchieveTrace");
    if (sCookie == undefined) {
        jQuery.ajax({
            url: "http://www.yoho.cn/ManageAchievementTrace.ashx",
            type: "post",
            data: { "action": "AchievementTraceInsert", "webAddress": webAddress },
            success: function(data) {
                if (data == 1 || data == "1") {
                    //setStatisticsCookie("YohoAchieveTrace", 1);
                }
            }
        });
    }
}

function InsertAchievementTraceNormal(webAddress) {
    var sCookie = getStatisticsCookie("YohoAchieveTrace");
    if (sCookie == undefined) {
        var xhr = new AjaxXmlHttpRequest();
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    var res = xhr.responseText;
                } else {
                }
            }
        }
        xhr.open("GET", "http://www.yoho.cn/ManageAchievementTrace.ashx?action=AchievementTraceInsert&webAddress=" + webAddress, true);
        xhr.send(null);
    }
}

//跨浏览器获取XmlHttpRequest对象
function AjaxXmlHttpRequest() {
    var xmlHttp;
    try {
        //　 Firefox,　Opera　8.0+,　Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        //　Internet　Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("您的浏览器不支持AJAX！");
                return false;
            }
        }
    }
    return xmlHttp;
}


function getStatisticsCookie(cookie_name) {
    var allcookies = document.cookie;
    var cookie_pos = allcookies.indexOf(cookie_name);
    // 如果找到了索引，就代表cookie存在，   
    // 反之，就说明不存在。   
    if (cookie_pos != -1) {
        // 把cookie_pos放在值的开始，只要给值加1即可。   
        cookie_pos += cookie_name.length + 1;
        var cookie_end = allcookies.indexOf(";", cookie_pos);
        if (cookie_end == -1) {
            cookie_end = allcookies.length;
        }
        var value = unescape(allcookies.substring(cookie_pos, cookie_end));
    }
    return value;
}

function setStatisticsCookie(cookieName, time) {
    var date = new Date();
    var name = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ":" + date.getSeconds();
    if (!navigator.cookieEnabled) {
        name = "";
    } else {

        date.setTime(date.getTime() + 60000 * time);
        document.cookie = cookieName + '=' + escape(cookieName) + ';expires=' + date.toGMTString() + ';path=/' + ';domaim=yoho.cn' + ':secure';

    }
    return name;
} 
