﻿//创建XMLHttpRequest对象
var xmlHttp = null;
function createXMLHttpRequest(){
	if (window.ActiveXObject) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else {
		xmlHttp = new XMLHttpRequest;
	}
}
function sendRequest(url){
	var method = "POST";
    createXMLHttpRequest();
	//发送异步请求
	xmlHttp.onreadystatechange = function(){
	  if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				Cookie.setCookie("Counter","Counter");
			}
		}
	};
	xmlHttp.open(method, url, true);
	if (method == "POST") {
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	xmlHttp.send();
}

var Cookie={
  setCookie:function(name,value,option){
    var str=name+"="+escape(value);
    if(option){
      if(option.expireDays){
        var date=new Date();
        var ms=option.expireDays*24*3600*1000;
        date.setTime(date.getTime()+ms);
        str+=";expires="+date.toGMTString();
      }
      if(option.path)str+=";path="+path;
      if(option.domain)str+=";domain"+domain;
      if(option.secure)str+=";true";
    }
    document.cookie=str;
  },
  getCookie:function(name){
    var cookieArray=document.cookie.split("; ");
    var cookie=new Object();
    for(var i=0;i<cookieArray.length;i++){
      var arr=cookieArray[i].split("=");
      if(arr[0]==name)return unescape(arr[1]);
    }
    return "";
  },
  deleteCookie:function(name){
    this.setCookie(name,"",{expireDays:-1});
  }
}
document.getElementsByTagName("body").onload=sendRequest("Counter.ashx");

