
(function()
{
  if (window.addEventListener)
  {
    window.addEventListener("load", setup_misc, false);    
  }
  else
  {
    window.attachEvent("onload", setup_misc);
  }
})();

function setup_misc()
{
  var inputs = document.getElementsByTagName("input");
  
  for (var i = 0; i < inputs.length; i++)
  {	  
	  var id = inputs[i].id;
	  
    if (id.substring(0, 10) === "highlight_")
    {
      add_highlight(inputs[i]);
    }
    else if (id.substring(0, 8) === "winopen_")
    {
      add_window_open(inputs[i]);
    }
    else if (id.substring(0, 11) === "winlocation")
    {
      add_redirect(inputs[i]);
    }
  }
}

function add_highlight(elem)
{
  var id = elem.id.substring(10);
      
  elem.onclick = function(){document.getElementById(id).select();};
}

function add_window_open(elem)
{	
	var page = elem.id.substring(8);
	
	var attrs = "'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=300'";

  elem.onclick = function(){window.open(page, '', attrs);};
}

function add_redirect(elem)
{
	var items = elem.id.split("_");

  var other = "";
  
  if (items.length > 1)
  {
    other = "?";
  }
  
  for (var i = 1; i < items.length; i += 2)
  {
    other += items[i] + "=" + items[i + 1];
    
    if (i < items.length - 2)
    {
      other += "&";
    }
  }
  
  elem.onclick = function(){window.location = other};
}
