/* Blue River Digital API - Component **********************************
 *	
 *	This API contains all the functions needed to use custom components
 *
 *	Component List:
 *		
 *		- Edit Text
 *		- Edit Text Area
 *		- Dropdown List
 *		- Query Table
 *		- Banner Ad
 *		- Image Button
 *
 *********************************************************************/
 
 	var cancelTip 						= true;
 	var currentRowClassSaved 			= "";
	var currentRowSelected 				= "";
	var currentRowSelectedClassSaved 	= "";
	var oldComponentValue 				= "";
	var onLoadQuery				 		= false;
	var disableQueryRowClickAction 		= false;
	var activePageTab					= null;
	var cancelTabActivation				= false;
	var formDataQueryString				= "";
	
	addLoadEvent(initializeComponents);
	
 	
/*  Initialize Components * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function initializeComponents()
	{
	    // Initialize Page Tabs Container ******************
		if (getElementsByComponent("pageTabsContainer").length > 0)
		{
			setPageTabsContainerComponentMembers();
		}
		
		// Initialize Edit Text *****************
		if (getElementsByComponent("editText").length > 0)
		{
			addEditTextComponentMembers();
			setComponentEditTextActions();
		}
		
		// Initialize Edit Text Area *****************
		if (getElementsByComponent("editTextArea").length > 0)
		{
			addEditTextAreaComponentMembers();
			setComponentEditTextAreaActions();
		}
		
		// Initialize Dropdown List *****************
		if (getElementsByComponent("dropdownList").length > 0)
		{
			addDropdownListComponentMembers();
			setComponentDropdownListActions();
		}
		
		// Initialize Banner Ads *********************
		if (getElementsByComponent("bannerAd").length > 0)
		{
			addBannerAdComponentMembers();
			setComponentBannerAdActions();
		}
		
		// Initialize Image Buttons ******************
		if (getElementsByComponent("imageButton").length > 0)
		{
			addImageButtonComponentMembers();
			setComponentImageButtonActions();		
		}
		
		// Initialize Question Icon Popups ******************
		if (getElementsByComponent("questionIconPopup").length > 0)
		{
			addQuestionIconPopupComponentMembers();
			setComponentQuestionIconPopupActions();		
		}
		
		// Initialize Query Tables ******************
		if (getElementsByComponent("queryTable").length > 0)
		{
			getComponentQueryTables();
		}
		
		// Initialize Radio List ******************
		if (getElementsByComponent("radioList").length > 0)
		{
			addFormListComponentMembers("radioList");
		}
		
		// Initialize Checkbox List ******************
		if (getElementsByComponent("checkboxList").length > 0)
		{
		   	addFormListComponentMembers("checkboxList");
		}
	}
	
	
/* ************************************************************************************************************ 
 * 
 * 		Common Component Functions - Used by All                          
 *
 **************************************************************************************************************/


/*  Get Elements By Component * *******************************************************
 *
 *	TAKES:		Component Name
 * 	RETURNS:	Array of elements that have the custom component attribute specified
 *
 *************************************************************************/
 
 	function getElementsByComponent(componentName)
	{
		var componentElements 	= getElementsByAttribute("component");	
		var componentElement	= "";
		var thisComponent		= "";
		var componentArray 		= new Array();
		
		if (componentName != "")
		{
			if (componentElements.length > 0)
			{
				for(var ctr=0; ctr<componentElements.length; ctr++)
				{
					componentElement = componentElements[ctr];
					thisComponent = componentElement.getAttributeNode("component").value;
					
					if (thisComponent == componentName)
					{
						if (componentArray.length > 0)
						{
							componentArray = componentArray.concat(new Array(componentElement));
						}
						else
						{
							componentArray = new Array(componentElement);
						}
					}
				}		
			}
		}
		
		return componentArray;
		
	}

/*  Get Component Attribute Value * *******************************************************
 *
 *	TAKES:		Component Element, Component Attribute
 * 	RETURNS:	Component Attribute Value
 *
 *************************************************************************/
 
 	function getComponentAttributeValue(componentElement, componentAttribute)
	{
		var attributeValue = "";
		var attributeElement = ""
		
		if (componentElement)
		{
			attributeElement = componentElement.getAttributeNode(componentAttribute);
			
			if (attributeElement)
			{
				attributeValue = attributeElement.value;
			}
		}
		
		return attributeValue;
	}
	
/*  Set Component Attribute Value * *******************************************************
 *
 *	TAKES:		Component Element, Component Attribute, Attribute Value
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function setComponentAttributeValue(componentElement, componentAttribute, attributeValue)
	{
		var attributeElement = ""
		
		if (componentElement)
		{
			attributeElement = componentElement.getAttributeNode(componentAttribute);
			
			if (attributeElement)
			{
				attributeElement.value = attributeValue;
			}
			else
			{
				// Create New Attribute ******************
				var newAttr = document.createAttribute(componentAttribute);
				newAttr.nodeValue = attributeValue;
				
				componentElement.setAttributeNode(newAttr);
			}
		}
		
	}

/*  Is Component * *******************************************************
 *
 *	TAKES:		Element
 * 	RETURNS:	True if the Element is a Component, False if the Element
 *				is not a Component.
 *
 *************************************************************************/
 
 	function isComponent(element)
	{
		if (getComponentAttributeValue(element, "component") != "")
		{
			return true;	
		}
		else
		{
			return false;
		}
		
	}
	
/* Timed Tool Tip ********************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *	
 ********************************************************************************/
 
 	function timedToolTip()
	{
		if (IE)
		{
			var range = document.selection.createRange();
			
			if ((!cancelTip) & (range.text == ""))
			{
				altTextPopup("Double Click to Edit");
			}
		}
	}
	

/*  Toggle Component ********************************************************
 *
 *	TAKES:		ComponentId, Toggle Action (show|hide)
 * 	RETURNS:	NOTHING
 *	NOTE:		Toggle refers to the Edit Member:
 *					- show:		show --> Edit Member, hide --> Text Member
 *					- hide:		hide --> Edit Member, show --> Text Member
 *
 ********************************************************************************/
 
	function toggleComponent(componentId, toggleAction)
	{
		var componentElement 	= getElement(componentId);
		var componentType		= getComponentAttributeValue(componentElement, "component");
		var textElement 		= getElement("text_" + componentId);
		var editElement 		= getElement(componentType + "_" + componentId);
		
		// Data ************************
		if (toggleAction == "show")
		{
			hideElement(textElement.id);
		}
		else if (toggleAction == "hide")
		{
			showElement(textElement.id);
		}
		
		// Edit ************************
		if (toggleAction == "hide")
		{
		   	hideElement(editElement.id);
		}
		else if (toggleAction == "show")
		{
			showElement(editElement.id);
			setFocus(editElement.id);
		}
	}
	

/*  Get Component List Value Element * *******************************************************
 *
 *	TAKES:		Component Id, Component Value
 * 	RETURNS:	Component Value Element
 *  NOTES:      Only supports "list" components (radioList, dropdownList, checkboxList)
 *
 *************************************************************************/
 
    function getComponentListValueElement(componentElement, componentValue)
    {
        var optionValueElement = null;
        
        if (isComponent(componentElement))
        {
            var componentType = getComponentAttributeValue(componentElement, "component");
            
            switch(componentType)
            {
                case "radioList":
                    
                    
                        var listValueContainerElements = getTagGroup("div", "listValueContainer." + componentElement.id);
                        
                        var iterateAction = function(containerElement, ctr)
                        {
                            var listValueElement = getElement(containerElement.id.replace("listValueContainer.", ""));
                            
                            if (listValueElement.value == componentValue)
                            {
                                optionValueElement = containerElement;
                            }
                        }
                        
                        iterateElementList(listValueContainerElements, iterateAction);
                        
                    break;
                    
                case "checkboxList":
                    
                        var listValueContainerElements = getTagGroup("div", "listValueContainer." + componentElement.id);
                        
                        var iterateAction = function(containerElement, ctr)
                        {
                            var listValueElement = getElement(containerElement.id.replace("listValueContainer.", ""));
                            
                            if (listValueElement.value == componentValue)
                            {
                                optionValueElement = containerElement;
                            }
                        }
                        
                        iterateElementList(listValueContainerElements, iterateAction);
                    
                    break;
                    
                case "dropdownList":
                    
                        var dropdownElement = getElement("dropdownList_" + componentElement.id);
                        
                        var iterateAction = function(optionElement, ctr)
                        {
                            if (optionElement.value == componentValue)
                            {
                                optionValueElement = optionElement;
                            }
                        }
                        
                        iterateElementList(dropdownElement.options, iterateAction);
                    
                    break;
            }
        }
        
        return optionValueElement;
    }
    
 /*  Show Component List Value Element * *******************************************************
 *
 *	TAKES:		Component Id, Component Value
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
    function showComponentListValueElement(componentElement, componentValue)
    {
        var componentValueElement = getComponentListValueElement(componentElement, componentValue);
        
        if (componentValueElement != null)
        {
            componentValueElement.style.display = "block";
        }
    }  

 /*  Hide Component List Value Element * *******************************************************
 *
 *	TAKES:		Component Id, Component Value
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
    function hideComponentListValueElement(componentElement, componentValue)
    {
        var componentValueElement = getComponentListValueElement(componentElement, componentValue);
        
        if (componentValueElement != null)
        {
            
            var tagName = componentValueElement.nodeName;
            
            switch(tagName.toLowerCase())
            {
                case "div": // Radio, Checkbox
                    
                    var inputElementId  = componentValueElement.id.replace("listValueContainer.", "");                     
                    var inputElement    = getElement(inputElementId);
                    
                    inputElement.checked = false;
                    
                    break;
                    
                case "option": // DropdownList
                    
                    setComponentValue(componentElement.id, "");
                    
                    break;
            }
            
            componentValueElement.style.display = "none";
        }
    }  

/*  Set Component Value * *******************************************************
 *
 *	TAKES:		Component Id, Data Value
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function setComponentValue(componentId, dataValue)
	{
		var componentElement = getElement(componentId);
		
		if (componentElement)
		{
			var componentType	= getComponentAttributeValue(componentElement, "component");
			var dataType		= getComponentAttributeValue(componentElement, "dataType");
			var textElement 	= getElement("text_" + componentId);
			var editElement 	= getElement(componentType + "_" + componentId);
			
			// Update Members ***********************
			
				// Text Member **********************
				if ((componentType == "editText") || (componentType == "editTextArea"))
				{
				    if (dataType == "email")
				    {
					    textElement.innerHTML = "<a href=\"mailto:" + dataValue + "\">" + dataValue + "</a>";
				    }
				    else
				    {
					    textElement.innerHTML = dataValue;
				    }
                }
                
                if (textElement)
                {
                    textElement.innerHTML = dataValue;
                }
				
				//showElement(textElement.id);
				
				// Dynamic Content Members *************************
				dataValue = dataValue.replace(/<br>/g, "\n");
				
				switch(componentType)
				{
					case "editText":
						
						editElement.value = dataValue;
						break;
					
					case "dropdownList":
						
						var dropdownSet = false;
						
						for(var listCtr=0; listCtr<editElement.options.length; listCtr++)
						{
							if (editElement.options[listCtr].text == dataValue)
							{
								editElement.selectedIndex = listCtr;
							    dropdownSet = true;
							}
						}
						
						if (!dropdownSet)
						{
						    editElement.selectedIndex = 0;
						}
						
						break;
					
					case"radioList":
					
					    var radioElements = getTagGroup("input", componentId + ".");
					    
					    var iterateAction = function(radioElement, ctr)
                        {
                            if (radioElement.value == dataValue)
                            {
                                radioElement.checked = true;
                            }
                        }
                        
                        iterateElementList(radioElements, iterateAction);
                            
                        break;
                        
                    case"checkboxList":
					
					    var checkboxElements = getTagGroup("input", componentId + ".");
					    
					    var iterateAction = function(checkboxElement, ctr)
                        {
                            if (checkboxElement.value == dataValue)
                            {
                                checkboxElement.checked = true;
                            }
                        }
                        
                        iterateElementList(checkboxElements, iterateAction);
                            
                        break;
						
					default:
					
						editElement.value = dataValue;
						break;
				}
			
		}
	}

/*  Set Component Id * *******************************************************
 *
 *	TAKES:		Component Element, Id Value
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function setComponentId(componentElement, newIdValue)
	{
	    if (isComponent(componentElement))
	    {
	        var componentType = getComponentAttributeValue(componentElement, "component");
	        
	        getElement("text_" + componentElement.id).id = "text_" + newIdValue;
	        getElement("error_" + componentElement.id).id = "error_" + newIdValue;
	        getElement(componentType + "_" + componentElement.id).id = componentType + "_" + newIdValue;
	        
	        componentElement.id = newIdValue;
	    }
	} 
	
/*  Get Component Value * *******************************************************
 *
 *	TAKES:		Component Id
 * 	RETURNS:	Data value of the component
 *
 *************************************************************************/
 
 	function getComponentValue(componentId)
	{
		var componentElement = getElement(componentId);
		
		if (componentElement)
		{
			var componentType	= getComponentAttributeValue(componentElement, "component");
			var textElement 	= getElement("text_" + componentId);
			var editElement 	= getElement(componentType + "_" + componentId);
			
			var componentValue = "";
			
			// Get Data ***********************
			if (getComponentAttributeValue(componentElement, "staticMember") == true)
			{
			    componentValue = textElement.innerHTML;
			}
			else
			{
			    switch(componentType)
			    {
			        case "dropdownList":
			            
			            var optionElement = editElement.options[editElement.selectedIndex];
			            var optionValue = optionElement.value;
			            var optionText  = optionElement.text;
			            
			            if ((optionValue != null) & (optionValue != "undefined") & (optionValue != ""))
			            {
			                componentValue = optionValue;
			            }
			            else
			            {
			                componentValue = optionText;
			            }
			            
			            break;
			        
			        case "radioList":
			            componentValue = getRadioValue(componentId);
			            break;
			        
			        case "checkboxList":
			            componentValue = getCheckedValues(componentId);
			            break;
			        
			        default:
			           componentValue = editElement.value;
			           break;
			    }
			}
			
			return componentValue;
			
		}
	}

