function showHideDefaultInputText(input, defaultText, isFocused) {
	if (isFocused && (input.value == defaultText)) {
		input.value = "";
	} else if ((!isFocused) && (input.value == "")) {
		input.value = defaultText;
	}
	
	return true;
}

function loadWeather(url, loadingImg) {
	$('#weatherResultDiv').html('<div class="weatherLoaderImageHolder"><img alt="" src="' + loadingImg + '" /></div>');
	$.ajax({
		url: url,
		success: function(data) {
			$('#weatherResultDiv').html(data);
			return true;
		},
		error: function(data) {
			$('#weatherResultDiv').html("N/A");
			return false;
		}
	});
}

function clickTreeElement(element, writeInto, elementId)
{
	$($($('#treeUOCategories').children('ul')[0]).children('li')).children("a").removeClass('markedTreeEntry');
	$($($($($('#treeUOCategories').children('ul')[0]).children('li')).children("ul")).children('li')).children('a').removeClass('markedTreeEntry');

	element.addClass("markedTreeEntry");

	writeInto.val(elementId);
	
	return false;
}

function openActiveTreeNode()
{
	$($($('#treeUOCategories').children('ul')[0]).children('li')).each(function(index) {
		if (($(this).children("a").hasClass('markedTreeEntry'))) {
			//checking for a selected parent element
			$('#treeUOCategories').jstree("open_node", $(this), null, true);
			
		} else {
			//checking for a selected child element
			$($($(this).children("ul")).children('li')).each(function(index) {
				if (($(this).children("a").hasClass('markedTreeEntry'))) {
					$('#treeUOCategories').jstree("open_node", $($(this).parent()).parent(), null, true);
				}
			});
		}
	});
}

function noexit(){
	exit = false;
	return;
}


function bookmark(url, description)
{
	netscape="First push OK and then hit CTRL+D to add a bookmark to this site."

	if (navigator.appName=='Microsoft Internet Explorer')
	{
		window.external.AddFavorite(url, description);
	}
	else if (navigator.appName=='Netscape')
	{
		alert(netscape);
	}
}

/**
 * Replaces the iframe with another one, so the results are cleared.
 * 
 * @return void
 */
function resetTsmIframe()
{
	$('#tsmIFrameHolder').html('<iframe id="tsmIFrame" width="100%;" height="1200" scrolling="no" align="top" frameborder="0" marginwidth="0" marginheight="0" name="tsmIFrame" style="display:none;"></iframe>');
}

/**
 * Performs a route search and displays the results in the Google map
 */
function calcRoute() {
	var start = $('#mapRouteStartAddress').val();
	var end = $('#mapRouteEndAddress').val();
	
	var request = {
		origin:start, 
		destination:end,
		travelMode: google.maps.DirectionsTravelMode.DRIVING
	};
	
	directionsService.route(request, function(result, status) {
		if (status == google.maps.DirectionsStatus.OK) {
			directionsDisplay.setDirections(result);
		} else if (google.maps.DirectionsStatus.NOT_FOUND) {
			alert("One of the locations specified in the requests's origin, destination, or waypoints could not be geocoded.");
		} else if (google.maps.DirectionsStatus.ZERO_RESULTS) {
			alert("No route could be found between the origin and destination.");
		} else if (google.maps.DirectionsStatus.MAX_WAYPOINTS_EXCEEDED) {
			alert("Too many DirectionsWaypoints were provided in the DirectionsRequest.");
		} else if (google.maps.DirectionsStatus.OVER_QUERY_LIMIT) {
			alert("Webpage has sent too many requests within the allowed time period.");
		} else if (google.maps.DirectionsStatus.INVALID_REQUEST) {
			alert("The provided DirectionsRequest was invalid.");
		} else if (google.maps.DirectionsStatus.REQUEST_DENIED) {
			alert("Webpage is not allowed to use the directions service.");
		} else if (google.maps.DirectionsStatus.UNKNOWN_ERROR) {
			alert("Directions request could not be processed due to a server error. The request may succeed if you try again.");
		} else {
			alert("Directions request could not be processed due to a server error. The request may succeed if you try again.");
		}
	});
}

function sFs(isSubmit) {
	if (isSubmit) {
		document.getElementById('contentwrap').style.display = "none";
		document.getElementById('right').style.display = "none";
		document.getElementById('qsf-results').style.display = "block";
		document.getElementById('tsmIFrame').style.display = "block";
		
	} else {
		document.getElementById('contentwrap').style.display = "block";
		document.getElementById('right').style.display = "block";
		document.getElementById('qsf-results').style.display = "none";
		document.getElementById('tsmIFrame').style.display = "none";

		//clear the cached results
		resetTsmIframe();
	}
	
	return isSubmit;
}

/**
 * shows the text field or the select field for the name of the searched item,
 * found in the Map-Search form.
 * 
 * @param bool isGeographic
 * @return bool
 */
function changeMapSearchType(isGeographic) {
	if (isGeographic) {
		$("#name-label").hide();
		$("#name-element").hide();
		$("#name_geographic-label").show();
		$("#name_geographic-element").show();
	} else {
		$("#name-label").show();
		$("#name-element").show();
		$("#name_geographic-label").hide();
		$("#name_geographic-element").hide();
	}
	
	return true;
}

function mapSearchTypeRadioChanged(value) {
	if (value == 2) {
		return changeMapSearchType(true);
	} else {
		return changeMapSearchType(false);
	}
}

/**
 * Dynamic Version by: Nannette Thacker
 * Original by: Ronnie T. Moore
 * Web Site: The JavaScript Source
 * Use one function for multiple text areas on a page
 * Limit the number of characters per textarea
 */
function textCounter(field, cntfield, maxlimit) {
	if (field.value.length > maxlimit) { // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	} else {
		// otherwise, update 'characters left' counter
		cntfield.value = maxlimit - field.value.length;
	}
}
