﻿

//获取时间
function getTime(ns) {

    var s = ns % 60;
    var m = (ns - s) / 60 % 60;
    var h = ((ns - s) / 60 - m) / 60;
    m = m > 0 ? m + ":" : "";
    h = h > 0 ? h + ":" : "0:";
    return (h + m + s);

}
//获取字符长度
function getLength(v) {

    var len = 0;
    for (i = 0; i < v.length; i++) {
        if (v.charCodeAt(i) > 256) {
            len += 2;
        }
        else {
            len++;
        }
    }
    return len;
}

function chkLength(obj, length)  //限制
{
    if (getLength(obj.value) > length * 2) { obj.value = obj.value.substring(0, length) }
}

// 获取URL 参数
function Request(pname) {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    var Request = new Object();
    Request = theRequest;
    return Request[pname];
}

function GetqueryVal(url, key) {

    if (!CheckNull(url)) {
        return "";
    }

    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.split('?');
        if (str.length < 2) {

            return "";
        }
        strs = str[1].split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest[key];

}

function getCookie(objName) {//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName) return unescape(temp[1]);
    }
}
function addCookie(objName, objValue, objHours) {//添加cookie
    var str = objName + "=" + escape(objValue);

    if (objHours > 0) {//为0时不设定过期时间，浏览器关闭时cookie自动消失  return str1*60*60*1000; path=" + "/" + "; 
        var date = new Date();
        var ms = objHours * 3600 * 1000;
        date.setTime(date.getTime() + ms);
        str += ";expires=" + date.toGMTString();
    }
    var path = '\/';
    str += ";path=" + path; //指定可访问cookie的目录

    document.cookie = str;
    //alert("添加cookie成功");
}
function delCookie(name) {//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间
    var date = new Date();
    date.setTime(date.getTime() - 10000);
    document.cookie = name + "=a; expires=" + date.toGMTString();
}
function CheckNull(value) {
    if (value == null || typeof (value) == '' || typeof (value) == "undefined" || getLength(value) < 1) {
        return false;
    } else {
        return true;
    }

}
//记住第一次访问本站的来源源
var curlkey = 'dy_referrer';
var typeid = 0;
var curlvalue = getCookie(curlkey);
if(CheckNull(Request("from")))
{
    typeid =1;
}

if (!CheckNull(curlvalue)) {
    var referurl;
    if (document.referrer) {
        referurl = document.referrer;
        curlvalue = referurl;
        addCookie(curlkey, curlvalue, 10000); //
    }
    else {
        curlvalue = '直接访问';
        addCookie(curlkey, curlvalue, 10000); //
    }
}

//alert(GetqueryVal(location.href,'from')); //获取当前键接中的from值
var curlFromkey = 'dy_from';
var curfromvalue;
curfromvalue = GetqueryVal(location.href, 'from');
if (!CheckNull(curfromvalue)) {
    curfromvalue = getCookie(curlFromkey); //检查cookies中有没有值
    if (!CheckNull(curfromvalue)) {
        curfromvalue = GetqueryVal(curlvalue, 'from');
        if (CheckNull(curfromvalue)) {
            addCookie(curlFromkey, curfromvalue, 10000); //有值时，写cookies
        }
    }
}
else {
    addCookie(curlFromkey, curfromvalue, 10000); //有值时，写cookies

}

//这里统计每个页面的点击情况
document.write(unescape("%3Cscript src='/app/urlhit.ashx?from=" + escape(escape(curfromvalue)) + "&urlfrom=" + escape(escape(curlvalue)) + "&regfrom=" + escape(escape(location.href)) + "&typeid=" + typeid + "' type='text/javascript'%3E%3C/script%3E"));




function downloadGame(url) {
    //document.write(unescape("%3Cscript src='/app/urlhit.ashx?from=" + escape(escape(curfromvalue)) + "&urlfrom=" + escape(escape(curlvalue)) + "&regfrom=" + escape(escape(url)) + "' type='text/javascript'%3E%3C/script%3E"));
 //   document.write(unescape("%3Cscript src='/app/hitcount.ashx?urlfrom=" + escape("http://sq.dyjoy.com/app/dw.aspx") + "' type='text/javascript'%3E%3C/script%3E"));

    $.get('/app/hitcount.ashx', { "urlfrom": "http://sq.dyjoy.com/app/dw.aspx", random: Math.random() }, function(d) { } );
    window.open(url);
}



//alert(getCookie(curlFromkey));

//alert(location.search);
//alert(location.href);

