// JavaScript Document
var Hits = {
	autorun : true,
	
	ajaxUrl : '/ajax/hits.php',
	
	infoHitsId : 'infoHits',
	
	types : {
		'goods' : true, 
		'news' : true , 
		'agent' : true, 
		'exhibition' : true,
		'job' : true,
		'trade' : true
	},
	
	shops : {
		'goods' : true,
		'agent' : true,
		'trade' : true
	},
	
	run : function(){
		var type, id, url, r, flag;
		url = document.location.pathname;
		//url = 'news.jc001.cn/detail/123.html';
		//url = 'shop.jc001.cn/6388/goods/9115.html';
		r = url.match(/(\w+)\/.+?\/(\d+)\.html$/i);
		if(!r){
			r = url.match(/shop.+?d+\/(\w+)\/.+?\/(\d+)\.html$/i);
			if(!r || !this.shops[r[1]]){
				return false;
			}
		}
		
		this.submit(r[1], r[2]); // r[1] -- type, r[2] -- id
	},
	
	validate: function(type){
		if(this.types[type]){
			return true;
		}else{
			return false;
		}
	},
	
	submit : function(type, id){
		if(!this.validate(type)){
			return false;
		}
		
		var pars = '?type=' + type + '&id=' + id ;
		var xmlHttpReq = this.getXmlHttpReq();
		//window.status = this.ajaxUrl + pars;
		xmlHttpReq.open("GET", this.ajaxUrl + pars, true);
		xmlHttpReq.send(null);
		
		var infoHitsId = this.infoHitsId;
		xmlHttpReq.onreadystatechange = function(){
			if(xmlHttpReq.readyState == 4){
				if(xmlHttpReq.status == 200){
					var infoHits = document.getElementById(infoHitsId);
					if(infoHits){
						infoHits.innerHTML = xmlHttpReq.responseText;
					}
				}
			}
		}
	},
	
	getXmlHttpReq : function(){
		if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
}

window.onload = function(){
	if(Hits.autorun){
		Hits.run();	
	}
}
