/* theme.js 
 * - A toolkit of essential javascript functions used by theme
 * by Helene D. 1/31/2007
 * ----------------------------------------------------------- */

/* ### getElem()
 * Return a document element object. 
 * This is the prototype dollar $() function renamed
 */
function getElem() {
 	var elements = new Array();
 	for (var i = 0; i < arguments.length; i++) {
 		var element = arguments[i];
 		if (typeof element == 'string')
 			element = document.getElementById(element);
 		if (arguments.length == 1)
 			return element;
 		elements.push(element);
 	}
 	return elements;
}

/* ### getQueryParam(param_name)
 * retrieve a parameter value from url querystring...
 */
function getQueryParam( paramname, hrefstring ) {
	paramname = paramname.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	if ( hrefstring == '') hrefstring = window.location.href;
	var regexS = "[\\?&]"+mapname+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( hrefstring );
	if( results == null )
		return "";
	else
		return results[1];
}

/* ### toggleDisplay(div_id, disp_type) 
 * Toggle the display style of a division element:
 *   If element has display=='none' or has width==0, set to disp_type 
 *   or 'inline'. If display=='' set to 'none';
 */
function toggleDisplay(div_id, disp_type){
 	if(!disp_type) {
 		disp_type = 'inline';
 	}
 	var obj = getElem(div_id);
 	// If object was originally display:none in the CSS, it will show 
 	// the first time as just display=='', but the width will be 0.
 	if((obj.style.display == 'none') || ((obj.style.display=='') && (obj.offsetWidth==0))){
 		obj.style.display = disp_type;
 	} else {
 		obj.style.display = 'none';
 	}
}
