function subscribe(node) {
	var url = '/ali/processors/subscribe_processor.php?tid=' + tid;

	request.open("GET",url,true);
	request.onreadystatechange = function() { subscribeResults(node); };
	request.send(null);
}

function subscribeResults(node) {
	if (request.readyState == 4 && request.status == 200) {
		if (hasClass(node,"subscribe")) {
			node.className = "action_link unsubscribe";	
			node.innerHTML = "Unsubscribe from this thread";
		} else {
			node.className = "action_link subscribe";	
			node.innerHTML = "Subscribe to this thread";		
		}
		
		node.style.backgroundColor = "#dddddd";
	}
}

function reply(node) {
	var pid = node.getAttribute("id");
	
	new Effect.ScrollTo('newPost',{offset: -1});
	clearForm();
	
	var replyForm = document.forms.newPost;
	replyForm.replyTo.value = pid;
	
	// Find parent head
	var pNode = node.parentNode;
	
	while (!hasClass(pNode,'head')) {
		pNode = pNode.parentNode;
	}
	
	var header = pNode.getElementsByTagName("b")[0];
	var headText = header.firstChild.data;
	
	var intro = headText.substr(0,3);

	if (intro != "RE:") {
		replyForm.title.value = "RE: " + headText;
	} else {
		replyForm.title.value = headText;	
	}

	var th = document.createElement("th");
	th.className = "align_right";
	var th_text = "In Reply To:";
	var th_tnode = document.createTextNode(th_text);
	th.appendChild(th_tnode);
	
	var td = document.createElement("td");
	var b = document.createElement("b");
	var td_node = document.createTextNode(headText);
	b.appendChild(td_node);

	var clear = document.createElement("a");
	clear.href = window.location;
	clear.innerHTML = "[clear]";
	clear.className = "clearForm";
	clear.onclick = function() { clearForm(); return false; };
	
	td.appendChild(b);
	td.appendChild(clear);
	
	var replyArea = document.getElementById("insertReply");
	replyArea.appendChild(th);
	replyArea.appendChild(td);	
}

function edit(node) {
	var pid = node.getAttribute("id");

	var pNode = node.parentNode;
	
	while (!hasClass(pNode,'head')) {
		pNode = pNode.parentNode;
	}
	
	var header = pNode.getElementsByTagName("b")[0];
	var headText = header.firstChild.data;

	while (!hasClass(pNode,'post')) {
		pNode = pNode.parentNode;
	}

	var divs = pNode.getElementsByTagName("div");
	
	for (i=0;i<divs.length;i++) {
		if (hasClass(divs[i],"message")) {
			var messageText = divs[i].getElementsByTagName("span")[0].innerHTML;
		}
	}


	new Effect.ScrollTo('newPost',{offset: -1});
	clearFormPlus();

	var replyForm = document.forms.newPost;
	replyForm.title.value = headText;
	replyForm.message.value = messageText;
	replyForm.action.value = "edit";
	replyForm.replyTo.value = pid;

	var th = document.createElement("th");
	th.className = "align_right";
	var th_text = "Editing:";
	var th_tnode = document.createTextNode(th_text);
	th.appendChild(th_tnode);
	
	var td = document.createElement("td");
	var b = document.createElement("b");
	var td_node = document.createTextNode(headText);
	b.appendChild(td_node);

	var clear = document.createElement("a");
	clear.href = window.location;
	clear.innerHTML = "[clear]";
	clear.className = "clearForm";
	clear.onclick = function() { clearFormPlus(); return false; };
	
	td.appendChild(b);
	td.appendChild(clear);
	
	var replyArea = document.getElementById("insertReply");
	replyArea.appendChild(th);
	replyArea.appendChild(td);
}

function clearForm() {
	var replyArea = document.getElementById("insertReply");
	replyArea.innerHTML = "";

	var replyForm = document.forms.newPost;
	replyForm.replyTo.value = "";
	replyForm.title.value = "";
	replyForm.action.value = "newPost";
}

function clearFormPlus() {
	var replyArea = document.getElementById("insertReply");
	replyArea.innerHTML = "";

	var replyForm = document.forms.newPost;
	replyForm.replyTo.value = "";
	replyForm.title.value = "";
	replyForm.message.value = "";
	replyForm.action.value = "newPost";
}

function openBox(id) {
	var content = document.getElementById(id);
	var box = content.parentNode;

	while (!hasClass(box,"sidebox")) {
		box = box.parentNode;
	}
		
	if (hasClass(box,"expanded")) {
		box.className = "sidebox";
		Effect.BlindUp(id,{duration: .2});
	} else {
		box.className = "sidebox expanded";
		Effect.BlindDown(id,{duration: .2});		
	}
}

function scrollToForm(node) {
	clearForm();

	new Effect.ScrollTo('newPost',{offset: -1});
}

function featureThread (item) {
	
	var url = "processors/feature_thread.php?threadid=" + item +  "&action=featureThread";
	alert (url);
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	  	alert ("Thread Featured.");
	}
	});
	
	}