var PHP = function(){};

PHP.ceil = function(number) {
	number/=1;
	if(number==Math.round(number)) return number;
	return Math.round(number+.5);
}

PHP.floor = function(number) {
	number/=1;
	if(number==Math.round(number)) return number;
	return Math.round(number-.5);
}

PHP.in_array = function(str, array) {
	str+='';
	var self = array;
	for(var i in self) {
		if(self[i]==str) return true;
	}
	return false;
}

PHP.ltrim = function(str) {
	str+='';
	var re = /\s*((\S+\s*)*)/;
	return str.replace(re, "$1");
}

PHP.microtime = function() {
	return new Date().getTime();
}

PHP.print_r = function(theObj, doReturn, __indent) {
	if(!doReturn) doReturn = false;
	if(!__indent) __indent=0;
	var tab = '    ';
	var result = '';
	
	if(theObj.constructor == Array || theObj.constructor == Object) {
	
		var indentString = '';
		for(i=0; i<__indent; i++) {
			indentString += tab;
		}
		
		result += theObj ? typeof(theObj)+'('+theObj.length+') {\n' : 'null\n';
		__indent++;
		indentString += tab;
		
		for(var p in theObj){
			
			if(theObj[p] && (theObj[p].constructor == Array || theObj[p].constructor == Object)) {
				result += indentString;
				result += '['+p+'] => ';
				result += PHP.print_r(theObj[p], true, __indent);
			} else {
				result += indentString;
				result += '['+p+'] => '+theObj[p];
				result += '\n';
			}
			
		}
		
		result += indentString.substring(0,indentString.length-tab.length) + '}\n';
	}
	
	if(doReturn) return result;
	else {
		var div = document.createElement('div');
		var pre = document.createElement('pre');
		pre.innerHTML = result;
		div.appendChild(pre);
		document.body.appendChild(div);
	}
	
}

PHP.round = function(number, precision) {
	number/=1;
	if(!precision || precision<0) precision = 0;
	if(precision==0) return Math.round(number);
	else {
		var tmp = Math.pow(10,precision);
		number *= tmp;
		number = Math.round(number);
		return number/tmp;
	}
}

PHP.rtrim = function(str) {
	str+='';
	var re = /((\s*\S+)*)\s*/;
	return str.replace(re, "$1");
}

PHP.time = function() {
	return Math.round(new Date().getTime()/1000);
}

PHP.trim = function(str) {
	str+='';
	return PHP.ltrim(PHP.rtrim(str));
}

PHP.ucfirst = function(str){
	str+='';
	return str.replace(/\w+/, function(a) {
		return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
	});
}

PHP.ucwords = function(str){
	return str.replace(/\w+/g, function(a){
		return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
	});
}