//show the problem report box
function popup_problem(){
	$('#problem_report_container').show("slow");
}

//hide the problem report box
function hide_problem(){
	$('#problem_report_container').hide("slow");
}

//submit and send problem report to php for processing
function submit_problem() {
	var post = $("#problem_report").serialize();
	$.post("/ajax/site.php?action=submit_bug_report",
	post, function(problem_result){alert(problem_result);});

	hide_problem();
}

//show stats based on type
function show_type_stats(type, type_id) {
	$('#text_body').hide("slow");
	$('#ajax_body').show("slow");

	$.post("/ajax/site.php?action=show_page_stats",
	{'type':type, 'type_id':type_id}, function(result){$('#ajax_body').html(result);});
}

//show stats based on type
function show_type_history(type, type_id) {
	$('#text_body').hide("slow");
	$('#ajax_body').show("slow");

	$.post("/ajax/site.php?action=show_type_history",
	{'type':type, 'type_id':type_id}, function(result){$('#ajax_body').html(result);});
}

//show page type rev history
function show_rev_history(type_id) {
	$('#text_body').hide("slow");
	$('#ajax_body').show("slow");

	$.post("/ajax/site.php?action=show_rev_history",
	{'type_id':type_id}, function(result){$('#ajax_body').html(result);});
}

//show contributors for page type
function show_type_contributors(type, type_id) {
	$('#text_body').hide("slow");
	$('#ajax_body').show("slow");

	$.post("/ajax/site.php?action=show_type_contributors",
	{'type':type, 'type_id':type_id}, function(result){$('#ajax_body').html(result);});
}

//show hide stats and go back to text
function show_type_body() {
	$('#text_body').show("slow");
	$('#ajax_body').hide("slow");
}

//show the problem report box
function popup_twitter(){
      $('#twitter_container').show("slow");
}

//hide the problem report box
function hide_twitter(){
      $('#twitter_container').hide("slow");
}

//submit and send problem report to php for processing
function submit_twitter() {
      var post = $("#twitter").serialize();
      $.post("/ajax/site.php?action=submit_twitter",
              post, function(problem_result){alert(problem_result);});

              hide_problem();
}

//show the problem report box
function popup_blogcalendert(){
      $('#blogcalendert_container').show("slow");
}

//hide the problem report box
function hide_blogcalendert(){
      $('#blogcalendert_container').hide("slow");
}

//show the problem report box
function popup_blogcalenderb(){
      $('#blogcalenderb_container').show("slow");
}

//hide the problem report box
function hide_blogcalenderb(){
      $('#blogcalenderb_container').hide("slow");
}

//show the problem send2friend
function popup_send2friend(){
	$('#send2friend_container').show("slow");
}

//hide the problem send2friend
function hide_send2friend(){
	$('#send2friend_container').hide("slow");
}

//process send2friend when submited
function submit_send2friend() {
	var post = $("#send2friend_form").serialize();
	$.post("/ajax/site.php?action=submit_send2friend",
	post, function(send2friend_result){alert(send2friend_result);});

	$('#send2friend_container').hide();
}

//show top rightside login
function popup_login(){
	$('#login_container').show("slow");
}

//hide top rightside login
function hide_login(){
	$('#login_container').hide("slow");
}

//process top rightside login when submited
function submit_login() {
	var post = $("#login_form").serialize();
	$.post("/ajax/site.php?action=submit_login",
	post, function(login_result){
		if(login_result=="1")
			window.location.reload();
		else
			alert('Login failed, please try again ' + login_result);
	});

	$('#login_container').hide();
}

//process top rightside login when submited
function submit_loginctrl() {
	var post = $("#login_control").serialize();
	$.post("/ajax/site.php?action=submit_login",
	post, function(login_result){
		if(login_result=="1")
			window.location.reload();
		else
			alert('Login failed, please try again ' + login_result);
	});

	$('#login_container').hide();
}

//process logoff
function logoff(go_to) {
	$("#logoff").load("/ajax/site.php?action=logoff&go_to="+go_to);

	window.location.reload();
}

function revert_content(content_id, revision_id) {
	//alert("reverting...");
	$("#revert").load("/ajax/site.php?action=revert_content&content_id="+content_id+"&revision_id="+revision_id);

	//alert("content reverted");
	//window.location.reload();
}

function check_username_avil(username) {
	$.post("/ajax/site.php?action=check_username_avil",
	{'username':username}, function(result){
		if(result=="Taken") {
			$('input[type=submit]').attr('disabled', 'disabled');
			$('#userStatus').html("This username is " + result);
			$('#username').val("Taken");
		 } else {
			 $('input[type=submit]').removeAttr("disabled");
			 $('#userStatus').html("This username is " + result);
		 }
	});
}

function check_email_avil(email) {
	var filter=/^.+@.+\..{2,3}$/

	if (filter.test(email)) {
		$.post("/ajax/site.php?action=check_email_avil",
		{'email':email}, function(result){
			if(result=="Taken") {
				$('input[type=submit]').attr('disabled', 'disabled');
				$('#emailStatus').html("This email is " + result);
				$('#email').val("Taken");
			} else {
				$('input[type=submit]').removeAttr("disabled");
				$('#emailStatus').html("This email is " + result);
			}
		});
	} else {
		$('input[type=submit]').attr('disabled', 'disabled');
		$('#emailStatus').html("This email address is invalid");
	}
}