﻿//-SendNPDate.js
//是否计算访问量的网络环境标志，1：计算；0：不计算
var GetInfoSwitch = 1;

var GetNewsPaperType ="";
var getjstimeid = null;
var getjstime = 100;
//var getjssendurl = "61.175.199.60:3949";
var getjssendurl = "sjjs.51028.com.cn:3949";

///=========================
///功能性函数
///=========================
function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie(name, value,expiresTime )
//设定Cookie值
{
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;

//设置过期时间(按天计算)
expdate.setTime(expdate.getTime() + ( 1000*24*60*60*expiresTime ));

document.cookie = name + "=" + escape (value) +("; expires="+ expdate.toGMTString())
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}

function DelCookie(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}


function GetCookie(name)
//获得Cookie的原始值
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

function GetGuid()
//生成Guid
{
var guid = "{";
for (var i = 1; i <= 32; i++)
  {
  var n = Math.floor(Math.random() * 16.0).toString(16);
  guid += n;
  if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
  guid += "-";
  }
guid += "}";
return guid;
}

///=========================
///End
///=========================


function SendNP_init()
{
	var SendNP_aaa = document.createElement("<IFRAME name='iframe_senddate'></IFRAME>");
	document.getElementsByTagName("body")[0].appendChild(SendNP_aaa);
	SendNP_aaa.style.display = "none";

	//var SendNP_google = document.createElement("script");
	//document.getElementsByTagName("body")[0].appendChild(SendNP_google);
	//SendNP_google.id = "SendNP_google";
	//SendNP_google.src = "http://www.google-analytics.com/urchin.js";
	//SendNP_google.type = "text/javascript";
}

