function hystatistic_client(){

}
hystatistic_client.prototype.eregi=function(pattern,str){
	str = str.toLowerCase();
	pattern = pattern.toLowerCase();
	return str.match(pattern);
}
hystatistic_client.prototype.strpos=function(str,pattern){
	var pos=str.search(pattern);
	if(pos==-1) return false;
	return pos;
}
hystatistic_client.prototype.getOS=function(agent){	
	if (this.eregi('win', agent) && this.strpos(agent, '95')){
		os = 'Win 95';
	}
	else if (this.eregi('win 9x', agent) && this.strpos(agent, '4.90')){
		os = 'Win ME';
	}
	else if (this.eregi('win', agent) && this.eregi('98', agent)){
		os = 'Win 98';
	}
	else if (this.eregi('win', agent) && this.eregi('nt 5.1', agent)){
		os = 'Win XP';
	}
	else if (this.eregi('win', agent) && this.eregi('nt 5.2', agent)){
		os = 'Win 2003';
	}
	else if (this.eregi('win', agent) && this.eregi('nt 5', agent)){
		os = 'Win 2000';
	}
	else if (this.eregi('win', agent) && this.eregi('nt 6.0', agent)){
		os = 'Vista';
	}
	else if (this.eregi('win', agent) && this.eregi('nt', agent)){
		os = 'Win NT';
	}
	else if (this.eregi('linux', agent)){
		os = 'Linux';
	}
	else if (this.eregi('unix', agent)){
		os = 'Unix';
	}
	else if (this.eregi('Mac', agent) && this.eregi('PC', agent)){
		os = 'Macintosh';
	}
	else {
		 os = '';
	}
	return os;
}

hystatistic_client.prototype.getAPP=function(agent){
	if (this.eregi('msie',agent)) {
		if (this.strpos(agent, '8.0')) {
			app = 'IE 8.0';	
		} else if (this.strpos(agent,'7.0')) {
			app = 'IE 7.0';
		} else if (this.strpos(agent,'6.0')) {
			app = 'IE 6.0';
		} else {
			app = 'IE 5';
		}
	} else if (this.eregi('navigator')) {
		app = 'Navigator';
	} else	if (this.eregi('firefox',agent)) {
		if (this.strpos(agent, '/3.')) {
			app = 'FireFox V3';	
		} else if (this.strpos(agent,'/2')) {
			app = 'FireFox V2';	
		} else if (this.strpos(agent,'/1')) {
			app = 'FireFox V1';	
		}
	} else if (this.eregi('opera',agent)) {
		app = 'Opera';
	} else if (this.eregi('safari',agent)) {
		app = 'Safari';
	}
	return app;
}
hystatistic_client.prototype.GetCookie = function (name) { 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while (i < clen) { 
	  var j = i + alen; 
	  if (document.cookie.substring(i, j) == arg) 
		return this.getCookieVal (j); 
	  i = document.cookie.indexOf(" ", i) + 1; 
	  if (i == 0) break; 
	} 
	return null; 
} 

hystatistic_client.prototype.getCookieVal = function(offset) { 
	var endstr = document.cookie.indexOf (";", offset); 
	if (endstr == -1) 
	 endstr = document.cookie.length; 
	return unescape(document.cookie.substring(offset, endstr)); 
} 

hystatistic_client.prototype.SetCookie = function (name, value) { 
	document.cookie = name + "=" + escape (value)+ "; path=/"; 
}


hystatistic_client.prototype.hystatistic_writejs = function(){

	if(!document.getElementsByTagName){
		var urlparse=document.scripts[document.scripts.length-1].src.split("\?");
	}else{
		var scripts=document.getElementsByTagName('script');
		var urlparse=scripts[scripts.length-1].src.split("\?");
	}

	var urlpath=urlparse[0].substr(0,urlparse[0].length-"userjs.js".length);
	var urlsearch=urlparse[1];
	var reqs=urlsearch.split("&");
	var http_get_vars = new Array();
	for(i=0;i<reqs.length;i++){
	   req=reqs[i].split("=");
	   eval("http_get_vars['"+req[0]+"']='"+unescape(req[1])+"';");
	}
	
	var referrer = top.document.referrer;
	referrer = (referrer=="")?document.referrer:referrer;
	referrer = escape(referrer);
	
	var file = window.location.href;
	if(file.indexOf('#')!=-1){	file = file.substr(0,file.indexOf('#')); }

	fileparse = file.split("\?");
	if(fileparse.length>1){
		var reqs = fileparse[1].split("&");
		reqs.sort();
		file = fileparse[0]+"?"+reqs.join('&');
	}
	file = escape(file);
				   
	var pagetitle = escape(escape(document.title));

	//var browser = escape(navigator.appName);
	var browser = escape(this.getAPP(navigator.userAgent));
	var opsystem = escape(this.getOS(navigator.userAgent));

	if(this.GetCookie("hystatistic_visited")=="1"){
		var visited = 1;
	}else{
		var visited = 0;
	}
	this.SetCookie("hystatistic_visited","1");

	document.write("<script language='javascript' src='"+urlpath+"count.php?userid="+http_get_vars["userid"]+"&icon="+(http_get_vars["icon"]==1?1:0)+"&visited="+visited+"&screenwidth="+window.screen.width+"&screenheight="+window.screen.height+"&referrer="+referrer+"&file="+file+"&pagetitle="+pagetitle+"&browser="+browser+"&opsystem="+opsystem+"'></script>");
}

if(!hystatistic_client_obj){
	var hystatistic_client_obj = new hystatistic_client();
	hystatistic_client_obj.hystatistic_writejs();
}