function search_food(input_string) {
  frames['search_iframe'].location.href = 'food.php?action=search_frame&input='+input_string;
}

function remove_item(item_no) {
    /* clear out:
    tag_0
    weight_count_0_18041  ignore for now
    weight_id_0_18041_0   ignore for now
    weight_name_0_18041_0 ignore for now
    NDB_No_0 (select)
    number_0
    weight_id_0 (select)
    */
    eval("document.the_form.tag_"+item_no+".value = '';");
    eval("document.the_form.NDB_No_"+item_no+".value = '';");
    eval("document.the_form.NDB_No_"+item_no+".options.length = 0 ;");
    eval("document.the_form.NDB_No_"+item_no+".disabled = true;");
    eval("document.the_form.number_"+item_no+".value = '';");
    eval("document.the_form.number_"+item_no+".disabled = true;");
    eval("document.the_form.weight_id_"+item_no+".value = '';");
    eval("document.the_form.weight_id_"+item_no+".disabled = true;");
    eval("document.the_form.weight_id_"+item_no+".options.length = 0;");
    
    eval("document.getElementById('tag_name_"+item_no+"').style.textDecoration = 'line-through';");
    
    
    eval("document.the_form.erase_"+item_no+".disabled = true;");
    document.the_form.number_of_items.value = (parseInt(document.the_form.number_of_items.value)-1);
}

/* 
update_weight() updates the list of weights depending on the food selected

There should be a bunch of hidden form fields with the name convention of
	weight_count_1_18521
	weight_id_1_18521_0
    weight_name_1_18521_0
	.. where the first number is the item_number, the second is the NDB_No, 
    	and the third is the number of possible weights.

TODO:  make this AJAXy.  This is really inefficient.
*/
function update_weights(item_number,NDB_No) {
		
	var cur_id, cur_name, cur_count, select_flag, weight_select, new_weight_opt;        
  target_form = document.the_form;

  eval("weight_select = target_form.weight_id_"+item_number+";");
  weight_select.options.length = 0 ;
  weight_select.disabled = false;
 
  eval("cur_count = target_form.weight_count_"+item_number+"_"+NDB_No+".value;");
  for (i=0; i<cur_count; i++) { 
    eval("cur_id = target_form.weight_id_"+item_number+"_"+NDB_No+"_"+i+".value;");
    eval("cur_name = target_form.weight_name_"+item_number+"_"+NDB_No+"_"+i+".value;");
    if (i==0) {
			select_flag = true;
    } else {
			select_flag = false;
    }
    
    //old way: weight_select.options[i] = new Option(cur_name,cur_id,select_flag,select_flag);
		// might be able to use the above again now the problem is fixed.  Leaving Try/catch for now.
  	try {
        new_weight_opt = new Option(cur_name,cur_id,select_flag,select_flag);
    } catch (err1) {
    	alert('Cannot create options  '+err1.message);
    }
  	try {
        weight_select.options[i] = new_weight_opt;
    } catch (err2) {
    	alert('Cannot modify select  '+err2.message);
    }
    
  }
  weight_select.className = 'active';
}


