	function submitMenuChanges(){
		addMenuDataToHiddenField('selRight','search')
		document.search.submit()
	}

//--------------------------------------------------------------------------------

	function checkwords(){
		location.href = "advancedsearch.php?cw=" + document.search.addword.value;
	}

//--------------------------------------------------------------------------------

	function updateSelB(bval) {
		var objWords=eval("document.search.b");
		if (bval == "min") {
			objWords.selectedIndex = 0;
		} else if (bval == "max") 	{
			objWords.selectedIndex = objWords.length-1;
		}
	}

	function updateRadM(mval) {
		document.search.match[mval].checked = true;
	}

//--------------------------------------------------------------------------------




	function addMenuDataToHiddenField(menuName,hiddenField){
		var objMenu = eval("document.search." + menuName);		//menu of data to compile
		var objHidden = eval("document.search." + hiddenField);	//hidden field to store menu data in
		var strData="";																		//string of formatted data to put in hidden field
		var menuLength = objMenu.length;											//length of the menu
		for (i=0;i<menuLength;i++ ){
			//strData += objMenu.options[i].value + "," + objMenu.options[i].text + "|";
			strData += objMenu.options[i].value + " ";
		}
		strData = strData.substring(0,strData.length-1);
		objHidden.value = strData;
		//alert(objHidden.value);
	}

//--------------------------------------------------------------------------------
	function cleanUpMenus(menuName){
		var objMenu = eval("document.search." + menuName)		
		var placeInArray = 0		// place holder
		var placeInMenu = 0		// place holder
		var menuValueArray = new Array(objMenu.length-1)    //array used to store menu values
		var menuTextArray = new Array(objMenu.length-1)    //array used to store menu text						
		for (i=0; i<objMenu.length; i++){			//loop through the menu									
				menuValueArray[placeInArray] = objMenu.options[i].value;		//add the value to the array				
				menuTextArray[placeInArray]= objMenu.options[i].text; 			//add the text to the array
				placeInArray =placeInArray+1;		//increment place holder						
		}		
		objMenu.length=0;		//empty the menu
		placeInMenu=0;		
		for (i=0; i<menuValueArray.length; i++){		//add data from array back into the menu									
			if (menuValueArray[i]!=""){			//if there is data in the current array field...								
				objMenu.length = objMenu.length + 1;		//add a blank entry to the menu			
				objMenu.options[placeInMenu].value=menuValueArray[i];		//add the value to the new menu entry
				objMenu.options[placeInMenu].text=menuTextArray[i];			//add the text to the new menu entry			
				placeInMenu = placeInMenu + 1;			//increment place holder
			}			
		}		
	}
//--------------------------------------------------------------------------------
	function  moveSelection(fromField, toField){		
		var objFromMenu=eval("document.search." + fromField)			//menu to move from		
		var objToMenu=eval("document.search." + toField)				//menu to move to
		var placeInArray = 0		// place holder		
		var menuValueArray = new Array(objFromMenu.length-1)    //array used to store menu values
		var menuTextArray = new Array(objFromMenu.length-1)    //array used to store menu text
		var numOfFromOptions=objFromMenu.length		 //number of options in the menu to be moved from
		var numOfToOptions = objToMenu.length		 //number of options in the menu to be moved to											
		for (i=0; i<objFromMenu.length; i++){			//loop through the menu and add options to the array
			if (objFromMenu.options[i].selected) {		//if the option is selected...													
				menuValueArray[placeInArray] = objFromMenu.options[i].value;		//add the value to the array				
				menuTextArray[placeInArray]= objFromMenu.options[i].text; 			//add the text to the array				
				objFromMenu.options[i].value= ""		//clear the value of the selected field
				objFromMenu.options[i].text = ""			//clear the text of the selected field														
			} else {														//if the option is not selected...				
				menuValueArray[placeInArray] = ""		//add a blank string to the array				
				menuTextArray[placeInArray]= ""		//add a blank string to the array			
			}		
			placeInArray =placeInArray+1;				//increment place holder
		}					
		for (i=0;i<=menuValueArray.length-1;i++){		//loop through the array and add thems to the to menu
			if(menuValueArray[i]!=""){			//if there is no data, do not add it to the menu
				objToMenu.length = objToMenu.length + 1
				objToMenu.options[objToMenu.length-1].value=menuValueArray[i]  		//set the value of the new field
				objToMenu.options[objToMenu.length-1].text=menuTextArray[i]			//set the text of the new field				
			}													
		}		
		cleanUpMenus(fromField);				
		buildselectwords();
	}
