// This script uses the JQuery lib - see http://jquery.com/ for more info. 
// JQuery must already be included for this to run properly.

// This is a utility to send the original URL visited and the Referer URL from the HTTP 
// header to our server (this will be run client side) so that the values can be stored 
// in the HTTP session.

$(document).ready(
	function() {
		// See ticket:2341 "Download/SetupUserSettings: Need to track initial referrer URL 
	    // and our sites complete initial visit URL (including any advertising campaign tracking parameter) per user"
		// Send the refer and original URLs to the server - This is done by requesting a jsp page whose only utility is to store the urls. 
		// Done this way (hack)as opposed to using ParameterAndHeaderHelper.java because JForum uses Freemarker with this template to generate 
		// an HTML page and doesn't speak Java. There may be a way to connect Freemarket and our POJOs by editing the JForum code - something to look into. 
		
		// Note that this script sends empty strings on purpose if the values are missing. If there is no referer, we want to put "" in the database, rather than a spurious referer. 
		var ourl = ( document.URL != null ? document.URL : "" );
		var oref = ( document.referrer != null ? document.referrer : "" );
		
		// Send an HTTP GET request for the page to store the URLs.  
		$.get("/download/jsputilities/addOriginalReferURLToSession.jsp",{ "x-bw-ourl": ourl, "x-bw-oref": oref }, 
			function(data){
				$("#mike").html( data );
			}
		);
    }
);