/***********************************************************************\
* File:     MoJoForm.js                                                 *
* Date:     August 17, 2007                                             *
* Author:   James Carpenter                                             *
* Purpose:  To create a form system that prevents bot spam submission   *
\***********************************************************************/

// function to execite
var enterFunc2 = "";
var tempFunc2 = "";
var elem2 ;

// function to setup correct actions for the form
function makeForm2( action, method, validateFunc )
{
	// if a validation function was passed and is true or if no function passed
	if ( validateFunc == '' || (typeof validateFunc == 'function' && validateFunc() == true) )
	{
		// get a handle to the existing form
		var mojoForm2 = document.getElementById('mojoFormRequestAppointment');
		
		// set up the attributes of the form
		mojoForm2.action = action;
		mojoForm2.method = method;
			
		// submit the form 
		mojoForm2.submit();
	}
}

// capture event keypress and submit form 
function kH(e) {
	var pK = e ? e.which : window.event.keyCode;
	if (pK == 13) eval(enterFunc2);
	return true;
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);

function setElements2()
{
	elem2 = document.getElementById('mojoFormRequestAppointment').elements;
	for(var i = 0; i < elem2.length; i++)
	{
		if( elem2[i].type == "textarea" )
		{
			elem2[i].onfocus = function()
			{
				tempFunc2 = enterFunc2;
				enterFunc2 = "";
			}
			elem2[i].onblur = function()
			{
				enterFunc2 = tempFunc2;
				tempFunc2 = "";
			}
		}		
	} 	
}

setTimeout( setElements2, 100 );
