/* hides <select> and <applet> objects (for IE only) */

function resetForm()
{
  document.forms[0].reset();
}

function setMid(mid)
{
  var action = document.forms[0].action;
  document.forms[0].action = action + "?smid=" + mid;
}

function goMid(mid)
{
  var action = document.forms[0].action;
  var index = action.indexOf('smid=');
  if (index != -1)
  {
    action = action.substring(0, index) + "xmid=" + mid;
    document.forms[0].action = action;
    document.forms[0].submit();
  }
}

var jscalendarIe = document.all;
var buttonPushed = false;

function jsHideElement(elmID, overDiv)
{
  if (jscalendarIe)
  {
    for( i = 0; i < document.all.tags( elmID ).length; i++)
    {
      obj = document.all.tags( elmID )[i];
      if( !obj || !obj.offsetParent)
        continue;

      // Find the element's offsetTop and offsetLeft relative to the BODY tag.
      objLeft   = obj.offsetLeft;
      objTop    = obj.offsetTop;
      objParent = obj.offsetParent;

      while( objParent.tagName.toUpperCase() != "BODY" )
      {
        objLeft  += objParent.offsetLeft;
        objTop   += objParent.offsetTop;
        objParent = objParent.offsetParent;
      }

      objHeight = obj.offsetHeight;
      objWidth = obj.offsetWidth;

      // Find the element's offsetTop and offsetLeft relative to the BODY tag.
      overDivLeft   = overDiv.offsetLeft;
      overDivTop    = overDiv.offsetTop;
      overDivParent = overDiv.offsetParent;

      while (overDivParent.tagName.toUpperCase() != "BODY")
      {
        overDivLeft  += overDivParent.offsetLeft;
        overDivTop   += overDivParent.offsetTop;
        overDivParent = overDivParent.offsetParent;
      }

      if ((overDivLeft + overDiv.offsetWidth ) <= objLeft);
      else if(( overDivTop + overDiv.offsetHeight ) <= objTop);
      else if( overDivTop >= ( objTop + objHeight ));
      else if( overDivLeft >= ( objLeft + objWidth ));
      else obj.style.visibility = "hidden";
    }
  }
}

/*
* shows <select> and <applet> objects (for IE only)
*/
function jsShowElement(elmID)
{
  if (jscalendarIe)
  {
    for (i = 0; i < document.all.tags( elmID ).length; i++)
    {
      obj = document.all.tags( elmID )[i];

      if (!obj || !obj.offsetParent)
        continue;

      obj.style.visibility = "";
    }
  }
}

function jsHideElement2(elmID, overDiv)
{
  if (jscalendarIe)
  {
    for (i = 0; i < document.all.tags( elmID ).length; i++)
    {
      obj = document.all.tags( elmID )[i];

      if (!obj || !obj.offsetParent)
        continue;

      obj.style.visibility = "hidden";
    }
  }
}

//toggles layer visibility on and off
function show(id)
{
  var element = document.getElementById(id);
  if (element != null)
  {
    element.style.visibility = "visible";
  }
}

function hide(id)
{
  var element = document.getElementById(id);
  if (element != null)
  {
    element.style.visibility = "hidden";
  }
}

function push(id)
{
  var element = document.getElementById(id);
  if (element != null)
  {
    if (element.style.visibility == "hidden") 
    {
      show(id);
      jsHideElement2('select', document.getElementById(id));
    }
    else
    {
      hide(id);    
      jsShowElement('select');
    }
    buttonPushed = true;
  }
}

function pushOutside(id)
{
  if (!buttonPushed)
  {
    hide(id);
    jsShowElement('select');
  }
  buttonPushed = false;
}

function checkMaxLength(field, limit)
{
  if (field.value.length >= limit) field.value = field.value.substring(0, limit - 1);
}
