﻿function showHide( elementId, mode )
{
  try
  {
    if ( mode == 'hide' )
    {
      $( '#' + elementId ).hide();
    }
    else if ( mode == 'show' )
    {
      $( '#' + elementId ).show();
    }
    else
    {
      $( '#' + elementId ).toggle();
    }
  }
  catch ( e )
  {
//    alert( e );
  }
}

var maxItems;

function checkWorkshops( className )
{
  var counter = 0;
  var unsetCheckbox = false;

  if ( !maxItems )
  {
    maxItems = 2;
  }

  $( 'input.' + className ).each(
    function( thisItem )
    {
      if ( this.checked )
      {
        counter++;
//        alert( counter + this.name + '=' + this.value );
      }

      if ( counter > maxItems )
      {
        alert( 'Bitte wählen Sie maximal ' + maxItems + ' Workshop(s) pro Tag und Uhrzeit aus.' );
        unsetCheckbox = true;
        return false;
      }
    }
  );

  return !unsetCheckbox;
}

function bindOnClick()
{
  $( '[name*=workshops]' ).each(
    function( intIndex )
    {
      try
      {
        $( this ).click(
          function()
          {
            if ( !checkWorkshops( this.className ) )
            {
              this.checked = false;
            }
          }
        );
      }
      catch ( e )
      {
//        alert( e );
      }
    }
  );
}
