$(document).ready(function() 
{	
	$('#demo-form').ajaxForm({ 
        // dataType identifies the expected content type of the server response 
        dataType:  'json', 
 
        // success identifies the function to invoke when the server response 
        // has been received 
        success:   processJson 
    }); 

	function processJson(data) {
		$('#response').attr('class', data.level);
		$('#response').hide();
		if ( data.level == 'success' )
		{
			$('#response').html('<h3>Free Trial Form - Sent!</h3><p>' + data.message[0] + '</p>').fadeIn('slow');
			$('#demo-form').hide();
		}
		else
		{
			var errors = '';
			for ( i = 0; i < data.message.length; i++ )
			{
				errors = errors + '<li>' + data.message[i] + '</li>';
			}
			$('#response').html('<h3>Free Trial Form - Error Detected!</h3><p>Could not send form because:</p><ul>' + errors + '</ul>').fadeIn('slow');
		}
	}

	$('#share-form').ajaxForm({ 
        // dataType identifies the expected content type of the server response 
        dataType:  'json', 
 
        // success identifies the function to invoke when the server response 
        // has been received 
        success:   processShareJson 
    }); 

	function processShareJson(data) {
		$('#response').attr('class', data.level);
		$('#response').hide();
		if ( data.level == 'success' )
		{
			$('#response').html('<h3>E-mail Sent!</h3><p>' + data.message[0] + '</p>').fadeIn('slow');
			$('#share-form').hide();
		}
		else
		{
			var errors = '';
			for ( i = 0; i < data.message.length; i++ )
			{
				errors = errors + '<li>' + data.message[i] + '</li>';
			}
			$('#response').html('<h3>Woops!</h3><p>Could not share page because:</p><ul>' + errors + '</ul>').fadeIn('slow');
		}
	}
});

