//Optional field hide/display
function setupOptionalForm(event)
{
  $$('.btn-optional-quote').each(function(button)
  {
    button.observe('click',updateOptionalBoxes);
  });
}

function updateOptionalBoxes(event)
{
  var visible = false;
  event.stop();
  button = event.element();
  if(button.hasClassName('on'))
  {
    button.removeClassName('on');
  }
  else
  {
    visible = true;
    button.addClassName('on');
  }
  $$('.optional').each(function(option)
  {
    if(visible)
    {
      option.style.visibility = "visible";
    }
    else
    {
      option.style.visibility = "hidden";
    }
  });
}

//Optional field hide/display
function setupOptionalInsuranceForm()
{
  Event.observe('include_quote', 'click', function()
  {
    updateOptionalInsurance();
  });
  updateOptionalInsurance();
}

function updateOptionalInsurance()
{
  $$('.optional').each(function(option)
  {
    var element = $('include_quote');
    if(element.checked)
    {
      option.style.display = "block";
    }
    else
    {
      option.style.display = "none";
    }
  });
}

function updateOptionalBoxes(event)
{
  var visible = false;
  event.stop();
  button = event.element();
  if(button.hasClassName('on'))
  {
    button.removeClassName('on');
  }
  else
  {
    visible = true;
    button.addClassName('on');
  }
  $$('.optional').each(function(option)
  {
    if(visible)
    {
      option.style.visibility = "visible";
    }
    else
    {
      option.style.visibility = "hidden";
    }
  });
}

//Occupation Hinting
function startHint(element,parameters)
{
  element.addClassName('loading');
  return parameters;
}

function displayHint(element)
{
  element.removeClassName('loading');
}

function showDIV(id)
{
  $(id).style.display = 'block';
}

function hideDIV(id)
{
  $(id).style.display = 'none';
}

/**
 * Adjust the observe to initiate setup for checkbox with the label not selecting
 */
document.observe('dom:loaded', function () {
  var is_iPad = navigator.userAgent.match(/iPad/i) != null;
  if (is_iPad)
  {
    $$('label').invoke('observe', 'click', function(event){});
  }
});