function SendNPDate_2()
{
	//alert(document.readyState);
	function replaceSubstring(inputString, fromString, toString) {
	var tttemp = inputString;
	if (fromString == "") {
	return inputString;
	}
	if (toString.indexOf(fromString) == -1) { 
	while (tttemp.indexOf(fromString) != -1) {
	var toTheLeft = tttemp.substring(0, tttemp.indexOf(fromString));
	var toTheRight = tttemp.substring(tttemp.indexOf(fromString)+fromString.length, tttemp.length);
	tttemp = toTheLeft + toString + toTheRight;
	}
	} else { 
	var midStrings = new Array("~", "`", "_", "^", "#");
	var midStringLen = 1;
	var midString = "";
	while (midString == "") {
	for (var i=0; i < midStrings.length; i++) {
	var tempMidString = "";
	for (var j=0; j < midStringLen; j++) { tempMidString += midStrings; }
	if (fromString.indexOf(tempMidString) == -1) {
	midString = tempMidString;
	i = midStrings.length + 1;
	}
	}
	} 
	while (tttemp.indexOf(fromString) != -1) {
	var toTheLeft = tttemp.substring(0, tttemp.indexOf(fromString));
	var toTheRight = tttemp.substring(tttemp.indexOf(fromString)+fromString.length, tttemp.length);
	tttemp = toTheLeft + midString + toTheRight;
	}
	while (tttemp.indexOf(midString) != -1) {
	var toTheLeft = tttemp.substring(0, tttemp.indexOf(midString));
	var toTheRight = tttemp.substring(tttemp.indexOf(midString)+midString.length, tttemp.length);
	tttemp = toTheLeft + toString + toTheRight;
	}
	} 
	return tttemp; 
	} 


	var getjs_ip,getjs_os,getjs_browser,getjs_location,getjs_referrer,getjs_guid;//定义变量

	//getjs_ip = escape("<%=ip%>");//获取IP

	//getjs_guid = "<%=guid%>";//获取Guid

	//alert(getjs_guid);

	getjs_os = window.navigator.userAgent;

	if(getjs_os.indexOf("Win")!=-1)
	{
		getjs_os = "Windows";
	}else
	{
		getjs_os = "No Windows";
	}

	getjs_os =  escape(getjs_os);//获取是何操作系统

	getjs_browser = escape(navigator.appName);//获取是何浏览器

	getjs_location = escape(window.location);//获取被访问页面地址

	var getjs_f = "";//来源页面

	// if pp_frames is true then try getting the framed referral (without error checking)
	if (typeof(pp_frames) != "undefined")
	if (pp_frames)
	  getjs_f = top.document.referrer;

	// get the referral for non-multi-domained-framed sites using a Netscape browser
	if ((getjs_f == "") || (getjs_f == "[unknown origin]") || (getjs_f == "unknown") || (getjs_f == "undefined"))
	if (document["parent"] != null) 
	  if (parent["document"] != null) // ACCESS ERROR HERE!
	  if (parent.document["referrer"] != null) 
		if (typeof(parent.document) == "object")
		  getjs_f = parent.document.referrer; 

	// get the referral for the current document if a framed referral wasn't found
	if ((getjs_f == "") || (getjs_f == "[unknown origin]") || (getjs_f == "unknown") || (getjs_f == "undefined"))
	if (document["referrer"] != null) 
	  getjs_f = document.referrer;

	// convert all the unknown's into blank
	if ((getjs_f == "") || (getjs_f == "[unknown origin]") || (getjs_f == "unknown") || (getjs_f == "undefined"))
	  getjs_f = "";

	getjs_referrer = escape(getjs_f);//获取来源页面地址

	//Send Info 
	var NewsPaperName,NewsEditionName,NewsEditionNumber,NewsArticleTitle,NewsArticleAuthor,NewsArticleTime,NewsPaperClass,Guid;

	//获取报纸相关信息
	NewsPaperName = escape(document.getElementById("NewsPaperName").innerHTML);//报纸名称
	NewsEditionName = escape(document.getElementById("NewsEditionName").innerHTML);//报纸版面
	NewsEditionNumber = escape(document.getElementById("NewsEditionNumber").innerHTML);//报纸版次

	NewsArticleTitle = document.getElementById("NewsArticleTitle").innerHTML;
	NewsArticleTitle = replaceSubstring(NewsArticleTitle, "<", "[");
	NewsArticleTitle = replaceSubstring(NewsArticleTitle, ">", "]");
	NewsArticleTitle = escape(NewsArticleTitle);//报纸文章

	NewsArticleAuthor = escape(document.getElementById("NewsArticleAuthor").innerHTML);//报纸作者
	NewsArticleTime = escape(document.getElementById("NewsArticleTime").innerHTML);//报纸发表时间
	NewsPaperClass = escape(document.getElementById("Class").innerHTML);//报纸的页面类型 1=版面导航页面 2=内容页面
	
	if(GetCookie("Guid") == null || GetCookie("Guid") == "")
	{
		SetCookie("Guid",GetGuid(),30);
	}
	Guid = GetCookie("Guid");

	var NewsArticleID;
	NewsArticleID = "";
	if (document.getElementById("Class").innerHTML == "2")
	{
		NewsArticleID = escape(document.getElementById("NewsArticleID").innerHTML);
	}
	
	var getjs_strA;

	getjs_strA = "NewsPaperName="+NewsPaperName+"&NewsEditionName="+NewsEditionName+"&NewsEditionNumber="+NewsEditionNumber+"&NewsArticleTitle="+NewsArticleTitle+"&NewsArticleAuthor="+NewsArticleAuthor+"&NewsArticleTime="+NewsArticleTime+"&os="+getjs_os+"&browser="+getjs_browser+"&location="+getjs_location+"&referrer="+getjs_referrer+"&Class="+NewsPaperClass+"&NewsArticleID="+NewsArticleID+"&Guid="+Guid+"";

	getjs_strA = replaceSubstring(getjs_strA, "%2520", "%20");
	getjs_strA = replaceSubstring(getjs_strA, "%B7", "%C2%B7");

	//document.write("<img style='display:none;' src='http://www.123.com/getinfo/sendinfo_plus.aspx?"+getjs_strA+"'></img>");
	//window.open("'http://192.168.0.81:88/GetInfo/sendinfo_plus.aspx?"+getjs_strA+"'",'iframe_senddate','');

	var strEval = "";
	strEval = "window.open('http://"+getjssendurl+"/GetInfo/sendinfo_plus.aspx?"+getjs_strA+"','iframe_senddate','');"
	eval(strEval);

	//_uacct = "UA-1637917-1";
	//urchinTracker();
	//alert(document.readyState);
}

function SendNPDate_1()
{
	clearTimeout(getjstimeid);
	if (document.readyState != "complete")
	{
		getjstimeid = setTimeout("SendNPDate_1();",getjstime);
	}else
	{
		getjstimeid = setTimeout("SendNPDate_2();",getjstime);
	}
}

if (GetInfoSwitch == 1)
{
SendNP_init();
getjstimeid = setTimeout("SendNPDate_1();",getjstime);
}
