/******************************************************************************
 * mondoScript.js
 *
 * Author: Frank Moore
 *
 * Description:
 * -----------------------------------------------------------------------------
 * This file contains the client-side javaScript code used in MondoPulse pages
 *
 * Revision History:
 * -----------------------------------------------------------------------------
 * 2008-06-25 - FM: Initial development of doNavSubmit
 * 2008-07-01 - FM: Added parseEnterKey function
 * 2008-09-03 - FM: modified the parseEnterKey function to genericize functionality
 *
 *
 *******************************************************************************
 */

function doNavSubmit(action) {
	
	/* there are three kinds of actions (i.e, Use Cases) that this function will
	 * perform, they are:
	 *
	 * next:	the function recalculates the recordset start (increments it by
	 * 			the size of the count variable) and submits the form
	 *
	 * prev:	the function recalculates the recordset start (decrements it by
	 * 			the size of the count variable) and submits the form
	 *
	 * filter:	the function resets the recordset start to zero and submits the
	 *			form with the filter text
	 *
	 */
	
	// get the navigator form
	var navForm = document.getElementById("MondoNav");
	
	// iterate through the elements in the form
	for ( var i = 0; i < navForm.length; i++ ) {
		// get the current element
		var formElem = navForm.elements[i];
		// capture the elements that are applicable to this function
		if ( "start" == formElem.id ) {
			var fStart = formElem;
		}
		if ( "count" == formElem.id ) {
			var fCount = formElem;
		}
		if ( "filter" == formElem.id ) {
			var fFilter = formElem;
		}
	}
	
	// take the appropriate action based on the passed parameter
	switch ( action ) {
		case "next":
			// recalculate the recordset start (increment by count)
			fStart.value = parseInt(fStart.value) + parseInt(fCount.value);
			
			// submit the form
			navForm.submit();
			
			break;
			
		case "prev":
			// recalculate the recordset start (decrement by count)
			fStart.value = parseInt(fStart.value) - parseInt(fCount.value);
			
			// submit the form
			navForm.submit();
			
			break;
			
		case "filter":
			// reset the recordset start to zero
			fStart.value = 0;
			
			// submit the form
			navForm.submit();
			
			break;
			
		default:
			//default code block
			
			// do nothing
		
	}
	
	return true;
}


function parseEnterKey(e, enterAction) {

	/*
	 * this function is very simple, it parses entries made the filter text field
	 * and, if the user pressed enter, it invokes the function call specificied 
	 * in the enterAction parameter
	 */
	
	var key;
	
	// check the window event
	if ( window.event ) {
		// handle IE/Safari browsers
		key = window.event.keyCode;
	}
	else {
		// handle Firefox/Netscape/Opera browsers
		key = e.which;
	}
	
	// if the user pressed the enter key (ASCII char 13)
	if ( key == 13 ) {
		return (eval(enterAction));
	}
	else {
		return true;
	}
	
}