// Utility to output an element as a standalone document
function prw(w, s) {
	w.document.writeln(s);
}
var w, pw;
function printThePage() {
	pw.print();
}
function printablePage(id) {
	var src, iframe, pdf;
	// Special case the PDF embedded document.
	pdf = document.getElementById('printPDF');
	if (pdf) {
		src = pdf.src;
		pw = window.open(src, window.name + "_PDFprint", "menubar,resizable,scrollbars,status");
		if(!pw) {
			alert("Window with printable form cannot be opened!\nThis is likely due to a popup blocker in your browser.");
			return;
		}
		pw.onload = printThePage;
		pw.focus();
		return;
	}
	// Special case the Newsletter iframe
	iframe = document.getElementById('newsletterIframe');
	if (iframe) {
		src = iframe.getAttribute("src");
		pw = window.open(src, window.name + "_NewsletterPrint", "menubar,resizable,scrollbars,status");
		if(!pw) {
			alert("Window with printable form cannot be opened!\nThis is likely due to a popup blocker in your browser.");
			return;
		}
		pw.onload = printThePage;
		pw.focus();
		return;
	}
	
	if(!w || w.closed) w = window.open("", window.name + "_print", "menubar,resizable,scrollbars,status");
	if(!w) {
		alert("Window with printable form cannot be opened!\nThis is likely due to a popup blocker in your browser.");
		return;
	}
	w.defaultStatus = "Loading.";
	w.document.open();

	// Test to see if we have a printable IFRAME
	var e;
	var iframe = document.getElementById('printIframe');
	if (iframe) {
		var doc = iframe.contentWindow || iframe.contentDocument;
		if (doc.document) {
			doc = doc.document;
		}
		e = doc.body;
	} else {
		e = document.getElementById(id);
	}

	//Search up to find object setting style
	for(t=e.parentNode; t.parentNode; t=t.parentNode) {
		if (t.style && t.style.backgroundColor) {
			bg = t.style.backgroundColor;
			w.document.bgColor = bg;
			break;
		}
	}  
	prw(w, "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">")
	prw(w, '<html><head>');
	prw(w, '<title>' + document.title + '</title>');
	prw(w, '<link href="/css/print.css" type="text/css" rel="stylesheet" media="all" />');
	prw(w, '</head><body>');
	// prw(w, "<body bgcolor=\"" + bg + "\">");
	
	var re = new RegExp("<script.*<\\/script>", "gim");
	prw(w, e.innerHTML.replace(/\n/g,'\uffff').replace(re,'').replace(/\uffff/g,'\n'));
	prw(w, "<p align=\"right\">&copy; 1999-2007 Debbie Dadey<br>All rights reserved</p>");
	prw(w, "</body></html>");
	w.document.close();
	w.defaultStatus = "Done.";
	w.focus();
	w.print();
}

function printPage(body) {
	//if (w) return;
	if(!w || w.closed) w = window.open("", window.name + "_print", "menubar,resizable,scrollbars,status");
	if(!w) {
		alert("Window with printable form cannot be opened!\nThis is likely due to a popup blocker in your browser.");
		return;
	}
	w.defaultStatus = "Loading.";
	w.document.open();
	//Search up to find object setting style
	/*
	for(t=e.parentNode; t.parentNode; t=t.parentNode) {
		if (t.style && t.style.backgroundColor) {
			bg = t.style.backgroundColor;
			w.document.bgColor = bg;
			break;
		}
	}  
	*/
	prw(w, "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">")
	prw(w, '<html><head>');
	prw(w, '<title>' + document.title + '</title>');
	prw(w, '<link href="/css/edit.css" type="text/css" rel="stylesheet" media="all" />');
	prw(w, '</head><body>');
	// prw(w, "<body bgcolor=\"" + bg + "\">");
	
	prw(w, body);
	prw(w, "</body></html>");
	w.document.close();
	w.defaultStatus = "Done.";
	w.focus();
	//w.print();
}
