<!--
// javascript.js - spolem.net - copyright Jake Laack - ekaj@spolem.net
//
// General purpose JavaScript


function getObject(obj)
//Returns reference to object matching given id
{
  if(document.getElementById) {
    obj = document.getElementById(obj);
  } else if (document.all) {
    obj = document.all.item(obj);
  } else {
    obj = null;
  }

  return obj;
}


function showthis(thing)
//Changes style of object with given id to be visible
{
  var x = getObject(thing);
  x.style.visibility = "visible";
	x.style.display = "block";
}

function hidethis(thing)
//Changes style of object with given id to be hidden
{
  var x = getObject(thing);
  x.style.visibility = "hidden";
	x.style.display = "none";
}


function setCookie(name, value, expire)
//Creates a cookie via JavaScript
{
  document.cookie = name + "=" + escape(value)
    + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}


function areYouSure(promptString)
//Used to ensure the user's choices
{
  message = "Are you sure you want to " + promptString + "?";
  return confirm(message);
}

function errorMessage(errorMsg)
{
  alert("Spolem.net Error:\n\n" + errorMsg);
}


function getSelection(txtBox)
//returns the selected text of a text field
{
  if (document.selection) {
  	txtBox.focus();
	  return document.selection.createRange().text;
	} else {
  	txtBox.focus();
	  return txtBox.value.substring(txtBox.selectionStart, txtBox.selectionEnd);
	}
}


function replaceSelection(myField, myValue)
//inserts "myValue" at the cursor position of "myField"
//NOTE: overwrites any text currently selected
{
  //IE supported method
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
    
  //MOZILLA/NETSCAPE supported method
  } else {
	  if (myField.selectionStart || myField.selectionStart == '0') {
      var startPos = myField.selectionStart;
      var endPos = myField.selectionEnd;
      myField.value = myField.value.substring(0, startPos)
      + myValue
      + myField.value.substring(endPos, myField.value.length);
      myField.setSelectionRange(startPos, (startPos + myValue.length));
    } else {
      myField.value += myValue;
    }
  }
}

//-->