/*  Set Component Text Actions * *******************************************************
 *
 *	TAKES:		Component Type
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/

	function setComponentTextActions(textMemberElement)
	{
		if (textMemberElement)
		{
			// Double Click Actions ************************
			textMemberElement.ondblclick = function()
			{
				cancelTip = true;
				
				hideElement("altTextPane");
				
				// Stores previous value ************************
				oldComponentValue = this.innerHTML;
				
				componentId = this.id.replace("text_", "");
				toggleComponent(componentId, "show");
			}
			
			// On Mouse Over Actions
			textMemberElement.onmouseover = function()
			{
				var textHoverClass = getComponentAttributeValue(this.parentNode, "textHoverClass");
				
				if (textHoverClass == "")
				{
					textHoverClass = "textHover";
				}
				
				this.className = textHoverClass;
				this.style.cursor = "text";
			}
			
			// On Mouse Out Actions
			textMemberElement.onmouseout = function()
			{
				var textClass = getComponentAttributeValue(this.parentNode, "textClass");
				
				if (textClass == "")
				{
					textClass = "plainTextbox";
				}
				
				this.className = textClass;
				this.style.cursor = "";
				hideElement("altTextPane");
			}
			
			// On Click Actions
			textMemberElement.onclick = function()
			{
				cancelTip = false;
				setTimeout(timedToolTip, 500);	
			}	
		}
	}
	
/*  Run Component Callback * *******************************************************
 *
 *	TAKES:		Callback code
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function runComponentCallback(componentElementId, callback)
	{
	    var thisRegExp = null;
	    
	    if (callback != "")
		{
		  
			if (callback.indexOf("(this)") != -1)
			{
			    //thisRegExp = new RegExp("(this)", "g"); 
				//callback = callback.replace(thisRegExp, "(getElement('" + componentElementId + "'))");
			    callback = callback.replace(/\(this\)/g, "(getElement('" + componentElementId + "'))");
			}
			
			if (callback.indexOf("(this,") != -1)
			{
			    //thisRegExp = new RegExp("(this,", "g"); 
				//callback = callback.replace(thisRegExp, "(getElement('" + componentElementId + "'),");
				callback = callback.replace(/\(this,/g, "(getElement('" + componentElementId + "'),");
			}
		
			eval(callback);
		}		
	}

/* Throw Component Error * *******************************************************
 *
 *	TAKES:		Component Element
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function throwComponentError(componentElement, errorMessage)
	{
		var componentType				= getComponentAttributeValue(componentElement, "component");
		var thisErrorMemberElement 		= getElement("error_" + componentElement.id);
		var thisComponentMemberElement 	= getElement(componentType + "_" + componentElement.id);
		
		if (thisComponentMemberElement)
		{
		    switch(componentType)
		    {
		        case "dropdownList":
		            thisComponentMemberElement.className = "dropdownListError";
		            break;
		            
		        default:
		            
		            thisComponentMemberElement.className = "editTextboxError";
		            break;
		    }
			
		}
		
		thisErrorMemberElement.innerHTML = errorMessage;
		showElement(thisErrorMemberElement.id);
	}
	
/* Error Is Thrown * *******************************************************
 *
 *	TAKES:		Component Element
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function errorIsThrown(componentElement)
	{
		var errorThrown = false;
		var thisErrorMemberElement = getElement("error_" + componentElement.id);
		
		if (isVisible(thisErrorMemberElement.id))
		{
			errorThrown = true;	
		}
		
		return errorThrown;
	}
	
/* Clear Component Error * *******************************************************
 *
 *	TAKES:		Component Element
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function clearComponentError(componentElement)
	{
		var componentType				= getComponentAttributeValue(componentElement, "component");
		var thisErrorMemberElement 		= getElement("error_" + componentElement.id);
		var thisComponentMemberElement 	= getElement(componentType + "_" + componentElement.id);
		
		if (thisComponentMemberElement)
		{
			switch(componentType)
		    {
		        case "dropdownList":
		            thisComponentMemberElement.className = "dropdownList";
		            break;
		            
		        default:
		            
		            thisComponentMemberElement.className = "editTextbox";
		            break;
		    }
		}
		
		thisErrorMemberElement.innerHTML = "";
		hideElement(thisErrorMemberElement.id);
	}

/* Get Error Member * *******************************************************
 *
 *	TAKES:		Component Element Id
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function getErrorMember(componentId)
	{
		var errorMember 				= "";
		errorMember 					= document.createElement("div");
		errorMember.id 					= "error_" + componentId;
		errorMember.className			= "editTextboxErrorText";
		errorMember.style.display		= "none";
		
		return errorMember;
	}


/* Get List Value Member * *******************************************************
 *
 *	TAKES:		Component Element Id, List Type (radio | checkbox), Component List Values
 * 	RETURNS:	List Value Container
 *
 *************************************************************************/
 
	function getListValueMember(componentElement, listType)
	{
		var listValueContainer 		    = document.createElement("div");
		var componentId				    = getComponentAttributeValue(componentElement, "id");
		var componentListValues		    = getComponentAttributeValue(componentElement, "listValues");
		var componentListText	        = getComponentAttributeValue(componentElement, "listText");
        var componentListOnClickActions	= getComponentAttributeValue(componentElement, "listOnClickActions");

		var componentOnClickAction	= getComponentAttributeValue(componentElement, "onClickAction");
		
		if (componentOnClickAction == "")
        {
            componentOnClickAction = getComponentAttributeValue(componentElement,"callback");
        }
		
		var componentDefaultValues	= getComponentAttributeValue(componentElement, "value");
		
		// List Values ******************************************
		
		    var listValuesArray = new Array();
    	
		    if (componentListValues != "")
		    {
			    // Support both ", " and "," separators ****************
			    listValuesArray = componentListValues.split(", ");
    			
			    if (listValuesArray.length == 0)
			    {
				    listValuesArray = componentListValues.split(",");
			    }
		    }
		
		// List Text ******************************************
		
		    var listTextArray = new Array();
    	
		    if (componentListText != "")
		    {
			    // Support both ", " and "," separators ***************
			    listTextArray = componentListText.split(", ");
    			
			    if (listTextArray.length == 0)
			    {
				    listTextArray = componentListText.split(",");
			    }
		    }
		
		// List OnClick Actions ******************************************
		
		    var listOnClickActionsArray = new Array();
    	
		    if ((componentListOnClickActions != "") & (componentListOnClickActions != "null"))
		    {
			    // Support both ",, " and ",," separators *********************
			    listOnClickActionsArray = componentListOnClickActions.split(",, ");
    			
			    if (listOnClickActionsArray.length == 0)
			    {
				    listOnClickActionsArray = componentListOnClickActions.split(",,");
			    }
		    }
		   
		// Default Values *********************************
		
		    var defaultValuesArray = new Array();
    		
		    if (componentDefaultValues != "")
		    {
			    // Support both ", " and "," separators ********************
			    defaultValuesArray = componentDefaultValues.split(", ");
    			
			    if (defaultValuesArray.length == 0)
			    {
				    defaultValuesArray = componentDefaultValues.split(",");
			    }
		    }
		
		
		// List Element Loop *******************************
		
		for(var listCtr=0; listCtr<listValuesArray.length; listCtr++)
		{
		    var thisListValueId     = componentId + "." + listCtr;
			var listValue           = listValuesArray[listCtr];
			var listText            = "";
			var listOnClickAction   = "";
			
			if (listTextArray.length > 0)
			{
			    listText = listTextArray[listCtr];
			}
			
			if (listOnClickActionsArray.length > 0)
			{
			    listOnClickAction = listOnClickActionsArray[listCtr];
			}
			
			 
			/* EXCEPTION!!!!! ****************************************
			*
			* 	Need to Change later: Allows the use of commas in the
			*	dropdown list text or value.
			*
			*********************************************************/
			 
				listValue = listValue.replace(/#comma#/g, ",");
			
			// *********************************************************
			
			var inputRow	= document.createElement("div");
			inputRow.id     = "listValueContainer." + thisListValueId;
			
			var inputTable 	= createTable(1, 2);
			inputTable.cellPadding = 2;
			inputTable.width = "";
			
			var tableCells = inputTable.rows[0].cells;
			
			var inputElement = document.createElement("input");
			inputElement.setAttribute("type", listType, 0);
			inputElement.setAttribute("id", thisListValueId, 0);
			inputElement.setAttribute("name", componentId, 0);
			inputElement.setAttribute("value", listValue, 0);
			
			if (listOnClickAction != "")
		    {
		       inputElement.setAttribute("listOnClickAction", listOnClickAction, 0);
		    }
			    
			// Check Default Values ************
			for(var valueCtr=0; valueCtr<defaultValuesArray.length; valueCtr++)
			{
				var thisDefaultValue = defaultValuesArray[valueCtr];
				
				/* EXCEPTION!!!!! ****************************************
				*
				* 	Need to Change later: Allows the use of commas in the
				*	dropdown list text or value.
				*
				*********************************************************/
				
					thisDefaultValue = thisDefaultValue.replace(/#comma#/g, ",");
				
				// *********************************************************
				
				if (thisDefaultValue == listValue)
				{
					inputElement.setAttribute("checked", "checked");
				}
				
			}
			
			// OnClick Action for the list values *****************************
			var thisComponentOnClickAction = function()
			{
			    var idArray 			= this.id.split(".");
				var thisComponentId		= idArray[0];
				
				var inputElementId 	= idArray[0] + "." + idArray[1];
				var inputElement 	= getElement(inputElementId); 
				var inputType		= inputElement.getAttribute("type");
				
				if (inputType == "checkbox")
				{
				    if (this != inputElement)
				    {
					    toggleCheckboxElement(inputElementId);
				    }
				}
				else
				{
					toggleRadioElement(inputElementId);
				}
				
				//var thisOnClickAction	    = getComponentAttributeValue(getElement(thisComponentId), "onClickAction");
				var thisOnClickAction       = componentOnClickAction;
				var thisListOnClickAction	= inputElement.getAttribute("listOnClickAction");
				var thisMaxNumChoices	    = getComponentAttributeValue(getElement(thisComponentId), "maxNumChoices");
				
				// Append the List actions ***************
				if (thisListOnClickAction != "")
				{
				    if (thisOnClickAction != "") { thisOnClickAction += "; "; }
				    
				    thisOnClickAction += thisListOnClickAction;  
				}
				
				// Limit Checkboxes ******************
				if (thisMaxNumChoices != "")
				{
					checkCheckboxLimitChoice(inputElement, thisMaxNumChoices);
				}
				
				if (thisOnClickAction != "")
				{	
					runComponentCallback(inputElementId, thisOnClickAction);
				}
			}
			
			// Add OnClick ******************************
			inputElement.onclick = thisComponentOnClickAction;
			
			tableCells[0].appendChild(inputElement);
			
			var spanElement = document.createElement("span")
			spanElement.setAttribute("id", componentId + "." + listCtr + ".LabelText");
			
			spanElement.onmouseover = function(e)
			{
				e = e || window.event; this.style.cursor="pointer";
			}
			
			spanElement.onselectstart = function() { return false; }
			spanElement.onclick = thisComponentOnClickAction;
			
			if (listText != "")
			{
			    spanElement.innerHTML 		= listText;
			}
			else
			{
			    spanElement.innerHTML 		= listValue;
			}
			
			tableCells[1].appendChild(spanElement);
			
			inputRow.appendChild(inputTable);
			
			listValueContainer.appendChild(inputRow);
		}
		
		return listValueContainer;
	}


/* ************************************************************************************************************ 
 * 
 * 		Component: 		Edit Text Functions
 *
 *		Attributes:		id					- Identifier 
 *						component			- Type of Component
 *						dataType			- Restricts the type of data that can be submitted through this 
 *											  component (ref. brdApiCommon.js - "dataIsValid" for data type)
 *						size				- Size of the edit textbox
 *                      maxLength           - Maximum amount of characters allowed in this text field.
 *						callback			- Javascript code executed after the edit textbox loses focus.
 *						value				- Default value
 *						staticMember		- Describes the component member that will always be visible, even
 *											  after component actions are fired. (true | false)
 *						textClass			- Class for the text view of this component
 *                      dropdownWidth       - CSS style width for the dropdown member
 *                      errorMemberContainerId    - Specifies the element id of the container to place the error member. 
 *
 **************************************************************************************************************/
 

/*  Add Edit Text Component Members * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function addEditTextComponentMembers()
	{
		var componentElements 		= getElementsByComponent("editText");
		var componentElement 		= "";
		var componentId				= "";
		var componentValue			= "";
		var componentSize			= "";
		var componentMaxLength      = "";
		var componentTextClass		= "";
		var componentStaticMember	= "";
		var componentDataType 		= "";
		var componentErrorContainerId = "";
		
		if (componentElements.length > 0)
		{
			
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				
				componentElement 	= componentElements[ctr];
				
				// Check to see that the Component is not already constructed *****************************
				
				if (getComponentAttributeValue(componentElement, "constructed") != "true")
				{
					componentId			= getComponentAttributeValue(componentElement, "id");
					componentValue		= getComponentAttributeValue(componentElement, "value");
					componentSize		= getComponentAttributeValue(componentElement, "size");
					componentMaxLength	= getComponentAttributeValue(componentElement, "maxLength");
					componentTextClass	= getComponentAttributeValue(componentElement, "textClass");
					componentErrorContainerId	= getComponentAttributeValue(componentElement, "errorMemberContainerId");
					componentStaticMember = getComponentAttributeValue(componentElement, "staticMember");
					componentDataType 	= getComponentAttributeValue(componentElement, "dataType");
					
					setComponentAttributeValue(componentElement, "constructed", true);
					
					/* Members: *************************
					*	
					*	1. Text 		- div
					*	2. Edit Text 	- input textbox
					*	3. Error 		- div
					*
					*************************************/
					
					// 1. Text ******************************
					
					var textMember 					= "";
					textMember 						= document.createElement("div");
					textMember.id 					= "text_" + componentId;
					
					if (componentDataType == "email")
					{
						// Enable the mailto link *****************
						textMember.innerHTML			= "<a href=\"mailto:" + componentValue + "\">" + componentValue + "</a>";
					}
					else
					{
					    textMember.innerHTML = componentValue;	
					}
					
					if (componentStaticMember == "true")
					{
						textMember.style.display	= "none";	
					}
					else 
					{
						textMember.style.display	= "block";	
					}
					
					if (componentTextClass != "")
					{
						textMember.className			= componentTextClass;
					}
					else
					{
						textMember.className			= "plainTextbox"; // Default
					}
					
					// Set the size ***********************
					
					if (componentSize == "100%")
					{
						textMember.style.width = "100%";
					}
					else
					{
						textMember.style.width = (componentSize * 5.5) + "px";
					}
					
					
					
					componentElement.appendChild(textMember);
					
					// 2. Edit Text ******************************
					
					var editTextMember 				= "";
					editTextMember					= document.createElement("input");
					editTextMember.type 			= "text";
					editTextMember.id 				= "editText_" + componentId;
					
					if (componentStaticMember == "true")
					{
						editTextMember.style.display	= "block";	
					}
					else
					{
						editTextMember.style.display	= "none";	
					}
					
					editTextMember.className		= "editTextbox";
					
					// Set the size ***********************
					if (componentSize == "100%")
					{
						editTextMember.size = 10;
					}
					else
					{
						editTextMember.size = componentSize;
					}
					
					editTextMember.value			= componentValue;
					
					// Set Max Length **************************
					if ((componentMaxLength != "") & (dataIsValid(componentMaxLength, "integer")))
                    {
                        editTextMember.setAttribute("maxlength", componentMaxLength);
                    }
					
					componentElement.appendChild(editTextMember);
					
					// 3. Error ******************************
					
					var errorMember 				= "";
					errorMember 					= document.createElement("div");
					errorMember.id 					= "error_" + componentId;
					errorMember.className			= "editTextboxErrorText";
					errorMember.style.display		= "none";
					errorMember.style.width         = "100%";
					
					var errorMemberContainer = null;
					
					if (componentErrorContainerId != "")
					{
					    errorMemberContainer = getElement(componentErrorContainerId);
					}
					
					if ((errorMemberContainer != null) & (errorMemberContainer  != "undefined"))
					{
					    errorMemberContainer.appendChild(errorMember);
					}
					else
					{
					    componentElement.appendChild(errorMember);
					}
					
				} // End Construction Check
				
			} // End For
			
		}
		
	}

