/* source code cookie tracking for Jive/ATG - dependencies - jQuery */

(function($){

	function getURLParameter( parameter ) {
	
		// Start by replacing all slashes in the URL
		parameter = parameter.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]" + parameter + "=([^&#]*)";
	  
		// Create a regex object and parse the URL
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
	  
		// Return the string or an empty string (if none exists)
		if( results == null )
			return "";
		else
			return results[1];
	  
		} // end function getURLParameter()


	function srcCodeCookie() {
		var setCookie = false;
		// Set the expiration time for the COOKIE
		var today = new Date();
		today.setTime( today.getTime() );

		var day14 = 14 * 24 * 60 * 60 * 1000;
	
		var expires = new Date( today.getTime() + ( day14 ) );
	
		if( getURLParameter( 'src' ) != '' ) {
			var setCookie = true,
				cookieValue = getURLParameter( 'src' );
		} else if( getURLParameter( 'source' ) != '' ) {
			var setCookie = true,
				cookieValue = getURLParameter( 'source' );
		};
		
		if( setCookie == true ) {
		document.cookie = 'SourceCode' + "=" + escape(cookieValue) + ';' +
			'expires=' + expires.toGMTString() + ';' +
			'path=/';
		};
		
		return 0;
	}
	
	srcCodeCookie();
	
})(jQuery)

