/**
* checkSubmit
*
* Will make sure the user cannot submit a
* form multiple times.
*/
var submitted = "false";

function checkSubmit() {
  if (submitted == "true") {
    return false;
  } else {
    submitted = "true";
    return true;
  }
}

/**
* colorTextbox
*
* Changes the color of a text box or text area
*
* @param  string  myObject  name of field
*/
function colorTextbox(myObject) {
  if(document.getElementById) {
    myObject.style.backgroundColor = '#FFFFCC';
  } else if(document.all) {
    myObject.style.backgroundColor = '#FFFFCC';
  }
}

/**
* uncolorTextbox
*
* Changes the color of a text box or text area
* back to white
*
* @param  string  myObject  name of field
*/
function uncolorTextbox(myObject) {
  if(document.getElementById) {
    myObject.style.backgroundColor = '#FFFFFF';
  } else if(document.all) {
    myObject.style.backgroundColor = '#FFFFFF';
  }
}

function auto_tab(myObject)
{
  var key = 0;
  if(window.event.keyCode)
  {
    key = window.event.keyCode;
  }
  // just make sure this action is possible...
  if(myObject.value.length && myObject.maxLength)
  {
    if(myObject.value.length >= myObject.maxLength)
    {
      if (key != 9 && key !=16) // tab or shift key
      {
        // get current index for this element
        var nextItem = -1;
        for (var i=0;i<document.main.elements.length;i++)
        {
          if (myObject == document.main.elements[i])
          {
            nextItem = i+1;
          }
        }
        if(nextItem != -1)
        {
          if(document.main.elements[nextItem].focus())
          {
            document.main.elements[nextItem].focus();
          }
        }
      } // end of not a "tab"
    }
  }
}

/* toggle item */
function toggle_item(itemId)
{
  if(document.getElementById) // modern browsers
  {
    if(document.getElementById(itemId))
    {
      if(document.getElementById(itemId).style.visibility != 'visible')
      {
        document.getElementById(itemId).style.visibility = 'visible';
        document.getElementById(itemId).style.display = 'block';
      }
      else
      {
        document.getElementById(itemId).style.visibility = 'hidden';
        document.getElementById(itemId).style.display = 'none';
      }
    }
  }
}
/* 3 functions for text area javascript */
function mozWrap(txtarea, lft, rgt) {
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;

    if (selEnd==1 || selEnd==2) selEnd=selLength;
    var s1 = (txtarea.value).substring(0,selStart);
    var s2 = (txtarea.value).substring(selStart, selEnd)
    var s3 = (txtarea.value).substring(selEnd, selLength);
    txtarea.value = s1 + lft + s2 + rgt + s3;
}

function IEWrap(txtarea, lft, rgt) {
    strSelection = document.selection.createRange().text;
    if (strSelection != "") {
        document.selection.createRange().text = lft + strSelection + rgt;
    } else {
        txtarea.value = txtarea.value + lft + rgt;
    }
}

function wrapSelection(txtarea, lft, rgt) {
    if (document.all) {
        IEWrap(txtarea, lft, rgt);
    } else if (document.getElementById) {
        mozWrap(txtarea, lft, rgt);
    }
}
function wrapImgSelection(txtarea)
{
  lft = '[img src="http://" alt="" border="0"';
  rgt = ' /]';
    if (document.all) {
        IEWrap(txtarea, lft, rgt);
    } else if (document.getElementById) {
        mozWrap(txtarea, lft, rgt);
    }
}
function wrapUrlSelection(txtarea)
{
  lft = '[link ="http://" /][text][/text]';
  rgt = '[/link]';
    if (document.all) {
        IEWrap(txtarea, lft, rgt);
    } else if (document.getElementById) {
        mozWrap(txtarea, lft, rgt);
    }
}

/* just a function to verify you have the JS loaded, call from the page you are testing */
function test_it()
{
  alert("yes");
}