
var showTab = function(elmID) {
	$('.tabContent').hide();
	$('#'+elmID).fadeIn('slow');	
}

$(document).ready(function() {
	//setup forms
	$('#loginForm').applyMasks();
	$('#signupForm').applyMasks();
	$('#helpForm').applyMasks();

	//mark required labels
	$('body .required').each(function(i, elm) {
		$('label[for="'+$(elm).attr('id')+'"]').addClass('required');
	});
	
	$('#home_signupBtn').click(function() {
		//do error checking
		var msg = '';
		$('#signupForm').find('input.required, select.required, textarea.required').each(function(i, elm) {
			if ($(elm).val() == '') {
				msg += $('label[for="'+$(elm).attr('id')+'"]').html() + ' is required\n';
			}
		});
		if (msg != '') {
			showDialog(msg, 'error');
			return false;
		}	
		$.ajax({
			url: '/index_post.php', 
			type: 'post',
			dataType: 'json',
			data: $('#signupForm').serialize(),
			success: function(data) {
				showDialog(data.message, data.status);
				if (data.status == 'success') {
					$('#signupForm')[0].reset();
				}
			}	
		});		
	});

	$('#home_helpBtn').click(function() {
		//do error checking
		var msg = '';
		$('#helpForm').find('input.required, select.required, textarea.required').each(function(i, elm) {
			if ($(elm).val() == '') {
				msg += $('label[for="'+$(elm).attr('id')+'"]').html() + ' is required\n';
			}
		});
		if (msg != '') {
			showDialog(msg, 'error');
			return false;
		}		
		$.ajax({
			url: '/index_post.php', 
			type: 'post',
			dataType: 'json',
			data: $('#helpForm').serialize(),
			success: function(data) {
				showDialog(data.message, data.status);	
				if (data.status == 'success') {
					$('#helpForm')[0].reset();
				}
			}	
		});		
	});
	
	//start the page with the login showing
	showTab('loginContent');
});
