// This Javascript is necessary for the checkDrop.cfm custom tag to work.

		   intCurrentDropdown = -1;
		   anyMatchValue = -1;
		
		// arrayManualInputs will hold objects containing related IDs to check for automatic hiding of manual dropdowns
		   arrayManualInputs = new Array();
		   arrayCheckdropPrefixes = new Array();
			
		// f: updateManualDropdown
		function updateManualDropdown( dropdown ){
			
		
			if( typeof dropdown == "string"){
			
				dropdown = document.getElementById(dropdown);
			
			}
			
			// Parse prefix 
			var prefix = dropdown.id.split('_');
				prefix = prefix[0];
			
			var arrayCurrentValues = new Array();
			
			var valueToUpdate = prefix + "Value";
			
			//var valueToUpdate = valuesFauxSelect[0].divValue;
			
			// Loop through the corresponding object array and find the match, extract the display value, 
				//and update the display of the value and the hidden form fields that represent the checkbox assortment
				
			var currentValuesArray = eval(prefix + 'ValuesArray');
			
			var allConverter = false;
			
			// Check for and enforce the all option
			if ( document.getElementById( '' + prefix + '_All' ) != null ){
			
				// If it was selected
				if( document.getElementById( '' + prefix + '_All' ) == dropdown ){
				
					document.getElementById( '' + prefix + '_All' ).checked = true;
				
					// Loop through the dropdown's values and clear other checks
					for ( var i = 1; i < currentValuesArray.length; i++ ){
				
						if (document.getElementById('' + prefix + '_' + currentValuesArray[i].key) != prefix + '_All'){
							
							document.getElementById('' + prefix + '_' + currentValuesArray[i].key).checked = false;
						
						}
				
					}
				
				} else { 
				
					// If nothing else is selected (usually on page serve), leave it checked.
					if( ! dropdown.checked ){
					
					} else {
				
					// If something else was selected
					document.getElementById( '' + prefix + '_All' ).checked = false;
			
					}
			
				}
			
			}
			
			
				
			// Loop through the dropdown's values and build a new value 	
			for ( var i = 0; i < currentValuesArray.length; i++ ){
			
				//alert(document.getElementById('' + prefix + '_' + currentValuesArray[i].key).id);	
				
				// If a checkbox is selected, add it to the current values array for display
				if ( document.getElementById('' + prefix + '_' + currentValuesArray[i].key).checked ){
					
					arrayCurrentValues.push( currentValuesArray[i].label );
				
				}
				
			}
			
			// If no values are checked, attempt to update the any/all option:
			if (arrayCurrentValues.length == 0){
			
				if ( document.getElementById( '' + prefix + '_All' ) != null ){
				
					// Check the option
					document.getElementById( '' + prefix + '_All' ).checked = true;
					
					// Add the "all" value to the array to update the textual display
					arrayCurrentValues.push( currentValuesArray[0].label );
					
				}
				
			}
			
			
			// Update the visual display for users
			document.getElementById(valueToUpdate).innerHTML = buildDisplayStringForManualDropdowns( arrayCurrentValues );
		
		}
		// x: updateManualDropdown
		
		
		// f: buildDisplayStringForManualDropdowns
		function buildDisplayStringForManualDropdowns(selectedDisplayStrings){
			
			var stringCurrentValue = "";
			var firstItem = true;
			
			// Loop through selectedDisplayStrings and build an x charactered string
			for (var i = 0; i < selectedDisplayStrings.length; i++){
			
				if ( firstItem ){
					
					stringCurrentValue += selectedDisplayStrings[i];
					firstItem = false;
				
				} else {
					
					stringCurrentValue += ", " + selectedDisplayStrings[i];
				
				}
				
			}
			
			// Format the new string for display
			if ( stringCurrentValue.length >= 15 )				
				return stringCurrentValue.substr( 0, 15 ) + '...';
			else 
				return stringCurrentValue;
			
			
		}
		// x: buildDisplayStringForManualDropdowns	
			
			
		// f: closeAndRecalculateAllCheckboxDropdowns
		function closeAndRecalculateAllCheckboxDropdowns(e){
		
			//alert(intCurrentDropdown);
		
			//e.stopPropagation();
			//if ( e.srcElement != null )
			if ( mode.match('IE') != null )
			{
			
				//alert("IE");
				trigger = e.srcElement.id;
			
			}
			
			//( e.target )
			if ( mode.match('Normal') != null )
			{
		
				//alert("Non-IE");
				trigger = e.target.id;
			
			}
			
			//alert( "intCurrentDropdown: " + intCurrentDropdown + "\ntrigger: " + trigger);
			
			// If something without an ID triggered the click, hide the current dropdown
			if(trigger == '' && intCurrentDropdown != -1){
			
				//alert("Blank");
				document.getElementById(  arrayManualInputs[intCurrentDropdown][0]  ).style.display = "none";
			
			}
			
			
			// Refresh the catch all
			anyMatchValue = -1;
			
			
			// Loop through the manual form IDs and find a match.
			for( var i = 0; i < arrayManualInputs.length; i++){
			
				matchPoint = findInArray( trigger, arrayManualInputs[i] );
			
				//alert('Testing: ' + trigger + ' vs. ' + arrayManualInputs[i] + '\n' + matchPoint );
			
				if ( matchPoint != -1 ){
				
					// Set the trigger flag to hide a current dropdown on lost focus
					anyMatchValue = i;
				
					if( anyMatchValue != intCurrentDropdown && intCurrentDropdown != -1){
				
						document.getElementById(  arrayManualInputs[intCurrentDropdown][0]  ).style.display = "none";
					
					}
					
					// Update the current dropdown
					intCurrentDropdown = i;
				
				}
				
			}
			
			
			// Any match
			if (anyMatchValue == -1 && intCurrentDropdown != -1){
			
				// If no match was made, hide the previous manual dropdown
				document.getElementById(  arrayManualInputs[intCurrentDropdown][0]  ).style.display = "none";
				
				//alert("intCurrentDropdown = " + "-1");
				
				intCurrentDropdown = -1;
			
			}
			
			//alert(intCurrentDropdown);
		
		}
		// x: closeAndRecalculateAllCheckboxDropdowns
		
		
				// f: findInArray
				function findInArray( criteria, arrayToSearch ){
				
					// Loop through the array and search for a match
					for ( var i = 0; i < arrayToSearch.length; i++ ){
					
						//alert("Searching : " + criteria + " vs. " + arrayToSearch[i]);
					
						if ( criteria == arrayToSearch[i] ){
						
							return i;
						
						}
					
					}	
				
					return -1;
						
				}
				// x: findInArray
		
				// f: toggle
				function toggle(target, display){
				
					// You can pass inline, block, etc. as a display parameter
					if (display == undefined )
						display = "inline";
				
					target = document.getElementById(target);
					
					if (target.style.display != "none" && target.style.display != ""){
					
						target.style.display = "none";
						//document.getElementById('mute').style.display = "none";
					
					}
					
					else {
					
						target.style.display = display;
						//document.getElementById('mute').style.display = display;
					
					}
						
				}	
				// x: toggle
				
				// f: resetCheckDrops
				function resetCheckDrops(){
					
					for ( x = 0; x < arrayCheckdropPrefixes.length; x++){
						
							for ( i = 0; i < eval(arrayCheckdropPrefixes[x] + 'ValuesArray').length; i++){
							
								var id = arrayCheckdropPrefixes[x] + "_" + eval(arrayCheckdropPrefixes[x] + 'ValuesArray')[i].key;

								document.getElementById(id).checked = false;
								
								
								// Update the value on the last item in each dropdown
								if ( i == eval(arrayCheckdropPrefixes[x] + 'ValuesArray').length - 1 ){
									
									updateManualDropdown(id);
								
								}
								
								//alert(id + " | " + document.getElementById(id).checked);
							
							}
							
					}
					
				}
				// x: resetCheckDrops
				
				
				// h: Ext.onReady
				Ext.onReady(function() {
						
					// Test all click events before processing
					if(window.addEventListener){ // Mozilla, Netscape, Firefox
				
						mode = 'Normal';
						document.body.addEventListener('click', closeAndRecalculateAllCheckboxDropdowns, false);
						
					} else { // IE
				
						mode = 'IE';
						document.body.attachEvent('onclick', closeAndRecalculateAllCheckboxDropdowns);
						
					}
					
					//Ext.get('fauxSelectOptions').setOpacity(.96);
					
				});
				// x: Ext.onReady

		