// <script>

var Membership = Class.create();
Membership.prototype = {

	initialize : function() {

		$A($('calculator').getInputs()).each(function(el){
			Event.observe(el,'keyup',this.totalScore.bindAsEventListener(this));
		}.bind(this));
		
		// make sure it's in sync
		this.totalScore();			
			
	},
	
	totalScore : function (){
		
		var totalScore = 0;
		
		$A($('calculator').getInputs()).each(function(el){
			var subtotal = ((el.value*el.className))
			if (!isNaN(subtotal)){
				totalScore += subtotal;
			}
		});
		
		// total for these cannot be greater than 40
		var cityMaxPoints = 40
		var cityWinnerPoints = $F('winnerCity') * $('winnerCity').className;
		var cityFinishedPoints = $F('finished2-5City') * $('finished2-5City').className;
		var citySubTotal = cityWinnerPoints + cityFinishedPoints;
		if (!isNaN(citySubTotal) && (citySubTotal > cityMaxPoints)){
			totalScore = totalScore-(citySubTotal-cityMaxPoints);
		}
		
		// show updated count
		$('points').innerHTML = totalScore;		
		(totalScore>75) ? Element.hide('notExceed'):Element.show('notExceed');

	}
			
};

Event.observe(window, "load", function() { new Membership() } );

