function eatWhiteSpace ( origString )
{

        var prevString;
        var thisString = origString;

        while ( prevString != thisString )
        {
               prevString = thisString;
               thisString = thisString.replace( /%20%20/g, "%20" );
               thisString = thisString.replace( /%20%0D/g, "%0D");
               thisString = thisString.replace( /%0A%20/g, "%0A");
               // I can't recall which would come first...
               }

        // a bit of clean up
        thisString = thisString.replace ( /%0D%0A%0D%0A/g, "<><><>");
        thisString = thisString.replace ( /%0D%0D/g, "<><><>" );
        thisString = thisString.replace ( /%0A%0A/g, "<><><>" );
        thisString = thisString.replace ( /%0D/g, "" );
        thisString = thisString.replace ( /%0A/g, " " );
        thisString = thisString.replace ( /<><><>/g, "%0D%0A%0D%0A" );

	// more clean up
	thisString = thisString.replace ( /%u2014/g, "--");
	thisString = thisString.replace ( /%u2013/g, "--");
	thisString = thisString.replace ( /%u2019/g, "'");
	thisString = thisString.replace ( /%u201C/g, "\"");
	thisString = thisString.replace ( /%u201D/g, "\"");

        return thisString;
        }

function doNewsItem ()
{
	var q, titlestart, urlstart, selstart, title, url, sel, i
	q = location.search;
	titlestart = q.indexOf("title=");
	urlstart = q.indexOf("url=");
	selstart = q.indexOf("selText=");

	title = q.slice(titlestart + 6, urlstart - 1);
	title = unescape(eatWhiteSpace (title));
	url = unescape(q.slice(urlstart + 4, selstart - 1));
	sel = q.slice(selstart + 8 );

	sel = eatWhiteSpace ( sel );
	sel = unescape ( sel );
	if ( sel != "" ) sel = "<i>Quote:</i> \"" + sel + "\"<br /><br /><i>Comment:</i> ";
	for (i=0; i<=(document.forms.length-1); i++) {
		if (document.forms[i].action.indexOf("/newsItems/edit/post")!=-1){
			document.forms[i].title.value = title;
			document.forms[i].url.value = url;
			document.forms[i].body.value = sel;
			if (bMode){
				messageText.innerText=sel;
			}
			break;
		}
	}
}

function tryNews(){
if (document.location.href.indexOf("/newsItems/edit/new")!=-1){
	doNewsItem ()
}
}