function borderme(obj) {
  obj.style.border = "1px solid black";
}
function unborderme(obj) {
  obj.style.border = "1px solid #E8EEF7";
}

function insertAtCursor(field, startTag, endTag) { 
  //IE support 
  if (document.selection) { 
    field.focus();
    //in effect we are creating a text range with zero 
    //length at the cursor location and replacing it 
    //with tag 
    //sel = document.selection.createRange(); 
    //sel.text = tag + sel.text + tag; 
  }
  //Mozilla/Firefox/Netscape 7+ support 
  else if (field.selectionStart || field.selectionStart == '0') {
    // selection is the cursor positions before or after
    // a selected text or just the current cursor position.  therefore,
    // in that case startPos == endPos
    var startPos     = field.selectionStart;  
    var endPos       = field.selectionEnd; 
    var textLength   = field.value.length;
    var selectedText = field.value.substring(startPos, endPos);
    var beforeText   = field.value.substring(0, startPos);
    var afterText    = field.value.substring(endPos, textLength);
    field.value = beforeText + startTag + selectedText + endTag + afterText;
  } 
}


function text_bold(tag) {
  obj = document.getElementById(tag);
  insertAtCursor(obj, "[B]", "[/B]");
}

function text_italic(tag) {
  obj = document.getElementById(tag);
  insertAtCursor(obj, "[I]", "[/I]");
}

function text_underline(tag) {
  obj = document.getElementById(tag);
  insertAtCursor(obj, "[U]", "[/U]");
}

function text_createlink(tag) {
  obj = document.getElementById(tag);
  var link = prompt("Enter a URL", "http://");
  if (link) {
    link = '[URL=' + link + ']' + link + "[/URL]";
    insertAtCursor(obj, "", link);
  }
}

function text_insertimage(tag) {
  obj = document.getElementById(tag);
  var link = prompt("Enter a image URL", "http://");
  if (link) {
    link = '[IMG=' + link + ']' + link + "[/IMG]";
    insertAtCursor(obj, "", link);
  }
}

function show_element(id) {
  var form = document.getElementById(id)
  form.style.display = "";
}

function hide_element(id) {
  var form = document.getElementById(id)
  form.style.display = "none";
}

function disable_element(id) {
  var form = document.getElementById(id)
  form.style.display = "";
}

function enable_element(id) {
  var form = document.getElementById(id)
  form.style.display = "none";
}

function remove_file(file_id, div_id) {
  disable_element(file_id);
  hide_element(div_id);
}



function verify_post_form() {
  var post_ok = true;
  var errors = "";

  var msg = document.getElementById("message");
  if (msg.value == "") {
    post_ok = false;
    errors += "Need a Message for this post.\n";
  }

  if (errors) alert(errors);

  return post_ok;
}   

function verify_thread_form() {
  var post_ok = true;
  var errors = "";

  var msg = document.getElementById("message");
  if (msg.value == "") {
    post_ok = false;
    errors += "Need a Message for this thread.\n";
  }
  var headline = document.getElementById("headline");
  if (headline.value == "") {
    post_ok = false;
    errors += "Need a Title for this thread.\n";
  }

  if (errors) alert(errors);

  return post_ok;
}   




