var quesEditStatus = 0;

function quesAddLoad () {
	new Ajax.Request("/data/question_edit.php?qa=add", {onSuccess: quesEditDraw});
}

function quesEditLoad (quesId) {
	new Ajax.Request("/data/question_edit.php?qid=" + quesId + "&qa=edit", {onSuccess: quesEditDraw});
}

function quesEditDraw (t) {
	tmpResponse = t.responseText;
	if (tmpResponse == "//back//") {
		window.location.href = "/discussions";
	} else {
		$("wPane").innerHTML = t.responseText;
		if (BrowserDetect.browser == "Explorer") {
			$("wPane").style.display = "block";
		} else {
			new Effect.Appear("wPane", {queue: {position: "end", scope: "pane"}, duration: 0.25});
		}
		quesEditStatus = 0;
	}
}

function quesEditProcess () {
	new Ajax.Request("/data/question_edit.php", {onSuccess: quesEditProcessOut, parameters: Form.serialize(document.quesEdit)});
}

function quesEditProcessOut (t) {
	quesEditStatus = 0;
	quesEditCancel();
	tmpMessage = t.responseText;
	if (tmpMessage == "//reload//") {
		window.location.reload(false);
	} else if (tmpMessage == "//back//") {
		window.location.href = "/discussions";
	} else {
		alertBubbleAdd(tmpMessage);
	}
}

function quesEditChanged () {
	quesEditStatus = 1;
}

function quesEditCancel () {
	if (quesEditStatus == 1) {
		if (window.confirm("By canceling without saving, your changes will be lost. If you are okay with this, please click OK. To return to your edits, click Cancel.")) {
			new Effect.Fade("wPane", {queue: {position: "end", scope: "pane"}, duration: 0.25});
			quesEditStatus = 0;
		}
	} else {
		new Effect.Fade("wPane", {queue: {position: "end", scope: "pane"}, duration: 0.25});
	}
}

var ansEditStatus = 0;

function ansAddLoad (quesId) {
	new Ajax.Request("/data/answer_edit.php?aa=add&qid=" + quesId, {onSuccess: ansEditDraw});
}

function ansEditLoad (ansId) {
	new Ajax.Request("/data/answer_edit.php?aid=" + ansId + "&aa=edit", {onSuccess: ansEditDraw});
}

function ansEditDraw (t) {
	$("wPane").innerHTML = t.responseText;
	if (BrowserDetect.browser == "Explorer") {
		$("wPane").style.display = "block";
	} else {
		new Effect.Appear("wPane", {queue: {position: "end", scope: "pane"}, duration: 0.25});
	}
	ansEditStatus = 0;
}

function ansEditProcess () {
	new Ajax.Request("/data/answer_edit.php", {onSuccess: ansEditProcessOut, parameters: Form.serialize(document.ansEdit)});
}

function ansEditProcessOut (t) {
	ansEditStatus = 0;
	ansEditCancel();
	tmpMessage = t.responseText;
	if (tmpMessage == "//reload//") {
		window.location.reload(false);
	} else {
		alertBubbleAdd(tmpMessage);
	}
}

function ansEditChanged () {
	ansEditStatus = 1;
}

function ansEditCancel () {
	if (ansEditStatus == 1) {
		if (window.confirm("By canceling without saving, your changes will be lost. If you are okay with this, please click OK. To return to your edits, click Cancel.")) {
			new Effect.Fade("wPane", {queue: {position: "end", scope: "pane"}, duration: 0.25});
			ansEditStatus = 0;
		}
	} else {
		new Effect.Fade("wPane", {queue: {position: "end", scope: "pane"}, duration: 0.25});
	}
}

var profFollowId = 0;
function profFollow(profId) {
	profFollowId = profId;
	new Ajax.Request("/data/prof_follow.php?pid=" + profId, {onSuccess: profFollowDraw});
}
function profFollowDraw(t) {
	tmpResponse = t.responseText;
	if (tmpResponse == "//followed//") {
		alertBubbleAdd("You are now following this professional.");
	} else {
		alertBubbleAdd("You are no longer following this professional.");
	}
}
