var postID = 0;

/*
Toggle the login table
*/
function toggleLoginTable() {
	var transSpeed = 'slow';
	
	if ((navigator.userAgent.indexOf('MSIE') > 0) || (navigator.userAgent.indexOf('Safari') > 0)) {
		transSpeed = 1;
	}
	
	if ($('#new_user:checked').val() == 1) {
		$('#new_user_table').show(transSpeed, function() {$('#email_address').focus();});
		$('#existing_user_table').hide(transSpeed);
		$('#updateBtn').val('Create Account');
	} else {
		$('#new_user_table').hide(transSpeed, function() {$('#password').focus();});
		$('#existing_user_table').show(transSpeed);		
		$('#updateBtn').val('Login Now');
	}
}


/*
Show the Post a New Thread field
*/
function postNewField() {
	$('#thread_div').show();
	$('#new_thread').attr('disabled', false);
	$('#new_thread').show();
	$('#new_thread').val('');
}


/*
Show the Post a New Reply to a thread
*/
function postNewReply() {
	$('#reply_div').show();
	$('#reply_text').attr('disabled', false);
	$('#reply_text').show();
	$('#reply_text').val('');
}


/*
Submit the new thread to the DB
*/
function submitNewPost() {
	if (!$('#new_thread').attr('disabled')) {
		submitAJAX('/members/index.php?action=POST_THREAD', {0: $('#new_thread').val()}, true);
		$('#new_thread').attr('disabled', true);
		$('#post_btn').attr('disabled', true);
	}
}


/*
Submit the new reply to the DB
*/
function submitReply() {
	if (!$('#reply_text').attr('disabled')) {
		submitAJAX('/members/index.php?action=POST_REPLY', {0: $('#reply_text').val(), 1: postID}, true);
		$('#reply_text').attr('disabled', true);
		$('#reply_btn').attr('disabled', true);
	}
}


/*
Confirm the post deletion
*/
function deletePost(iPostID) {
	var tmpResp = confirm('Are you sure you want to delete this post?');
	
	if (tmpResp) {	
		window.location.href='/index.php?action=DELETE_POST&post_id=' + iPostID;
	}	
}

/*
Confirm the reply deletion
*/
function deleteReply(iReplyID) {
	var tmpResp = confirm('Are you sure you want to delete this reply?');
	
	if (tmpResp) {	
		window.location.href='/index.php?action=DELETE_REPLY&reply_id=' + iReplyID;
	}	
}
