	$().ready(function() {
			$('input#updates').live('click', function() {
				if ($(this).attr('checked') == true) $(this).attr('value', 'checked');
				else $(this).attr('value', '');
			});
			
			$('td').live('click', function() {
				if ($(this).children('input').attr('checked') == 'checked') $(this+ 'input').attr('checked', '');
				else $(this).children('input').attr('checked', 'checked');
			});
			
			$('a#step-1').live('click', function() {
				var responses = '';
				$('tr.question').each(function() { 
					var val = $('input[name=q-'+$(this).attr('id')+']:checked').val();
					if (val != null) responses = responses + $(this).attr('id') + ':' + val + ',';
					else responses = responses + $(this).attr('id') + ':0,';
				});
				$.post('quiz-steps.php', {
					step: $(this).attr('id'),
					token:  $('input#token').val(),
					referrer: $('input#referrer').val(),
					zip: $('input#zip').val(),
					name: $('input#name').val(),
					email: $('input#email').val(),
					updates: $('input#updates').val(),
					responses: responses },
					function(result) { $('#quiz').html(result); }
				);
			});
		
			$('a#step-2').live('click', function() {
				$.post('quiz-steps.php', {
					step: $(this).attr('id'),
					token: $('input#token').val(),
					referrer: $('input#referrer').val(),
					zip: $('input#zip').val(),
					name: $('input#name').val(),
					email: $('input#email').val(),
					updates: $('input#updates').val(),
					responses: $('input#responses').val() },
					function(result) { $('#quiz').html(result); }
				);
			});
			
			$('a#step-3').live('click', function() {
				var complete = true;
				var responses = '';
				if ($('input#responses').val() == null) {
					$('tr.question').each(function() { 
						var val = $('input[name=q-'+$(this).attr('id')+']:checked').val();
						if (val == null) { complete = false; return false; }
						else responses = responses + $(this).attr('id') + ':' + val + ',';
					});
				} else responses = $('input#responses').val();
				if (complete) {
					$.post('quiz-steps.php', {
						step: $(this).attr('id'),
						token: $('input#token').val(),
						referrer: $('input#referrer').val(),
						zip: $('input#zip').val(),
						name: $('input#name').val(),
						email: $('input#email').val(),
						updates: $('input#updates').val(),
						responses: responses },
						function(result) { $('#quiz').html(result); }
					);
				} else { alert('Please answer all question.'); }
			});
			
 			$('a#step-4, a#step-5').live('click', function() {
				var step = $(this).attr('id');
				
				if ($('input#zip').val() == '') {
					alert('Please enter your zip code.');
					$('input#zip').focus();
					return false;
				}
				
				if ($('input#name').val() == '') {
					alert('Please enter your name.');
					$('input#name').focus();
					return false;
				}
				
				if ($('input#email').val() == '') {
					alert('Please enter your email address.');
					$('input#email').focus();
					return false;
				}
				
				if ($(this).attr('id') == 'step-5') {
					if ($('input[name=correct]:checked').val() == 'no') step = 'step-3';
					if ($('input[name=correct]:checked').val() == null) {
						alert('Please answer the question.');
						return false;
					}
				}
				
				$.post('quiz-steps.php', {
					step: step,
					token: $('input#token').val(),
					referrer: $('input#referrer').val(),
					zip: $('input#zip').val(),
					name: $('input#name').val(),
					email: $('input#email').val(),
					updates: $('input#updates').val(),
					responses: $('input#responses').val() },
					function(result) { $('#quiz').html(result); }
				);
			});
			
			$('form#unsub').submit(function() {
				if ($('#email').attr('value') == '') {
					alert('Please enter your email address.');
					return false;
				}
			});
		})
