// fvshowall.js

		function closeMoreOverlay(anElement){
		if (cmmodal) {
				buildMultiFacetRequestFromDOM();
				cmmodal.close();
				cmmodal = null;			
				document.body.removeChild(document.getElementById('showAllContent'));
			}
		}

		function buildMultiFacetRequestFromDOM(){
				
			//Get the more form and get the selected elements from it. 
			var moreForm = document.getElementById('more-overlay-form');
			var parameters = '&ps='+facetContext.psValue;
			var mfvParams = '&mfv='+ facetContext.selectedFacetId;
			var removelid = fixEscape(moreForm.removeAllValuesForShowAll.value);
			if (facetContext.sidValue != ""){
				facetContext.sidValue = facetContext.sidValue.replace('+','*');
				parameters = parameters + '&sid='+facetContext.sidValue;
			}
			
			var itemsSelected = false;
			var selectionsChanged = false;
			//Now iterate over the listItems to find out what 
			if (moreForm != null){
				//Now get the list itmes
				var listItems = moreForm.getElementsByTagName('li');
				var theID;
				//For each item we need to determine if they are selected or not and use a new attribute
				//to send this information to the server
				if (listItems.length > 0){				
					for (i=0;i<listItems.length;i++){
						if(listItems[i].className.indexOf('selected') > -1){
							mfvParams = mfvParams + ';' + getIdForInputField(listItems[i]);
							itemsSelected = true;	
							//If a new selection it will not have an id
							if (listItems[i].getAttribute('id') == null || listItems[i].getAttribute('id') == ''){								  											
								selectionsChanged=true;
							}						
						} else {
							//We need to check if the change has been to deselect everything, i.e. not selected by we previously
							if (listItems[i].getAttribute('id') != null && listItems[i].getAttribute('id').indexOf('_prev') > -1 ){
								selectionsChanged = true;
							}						
						}						  				
	  				}
	  				//If itemsSelected then send the selections
	  				if(selectionsChanged){
	  					if(itemsSelected){	  					
		  					navigate(this,facetContext.baseURL+parameters+mfvParams, true);
	  					}else{
	  						navigate(this,facetContext.baseURL.substring(0,facetContext.baseURL.indexOf('&lid'))+'&lid='+removelid+parameters, true);
	  					}	  				
	  				}
				}
			}
		}

		function getIdForInputField(aListItem){
			var itemID = '';
			if (aListItem.getElementsByTagName('input').length > 0){
				itemID = (aListItem.getElementsByTagName('input')[0]).getAttribute('id');
			}				
			return itemID.replace('_more','');
			
		}
		