/* Clear Component Edit Text Errors ********************************************************
 *
 *	TAKES:		NOTING
 * 	RETURNS:	NOTHING
 *	NOTE:		Sets the edit text components on the page to cleared status
 *
 ********************************************************************************/
 
	function clearComponentEditTextErrors()
	{
		var errorElements = getTagGroup("div", "error_");
		var errorElement = "";
		
		if (errorElements.length > 0)
		{
			for(var ctr=0; ctr<errorElements.length; ctr++)
			{
				errorElement = errorElements[ctr];
				
				if (errorElement)
				{
					var editTextElement = getElement(errorElement.id.replace("error_", "editText_"))
					var componentId = errorElement.id.replace("error_", "");
					
					if (editTextElement)
					{
						editTextElement.className = "editTextbox";
						toggleComponent(componentId, "hide");
						hideElement(errorElement.id);
					}
				}
			}
		}
	}
	
/* Clear Component Edit Text Values ********************************************************
 *
 *	TAKES:		NOTING
 * 	RETURNS:	NOTHING
 *	NOTE:		Sets the edit text components on the page to cleared status
 *
 ********************************************************************************/
 
	function clearComponentEditTextValues()
	{
		var componentElements = getElementsByComponent("editText");
		
		var iterateAction = function(componentElement, ctr)
		{
			setComponentValue(componentElement.id, "");
		}
		
		iterateElementList(componentElements, iterateAction);
	}

/*  Set Component Edit Text Actions * ***************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function setComponentEditTextActions()
	{
		// Get All Member Elements **************************************
		var textMemberElements			= getTagGroup("div", "text_");
		var editTextMemberElements		= getTagGroup("input", "editText_");
		
		var textMemberElement 			= "";
		var editTextMemberElement 		= "";
		var dropdownListMemberElement 	= "";
		var errorMemberElement 			= "";
		
		var componentId 			= "";
		var dataType	 			= "";
		var staticMember			= "";
		var testError 				= "";
		
		var memberCount = textMemberElements.length;
		
		for(var ctr=0; ctr<memberCount; ctr++)
		{
			
			componentId = "";
			testError = "";
			
			// Text Member Actions --------------------------------------
			
			textMemberElement = textMemberElements[ctr];
			
			if (textMemberElement)
			{
				setComponentTextActions(textMemberElement);
			}
			
			// Edit Text Member Actions --------------------------------------
			
			editTextMemberElement = editTextMemberElements[ctr];
			
			if (editTextMemberElement)
			{
				// On Foucs Out ---------------------------------------------
				editTextMemberElement.onblur = function()
				{
					componentId 	= this.id.replace("editText_", "");
					dataType 		= getComponentAttributeValue(getElement(componentId), "dataType");
					staticMember	= getComponentAttributeValue(getElement(componentId), "staticMember");
					
					cancelTip 		= false;
					testError 		= true;
					
					var thisTextMemberElement 	= getElement("text_" + componentId);
					var thisErrorMemberElement 	= getElement("error_" + componentId);
					
					if (this.value != "")
					{
						if (dataType == "")
						{
							dataType = "text";	
						}
					
						switch(dataType)
						{
								
							case "alt_phone":
						
								testError = dataIsValid(this.value, "phone");
								break;
							
							default:
								
								testError = dataIsValid(this.value, dataType);
								break;
						}
					}
					
					if (testError == true)
					{
						hideElement(thisErrorMemberElement.id);
						this.className = "editTextbox";
						
						if (dataType == "email")
						{
							thisTextMemberElement.innerHTML = "<a href=\"mailto:" + this.value + "\">" + this.value + "</a>";
						}
						else
						{
							// Sets the text member
							thisTextMemberElement.innerHTML = this.value;
						}
						
						// Sets the Component value
						getElement(componentId).setAttribute("value", this.value);
						
						if (staticMember != "true")
						{
						   	toggleComponent(componentId, "hide");
						}
						
						var componentCallback = getComponentAttributeValue(getElement(componentId), "callback");
						
						runComponentCallback(componentId, componentCallback);
						
					}
					else
					{
						this.className = "editTextboxError";
						thisErrorMemberElement.innerHTML = testError + " Please correct the errrors before proceeding.";
						showElement(thisErrorMemberElement.id);
					}
					
				} // OnBlur Action
			
			} // if editTextMemberElement
			
			
		}
		
	}
	
/* ************************************************************************************************************ 
 * 
 * 		Component: 		Edit Text Area Functions
 *
 *		Attributes:		id					- Identifier 
 *						component			- Type of Component
 *						width				- Width of the Text Area
 *						height				- Height of the Text Area
 *						callback			- Javascript code executed after the edit textbox loses focus.
 *						value				- Default value
 *						staticMember		- Describes the component member that will always be visible, even
 *											  after component actions are fired. (true | false)
 *						textClass			- Class for the text view of this component
 *						maxlength			- maximum number of characters that can be entered.
 *                      singleClickEdit		- Enables single click editing otherwise default is double
 *                                            click to edit (true | false).  
 *
 **************************************************************************************************************/
 

/*  Add Edit Text Area Component Members * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function addEditTextAreaComponentMembers()
	{
		var componentElements 		= getElementsByComponent("editTextArea");
		var componentElement 		= "";
		var componentId				= "";
		var componentValue			= "";
		var componentTextClass		= "";
		var componentStaticMember	= "";
		var componentWidth 			= "";
		var componentHeight	 		= "";
		var componentMaxLength		= "";
		
		if (componentElements.length > 0)
		{
			
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				
				componentElement 	= componentElements[ctr];
				
				// Check to see that the Component is not already constructed *****************************
				
				if (getComponentAttributeValue(componentElement, "constructed") != "true")
				{
					componentId			= getComponentAttributeValue(componentElement, "id");
					componentValue		= getComponentAttributeValue(componentElement, "value");
					componentWidth		= getComponentAttributeValue(componentElement, "width");
					componentHeight		= getComponentAttributeValue(componentElement, "height");
					componentTextClass	= getComponentAttributeValue(componentElement, "textClass");
					componentStaticMember = getComponentAttributeValue(componentElement, "staticMember");
					componentMaxLength 	= getComponentAttributeValue(componentElement, "maxlength");
					
					setComponentAttributeValue(componentElement, "constructed", true);
					
					/* Members: *************************
					*	
					*	1. Text 		- div
					*	2. Edit Text 	- input textbox
					*	3. Error 		- div
					*
					*************************************/
					
					// 1. Text ******************************
					
					var textMember 					= "";
					textMember 						= document.createElement("div");
					textMember.id 					= "text_" + componentId;
					textMember.innerHTML			= componentValue;
					
					if (componentStaticMember == "true")
					{
						textMember.style.display	= "none";	
					}
					else
					{
						textMember.style.display	= "block";	
					}
					
					if (componentTextClass != "")
					{
						textMember.className			= componentTextClass;
					}
					else
					{
						textMember.className			= "plainTextbox"; // Default
					}
					
					if (componentWidth != "")
					{
					    textMember.style.width = componentWidth + "px";
					}
					
					if (componentHeight != "")
					{
					    textMember.style.height = componentHeight + "px";
					}
					
					 componentElement.appendChild(textMember);
					
					// 2. Edit Text ******************************
					
					var editTextAreaMember 				= "";
					editTextAreaMember					= document.createElement("textarea");
					editTextAreaMember.id 				= "editTextArea_" + componentId;
					
					if (componentStaticMember == "true")
					{
						editTextAreaMember.style.display	= "block";	
					}
					else
					{
						editTextAreaMember.style.display	= "none";	
					}
					
					if (componentMaxLength != "")
					{
						editTextAreaMember.maxlength = componentMaxLength;
					}
					
					if (componentWidth == "") { componentWidth = 50; }
					if (componentHeight == "") { componentHeight = 35; }
					
					
					/* ***************************************************
					*  
					*	Style Exception:
					*
					*		- 	Need to figure out how to set the
					*			"className" without deleting the "value".
					*
					* ****************************************************/
					
					editTextAreaMember.className		= "editTextbox";
					editTextAreaMember.style.width		= componentWidth + "px";
					editTextAreaMember.style.height		= componentHeight + "px";
					
					editTextAreaMember.value			= componentValue;
					
					componentElement.appendChild(editTextAreaMember);
					
					// 3. Error ******************************
					
					var errorMember 				= "";
					errorMember 					= document.createElement("div");
					errorMember.id 					= "error_" + componentId;
					errorMember.className			= "editTextboxErrorText";
					errorMember.style.display		= "none";
					errorMember.style.width         = "100%";
					
					componentElement.appendChild(errorMember);
			
				} // End Construction Check
				
			} // End For
			
		}
	}

/*  Set Component Edit Text Actions * ***************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function setComponentEditTextAreaActions()
	{
		// Get All Component Elements **************************************
		var componentElements			= getElementsByComponent("editTextArea");
		var componentElement			= "";
		
		var textMemberElement 			= "";
		var editTextAreaMemberElement 	= "";
		var errorMemberElement 			= "";
		
		var componentId 			= "";
		var dataType	 			= "";
		var staticMember			= "";
		var testError 				= "";
		var temp = "";
		var memberCount = componentElements.length;
		
		for(var ctr=0; ctr<memberCount; ctr++)
		{
			componentId = "";
			testError = "";
			
			componentElement = componentElements[ctr]; 
			
			// Get All Member Elements 
			textMemberElement = componentElement.getElementsByTagName("div")[0];
			editTextAreaMemberElement = componentElement.getElementsByTagName("textarea")[0];
		
		
			// Text Member Actions --------------------------------------
			if (textMemberElement)
			{
				setComponentTextActions(textMemberElement);
			}
			
			// Edit Text Area Member Actions --------------------------------------
			if (editTextAreaMemberElement)
			{
				
				// On Foucs Out ---------------------------------------------
				editTextAreaMemberElement.onblur = function()
				{
					componentId 	= this.id.replace("editTextArea_", "");
					dataType 		= getComponentAttributeValue(getElement(componentId), "dataType");
					staticMember	= getComponentAttributeValue(getElement(componentId), "staticMember");
					cancelTip 		= false;
					testError 		= true;
					
					var thisTextMemberElement 	= getElement("text_" + componentId);
					var thisErrorMemberElement 	= getElement("error_" + componentId);
					
					if (this.value != "")
					{
						// Needs a unique error checking system...
					}
					
					if (testError == true)
					{
						hideElement(thisErrorMemberElement.id);
						this.className = "editTextbox";
						
						thisTextMemberElement.innerHTML = this.value.replace(/\n/g, "<br>");
						getElement(componentId).setAttribute("value", this.value);
						
						if (staticMember != "true")
						{
							toggleComponent(componentId, "hide");
						}
						
						var componentCallback = getComponentAttributeValue(getElement(componentId), "callback");
						
						runComponentCallback(componentId, componentCallback);
						
					}
					else
					{
						this.className = "editTextboxError";
						thisErrorMemberElement.innerHTML = testError + " Please correct the errrors before proceeding.";
						showElement(thisErrorMemberElement.id);
					}
					
				} // OnBlur Action
			
			} // if editTextMemberElement
			
			
		} // End For
		
	}

/* ************************************************************************************************************ 
 * 
 * 		Component: Dropdown List Functions
 *		
 *		Attributes:		id					- Identifier 
 *						component			- Type of Component
 *						dataType			- Restricts the type of data that can be submitted through this 
 *											  component (ref. brdApiCommon.js - "dataIsValid" for data type)
 *						size				- Size if the edit textbox
 *						callback			- Javascript code executed after the edit textbox loses focus.
 *						value				- Default value
 *						queryTag			- Query Profile Tag that defines the database content to populate 
 *											  the Dropdown box component.  Requires that the Query Profile contain
 *											  only one Query Profile Column definition. (ref. brdApiQuery.asp)
 *						listValues			- Comma separated list items that will populate the Dropdown box
 *											  component "value" attribute.
 *						listText			- Comma separated list items that will populate the Dropdown box
 *											  component OPTION text.
 *                      listOnClickActions  - Comma separated list items that will populate the Dropdown box
 *											  component "onclick" attribute.
 *						staticMember		- Describes the component member that will always be visible, even
 *											  after component actions are fired. (true | false)
 *						integerRangeLower	- The lower end of a manualy generated values list based on ascending
 *											  intger values.
 *						integerRangeUpper	- The upper end of a manualy generated values list based on ascending
 *											  intger values.
 *                      errorMemberContainerId    - Specifies the element id of the container to place the error member. 
 *
 **************************************************************************************************************/
 

