///////////////////////////////////////////////////////////////////////////////
//	alterDisplay(tag,value)
//
//	Alters the Display property of the object (div, td, tr)
//
//	null checks before calling the display property
//
///////////////////////////////////////////////////////////////////////////////
	function alterDisplay(tag,value) {
		if(doesElementExist(tag)) {
        	docElement(tag).style.display = value;
		}
	}
	
///////////////////////////////////////////////////////////////////////////////
//	updateHtml(tag,value)
//
//	Alters the layer's HTML contents
//
//	null checks before calling the innerHTML property
//
///////////////////////////////////////////////////////////////////////////////
	function updateHtml(tag,value){
		if(doesElementExist(tag)) {
        	docElement(tag).innerHTML = value;
		}
	}

///////////////////////////////////////////////////////////////////////////////
//	setCookie(name, value, expire)
//
//	Sets cookie values. Expiration date is optional
//
//	null checks expire before setting it
//
//	http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/advtopic.htm#1013101
//
///////////////////////////////////////////////////////////////////////////////
	function setCookie(name, value, expire) {
		document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
	}
	
///////////////////////////////////////////////////////////////////////////////
//	getCookie(Name)
//
//	The following function returns a cookie value, given the name of the cookie
//
//	http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/advtopic.htm#1013101
//
///////////////////////////////////////////////////////////////////////////////
	function getCookie(name) {
		var search = name + "=";
		if (document.cookie.length > 0) { // if there are any cookies
			offset = document.cookie.indexOf(search);
			if (offset != -1) { // if cookie exists
				offset += search.length;
				// set index of beginning of value
				end = document.cookie.indexOf(";", offset);
				// set index of end of cookie value 
				if (end == -1){
					end = document.cookie.length
				}
				return unescape(document.cookie.substring(offset, end))
			}
		}
	}
	
///////////////////////////////////////////////////////////////////////////////
//	wr(txt)
//
//	Shorthand document.write, to decrease bytes transferred on heavy JS pages
//
///////////////////////////////////////////////////////////////////////////////
	function wr(txt){
		document.write(txt);
	}

///////////////////////////////////////////////////////////////////////////////
//	whatIsDisProp(tag)
//
//	This returns the value of style.display for a tag.
//
///////////////////////////////////////////////////////////////////////////////
	function whatIsDisProp(tag) {
		if(doesElementExist(tag)) {
        	return docElement(tag).style.display;
		}
		return "";
	}

///////////////////////////////////////////////////////////////////////////////
//	toogleDisplay(tag, value)
//
//	This toogles between "none" and passed in value for display setting
//
///////////////////////////////////////////////////////////////////////////////
	function toggleDisplay(tag,value) {
		if(doesElementExist(tag)) {
			if(whatIsDisProp(tag) == value) {
				alterDisplay(tag,"none")
			} else {
				alterDisplay(tag,value)
			}
		}
	}

///////////////////////////////////////////////////////////////////////////////
//	doesElementExist(tag)
//
//	Returns boolean - if the object is exist
//
///////////////////////////////////////////////////////////////////////////////
	function doesElementExist(tag) {
		var aElement = docElement(tag);
		if(null != aElement) {
			return true;	//	Element Does Exist
		} else {
			return false;	//	Element Does NOT Exist
		}
	}

///////////////////////////////////////////////////////////////////////////////
//	docElement(tag)
//
//	Returns the object that is passed in
//
///////////////////////////////////////////////////////////////////////////////
	function docElement(tag) {
		var aElement = null;
	 	if (document.all){	//	ie
			aElement = document.all(tag);
		} else if (document.getElementById){	//	NS 6+
			aElement = document.getElementById(tag);
		}
		return aElement;
	}

///////////////////////////////////////////////////////////////////////////////
//	toogleSearchLeftNavDiv(theCount)
//
//	For the SearchLeftNav Div, this changes the text from more to less and vice versa
//	and also toggles the display of the hidden items.
//	Assumes that its a DIV object, so value and tag are constants
//	Add theCount that is passed in to the constants for unique identifier	
//
///////////////////////////////////////////////////////////////////////////////
	function toggleSearchLeftNavDiv(theCount) {
		var value = "block";
		var tag = "moreStuff" + theCount;
		var changeTag = "moreLess" + theCount;
		if(doesElementExist(tag)) {
			if(whatIsDisProp(tag) == value) {
				toggleDisplay(tag,value);
				updateHtml(changeTag,"more..")
			} else {
				toggleDisplay(tag,value);
				updateHtml(changeTag,"less..")
			}
		}
	}

///////////////////////////////////////////////////////////////////////////////
//	jsRedirect(url)
//
//	To use the document.location to replace the URL in the address bar
//	This also removes the URL from the browser history.
//	Developed to solve the "back" button redirect loop.
//
///////////////////////////////////////////////////////////////////////////////
	function jsRedirect(url) {
		document.location.replace(url);
	}

///////////////////////////////////////////////////////////////////////////////
//	printImageToFitForHeight(imageUrl, max_height, extras)
//
//	Takes the height of the image and determines if its greater than the max
//	If so, get its proportions to it shrink it to the height given
//	You can pass in extras such is alt and css styles if you need
//
///////////////////////////////////////////////////////////////////////////////
	function printImageToFitForHeight(imageUrl, maxHeight, extras) {
		var image = new Image();

		image.src = imageUrl;

		var height = image.height;

		if (height <= maxHeight){
	    	wr('<img src="' + image.src + '" border="0" ' + extras + ' />');
	    	return;
	    }

	    if (height > maxHeight) {
	    	var shrinkage;
	    	shrinkage = maxHeight / height;
	    	height = height * shrinkage;
	    }

	    wr('<img src="' + image.src + '" height="' + height + '" border="0" ' + extras + ' />');
	}

///////////////////////////////////////////////////////////////////////////////
//	getQueryStringValue(queryStringName)
//
//	Takes the url, checks to see if the element is there, if so, parse on "="
//	gets the value to the end of url or to the next "&"
//
///////////////////////////////////////////////////////////////////////////////
	function getQueryStringValue(queryStringName) {
		var value = "";
		var qsName = queryStringName + "=";
		var theURL = new String(document.URL);
		var startValue = 0;
		var endValue = 0;

		var remainStr = "";

		//check to see if the queryStringName is in the url
		if (theURL.indexOf(qsName) > -1) {
			startValue = theURL.indexOf(qsName) + qsName.length;
		}

		remainStr = theURL.substring(startValue);

		if(remainStr.indexOf("&") > -1) {
			endValue = remainStr.indexOf("&");
		} else {
			endValue = remainStr.length;
		}

		if(endValue > 0) {
			return remainStr.substring(0,endValue);
		} else {
			return "";
		}
	}