/*!
 * Copyright 2009-2010, James FitzRandolph
 * All rights reserved 
 * Unathorized use strictly forbidden
 */

var msg = function(title, msg)
{
  Ext.Msg.show
  (
    {
      title: title,
      msg: msg,
      minWidth: 200,
      modal: true,
      icon: Ext.Msg.INFO,
      buttons: Ext.Msg.OK
    }
  );
};

function menu_layout_override(ct, target)
{
  if(!this.leftTr)
  {
    target.addClass('x-toolbar-layout-ct');
    target.insertHtml('beforeEnd', '<table cellspacing="0" class="x-toolbar-ct"><tbody><tr><td class="x-toolbar-left" align="left"><table cellspacing="0" align="center"><tbody><tr class="x-toolbar-left-row"></tr></tbody></table></td><td class="x-toolbar-right" align="right"><table cellspacing="0" class="x-toolbar-right-ct"><tbody><tr><td><table cellspacing="0"><tbody><tr class="x-toolbar-right-row"></tr></tbody></table></td><td><table cellspacing="0"><tbody><tr class="x-toolbar-extras-row"></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>');
    this.leftTr = target.child('tr.x-toolbar-left-row', true);
    this.rightTr = target.child('tr.x-toolbar-right-row', true);
    this.extrasTr = target.child('tr.x-toolbar-extras-row', true);
  }
  this.constructor.prototype.onLayout.call(this, ct, target);
}


function visitors_menu()
{
  Ext.QuickTips.init();

  var tb = new Ext.Toolbar( { layoutConfig: { onLayout: menu_layout_override } } );

  tb.add
  (
    '-',
    { text: 'Home',       handler: function() { location.href = "index.php";    } },
    '-',
    new Ext.Button
    (
      {
        text: 'About Us',
        menu:
        {
          items:
          [
            {text: 'The Band',       handler: function() { location.href = "about.php"; }},
            {text: 'Pipe Major',     handler: function() { location.href = "about_pm.php"; }},
//          {text: 'Pipe Sergeant',  handler: function() { location.href = "about_ps.php"; }},
            {text: 'Drum Major',     handler: function() { location.href = "about_dm.php"; }},
            {text: 'Drum Sergeant',  handler: function() { location.href = "about_ds.php"; }},
            {text: 'Music Director', handler: function() { location.href = "about_md.php"; }}
          ]
        }
      }
    ),
    '-',
    { text: 'The Rules ', handler: function() { location.href = "rules.php";          } },
    '-',
    { text: 'Links ',     handler: function() { location.href = "links.php";          } },
    '-',
    { text: 'Members',    handler: function() { location.href = "login.php";  } },
    '-'
  );
  tb.render('toolbar');
}

function members_menu()
{
  Ext.QuickTips.init();

  var tb = new Ext.Toolbar( { layoutConfig: { onLayout: menu_layout_override } } );

  tb.add
  (
    '-',
    { text: 'Home',       handler: function() { location.href = "index.php";    } },
    '-',
    new Ext.Button
    (
      {
        text: 'About Us',
        menu:
        {
          items:
          [
            {text: 'The Band',       handler: function() { location.href = "about.php"; }},
            {text: 'Pipe Major',     handler: function() { location.href = "about_pm.php"; }},
//          {text: 'Pipe Sergeant',  handler: function() { location.href = "about_ps.php"; }},
            {text: 'Drum Major',     handler: function() { location.href = "about_dm.php"; }},
            {text: 'Drum Sergeant',  handler: function() { location.href = "about_ds.php"; }},
            {text: 'Music Director', handler: function() { location.href = "about_md.php"; }}
          ]
        }
      }
    ),
    '-',
    { text: 'The Rules ', handler: function() { location.href = "rules.php";          } },
    '-',
    new Ext.Button
    (
      {
        text: 'Files',
        menu:
        {
          items:
          [
            {text: 'File List', handler: function() { location.href = "show_files.php";  }                },
            {text: 'Add File',  handler: function() { location.href = "create_file.php"; }, id:"add-file" }
          ]
        }
      }
    ),
    '-',
    new Ext.Button
    (
      {
        text: 'Events',
        menu:
        {
          items:
          [
            {text: 'Calendar',   handler: function() { location.href = "calendar_month.php";}                },
            {text: 'Event List', handler: function() { location.href = "show_events.php";   }                },
            {text: 'Add Event',  handler: function() { location.href = "edit_event.php";    }, id:"add-event"}
          ]
        }
      }
    ),
    '-',
    new Ext.Button
    (
      {
        text: 'Users',
        menu:
        {
          items:
          [
            {text: 'User List',      handler: function() { location.href = "show_users.php";       }},
            {text: 'Get VCF List',   handler: function() { location.href = "fetch_vcf.php";        }},
            {text: 'Edit User Info', handler: function() { location.href = "admin_users.php";      }},
            {text: 'Print Roster',   handler: function() { window.open('show_roster.php');         }}
          ]
        }
      }
    ),
    '-',
    { text: 'Links ',     handler: function() { location.href = "links.php";          } },
    '-',
    { text: 'Logout',     handler: function() { location.href = "logout.php";         } },
    '-'
  );
  tb.render('toolbar');

  if ((js_session_privs & 1) == 0) // user admin
  {
    // nothing yet
  }
  if ((js_session_privs & 2) == 0) // files admin
  {
    Ext.getCmp("add-file").setVisible(0);
  }
  if ((js_session_privs & 4) == 0) // event admin
  {
    Ext.getCmp("add-event").setVisible(0);
  }
}
