/*********************************
GREEK9 SOURCE CODE
**********************************
GREEK9.JS [Nick Staples]
*********************************/





			
				
				
window.onload = function()
{
	//	

}




function change_def(id, type)
{
	theNode = document.getElementById(id);
	oldval = theNode.firstChild.nodeValue;
	
	sign = oldval[0];
	
	if (sign == '-')
		oldnum = oldval[1]*(-1);
	else
		oldnum = oldval[1]*1;
	
	oldnum = parseInt(oldval);
	
	if (type == "+")
		oldnum++;
	else
		oldnum--;
	
	if (oldnum >= 0)
		newnum = '+'+oldnum;
	else
		newnum = oldnum;
	
	theNode.firstChild.nodeValue = newnum;
}

function disactivate_def(id)
{
	upNode = document.getElementById("dgu"+id);
	downNode = document.getElementById("dgd"+id);
	upNode.src = "images/icons/def_up_off.png";
	downNode.src = "images/icons/def_down_off.png";
	
	upNode.parentNode.removeAttribute("href");
	downNode.parentNode.removeAttribute("href");
	
}

function du(post_id) // def up
{
	//http://greek9/greek/def.php?a=d&t=1&p=6
	new ajax('def.php',{postBody:'a=u&p='+post_id}).request();
	change_def('d'+post_id, "+");
	disactivate_def(post_id);
	//new ajax('def.php',{postBody:'a=u&p='+post_id, onComplete: showResponse}).request();
	// function showResponse(request) { alert(request); };

}

function dd(post_id) // def down
{
	new ajax('def.php',{postBody:'a=d&p='+post_id}).request();
	change_def('d'+post_id, "-");
	disactivate_def(post_id);
}

function sp(post_id) // show post
{
	//scriptalicious (too hot)
	//new Effect.SlideDown('c'+post_id);
	//new Effect.Opacity('t'+post_id, {duration:1.0, from:0.3, to:1.0});
	
	//interface (too cold)
	//$('#c'+post_id).SlideInUp(2000);
	
	//moo (juuuuust right)
	b1Toggle = new Fx.Height('c'+post_id, {duration: 500, onComplete:
	
	function()
	{
		new Fx.Style('t'+post_id, 'opacity', {duration:500}).custom(.3,1); 
		
	}
	
	});
	
	$('c'+post_id).setStyle('display','block');
	b1Toggle.toggle();
	
	
	bo = document.getElementById('v'+post_id);
	bo.href = "javascript:hp("+post_id+");"; // edit the javascript function
	bo.firstChild.nodeValue = " [hide comment] "; // edit the text
	
	//alert(comment.style);
}

function hp(post_id)
{
	   
	//scriptalicious (too hot)
	//new Effect.SlideUp('c'+post_id);
	//new Effect.Opacity('t'+post_id, {duration:1.0, from:1.0, to:0.3});
	
	//interface (too cold)
	//$('#c'+post_id).SlideOutUp(2000);
	
	//moo (juuuuust right)
	b1Toggle = new Fx.Height('c'+post_id, {duration: 500, onComplete:
	
	function()
	{
		new Fx.Style('t'+post_id, 'opacity', {duration:500}).custom(1,.3); 
		
	}
	
	});
	b1Toggle.toggle();

	bo = document.getElementById('v'+post_id);
	bo.href = "javascript:sp("+post_id+");"; // edit the javascript function
	bo.firstChild.nodeValue = " [show comment] "; // edit the text
	
	//comment = document.getElementById('c'+post_id);
	//comment.setStyle('height', 'auto');
}


function dp(target, type) // delete post
{
	
	if (type == 1)
		var rvalue = confirm("Do you really want to delete this comment?");
	else
		var rvalue = confirm("Do you really want to delete this post?");
	
	if (rvalue == true)
		window.location = target;
	

	


}

