<!--
// splog.js - spolem.net - copyright Jake Laack - ekaj@spolem.net

/* Tag insertion helper functions */

var focusedTextBox = null;

function focusTextBox(thisTextBox)
{
  focusedTextBox = thisTextBox;
  return true;
}

/* The following 3 functions require the getSelection and insertAtCursor functions */

function insertTag(tagName)
//-------------------
//inserts a simple tag around selected text of a text field
{
  if(focusedTextBox == null) {
    alert("Please select a textbox.");
    return;
  }
  
	selected = getSelection(focusedTextBox);
  text = "<" + tagName + ">" + selected + "</" + tagName + ">";
  replaceSelection(focusedTextBox, text);

}//end addTag function


function insertLink()
//-------------------
//prompts for a url and inserts link tag around selected text of a text field
{
  if(focusedTextBox == null) {
    alert("Please select a textbox.");
    return;
  }
  
  var url = prompt("Enter URL:", "");

  if((url != null) && (url != "")) {
	  selected = getSelection(focusedTextBox);
    text = "<a href=\"" + url + "\">" + selected + "</a>";
    replaceSelection(focusedTextBox, text);
	}//end if
}//end addLink function


function insertImage(type)
//-------------------
//prompts for an image and inserts link tag around selected text of a text field
{
  if(focusedTextBox == null) {
    alert("Please select a textbox.");
    return;
  }
  
  var image = prompt("Enter [img tag:", "");

	selected = getSelection(focusedTextBox);
  text = "<div class=\"Float" + type + "\">" + image + selected + "</div>";
  replaceSelection(focusedTextBox, text);
}//end insertURL function


function redate(txtBox, newDate)
{
  txtBox.value = newDate;
}

/* Form validation functions */

function checkComment(form)
{
  if((! minimalString(form.comment_name, "Please enter your name.")) ||
     ((form.comment_email.value > "") && (! validEmail(form.comment_email))) || 
     ((form.comment_website.value > "") && (! validURL(form.comment_website))) || 
     (! minimalString(form.comment_message, "Please enter a message."))) {
    return false;
  } else {
    return true;
  }
}

function checkCategoryCreate(form)
{
  if(! minimalString(form.category_create_name, "Please enter a category.")) {
    return false;
  } else {
    return true;
  }
}

function checkCategoryRename(form)
{
  if(! minimalString(form.category_rename_newname, "Please enter a new category.")) {
    return false;
  } else {
    return true;
  }
}

function checkLinkForm(form)
{
  if((! minimalString(form.item_title, "Please enter a title.")) ||
     (! validURL(form.item_url)) || 
     (! minimalString(form.item_date, "Please enter a date.")) || 
     (! minimalString(form.item_description, "Please enter a description."))) {
    return false;
  } else {
    return true;
  }
}

function checkPostForm(form)
{
  if((! minimalString(form.item_title, "Please enter a title.")) ||
     (! minimalString(form.item_date, "Please enter a date.")) || 
     (! minimalString(form.item_content, "Please enter content."))) {
    return false;
  } else {
    return true;
  }
}

function checkArticleForm(form)
{
  if((! minimalString(form.item_title, "Please enter a title.")) ||
     (! minimalString(form.item_date, "Please enter a date.")) || 
     (! minimalString(form.item_description, "Please enter a description.")) || 
     (! minimalString(form.item_content, "Please enter a content."))) {
    return false;
  } else {
    return true;
  }
}


/* Popup image functions */

function popShow(obj)
//Reveals a "pop-up" image.
{
	obj = document.getElementById(obj);
	obj.style.visibility = 'visible';
}

function popHide(obj)
//Hides a "pop-up" image.
{
	obj = document.getElementById(obj);
	obj.style.visibility = 'hidden';
}

//-->