function $(element)
{
   if (typeof element == 'string')
      return document.getElementById(element);
}

function toggleDiv(t_id, div_id)
{
   var id_div = document.getElementById(div_id);
   if (t_id) var t_img = document.getElementById(t_id);

   if (id_div.style.display == "none")
   {
      id_div.style.display = "block";
      if (t_id) t_img.src = "images/minus.gif";
   }
   else
   {
      id_div.style.display = "none";
      if (t_id) t_img.src= "images/plus.gif";
   }
}

function rgbConvert(str)
{
   str = str.replace(/rgb\(|\)/g, "").split(",");
   str[0] = parseInt(str[0], 10).toString(16).toLowerCase();
   str[1] = parseInt(str[1], 10).toString(16).toLowerCase();
   str[2] = parseInt(str[2], 10).toString(16).toLowerCase();
   str[0] = (str[0].length == 1) ? '0' + str[0] : str[0];
   str[1] = (str[1].length == 1) ? '0' + str[1] : str[1];
   str[2] = (str[2].length == 1) ? '0' + str[2] : str[2];
   return ('#' + str.join(""));
}

// http://www.javascripter.net/faq/hextorgb.htm
function hexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function hexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function hexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}

var del_color = '#800000';
var highlight_color = '#B7C3D0';

function updateDelete(chkbox, id, highlight_color)
{
   // highlight_color is optional (use above global)
   var el = document.getElementById('row_'+id);

   if (chkbox.checked == true)
   {
      el.style.background = del_color;
   }
   else
   {
      el.style.background = highlight_color;
   }
}

function highlightRow(id, hi_color)
{
   if (!hi_color) hi_color = highlight_color;

   var el = document.getElementById('row_'+id);
   var curr_color;

   // Firefox returns color as 'rgb(rrr, ggg, bbb)
   if (el.style.backgroundColor.charAt(0) != '#')
      curr_color = rgbConvert(el.style.backgroundColor);
   else
      curr_color = el.style.backgroundColor;

   if (curr_color != del_color)
      el.style.backgroundColor = hi_color;
}

function unHighlightRow(id, bgcolor)
{
   var el = document.getElementById('row_'+id);
   var curr_color;

   if (el.style.backgroundColor.charAt(0) != '#')
      curr_color = rgbConvert(el.style.backgroundColor);
   else
      curr_color = el.style.backgroundColor;

   if (curr_color != del_color)
      el.style.backgroundColor = bgcolor;
}

