(function() {
	var Fx;
	if (!Fx) Fx = {};
	Fx.Stat = function() {
		var domain = 'http://';
		if (/^https/.test(document.location.href)) {
			domain = 'https://';
		}
		domain += "wa.fx-func.com/";
		var __wa_init_url = domain + 'pv.ashx?',
		__wa_travel_url = domain + 'reg.ashx?',
		__wa_clickcount_url = domain + "tpe.ashx?",
		__wa_out_url = domain + "ot.ashx?",
		__wa_visit_url = domain + "time.ashx?"
		//自定义的属性名和属性值
		__attr = 'regid',
        __loadEndDate = new Date().getTime();
		//__attrV='tuijianwei',
		var hasAttribute = function(ele, attribute) {
			return ele.getAttribute(attribute) != null;
		}

		function getElementsByAttr(attribute, attributeValue) {
			var ea = new Array();
			var ma = new Array();
			if (document.all) {
				ea = document.all;
			}
			else {
				ea = document.getElementsByTagName("*");
			}
			for (var i = 0, l = ea.length; i < l; i++) {
				if (hasAttribute(ea[i], attribute)) {
					ma.push(ea[i]);
				}
			}
			return ma;
		};
		//记录某一类型的链接点击
		function clickCount_type(sType) {
			try {
				if (sType.length > 0) {
					var img = new Image();
					img.src = __wa_clickcount_url + 'key=' + escape(sType) + '&linkindex=0&lastmode=' + Math.random(); ;
					img.onload = function() {
						img.onload = null;
						img.onerror = null;
					}
					img.onerror = function() {
						img.onload = null;
						img.onerror = null;
					}
				}
			} catch (e) { }
		};
		//记录某一指定regId的数据
		function clickCount_regId(regId) {
			try {
				if (typeof regId != 'undefined') {
					var img = new Image();
					img.src = __wa_travel_url + 'regid=' + regId + '&linkindex=0&lastmode=' + Math.random() + getWaidInfo();
					img.onload = function() {
						img.onload = null;
						img.onerror = null;
					}
					img.onerror = function() {
						img.onload = null;
						img.onerror = null;
					}
				}

			} catch (e) { }
		};
		// 清楚c参数
		function clearParam(url) {
			var rev = '';
			var reg = new RegExp("(\\&c=)([^&]*)", "gi");
			rev = url.replace(reg, '');

			if (url.indexOf('&') > 0) {
				reg = new RegExp("(\\?c=)([^&]*)(&)", "gi");
				rev = rev.replace(reg, '?');
			}
			else {
				reg = new RegExp("(\\?c=)([^&]*)", "gi");
				rev = rev.replace(reg, '');
			}
			return rev;
		}
		// 获取flash 版本
		function getFlashVersion() {
			p = navigator.plugins;
			if (p && p.length) {
				for (var i = 0; i < p.length; i++) {
					if (p[i].name.indexOf('Shockwave Flash') > -1) {
						return (p[i].description.split('Shockwave ')[1]);
						break;
					}
				}
			} else if (window.ActiveXObject) {
				var f = '';
				for (var j = 9; j >= 6; j--) {
					try {
						var fl = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash." + j + "');");
						if (fl) {
							f = j + '.0';
							break;
						}
					}
					catch (e) { }
				}

				return f;
			}

			return "未知";
		}

		//记录写在页面上的Id
		function getWaidInfo() {
			var strArr = [], _waiid = typeof fx_waiid != 'undefined' && fx_waiid || 0, _wasud = typeof fx_wasud != 'undefined' && fx_wasud || 0;
			var _isspace = (typeof fx_isspace != 'undefined' && fx_isspace == false ? 0 : 1);
			var _objectmark = typeof fx_objectmark != 'undefined' && fx_objectmark || '';
			var _category = typeof fx_category != 'undefined' && fx_category || '';
			strArr = ['waiid=' + _waiid, 'wasud=' + _wasud, 'isspace=' + _isspace, 'objectmark=' + _objectmark, 'category=' + _category];

			return '&' + strArr.join('&');
		}

		function click_Travel() {
			var initImg = new Image(), strArr = [], d = document, s = window.screen, fs = typeof fx_pagestart != 'undefined' && fx_pagestart || 0, lh = clearParam(d.location.href), eu = encodeURIComponent;
			if (!(/^file/.test(lh))) {
				strArr = ['url=' + eu(lh), 'referrer=' + eu(clearParam(d.referrer)), 'sw=' + s.width, 'sh=' + s.height, 'sc=' + s.colorDepth, 'urlIdentity=' + __wa__urlMark, 'lastmode=' + Math.random(), 'pageloadtime=' + (new Date().getTime() - fs), 'fl=' + getFlashVersion()];
				initImg.src = __wa_init_url + strArr.join('&') + getWaidInfo();
				initImg.onload = function() {
					initImg.onload = null;
					initImg.onerror = null;
				};
				initImg.onerror = function() {
					initImg.onload = null;
					initImg.onerror = null;
				}
			}
		};

		function visit_Travel() {
			var vtImg = new Image(), strArr = [], d = document, s = window.screen, fs = typeof fx_pagestart != 'undefined' && fx_pagestart || 0, lh = clearParam(d.location.href), eu = encodeURIComponent;
			if (!(/^file/.test(lh))) {
				if (lh.indexOf('i.fx-func.com') != -1) {
					strArr = ['url=' + eu(lh), 'referrer=' + eu(clearParam(d.referrer)), 'urlIdentity=' + __wa__urlMark, 'lastmode=' + Math.random()];
					vtImg.src = __wa_visit_url + strArr.join('&') + getWaidInfo();
					vtImg.onload = function() {
						vtImg.onload = null;
						vtImg.onerror = null;
					};
					vtImg.onerror = function() {
						vtImg.onload = null;
						vtImg.onerror = null;
					}
				}
			}
		}

		//1.记录regId中的a,submit,button元素的点击
		//2.记录单独的a或者单独的submit.button，并且a中可以含有其他元素
		function linkClick(e, j, regId, self) {
			// debugger;
			var e = e || window.event,
            t = e.target || e.srcElement,
            tagname = t.tagName.toLowerCase(),
            stagname = self.tagName.toLowerCase(),
            cpImg = new Image();
			if (stagname === 'div') {
				//if (has(t)) {
				if (t.type === 'submit' || t.type == 'button') {
					cpImg.src = __wa_travel_url + 'linkindex=' + j + '&regid=' + regId + '&lastmode=' + Math.random() + getWaidInfo();
				} else if (has(t)) {
					cpImg.src = __wa_travel_url + 'linkindex=' + j + '&regid=' + regId + '&lastmode=' + Math.random() + getWaidInfo();
				}
				//   }
			} else {
				cpImg.src = __wa_travel_url + 'linkindex=' + j + '&regid=' + regId + '&lastmode=' + Math.random() + getWaidInfo();
			}

			cpImg.onload = function() {
				cpImg.onload = null;
				cpImg.onerror = null;
			}
			cpImg.onerror = function() {
				cpImg.onload = null;
				cpImg.onerror = null;
			}
		}
		/*################################对事件对象的标准化开始#####################################*/
		function addEvent(obj, type, fn) {
			if (obj.attachEvent) {
				obj['e' + type + fn] = fn;
				obj[type + fn] = function() { obj['e' + type + fn](window.event); }
				obj.attachEvent('on' + type, obj[type + fn]);
			} else
				obj.addEventListener(type, fn, false);
		}
		function removeEvent(obj, type, fn) {
			if (obj.detachEvent) {
				obj.detachEvent('on' + type, obj[type + fn]);
				obj[type + fn] = null;
			} else
				obj.removeEventListener(type, fn, false);
		}
		/*############################对事件对象的标准化结束#########################################*/
		//记录a元素在某一个标志位的索引
		function aIndex(a, reg) {
			var regas = reg.getElementsByTagName('a');
			if (regas) {
				for (var i = 0; i < regas.length; i++) {
					if (regas[i] == a) return i;
				}
			}
			return 0;

		}
		function has(t) {
			var pt;
			do {
				pt = t.tagName ? t.tagName.toLowerCase() : '';
				if (pt == 'a' || pt == 'button') return true;
			} while (t = t.parentNode)
		}
		return {
			clickCount_type: clickCount_type,
			clickCount_regId: clickCount_regId,
			initTravel: click_Travel,
			visitTravel: visit_Travel,
			captureTravel: function() {
				var eles = getElementsByAttr(__attr);
				if (eles) {
					for (var i = 0, l = eles.length; i < l; i++) {
						var regId = eles[i].getAttribute(__attr);
						addEvent(eles[i], "click", (function(j, redId) {
							return function(e) {
								linkClick(e, j, redId, this);
							}
						})(0, regId));
					}
				}
			}
		}

	} ();
	//公有方法，记录指定类型
	window.wa_typeCount = Fx.Stat.clickCount_type;
	//公有方法，记录指定regId
	window.wa_regIdCount = Fx.Stat.clickCount_regId;
	window.wa_clickTravel = Fx.Stat.initTravel;
	window.wa_visitTravel = Fx.Stat.visitTravel;
	Fx.Stat.captureTravel();
	Fx.Stat.initTravel();
	setInterval("window.wa_visitTravel()", 60 * 1000);

})()
//