/*
	sfatistics - Very Simple Web Analytics
*/

var sfatisticsScript="/sfatistics/sfatistics.php";


function sfatisticsLog(url, ref, act) {
	if( !url )
		url = window.location.href;
	if( !ref )
		ref = document.referrer;
	if( !act )
		act = "0";
	
	if( (sess = sfatisticsGetCookie("sfatistics")) == "" ) {
		sess = "sf" + sfatisticsGetDateString() + Math.floor(Math.random()*10000000);
		sfatisticsSetCookie("sfatistics",escape(sess));
	}
	scall = sfatisticsScript + "?url=" + escape(url) + "&ref=" + escape(ref) + "&sess=" + escape(sess) + "&act=" + escape(act);
	document.write("<img src=\"" + scall + "\" alt=\"\" />");
}


function sfatisticsGetDateString() {
	d = new Date();
	year = d.getYear();
	if( year < 999 )
		year += 1900;
	month = d.getMonth() + 1;
	if( month < 10 )
		month = "0" + month
	day = d.getDate();
	if( day < 10 )
		day = "0" + day
	return year + month + day;
}

function sfatisticsSetCookie(cname, cvalue) {
	document.cookie = cname+ "=" +escape(cvalue);
}

function sfatisticsGetCookie(cname) {
	if (document.cookie.length>0) {
		cstart=document.cookie.indexOf(cname + "=");
		if( cstart != -1) {
			cstart = cstart + cname.length + 1;
			cend = document.cookie.indexOf(";",cstart);
			if (cend == -1)
				cend = document.cookie.length;
			return unescape(document.cookie.substring(cstart,cend));
		}
	}
	return "";
}
