var is_reply = false;

function selectHiddenMessage(id)
{
  var div = document.getElementById("msgid_" + id);
  div.innerHTML = "<input name='MessagesList[]' type='hidden' value='" + id + "'>";
}

function doDelete() {
  var div = document.getElementById("messageCommand");
  div.innerHTML = "<input name='Delete' type='hidden' value='1'>";
  document.theForm.submit();
}

function doReply () {
  var div = document.getElementById("messageCommand");
  div.innerHTML = "<input type=\"hidden\" name=\"rid\" value=\"1\" />";

  document.theForm.submit();
}

function doBlock() {
  var div = document.getElementById("messageCommand");
  div.innerHTML = "<input type=\"hidden\" name=\"block\" value=\"1\" />";

  document.theForm.submit();
}

function doSend()
{
  var div = document.getElementById("messageCommand");
  var html = "<input name='SendMail' type='hidden' value='1'>";
  if(is_reply)
  {
    html += "\n<input type='hidden' name='msg_replyid' id='msg_replyid' value='" + is_reply + "' />\n";
  }
  div.innerHTML = html;
  document.theForm.submit();
}

function newMessage(reply, replyToUser)
{
  var store = document.getElementById("readcreate_store");
  var msg   = document.getElementById("readmessage");

  is_reply = reply;
  if (!reply)// && to_msg && subject_msg && content_msg)
  {
//    var to = document.getElementById("msg_to");
    var subject = document.getElementById("msg_subject");
    var content = document.getElementById("msg_content");

//    to.value = '';
    if(subject != null)
    {
      subject.value = '';
    }
    if(content != null)
    {
      content.value = '';
    }
  }
  else
  {
    var theForm = document.forms["theForm"];
    var z = 0;

    for(z = 0; z < theForm.length; z++)
    {
      if(theForm[z].type == 'checkbox')
      {
        //msg_to
        var thisValue = theForm[z].value;
        if(thisValue == replyToUser)
        {
          theForm[z].checked = true;
        }
      }
    }
  }

  if(msg)
  {
    msg.style.display = "none";
  }
  store.style.display = "block";
}

//msg_to
function checkUncheckAll(theElement)
{
  var theForm = theElement.form, z = 0;
  var checked = theElement.checked;

  for(z = 0; z < theForm.length; z++)
  {
    if(theForm[z].type == 'checkbox')
    {
      //msg_to
      var thisId = theForm[z].id;
      if(thisId.length >= 6 && thisId.substring(0, 6) == 'msg_to')
      {
        theForm[z].checked = checked;
      }
    }
  }
}
