// Copyright Basement.nl, 2009

function RealCommentLength(AText)
{
  var LWordLength = 0;
  var LSmileCodes = [":", ";", "-", "_", " ", "^", "(", ")", ".", ",", "/", "?", "!", "@", "|", "3", "6"];

  for (var I = 0; I < AText.length; I++)
  {
    if (LSmileCodes.bas_indexOf(AText.charAt(I)) == -1)
    {
      LWordLength++;
    }
  }
  return LWordLength;
}

function btnSubmitClick()
{
  var LName = document.frmComment.poster_name.value.bas_trim();
  var LComment = document.frmComment.comment.value.bas_trim();

  if (FPindakaasGesmeerd === false)
  {
    document.frmComment.pindakaas.value = DoSmeerBoterhamMetPindakaas(document.frmComment.pindakaas.value);
  }

  LName = DoRemoveDoubleChars(LName);
  document.frmComment.poster_name.value = LName;
  LComment = DoRemoveDoubleChars(DoRemoveDoubleLines(LComment));
  document.frmComment.comment.value = LComment;
  
  document.frmComment.poster_site.value = DoFormatUrl(document.frmComment.poster_site.value);

  if (LName.length < 2)
  {
    document.getElementById("idPosterNameStar").style.color = "Red";
    alert("je naam moet nog worden ingevuld.");
    document.frmComment.poster_name.focus();
  }
  else if (LName == LComment || !IsValidName(LName) || !IsValidWordLength(LName))
  {
    document.getElementById("idPosterNameStar").style.color = "Red";
    alert("ik geloof niet dat dit je naam is..");
    document.frmComment.poster_name.focus();
  }
  else if (!IsValidEmail(document.frmComment.email.value))
  {
    document.getElementById("idEmailStar").style.color = "Red";
    alert("je e-mailadres klopt niet. het e-mailadres wordt niet getoond op de site.");
    document.frmComment.email.focus();
  }
  else if (RealCommentLength(LComment) < 10)
  {
    document.getElementById("idCommentStar").style.color = "Red";
    alert("deze reactie is te kort. anderen moeten er iets aan hebben, zoals een verbetering.");
    document.frmComment.comment.focus();
  }
  else if (!IsValidComment(LComment))
  {
    document.getElementById("idCommentStar").style.color = "Red";
    alert("deze reactie is geen verbetering op bovenstaande lijst.. blijf daarbij netjes..");
    document.frmComment.comment.focus();
  }
  else if (!IsValidWordLength(LComment))
  {
    document.getElementById("idCommentStar").style.color = "Red";
    alert("je gebruikt een woord langer dan het langste woord in de dikke van dale! gebruik gewoon nederlands.");
    document.frmComment.comment.focus();
  }
  else if (!IsValidUrl(document.frmComment.poster_site.value))
  {
    alert("het website-adres is niet goed ingevuld.");
    document.frmComment.poster_site.focus();
  }
  else
  {
    document.frmComment.submit();
  }
}

function InsertContent(AField, AValue)
{
  if (document.selection)  // IE support
  {
    AField.focus();
    document.selection.createRange().text = AValue;
    AField.focus();
  }
  else if (AField.selectionStart || AField.selectionStart == "0")  // MOZILLA/NETSCAPE support
  {
    var LStartPos = AField.selectionStart;
    var LEndPos = AField.selectionEnd;
    AField.value = AField.value.substring(0, LStartPos) + AValue + AField.value.substring(LEndPos, AField.value.length);
    AField.focus();
    AField.selectionStart = LStartPos + AValue.length;
    AField.selectionEnd = LStartPos + AValue.length;
  }
  else
  {
    AField.value += AValue;
    AField.focus();
  }
}

function btnInsertSmileClick(ASmile)
{
  InsertContent(document.frmComment.comment, " " + ASmile + " ");
}

function btnDeleteCommentClick(AForm)
{
  if (confirm("deze reactie verwijderen?"))
  {
    AForm.submit();
  }
}

