var K = {
}

K.isIE = (navigator.appName.indexOf("Microsoft Internet Explorer") > -1) && navigator.appName.indexOf('Opera')<0;
K.isOpera = navigator.appName.indexOf('Opera') > -1;

K.debug = function(e) {
	if (window.console) {
		window.console.log(e);
	} else if (console.debug) {
		console.debug(e);
	}
}

K.makeHomePage = function(a) {
	try {
		a.style.behavior='url(#default#homepage)'; 
		a.setHomePage('http://www.kabillion.com/?gatrack=homepge')
		return false;
	} catch (e) {}
	return true;
}

K.Debugger_base = Class.create();
K.Debugger_base.prototype = {
	on: 0,
	initialize : function() {},
	debug: function() {
		if (!this.on) return;
		if (typeof(console) == 'undefined') {
			window.status = $A(arguments).join(', ') + ' :: ' + window.status;
		} else {
			switch(arguments.length) {
				case 1: console.debug(arguments[0]); break;
				case 2: console.debug(arguments[0],arguments[1]); break;
				default: console.debug(arguments);
			}
		}
	}
}

K.onLoadStatements = [];

K.addLoader = function(statement) {
	this.onLoadStatements[this.onLoadStatements.length] = statement;
	if (this.onLoadStatements.length==1) {
		Event.observe(window,'load',function(){
			for (i=0;i<K.onLoadStatements.length;i++) {
				eval(K.onLoadStatements[i]);
			}
		});
	}
}

K.number_format = function(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

K.Math = {};

K.rand = function(max) {
//	var n = Math.random();
	return Math.floor(Math.random()*max) % max + 1;
}

K.roll = function(sides,dice) {
	var roll = 0;
	for (var i =0; i<dice; i++) {
		roll += Math.round(Math.random() * sides) % sides + 1
	}
	return roll;
}

K.addFriend = function(friend_id) 
{
	new Ajax.Updater('ajaxDiv', '/post/addfriend.php', {evalScripts:true,postBody:'friend_id=' + friend_id});
	return false;
}


/* Test K.rand()
var test = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
for (i=0;i<1000;i++) {
	var n =K.rand(20);
	test[n]++;
}
for (i=1;i<21;i++){
	console.debug(i+':',test[i]);
	
}
//*/



//* Test K.roll()

/* Test K.rand()
var test = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
for (i=0;i<10000;i++) {
	var n =K.roll(6,3);
	test[n]++;
}
for (i=1;i<19;i++){
	console.debug(i+':',test[i]);
	
}
//*/

