var sel;    // variable for holding an HTML DOM select object
var opt;    // variable for holding an HTML DOM option object
var img;    // variable for holding an HTML DOM select object
var newimg; // variable for holding an HTML DOM option object
var src;    // variable for holding an HTML DOM IMG SRC object.    
var elem;   // variable for holding an HTML DOM element object
var redir;  // variable for holding an alternerate id


/*
** this function hides an element by id.
*/
function hide_id(id)
{
  if (('' + id) && (elem = document.getElementById(id)))
  {
    elem.style.display    = 'none';
//    elem.style.visibility = 'hidden';
  }
}

/*
** this function shows an element by id (and by display style -- default
** is inline).
*/
function show_id(id, display)
{
  if (!display)
  {
    display = 'inline'; 
  }
  if ((id) && (elem = document.getElementById(id)))
  {
    elem.style.display    = display;
//    elem.style.visibility = 'visible';
  }
}

/*
** this function disables changes to a form element, and keeps its
** value from passing to the form handler.
*/
function disable(id)
{
  if (elem = document.getElementById(id))
  {
    elem.value	  = '';
    elem.readOnly = 'ReadOnly';
    elem.disabled = 'disabled';
  }
}

/*
** this function enables changes to a form element, and makes sure its
** value will pass to the form handler.
*/
function enable(id)
{
  if (elem = document.getElementById(id))
  {
    elem.readOnly = '';
    elem.disabled = '';
  }
}

/*
** this function puts a value in a form element as selected by id, just
** to make the interface a little simpler
*/
function input_value(id, value)
{
  if (elem = document.getElementById(id))
  {
    return elem.value = value;
  }
  return 'NOT FOUND';
}

/*
** Specific pages helpers.
*/

/*
** this function stores a value in an input field and launches a form
*/
function confirmed_submit(id, input_id, form_id)
{
  input_value('' + input_id, id);
  document.getElementById('' + form_id).submit();
}


/*
** this function is for coloring a select to match the option, and 
** changing a display image.  Specifically designed for use in the
** publitapias site.
*/
function color_me(id, indir)
{
  if ((sel = document.getElementById(id)) &&
      (opt = sel.options[sel.selectedIndex]))
  {
    redir = ('' + indir) ? opt.id : opt.value;

    if ((img	= document.getElementById('img_'      + id)) &&
	(newimg	= document.getElementById('flag_id_'  + redir)))
    {
      img.src = newimg.src;
    }
    sel.style.backgroundColor = opt.style.backgroundColor;
    sel.style.color	      = opt.style.color;
  }
}
/*
** this function puts one img src with another. useful for rollovers.
** requires: all images loaded.  Typically invisible div at bottom of
** page holds swap images.
*/
function swapsrc(id, newid)
{
  if ((img    = document.getElementById('' + id)) &&
      (newimg = document.getElementById('' + newid)))
  {
    src		= img.src;
    img.src	= newimg.src;
    newimg.src	= src;
  }
}

