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

// var counter_path ='http://solo1150/public_html/download.kabukimono.net/analyze/';
var counter_path ='http://download.kabukimono.net/analyze/';

var type = 'NONE';
if(document.getElementById('download_counter')) {
	var src = document.getElementById('download_counter').src;
	type = src.substring(src.indexOf('?') +1);
}

var usercode = getCookie('download_counter_usercode');
if( usercode == 0 ){
	var dd = new Date();
	usercode = Math.floor(dd.getTime()/1000);
	for (j = 0; j < 10; j++) { usercode += ''+ Math.floor(Math.random() * 10) +''; }
	setCookie( 'download_counter_usercode', usercode);
	
	to_counter();
}else{
//	window.alert('NG['+ usercode +']');
}

function to_counter(){
document.write('<span id="download_counter_area"></span>');
// start from 10 (0-9 from Perl Script)
var str ='<img border=0 width=0 height=0 src="'+ counter_path +'counter.cgi?';
str += '' + getFullURL() + '&=';
str += '' + type + '&=';
str += '' + document.title + ' &=';
str += '&=';
str += '&=';
str += '&=';
str += '&=';
str += '&=';
str += '&=';
str += '&=';
str += '' + Math.floor(Math.random() * 999999) + '&=';
str += '\">';
document.getElementById('download_counter_area').innerHTML= str;
}

function getFullURL () {
	var path_file = top.location.pathname;
	wk1 = top.location.pathname.indexOf('/index.htm');
	if( wk1 >= 0 ) { path_file = top.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://'+ top.location.host + path +'/';
	var fullpath = (path + file + top.location.search);
	
	return fullpath;
}

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;';
}
