/*
* Manro流量分析系统 *************
* ============================================================================
* 版权所有 2008-2010 上海迈若科技、OKYO Studio，并保留所有权利。
* 网站地址: http://www.manro.com.cn、 http://www.okyo.cn
* ============================================================================
* 该文件用于对外的调用，通过<script></script>方式引入到需要进行流量统计的页面
* 计数器调用JS，通过Ajax方式进行流量统计
*
* Version 1.1
* Author:Dicky Pan
* Release Date:2010-8-2
* 
*/
var request;
var sysPath = '/manro_counter/';
function createRequest() {
    try {
        request = new XMLHttpRequest();
    } catch (trymicrosoft) {
        try {
            request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (othermicrosoft) {
            try {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (failed) {
                request = false;
            }
        }
    }
    if (!request){
        alert("Error initializing XMLHttpRequest!");
    } 
}

function getCustomerInfo() {
    var referrerUrl = document.referrer;
    var selfUrl = self.location.href;
    var url = sysPath + "counter.php";
    createRequest();
    request.open("POST", url, true);
    request.onreadystatechange = updatePage;
    request.setRequestHeader("Content-Type" ,"application/x-www-form-urlencoded");
    request.send('selfurl='+encodeURIComponent(selfUrl)+'&referrer='+encodeURIComponent(referrerUrl));
}


//计数器执行结果处理函数
function updatePage() {
    if (request.readyState == 4){
        if (request.status == 200){
             //操作正常，responseText为conter.php的输出值，默认输出访问总数
			 //alert(request.responseText);
        }else if (request.status == 404){
			//操作错误，未找到counter.php文件
             //alert("Request URL does not exist");
        }else{
			//操作错误，输出错误
            //alert("Error: status code is " + request.status);
        }
    }    
}
getCustomerInfo();