/*  Add Dropdown List Component Members * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function addDropdownListComponentMembers()
	{
		var componentElements 			= getElementsByComponent("dropdownList");
		var componentElement 			= "";
		var componentId					= "";
		var componentValue				= "";
		var componentSize				= "";
		var componentIntegerRangeLower 	= "";
		var componentIntegerRangeUpper 	= "";
		var componentListValues			= "";
		var componentQueryTag			= "";
		var componentTextClass			= "";
		var componentStaticMember		= "";
		var listValuesArray				= "";
		var listTextArray				= "";
		var listOnClickActionsArray     = "";
		var componentListOnClickActions = "";
		var componentErrorContainerId   = "";
		
		if (componentElements.length > 0)
		{
			
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				
				componentElement 	= componentElements[ctr];
				
				// Check to see that the Component is not already constructed *****************************
				
				if (getComponentAttributeValue(componentElement, "constructed") != "true")
				{
					// Construct Component *******************************************************
					
					componentId			= getComponentAttributeValue(componentElement, "id");
					componentValue		= getComponentAttributeValue(componentElement, "value");
					componentSize		= getComponentAttributeValue(componentElement, "size");
					
					componentIntegerRangeLower 	= getComponentAttributeValue(componentElement, "integerRangeLower");
					componentIntegerRangeUpper 	= getComponentAttributeValue(componentElement, "integerRangeUpper");
					componentListValues			= getComponentAttributeValue(componentElement, "listValues");
					componentListText			= getComponentAttributeValue(componentElement, "listText");
					componentQueryTag			= getComponentAttributeValue(componentElement, "queryTag");
					componentTextClass			= getComponentAttributeValue(componentElement, "textClass");
					componentStaticMember		= getComponentAttributeValue(componentElement, "staticMember");
					componentListOnClickActions = getComponentAttributeValue(componentElement, "listOnClickActions");
					componentErrorContainerId	= getComponentAttributeValue(componentElement, "errorMemberContainerId");

					
					setComponentAttributeValue(componentElement, "constructed", true);
					
					if ((componentSize == "") || (componentSize == "undefined"))
					{
						componentSize = 5;
					}
					
					
		           // List Values Array ***********************************
		                
					    listValuesArray = new Array();
    					
					    if (componentListValues != "")
					    {
						    // Support both ", " and "," separators
						    listValuesArray = componentListValues.split(", ");
    						
						    if (listValuesArray.length == 0)
						    {
							    listValuesArray = componentListValues.split(",");
						    }
					    }
    		       
    		       // List Text Array ******************************
    		       
					    listTextArray = new Array();
    					
					    if (componentListText != "")
					    {
					        // Support both ", " and "," separators
						    listTextArray = componentListText.split(", ");
    						
						    if (listTextArray.length == 0)
						    {
							    listTextArray = componentListText.split(",");
						    }
					    }
					
					/* Members: *************************
					*	
					*	1. Text 			- div
					*	2. Dropdown List 	- selection box
					*	3. Error 			- div
					*
					*************************************/
					
					// 1. Text ******************************
					
					var textMember 					= "";
					textMember 						= document.createElement("div");
					textMember.id 					= "text_" + componentId;
					textMember.innerHTML			= componentValue;
					
					if (componentStaticMember == "true")
					{
						textMember.style.display	= "none";	
					}
					else
					{
						textMember.style.display	= "block";	
					}
					
					if (componentTextClass != "")
					{
						textMember.className			= componentTextClass;
					}
					else
					{
						textMember.className			= "plainTextbox"; // Default
					}
					
					// Set the size ***********************
					textMember.style.width = (componentSize * 5.5) + "px";
					
					componentElement.appendChild(textMember);
					
					// 2. Dropdown List ******************************
					
					var dropdownListMember 				= "";
					dropdownListMember					= document.createElement("select");
					dropdownListMember.className		= "dropdownList";
					dropdownListMember.id 				= "dropdownList_" + componentId;
					dropdownListMember.multiple			= false;
					
					// Build the Dropdown Menu *****************************************************
					if ((componentIntegerRangeLower != "") & (componentIntegerRangeUpper != ""))
					{
						// Integer Range ********************************************
						
						var incrementValue = 1;
						
						if (componentIntegerRangeLower > componentIntegerRangeUpper)
						{
							incrementValue = -1;	
						}
						
						for(var optionCtr=(incrementValue*componentIntegerRangeLower); optionCtr<=componentIntegerRangeUpper; optionCtr++)
						{
							var integerValue = document.createElement("option");
							integerValue.text = Math.abs(optionCtr);
							
							if (IE)
							{
								dropdownListMember.add(integerValue);
							}
							else
							{
								dropdownListMember.add(integerValue, null);
							}
						}
						
					}
					else if (listValuesArray.length > 0)
					{
						// List Values ******************************************
						
						// Default: - Select -
						var defaultDropdownValue = document.createElement("option");
						defaultDropdownValue.text = "- Select -";
						
						if (IE)
						{
							dropdownListMember.add(defaultDropdownValue);
						}
						else
						{
							dropdownListMember.add(defaultDropdownValue, null);
						}
						
						for(var listCtr=0; listCtr<listValuesArray.length; listCtr++)
						{
							
							var listValue = document.createElement("option");
							
							if (listTextArray.length > 0)
							{
							    listValue.text = listTextArray[listCtr];
							    listValue.value = listValuesArray[listCtr];
							}
							else
							{
							    listValue.text = listValuesArray[listCtr];
							}
							
							/*if (listOnClickActionsArray.length > 0)
							{
							    listValue.setAttribute("onclick", listOnClickActionsArray[listCtr]);
							}*/
							
							/* EXCEPTION!!!!! ****************************************
							*
							* 	Need to Change later: Allows the use of commas in the
							*	dropdown list text or value.
							*
							*********************************************************/
							    
								listValue.text = listValue.text.replace("#comma#", ",");
							
							// *********************************************************
							
							if (IE)
							{
								dropdownListMember.add(listValue);
							}
							else
							{
								dropdownListMember.add(listValue, null);
							}
							
						}
						
					}
					else if (componentQueryTag != "")
					{
						// Query Tag *****************************************
						
						setAjaxUrl("updateData", "/Includes/api/brdApiQuery.asp?action=getQueryData&queryTag=" + componentQueryTag, false, "setComponentDropdownListQueryData('" + componentId + "');");
					
					}
					
					// Set the Default Value ************************************
					if ((componentValue != "") & (componentValue != undefined)) 
					{
						for(var i=0; i<dropdownListMember.options.length; i++)
						{
							if ((dropdownListMember.options[i].value == componentValue) || (dropdownListMember.options[i].text == componentValue))
							{
								dropdownListMember.options[i].selected = true;
							}
							
							
						}
					}
					
					// Set Static Option **********************************
					if (componentStaticMember == "true")
					{
						dropdownListMember.style.display	= "block";	
					}
					else
					{
						dropdownListMember.style.display	= "none";
					}
					
					componentElement.appendChild(dropdownListMember);
					
					
					// 3. Error ******************************
					
					var errorMember 				= "";
					errorMember 					= document.createElement("div");
					errorMember.id 					= "error_" + componentId;
					errorMember.className			= "editTextboxErrorText";
					errorMember.style.display		= "none";
					errorMember.style.width         = "100%";
					
					var errorMemberContainer = null;
					
					if (componentErrorContainerId != "")
					{
					    errorMemberContainer = getElement(componentErrorContainerId);
					}
					
					if ((errorMemberContainer != null) & (errorMemberContainer  != "undefined"))
					{
					    errorMemberContainer.appendChild(errorMember);
					}
					else
					{
					    componentElement.appendChild(errorMember);
					}	
					
					
				} // Check to see if Component is already constructed
			}
		}
	}

/*  Run Component OnClick Action * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
     
    function runDropdownOnClickAction(dropdownElement)
    {
        
        var componentId = dropdownElement.id.replace("dropdownList_", "");
	    var componentElement = getElement(componentId);
	    
	    var onClickActions = getComponentAttributeValue(componentElement, "listOnClickActions");
	    
	    // List OnClick Actions ******************************************

            listOnClickActionsArray = new Array();
    	
            if (onClickActions != "")
            {
                // Support both ",, " and ",," separators *********************
                listOnClickActionsArray = onClickActions.split(",, ");
    			
                if (listOnClickActionsArray.length == 0)
                {
                    listOnClickActionsArray = onClickActions.split(",,");
                }
                
                // Execute the Action *****************************
                if (listOnClickActionsArray.length >= dropdownElement.selectedIndex-1)
                {
                    eval(listOnClickActionsArray[dropdownElement.selectedIndex-1]);
                }
               
            }
    }
    
/*  Set Component Dropdown List Query Data * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function setComponentDropdownListQueryData(componentId)
	{
		var dropdownListMember = getElement("dropdownList_" + componentId);
		var listValueElements = getElement("updateData").getElementsByTagName("input");
		
		if (listValueElements.length > 0)
		{
			// Default: - Select -
			var defaultDropdownValue = document.createElement("option");
			defaultDropdownValue.text = "- Select -";
			
			if (IE)
			{
				dropdownListMember.add(defaultDropdownValue);
			}
			else
			{
				dropdownListMember.add(defaultDropdownValue, null);
			}
						
			for(var listCtr=0; listCtr<listValueElements.length; listCtr++)
			{
				var listValue = document.createElement("option");
				listValue.text = listValueElements[listCtr].value;
				
				if (IE)
				{
					dropdownListMember.add(listValue);
				}
				else
				{
					dropdownListMember.add(listValue, null);
				}
			}
		}
		
	}

/*  Set Component Dropdown List Actions * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function setComponentDropdownListActions()
	{
		// Get All Member Elements **************************************
		var textMemberElements			= getTagGroup("div", "text_");
		var dropdownListMemberElements	= getTagGroup("select", "dropdownList_");
		
		var textMemberElement 			= "";
		var dropdownListMemberElement 	= "";
		var errorMemberElement 			= "";
		
		var componentId 			= "";
		var dataType	 			= "";
		var testError 				= "";
		var staticMember			= "";
		var componentValue			= "";
		
		var memberCount = textMemberElements.length;
		
		for(var ctr=0; ctr<memberCount; ctr++)
		{
			componentId = "";
			testError = "";
			
			// Text Member Actions --------------------------------------
			
			textMemberElement = textMemberElements[ctr];
			
			if (textMemberElement)
			{
				setComponentTextActions(textMemberElement);
			}
			
			// Dropdown List Member Actions --------------------------------------
			
			dropdownListMemberElement = dropdownListMemberElements[ctr];
			
			if (dropdownListMemberElement)
			{
				
				// On Change ---------------------------------------------
				dropdownListMemberElement.onchange = function()
				{
					componentId 	= this.id.replace("dropdownList_", "");
					dataType 		= getComponentAttributeValue(getElement(componentId), "dataType");
					staticMember	= getComponentAttributeValue(getElement(componentId), "staticMember");
					cancelTip 		= false;
					testError 		= true;
					
					var thisTextMemberElement 	= getElement("text_" + componentId);
					var thisErrorMemberElement 	= getElement("error_" + componentId);
					
					var dropdownValue = this.options[this.selectedIndex].text;
					
					if (this.value != "")
					{
						testError = dataIsValid(dropdownValue, dataType);
					}
					
					if (testError == true)
					{
						// No Errors **********************
						
						var holder = "";
						
						hideElement(thisErrorMemberElement.id);
						this.className = "dropdownList";
						
						thisTextMemberElement.innerHTML = dropdownValue;
						getElement(componentId).setAttribute("value", dropdownValue);
						
						if (staticMember != "true")
						{
							toggleComponent(componentId, "hide");
						}
						
						// OnClick List Actions **************************
						runDropdownOnClickAction(this);
						
						var componentCallback = getComponentAttributeValue(getElement(componentId), "callback");
						
						runComponentCallback(componentId, componentCallback);
					}
					else
					{
						// Errors Found ************************
						this.className = "dropdownListError";
						thisErrorMemberElement.innerHTML = testError + " Please correct the errrors before proceeding.";
						showElement(thisErrorMemberElement.id);
					}
					
				} // OnBlur Action
				
				dropdownListMemberElement.onblur = function()
				{
				    componentId 	= this.id.replace("dropdownList_", "");
				    staticMember	= getComponentAttributeValue(getElement(componentId), "staticMember");
					
				    if (staticMember != "true")
					{
						toggleComponent(componentId, "hide");
					}
				}
				
			} // if dropdownMemberElement
			
			
		}
		
	}

/* ************************************************************************************************************ 
 * 
 * 		Component: Form List Functions
 *		
 *		Attributes:		id					- Identifier 
 *						component			- Type of Component (radioList | checkboxList)
 *						dataType			- Restricts the type of data that can be submitted through this 
 *											  component (ref. brdApiCommon.js - "dataIsValid" for data type)
 *						onClickAction		- Javascript code executed after the radio button is clicked
 *						value				- Default value
 *						queryTag			- Query Profile Tag that defines the database content to populate 
 *											  the radio list component.  Requires that the Query Profile contain
 *											  only one Query Profile Column definition. (ref. brdApiQuery.asp)
 *						listValues			- Comma separated list items that will populate the Dropdown box
 *											  component "value" attribute.
 *                      listText            - Comma separated list items that will populate the Dropdown box
 *											  component "text" attribute.
 *                      listOnClickActions  - Double comma separeated items that will populate the list items
 *                                            "onclick" attribute.
 *						maxNumChoices 		- Integer value that limits the number of choices for a checkboxList
 *											  component.
 *
 **************************************************************************************************************/
 

/*  Add Form List Component Members * *******************************************************
 *
 *	TAKES:		Component Type (radioList | checkboxList)
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function addFormListComponentMembers(componentType)
	{
		var inputFormType				= componentType.replace("List", "");
		var componentElements 			= getElementsByComponent(componentType);
		var componentElement 			= "";
		var componentId					= "";
		var listValuesArray				= "";
		var listTextArray				= "";
		var listOnClickActionsArray      = "";
		
		var iterateAction = function(componentElement, ctr)
		{
			
			// Check to see that the Component is not already constructed *****************************
				
				if (getComponentAttributeValue(componentElement, "constructed") != "true")
				{
					// Construct Component *******************************************************
					
					componentId			= getComponentAttributeValue(componentElement, "id");
					componentValue		= getComponentAttributeValue(componentElement, "value");
					
					componentListValues	        = getComponentAttributeValue(componentElement, "listValues");
					componentListText	        = getComponentAttributeValue(componentElement, "listText");
					componentListOnClickActions	= getComponentAttributeValue(componentElement, "listOnClickActions");
					componentQueryTag	        = getComponentAttributeValue(componentElement, "queryTag");
					
					setComponentAttributeValue(componentElement, "constructed", true);
					
					// 1. Input Members **************************
					
					if (componentListValues != "")
					{
					    
						componentElement.appendChild(getListValueMember(componentElement, inputFormType));
						
						/* EXCEPTION!!!!! ****************************************
						*
						* 	Need to Change later: Allows the use of commas in the
						*	dropdown list text or value.
						*
						*********************************************************/
						
							componentListValues = componentListValues.replace(/#comma#/g, ",");
							
						// *********************************************************
						
						// Support both ", " and "," separators *************************
						
						    listValuesArray         = componentListValues.split(", ");
					        
    					    
						    if (listValuesArray.length == 0)
						    {
							    listValuesArray = componentListValues.split(",");
						    }
    					
						for(var valuesCtr=0; valuesCtr<listValuesArray.length; valuesCtr++)
						{
							var thisListValue = listValuesArray[valuesCtr];
							
							if (thisListValue == componentValue)
							{
							    var thisInputElement = getElement(componentId + "." + valuesCtr);
							    
								if (IE)
								{
								    thisInputElement.setAttribute("checked", "checked");
								    //thisInputElement.checked = true;
								}
								else
								{
								    thisInputElement.setAttribute("checked", "checked");
								}
							}
						}
						
						
					} // Input members
					
					// 2. Error Member ********************************
					
						componentElement.appendChild(getErrorMember(componentId));
						getElement("error_" + componentId).style.paddingLeft = "10px";
					
				}
				
		}
		
		iterateElementList(componentElements, iterateAction);
		
	}
	
