/*------------------------------------------------------------------------------

GLOBAL $Revision: 1.1 $
Copyright 2006 Adobe Systems Incorporated

------------------------------------------------------------------------------*/


/*------------------------------------------------------------------------------	

Function: getSearchQuery
Get a window search parameter or a hash of all parameters

Parameters:
id(optional) - string

Returned Value:
String or Hash

------------------------------------------------------------------------------*/
var getSearchParams = (function() {
	var _loadedParams = null;
	return function(id) {
		var params = _loadedParams || (_loadedParams = window.location.search.toQueryParams());
		return (id) ? params[id] : params;
	}
})();

/*------------------------------------------------------------------------------	

Function: Open Window
Simple Popup Window

Parameters:
uri - string
width - number (of pixels)
height - number (of pixels)
options - string
name - string

------------------------------------------------------------------------------*/
function OpenWindow( url, width, height, opt , name ) {
	window.open( url, (name || "OutsideWindow"), "width="+(width || 714)+",height="+(height || 536)+","+(opt ||  "scrollbars=yes,menubar=yes,toolbar=yes,location=yes,status=yes,resizable=yes")).focus();
}

/*------------------------------------------------------------------------------	

Function: Select Form Action
Simple processing of form dropdown options

Parameters:
formID - ID of form to be processed
dropdownID - ID of <select> tag to be processed

------------------------------------------------------------------------------*/
function selectFormAction (formID,dropdownID) { 
	var selectedLink = document[formID][dropdownID].options[document[formID][dropdownID].selectedIndex].value;
	if (selectedLink != '#') {
		window.location=document[formID][dropdownID].options[document[formID][dropdownID].selectedIndex].value;
	} else if (selectedLink == '#') {
		document[formID][dropdownID].selectedIndex = 0;
	}
}

/*------------------------------------------------------------------------------

Class: OneShotEventRegister
Abstract FIFO event register that expires after a single event. Allows subsequent calls to be optionally executed or passed to an overflow method.

Parameters:
element - element reference
eventname - string
overflow(optional) - boolean
overflower(optional) - function

Returned Value:
Object

------------------------------------------------------------------------------*/

var OneShotEventRegister = Class.create({
	initialize: function(element, eventname, overflow, overflower) {
		this.expired = false;
		this.queue = [];
		this.overflow = !!overflow;
		this.overflower = overflower;
		Event.observe(element, eventname, this.expire.bindAsEventListener(this));
	},
/*------------------------------------------------------------------------------

	Method: expire
	Execute and remove all queued functions
	
	Returned Value:
	None
	
------------------------------------------------------------------------------*/
	expire: function() {
		var i;
		while(i=this.queue.shift()) {
			i();
		}
		this.expired = true;
	},
/*------------------------------------------------------------------------------

	Method: register
	Add function to queue or if overflow enabled pass thru function
	
	Returned Value:
	Boolean
	
------------------------------------------------------------------------------*/
	register: function(func) {
		if(!this.expired) {
			this.queue.push(func);
		} else if(this.overflower) {
			this.overflower(func)
		} else if(this.overflow) {
			func();
		} else {
			return false;
		}
		return true;
	}
});

/*------------------------------------------------------------------------------

Function: registerOnLoad
Execute a specified callback when the root document is loaded.

Parameters:
func - function object reference

Returned Value:
None

------------------------------------------------------------------------------*/
var registerOnLoadFunc = (
registerOnLoad = (function() {
	var _exec = new OneShotEventRegister(window, "load", true);
	return function(func) { 
		_exec.register(func); 
	}
})());


/*------------------------------------------------------------------------------

Function: registerOnReady
Execute a specified callback when the root document is ready.

Parameters:
func - function object reference

Returned Value:
None

------------------------------------------------------------------------------*/

var registerOnReady = (function() {
	var _exec = new OneShotEventRegister(document, "dom:loaded", true, registerOnLoad);
	return function(func) {
		_exec.register(func);
	}
})();
