// JavaScript Document

/*************************************************

Charter for Compassion Commit Button

Author: Olin Lagon

Based on: Jquery

	

************************************************/

function showRemove(cid) {
	$("#remove_" + cid).slideToggle("slow");
}

function showCommit(cid) {
	$("#commit_" + cid).slideToggle("slow");
}

function commit(cid,t) {
	$("#banner_" + cid).removeClass("commitbannerblue").fadeOut("slow").addClass("commitbanneryellow").fadeIn("slow");
	var link = "<a href=\"#\" onClick=\"showRemove(" + cid + ");return false;\">On Board!</a>"
	$("#commitbox_" + cid).html(link);
	$("#commit_" + cid).slideToggle("slow");
	$.post('/actions/commitments/commit/index.tpl', {
		type: t,
		cid: cid
	});
	v = Number($("#num_" + cid).html()) + 1;
	if (v == 0)
		v = "0";
	$("#num_" + cid).html(v);
}

function removeCommitment(cid) {
	$("#banner_" + cid).removeClass("commitbanneryellow").fadeOut("slow").addClass("commitbannerblue").fadeIn("slow");
	var link = "<a href=\"#\" onClick=\"showCommit(" + cid + ");return false;\">I Commit!</a>"
	$("#commitbox_" + cid).html(link);
	$("#remove_" + cid).slideToggle("slow");
	$.post('/actions/commitments/remove/index.tpl', {
		cid: cid
	});
	v = Number($("#num_" + cid).html()) - 1;
	if (v == 0)
		v = "0";
	$("#num_" + cid).html(v);
}

function addcommitment(cid) {
	$("#c_" + cid).removeClass("commitoff").fadeOut("slow").addClass("commiton").fadeIn("slow");
	v = Number($("#v_" + cid).html()) + 1;
	if (v == 0)
		v = "0";
	$("#b_" + cid).html("<div id=\"v_"+cid+"\">"+v+"</div>");
	$("#o_" + cid).html("<P style=\"text-align:left;font-size:8pt;background:#ffffcc\">My status: 	<strong>Habit / I did it</strong> - <a href=\"/?on=c\">change status</a></p>").fadeOut("slow").fadeIn("slow");
	$.post('/actions/commit/add/index.tpl', {
		cid: cid
	});
}

function removecid(cid) {
	$("#c_" + cid).removeClass("commiton").fadeOut("slow").addClass("commitoff").fadeIn("slow");
	v = Number($("#v_" + cid).html()) - 1;
	$("#b_" + cid).html("<a href=\"#\" onClick=\"addcommitment("+cid+");return false;\" class=\"clean\"><div id=\"v_"+cid+"\">"+v+"</div><br /><img src=\"/images/spacer.gif\" style=\"width:100%;height:100%;border:none;\"></a>");
	$("#o_" + cid).slideToggle("slow").html("");
	$.post('/actions/commit/remove/index.tpl', {
		cid: cid
	});

}
function changestatus(cid,type) {
	$.post('/actions/commit/changestatus/index.tpl', {
		cid: cid,
		type: type
	});
	$("#o_" + cid).load("/ajax/genoptions.tpl?cid="+cid+"&type="+type+"&r="+Math.random()).fadeOut("slow").fadeIn("slow");	
}
function addaction(aid) {
	$("#c_" + aid).removeClass("actionoff").fadeOut("slow").addClass("actionon").fadeIn("slow");
	v = Number($("#v_" + aid).html()) + 1;
	if (v == 0)
		v = "0";
	$("#b_" + aid).html("<div id=\"v_"+aid+"\">"+v+"</div>");
	$.post('/actions/action/add/index.tpl', {
		aid: aid
	});
}