//-------------------------------------------------------------------------------

function buildselectwords() {
	var objToMenu=eval("document.search.selRight");				//menu to move to
	var objWords=eval("document.search.b");
	for (i=0;i<=objWords.length-1;i++){
		objWords.options[objWords.length-1].value=null;
		objWords.options[objWords.length-1].text=null;		
	}
	objWords.length=0;

	for (i=0;i<=objToMenu.length-1;i++){		//loop through the array and add thems to the to menu
		objWords.length = objWords.length + 1;
		objWords.options[objWords.length-1].value=i+1;
		objWords.options[objWords.length-1].text=i+1;				
	}

	if (document.search.match[0].checked) {
		updateSelB("max");
	} else if (document.search.match[1].checked) {
		updateSelB("min");
	}
}
//--------------------------------------------------------------------------------
	function moveFields(fieldName, direction){
		var objField = eval("document.search." + fieldName);   //create a reference to the field that has items that are to be moved
		var menuValueArray = new Array(objField.length-1);    //array used to store menu values
		var menuTextArray = new Array(objField.length-1);    //array used to store menu text
		var menuSelValueArray = new Array(objField.length-1);    //array used to store selected menu values
		var menuSelTextArray = new Array(objField.length-1);    //array used to store selected menu text
		var firstSelItem=-1;	// index of the first selected item
		var lastSelItem=-1;	// index of the last selected item		
		var menuLength=objField.length; 		// get the starting length of the menu		
		var placeHolder=0;		// place holder used when adding items back to the menu
		var selectedItems=0;		// used to count the number of selected items	
		var nonSelectedItems=0;		// used to count the number of items not selected		
		var okToRun=true;			// used to make sure that running will work
		var errorMsg="";			// error to display if there is a problem				
		for (i=0; i<menuLength; i++){			//loop through the menu and add options to the arrays
			if (objField.options[i].selected) {		//if the option is selected add it to the selected array																	
				menuSelValueArray[selectedItems] = objField.options[i].value;		//add the value to the array				
				menuSelTextArray[selectedItems]= objField.options[i].text; 			//add the text to the array
				selectedItems++;						//increment the number of selectedItems
				if (firstSelItem==-1) firstSelItem=i;
				lastSelItem=i;				
			} else {					//if the option is not selected add it to the main array				
				menuValueArray[nonSelectedItems] = objField.options[i].value;		//add the value to the array				
				menuTextArray[nonSelectedItems]= objField.options[i].text; 			//add the text to the array	
				nonSelectedItems++;					//increment the number of  nonSelectedItems		
			}					
		}				
		if (direction=="up" && objField.options[0].selected) {okToRun=false;errorMsg="Item is already at the top of the list."}		// check to see if  the item can be moved up
		if (direction=="down" && objField.options[menuLength-1].selected) {okToRun=false;errorMsg="Item is already at the bottom of the list."}  // check if item can be moved down
		if (selectedItems == 0){okToRun=false;errorMsg="You must select an item to move."}	// check if any items are selected
		if (okToRun){
			for (i=firstSelItem;i<=lastSelItem;i++){
				if (!objField.options[i].selected) {		//make sure that all of the selected items are in a group
					okToRun=false;
					errorMsg="Unable to move items that are not adjacent.";
				}
			}
		}
		if (okToRun){		// if everything checked out ok, repopulate the menu in the correct order				
			objField.length=0;				
			for (i=0;i<=nonSelectedItems;i++){		//loop through the array of non selected items	
				if (((i==firstSelItem-1)&&(direction=="up"))||((i==firstSelItem+1)&&(direction=="down"))){	//if i is where the selected items should start being listed				
					for (s=0;s<selectedItems;s++){			// add all of the selected items to the menu
						objField.length++;	// increase the size of the menu
						var objOption = new Option(menuSelTextArray[s], menuSelValueArray[s],true, true)		//Create the new option object
						objField.options[placeHolder]=objOption;		// assign the new option object to the new field																													
						placeHolder++;		// increment the placeholder													
					}																	
				}
				if (i<nonSelectedItems){		// add the next item to the menu
					objField.length++;		// increase the size of the menu
					var objOption = new Option(menuTextArray[i], menuValueArray[i],false, false)		//Create the new option object
					objField.options[placeHolder]=objOption;	// assign the new option object to the new field								
					placeHolder++;		// increment the placeholder																
				}
			}
		}								
		if (errorMsg != "") alert(errorMsg);		// alert if there is an error
	}
