/*
  Scrub the Search
*/
  function checkSearch(anId) {
    ok = false;
    term = document.getElementById(anId);
    if (term != null && term.value.length > 0) {
      var stuff = new RegExp("[^a-zA-Z0-9_ .*~-]","g");
      term.value = term.value.replace(stuff,"");
      term.value = term.value + "*";
      ok = true;
    }
    return ok;
  }


/*
  Get Id

  Parameters: anId

  Returns the DOM object associated to the Id passed into the function.
*/
  function getById(aString) {
    return document.getElementById(aString);
  }


/*
  Get Names

  Parameters: names

  Returns the DOM objects associated to a partial match of the name string
  passed into the function.
*/
  function getByNames(aString) {
    return document.getElementsByName(aString);
  }

/*
  ----------------------------------------------------------------------------
    Check for Valid Email

    checks for a period and the at symbol

    anId is the ID of the input field

    return true if passed, false if failed

    Ex: <form action="#" onsubmit="return checkEmail('emailA')">
          <input name="emailA" id="emailA" type="text">
  ----------------------------------------------------------------------------
*/

function checkEmail(anId) {
  var e = document.getElementById(anId);
  var ok = false;
  if (e != null) {
    if (e.value.indexOf(".") != -1 && e.value.indexOf("@") != -1) {
      ok =  true;
    }
  }
  return ok;
}

/* Detail page tab script ----------------------------------------------------*/

window.addEvent('domready', function() {

var tabs = $$('.tab');
  var tabsContent = $$('.tabContent');
  if (tabs != null && tabsContent != null) {
    tabs.each(function(tab, i) {
      tab.addEvent('click', function(event) {
        if (!tab.hasClass('active')) {
          tabs.removeClass('active');
          tab.addClass('active');
          tabsContent[0].getElements('.tabContentDiv').removeClass('active');
          tabsContent[0].getElements('.tabContentDiv')[i].addClass('active');          
        }
        event.stop();
      });
      /*
      if (i > 0) {
        tab.toggleClass('active');
      }
      */
    });
  }
}); 
