// Helper function: get elements by their class name
function getElementsByClass(c,parentNode) {
	var ns = new Array();
	if (typeof parentNode == "undefined") {
		ns = document.getElementsByTagName("*");
	} else {
		ns = parentNode.getElementsByTagName("*");
	}
	var nsToReturn = new Array();

	// Loop over all elements, push onto return array if they match
	// classname with word boundaries
	for(i = 0; i < ns.length; i++) {
		if ( ns[i].className.match(RegExp("\\b" + c + "\\b")) ) {
			nsToReturn.push(ns[i]);
		}
	}
	return nsToReturn;
}

// Helper function: get first element from a list assembled by class
function getFirstElementByClass(c) {
	var nsElems = getElementsByClass(c);
	if (nsElems.length == 0) {
		return;
	}
	return nsElems[0];
}

// Helper function: clear a select's options and add new ones from a semicolon-delimited
// list of 'value;text;value;text;value;text'...
// Select should have a single option already in it,
// carrying the default value in its @value.
function addOptionsFromList(nSel,listOptions) {

	var default_option = '';
	// Should have a single option in the select, containing the default
	if (nSel.options.length > 0) {
		default_option = nSel.options[0].value;
	}
	// Clear select
	nSel.options.length = 0;

	// Split up list into val/txt pairs
	// Put val into @value and txt into the option text
	var vals_txts = listOptions.split(/;/);
	for(;vals_txts.length > 0;) {
		// Create option
		var val = vals_txts.shift();
		var txt = vals_txts.shift();
		nOption = new Option(txt,val,(default_option==val),(default_option==val));

		nSel.options[nSel.options.length] = nOption;
	}
}

function isUndefinedOrNull(obj) {
	if (typeof obj == 'undefined') {
		return true;
	}
	if (obj == null) {
		return true;
	}
	return false;
}

function makeQueryStringFromDDChildren(nDL) {
	var qsChilds = '';

	nsDTs = nDL.getElementsByTagName("dt");
	nsDDs = nDL.getElementsByTagName("dd");

	for(var i=0 ;i < nsDTs.length ; i++) {
		qsChilds = '&' + qsChilds + encodeURIComponent(nsDTs[i].innerHTML) + '=' + encodeURIComponent(nsDDs[i].innerHTML);
	}
	return qsChilds;
}
