//	**********************************************************************************************
//	STANDARD JAVASCRIPT BROWSER EVENTS CAPTURE AND FORM PROCESSING
//
//	Include this javascript library into a page where you want to:
//
//	1. Catch cross browser events like onclick images etc (i.e. work in firefox and IE)
//	2. Where you have a form, and want to validate entries and submit
//
//	** NOTE **
//	You must have the <body> tag set to <body onload="init();" for this to work !!!!!!
//
//	**********************************************************************************************

function init()
//
//	Setup the event handles and define actions
{
//	Next section sets up the handles for click and mouseover - you can add other
//	events if necessary
	var tmpObj;
	for (count=0;count<eventHandlers.length;count++)
	{
		tmpObj=window.document.getElementById(eventHandlers[count]);
		tmpObj.clicked = false;
		tmpObj.onclick = handleClick;
		tmpObj.onmouseover = handleMouseOver;
	}
}

function handleMouseOver()
//
//	Change the cursor on mouseover
{
	obj=window.document.getElementById(this.id);
	obj.style.cursor="pointer";
}
function handleClick()
//
//	This function handles the click event
{
	var oEvent = document.getElementById(this.id);
	var sError="";

	switch(oEvent.id)
	{
//		If the event ID is "checkform" we treat this as a trigger to check the mandatory fields and
//		then generate an additional "checkform_ok" function to continue if ok,
//		otherwise just generate a standard event handler for the ID for example IMAGE1_CLICK

//		Also if a textbox is named "email" we automatically check the email for validity
		case "checkform" :

			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

			// Check if all the required fields have been entered
			for(c=0; c<checkitems.length;c++)
			{
				var oItem=document.getElementById(checkitems[c]);
				if(oItem.value=="")
				{
					sError=sError+"Need to add: " + oItem.name + ". ";
					oItem.style.background="#FFC1C1";
				}
				else
				{
					if(oItem.id=="email")
					{
						if (filter.test(oItem.value))
						{
							// Ok
						}
						else
						{
							sError=sError+"Email format is incorrect. For example: someone@website.com";
						}
					}
					oItem.style.background="#FFFFFF";
				}
			}
	
		// Inform the user to correct the mandatory entries
		if(!sError=="")
		{
			alert(sError);
			break;
		}
		else
		// The mandatory entries have all checked out ok, so call the function checkform_ok
		{
			checkform_ok();
			break;
		}

//		If a standard event, call (eval) the function ID with a _CLICK
		default :
			eval(oEvent.id + "_click()");
			break;
	}
}