// **************************************************************
// General form validation for non immediate annuity rates pages
// **************************************************************

// Set Globals

// the_focus_item is a global, and will be set only on the first item found
var b_first_focus = false;// set the focus only on the first item found
var focus_click = 0;//we start with both click_counter and focus_click set to 0
var the_focus_item;
var error_start = "We need a little more information to complete this request.\nPlease complete the following items: \n\n";
var error_close = "Thank You.";

function validateForm(theForm,whichForm)
{
	/* 
	You need dump this to make the server side purpose[] checkbox validation method work
	javascript doesn't recognize the purpose[] syntax, although php does.
	Currently the site uses the standard purpose, no []
	*/
	var error_message = '';
	
	if ( whichForm == 'contact' ){
		if (theForm.full_name.value == "") {
			error_message += "* Please enter your \"Name\"\n\n";
			which_item_to_focus( theForm.full_name );
		}
	}

	// Check for the first email
	if (theForm.email.value == "") {
		error_message += "* Please enter your \"E-mail Address\"\n\n";
		which_item_to_focus( theForm.email );
	}
	// Check for valid email address format
// 	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value)))
// 	{
// 	  error_message += "* Invalid E-mail Address! Please re-enter.\n\n";
// 	  which_item_to_focus( theForm.email );
// 	} 

	// Check for the daytime phone  
	if (theForm.main_phone.value == "") {
		error_message += "* Please enter a \"Phone\" number\n\n";
		which_item_to_focus( theForm.main_phone );
	}

	// process for error messages, create the error message alert text, set focus on first item
	if ( error_message ) {// if any of the tests triggered an error
		b_first_focus = false;// reset first focus
		error_message = error_start + error_message + error_close;
		alert( error_message );
		the_focus_item.focus();
		return (false);
	}
	else {
		return (true);
	}
}

/***************************
End : Validation

Begin: utilities, set focus
***************************/
// is it used?
function takeAction()
{
	alert("You are closing this window");
}
// if it's the first item found, set focus on it
// b_first_focus is reset every user click
function which_item_to_focus( focus_on )
{
	if ( !b_first_focus )// if it has not been tripped yet on this call, that is.
	{
		b_first_focus = true;
		the_focus_item = focus_on;
	}
}

