var url = "";

// find value of page parameter in query string
var page;

function initPage(){
	if (url.indexOf('page=') == -1) {
		page = 1;
		if (url.indexOf('?') == -1) {
			url += '?page=1';
		} else {
			url += '&page=1';
		}
	} else {
		page = parseInt(url.substring(parseInt(url.indexOf('page=') + 5)));
	}
}

function writePageNumber(pageTot) {
	var pageLink;
	url = document.URL;
	initPage();
	if (pageTot > 1) {
		// write previous link
		if (page == 1) {
			document.write('&lt;&lt;&lt; PREVIOUS ');
		} else {
			pageLink = url.replace('page=' + page, 'page=' + (page - 1));
			document.write('<a href="' + pageLink + '" style="font-weight:bold;">&lt;&lt;&lt; PREVIOUS</a> ');
		}
		// write page links
		var c;
		for (c = 1; c <= pageTot; c++) {
			if (c == page) {
				document.write(' ' + c + ' ');
			} else {
				pageLink = url.replace('page=' + page, 'page=' + c);
				document.write(' <a href="' + pageLink + '" style="font-weight:bold;">' + c + '</a> ');				
			}
		}
		// write next link
		if (page == pageTot) {
			document.write(' NEXT &gt;&gt;&gt;');
		} else {
			//pageLink = url.replace('page=' + page, 'page=' + (page + 1));
			pageLink = url.replace('page=' + page, 'page=' + (page + 1));
			document.write(' <a href="' + pageLink + '" style="font-weight:bold;">NEXT &gt;&gt;&gt;</a>');
		}
	}
}



// Comment: Rob Potton - rob.potton@rci.rogers.com - March 2006 - Canadian Business Online
// Legacy: The function below has been replaced by regular expressions in the file jsp_article.tpl.
function writeArticleSource(source) {
	if (source.indexOf("Canadian Business Online") != -1) {
		document.write(source);
	} else {
		document.write("From the " + source + " issue of Canadian Business magazine");
	}
}

// Handles print window
function printWindow(content) {
	window.open('/shared/print.jsp?content=' + content, 'cbPrintWindow','width=620, height=600, status=1, scrollbars=1');
}

// Handles e-mail window
function emailArticle(content) {
	window.open('/shared/email.jsp?content=' + content, 'cbEmailWindow','width=620, height=500, status=1, scrollbars=1');
}

