String.prototype.trim = function() {
	return(this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
};


	Ajax.Responders.register({
		onCreate: function() {
			if($('more-control')) {
				$('more-control').select(".loading")[0].removeClassName("x-hidden");
			}
		},
		onComplete: function() {
			if($('more-control')) {
				$('more-control').select(".loading")[0].addClassName("x-hidden");
			}
		}
	});


function placeholder(id, hint) {
	var input = Ext.get(id);
	input.hint = hint;
	if(input.dom.value == "") {
		input.dom.value = input.hint;
		input.addClass("hinted");
	}

	input.on('focus', function() {
		if(this.dom.value == this.hint) {
			this.dom.value = "";
			this.removeClass("hinted");
		}
	}, input);

	input.on('blur', function() {
		if(this.dom.value == "") {
			this.dom.value = this.hint;
			this.addClass("hinted");
		}
	}, input);

	var form = Ext.get(input.dom.form);
	if(form) {
		form.on('submit', function() {
			if(this.dom.value == this.hint) {
				this.dom.value = "";
			}
		}, input);
	}
}

function asHtml(text) {
	if(!text)
		text = "";
	text = text.trim();
	text = text.replace(new RegExp("\n", 'mgi'), "<br>");
	text = text.replace(new RegExp("\t", 'mgi'), "&nbsp;&nbsp;&nbsp;&nbsp;");
	text = text.replace(new RegExp("'", 'mgi'), "&#39;");
	text = text.replace(new RegExp("\"", 'mgi'), "&quot;");
	return text;
}

/*
 as key presses happen, detect if there is currently a url being typed
 if a space or blur happens after there is a current url, scan text for urls
 for each url found, check to see if we have it, if not, add it to the list
 as key presses happen, detect if existing text is being modified (delete or backspace) and reverse check urls to see
 if they should be removed
 This doesn't handle when text is highlighted and something other then delete or backspace is entered
 so instead, maybe we can just see if the text length has decreased and then re-reverse check urls
 Note: but this isn't necessary since we are removing the URL as we go... so wtf?
 */
function createTag(parentUl, name, text, deleteCb) {
	var parent = Ext.get(parentUl);
	// filter for illegal characters in displayed HTML
	text = text.replace("<", "&lt;");
	text = text.replace(">", "&gt;");

	var tag = parent.createChild({ tag: 'li', id: Ext.id(), cls: 'tag', html: text });
	//var tag = parent.createChild({ tag: 'li', id: Ext.id(), cls: 'tag' });

	tag.on('mouseover', function() {
		this.addClass('tag-hover');
	});
	tag.on('mouseout', function() {
		this.removeClass('tag-hover');
	});
	tag.deleteCb = deleteCb;

	var close = tag.createChild({ tag: 'a', href: '#', cls: 'closebutton', title: "Remove" });
	//tag.createChild({ tag: 'span', html: text });
	tag.createChild({ tag: 'input', type: 'hidden', name: name, value: text });

	close.on('click', function(e) {
		e.stopEvent();
		this.remove();
		if(this.deleteCb)
			this.deleteCb(this.id);
	}, tag);

	return tag.id;
}

function getFileExt(name) {
	if(!name)
		return "";
	var atmp = name.split('.');
	if(1 === atmp.length) {
		return "";
	} else {
		return atmp.pop().toLowerCase();
	}
}

function toString(obj) {
	var str = "";
	for(var f in obj) {
		str += (f + " = " + obj[f]);
	}
	return str;
}

function trim(str) {
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function log(obj, consoleMethod) {
	if(window.console/* && window.console.firebug && window.console.firebug.trim() !== ''*/) {
		if(typeof consoleMethod === "string" && typeof console[consoleMethod] === "function") {
			console[consoleMethod](obj);
		} else {
			console.log(obj);
		}
	}
}

function remove(el) {
	if(el)
		el.hide({anim:true, easing: 'easeBothStrong',
			callback:el.setHeight.createDelegate(el, [0, {anim:true, easing: 'easeBothStrong',
				callback:el.remove.createDelegate(el)}])});

	//container.hide({anim:true, easing: 'easeBothStrong', callback:help.setHeight.createDelegate(help, [0, {anim:true, easing: 'easeBothStrong'}])});
	//container.setHeight(0, {anim:true, easing: 'easeBothStrong'/*, callback:help.remove.createDelegate(help)*/});
}

function storageSupported() {
	if(localStorage)
		return true;
	return false;
}

function insertEntry(key, value) {
	if(!localStorage)
		throw "Local storage not present.";

	try {
		localStorage.setItem(key, value);
	} catch(ex) {
		log("Unable to update local storage: " + ex);
	}
}

function getEntry(key) {
	if(!localStorage)
		throw "Local storage not present.";

	try {
		return localStorage.getItem(key);
	} catch(ex) {
		log("Unable to update local storage: " + ex);
	}

	return null;
}

function error(e) {
	alert("Server error: " + e.responseText);
}
