
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FILE LOCATION: /2008_templates/scripts/format_printPage.js
DESCRIPTION: Printer version script
DATE of LAST EDIT: August 20, 2008 
CHANGE LOG: 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

//Create global references
var printWindow = null;
var blIsOpen = false;
var opener;
var objPrint;


function getHeader() {
	var header;
	//BC logo plus print buttons
	header = "<div id='header'>";
	header += "<a href='http://www.gov.bc.ca/'><img id='logo' src='" + sSiteRoot + "2008_templates/images/logos/bcgov.gif' width='163' height='58' alt='British Columbia - The Best Place on Earth'></a>";
	header += getPrintButtons() ;
	header += "</div>";
	return header;
}


function getMainCol() {
	return "<div id='content'>"+document.getElementById("content").innerHTML+"</div>";
}


function getPrintButtons() {
	var strFooter;
		strFooter = "<div class='print-buttons'>" +
			"<a href='javascript:print(); window.self.close();'>" + 
			"<img src='" + sSiteRoot + "2008_templates/images/buttons/printClose.gif' id='printClose' width='108' height='28' alt='Print and close'></a>" +
			"<a href='javascript:window.self.close();'>" + 
			"<img src='" + sSiteRoot + "2008_templates/images/buttons/printCancel.gif' id='printCancel' width='108' height='28' alt='Cancel'></a>" +
			"</div>";
	return strFooter;
}


function doPrint(objWindow) {
	if (blPrintWindowOpen()) {
		printWindow.focus();//make the preview window bubble to surface
	} else {
	objPrint = new objPrintObject();
	blIsOpen = true;
	opener = objWindow;
	printWindow = window.open("", "PrintVersion", "left=100,screenX=200,top=50,screeny=100,resizable=yes,toolbar=yes,menubar=yes,width=800,height=600,modal=yes,scrollbars=yes,status=yes");
	printWindow.document.bgColor="white";
	printWindow.document.write("<html><head>");
	printWindow.document.write("<style type='text/css' media='all'>" +
							   "@import '" + sSiteRoot + "2008_templates/css/print.css';" +
							   "</style>");
	printWindow.document.write("</head>");
	printWindow.document.write("<body>");
	printWindow.document.write("<div id='wrapper'><a name='top'></a>");
	printWindow.document.write(objPrint.header);
	printWindow.document.write("<div id='content'>");
	printWindow.document.write(objPrint.mainCol);
	printWindow.document.write("</div>");
	printWindow.document.write("<div id='footer'>" + objPrint.printButtons + "</div>");
	printWindow.document.write("</div></body></html>");
	printWindow.document.close();
	}
}


function objPrintObject() {
	this.header = getHeader();
	this.mainCol = getMainCol();
	this.printButtons = getPrintButtons();
	this.ParentWindow = window;
}


function blPrintWindowOpen() {
	if ((printWindow != null) && (blIsOpen == true)) {
		return (! printWindow.closed);
	} else {
		blIsOpen = false;
		return false;
	}
}


function closeWindow() {
	if((printWindow != null) && (blIsOpen == true)) {
		printWindow.close();
		printWindow=null;
		blIsOpen = false;
		return true;
	}
	return false;
}