/*
Geocaching Show All Logs - v1.1 2005-12-09
(c) 2005, Prime Suspect Software

Greasemonkey user script: see http://greasemonkey.mozdev.org

Compatible with Greasemonkey 0.6.4.

Automatically reloads cache pages to show all logs.

Revision History:

v1.0 - Initial release

v1.1 - Change so that reloading the page does not insert an extra
  entry in the browser's back-button history.

*/

// ==UserScript==
// @name		GC Show All Logs
// @filename		gcshowalllogs.user.js
// @description		Automatically Shows All Logs v1.1
// @namespace       	http://gmscripts.locusprime.net
// @include         	http://www.geocaching.com/seek/cache_details.aspx*
// ==/UserScript==

(function() {
	
	// Exit if printer friendly mode.
	var printFriendly = UrlParm('pf');
	if (printFriendly == 'y') {return}

	// Exit if already displaying all logs.
	var logVal = UrlParm('log');
	if (logVal == 'y') {return}
	
	// Get current URL.
	var DocUrl = document.location + '';

	// Remove any existing log parms.
	while (DocUrl.match(/[?|&]log=/)) {
		DocUrl = DocUrl.replace(/(\?|&)log=.*?(&|$)/, '$1')
		DocUrl = DocUrl.replace(/&+$/, '');
	}

	// Add all-logs parm to URL and reload page.
	document.location.replace(DocUrl + '&log=y');


// -------------------- Functions -------------------- //

	
	//  Returns a URL parameter.
	//    ParmName - Parameter name to look for.
	//    IgnoreCase - (optional) *false, true. Ignore parmeter name case.
	//    UrlString - (optional) String to search. If omitted, document URL is used.
	function UrlParm(ParmName, IgnoreCase, UrlString) {
		var RegRslt, sc = '', RtnVal = '';
		if (IgnoreCase) {sc = 'i'}
		if(UrlString) {
			var PageUrl = UrlString;
		} else {
			PageUrl = document.location + '';
		}
		var ParmString = PageUrl.substring(PageUrl.indexOf('?') + 1);
		var RegEx1 = new RegExp('(^|&)' + ParmName + '=(.*?)(&|#|$)', sc);
		RegRslt = RegEx1.exec(ParmString);
		if (RegRslt) {RtnVal = RegRslt[2]}
		return RtnVal;
	}

	
})();

