/*

  Author - Larry Groebe
  Website - http://www.thimbleopensource.com/tutorials-snippets/jquery-plugin-filter-text-input
  Version - 1.0
  Release - 20th October 2011

place a calculation attribute onto a form field like so:
<input type='text' name='result' id='my test_result' value='' onchange='edited(this)' title='' calculation="form_amount*form_tax" >
it will recalculate this field using values form other fields.

*/

$(document).ready(function() { 
	$("input[calculation]").each( function(){
		calculate($(this))
		});
 	$('input').change(function() {
		$("input[calculation]").each( function(){
			calculate($(this))
			});
		})

	function calculate(me) {
		cstring="result="+me.attr('calculation');
		search = /form_(\w+)/g;
		replace = "$(\"input[name='$1']\").val()";
		cstring=cstring.replace(search,replace);
		me.val(eval(cstring));
		}
	})

