
function SetupGenPopInfo( el )
{
	var info = new PopupInfo;
	info.position = 'bottom-right';
	info.origin = 'element';
	info.offset = [el.offsetWidth,0];
	info.opacity = 85;
	info.showDelay = 100;
	info.hideDelay = 250;
	info.fadeInDuration = 0;
	info.fadeOutDuration = 300;
	return( info );
}

/*
 * el - the href (or other element) containing the href
 * evt - the event associated, (ie OnClick)
 * oPopUp - the popup object to use (new Popup( "", 'bubble'), best use a global)
 * sURL optional url, uses el.href if not defined
 */
function GenericPopup( el, evt, oPopUp, sURL, iHideDelay )
{
	var info = SetupGenPopInfo( el );
	info.src = ( sURL ? sURL : el.href );
	info.opacity = 100;
	info.keepInView = true;
	if( iHideDelay != null )
		info.hideDelay = iHideDelay;
	oPopUp.create(el, evt, info);
	return( false ); // return this for ease of plugging in
}

function GenericInlinePopup( el, evt, oPopUp, sHtmlId, iHideDelay )
{
	var info = SetupGenPopInfo( el );
	info.html = document.getElementById( sHtmlId ).innerHTML;
	info.opacity = 100;
	info.keepInView = true;
	if( iHideDelay != null )
		info.hideDelay = iHideDelay;
	oPopUp.create(el, evt, info);
	return( false ); // return this for ease of plugging in
}

//
// Generic Form
//

// CheckInput
//
// Selects, clears or inverts multiple checkboxes
//
// name: Name attribute common to group of checkbox elements
// action: 'clear' to clear all
//         'select' to select all
//         'toggle' to toggle current state
function GenFormCheckMulti(name, action)
{
	var options;

	options = document.getElementsByName(name);

	switch (action)
	{
	case 'clear':
		for (var i = 0, count = options.length; i < count; i++)
			options[i].checked = '';
		break;
	case 'select':
		for (var i = 0, count = options.length; i < count; i++)
			options[i].checked = 'checked';
		break;
	case 'toggle':
		for (var i = 0, count = options.length; i < count; i++)
			if (options[i].checked)
				options[i].checked = '';
			else
				options[i].checked = 'checked';
		break;
	}
}


//
// Returns a map containing the name-value pairs of a query string (e.g., "name1=foo&name2=bar" ).
// Note: If the whole url is passed in, the string precedes '?' will be discarded
//
function CreateMapFromQueryString( s )
{
    var cMap = new Object();

	if( s )
	{
		var sStr = s;
		if( sStr.indexOf( '?' ) >= 0 )
		{
			sStr = sStr.split( '?' )[1];
		}

		if( sStr.indexOf( '#' ) >= 0 )
		{
			sStr = sStr.split( '#' )[0];
		}

		var sNVs = sStr.split( '&' );
		for( var u = 0; u < sNVs.length; ++u )
		{
			if( sNVs[u].length == 0 )
			{
				continue;
			}

			var sNV = sNVs[u].split( '=' );
			if( sNV.length == 2 )
			{
				// Insert the name-value pair
				cMap[ sNV[0] ] = decodeURIComponent( sNV[1] );
			}
		}
	}

	return( cMap );
}

//
// Returns a url-encoded query string from a given map object containing name-value pairs.
// Does not include param without value (such as "foo=") when bRemoveEmptyParam is true
//
function CreateQueryStringFromMap( cObj, bRemoveEmptyParam )
{
	var sQS = "";	// URL encoded query string

	for( sName in cObj )
	{
		if( bRemoveEmptyParam && cObj[sName].length == 0 )
			continue;

		if( sQS.length > 0 )
			sQS += "&";
		sQS += sName + "=" + encodeURIComponent( cObj[sName] );
	}

	return( sQS );
}

function TinyUrl()
{
	var sURL = window.location.href;
	var win = window.open('index.cgi?a=tinyurl&URL=' + encodeURIComponent( sURL ),'TinyUrl','width=750,height=350,top=150,left=150');
	win.focus();
}

// 
// Sets element visibility to the specified value. If no value was passed, will toggle
// visibility between 'block' and 'none'
//
function SetElementDisplay( elemId, value )
{
    if ( document.getElementById( elemId ) == undefined )
		return;
    style = document.getElementById( elemId ).style;
	if( value )
		style.display = value;
	else if ( style.display == "none" )
	{
        style.display = "block";
    }
	else 
	{
        style.display = "none";
    }
}

