function validateFormInput(theForm,whichform)
{
	b_failed = false;
	// assign correct form field names
	if ( whichform == 'imm' )
	{
		ff_state = theForm.state;
		ff_age = theForm.age;
		ff_gender = theForm.gender;
		ff_deposit = theForm.deposit;
		ff_income = theForm.income;
		ff_period = theForm.deposit;
	}
	else if ( whichform == 'def' )
	{
		ff_state = theForm.propertyID96;
		ff_age = theForm.age;
		ff_gender = theForm.gender;
		ff_deposit = theForm.propertyID97;
		ff_period = theForm.propertyID99;
	}
	// Check for the State
	if (ff_state.selectedIndex == 0)
	{
		alert("Please select your \"State\"");
		ff_state.focus();
		return (false);
	}

// Check for the city, state and zip  
	if (ff_age.selectedIndex == 0)
	{
		alert("Please select your \"Age\"");
		ff_age.focus();
		return (false);
	}

	if (ff_gender.selectedIndex == 0)
	{
		alert("Please select your \"Gender\"");
		ff_gender.focus();
		return false;
	}
	if ( whichform == 'def' )
	{
		if (ff_period.selectedIndex == 0)
		{
			alert("Please select the \"Guarantee Period in Years\"");
			ff_period.focus();
			return (false);
		}
		if (ff_deposit.value == "" )
		{
			alert("Please fill in the\n'How much you are investing'\n  box then resubmit the form.");
			ff_deposit.focus();
			return false;
		}
	}
	else if ( whichform == 'imm' )
	{
		if (ff_deposit.value == "" && ff_income.value== "")
		{
			alert("Please fill in either the\n'How much you are investing'\n or 'How much you would like to receive' box\nthen resubmit the form.");
			ff_deposit.focus();
			return false;
		}
		else if (ff_deposit.value != "" && ff_income.value != "")
		{
			alert("You can only fill in one of the\n'How much you are investing'\n or 'How much you would like to receive' boxes.\nPlease fill in only the one you want, then resubmit the form.");
			ff_deposit.focus();
			return false;
		}
	}

	
	if ( ff_deposit.value != "" )
	{
		if ( !filter_number(ff_deposit.value) )
		{
			alert("The numbers you enter in the deposit field\nmust be in one of the following formats:\n " +
			"20,000\n20000\n20000.00\n20,000.00\nPlease Correct your entry, Thank You");
			ff_deposit.focus();
			return false; 
		}
		else
		{
			return true;
		}
		
	}
	else if ( ff_income.value != "" && whichform == 'imm' )
	{
		if ( !filter_number(ff_income.value) )
		{
			alert("The numbers you enter in the desired income field\nmust be in one of the following formats:\n " +
			"20,000\n20000\n20000.00\n20,000.00\nPlease Correct your entry, Thank You");
			ff_income.focus();
			return false; 
		}
		else
		{
			return true;
		}
	}
}

function filter_number(currency)
{
	//pattern = /^\d{1,3}(,\d{3})*(\.\d{1,2})?$|^\d+(\.\d{1,2})?$/;
	// this is a very loose version of the stricter pattern above
	pattern = /^\d+(,\d{3})*(\.\d*)?$|^\d+(\.\d*)?$/;

	if ( currency.search( pattern ) != -1 )
	{
		//alert( 'pattern found' );
		return true;
	}
	else
	{
		return false;
	}



	
	if ( ff_deposit.value != "" )
	{
		if ( !filter_number(ff_deposit.value) )
		{
			error_message += "* The numbers you enter in the deposit field\nmust be in one of the following formats:\n " +
			"20,000\n20000\n20000.00\n20,000.00\nPlease Correct your entry, Thank You\n\n";
			which_item_to_focus( ff_deposit );
		}
	}
	else if ( whichform == 'imm' && ff_income.value != "" )
	{
		if ( !filter_number(ff_income.value) )
		{
			error_message += "* The numbers you enter in the desired income field\nmust be in one of the following formats:\n " +
			"20,000\n20000\n20000.00\n20,000.00\nPlease Correct your entry, Thank You\n\n";
			which_item_to_focus( ff_income );
		}
	}

	// 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
	{
		error_message = error_start + error_message + error_close;
		alert( error_message );
		the_focus_item.focus();
		return (false);
	}
	else
	{
		return (true);
	}
}

function filter_number(currency)
{
	//pattern = /^\d{1,3}(,\d{3})*(\.\d{1,2})?$|^\d+(\.\d{1,2})?$/;
	// this is a very loose version of the stricter pattern above
	pattern = /^(\$)?\d+(,\d{3})*(\.\d*)?$|^\d+(\.\d*)?$/;

	if ( currency.search( pattern ) != -1 )
	{
		//alert( 'pattern found' );
		return true;
	}
	else
	{
		return false;
	}
}
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;
	}
}

// wcw audit functions
//<script type="text-javascript" src="http://www.whosclickingwho.com/wcwsc.js"></script>
function WCWAudit(parms) {
	var uri='<iframe src="//www.whosclickingwho.com/cgi-bin/wcwauditor.cgi?wcwrequesturi=' + escape(document.URL) + '%26' + escape(parms) + '&' + 'ppcreferer=' + escape(document.referrer) + '" frameborder=0 width=1 height=1></iframe>';
 	document.writeln(uri);
}
function WCWThankYou(value) { 
	var today = new Date();
	var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); 
	document.cookie="WCWCookie=" + value + "; expires=" + expiry.toGMTString();
} 
