// $Id: c.js, v1.03 2005/12/22 17:22 T.I Exp $
ITGCntTitle = "Access Counter";
ITGCntSvr = "cnt1.itgear.jp";
ITGCntPrm = new Array();
ITGCntImage=100;
ITGCntFigure=5;
ITGCntReload=1;
//ITGCntCount=0;
//ITGCntClrgrp=0;
//ITGCntParam=1
if (typeof(ITGCntImage) !="undefined") ITGCntPrm[ITGCntPrm.length]="i="+escape(ITGCntImage);
if (typeof(ITGCntFigure)!="undefined") ITGCntPrm[ITGCntPrm.length]="f="+escape(ITGCntFigure);
if (typeof(ITGCntReload)!="undefined") ITGCntPrm[ITGCntPrm.length]="r="+escape(ITGCntReload);
if (typeof(ITGCntCount) !="undefined") ITGCntPrm[ITGCntPrm.length]="c="+escape(ITGCntCount);
if (typeof(ITGCntClrgrp)!="undefined") ITGCntPrm[ITGCntPrm.length]="l="+escape(ITGCntClrgrp);
if (typeof(ITGCntParam) !="undefined") ITGCntPrm[ITGCntPrm.length]="p="+escape(ITGCntParam); else ITGCntParam = 0;
ITGCntPrm[ITGCntPrm.length]="t="+(new Date()).getTime();
ITGCntAd = ITGCntIsValidHost(location)
	? '<img src="http://'+ITGCntSvr+'/'+ITGCntUrl2UserPath()+'/count.gif?'+ITGCntPrm.join('&')+'" alt="'+ITGCntTitle+'" border="0" />'
	: '<span style="padding:2px 1px 1px 2px; border:1px solid #000; background:#fff; color:#00f; font-size:12px;">'+ITGCntTitle+'</span>';
document.write('<a style="text-decoration:none;"" target="_blank">'+ITGCntAd+'</a>');
function ITGCntUrl2UserPath(url) {
	var i, pos, query;
	url = (url || location.href)+"#";
	var id = url.substring(url.indexOf("//")+2, url.indexOf("#"));
	if (id.substring(0,4) == "www.") id = id.substring(4);
	query = id.indexOf("?")==-1 ? "" : id.substring(id.indexOf("?"));
	id = id.substring(0,(id+"?").indexOf("?"));
	id = id.replace(/\/index\..{3,5}$/, "/");
	id = (id+"/").replace(/\/\/+/g, "/");
	while ((pos=id.indexOf("%"))!=-1 && pos<=id.length-3)
		id = id.substring(0,pos) + unescape(id.substring(pos,pos+3)) + id.substring(pos+3);
	if (ITGCntParam < 0) id += query;
	else {
		var pn=ITGCntParam, ps=0, pe;
		while (pn-- && ps < query.length) {
			id += query.substring(ps, pe=(query+"&").indexOf("&",ps+1));
			ps = pe;
		}
	}
	id = id.toLowerCase();
	id = ITGCntReplaceChar(id,"/","S");
	id = ITGCntReplaceChar(id,".","D");
	id = ITGCntReplaceChar(id,"-","H");
	id = ITGCntReplaceChar(id,"~","T");
	id = ITGCntReplaceChar(id,"?","Q");
	id = ITGCntReplaceChar(id,"=","E");
	id = ITGCntReplaceChar(id,"&","N");
	id = ITGCntReplaceChar(id,"+","C");
	id = ITGCntReplaceChar(id,"@","A");
	id = ITGCntReplaceChar(id,"%","P");
	var ch;
	while ((ch = id.match(/\W/)) != null) {
		var hex = "00" + String(ch).charCodeAt(0).toString(16);
		id = id.replace(ch, "P" + hex.substring(hex.length-2).toLowerCase());
	}
	var dir = id.charAt(0);
	if (!("0"<=dir && dir<="9" || "a"<=dir && dir<="z")) dir = "0";
	return dir+"/"+id;
}
function ITGCntReplaceChar(str, sep, rep) {
	var listItem = str.split(sep);
	var listJoin = new Array();
	for (var i = 0; i < listItem.length-1; i++) {
		if (listItem[i] != "") listJoin[listJoin.length] = listItem[i];
	}
	listJoin[listJoin.length] = listItem[listItem.length-1];
	return listJoin.join(rep);
}
function ITGCntIsValidHost(url) {
	if (url.protocol.indexOf("http") != 0 || url.hostname == "localhost") return false;
	if (url.hostname.match(/^(\d+)\.(\d+)\.\d+\.\d+$/)) {
		if (
			(RegExp.$1==127) ||
			(RegExp.$1==192 && RegExp.$2==168) ||
			(RegExp.$1==172 && 16<=RegExp.$2 && RegExp.$2<=31) ||
			(RegExp.$1==10)
		)
			return false;
	}
	return true;
}
