/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FILE LOCATION: /2008_templates/scripts/format_printPage.js
DESCRIPTION: Printer version script
DATE of LAST EDIT: August 20, 2008 
CHANGE LOG: 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

var sSiteRoot = window.location.protocol + "//" + window.location.host + "/";
//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 += "<div id='bcartslogo'><a href='/'><img src='"+ sSiteRoot + "images/printerversion-logo.gif' width='250' height='68' border='0' /></a></div>";
    header += "<div id='bcgovlogo'><a href='http://www.gov.bc.ca/' target='_blank'><img src='"+ sSiteRoot +  "images/printerversion-bclogo.gif' width='163' ";    header += "height='58' border='0' /></a></div>";
    header += "<div style='clear:both; float:right'>" +getPrintButtons() +  "</div></div>";
    header += "<div style='clear:both'></div><div><hr /></div>";
   	return header;
}


function getMainCol() {
	return "<div id='content2'>"+document.getElementById("content2").innerHTML+"</div>";
}

function getRightCol() {
	var rightCol = "";
	var str = document.getElementById("rightcol2").innerHTML;
	var temp = str.replace(/<script language=\"javascript\" src=\"scripts\/random.js\"><\/script>/, "");
	
	rightCol = "<div class='interactive-calendar' style='background:url(images/interactive-calendar.gif) no-repeat top; margin-top:20px; padding-top: 35px;'>" +document.getElementById("rightcol1").innerHTML + "</div>" +
	"<div class='community' style='background:url(images/arts-in-your-community.gif) no-repeat top; margin-top:-10px; padding-top: 35px;'>" + temp +  "</div>" +
	"<div class='difference' style='background:url(images/arts-make-a-difference.gif) no-repeat top; margin-top:-10px; padding-top: 35px;'>" +document.getElementById("rightcol3").innerHTML +"</div>" +
	"<div class='informed' style='background:url(images/stay-informed.gif) no-repeat top; margin:0px; padding-top: 35px;'>" +document.getElementById("rightcol4").innerHTML +"</div>" ;
	return rightCol;
}
function getCentreCol() {
	return document.getElementById("centrecolumn").innerHTML;
}
function getNews() {
	return "<div id='news'>" + document.getElementById("news").innerHTML + "</div><div id='upcoming-deadlines'>" + document.getElementById("upcoming-deadlines").innerHTML + "</div>";
}

function getPrintButtons() {
	var strFooter;
		strFooter = "<a href='javascript:print(); window.self.close();'>" + 
			"<img src='" + sSiteRoot + "images/printClose.gif' id='printClose' width='128' height='28' alt='Print and close' border='0'></a>&nbsp;&nbsp;" +
			"<a href='javascript:window.self.close();'>" + 
			"<img src='" + sSiteRoot + "images/printCancel.gif' id='printCancel' width='128' height='28' alt='Cancel' border='0'></a>"; 
	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 + "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><hr /></div>");
	printWindow.document.write("<div id='footer'>" + objPrint.printButtons +
							   "<br /><br /><a href='http://www.gov.bc.ca/com/copyright.html' target='_blank'>COPYRIGHT</a> | <a href='http://www.gov.bc.ca/com/disclaimer.html' target='_blank'>DISCLAIMER</a> | <a href='http://www.gov.bc.ca/com/privacy.html' target='_blank'>PRIVACY</a> | <a href='http://www.gov.bc.ca/com/accessibility.html' target='_blank'>ACCESSIBILITY</a><br><br>" +
							    "</div>");
	printWindow.document.write("</div></body></html>");
	printWindow.document.close();
	}
}



function doPrintHome(objWindow) {
	if (blPrintWindowOpen()) {
		printWindow.focus();//make the preview window bubble to surface
	} else {
	objPrint = new objPrintObjectHome();
	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 + "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='wrap'>");
	printWindow.document.write("<div id='rightcol' style='width:201px; float:right; margin-right:10px;'>");
	printWindow.document.write(objPrint.rightCol);
	printWindow.document.write("</div>");  //rightcol
	//printWindow.document.write("<div id='leftcolumn' style='width:700px;'>");
	printWindow.document.write("<div id='content-home' style='width:540px; float:left; margin-left:10px'>");
	printWindow.document.write(objPrint.centreCol);
	printWindow.document.write("</div>"); //centercol
	//printWindow.document.write(objPrint.news);
	//printWindow.document.write("</div>");  //leftcolumn
	printWindow.document.write("</div>");  //wrap
	printWindow.document.write("</div><div style='clear:both'></div>"); //wrapper
	printWindow.document.write("<div><hr /></div>");
	printWindow.document.write("<div id='footer'>" + objPrint.printButtons +
							   "<br /><br /><a href='http://www.gov.bc.ca/com/copyright.html' target='_blank'>COPYRIGHT</a> | <a href='http://www.gov.bc.ca/com/disclaimer.html' target='_blank'>DISCLAIMER</a> | <a href='http://www.gov.bc.ca/com/privacy.html' target='_blank'>PRIVACY</a> | <a href='http://www.gov.bc.ca/com/accessibility.html' target='_blank'>ACCESSIBILITY</a><br><br>" +
							    "</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 objPrintObjectHome() {
	this.header = getHeader();
	this.rightCol = getRightCol();
	this.centreCol = getCentreCol();
	//this.news = getNews();
	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;
}

function sf(){document.seek1.qt.focus();}

function checkrequired(which) {
 var pass = true;
 if (document.images) {
  for (i=0; i<which.length; i++) {
   var tempobj = which.elements[i];
   if (tempobj.name.substring(0, 2) == "qt") {
    if (((tempobj.type == "text" || tempobj.type == "textarea") && tempobj.value == '') || (tempobj.type.toString().charAt(0) == "s" && tempobj.selectedIndex == 0)) {
     pass = false;
     break;
    }
   }
  }
 }
 if (!pass) {
  
  alert("We cannot provide search results as expected. Please type one or more search words into the text box then select -Search-. ");
  return false;
 } else {
  return true;
 }
}

function checkChoice(field, i) {
if (i == 0) { // "All" checkbox selected.
if (field[0].checked == true) {
for (i = 1; i < field.length; i++)
field[i].checked = false;
}
}
else { // A checkbox other than "Any" selected.
if (field[i].checked == true) {
field[0].checked = false;
}
}
}