/* ************************************************************************************************************ 
 * 
 * 		Component: 		Banner Ad
 *		Requires:		brdApiAds.js
 *		
 *		Attributes:		id					- Identifier 
 *						component			- Type of Component
 *						class				- CSS Class that defines the container attributes for the ads:
 *													a. width
 *													b. height
 *													c. background-color
 *						
 *
 **************************************************************************************************************/
 

/*  Add Banner Ad Component Members * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function addBannerAdComponentMembers()
	{
		var componentElements 			= getElementsByComponent("bannerAd");
		var componentElement 			= "";
		var componentId					= "";
		var componentContainerClass		= "";
		
		if (componentElements.length > 0)
		{
			
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				
				componentElement 	= componentElements[ctr];
				
				// Check to see that the Component is not already constructed *****************************
				
				if (getComponentAttributeValue(componentElement, "constructed") != "true")
				{
					
					componentId				= getComponentAttributeValue(componentElement, "id");
					componentBannerClass 	= getComponentAttributeValue(componentElement, "bannerClass");
					
					setComponentAttributeValue(componentElement, "constructed", true);
					
					/* Members: ***************************************
					*	
					*	1. Link 					- Input: hidden
					*	2. Alt text 				- Input: hidden
					*	3. Ad Image					- Image
					*	4. Loading Container 		- Div
					*		4.1. Loading Image		- Image
					*	5. Ad Navigation Container	- Div
					*		5.1. Ad Nav. 			- Table
					*
					***************************************************/
					
					// 1. Link ******************************
					
					var linkMember 			= "";
					linkMember 				= document.createElement("input");
					linkMember.type			= "hidden";
					linkMember.id 			= "bannerAdLink"; // Add componentId to have more than one on a page
					linkMember.value		= "";
					
					componentElement.appendChild(linkMember);
					
					// 2. Alt Text ******************************
					
					var altTextMember 		= "";
					altTextMember 			= document.createElement("input");
					altTextMember.type		= "hidden";
					altTextMember.id 		= "bannerAdAlt"; // Add componentId to have more than one on a page
					altTextMember.value		= "";
					
					componentElement.appendChild(altTextMember);
					
					// 3. Ad Image ******************************
					
					var adImageMember 		= "";
					adImageMember 			= document.createElement("img");
					adImageMember.id 		= "bannerAdImage"; // Add componentId to have more than one on a page
					adImageMember.src		= "";
					adImageMember.border	= 0;
					adImageMember.style.display	= "none";
					
					componentElement.appendChild(adImageMember);
					
					// 4. Loading Container **********************
					
					var loadingContainerMember		= "";
					loadingContainerMember			= document.createElement("div");
					loadingContainerMember.id		= "bannerAdLoading"; // Add componentId to have more than one on a page
					
					loadingContainerMember.style.paddingTop = "50px";
					loadingContainerMember.align 			= "center";
					
						// 4.1 Loading Image ************************
						
						var loadingImageMemeber		= "";
						loadingImageMember			= document.createElement("img");
						loadingImageMember.src		= "/images/loadingGraphicIndicatorGrayBg.gif";
						
					loadingContainerMember.appendChild(loadingImageMember);
					
					componentElement.appendChild(loadingContainerMember);
				
				} // End Construction Check
				
			} // End For
		}
	}
	
/* ************************************************************************************************************ 
 * 
 * 		Component: 		Banner Ad
 *		Requires:		brdApiAds.js
 *		
 *		Attributes:		id					- Identifier 
 *						component			- Type of Component
 *						class				- CSS Class that defines the container attributes for the ads:
 *													a. width
 *													b. height
 *													c. background-color
 *						
 *
 **************************************************************************************************************/
 

/*  Add Banner Ad Component Members * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function addBannerAdComponentMembers()
	{
		var componentElements 			= getElementsByComponent("bannerAd");
		var componentElement 			= "";
		var componentId					= "";
		var componentContainerClass		= "";
		
		if (componentElements.length > 0)
		{
			
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				
				componentElement 	= componentElements[ctr];
				
				// Check to see that the Component is not already constructed *****************************
				
				if (getComponentAttributeValue(componentElement, "constructed") != "true")
				{
					
					componentId				= getComponentAttributeValue(componentElement, "id");
					componentBannerClass 	= getComponentAttributeValue(componentElement, "bannerClass");
					
					setComponentAttributeValue(componentElement, "constructed", true);
					
					/* Members: ***************************************
					*	
					*	1. Link 					- Input: hidden
					*	2. Alt text 				- Input: hidden
					*	3. Ad Image					- Image
					*	4. Loading Container 		- Div
					*		4.1. Loading Image		- Image
					*	5. Ad Navigation Container	- Div
					*		5.1. Ad Nav. 			- Table
					*
					***************************************************/
					
					// 1. Link ******************************
					
					var linkMember 			= "";
					linkMember 				= document.createElement("input");
					linkMember.type			= "hidden";
					linkMember.id 			= "bannerAdLink"; // Add componentId to have more than one on a page
					linkMember.value		= "";
					
					componentElement.appendChild(linkMember);
					
					// 2. Alt Text ******************************
					
					var altTextMember 		= "";
					altTextMember 			= document.createElement("input");
					altTextMember.type		= "hidden";
					altTextMember.id 		= "bannerAdAlt"; // Add componentId to have more than one on a page
					altTextMember.value		= "";
					
					componentElement.appendChild(altTextMember);
					
					// 3. Ad Image ******************************
					
					var adImageMember 		= "";
					adImageMember 			= document.createElement("img");
					adImageMember.id 		= "bannerAdImage"; // Add componentId to have more than one on a page
					adImageMember.src		= "";
					adImageMember.border	= 0;
					adImageMember.style.display	= "none";
					
					componentElement.appendChild(adImageMember);
					
					// 4. Loading Container **********************
					
					var loadingContainerMember		= "";
					loadingContainerMember			= document.createElement("div");
					loadingContainerMember.id		= "bannerAdLoading"; // Add componentId to have more than one on a page
					
					loadingContainerMember.style.paddingTop = "50px";
					loadingContainerMember.align 			= "center";
					
						// 4.1 Loading Image ************************
						
						var loadingImageMemeber		= "";
						loadingImageMember			= document.createElement("img");
						loadingImageMember.src		= "/images/loadingGraphicIndicatorGrayBg.gif";
						
					loadingContainerMember.appendChild(loadingImageMember);
					
					componentElement.appendChild(loadingContainerMember);
				
				} // End Construction Check
				
			} // End For
		}
	}

/*  Set Component Banner Ad Actions * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function setComponentBannerAdActions()
	{
		// Get All Member Elements **************************************
		var componentElements 			= getElementsByComponent("bannerAd");
		var componentElement 			= "";
		var componentId		 			= "";
		
		
		if (componentElements.length > 0)
		{
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				componentElement 		= componentElements[ctr];
				componentId				= getComponentAttributeValue(componentElement, "id");
				
				if (componentElement)
				{
					// On Mouse Over *************************
					componentElement.onmouseover = function()
					{
						this.style.cursor = "pointer";
					}
					
					// On Click *****************************
					componentElement.onclick = function()
					{
						location.href = getElement("bannerAdLink").value;	
					}
					
					// On Mouse Move ***********************
					componentElement.onmousemove = function()
					{
						altTextPopup(getElement("bannerAdAlt").value);	
					}
					
					// On Mouse Out ***********************
					componentElement.onmouseout = function()
					{
						this.style.cursor = "";
						hideElement("altTextPane");
					}
				}
			}
		}
	}

/* ************************************************************************************************************ 
 * 
 * 		Component: Image Button
 *		
 *		Attributes:		id					- Identifier 
 *						component			- Type of Component
 *						image				- Default image to display for the button
 *						hoverImage			- Image to display when the mouse is over the button
 *						imageClass			- Default CSS class
 *						imageHoverClass		- CSS class for "onmouseover" event
 *						onclickAction		- "onclick" action
 *						onMouseOverAction	- "onmouseover" action
 *
 **************************************************************************************************************/
 

/*  Add Image Button Component Members * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 	
	function addImageButtonComponentMembers()
	{
		var componentElements 			= getElementsByComponent("imageButton");
		var componentElement 			= "";
		var componentId					= "";
		var componentImage				= "";
		var componentClass				= "";
		
		if (componentElements.length > 0)
		{
			
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				
				componentElement 	= componentElements[ctr];
				
				// Check to see that the Component is not already constructed *****************************
				
				if (getComponentAttributeValue(componentElement, "constructed") != "true")
				{
					
					componentId				= getComponentAttributeValue(componentElement, "id");
					componentImage 			= getComponentAttributeValue(componentElement, "image");
					componentClass 			= getComponentAttributeValue(componentElement, "imageClass");
					
					setComponentAttributeValue(componentElement, "constructed", true);
					
					/* Members: ***************************************
					*	
					*	1. Image 			- Img
					*
					***************************************************/
					
					// 1. Image ******************************
					
					var imageMember 		= "";
					imageMember 			= document.createElement("img");
					imageMember.id 			= "imageButton_" + componentId; // Add componentId to have more than one on a page
					imageMember.src			= componentImage;
					imageMember.className	= componentClass;
					
					componentElement.appendChild(imageMember);
				
				} // End Construction Check
			
			}// End For
		}
	}
 
 /*  Set Component Image Button Actions * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function setComponentImageButtonActions()
	{
		// Get All Member Elements **************************************
		var componentElements 			= getElementsByComponent("imageButton");
		var componentElement 			= "";
		var componentId		 			= "";
		var componentImage				= "";
		var componentClass				= "";
		var componentHoverClass			= "";
		var componentHoverImage			= "";
		
		if (componentElements.length > 0)
		{
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				componentElement 		= componentElements[ctr];
				
				if (componentElement)
				{
					
					// On Mouse Over *************************
					componentElement.onmouseover = function()
					{
						componentClass 			= getComponentAttributeValue(componentElement, "imageClass");
						componentHoverClass 	= getComponentAttributeValue(this, "imageHoverClass");
						componentHoverImage 	= getComponentAttributeValue(this, "hoverImage");
						
						if (componentHoverClass == "")
						{
							componentHoverClass = componentClass;
						}
					
						var imageMember 		= getElement("imageButton_" + this.id);
						
						this.style.cursor 		= "pointer";
						imageMember.className 	= componentHoverClass;
						imageMember.src			= componentHoverImage;
						
						eval(getComponentAttributeValue(this, "onMouseOverAction"));
					}
					
					// On Click *****************************
					componentElement.onclick = function()
					{
						
						eval(getComponentAttributeValue(this, "onclickAction"));
					}
					
					// On Mouse Out ***********************
					componentElement.onmouseout = function()
					{
						componentImage 			= getComponentAttributeValue(this, "image");
						componentClass 			= getComponentAttributeValue(componentElement, "imageClass");
						
						var imageMember = getElement("imageButton_" + this.id);
						
						this.style.cursor 		= "";
						imageMember.className 	= componentClass;
						imageMember.src			= componentImage;
						
						hideElement("altTextPane");
					}
				}
			}
		}
	}

/* ************************************************************************************************************ 
 * 
 * 		Component: Question Icon Popup
 *		
 *		Attributes:		id					- Identifier 
 *						component			- Type of Component
 *						popupTitle          - Title of the popup
 *                      popupText           - Explanation text that appears in the popup.
 *
 **************************************************************************************************************/
 

/*  Add Question Icon Popup Component Members * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 	
	function addQuestionIconPopupComponentMembers()
	{
	    var componentElements 			= getElementsByComponent("questionIconPopup");
		var componentElement 			= "";
		var componentId					= "";
		var componentTitle				= "";
		var componentText				= "";
		
		if (componentElements.length > 0)
		{
			
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				
				componentElement 	= componentElements[ctr];
				
				// Check to see that the Component is not already constructed *****************************
				
				if (getComponentAttributeValue(componentElement, "constructed") != "true")
				{
					
					componentId				= getComponentAttributeValue(componentElement, "id");
					componentTitle 			= getComponentAttributeValue(componentElement, "popupTitle");
					componentText 			= getComponentAttributeValue(componentElement, "popupText");
					
					setComponentAttributeValue(componentElement, "constructed", true);
					
					/* Members: ***************************************
					*	
					*	1. Question Icon 			- Img
					*   2. Popup Div                - Div
					*
					***************************************************/
					
					    // 1. Question Icon ******************************
    					
					        var iconMember 		    = "";
					        iconMember 			    = document.createElement("img");
					        iconMember.id 			= "questionIcon_" + componentId; // Add componentId to have more than one on a page
					        iconMember.src			= "/images/questionIcon.png";
					        iconMember.style.cursor = "pointer";
    					    iconMember.width        = 15;
    					    iconMember.height        = 15;
    					     
					        componentElement.appendChild(iconMember);
					        
					  // 2. Popup Member *************************************
					  
					        var popupMember = document.createElement("div");
					        popupMember.id = "questionPopup_" + componentId;
					        popupMember.className = "questionPopupContainer";
					        
					        // Main Container *******************
					        
					            var popupContainer = document.createElement("div");
					            popupContainer.className = "questionPopupMainContainer";
					        
					            // Header **********************
    					            
					                var popupHeader = document.createElement("div");
					                popupHeader.className = "questionPopupHeader";
					                popupHeader.innerHTML = componentTitle;
    					            
					                popupContainer.appendChild(popupHeader);
    					       
					            // Body ******************************
    					            
					                var popupBody = document.createElement("div");
					                popupBody.className = "questionPopupBody";
					                popupBody.innerHTML = componentText;
    					            
					                popupContainer.appendChild(popupBody);
					                
					            popupMember.appendChild(popupContainer);
					          
					        // Arrow Down Table *************************
					        
					            var arrowDownTable = createTable(1, 3);
					            arrowDownTable.width = "252";
					            arrowDownTable.cellPadding = 0;
					            arrowDownTable.cellSpacing = 0;
					            
					            var row1 = arrowDownTable.rows[0];
					            row1.vAlign = "top";
					            
					            var cell1 = row1.cells[0];
					            var cell2 = row1.cells[1];
					            var cell3 = row1.cells[2];
					            
					            cell1.className = "arrowDownCell";
					            cell1.innerHTML = "&nbsp;";
					            cell1.width = "50%";
					            
					            cell2.innerHTML = "<img src=\"/images/questionArrowDown.png\" />";
					            cell2.width = 21;
					            
					            cell3.className = "arrowDownCell";
					            cell3.innerHTML = "&nbsp;";
					            cell3.width = "50%";
					            
					            popupMember.appendChild(arrowDownTable);
					            
    				        componentElement.appendChild(popupMember);    
    				        
    				    // Position *************************
    				    
    				        setPosX(popupMember, (getElementX(iconMember) - windowLeftOffset) - (getWidth(popupMember)/2) + getBrowserOffsetX() + 7);
					        setPosY(popupMember, getElementY(iconMember) - getHeight(popupMember) + getBrowserOffsetY());
    				
				} // End Construction Check
			
			}// End For
		}
	
	}

