//Create and show a popup window containing a printable version of the web page
function nyandoPrinterFriendlyPopup()
{
	//Start some HTML for the popup window
	var html = '';
	html += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r\n';
	html += '<html xmlns="http://www.w3.org/1999/xhtml">';
	html += '<head>';
	var docTitle = document.title.trim();
	html += '<title>' + document.title + (docTitle.length == 0 ? '' : ' - ') + 'Printer Friendly Version</title>';

	//Copy over the <link> style sheets for default element styles
	var links = $(document.head).getElements('link'); //Get all <link> tags from the <head> of this page
	for (var i = 0; i < links.length; i++) //For (each <link> tag)...
	{
		//If (the <link> is for a style sheet AND it's not for AddThis.com)...
		if (links[i].rel.toLowerCase() == 'stylesheet' && links[i].href.toLowerCase().indexOf('.addthis.com') == -1)
		{
			//Generate a <link> tag for the popup window
			html += '<link rel="stylesheet" type="text/css" href="' + links[i].href + '"/>';
		}
	}

	//Copy over embedded <style> tags for all cart screens (and anything else) on this page
	html += '\n<style>\n';
	var styles = $(document.body).getElements('style'); //Get all <style> tags from the <body> of this page
	for (var i = 0; i < styles.length; i++) //For (each <style> tag)...
	{
		//Copy over the raw <style> information
		html += styles[i].get('html') + '\n';
	}

	//Convert all gradient styles to "white". Code below will remove their background images.
	html += '.olsonBgShadedLight    { background-color: white; }' + '\n';
	html += '.olsonBgShadedDark     { background-color: white; }' + '\n';
	html += '.olsonBgGradientBlock  { background-color: white; }' + '\n';
	html += '.olsonBgGradientBubble { background-color: white; }' + '\n';
	html += '.olsonShadedBlock a.olsonLink { font-weight: 900; color: #4C5CC5; text-decoration: none; }' + '\n';
	html += '.olsonShadedBlock a           { font-weight: 900; color: #4C5CC5; text-decoration: underline; }' + '\n';

	html += '\n</style>\n';

	//Copy over the <script> links
	var scripts =  $(document.head).getElements('script');  //Get all <script> tags from the <head> of this page
	scripts.extend($(document.body).getElements('script')); //Get all <script> tags from the <body> of this page
	for (var i = 0; i < scripts.length; i++) //For (each <script> tag)...
	{
		//Generate a <script> tag for the popup window
		var scriptType = '';
		if (scripts[i].type != '') scriptType = ' type="' + scripts[i].type + '"';
		var scriptSource = '';
		if (scripts[i].src != '') scriptSource = ' src="' + scripts[i].src + '"';
		if (scriptSource.toLowerCase().indexOf('.addthis.com') == -1)
		{
			html += '<script' + scriptType + scriptSource + '>' + scripts[i].get('html') + '</script>\n';
		}
	}

	//Done with the popup's <head> section
	html += '</head>';

	//Get the body HTML from the currently displayed page
	var htmlBody = $(document.body).get('html');

	//Remove all background images, which will be gradients and bubbles, etc.
	htmlBody = htmlBody.replace(/background-image\:\s*url\(.+?\);?/gi, '');

	//Remove other sections from the page that don't have much bearing on a printout
	htmlBody = htmlBody.replace(/<\!-- BEGIN AUX NAVIGATION -->[\w\W]*<\!-- END AUX NAVIGATION -->/, '&nbsp;');
	htmlBody = htmlBody.replace(/<\!-- BEGIN TAG LINE SEARCH -->[\w\W]*<\!-- END TAG LINE SEARCH -->/, '<div style="float: right; margin-top: 2px; margin-right: 14px;"><a href="javascript:window.print();">Print This Page</a></div>');
	htmlBody = htmlBody.replace(/<\!-- BEGIN TABS -->[\w\W]*<\!-- END TABS -->/, '');
	htmlBody = htmlBody.replace(/<\!-- BEGIN BANNER -->[\w\W]*<\!-- END BANNER -->/, '');

	//Remove the "Add This" HTML
	var addThisDiv = $('at20mc');
	if (addThisDiv)
	{
		var addThisHTML = addThisDiv.get('html');
		htmlBody = htmlBody.replace(addThisHTML, '');
	}

	//Add the edited body content
	html += htmlBody;

	//Add a "marker" for the domready event so that it won't add dynamic background images back in
	html += '<div id="chcPrinterFriendlyMode" style="display: none;"></div>';

	//Done with all HTML for the popup
	html += '</html>';

	//Create the popup window
	var popup = window.open('', '_blank', 'height=650,width=1000,resizable=yes,scrollbars=yes');

	//Write the HTML to the popup window
	popup.document.open('text/html');
	popup.document.write(html);
	popup.document.close();
}

