function flexToggle(el) {
  if (el.className == 'flexOpen') {
    el.className = 'flexShut';
  } else {
    el.className = 'flexOpen';
  }
}

function ge()
{
  var ea;
  for( var i = 0; i < arguments.length; i++ ) {
    var e = arguments[i];
    if( typeof e == 'string' )
      e = document.getElementById(e);
    if( arguments.length == 1 )
      return e;
    if( !ea )
      ea = new Array();
    ea[ea.length] = e;
  }
  return ea;
}

function show()
{
  for( var i = 0; i < arguments.length; i++ ) {
    var element = ge(arguments[i]);
    if (element && element.style) element.style.display = 'block';
  }
}

function show2()
{
  for( var i = 0; i < arguments.length; i++ ) {
    var element = ge(arguments[i]);
   	if (element && element.style) element.style.display = "inline";
  }
  return false;
}

function hide()
{
  for( var i = 0; i < arguments.length; i++ ) {
    var element = ge(arguments[i]);
    if (element && element.style) element.style.display = 'none';
  }
}

function shown(el) {
    el = ge(el);
    return (el.style.display != 'none');
}

function shide(el) {if (shown(el)) {hide(el);} else {show(el);}}

function isIE() {
 return (navigator.userAgent.toLowerCase().indexOf("msie") != -1);
}

function addEventBase(obj, type, fn, name_hash)
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
                obj["e"+type+fn+name_hash] = fn;
		obj[type+fn+name_hash] = function() { obj["e"+type+fn+name_hash]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn+name_hash] );

	}
}

function removeEventBase(obj, type, fn, name_hash)
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn+name_hash] );
		obj[type+fn+name_hash] = null;
		obj["e"+type+fn+name_hash] = null;
	}
}

Function.prototype.bind = function(context) {
  var method = this;
  return function() {
    return method.apply(context, arguments);
  }
}

function optional_drop_down_menu(arrow, link, menu, event, arrow_class, arrow_old_class)
{
  if (menu.style.display=='none') {
    menu.style.display='block';
    var old_arrow_classname = arrow_old_class ? arrow_old_class : arrow.className;

    // Lock In Button Pressed State
    if (link) {
      link.className = 'active';
    }

    arrow.className = arrow_class ? arrow_class : 'global_menu_arrow_active';

    var justChanged = true;

    // prevent selects from showing through menu in ie6
    var shim = ge(menu.id + '_iframe');
    if (shim) {
      shim.style.top = menu.style.top;
      shim.style.right = menu.style.right;
      shim.style.display = 'block';
      shim.style.width = (menu.offsetWidth +2) + 'px';
      shim.style.height = (menu.offsetHeight +2) + 'px';
    }

    menu.offclick = function(e) {
      if (!justChanged) {
        // Hide dropdown
        hide(this);

        // Restore Normal link and hover class
        if (link) {
          link.className = '';
        }
        arrow.className = old_arrow_classname;

        var shim = ge(menu.id + '_iframe');
        if (shim) {
          shim.style.display = 'none';
          shim.style.width = menu.offsetWidth + 'px';
          shim.style.height = menu.offsetHeight + 'px';
        }

        removeEventBase(document, 'click', this.offclick, menu.id);
      } else {
        justChanged = false;
      }
    }.bind(menu);

    addEventBase(document, 'click', menu.offclick, menu.id);
  }
  return false;
}

function isSafari() {
 return (navigator.userAgent.indexOf("Safari") != -1);
}
