// Ajax Access Counter v1.02.2
// created by Sajiro since 2005 - 2006
// http://sajiro.net/pac/

// var pacpath ="./";
var pacpath ="http://sajiro.net/pac/";
var toppage = "/";


// ----------------------------------
var updloop = 0;
var cntloop = 0;
var cnttime = new Array("",10);
var type = 0;
if(document.getElementById("ajax_access_counter")) {
	var src = document.getElementById("ajax_access_counter").src;
	type = src.substring(src.indexOf("?") +1);
}

var path_file = location.pathname;
wk1 = location.pathname.indexOf("/index.htm");
if( wk1 >= 0 ) { path_file = location.pathname.substring(0, wk1+1); }

var file = wk2 = path_file; 
wk1 = path_file.lastIndexOf("/");
if( wk1 >= 0 ) { file = path_file.substring(wk1+1); wk2 = path_file.substring(0, wk1+1); }

wk1 = "dmy1/"+ wk2 + "dmy2/";
wk2 = wk1.split("/");
wk1 = wk2.slice(1,(wk2.length-2));
var path = wk1.join("/");
path = "http://"+ location.host + path +"/";

var fold = new Array("","","","","","","","","","");
for (j = 0; j < wk1.length; j++) {
	if( ("xx"+ wk1[j] +"xx") != "xxxx") { if( j >= 9 ) { wk2 = wk1.slice(j); fold[j] = wk2.join("/"); break; }else{ fold[j]=wk1[j]; } }
}

var usercode = getCookie( "usercode");
if( usercode <= 0 ){
	var dd = new Date();
	var today = Math.floor(dd.getTime()/1000);
	usercode=today;
	for (j = 0; j < 10; j++) { usercode += ""+ Math.floor(Math.random() * 10) +""; }
	setCookie( "usercode", usercode);
}

var fullpath = (path + file + location.search);
document.write('<span id=ajaxac_analyze></span>');
if( location.host != 'localhost' ) { pac_count(); }

if(type == 1) {
	document.write('<span id=ajaxac_img></span><a href=\"http://sajiro.net/c11531429737669615648/\"><img src=\"'+ pacpath +'image/circle-ball-dark-antialiased.gif\" border=0 alt=\"Ajax Access Counter\"></a>');
	pac_counter_view1();
}else if(type == 2) {
	document.write("Powered by Ajax Access Counter");
}else if(type == 'default') {
	document.write('<a href=\"http://sajiro.net/c11531429737669615648/\"><img src=\"'+ pacpath +'image/circle-ball-dark-antialiased.gif\" border=0 alt=\"Ajax Access Counter\"></a>');
}else{
	document.write('');
}

/******* debug start
document.write("debug: location.host:["+ location.host +"]<br>");
document.write("debug: location.pathname:["+ location.pathname +"]<br>");
document.write("debug: path_file:["+ path_file +"]<br>");
document.write("debug: path:["+ path +"]<br>");
for (j = 0; j < fold.length; j++) { document.write("debug: fold"+ j +" ["+ fold[j] +"]<br>"); }
document.write("debug: file:["+ file +"]<br>");
debug_cookie=document.cookie.split("; ");
for (j = 0; j < debug_cookie.length; j++) {	document.write("debug :"+ debug_cookie[j] +"<br>"); }
document.write("debug: toppage:["+ toppage +"]<br>");
debug end ********/


function pac_count() {



// start from 20 (0-19 from Perl Script)
var str ='<img border=0 width=0 height=0 src=\"'+ pacpath +'paca.cgi?';
str += "" + fullpath + "&=";
str += "" + location.host + "&=";
str += "" + fold[0] + "&=";
str += "" + fold[1] + "&=";
str += "" + fold[2] + "&=";
str += "" + fold[3] + "&=";
str += "" + fold[4] + "&=";
str += "" + fold[5] + "&=";
str += "" + fold[6] + "&=";
str += "" + fold[7] + "&=";
str += "" + fold[8] + "&=";
str += "" + fold[9] + "&=";
str += "" + file + "&=";
str += "" + location.search + "&=";
str += "&=";
str += "&=";
str += "&=";
str += "&=";
str += "&=";
str += "&=";
str += "" + document.title + " &=";
str += "&=";
str += "&=";
str += "&=";
str += "" + usercode + "&=";
str += "" + (cnttime[cntloop]) + "&=";
str += "&=";
str += "&=";
str += "&=";
str += "&=";
str += "" + navigator.appName + "&=";
str += "" + navigator.appVersion + "&=";
str += "" + navigator.platform + "&=";
str += "" + navigator.cpuClass + "&=";
str += "" + top.document.referrer + "&=";
str += "&=";
str += "&=";
str += "&=";
str += "&=";
str += "" + Math.floor(Math.random() * 999999) + "&=";
str += "\">";
document.getElementById("ajaxac_analyze").innerHTML= str;
// document.write(""+ str +"");

if( (++cntloop) < cnttime.length ) { setTimeout(pac_count, (cnttime[cntloop]+0)*1000); }
}

function pac_counter_view1( ) {
document.getElementById("ajaxac_img").innerHTML='<img src=\"'+ pacpath +'paci.cgi?'+ path +'\" alt=\"loading\">';
if( (updloop++) < 12 ) { setTimeout(pac_counter_view1,15000); }
}

function getCookie(key, tmp1, tmp2, xx1, xx2, xx3) {
	tmp1 = " " + document.cookie + ";";
	xx1 = xx2 = 0;
	len = tmp1.length;
	while (xx1 < len) {
		xx2 = tmp1.indexOf(";", xx1);
		tmp2 = tmp1.substring(xx1 + 1, xx2);
		xx3 = tmp2.indexOf("=");
		if (tmp2.substring(0, xx3) == key) {
			return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
		}
		xx1 = xx2 + 1;
	}
	return(0);
}

function setCookie(key, val, tmp) {
	tmp = key + "=" + escape(val) + "; ";
	tmp += "expires=Tue, 31-Dec-2030 23:59:59; ";
	if(toppage.length > 0 ) { tmp += "path="+ toppage +"; "; }
//    tmp += "expires=Tue, 31-Dec-2030 23:59:59; ";
	document.cookie = tmp;
}

function clearCookie(key) {
	document.cookie = key + "=" + "; expires=Tue, 1-Jan-1980 00:00:00;";
}
