﻿/// <reference path="http://www.yoho.cn/js/jquery-1.4.min.js" />
jQuery(function() {
    var ua = navigator.userAgent;
    var ADViewCookie = getStatisticsCookie("AdvertiseHomeHotPicView");
    if (ADViewCookie == undefined) {
        var cookieVal = setStatisticsCookie("AdvertiseHomeHotPicView", 60*24);
        var ImgPath = "";
        var Link = ""
        var Title = "";
        var PageMainPos = "";
        var PageChildPos = "";
        var recordType = "UserView";
        jQuery(".y_hotpic").find("a").each(function(i) {
            
            if (i == 0) {
                ImgPath = encodeURIComponent(jQuery(this).find("img").attr("src"));
                Link = encodeURIComponent(jQuery(this).attr("href"));
            }
            else {
                ImgPath = ImgPath + "," + encodeURIComponent(jQuery(this).find("img").attr("src"));
                Link = Link + "," + encodeURIComponent(jQuery(this).attr("href"));
            }
            Title = "";
            PageMainPos = encodeURIComponent("首页");
            PageChildPos = encodeURIComponent("滚动广告");
        });
        jQuery.ajax({
            url: "index/ajax/YohoAdvertisementTraceManage.ashx",
            type: "post",
            data: { "action": "HomeUserView", "PageMainPos": PageMainPos, "PageChildPos": PageChildPos, "UserAgent": ua, "Link": Link, "ImgPath": ImgPath, "Title": Title, "Cookie": cookieVal, "recordType": recordType },
            success: function(data) {

            }
        });
    }
//    else {
//        var recordType = "PersonView";
//        var ImgPath = "";
//        var Link = ""
//        var Title = "";
//        var PageMainPos ="";
//        var PageChildPos = "";
//        jQuery(".y_hotpic").find("a").each(function(i) {
//            
//            if (i == 0) {
//                ImgPath = encodeURIComponent(jQuery(this).find("img").attr("src"));
//                Link = encodeURIComponent(jQuery(this).attr("href"));
//            }
//            else {
//                ImgPath = ImgPath + "," + encodeURIComponent(jQuery(this).find("img").attr("src"));
//                Link=Link + "," + encodeURIComponent(jQuery(this).attr("href"));
//            }
//            Title = "";
//            PageMainPos = encodeURIComponent("首页");
//            PageChildPos = encodeURIComponent("滚动广告");
//        });
//        jQuery.ajax({
//            url: "index/ajax/YohoAdvertisementTraceManage.ashx",
//            type: "post",
//            data: { "action": "HomeUserView", "PageMainPos": PageMainPos, "PageChildPos": PageChildPos, "UserAgent": ua, "Link": Link, "ImgPath": ImgPath, "Title": Title, "Cookie": "No", "recordType": recordType },
//            success: function(data) {

//            }
//        });
//    }
});
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);
        date.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
        date.setHours(23, 59, 59);
        document.cookie = cookieName + '=' + escape(cookieName) + ';expires=' + date.toGMTString() + ';path=/' + ';domaim=yoho.cn' + ':secure';

    }
    return name;
} 