/*  Set Component Question Icon Popup Actions * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
 	function setComponentQuestionIconPopupActions()
	{
		// Get All Member Elements **************************************
		var componentElements 			= getElementsByComponent("questionIconPopup");
		var componentElement 			= "";
		var componentId					= "";
		var componentTitle				= "";
		var componentText				= "";
		
		if (componentElements.length > 0)
		{
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				componentElement 		= componentElements[ctr];
				
				if (componentElement)
				{
					componentId = componentElement.id;
						
			        var iconMember  = getElement("questionIcon_" + componentId);
						
					// On Mouse Over *************************
					iconMember.onmouseover = function()
					{
					    var thisComponentId = this.id.replace("questionIcon_", "");
						var popupMember = getElement("questionPopup_" + thisComponentId);
						showElement(popupMember.id);
						
					    setPosX(popupMember, (getElementX(this) - windowLeftOffset) - (getWidth(popupMember)/2) + getBrowserOffsetX() + 7);
					    setPosY(popupMember, getElementY(this) - getHeight(popupMember) + getBrowserOffsetY());
					    
					    showElement(popupMember.id);
					}
					
					// On Mouse Out ***********************
					iconMember.onmouseout = function()
					{
					    var thisComponentId = this.id.replace("questionIcon_", "");
						var popupMember = getElement("questionPopup_" + thisComponentId);
					    
					    hideElement(popupMember.id);
					}
				}
			}
		}
	}
	
/* ************************************************************************************************************ 
 * 
 * 		Component: Page Tabs Container
 *		
 *		Attributes:		component			- Type of Component
 *						dataForm			- (true|false) If true, additional component members are added to
 *											   facilitate automatic processing of form data.
 *                      enableSubmitBtn     - (true|false) (Requires: dataForm = true) Enables the submit button
 *                                            on the last page in the tab sequence.
 *                      submitFormBtnLabel  - (Requires: enableSubmitBtn = true) The text label that appears 
 *                                            on the last button in the page sequence.
 *						submitFormAction 	- (Requires: dataForm = true) Specifies a javascript function that 
 *											  gets called after user logs in and the form is submitted. This
 *                                            function must accept the global variable "formDataQueryString" as 
 *                                            a parameter. (EX: myFunction(formDataQueryString) )
 *
 *		NOTES:			Limitation - one per page.
 *
 **************************************************************************************************************/
 

/*  Set Page Tabs Container Component Members * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 	
	function setPageTabsContainerComponentMembers()
	{
		var componentElements 			= getElementsByComponent("pageTabsContainer");
		var componentElement 			= "";
		var componentId					= "";
		var componentClass				= "";
		
		if (componentElements.length > 0)
		{
			componentElement 	= componentElements[0]; // One Instance (Singleton Design Pattern)
			
			// Check to see that the Component is not already constructed *****************************
			if (getComponentAttributeValue(componentElement, "constructed") != "true")
			{
				
				var dataForm 			= getComponentAttributeValue(componentElement, "dataForm");
				var submitFormAction 	= getComponentAttributeValue(componentElement, "submitFormAction");
				
				// Set the default classes ******************************
				componentElement.id = "pageTabsContainer";
				componentElement.className = "pageTabsContainer";
				
				setComponentAttributeValue(componentElement, "constructed", true);
				
				// Build the Page Container ***************************
				var pageContainer = document.createElement("div");
				pageContainer.id = "formPageContainer";
				pageContainer.className = "formPageOuterContainer";
				
				var pageInnerContainer = document.createElement("div");
				pageInnerContainer.id = "formPageInnerContainer";
				pageInnerContainer.className = "formPageInnerContainer";
				
				var pageContentContainer = document.createElement("div");
				pageContentContainer.id = "formPageContentContainer";
				pageContentContainer.className = "formPageContentContainer";
				
				pageInnerContainer.appendChild(pageContentContainer);
				pageContainer.appendChild(pageInnerContainer);
				
				componentElement.parentNode.insertBefore(pageContainer, componentElement.nextSibling);
				
				// Add Addtional Members for Data Form **********************************
				
				if (dataForm == "true")
				{
					// Stores all the form data collected ****************
					var formDataElement = document.createElement("div");
					formDataElement.id = "formDataElements";
					
					componentElement.parentNode.insertBefore(formDataElement, pageContainer.nextSibling);
					
					// Define the onLoginSuccess function ****************
					var scriptContainer = document.createElement("script");
					scriptContainer.type = "text/javascript";
					
					scriptContainer.text = "function onLoginSuccess(clientIdValue) { sendFormDataToScript('" + submitFormAction + "', clientIdValue); }";
					
					document.body.appendChild(scriptContainer); 

				}
				
				// Set pageTab Actions *******************************
				setPageTabComponentMembers(componentElement);
				setPageTabComponentActions();
				
			} // End Construction Check
			
		}
	}
	
/*  Save Page Tab Form Data * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/

	function savePageTabFormData()
	{
	    var pageTabNo	= activePageTab.id.replace("pageTab", "");
		var pageElement = getElement("pageElement" + pageTabNo);
		var divElements = pageElement.getElementsByTagName("div");
		var errorThrown = false;
		
		var iterateAction = function(divElement, ctr)
		{
			if (isComponent(divElement))
			{
			    if (isVisible(divElement.id))
				{
					// Check Component Form Errors *************
					var dataType 		= getComponentAttributeValue(divElement, "dataType");
					var thisRequired 	= getComponentAttributeValue(divElement, "required");
					var requiredError	= false;
					var componentValue	= getComponentValue(divElement.id);
					var validateResult 	= true;
					
					componentValue = componentValue.replace("- Select -", "");
					
					// If this component is required and is blank and is visible then throw required error ************
					if ((thisRequired == "true") & (componentValue == "") & (divElement.style.display != "none"))
					{
						requiredError = true;
						errorThrown = true;
						validateResult = "This field is required! Please fill out all the required fields.";
					}
					else if (componentValue != "")queryStringToRequestFormArray
					{
					    // Validate Data, strip breaks ********************
					    componentValue = componentValue.replace(/\n\r?/g, "");
					    componentValue = componentValue.replace(/<br>/g, "");
					    componentValue = componentValue.replace(/<br \/>/g, "");
					    validateResult = dataIsValid(componentValue, dataType);
					}
					
					if (validateResult == true)
					{
						clearComponentError(divElement);
						addFormDataElement(divElement.id + "Value", componentValue);
					}
					else
					{
						throwComponentError(divElement, validateResult);
						errorThrown = true;
					}
				}
				else
				{
					// Remove Form Data *************
					addFormDataElement(divElement.id + "Value", "");
					
				} // isVisible
				
			} // isComponent
			
		}
		
		iterateElementList(divElements, iterateAction);
		
		if (!errorThrown)
		{
			setNextPageTab();
		}
	}

	
/*  Add Form Data Element * *******************************************************
 *
 *	TAKES:		Data Id, Data Value
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function addFormDataElement(dataId, dataValue)
	{
		var formDataElements = getElement("formDataElements");
		
		var existingElement = getElement(dataId);
		
		if (existingElement)
		{
			existingElement.parentNode.removeChild(existingElement);
		}
	    
	    // Escape the Malicous Chars *******************
	    dataValue = dataValue.replace(/\"/g, "&quot;");
	    dataValue = dataValue.replace(/</g, "");
	    dataValue = dataValue.replace(/>/g, "");
	    
		var hiddenElement = document.createElement("input");
		hiddenElement.setAttribute("type", "hidden");
		hiddenElement.setAttribute("id", dataId);
		hiddenElement.setAttribute("value", dataValue);
		
		formDataElements.appendChild(hiddenElement);
	}
	
/*  Send Form Data To Script * *******************************************************
 *
 *	TAKES:		Submit Action Value, Client Id Value
 * 	RETURNS:	NOTHING
 *	NOTES:		Bundles all the data in the "formDataElements" into id/value pairs
 *				and sends the form data to the processing script.
 *
 *************************************************************************/

	function sendFormDataToScript(submitActionValue, clientIdValue)
	{
	    if (clientIdValue != "")
		{
			var formDataElements = getElement("formDataElements").childNodes;
			var queryString = "&clientId=" + encodeQueryString(clientIdValue);
			
			var iterateAction = function(formDataElement, ctr)
			{
				var formDataId = formDataElement.id;
				formDataId = formDataId.replace("Value", "");
				
				var formDataValue = formDataElement.value;
				formDataValue = formDataValue.replace(/\n\r?/g, "");
		        formDataValue = formDataValue.replace(/<br>/g, "");
				formDataValue = formDataValue.replace(/<br \/>/g, "");
				
				queryString += "&" + formDataId + "=" + encodeQueryString(formDataValue);
			}
			
			iterateElementList(formDataElements, iterateAction);
			alert(queryString);
			formDataQueryString = queryString;
			eval(submitActionValue);
		}
	}

/* ************************************************************************************************************ 
* 
* 		Component: Page Tab
*		
*		Attributes:		component 			- Type of Component
*						tabLabel			- Label for the tab
*						activateAction		- The action that fires once the tab is activated
*						deactivateAction	- The action that fires once the tab is deactivated
*						onClickAction		- "onclick" action (differs from "activateAction" in that this action is
*										  	  fired on a physical mouse click of the tab.)
*						defaultState		- <blank>, inactive, active, completed
*						clickable			- (true|false) If true the tab is clickable and the that actions
*										   	   associated with the click action is fired.
*
*		Globals:		cancelTabActivation	- (true|false) Halts all current requests for tab activation. Automatically
*											  set back to "false" after one activation cancelation.
*
*		NOTES:			The "onClickAction" fires BEFORE the "activateAction", and only if "clickable" equals "true".
*
**************************************************************************************************************/
					
/*  Set Page Tab Component Members * *******************************************************
 *
 *	TAKES:		Page Tabs Container Component
 * 	RETURNS:	NOTHING
 *	NOTES:		Since we are only allowing on instance of Page Tabs, we 
 *				can assume that there is only one Page Content Container.
 *
 *************************************************************************/
 
	function setPageTabComponentMembers(pageTabsContainerComponent)
	{
		// Page Tabs Container Attributes **********************
		var enableSubmitBtn     = getComponentAttributeValue(pageTabsContainerComponent, "enableSubmitBtn");
		var submitFormBtnLabel  = getComponentAttributeValue(pageTabsContainerComponent, "submitFormBtnLabel");
		var submitFormAction    = getComponentAttributeValue(pageTabsContainerComponent, "submitFormAction");
		
		// Get All Member Elements **************************************
		var tabElements 			= getElementsByComponent("pageTab");
		var pageContentContainer	= getElement("formPageContentContainer");
		
		var dataForm 				= getComponentAttributeValue(pageTabsContainerComponent, "dataForm");
			
		
		var iterateAction = function(tabElement, ctr)
		{
		    if (getComponentAttributeValue(tabElement, "constructed") != "true")
		    {
		        var defaultState 	= getComponentAttributeValue(tabElement, "defaultState");
			    var footerBgColor	= getComponentAttributeValue(tabElement, "footerBgColor");
			    var pageElement 	= document.createElement("div");
			    pageElement.id 		= "pageElement" + ctr;
			    tabElement.id		= "pageTab" + ctr;
    			
    			var contentDiv          = document.createElement("div");
    			contentDiv.innerHTML    = tabElement.innerHTML;
			    tabElement.innerHTML    = "";
    			
    			pageElement.appendChild(contentDiv);
			    
			    
			    showElement(tabElement.id);
    			
			    if (defaultState != "active")
			    {
				    pageElement.style.display = "none";	
			    }
    			
			    // Data Form Navigation ******************************
    			
			    if (dataForm == "true")
			    {
				    var formNavContainer 					= document.createElement("div");
				    formNavContainer.style.padding 			= "10px";
				    formNavContainer.style.backgroundColor 	= "#f8f4d8";
    				
				    var formNavTable 	= createTable(1, 2);
				    var formNavCols		= formNavTable.getElementsByTagName("td");
    				
				    if (ctr > 0)
				    {
					    var backBtn = document.createElement("input");
					    backBtn.setAttribute("type", "button");
					    backBtn.setAttribute("value", "< Back to Prev.");
					    //backBtn.setAttribute("onclick", "setPrevPageTab()");
					    
					    formNavCols[0].appendChild(backBtn); 
				        
				        backBtn.onclick = setPrevPageTab;
    					
				    }
    				
				    if (ctr < (tabElements.length-1))
				    {
					    var saveContinueBtn = document.createElement("input");
					    saveContinueBtn.setAttribute("type", "button");
					    saveContinueBtn.setAttribute("value", "Save & Continue >");
					   // saveContinueBtn.setAttribute("onclick", "savePageTabFormData()");
					    
					    
					    formNavCols[1].align = "right";
					    formNavCols[1].appendChild(saveContinueBtn); 
				        
				        saveContinueBtn.onclick = savePageTabFormData;
    					
				    }
				    else if (enableSubmitBtn == "true")
				    {
				        var submitBtn = document.createElement("input");
					    submitBtn.setAttribute("type", "button");
					    
					    if (submitFormBtnLabel != "")
					    {
					        submitBtn.setAttribute("value", submitFormBtnLabel);
					    }
					    else
					    {
					        submitBtn.setAttribute("value", "Submit");
					    }
					    
					    // Action ******************
					    if (submitFormAction != "")
					    {
					        submitBtn.onclick = function()
					        {
					            savePageTabFormData();
					            sendFormDataToScript(submitFormAction, "0");   
					        }
					        
					        //submitBtn.setAttribute("onclick", "savePageTabFormData(); sendFormDataToScript('" + submitFormAction + "', '0')");
					    }
					    
					    formNavCols[1].align = "right";
					    formNavCols[1].appendChild(submitBtn); 
				    }
    				
				    formNavContainer.appendChild(formNavTable);
				    pageElement.appendChild(formNavContainer);
				    
				    // Append to Top as well ********************
				    //var clonedNav = formNavContainer.cloneNode(true);
				    //pageElement.insertBefore(clonedNav, pageElement.firstChild);
				    
			    }
    			
			    pageContentContainer.appendChild(pageElement);
		    }
		}
		
		iterateElementList(tabElements, iterateAction);
		
	}
					
