//------------------------------------------------
// Bluestar BasketBall Javascript Library
//------------------------------------------------
/**
 * Custom namespace creation function
 */
function namespace() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; i=i+1) {
        d=a[i].split(".");
        o=window;
        for (j=0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }
    return o;
};

/**
 * Bluestar base class
 * @class BS
 */
var BS = function() {
	
	// Public Methods
	return {
		/*
		Changes value of an element or array of elements specified by ID
		@method: fillSelect
		@param: {Array: elemId} element Id
		@param: {Array: optionArray} array of values to fill option elements with
		@param: {String | Int: curValue} option value to make current selection
		@return: {NULL}
		*/
		fillSelect: function(elemId, optionArray, curValue) {
			// get reference to dropdown
			var selectElem = document.getElementById(elemId);
			
			// clear dropdown
			selectElem.options.length = 0;
			
			// add [select] dropdown
			selectElem.options.add(new Option("[Make a Selection]", ""));
			
			// iterate through school array
			for (var i in optionArray) {
				if (optionArray[i]) {
					// check if current value is equal to selected value
					if (curValue == i) {
						selectElem.options.add(new Option(optionArray[i], i, false, true));
					} else {
						selectElem.options.add(new Option(optionArray[i], i));
					}
					
				}
			}
		}, // end function fillSelect
		/*
		Changes value of an element or array of elements specified by ID
		@method: submitFormValues
		@param: {Array: elemIds} element id
		@param: {Array: arr1} array of  id to change and value to fill
		@param: {Array: arr2} array of  id to change and value to fill
		@return: {NULL}
		*/
		submitFormValues: function(elemId, arr1, arr2) {
			// get reference to form element
			var formElement = document.getElementById(elemId);
			
			// iterate through first array of values
			for (var i in arr1)  {
				// get reference to element
				firstElem = document.getElementById(i);
				
				// set value of element
				firstElem.value = arr1[i];
			}
			
			// iterate through second array of values
			for (var j in arr2)  {
				// get reference to element
				secondElem = document.getElementById(j);
				
				// set value of element
				secondElem.value = arr2[j];
			}
			
			//submit form
			formElement.submit();
			
		} // end function submitFormValues
	}; // end of return call
}();

/**
 * Bluestar Ajax class
 * @class BS.Ajax
 */
namespace("BS");
BS.Ajax = function() {
	// Public Methods
	return {
		/*
		Get an <option> tag list of data from database
		@method: getOptionList
		@param: {String: sUrl} url to get progress information from
		@param: {String: progressId} unique id of progress tracking key
		@param: {String: updateInterval} interval in
		@return: {NULL}
		*/
		getOptionList: function(sUrl, progressId, updateInterval, sumElemId, frameId, sRedirUrl) {
			// create modal progress container
			var pContainer = EW.popBoxDownload('400px', '125px');
			
			// get reference to progress bar
			var pBar = document.getElementById("progressinner");
			
			// create progress bar object
			var objPB = new EW.Ajax.ProgressBar(sUrl+'?rmode=ajax&progress_key='+progressId, updateInterval, pBar, pContainer);
			
			// set progress summary element
			objPB.setSummaryElem(document.getElementById(sumElemId));
			
			// set frame that is posted to 
			objPB.setSummaryFrame(document.getElementById(frameId));	
			
			// set redirection url
			objPB.setRedirUrl(sRedirUrl);	
			
			// begin progress bar updating in one second
			setTimeout(objPB.getProgress(), 250);
			
		} // end function startProgress	
	}; // end of return call
}();
