/**
 * Simple JS utilities to handle form submissions
 *
 * @author scampbell
 * @date 19-10-2005
 */


/**
 * Attaches a JS function to the onsubmit event of the
 * specified form, allowing the query to be modified
 * before being sent to the server.
 *
 * @param frm The form element to attach the function to
 * @param fnc The function to attach to the form
 */
function init_form_handler(frm, fnc) {
	frm.onsubmit = fnc;
}


/**
 * Replaces hyphens with a space, to allow search
 * queries to properly match entries in the Matrix
 * search index.
 */
function strip_hyphens() {
	var frm = this;
	var inputs = frm.getElementsByTagName("input");

	//find each text input and replace the offending hyphens
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type != "text") {
			continue;
		}

		var str = inputs[i].value;

		//removes hyphens that don't have a space on either side of them
		inputs[i].value = str.replace(/([^ ])-([^ ])/g, "$1$2");
	}
}