	
	/* ------------------------------------------
	*  VIEW TOPIC PAGE
	* ---------------------------------------- */
	function viewPage(){
		var replyForm = $('#reply-to-topic');
	
		// Submit the comment via ajax
		/*replyForm.submit(function(){
			$.ajax({
				url: $(this).attr('action'),
				method: $(this).attr('method'),
				data: {
					"enid": 1,
					"reply[body]": "test",
					"ajax": true
				},
				complete: function(transport){
					// Insert the comment into the DOM
					$('#replies').append('<div class="reply">test</div>');
					
					// Empty the textarea
					$('#txtReplyBody').val('');
				}
			});
			return false;
		});*/
		
		// Hook up the delete links
		$('a.delete_reply').click(function(){
			if (confirm("Are you sure you want to delete this comment? It cannot be undone.")){
				$.ajax({
					url: this.href,
					complete: function(){
						$(this).parents('div.reply').hide('drop', {direction:'down'}, 500);
					}.bind(this)
				});
			}
			return false;
		});
		
        // Hook up the reply links
		$('a.post_reply').click(function(){
			var enid = this.id.split('-')[1];
			var forumpost = $('#forumpost_' + enid);
			var quote = '<strong>In reply to ' + $('h5>a', forumpost).html() + '</strong>';
			$('#txtReplyBody') // PETRO: We will need to take care of an edge-case here, occuring when there is no "<p>" tag
				.val(quote + "\n<blockquote>" + $('#forumpost_body_' + enid + '>p').get($('#forumpost_body_' + enid + '>p').size()-1).innerHTML.replace('<br>', "") + "\n</blockquote>")
				.focus()
				.addClass('focus');
			return false;
		});

	}


/**
 * Main JavaScript file for the forums
 */


/**
 * Sets up a reply form at the topic/reply
 */
function replyto(node,entityid,mode) {
	mode = mode || 'reply';
	var rf = document.getElementById('replyform');
	var ennode = document.getElementById('enid');
	//set the current node id
	ennode.value = parseInt(entityid);
	
	//display the reply form
	rf.style.display = 'block';
	
	//move the reply form to the position of the button
	rf.style.top = (getTop(node) + node.scrollHeight) + 'px';
	rf.style.left = (getLeft(node) - (mode == 'reply' ? rf.offsetWidth - node.offsetWidth : 0)) + 'px';

	//and focus on the title field
	rf.getElementsByTagName('input')[1].focus();
}
/**
 * Validate the REPLY or TOPICform
 */
function validate(prepend) {
	var elms = [document.getElementById(prepend + '_title'),document.getElementById(prepend + '_body')];
	var ok = true;
	for(var i=0;i<elms.length;i++) {
		if(elms[i].value.length < 3) {
			elms[i].className = 'required_missing';
			ok = false;
		}
	}
	
	if(!ok) {
		document.getElementById('replynotice').firstChild.nodeValue = 'Please fill out the required fields before submitting your ' + prepend +'!';
	}
	return ok;
}
/**
 * Delete the post identified by enid
 * @param HTMLElement sender
 * @param bigint enid
 * @param string elementid - the id of the HTML element containing the post
 */
function deletePost(sender,enid,elementid) {
	if(confirm('Are your SURE you want to delete this post?\nThis will also delete all replies to this post and is PERMANENT')) {
		var xmlhttp = createXMLHttpRequest();
		xmlhttp.open('POST',DOMAIN_ASYNC + '/forum/delete',true);
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		var data = 'enid='+encodeURIComponent(enid);
		
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4) {
				var json = eval(xmlhttp.responseText);
				alert(json.header.msg);
				if(json.header.code == 0) {
					document.getElementById(elementid).style.display = 'none';
				}
			}
		};
		xmlhttp.send(data);
	}
	return false;
}