﻿/* author:Chaoyang
 * date:2009-10-13*/
var AjaxFlux = function AjaxFlux(url)
{
	var m_xmlReq=null;
	if(window.ActiveXObject)
	{
	    try 
	    {
	        m_xmlReq = new ActiveXObject('Msxml2.XMLHTTP'); 
	    }
	    catch(e)
	    {
	        try{m_xmlReq = new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
	    }
	}
	else if(window.XMLHttpRequest)
	{
	    m_xmlReq = new XMLHttpRequest();
	}
	
	this.postResult=function(d)
	{
	    if(!m_xmlReq)  return;
	    m_xmlReq.open('POST',url,false);
	    m_xmlReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
	    m_xmlReq.send(d);	
	    var requesttxt=m_xmlReq.responseText;	    
	    return requesttxt;
	}
}

//设置Cookie  
function setCookie(name,value)
{
    var exp = new Date(); 
    exp.setTime(exp.getTime()+24*60*60*1000);//cookie保存一天 每天有12个小时，一小时60分钟，每分钟有60秒，每秒1000毫秒 
    document.cookie = name + "=" + escape (value) + ";path=/;expires=" + exp.toGMTString()+";/";
}

//读取cookies的值
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg)) return unescape(arr[2]);
    else return null;
}

//删除cookies
function delCookie(name)
{
      var exp = new Date();
      exp.setTime(exp.getTime() - 1000);
      var cval=getCookie(name);
      if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

//获取参数
function myrequest(paras){
	var url=location.href;
	var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");     
	var paraObj = {}     
	for (i=0; j=paraString[i]; i++){     
		paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);     
	}     
	var returnValue = paraObj[paras.toLowerCase()];     
	if(typeof(returnValue)=="undefined"){
		return "";     
	}else{
		return returnValue;     
	}
}

var sourceID=myrequest("sourceID");
if (sourceID !=null && sourceID.length > 0) {
    setCookie('sid',sourceID);
    new AjaxFlux("/Ashx/Flux/SendData.ashx").postResult("Time="+new Date()+"&articleID="+sourceID);
}
else if (getCookie('sid')!=null)//无参，但有cookie
{
    sourceID=getCookie('sid');
    new AjaxFlux("/Ashx/Flux/SendData.ashx").postResult("Time="+new Date()+"&articleID="+sourceID);
}

//51反利要求
var uid=myrequest("uid");
if (uid !=null && uid.length > 0) {setCookie('uid',uid);}
//极限
var ids=myrequest("ids");
if (ids !=null && ids.length > 0) {setCookie('ids',ids);}

//网站联盟
var unioninfo=myrequest("union");
if(unioninfo!=null && unioninfo.length>0){
    setCookie('k6.union',unioninfo);
    new AjaxFlux("/Ashx/Flux/SendData.ashx").postResult("Time="+new Date()+"&unioninfo="+unioninfo);
}
else if (getCookie('union')!=null)//无参，但有cookie
{
    sourceID=getCookie('k6.union');
    alert(sourceID);
    new AjaxFlux("/Ashx/Flux/SendData.ashx").postResult("Time="+new Date()+"&unioninfo="+unioninfo);
}