$(document).ready(function() {
	$(".toggleQContent").click(function(){
		$(this).parent().next("p.padLeftQ").toggle();
	});

	$(".toggleAContent").click(function(){
		$(this).parent().next("p.padLeftA").toggle();
	});

});

$(document).ready(
	function() {
		$("#q-f-form").submit(function(){return false;});
		$("#q-f-form-submit").click(function(){checkQForm();});
	}
);

function checkQForm()
{
	var stp = false;
	var requiredFields = ["name","question_categories","question_title","question_content"];

    $.each(requiredFields, function() {
		if ($("#" + this).val() == '') {$("#" + this).addClass("errorInput"); stp = true; }
		else {$("#" + this).removeClass("errorInput"); }
    });

	var e = $("#email").val();
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if (!e.match(re)) { $("#email").addClass("errorInput"); stp = true;} else { $("#email").removeClass("errorInput"); }

	if (stp == true) {
		alert("Lütfen bilgilerinizi kontrol ediniz!");
	} else {
		$.ajax({
			type: "POST",
			url: "/forms/questions.php",
			dataType: "html",
			data: $("#q-f-form").serialize(),
			success: function(response){
				if (response == 'ok') {
					alert('Sorunuz listeye eklendi.');
					document.forms["q-f-form"].reset();
				} else {
					alert(response);
				}
			},
			error: function(){
				alert("Hata meydana geldi. Lütfen tekrar deneyiniz.");
			}
		});
		return false;
	}
}



/***LOGIN***/

$(document).ready(
	function() {
		$("#login-form").submit(function(){return false;});
		$("#login-form-submit").click(function(){checkLForm();});
	}
);

function checkLForm()
{
	var stp = false;
	var requiredFields = ["user","pass"];

    $.each(requiredFields, function() {
		if ($("#" + this).val() == '') {/*$("#" + this).addClass("errorInput");*/ stp = true; }
		else {/*$("#" + this).removeClass("errorInput");*/ }
    });

	if (stp == true) {
		alert("Lütfen bilgilerinizi kontrol ediniz!");
	} else {
		$.ajax({
			type: "POST",
			url: "/forum/xhr.php?t=auth_login",
			dataType: "html",
			data: $("#login-form").serialize(),
			success: function(response){
				if (response == 'OK') {
					//alert("OK");
					window.location = window.location.href;
				} else if (response == 'ERROR') {
					alert("Kullanıcı adı yada parola hatalı.");
				} else {
					alert("Hata meydana geldi. Lütfen tekrar deneyiniz.");
				}
			},
			error: function(){
				alert("Hata meydana geldi. Lütfen tekrar deneyiniz.");
			}
		});
		return false;
	}
}


/***LOGIN***/

$(function() {
  $("#module-categories").accordion({initShow : "ul.current"});
});

