var last_highlight = '';
var highlight_img_array = new Array();

function register_highlight(element)
{
  highlight_img_array[highlight_img_array.length] = element;
}

function get_highlight_element(element_id)
{
  for (var i = 0; i < highlight_img_array.length; i++)
  {
    if (highlight_img_array[i].id == element_id) return highlight_img_array [i];
  }

  return null;
}

function highlight(element_id)
{
  if (last_highlight == element_id) return;
  else if (last_highlight != '') unhighlight(last_highlight);
  
  var element = null;
  if (highlight_img_array.length != 0) element = get_highlight_element(element_id);
  if (element == null) element = document.getElementById(element_id);
  
  if (element != null)
  {
    element.style.visibility = 'visible';
    last_highlight = element_id;
  }
}

function unhighlight(element_id)
{
  var element = null;
  if (highlight_img_array.length != 0) element = get_highlight_element(element_id);
  if (element == null) element = document.getElementById(element_id);
  
  if (element != null)
  {
    element.style.visibility = 'hidden';
    last_highlight = '';
  }
}

function validate_and_submit__mail(form_name)
{
  var fail_count = 0;
  var theform = document.forms[form_name];

  for (i = 0; i < theform.length; i++)
  {
    var element = theform.elements[i];

    if ( ( element.name.substring(0,8) == "required" && 
           (element.type == "text" || element.type == "textarea") ) ||
         element.name == "email" )
    {
      if (element.value == "")
      {
        element.style.backgroundColor = "pink";
        fail_count++;
      }
      else
      {
        element.style.backgroundColor = "white";
      }
    }
  }

  if (fail_count > 0)
  {
    alert(fail_count + " of the required field(s) is/are not completed (marked in pink). Please complete all fields marked with an asterix, then resubmit!");
  }
  else
  {
    theform.action = 'http://www.goodbyegraffiti.com/cgi-bin/FormMail.pl';
    theform.submit();
  }
}

function validate_form(theform)
{
  var fail_count = 0;

  for (i = 0; i < theform.length; i++)
  {
    var element = theform.elements[i];

    if ( ( element.name.substring(0,8) == "required" && 
           (element.type == "text" || element.type == "textarea") ) ||
         element.name == "email" )
    {
      if (element.value == "")
      {
        element.style.backgroundColor = "pink";
        fail_count++;
      }
      else
      {
        element.style.backgroundColor = "white";
      }
    }
  }

  if (fail_count > 0)
  {
    alert(fail_count + " of the required field(s) is/are not completed (marked in pink). Please complete all fields marked with an asterix, then resubmit!");
    return false;
  }
  else
  {
    return true;
  }
}