/*  Set Page Tab Component Actions * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function setPageTabComponentActions()
	{
		// Get All Member Elements **************************************
		var componentElements 			= getElementsByComponent("pageTab");
		var componentElement 			= "";
		var componentId		 			= "";
		var componentClass				= "";
		var leftOffset					= 0;
		var topOffsetIE					= 0;
		var IEClass						= "";	
	
		if (IE)
		{
			IEClass = "IE";	
		}
		
		if (componentElements.length > 0)
		{
			for(var ctr=0; ctr<componentElements.length; ctr++)
			{
				componentElement 		= componentElements[ctr];
				
				if (getComponentAttributeValue(componentElement, "constructed") != "true")
				{
				    componentElement.setAttribute("constructed", "true");
				    
					var tabLabel 		= getComponentAttributeValue(componentElement, "tabLabel");
					var activeElement 	= getElement("pageElement" + ctr);
					var defaultState 	= getComponentAttributeValue(componentElement, "defaultState");
					
					// Member *************************************************
					
					var tabLabelElement = document.createElement("div");
					tabLabelElement.id = "pageTab" + ctr + "Label";
					tabLabelElement.className = "pageTabLabel" + IEClass;
					tabLabelElement.innerHTML = tabLabel;
					
					componentElement.appendChild(tabLabelElement);
					
					// Actions ***********************************************
					
					switch(defaultState)
					{
						case "inactive":
							componentElement.className = "pageTab" + IEClass;
							break;
						
						case "active":
							componentElement.className = "pageTab" + IEClass + "Active";
							tabLabelElement.className = "pageTabLabel" + IEClass + "Active";
							activePageTab = componentElement;
							break;
						
						case "completed":
							componentElement.className = "pageTabCompleted" + IEClass;
							break;
						
						default:
							componentElement.className = "pageTab" + IEClass;
							break;
						
					}
					
					// Left Offset ****************
					componentElement.style.left = leftOffset + "px";
					
					componentElement.onmouseover = function()
					{
						var clickable	 	= getComponentAttributeValue(this, "clickable");
						
						if ((clickable.toLowerCase() == "true") || (clickable == ""))
						{
							this.style.cursor = "pointer";	
						}
					}
					
					componentElement.onclick = function()
					{
						var clickable	 	= getComponentAttributeValue(this, "clickable");
						var onClickAction	 = getComponentAttributeValue(this, "onClickAction");
						
						if ((clickable.toLowerCase() == "true") || (clickable == ""))
						{
							eval(onClickAction);
							setActivePageTab(this);
						}
					}
					
				} // if constructed
			
			    leftOffset -= 2;
			}
			
		}
	}

/*  Set Active Page Tab * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function setActivePageTab(tabElement)
	{
		if (activePageTab != tabElement)
		{
			var thisTabNo = tabElement.id.replace("pageTab", "");
			var tabLabel = null;
			
			// Tab Styles **********************************
			
			// Deactivate the currently active tab ****************
			if (activePageTab != null)
			{
				// Deactivate Action ***************************************
				var deactivateAction = getComponentAttributeValue(activePageTab, "deactivateAction");
				
				if (deactivateAction != "")
				{
					eval(deactivateAction); // Opportunity to cancel the current tab activation
				}
				
				if (!cancelTabActivation)
				{
					// Deactivate Tab *****************************************
					tabLabel = getElement(activePageTab.id + "Label");
					activePageTab.className = activePageTab.className.replace("Active", "");
					tabLabel.className = tabLabel.className.replace("Active", "");
					
					// Enable Page Tab Click *********************
					setComponentAttributeValue(activePageTab, "clickable", "true");
				}
				
			}
			
			if (!cancelTabActivation)
			{
				activePageTab = tabElement;
				tabLabel = getElement(activePageTab.id + "Label");
				activePageTab.className = activePageTab.className + "Active";
				tabLabel.className = tabLabel.className + "Active";
				
				// Tab Page Content  **********************************
				hideAllActivePages();
				showElement("pageElement" + thisTabNo);
				
				// Active Action ***************************************
				var activateAction = getComponentAttributeValue(tabElement, "activateAction");
								
				if (activateAction != "")
				{
					eval(activateAction);	
				}
				
				scroll(0,0);
			}
			
			cancelTabActivation = false;
		}
	}
	
/*  Set Active Page Tab By Label * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function setActivePageTabByLabel(tabLabel)
	{
	    var pageTabContainer    = getElement("pageTabsContainer");
	    
	    if (pageTabContainer)
	    {
	        var pageTabElements     = getElementsByComponent("pageTab");
            
            var iterateAction = function(pageTabElement, ctr)
            {
                var labelValue = getComponentAttributeValue(pageTabElement, "tabLabel");
                
                if (labelValue == tabLabel)
                {
                    setActivePageTab(pageTabElement);
                }
            }
            
            iterateElementList(pageTabElements, iterateAction);
        }
	}

/*  Insert Page Tab * *******************************************************
 *
 *	TAKES:		Tab Title, Tab Content Element, Insert Index (zero based)
 * 	RETURNS:	Page Tab Element
 *  NOTES:      "-1" to append to the end of the tab list
 *
 *************************************************************************/
 	
	function insertPageTab(tabTitle, tabContentElement, insertIndex)
	{
	    var pageTabContainer    = getElement("pageTabsContainer");
	    
	    if (pageTabContainer)
	    {
	        var pageTabElements     = getElementsByComponent("pageTab");
    	    
    	    if (insertIndex > pageTabElements.length-1)
    	    {
    	        insertIndex = -1;
    	    }
    	    
    	    var newTab = document.createElement("div");
    	    newTab.setAttribute("component", "pageTab");
    	    newTab.setAttribute("tabLabel", tabTitle);
    	    newTab.appendChild(tabContentElement);
    	    
	        if (insertIndex == -1)
	        {
    	        pageTabContainer.appendChild(newTab);
	        }
	        else
	        {
	            for(var ctr=0; ctr<pageTabElements.length; ctr++)
	            {
	                if (ctr == insertIndex)
	                {
	                    pageTabContainer.insertBefore(newTab, pageTabElements[ctr]);
	                }
	            }
	        }
	        
	        setPageTabComponentMembers(pageTabContainer);
		    setPageTabComponentActions();
    	    
	        return newTab;
	   }
	    
	}
	
/*  Remove Page Tab * *******************************************************
 *
 *	TAKES:		Tab Element
 * 	RETURNS:	NOTHING
 *  NOTES:      
 *
 *************************************************************************/
 	
	function removePageTab(tabElement)
	{
	    if (isComponent(tabElement))
	    {
	        var pageTabContainer         = getElement("pageTabsContainer");
	        var formPageContentContainer = getElement("formPageContentContainer");
	        var tabElementContent        = getElement("pageElement" + tabElement.id.replace("pageTab", ""));
    	    
    	    var pageTabElements     = getElementsByComponent("pageTab");
    	    
    	    if (pageTabElements.length > 1)
    	    {
    	        var prevTab = pageTabElements[pageTabElements.length-2];
    	        
    	        activePageTab = null;
    	        pageTabContainer.removeChild(tabElement);
    	        formPageContentContainer.removeChild(tabElementContent);
    	        
    	        setActivePageTab(prevTab);
    	    }
    	}
	}
	
/*  Hide Page Tab * *******************************************************
 *
 *	TAKES:		Tab Element
 * 	RETURNS:	NOTHING
 *  NOTES:      Sets visibility and click-ability
 *
 *************************************************************************/
 
	function hidePageTab(tabElement)
	{
	    if (tabElement == activePageTab)
	    {
	        setPrevPageTab();
	    }
	    
	    setComponentAttributeValue(tabElement, "clickable", "false");
	    hideElement(tabElement.id);      
	}
	
/*  Show Page Tab * *******************************************************
 *
 *	TAKES:		Tab Element
 * 	RETURNS:	NOTHING
 *  NOTES:      Sets visibility and click-ability
 *
 *************************************************************************/
 
	function showPageTab(tabElement)
	{
	    setComponentAttributeValue(tabElement, "clickable", "true");
	    showElement(tabElement.id);
	    setActivePageTab(tabElement);
	}
	
/*  Set Next Page Tab * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function setNextPageTab()
	{
		var componentElements = getElementsByComponent("pageTab");
		var activeTabFound = false;
		
		var iterateAction = function(componentElement, ctr)
		{
			if (activeTabFound)
			{
				setActivePageTab(componentElement);
				activeTabFound = false;
			}
			else if (componentElement == activePageTab)
			{
				activeTabFound = true;
			}
		}
		
		iterateElementList(componentElements, iterateAction);
	}
	
/*  Set Prev Page Tab * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function setPrevPageTab()
	{
		var componentElements = getElementsByComponent("pageTab");
		var activeTabFound = false;
		var prevTab = null;
		
		var iterateAction = function(componentElement, ctr)
		{
			if ((componentElement == activePageTab) & (!activeTabFound))
			{
				activeTabFound = true;
				setActivePageTab(prevTab);
			}
			else
			{
				prevTab = componentElement;
			}
			
		}
		
		iterateElementList(componentElements, iterateAction);
	}

/*  Hide All Active Page * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 *************************************************************************/
 
	function hideAllActivePages()
	{
		var componentElements = getElementsByComponent("pageTab");
		
		var iterateAction = function(componentElement, ctr)
		{
			hideElement("pageElement" + ctr);
		}
		
		iterateElementList(componentElements, iterateAction);
		
	}
	
/* ************************************************************************************************************ 
 * 
 * 		Component: Query Table Functions                          
 *
 **************************************************************************************************************/

