//--------------------------------------------------------------------------------Utilities object
function oUtilities() {}

//Produce a random number between and including lower and upper
oUtilities.getRandom=function(lower,upper) {
	return Math.ceil(Math.random()*(upper-lower+1))+lower-1;}

oUtilities.getUniqueIdentifier=function() {
	return Math.random().toString().substring(2) + '.' + oDate.getDateString();}

oUtilities.leadingZero=function(value, size) {
	var i, j, zeros='';
	for (i=1;i<size;i++) {
		if (value<Math.pow(10,i)) {
			for (j=1;j<size-i+1;j++) {zeros=zeros+'0'}
			return zeros + value.toString();}}
	return value.toString();}

oUtilities.rightSubstrIndexOf=function(value,search) {
	return value.substr(value.lastIndexOf(search)+1);}

oUtilities.formatCLI=function(cli) {
	if (cli.indexOf("tel:")==0) cli=cli.substring(4);
	if (cli.length==11) return '+44 (0)' + cli.substring(1,5) + ' ' + cli.substring(5);
	if (cli.length==10) return '+44 (0)' + cli.substring(0,4) + ' ' + cli.substring(4);
	return cli;}

oUtilities.replace=function(search,find,replace) {
	while (search.indexOf(find)!=-1) search=search.substring(0,search.indexOf(find)) + replace + search.substring(search.indexOf(find) + find.length);
	return search;}

oUtilities.inherit=function(func,obj,args) {
	if (!(args.length==1 && args[0]=='inherit')) {
		var i=0;
		eval('var exists=obj.' + func + i + '!=undefined;');
		while (exists) {
			eval('obj.' + func + i + '(args);');
			i++;
			eval('exists=obj.' + func + i + '!=undefined;');}}}

oUtilities.wrap=function(line,width) {
	var current=width;
	while (current<line.length) {
		line=line.substring(0,current) + ' ' + line.substring(current);
		current+=width+1;}
	return line;}
            
oUtilities.objectToString=function(object) {
	var properties=new Array(),current=0,currentObject;
	for (var p in object) {
		properties[properties.length]='[\'' + p + '\']';}
	while (current<properties.length && current<300 && properties.length < 300) {
		eval('currentObject=object' + properties[current] + ';');
		var found=false,previous=properties[current],offset=0;
		if (currentObject.constructor!=Array) {
			for (p in currentObject) {
				if (!found) {
					found=true;
					properties[current]+='[\'' + p + '\']';}
				else {
					properties.splice(current+1+offset,0,previous + '[\'' + p + '\']');
					offset++;}}}
		if (!found) {
			eval('properties[current]+=\'=\' + typeof(object' + properties[current] + ');');
			current++;}}
	var o='\n';
	for (var i=0;i<properties.length;i++) o+='object' + properties[i].replace(/\'\]\[\'/g,".").replace(/\[\'/g,'.').replace(/\'\]/g,'') + '\n';
	return o;}
