/* Generic Cookie Code */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


//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=\"/\"><img id=\"logo\" src=\"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=\"images/buttons/printClose.gif\" id=\"printClose\" width=\"108\" height=\"28\" alt=\"Print and close\"></a>" +
			"<a href=\"javascript:window.self.close();\">" + 
			"<img src=\"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 \"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;
}