    /* Shows a hidden div. For some reason, anchor tags don't like this in the tag and require to have a separate
     * JavaScript function.
     *
     * 'divName' is the html tag ID of the div.
     */
    function showDiv(divName) {
        document.getElementById(divName).style.visibility='visible';
        document.getElementById(divName).style.display='';
    }

    /* Hides the div */
    function hideDiv(divName) {
        document.getElementById(divName).style.visibility='collapsed';
        document.getElementById(divName).style.display='none';
    }

    /*
     * Includes a Google map in the page:
     * divName - the name of the div that will containt the map
     * address - the address that should be resolved
     * label   - The text to display to the user as the address. Sometimes the whole address takes up too much space
     *           or has text that helps humans and would confuse the Google geolocation service.
     * index   - a unique number to help differentiate multiple maps on the same page.
     */
    function embedMap(divName, address, label, index) {
        if (GBrowserIsCompatible()) {
            // attempt to find address
            var geocoder = new GClientGeocoder();
            geocoder.getLatLng(address,
                function(point) {
                    if (!point) {
                        hideDiv(divName);
                    } else {
                        showDiv(divName);

                        // show initial map
                        var map = new GMap2(document.getElementById(divName));
                        map.addControl(new GSmallMapControl());
                        map.addControl(new GMapTypeControl());

                        map.setCenter(point, 13);
                        var marker = new GMarker(point);
                        map.addOverlay(marker);
                        marker.openInfoWindowHtml(label);
                        marker.bindInfoWindowHtml(label);
                    }
                }
            );
        }
    }

/**
 * Add trim functions to strings.
 */
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

/**
 * Found JavaScript for inserting text at the cursor in a textarea
 */
function insertAtCursor(formField, text) {
    if (document.selection) {
        //IE support
        formField.focus();

        //in effect we are creating a text range with zero
        //length at the cursor location and replacing it
        //with myValue
        sel = document.selection.createRange();
        sel.text = text;
        }
    else if (formField.selectionStart || formField.selectionStart == '0') {
        //Mozilla/Firefox/Netscape 7+ support

        //Here we get the start and end points of the
        //selection. Then we create substrings up to the
        //start of the selection and from the end point
        //of the selection to the end of the field value.
        //Then we concatenate the first substring, myValue,
        //and the second substring to get the new value.
        var startPos = formField.selectionStart;
        var endPos = formField.selectionEnd;
            formField.value = formField.value.substring(0, startPos)+ text+ formField.value.substring(endPos, formField.value.length);
    } else {
        formField.value += text;
    }
}


/**
 * Finds the current selection in the specified text area 'formField'. If there is text selected, it inserts
 * 'beforeText' before the selectioon and 'afterText' after the selection. If there is no text selected, it will
 * insert 'insertionText' at the cursor.
 */
function insertAroundSelection(formField, beforeText, afterText, insertionText) {
    if (document.selection) {
        //IE support
        formField.focus();

        sel = document.selection.createRange();
        selectedText = sel.text;
        if (!selectedText) {
            sel.text = insertionText;
        } else {
            sel.text = beforeText + selectedText + afterText;
        }
    } else if (formField.selectionStart || formField.selectionStart == '0') {
        //Mozilla/Firefox/Netscape 7+ support

        //Here we get the start and end points of the
        //selection. Then we create substrings up to the
        //start of the selection and from the end point
        //of the selection to the end of the field value.
        //Then we concatenate the first substring, myValue,
        //and the second substring to get the new value.
        var startPos = formField.selectionStart;
        var endPos = formField.selectionEnd;
        var selectedText = formField.value.substring(startPos, endPos);
        if (!selectedText) {
            // no text selected
            formField.value = formField.value.substring(0, startPos)+ insertionText+ formField.value.substring(endPos, formField.value.length);
        } else {
            formField.value = formField.value.substring(0, startPos)+ beforeText + selectedText + afterText+ formField.value.substring(endPos, formField.value.length);
        }

    } else {
        formField.value += text;
    }
}

/*
 * Found JavaScript to parse the QueryString
 */

/* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get

	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &

// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name

		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;

	var value=this.params[key]
	if (value==null) value=default_;

	return value
}


