
function toggleViewLooked(){

  if($('#IsVenusLooked').attr('checked') == true){
    $('.VenusLooked').css('color','#663300');
    $('.VenusLookedForm').removeAttr('disabled');
    $('.VenusLookedForm').css('color','#663300');
	$('.VenusLookedForm').css('border-color','#666');
  } else {
    $('.VenusLooked').css('color','#ccc');
	$('.VenusLookedForm').css('border-color','#ccc');
    $('.VenusLookedForm').css('color','#ccc');
    $('.VenusLookedForm').attr('disabled', 'disabled');
  }

}

function showLength(id, max_length){
  inputarea_id  = "#" + id;
  lengtharea_id = "#" + id + "_length";
  msgarea_id    = "#" + id + "_length_msg";
  input_length = $(inputarea_id).val().length;
  if(input_length > max_length){
    $(inputarea_id).css('color','red');
    $(lengtharea_id).css('color','red');
    $(msgarea_id).html(length_err);
  } else {
    $(inputarea_id).css('color','#663300');
    $(lengtharea_id).css('color','#663300');
    if(input_length > 0){
      $(msgarea_id).html("&nbsp;");
    }
  }
  $(lengtharea_id).html(input_length);
}

function checkLength(){

  err = false;
  msg = "";
  if($("#input_name").val().length > name_length){
    err = true;
  }
  if($("#input_comment").val().length > comment_length){
    err = true;
  }
  if(err == true){
    alert(length_err);
    return false;
  }
  return true;

}

$(function(){

  $('#IsVenusLooked').click(function(){ toggleViewLooked(); });
  toggleViewLooked();

  $("#input_name").keyup(function(){ showLength('input_name', name_length); });
  $("#input_comment").keyup(function(){ showLength('input_comment', comment_length); });

  $("#EntryFormFrame").submit(function () { return checkLength(); });
  showLength('input_name', name_length);
  showLength('input_comment', comment_length);

});
