/**********************************************************/
/* EVENT RELATED JAVASCRIPT FUNCTIONS                     */
/*                                                        */
/* METABASE JAVASCRIPT (c) 2009-2010 Vincent E. Milum Jr. */
/**********************************************************/


function addEvent(thing, msname, nsname, func, doc) {
  var element = getElement(thing, doc);
  if (!element) return;

  if (element.attachEvent) {
    element.attachEvent(msname, func);

  } else if (document.addEventListener) {
    element.addEventListener(nsname, func, true);

  } else {
    alert('Page events are NOT supported');
  }
}


function removeEvent(thing, msname, nsname, func, doc) {
  var element = getElement(thing, doc);
  if (!element) return;

  if (element.attachEvent) {
    element.detachEvent(msname, func);

  } else if (document.addEventListener) {
    element.removeEventListener(nsname, func, true);

  } else {
    alert('Page events are NOT supported');
  }
}


function preventDefaults(ev) {
  if (!ev) return;

  if (document.all) {
    ev.cancelBubble = true;
    ev.returnValue  = false;
  }

  if (ev.stopPropagation) ev.stopPropagation();
  if (ev.preventDefault)  ev.preventDefault();
}



function _page_error_handler_(message, url, line) {
  if ((typeof ajaxError) == "undefined") return false;
  
  //HERE IS OUR BLACKLIST.  IF URL HAPPENS TO BE
  //ONE OF THESE, JUST IGNORE IT!! JUST BOGUS
  //EXTERNAL JAVASCRIPT APIS, THATS ALL
  
  if (url) {
    if (url.indexOf('skype_ff_toolbar_win') >= 0) return false;
    if (url.indexOf('googleads.g.doubleclick.net') >= 0) return false;
    if (url.indexOf('google-analytics.com') >= 0) return false;
    if (url.indexOf('googlesyndication.com') >= 0) return false;
    if (url.indexOf('assoc-amazon.com') >= 0) return false;
    if (url.indexOf('snap.com') >= 0) return false;
    if (url.indexOf('ixnp.com') >= 0) return false;
    if (url.indexOf('chrome://') >= 0) return false;
  }
  
  var ajax = new ajaxError(message, url, line);
  return ajax.post();
}
