var currentSlide = null;

function swapSlide(targSlide, duration)
{
	targSlide.css('margin-top', '100%');
	currentSlide.animate(
		{
			'margin-top': '-120%',
		},
		duration
	);
	targSlide.animate(
		{
			'margin-top': '0%',
		},
		duration
	);
	currentSlide =targSlide;
}

function section_user_area_onload()
{
	$('#user_vol').css('margin-top', '100%');
	currentSlide = $('#user_main');
	
	$('#news_button').click(
		function(e)
		{
			var valid = true;
			$('#news_error').html('');
			$('.news_input').each(
				function(a, b)
				{
					if($(this).val() == $(this).attr('alt'))
					{
						valid = false;
						$('#news_error').html(mferror[$(this).attr('id')]);
					}
				}
			)
			if(valid)
			{
				$('.user_loading').show();
				$.post('scripts/php/insert_newsletter.php', $("#news_form").serialize(), 
					function(data) 
					{
						$('.user_loading').hide();
						$('#news_error').html(data);
					}
				);
			}
		
		}
	);
	
	$('#volunteer_button').click(
		function(e)
		{
			var valid = true;
			$('#volunteer_error').html('');
			$('.volunteer_input').each(
				function(a, b)
				{
					if($(this).val() == $(this).attr('alt'))
					{
						valid = false;
						$('#volunteer_error').html(mferror[$(this).attr('id')]);
					}
				}
			)
			if(valid)
			{
				$('.user_loading').show();
				$.post('scripts/php/insert_volunteer.php', $("#volunteer_form").serialize(), 
					function(data) 
					{
						$('.user_loading').hide();
						if(data != 'true')
						{
							$('#volunteer_error').html(data);
						}
						else
						{
							$('#volunteer_error').html('thank you for signing up!');
							setTimeout("swapSlide($('#user_main'), 350);", 5000);
						}
					}
				);
			}
		
		}
	);
	
	$('#news_button_out').click(
		function(e)
		{
			swapSlide($('#user_vol'), 350);
		}
	);
	
	$('#volunteer_button_out').click(
		function(e)
		{
			swapSlide($('#user_main'), 350);
		}
	);
	
	$("#volunteer_name, #news_name").keydown(
		function(e)
		{
			var key = e.keyCode  || e.charCode;
			
			return( (key >= 65 && key <= 90) 	||
					(key >= 48 && key <= 57) 	||
					key == 8 					|| 
					key == 9 					||
					key == 46 					||
					key == 32 					||
					key == 16 					||
					(key >= 37 && key <= 40) 	||
					(key >= 96 && key <= 105) );
			
		}
	);
	
	$("#volunteer_contact").keydown(
		function(e)
		{
			var key = e.keyCode  || e.charCode;
			
			return ( (key >= 48 && key <= 57)||
					key == 8 					|| 
					key == 46 );
		}
	);
}

function section_user_area_onenter()
{
}

function section_user_area_onexit()
{
}
