/* Jquery-based helpers - for common UI-related tasks */

/* Go to next field when maxlegnth is reached, for .goNext elements */
function goNext()
{
  if($(this).val().length >= $(this).attr('maxlength')) $(this).next('input').focus();
}

function popInfo(name)
{

  if( typeof(name) == 'object' ) name = this.name;

  var vals = new Array();
  /* Works for INPUT_ARRAY[] style names too! */
  $('[name="' + name + '"]').each(function()
  {
    /*
     * FYI - check & radio always val() to whatever value we define
     * them with.  We really only consider non-empty when they're
     * checked through, so we have to handle them as a special case.
     */
    switch( $(this).attr('type') )
    {
      case 'checkbox' || 'radio':
        if( $(this).is(':checked') ) vals.push($(this).val());
        break;
      default:
        if( $(this).val() ) vals.push($(this).val());
        break;
    }

  });

  if( vals.length > 0 )
  {
    $('#moreInfo').removeClass('hidden');
  }
  else
  {
    $('#moreInfo').addClass('hidden');
  }
}



/* Assign Handlers Here!!! */
$(document).ready(function(){
  $('.goNext').keyup(goNext);
  $('.popInfo').click(popInfo);
  //popInfo('VEHICLE_INTEREST[]');
});