jQuery(document).ready(function() {
	
	var ecomplexityCalcForm = function() {
	
		var the_post = { n_em_accts: jQuery('#n_em_accts').attr('value'), 
		                   n_em_chk: jQuery('#n_em_chk').attr('value'),
		                  n_em_rcvd: jQuery('#n_em_rcvd').attr('value'), 
		                  n_em_sent: jQuery('#n_em_sent').attr('value'),  
		                 n_im_accts: jQuery('#n_im_accts').attr('value'),
		                  n_im_sess: jQuery('#n_im_sess').attr('value'),
		                 n_sms_read: jQuery('#n_sms_read').attr('value'),
		                n_sms_write: jQuery('#n_sms_write').attr('value'),
		                 n_fax_rcvd: jQuery('#n_fax_rcvd').attr('value'),
		                 n_fax_sent: jQuery('#n_fax_sent').attr('value'),
		                 n_vm_accts: jQuery('#n_vm_accts').attr('value'),
		                  n_vm_msgs: jQuery('#n_vm_msgs').attr('value'),
		                 n_sn_accts: jQuery('#n_sn_accts').attr('value'),
		                  n_sn_sess: jQuery('#n_sn_sess').attr('value'),
		                n_blog_read: jQuery('#n_blog_read').attr('value'),
		                   n_tweets: jQuery('#n_tweets').attr('value'),
                              n_phone_calls: jQuery('#n_phone_calls').attr('value'),
                                        age: jQuery('#age').attr('value')
                                        		               		                		                  		                 		                  		                 		                 		                 		                };

		
		jQuery('.c-screen_c').empty();
		jQuery(".c-screen_c").append(jQuery('<p></p>').append(jQuery('<img />').attr('src', 'http://www.rocketvox.com/images/calculator/oload_lcd.gif')).addClass('spinner'));
							
		jQuery.post("calculator_files/ajax.php", the_post, 
			function(data){
				var the_output = jQuery('<div></div>').addClass('c-results').
					append(jQuery('<dl></dl>').
						append(jQuery('<p></p>').addClass('center').html('In minutes per day you:')).
						append(jQuery('<dt></dt>').addClass('c-ctime').html('Communicate')).
						append(jQuery('<dd></dd>').addClass('c-ctime').html(data.ctime)).
						append(jQuery('<dt></dt>').addClass('c-wtime').html('Waste')).
						append(jQuery('<dd></dd>').addClass('c-wtime').html(data.wtime)).
						append(jQuery('<p></p>').addClass('center').html('And in hours/day all '+data.visitors+' visitors:')).
						append(jQuery('<dd></dd>').addClass('c-actime').html(data.aggregate_ctime)).
						append(jQuery('<dd></dd>').addClass('c-awtime').html(data.aggregate_wtime)) 
					);
				jQuery('.c-screen_c').empty();
				jQuery('.c-screen_c').append(the_output);
				showReset();
			}
		, "json");
		return false;	
	}
	jQuery('#calculatorform').bind('submit', ecomplexityCalcForm);

	var showReset = function() {
		jQuery('.c-input_fields select, .c-input_fields label').hide();
		jQuery('.c-footer input').attr('src','calculator_files/reset.jpg').attr('alt','reset calculator').bind('click',showComplexityForm);
		jQuery('.c-input_fields').append(jQuery('<h2>Congratulations!</h2>'))
                                         .append(jQuery('<p>Here is how much time you are wasting shifting across all the various forms of communication you use!</p>'))
                                         .append(jQuery('<p>What if you had one place from which to send and receive all types of messages?</p>'))
                                         .append(jQuery('<h2>Think how much time you would save.</h2>'))
                                         .append(jQuery('<p>What will you do with that found time? Run for president? Bring peace to the Middle East? Send your Mom flowers? Tell us here on our blog what you might do with your found time.</p>'))
                                         .append(jQuery('<h2>Tell your friends!</h2>'))
                                         .append(jQuery('<p>Share your results with them. Send them here for their results. The more visitors the better!</p>'))
                                         .append(jQuery('<h2><a href="http://www.rocketvox.com">www.rocketvox.com</a></h2>') );

		return false;
	};

	var showComplexityForm = function() {
		jQuery('form.c-wrapper').bind('submit', ecomplexityCalcForm);
		jQuery('.c-input_fields h2, .c-input_fields p, .c-signup_fields').remove();
		jQuery('.c-input_fields select, .c-input_fields label, .c-other_fields').show();
		jQuery('.c-footer input').attr('src','calculator_files/calculate_now.jpg').attr('alt','calculate now').unbind('click',showComplexityForm);
		return false;
	};
});

