function forumUserGreeting() {
	if (mag_user && mag_user.logged_in) {
		user = mag_user;
		name = user.first_name || user.user_name;
		displayName = (name.length > 12) ? name.substring(0,12) + '…' : name ;
		document.write ('<span class="black_hdr">Welcome,&nbsp;</span>');
		document.write ('<div class="purple"><a href="/community/profile/">');
		document.write (displayName);
		document.write ('</a>');
        document.write ('</div>');
   } 
   else {
		document.write("<div class='purple'>");
		document.write("<a href='/registration/'>Join Free</a>");
		document.write("<img src='/cm/thesurvivorsclub/site_images/community/solid_slash.gif'/>");
		document.write("<a href='/login/'>Sign In</a>");
        document.write("</div>");
	}
}

function getUrlParam(name){
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	if (!results) { return null; }
	return results[1];
}

function forumPostingLink(topicId) {
	if (mag_user && mag_user.logged_in) {
		document.write('<img width="7" height="15" src="/cm/thesurvivorsclub/site_images/community/icon_arrow_black.gif" /><a href="/community/forums/newThread?topic_id=' + topicId + '">Post a New Thread</a>');
	} else {
		document.write('<img width="7" height="15" src="/cm/thesurvivorsclub/site_images/community/icon_arrow_black.gif" /><a href="/registration/">Join free</a> or <a href="/login/">Sign in</a><span> to Post a New Thread</span>');
	}
}

function profileLink() {
	if (mag_user && mag_user.logged_in) {
		document.write('<a href="/community/profile/">My Profile</a>');
	} else {
		document.write('<a href="/login">My Profile</a>');
	}
}

function cancelPost() {
	$('#hearst_forum_subject').val("");
	$('#hearst_forum_body').val("");
	var url = document.location.href;
	if(url.indexOf('community/forums/newThread') != -1) {		
		document.location.href='/community/forums/topic/' + getUrlParam('topic_id');
	}	
}

function postThread() {
	var txtsubject=$('#hearst_forum_subject').val();
	txtsubject=$.trim(txtsubject);
	var txtbody=$('#hearst_forum_body').val();
	txtbody=$.trim(txtbody);

	if(txtsubject=="" && txtbody=="")
	{
		alert("Please insert Subject and Message Body");
		return;
	}
	if(txtsubject=="")
	{
		alert("Please insert Subject");
		return;
	}
	if(txtbody=="")
	{
		alert("Please insert Message Body");
		return;
	}
	if (!mag_user.logged_in) 
		document.location.href="/login";	
	
	else 
		hearstforums.post();		
}

$(document).ready(function(){	
	if (mag_user.logged_in) {
		$("[forumstate='online']").hide();
	} else {		
		$("#post_wrapper #post_list a.reply").attr("href", "/login");		
	}
});
