function updateDropDown ( target, data ) {
	
	target.options.length = 1; // Erase all but the first option
	
	if ( (typeof(data) == "object") ) {
		
		for ( itemId in data ) {
			
			target.options[target.options.length] = new Option(data[itemId], itemId);
			
		} // for institutionId
		
	} // if
	
} // updateDropDown()


function submitComparisonForm ( action ) {
	
	var comparisonForm = document.getElementById("comparisonForm");
	comparisonForm.submitAction.value = action;
	
	if ( checkComparisonForm() ) {
		
		comparisonForm.submit();
		
	} // if
	
} // submitComparisonForm()

function checkComparisonForm (  ) {
	
	var comparisonForm = document.getElementById("comparisonForm");
	var selectedResults = document.getElementById("selectedChosen");
	
	switch ( comparisonForm.submitAction.value ) {
		
		case "search":
			
			if ( comparisonForm.query.value.length < 4 ) {
				
				alert(COMPARE_FORM_TOO_SHORT_QUERY);
				return false;
				
			} // if
			
		break; // case search
			
		case "add":
			
			if ( selectedResults.options.length == 2 ) {
				
				alert(COMPARE_FORM_TOO_MANY_ITEMS);
				return false;
				
			} // if
			
		break; // case search
		
	} // switch
	
	return true;
	
} // checkComparisonForm()

function compareDrugs ( tableUrl ) {
	
	var selectedResults = document.getElementById("selectedChosen");
	
	if ( selectedResults.options.length == 2 ) {
		
		var results = selectedResults.options;
		
		top.location.href = tableUrl + "&drug[a]=" + results[0].value + "&drug[b]=" + results[1].value;
		
	} else {
		
		alert(COMPARE_FORM_NOT_ENOUGH_ITEMS);
		
	} // else
	
} // compareDrugs()

function checkDrugsInteraction ( reportUrl ) {
	
	var selectedResults = document.getElementById("selectedChosen");
	
	if ( selectedResults.options.length == 2 ) {
		
		var results = selectedResults.options;
		
		top.location.href = reportUrl + "&interactor_id[a]=" + results[0].value + "&interactor_id[b]=" + results[1].value;
		
	} else {
		
		alert(COMPARE_FORM_NOT_ENOUGH_ITEMS);
		
	} // else
	
} // checkDrugsInteraction()