function ep(p_id, ref) // edit post
{
		
	comment = document.getElementById('p'+p_id);
	bottom_comment = document.getElementById('b'+p_id);
	
	//olddata = comment.firstChild.nodeValue;
	//comment.removeChild(comment.firstChild);
	olddata = comment.innerHTML;
	comment.innerHTML = "";
	
	ref = document.location;
	
	while (bottom_comment.firstChild)
	{
		bottom_comment.removeChild(bottom_comment.firstChild);
	}

	// hmmmmm. DOM or innerhtml, DOM or innerhtml. *sigh* imma do the right thing for once. DOM it is:
	
		var d = document;
		
		// createElement: eDIV = dce("div");
		function dce(obj) 
		{
			return d.createElement(obj);
		}
		
		// createTextNode: eTxtNode = dct("Hello World!");
		function dct(str) 
		{
			return d.createTextNode(str);
		}
		
		// appendChild: ac(eUL,eLI);
		function ac(pNode,cNode) 
		{
			pNode.appendChild(cNode);
		}
		
		// setAttribute: sa(eDIV,"id","myDiv");
		function sa(obj,attr,val) 
		{
			obj.setAttribute(attr,val);
		}
		
		// getElementById: ge("mContainer");
		function ge(objID) 
		{
			return d.getElementById(objID);
		}
		
		//Form
		eForm = dce("form");
		eForm.style.cssText = "display:inline";
		eForm.method = "POST";
		eForm.action = "post.php?action=edit";
		
		
		//center tag
		eCenter = dce("center");
		
		//text area
		eTextarea = dce("textarea");
		eTextarea.style.cssText = "width:450px; margin-left:15px; height:150px";
		eTextarea.name = "e_text";
		
		//eComment
		eComment = dct(olddata);
		
		//Submit button
		eSubmit = dce("input");
		eSubmit.className= "shade";
		eSubmit.style.cssText = "width:100px; margin-left:15px;";
		eSubmit.type = "submit";
		eSubmit.value= "Update";

		//hidden ref
		eRef = dce("input");
		eRef.type = "hidden";
		eRef.name = "ref";
		eRef.value = ref;
		
		//hidden pid
		ePid = dce("input");
		ePid.type = "hidden";
		ePid.name = "p_id";
		ePid.value = p_id;
		
		ac(eTextarea, eComment);
		ac(eCenter, eTextarea);
		ac(eForm, eCenter);
		
		ac(eForm, eRef);
		ac(eForm, ePid);
		
		ac(eForm, eSubmit);
		ac(comment, eForm);

	
}

function vouch_toggle(id, org, hid)
{

	cc_tag = "cc-" + org;
	that = document.getElementById(cc_tag);
	
	v_tag = "v-" + org + "-" + hid;	
	if(document.getElementById(v_tag).style.display == "inline")
		vouch_remove(id, org, hid, that);
	else
		vouch_add(id, org, hid, that);
	
}

function vouch_add(id, org, hid, that)
{
	if(confirm("Are you sure you want to VOUCH for this person?"))
	{
		new ajax('vouch.php',{postBody:'id=' + id + '&g=' + org + '&action=yes'}).request();
		v_tag = "v-" + org + "-" + hid;
		c_tag = "cb-" + org;
		document.getElementById(v_tag).style.display = "inline";
		document.getElementById(c_tag).style.backgroundColor = "#DAFFCC";
		that.checked = true;
	}
	else
		that.checked = false;
	
}


function vouch_remove(id, org, hid, that)
{
	if(confirm("Are you sure you want to REMOVE your vouch?"))
	{
		new ajax('vouch.php',{postBody:'id=' + id + '&g=' + org + '&action=no'}).request();
		v_tag = "v-" + org + "-" + hid;
		c_tag = "cb-" + org;
		document.getElementById(v_tag).style.display = "none";	
		document.getElementById(c_tag).style.backgroundColor = "#FFFFFF";
		that.checked = false;
	}
	else
		that.checked = true;

	
	
}

