function clearMe(thefield){
	if (thefield.defaultValue==thefield.value) {
		thefield.value = "";
	}
} 

function pop(ShowPage, intwidth, intheight) {

	var leftpos = (screen.width - intwidth) / 2;
	var toppos = (screen.height - intheight) / 2;
	var winprops = 'toolbar=0, scrollbars=1, location=0, statusbars=0, menubar=0, width=' + intwidth + ', height=' + intheight + ', left=' + leftpos + ', top=' + toppos + ', resizable=1';
    var popupwindow = window.open(ShowPage, 'poppage', winprops);

}

function in_array(stringToSearch, arrayToSearch) {
	for (s = 0; s < arrayToSearch.length; s++) {
		thisEntry = arrayToSearch[s].toString();
		if (thisEntry == stringToSearch) {
			return true;
		}
	}
	return false;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function addEvent(elm, evType, fn, useCapture) {
	// cross-browser event handling for IE5+, NS6 and Mozilla 
	// By Scott Andrew 
	if (elm.addEventListener) { 
		elm.addEventListener(evType, fn, useCapture); 
		return true; 
	} else if (elm.attachEvent) { 
		var r = elm.attachEvent('on' + evType, fn); 
		return r; 
	} else {
		elm['on' + evType] = fn;
	}
}

function findTarget(e) {
	// cross-browser function to find the event target
	var target;
	if (window.event && window.event.srcElement) {
		// IE does it differently... stores the event in a window.event object
		target = window.event.srcElement;
	}
	if (e && e.target) {
		target = e.target;
	}
	return target;
}

function changeSelect(selectID, paramName) {
	if (document.getElementById(selectID)) {
		var paramValue = document.getElementById(selectID).value;
		document.location.href = '?' + paramName + '=' + paramValue;
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function cancelClick(e) {
	if (window.event){
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		return;
	}
	if (e){
		e.stopPropagation();
		e.preventDefault();
	}
}

// This travels up from the given node until it finds a parent
// who has the given class name.
function getParentNodeWithClassName( objNode, strClassName ){
	// Lowercase the class name for comparison.
	strClassName = strClassName.toLowerCase();
	
	// Crawl up the parent node chain. Keep crawling until we find the 
	// node with the proper class name, we hit a null node, or we hit 
	// a non-text node that has no tag name (the document object).
	for ( 
		objNode = objNode.parentNode ; 
		(
			objNode && (			
				(objNode.tagName && (objNode.className.toLowerCase() != strClassName)) ||
				(!objNode.tagName && (objNode.nodeType != 3)) 
			)
		);
		objNode = objNode.parentNode
		){
		// Nothing has to be done within in the FOR loop. We are purely
		// using the FOR loop to crawl up the DOM structure.
	}

	// Return the node. At this point, it might contains a valid
	// parent node, or it might be null.
	return( objNode );
}


// This is our testing method.
function findParent( objNode, strClassName ){
	var objParent = getParentNodeWithClassName( objNode, strClassName );

	/*
	// Check to see if we found the parent.
	if (objParent != null){
		alert( "Found: " + objParent.tagName + " with Class '" + objParent.className + "'" );
	} else {
		alert( "No parent with the class name " + strClassName + " was found." );
	}
	*/
	if (objParent != null) { return objParent; }

}
