// JavaScript Document

function highlightTopMenu(menuID) {			
	menu = document.getElementById(menuID);
	
	if (menu != null && menu != "null") {
		menu.className = menuID + " selected";
	}
}

function highlightSideMenu(menuID) {
	menu = document.getElementById(menuID);

	if (menu != null && menu != "null") {
		menu.className = menuID + " selected";
	}
}

function onImageError(img, newSrc) {
	img.src = newSrc;
	img.onerror = "";
	return true;
}

//This function is used for forms that send to email addresses to format linebreaks as html breaks.
function formatTextAreaValue (textarea) {
	return textarea.value.replace(/\n/g, '<br />');
}

function getURLParameter(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

function addListener(element, type, expression, bubbling)
{
	bubbling = bubbling || false;
	
	if(window.addEventListener) { // Standard
		element.addEventListener(type, expression, bubbling);
		return true;		
	} else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} else return false;
}

function appendSearchTerms(frm) {
	frm.action = frm.action + '&searchterms=' + frm.CAT_Search.value;
	return true;
}