$(document).ready(
  function(){
    $("a#shcswitch").toggle(
      function () {
	$("a#shcswitch span").text("Show");
	$("a#shcswitch img").attr("src",templateDirect+"/external/images/bg_facilities_closed.gif");

	$("ol.commentlist").slideUp();
      },
      function () {
	$("ol.commentlist").slideDown();
	$("a#shcswitch img").attr("src",templateDirect+"/external/images/bg_facilities_open.gif");
	$("a#shcswitch span").text("Hide");
      }
    )
    $("a#acswitch").toggle(
      function () {
	$("a#acswitch img").attr("src",templateDirect+"/external/images/bg_facilities_closed.gif");
	$("#commentform").slideUp();
      },
      function () {
	$("#commentform").slideDown();
	$("a#acswitch img").attr("src",templateDirect+"/external/images/bg_facilities_open.gif");

      }
    )
  }
);

function gotoSignInFromComments() {
  window.location= signinUrl + window.location + "#respond";
}

function validateComment(){
  if($("#commentText").val() == ""){
    $("#commentform").append("<p class='errorMsg'>Please enter a comment.</p>");
    return false;
  }else{
    return true;
  }
}


function setCurrentUser(login){
  lpLoggedInUsername = login;
}

function userIsLoggedIn() {
  return (typeof lpLoggedInUsername != "undefined") && (lpLoggedInUsername != "");
}

function showNewCommentBox(){
  $("#addCommentBox").show();
  $("#signInToCommentBox").hide();
  $("#commentAuthorLogin").val(lpLoggedInUsername);
}

function showSignInBox() {
  $("#addCommentBox").hide();
  $("#signInToCommentBox").show();
}

function displayCommentBox(){
  if(userIsLoggedIn()) {
    showNewCommentBox();
  }
  else {
    showSignInBox();
  }
  return "Current user is:" + lpLoggedInUsername;
}

