<!--//   LIMIT MULTIPLE SELECTED OPTIONS SCRIPT || 01-21-2005   \\;
var selectedOptions = []; // Written by: WillyDuitt@hotmail.com \\;
var one_selectedOptions = [];
var two_selectedOptions = [];
var three_selectedOptions = [];
var four_selectedOptions = [];


 function countSelected(select, maxNumber){
 
 	for (var i = 0; i < select.options.length; i++) {
 		if (select.options[i].selected && !new RegExp(i, 'g').test(selectedOptions.toString())) {
 			selectedOptions.push(i);
 		}
 		
 		if (!select.options[i].selected && new RegExp(i, 'g').test(selectedOptions.toString())) {
 			selectedOptions = selectedOptions.sort(function(a, b){
 				return a - b
 			});
 			for (var j = 0; j < selectedOptions.length; j++) {
 				if (selectedOptions[j] == i) {
 					selectedOptions.splice(j, 1);
 				}
 			}
 		}
 		
 		if (selectedOptions.length > maxNumber) {
 			alert('You may only choose ' + maxNumber + ' options.');
 			select.options[i].selected = false;
 			selectedOptions.pop();
 			document.body.focus();
 		}
 		
 	}
	   
	
	//var four = document.getElementById('edit-taxonomy-four');
	
	var one = document.getElementById('edit-taxonomy-one');
	var two =  document.getElementById('edit-taxonomy-two'); 
	var three = document.getElementById('edit-taxonomy-three');
	var four = document.getElementById('edit-taxonomy-four');
	 
    one_selectedOptions = get_number_selected(document.getElementById('edit-taxonomy-one'));
	two_selectedOptions = get_number_selected(document.getElementById('edit-taxonomy-two'));
	three_selectedOptions = get_number_selected(document.getElementById('edit-taxonomy-three'));
	four_selectedOptions =  get_number_selected(document.getElementById('edit-taxonomy-four'));;
	
	var select_msg = "You may select from only one main category.";
	
    if(one_selectedOptions.length > 0 && two_selectedOptions.length > 0)
	 {	 	
	 	alert(select_msg);
		clear_box(one);
		clear_box(two);
		clear_box(three);
		clear_box(four);
	 }   
	 else if(one_selectedOptions.length > 0 && three_selectedOptions.length > 0)
	 {	 	
	 	alert(select_msg);
		clear_box(one);
		clear_box(two);
		clear_box(three);
		clear_box(four);
	 }	
	 else if(one_selectedOptions.length > 0 && four_selectedOptions.length > 0)
	 {	 	
	 	alert(select_msg);
		clear_box(one);
		clear_box(two);
		clear_box(three);
		clear_box(four);
	 }	 
	 else if(two_selectedOptions.length > 0 && three_selectedOptions.length > 0)
	 {	 	
	 	alert(select_msg);
		clear_box(one);
		clear_box(two);
		clear_box(three);
		clear_box(four);
	 }
	 else if(two_selectedOptions.length > 0 && four_selectedOptions.length > 0)
	 {	 	
	 	alert(select_msg);
		clear_box(one);
		clear_box(two);
		clear_box(three);
		clear_box(four);
	 }  
	 else if(three_selectedOptions.length > 0 && four_selectedOptions.length > 0)
	 {	 	
	 	alert(select_msg);
		clear_box(one);
		clear_box(two);
		clear_box(three);
		clear_box(four);
	 }   
	 
	 
 }
 
 
 function get_number_selected(select) 
 {
 	var total = [];
 	for (var i = 0; i < select.options.length; i++) {
		if (select.options[i].selected && !new RegExp(i, 'g').test(total.toString())) {
			total.push(i);
		}
	}
	 
	 return total;	
 }
 
 function clear_box(select)
 {
 	for (var i = 0; i < select.options.length; i++) 
	{
		select.options[i].selected = false;
	}
 }
 
 function clear_all()
 {
 		alert("You may only select from one list.");
		clear_box(one);
		clear_box(two);
		clear_box(three);
 }
 
 