/* 
 * Copyright Alpha
 * 2007-8-10
 */

/**
 * 页面使用Ajax提交时的统计调用
 * Ajax提交不刷新页面，一般在提交成功之后在 callback 方法里调用
 * modID:(功能,区域) 如：countZTPageViewByAjax('318,362');
 */
function countZTPageViewByAjax(modID){
	var mURL = escape(document.location.href);
	mURL = escape(mURL);
	countZTPageView(modID,mURL);
	//alert("Ajax");
}

/*
 * 页面刷新时的统计调用
 * 页面加载时自动调用
 */
function countZTPageView(ModID,ModURL){
	try{
		var par="";
		par+="&ModID="+ModID
			+"&ModUrl="+ModURL;
		var url="/Common.shtml?url=CountController"+par+"&math="+Math.random();
		if(window.XMLHttpRequest){
		   reqZTPageView = new XMLHttpRequest();
		   reqZTPageView.open("GET", url, true);
		   reqZTPageView.onreadystatechange = ztPageViewCallback;
		   reqZTPageView.send(null);
		}else if(window.ActiveXObject){
		   reqZTPageView = new ActiveXObject("Microsoft.XMLHTTP");
		   reqZTPageView.open("GET", url, true);
		   reqZTPageView.onreadystatechange = ztPageViewCallback;
		   reqZTPageView.send();
		}
	}catch(e){
		document.write('<iframe frameborder="0" name="ztPGVCount" height="0" id="ztPGVCount" scrolling="no" src="/Common.shtml?url=CountController&ModID='+mID+'&ModUrl='+mURL+'" width="0"></iframe>');
	}
}
function ztPageViewCallback(){
    if (reqZTPageView.readyState == 4) {
	}
}

var mURL = escape(document.location.href);
mURL = escape(mURL);
var mID = "1,0";
var ModIDStr = document.location.href.indexOf("ModID=(");
var beg = document.location.href.indexOf("(");
var end = document.location.href.indexOf(")");

if(ModIDStr>-1 & beg>-1 && end>-1 && end>beg){
	mID = (document.location.href.substring(beg+1,end));
}else{
	mID = document.getElementById("ctPageViewCount").title;
}
//alert(mID);
try{
	countZTPageView(mID,mURL);
	//alert("page");
}catch(e){
	document.write('<iframe frameborder="0" name="ztPGVCount" height="0" id="ztPGVCount" scrolling="no" src="/Common.shtml?url=CountController&ModID='+mID+'&ModUrl='+mURL+'" width="0"></iframe>');
}