
/**
* Our bindText() plugin.  It is used to bind a select element to a specific
*	text box so that when the select element is changed, the contents of the
*	text box also change.
*
* This plugin is "chained", which means that "this" amounts to 1 or more
*	DOM objects.
*
* @param string text_field A jQuery identifier of one or more text fields
*	that we are going to bind the select field(s) to.
*
* @param array settings An optional array of settings for this function.
*	append - If set, the value selected is appended to the contents
*		of the text box.
*/
jQuery.fn.bindText = function(text_field, settings) {

	settings = jQuery.extend({
		append: false
		}, settings);

	var text_field = jQuery(text_field);

	return(this.each(function() {

		var select = jQuery(this);

		//
		// Apply a handler to our select field.
		//
		select.change(function(e) {

			var new_val = jQuery(this).val();

			//
			// Either replace the current value, or append it to an 
			// existing value.
			//
			if (!settings["append"]) {
				text_field.val(new_val);

			} else {
				if (new_val) {
					var old_val = text_field.val();
					if (old_val) {
						text_field.val(old_val + ", " + new_val);
					} else {
						text_field.val(new_val);
					}

				}

			}

			});


	}));

}; // End of bindText() jQuery plugin.


