var GLOBAL_DIR = "";

jQuery(document).ready(function($){
	$('.comment-form').submit(function(){ submitCommentForm($(this)); return false;});
	
	
	$('textarea.richtextsimple').tinymce({
		// Location of TinyMCE script
		script_url : '/site/tiny_mce/tiny_mce.js',

		// General options
		theme : "advanced",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,bullist",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		//theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "",

		relative_urls : false, 
		
		

		file_browser_callback : "tinyBrowser",
		remove_script_host : false,

		height: "150px",
		width: "360px",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
		}
	});
	
	
		
	$('textarea.richtextsimple-large').tinymce({
		// Location of TinyMCE script
		script_url : '/site/tiny_mce/tiny_mce.js',

		// General options
		theme : "advanced",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,bullist",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		//theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "",

		relative_urls : false, 

		file_browser_callback : "tinyBrowser",
		remove_script_host : false,

		height: "300px",
		width: "540px",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
		}
	});
	
	
	$('textarea.richtextsimple-wide').tinymce({
		// Location of TinyMCE script
		script_url : '/site/tiny_mce/tiny_mce.js',

		// General options
		theme : "advanced",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,bullist",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		//theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "",

		relative_urls : false, 

		file_browser_callback : "tinyBrowser",
		remove_script_host : false,

		height: "150px",
		width: "540px",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
		}
	});	
	
	
});

function dropShadows()
{

}

function hideShadows()
{

}

/** Comment functions **/
function submitCommentForm(frm)
{

	var comment = frm.children("textarea.comment-form-textbox").val();
	var type = frm.children(":input[name=type]").val();
	var id = frm.children(":input[name=id]").val();
	var withComments = frm.children(":input[name=withComments]").val();
	var reply = frm.children(":input[name=reply]").val();
	var vote = "";
	
	comment = $.trim(comment);
	
	if(comment == "")
		return false;
				
	if(!(frm.children("div.'comment-check-parent").children(":input[name=comment-check]").is(':checked')))
	{
		alert("You must tick the checkbox regarding the Terms of Use to post a comment.");
		return false
	}
	if(type == "")
	{
		alert("Medical Observer system error - Comment form error TYPE_01");
		return false;
	}
	if(id == "")
	{
		alert("Medical Observer error - Comment form error IDENTIFIER_01");
		return false;
	}	
	if(reply != 0)
	{
		frm.parent().parent().find(".comment-new:last").append(getCommentScript(comment));
		$(".comment-form-reply").remove();
	}
	else
	{
		frm.parent().parent().find(".comment-new:last").append(getCommentScript(comment));
	}
	
	$.post(GLOBAL_DIR + "/comment/addComment", { comment: comment, type: type, id : id, vote: vote, reply: reply }, function(xml){
		frm.children("textarea.comment-form-textbox").val("");
	});	
	return false;
}

function getCommentScript(comment)
{
	var rtnText = '<div class="comment-display-new"><div class="comment-display-message"><div class="comment-display-avitar">';
	rtnText += '<span class="comment-display-name">You</span><Br /><span class="comment-display-time">Just now</span></div>';
	rtnText += '';
	rtnText += comment;
	rtnText += '</div><div class="clearMe"></div></div>';
	return rtnText;
}

function commentRemove(id, isSub)
{
	if(!confirm("Are you sure you want to remove this comment?"))
	{
		return;
	}
	$("#comment-" + id).css("background-color", "#F2BFBF");
	$("#comment-" + id + " .comment-display-delete").html("removing...");
	$.post(GLOBAL_DIR + "/comment/removeComment", {id : id }, function(xml){
		$("#comment-" + id).fadeTo("slow", 0.33);
		$("#comment-" + id + " .comment-display-delete").html("comment removed");
	});
}


function commentReport(id, isSub)
{
	if(!confirm("Are you sure you want to report this comment?"))
	{
		return;
	}
	$("#comment-" + id).css("background-color", "#F2BFBF");
	$("#comment-" + id + " .comment-display-delete").append("reporting...");
	$.post(GLOBAL_DIR + "/comment/reportComment", {id : id }, function(xml){
		$("#comment-" + id).fadeTo("slow", 0.33);
		$("#comment-" + id + " .comment-display-delete").html("comment reporting");
	});
}

function commentReply(id, id2, type)
{
	var rntText = '<form name="comment-form" class="comment-form-reply comment-form" onSubmit="return false"><textarea class="comment-form-textbox" name="comment" style="width: 500px"></textarea><input type="hidden" name="type" value="' + type + '"><input type="hidden" name="withComments" value="0"><input type="hidden" name="reply" value="' + id + '"><input type="hidden" name="id" value="'+ id2 + '">' + "<div style='float: left' class='comment-check-parent'><input type='checkbox' class='comment-check' name='comment-check'></div><div style='float: left; width: 400px; padding-left: 5px; margin-bottom: 5px'>I understand that submission of this comment is covered by the <a href='http://www.medicalobserver.com.au/about/terms-of-use' target='_blank'>Terms of Use</a> by which I am bound. <a href='http://www.medicalobserver.com.au/about/commenting-rules' target='_blank'>Commenting Rules</a>.</div>" + '<div class="clearAll"></div><input type="submit" class="comment-form-submit" value="Post Reply" style="font-size: 12px"  /></form>';
	$("#comment-" + id + " .comment-display-extra").html(rntText);
	$('.comment-form-reply').submit(function(){ submitCommentForm($(this)); return false;});
}

function validateThread(vv)
{
	if(vv.name.value == "")
	{
		alert("Please provide a name for this thread.");
		
	}
	if(vv.description.value == "")
	{
		alert("Please provide a description for this thread.");
	}
	return true;
}