/*  Set Component Query Table Actions * *******************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *	NOTE:		
 *
 *************************************************************************/
 
 	function setComponentQueryTableActions(queryTableId)
	{
		var componentElement 			= getElement(queryTableId);
		var componentId					= "";
		var componentSearchBar			= "";
		var componentHeaderClass		= "";
		var componentRowClass			= "";
		var componentRowClassAlt		= "";
		var componentRowOnClickClass	= "";
		var componentRowOnMouseOverClass = "";
		var componentRowOnClick			= "";
		var componentRemoveRowAction	= "";
		var componentQueryTag			= "";
		var componentPageMax			= "";
		
		if (componentElement)
		{
			componentId						= getComponentAttributeValue(componentElement, "id");
			componentSearchBar				= getComponentAttributeValue(componentElement, "searchBar");
			componentQueryTag				= getComponentAttributeValue(componentElement, "queryTag");
			componentPageMax				= getComponentAttributeValue(componentElement, "pageMax");
			componentHeaderClass			= getComponentAttributeValue(componentElement, "headerClass");
			componentRowClass				= getComponentAttributeValue(componentElement, "rowClass");
			componentRowClassAlt			= getComponentAttributeValue(componentElement, "rowClassAlt");
			componentRowOnClickClass		= getComponentAttributeValue(componentElement, "rowOnClickClass");
			componentRowOnMouseOverClass	= getComponentAttributeValue(componentElement, "rowOnMouseOverClass");
			componentRowOnClick				= getComponentAttributeValue(componentElement, "rowOnClick");
			componentRemoveRowAction		= getComponentAttributeValue(componentElement, "removeRowAction");
			
			setComponentAttributeValue(componentElement, "constructed", true);
			
			var rowElements = componentElement.getElementsByTagName("tr");
			var rowElement = "";
			var currentRowClass = componentRowClass;
			
			if (rowElements.length > 0)
			{
				for(var ctrAlt=0; ctrAlt<rowElements.length; ctrAlt++)
				{
					rowElement = rowElements[ctrAlt];
					
					if (rowElement.id.indexOf("rowHeader") != -1)
					{
						// Row Class
						rowElement.className = componentHeaderClass;
						
						// Column Element
						var columnElements = rowElement.getElementsByTagName("td");
						var columnElement = "";
						var columnSort = "";
						
						if (columnElements.length > 0)
						{
							for(var ctrCol=0; ctrCol<columnElements.length; ctrCol++)
							{
								columnElement 	= columnElements[ctrCol];
								
								if (columnElement.id.indexOf("Sortable") != -1)
								{
									columnElement.onmouseover = function()
									{
										this.style.cursor = "pointer";
									}
									
									columnElement.onmouseout = function()
									{
										this.style.cursor = "";	
									}
									
									columnElement.onclick = function()
									{
										var searchString 	= getQueryTableSearchString(componentId);
										var thisDirection 	= getQueryTableDirection(componentId);
										var currentPageNum 	= getCurrentQueryTablePage(componentId);
										
										// Toggle New Direction ***************
										if (thisDirection == "ASC")
										{
											thisDirection = "DESC"
										}
										else
										{
											thisDirection = "ASC"
										}
										
										searchQueryTable(queryTableId, this.id, thisDirection, searchString, currentPageNum);
										
									}
								}
							}
						}
						
					}
					else if (rowElement.id.indexOf("row") != -1)
					{
						// Row ***********************************
						if (rowElement.id.indexOf("SearchBar") == -1)
						{
							// Row Class
							rowElement.className = currentRowClass;
							
							// OnClick Actions *********************************
							
							rowElement.onclick = function()
							{
								if ((!disableQueryRowClickAction) & (componentRowOnClick != ""))
								{
									if (currentRowSelected != "")
									{
										currentRowSelected.className = currentRowSelectedClassSaved;
									}
									
									currentRowSelected = this;
									currentRowSelectedClassSaved = currentRowClassSaved;
									
									this.className = componentRowOnClickClass;
									
									eval(componentRowOnClick);
								}
							}
							
							// OnMouseOver Actions *********************************
							
							rowElement.onmouseover = function()
							{
								if (this != currentRowSelected)
								{
								    if (componentRowOnMouseOverClass != "")
								    {
									    currentRowClassSaved = this.className;
									    this.className = componentRowOnMouseOverClass;	
								    }
								}
							}
							
							// OnMouseOut Actions *********************************
							
							rowElement.onmouseout = function()
							{
								if (this != currentRowSelected)
								{
									if (componentRowOnMouseOverClass != "")
								    {
									    this.className = currentRowClassSaved;
									    currentRowClassSaved = "";
								    }
								}
							}
							
							// Remove Row Actions ********************************
							
							if (componentRemoveRowAction != "")
							{
								var removeElement = getElement(componentId + ".removeRow." + rowElement.id.replace("row", ""));
								
								removeElement.onmouseover = function()
								{
								    disableQueryRowClickAction = true;
								}
								
								removeElement.onmouseout = function()
								{
									disableQueryRowClickAction = false;	
								}
								
								removeElement.onclick = function()
								{
								   // alert(this.id);
								    var rowNum = this.id.replace(componentId + ".removeRow.", "");
								    componentRemoveRowAction = getComponentAttributeValue(getElement(componentId), "removeRowAction");
								    componentRemoveRowAction = componentRemoveRowAction.replace("(this)", "(getElement('row" + rowNum + "'))");
									//alert(componentRemoveRowAction );
									eval(componentRemoveRowAction);
								}
							}
							
							if (currentRowClass == componentRowClass)
							{
								currentRowClass = componentRowClassAlt;
							}
							else
							{
								currentRowClass = componentRowClass;
							}
							
						} // rowElement indexOf
						
					} // if rowHeader then
						
				} // for rowElements
				
			} // if rowElements 
			
			// Table Index Actions ------------------------
			rowElements = getTagGroup("div", queryTableId + "pageNum");
			
			if (rowElements.length > 0)
			{
				for(ctr=0; ctr<rowElements.length; ctr++)
				{
					rowElement = rowElements[ctr];
					
					// Mouse Over Actions -------------------------
					rowElement.onmouseover = function()
					{
						var pageNum = getCurrentQueryTablePage(queryTableId);
						var newPageNum = this.id.replace("pageNum", "");
						newPageNum = newPageNum.replace(queryTableId, "");
						
						if (pageNum != newPageNum)
						{
							this.className = "tableIndexNumHover";
							this.style.cursor = "pointer";
						}
					}
					
					// Mouse Out Actions -------------------------
					rowElement.onmouseout = function()
					{
						var pageNum = getCurrentQueryTablePage(queryTableId);
						var newPageNum = this.id.replace("pageNum", "");
						newPageNum = newPageNum.replace(queryTableId, "");
						
						if (pageNum != newPageNum)
						{
							this.className = "tableIndexNum";
							this.style.cursor = "";
						}
					}
					
					// On Click Actions -------------------------
					rowElement.onclick = function()
					{
						var searchString 	= getQueryTableSearchString(queryTableId);
						var thisDirection 	= getQueryTableDirection(queryTableId);
						var thisSortBy		= getQueryTableSortBy(queryTableId);
						
						var pageNum = getCurrentQueryTablePage(queryTableId);
						var newPageNum = this.id.replace("pageNum", "");
						newPageNum = newPageNum.replace(queryTableId, "");
						
						if (newPageNum == "First")
						{
							newPageNum = 1
						}
						else if (newPageNum.indexOf("Last") != -1)
						{
							 newPageNum = newPageNum.replace("Last", "");
						}
						
						pageNum = newPageNum;
						searchQueryTable(queryTableId, thisSortBy, thisDirection, searchString, pageNum);
					}
				}
			}	
			
		} // if componentElements
		
	}

 /* Get Current Query Table Page ********************************************************
 *
 *	TAKES:		Query Table Id
 * 	RETURNS:	Current Page Number
 *	NOTE:		
 *
 ********************************************************************************/
 
	function getCurrentQueryTablePage(queryTableId)
	{
		var currentPageNumElement = getElement(queryTableId + "CurrentPageNum");
		var currentPageNum = 1;
		
		if (currentPageNumElement)
		{
			currentPageNum = currentPageNumElement.value;
		}
		
		return currentPageNum;
	}

 /* Get Query Table Search String ********************************************************
 *
 *	TAKES:		Query Table Id
 * 	RETURNS:	Search String
 *	NOTE:		
 *
 ********************************************************************************/
 
	function getQueryTableSearchString(queryTableId)
	{
		var searchString = "";
		
		if (getElement(queryTableId + "SearchString"))
		{
			searchString = getElement(queryTableId + "SearchString").value;
		}
		
		return searchString;
	}
	
 /* Get Query Table Direction ********************************************************
 *
 *	TAKES:		Query Table Id
 * 	RETURNS:	Direction String
 *	NOTE:		
 *
 ********************************************************************************/
 
	function getQueryTableDirection(queryTableId)
	{
		var directionString = "";
		
		if (getElement(queryTableId + "Direction"))
		{
			directionString = getElement(queryTableId + "Direction").value;
		}
		
		return directionString;
	}
	
 /* Get Query Table SortBy ********************************************************
 *
 *	TAKES:		Query Table Id
 * 	RETURNS:	SortBy String
 *	NOTE:		
 *
 ********************************************************************************/
 
	function getQueryTableSortBy(queryTableId)
	{
		var sortByString = "";
		
		if (getElement(queryTableId + "SortBy"))
		{
			sortByString = getElement(queryTableId + "SortBy").value;
		}
		
		return sortByString;
	}
	
 /* Next Page Query Table ********************************************************
 *
 *	TAKES:		Query Table Id
 * 	RETURNS:	NOTHING
 *	NOTE:		Used in the index paging of the Query Table
 *
 ********************************************************************************/
 
	function nextPageQueryTable(queryTableId)
	{
		var searchString 	= getQueryTableSearchString(queryTableId);
		var thisDirection 	= getQueryTableDirection(queryTableId);
		var thisSortBy		= getQueryTableSortBy(queryTableId);
						
		var thisPageNum = parseInt(getCurrentQueryTablePage(queryTableId));
		var allPagesNum = parseInt(getElement(queryTableId + "NumPages").value);
		thisPageNum += 1;
		
		if (thisPageNum > allPagesNum)
		{
			thisPageNum = allPagesNum;
		}
		
		searchQueryTable(queryTableId, thisSortBy, thisDirection, searchString, thisPageNum);
	}

 /* Prev Page Query Table ********************************************************
 *
 *	TAKES:		Query Table Id
 * 	RETURNS:	NOTHING
 *	NOTE:		Used in the index paging of the Query Table
 *
 ********************************************************************************/
 
	function prevPageQueryTable(queryTableId)
	{
		var searchString 	= getQueryTableSearchString(queryTableId);
		var thisDirection 	= getQueryTableDirection(queryTableId);
		var thisSortBy		= getQueryTableSortBy(queryTableId);
						
		var thisPageNum = parseInt(getCurrentQueryTablePage(queryTableId));
		thisPageNum -= 1;
		
		if (thisPageNum <= 0)
		{
			thisPageNum = 1;
		}
		
		searchQueryTable(queryTableId, thisSortBy, thisDirection, searchString, thisPageNum);
	}

 /* Search Query Table ********************************************************
 *
 *	TAKES:		Query Table Id, Query Tag, Page Max
 * 	RETURNS:	NOTHING
 *	NOTE:		
 *
 ********************************************************************************/
 
 	function searchQueryTable(queryTableId, sortBy, direction, searchString, pageNum)
	{
		var componentElement 			= getElement(queryTableId);
		var componentQueryTag			= "";
		var componentQueryTagDataKey	= "";
		var componentQueryTagDataKeyValue = "";
		var componentPageMax			= "";
		var componentSearchCallback		= ""; // Called after the search is completed
		var componentRemoveRowAction	= "";
		
		if (componentElement)
		{
			componentQueryTag				= getComponentAttributeValue(componentElement, "queryTag");
			componentQueryTagDataKey		= getComponentAttributeValue(componentElement, "queryTagDataKey");
			componentQueryTagDataKeyValue	= getComponentAttributeValue(componentElement, "queryTagDataKeyValue");
			componentPageMax				= getComponentAttributeValue(componentElement, "pageMax");
			componentSearchCallback			= getComponentAttributeValue(componentElement, "searchCallback");
			componentRemoveRowAction		= getComponentAttributeValue(componentElement, "removeRowAction");
		}
		
		var callback = "";
		
		var queryVars = "&tag=" + componentQueryTag;
		queryVars += "&pageMax=" + componentPageMax;
		queryVars += "&sortBy=" + sortBy;
		queryVars += "&direction=" + direction;
		queryVars += "&searchString=" + searchString;
		queryVars += "&queryTableId=" + queryTableId;
		queryVars += "&pageNum=" + pageNum;
		queryVars += "&dataKey=" + componentQueryTagDataKey;
		queryVars += "&dataKeyValue=" + componentQueryTagDataKeyValue;
		
		if (componentRemoveRowAction != "")
		{
			queryVars += "&enableRemoveRow=true";
		}
		
		setAjaxUrl(queryTableId + "QueryTableResults", "/Includes/api/brdApiQuery.asp?action=runQueryTable" + queryVars , "setLoadingGraphic('" + queryTableId + "QueryTableResults');", "setComponentQueryTableActions('" + queryTableId + "'); " + componentSearchCallback);
		
	}
	
 /* Search Query Table ********************************************************
 *
 *	TAKES:		Query Table Id
 * 	RETURNS:	NOTHING
 *	NOTE:		
 *
 ********************************************************************************/
 
 	function resetQueryTable(queryTableId)
	{
		// Clear out search string ************************
		if (getElement(queryTableId + "SearchString"))
		{
			getElement(queryTableId + "SearchString").value = "";
		}
		
		searchQueryTable(queryTableId, "", "", "", 1);
	}

 /* Search Term Query Table ********************************************************
 *
 *	TAKES:		Query Table Id, Search String
 * 	RETURNS:	NOTHING
 *	NOTE:		
 *
 ********************************************************************************/
 
 	function searchTermQueryTable(queryTableId)
	{
		var searchString = getElement(queryTableId + "SearchString").value;
		searchQueryTable(queryTableId, "", "", searchString, 1);
	}
	
 /* Get Component Query Table ********************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *	NOTE:		Set up for Query Table component
 *
 ********************************************************************************/
 
 	function getComponentQueryTables()
	{
		var componentElements 			= getElementsByComponent("queryTable");
		var componentElement 			= "";
		var componentId					= "";
		var searchBarClass				= "";
		var searchBar					= "";
		var onLoadCallback				= "";
		
		if (componentElements.length > 0)
		{
	        for(var ctr=0; ctr<componentElements.length; ctr++)
		    {
			    componentElement 		= componentElements[ctr];
			    componentId				= getComponentAttributeValue(componentElement, "id");
			    searchBar				= getComponentAttributeValue(componentElement, "searchBar");
			    searchBarClass			= getComponentAttributeValue(componentElement, "searchBarClass");
			    pageMax					= getComponentAttributeValue(componentElement, "pageMax");
			    onLoadCallback			= getComponentAttributeValue(componentElement, "onLoadCallback");
			    removeRowAction			= getComponentAttributeValue(componentElement, "removeRowAction");
				
				if (getComponentAttributeValue(componentElement, "constructed") != "true")
		        {
			        var queryVars = "&queryTableId=" + componentId;
			        queryVars += "&searchBarClass=" + searchBarClass;
			        queryVars += "&searchBar=" + searchBar;
			        queryVars += "&pageMax=" + pageMax;
    				
			        // Setup the Search Field Key Actions ****************************
			        if (searchBar == "true")
			        {
				        addKeyUpEvent(searchBarKeyUp);
			        }
    				
			        // Remove Row Flag ****************
			        if (removeRowAction != "")
			        {
				        queryVars += "&enableRemoveRow=true";
			        }
    				
			        // Build the Table and Search Bar ********************************
			        setAjaxUrl(componentId, "/Includes/api/brdApiQuery.asp?action=getQueryTable" + queryVars, false, "setBrdButtonActions(); searchQueryTable('" + componentId + "', \"\", \"\", \"\", 1); " + onLoadCallback);
		        }
		    }
		
		}
	}

/* Delete Query Data ********************************************************
 *
 *	TAKES:		Query Data Container, Unique Data Id
 * 	RETURNS:	NOTHING
 *	NOTE:		Removes the data accessors from the Query Data Container
 *
 ********************************************************************************/
 
 	function deleteQueryData(queryDataContainerId, uniqueDataId)
	{
		// Remove from the data container **************************
		
		if ((queryDataContainerId != "") & (uniqueDataId != ""))
		{
			var queryDataContainer 	= getElement(queryDataContainerId);
			
			var queryInputElements = queryDataContainer.getElementsByTagName("input");
			var queryInputElement = "";
			
			if (queryInputElements.length > 0)
			{
				for(var ctr=0; ctr<queryInputElements.length; ctr++)
				{
					queryInputElement = queryInputElements[ctr];
					
					if (queryInputElement.id.indexOf(uniqueDataId) != -1)
					{
						queryDataContainer.removeChild(queryInputElement);
					} 
					
				}
				
			} // if fileInputElements.length
		
		} // if Main
	
	}


/* Update Query Data ********************************************************
 *
 *	TAKES:		Component Id, Query Tag, Component Value, Unique Data Id
 * 	RETURNS:	NOTHING
 *	NOTE:		Uses query profiles to update the component values in the 
 *				database.
 *
 ********************************************************************************/
 
 	function updateComponentData(componentId, updateQueryTag, componentValue, uniqueDataId)
	{
		componentValue = componentValue.replace(/\n/g, "<br>");
		componentValue = encodeQueryString(componentValue); 
		
		var queryVars = "thisId=" + componentId;
		queryVars += "&thisValue=" + componentValue;
		queryVars += "&uniqueId=" + uniqueDataId;
		queryVars += "&queryTag=" + updateQueryTag;
		
		setAjaxUrl("updateData", "/Includes/api/brdApiQuery.asp?action=updateQueryValue&" + queryVars, false, false);
	}

/* Search Bar Key Up ********************************************************
 *
 *	TAKES:		Keystroke Event
 * 	RETURNS:	NOTHING
 *	NOTE:		The search bar is setting the value "currentFocus" to the id of 
 *				the query table.
 *
 ********************************************************************************/
 
	function searchBarKeyUp(e)
	{
		if (!e) e = window.event;
		
		if (e.keyCode == 13) // Enter Key
		{
			if (currentFocus.match("SearchString") != null)
			{
				var thisQueryTableId 	= currentFocus.replace("SearchString", "");
				searchTermQueryTable(thisQueryTableId);
			}
		}
	}
	
/*  Get Query Table Value * **************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 ****************************************************************************************/
 
    function getQueryTableValue(rowElement, valueId)
    {
        var tableValue = "";
        
        if (rowElement)
        {
            var rowId = rowElement.id.replace("row", "");
            var queryTableComponents = getElementsByComponent("queryTable");
            
            if (queryTableComponents.length > 0)
            {
                var queryTableComponent = queryTableComponents[0];
               
                var tableValueElement = getElement(queryTableComponent.id + "." + valueId + "." + rowId); 
               
                if (tableValueElement)
                {
                    if (tableValueElement.tagName == "INPUT")
                    {
                        tableValue = tableValueElement.value;
                    }
                    else
                    {
                        tableValue = tableValueElement.innerHTML;
                    }
                }
            }
        }
        
        return tableValue;
    }
  
 /* Clear Current Selected Query Table Row * **************************************************
 *
 *	TAKES:		NOTHING
 * 	RETURNS:	NOTHING
 *
 ****************************************************************************************/
 
    function clearCurrentSelectedQueryTableRow()
    {
        if (currentRowSelected != "")
        {
            currentRowSelected.className = currentRowSelectedClassSaved;
            currentRowSelected = "";
        }
    }

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	