jQuery.fn.extend({
xhtml: function( val ) {
	//Removing Flash message 
	
	//$(".noFlashMessage").remove();
	
	if (val == undefined)
	{
		if (this.length == 0) return null;
		/*
		// internet explorer's innerHTML is craptastic so we use some hackery to fix it
		// if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1){
		// BUG: self-closing <a> tags don't work , e.g "<a name='inline' />"
		*/
		
		var reTag = /(<\/?\w+)([^>]*>)/g;
		var reAttr = /(\w+=)((['"])[\s\S]*\3|[^\s>]+)/g;
		str = $(this).html();
		
		function fixAttr($0, $1, $2, $3) {
			if ($3) return $1.toLowerCase() + $2;
			else return $1.toLowerCase() + '"' + $2 + '"'
		} 		

		function fixTag($0, $1, $2) {
			return $1.toLowerCase() + $2.replace(reAttr, fixAttr);
		}

		/* clean up tags (make html tags and attributes lowercase) */
		str = str.replace(reTag, fixTag);

		/* make sure self-closing tags are closed */
		var reSelfClosing = new RegExp("\<(area|base|basefont|br|hr|img|input)(.*?)>", "g");
		
		str = str.replace(reSelfClosing, "<$1$2/>");
		/*
		// IE's treatment of UL's and DL's is mind boggling.
		// A big brain came up with this series of search/replaces that fixes them.  You go Dan.  
		*/
		str = str.replace(/<!(?:--[\s\S]*?--\s*)?>\s*/igm, "");
		str = str.replace(/<\/li>|<\/dt>/g, "");							// get rid of all closing li and dt tags (for IE)
		str = str.replace(/\s*<li([^>]*)>/g, "<\/li><li$1>");		// put a closing li in front of all opening li
		str = str.replace(/<\/ul>/g, "<\/li><\/ul>");					// put a closing li in front of closing ul
		str = str.replace(/<ul([^>]*)>\s*<\/li>/g, "<ul$1>");		// remove closing li's that appear directly after opening ul
		str = str.replace(/\s*<dd([^>]*)>/g, "<\/dt><dd$1>");	// put a closing dt in front of all opening dd's
		/* end dan hackery */
		
		str = str.replace(/\r/igm, "");
		str = str.replace(/\t/igm, "");
		str = str.replace(/\n/igm, "");
		
		return str;		
	}
	else this.empty().append( val );
}

});
