// file: js/back-to_exhib.js
// author: James Williams, eScholarship Research Centre
// org: The University of Melbourne
// date: 2009-04-01
//
// AWAP Exhibitions JavaScript Referrer Backlink
// ======
// Usage:
// ======
// 
// - Including this javascript will check the referrer to see whether the
//   visitor came from a URL containing /exhib/ and append a "Back to 
//   exhibitions" backlink a element within the first div with id "back-to".
//
// - This file should sit in a top-level /js/ folder of an OHRM web output
//   folder, and be coupled with the $level_ variable in the web template.
//
// - It might be considered important to remove these comments entirely for
//   production websites
//
// LOCATION OF THE REFERRER LINK
// -----------------------------
// Where the backlink should appear, paste the following HTML code:
//
//	   <div id="back-to"></div>
//
//
// LOCATION OF THE JAVASCRIPT HOOK
// -------------------------------
// This *must* come AFTER (below) the above HTML code:
//
//	   <script type="text/javascript" src="$level_js/back-to_exhib.js"></script>
//
// NOTE - $level_ should be replaced by the relative path to the /js/ folder,
//        eg "../" or used (verbatim) as above in an OHRM generation template.
//
// 
// RECOMMENDED
// -----------
// Place the HTML code and the <script/> element together like so:
//
//	   <div id="back-to"></div>
//	   <script type="text/javascript" src="$level_js/back-to_exhib.js"></script>
//
// WHY?
// ----
// Because the JavaScript is so specific to the "back-to" div, and because the
// javascript is so specific to the /exhib/ string being in the referring URL,
// it makes better sense to keep them together on the page unless there is a
// need to genericize the functionality.
//
// It also plays nicer with other scripts, and a lot of other reasons.
//
//
// James Williams, April 1 2009.
//

// check referrer url for "/exhib/" and append an <a> element link back
if (document.referrer.indexOf('/exhib/') != -1)
{
	// prevent error if used incorrectly? check for existence of 'back-to' id?

	// NB: should this really be a javascrript, but remember to consider AJAX
	document.getElementById('back-to').innerHTML = '<a id="back-to_exhib" ' + 
		'href="' + document.referrer + '">Back to exhibition</a>';
}

