Object.extend(String.prototype, {
	//Replaces Prototype strip.
	strip: function() {
		return this.replace(/^\s+|\s+$/, '');
	},
	//Global strip.
	superStrip: function() {
		return this.replace(/^\s+|\s+$/g, '');
	},
	//Global strip plus strips quotes.
	stripQuotes: function(value) {
		return this.replace(/^[\s\u0027\u0022\u201c\u201d\u2018\u2019\u2039\u203A\u00AB\u00BB]+|[\s\u0027\u0022\u201c\u201d\u2018\u2019\u2039\u203A\u00AB\u00BB]+$/g, '');
	}
});

var Acw = {
	//HTML tags from http://www.tntluoma.com/sidebars/codes/
	//Unicode from  http://www.kadifeli.com/fedon/utf.htm
	quoteTags: [
		{open: '&quot;', close: '&quot;'}, //Regular Double Quotation mark - ", "
		{open: "'", close: "'"}, //Regular Single Quotation mark - ', '
		{open: '&ldquo;', close: '&rdquo;'}, //Double Quotation mark - “, ”
		{open: '&lsquo;', close: '&rsquo;'}, //Single Quotation mark - ‘, ’
		{open: '&laquo;', close: '&raquo;'}, //Double Angle Quotation mark - «, »
		{open: '&lsaquo;', close: '&rsaquo;'} //Single Angle Quotation mark - ‹, ›
	],
	createNewWindowLinks: function() {
		var newWindowLinks = $$('a.js_NewWindow');
		
		for(var i = 0; i < newWindowLinks.length; i++) {
			newWindowLinks[i].redirectUrl = newWindowLinks[i].href;
			
			newWindowLinks[i].observe('click',
				(function(event) {
					window.open(this.redirectUrl);
					Event.stop(event);
				}).bind(newWindowLinks[i])
			);
		}
	},
	//Based on http://juicystudio.com/article/fixing-ie-quotes.php
	addQuotes: function() {
		var isNested = function(objElement) {
			var objParent = objElement;
			
			do {
				objParent = objParent.parentNode;
				if(objParent.tagName) {
					switch(objParent.tagName.toLowerCase()) {
						case 'q':
						case 'blockquote':
							return true;
					}
				}
			}
			while(objParent.parentNode);
			
			return false;
		};
		var quoteElements = null;
		var i = 0, j = 0;
		
		if(Prototype.Browser.IE) {
			quoteElements = document.getElementsByTagName('q');
			
			for (i = 0; i < quoteElements.length; i++) {
				if (!isNested(quoteElements[i])) {
					Acw.quote(quoteElements[i], Acw.quoteTags[2]);
				} else {
					Acw.quote(quoteElements[i], Acw.quoteTags[3]);
				}
			}
		}
		
		quoteElements = document.getElementsByTagName('blockquote');
		
		for (i = 0; i < quoteElements.length; i++) {
			var pElements = quoteElements[i].getElementsByTagName('p');
			
			for (j = 0; j < pElements.length; j++) {
				if(j < pElements.length - 1) {
					Acw.quote(pElements[j], {open: Acw.quoteTags[2].open});
				} else {
					Acw.quote(pElements[j], Acw.quoteTags[2]);
				}
			}
		}
		
		quoteElements = null;
	},
	quote: function(element, quoteTags) {
		if(quoteTags.close) {
			element.innerHTML = quoteTags.open + element.innerHTML.stripQuotes() + quoteTags.close;
		} else {
			element.innerHTML = quoteTags.open + element.innerHTML.stripQuotes();
		}
	}
};