/*!
 * Ext JS Library 3.0.3
 * Copyright(c) 2006-2009 Ext JS, LLC
 * licensing@extjs.com
 * http://www.extjs.com/license
 */
var startpris30=30;
tilmelding[0] = new Ext.FormPanel({
  labelAlign: 'top',
  collapsible: false,
  collapsed: false,
  frame:true,
  bodyStyle:'padding:5px 5px 0',
  autoScroll: true,
  defaults:{
    animCollapse: true,
    xtype:'fieldset',
    collapsible: true,
    collapsed: false,
    titleCollapse: true,
    autoHeight:true
  },
  items: [
  {
    layout:'column',
    title: 'Person oplysninger',
    items:[{
      columnWidth:.5,
      layout: 'form',
      defaultType: 'textfield',
      defaults:{
        allowBlank: false,
        anchor: '95%'
      },
      items: [{
        fieldLabel: 'Fornavn(e)',
        id: 'firstname30',
        name: 'firstname',
        //vtype:'alphadk',
        tabIndex: 1
      }, {
        fieldLabel: 'Adresse',
        id: 'address30',
        //vtype:'alphadkgade',
        name: 'address',
        tabIndex: 3
      }, new Ext.form.ComboBox({
        store: storepostby,
        displayField: 'Postby',
        valueField: 'Postnr',
        id: 'postby30',
        typeAhead: true,
        mode: 'local',
        emptyText: 'Vælg postnummer',
        selectOnFocus: true,
        forceSelection: true,
        hiddenName: 'postby',
        fieldLabel: 'Postnummer og by',
        tabIndex: 4
      }), new Ext.form.ComboBox({
        store: storeHoldTilmelding,
        tpl: '<tpl for="."><div ext:qtip="{team}<br>Kaptajn: {leader}" class="x-combo-list-item">{team}</div></tpl>',
        displayField: 'team',
        valueField: 'Id',
        id: 'teamcombo30',
        typeAhead: true,
        mode: 'local',
        emptyText: 'Vælg hold',
        selectOnFocus: true,
        forceSelection: true,
        allowBlank: true,
        hiddenName: 'team',
        fieldLabel: 'Deltager på hold',
        tabIndex: 8,
        listeners: {
          focus : function(field){
            storeHoldTilmelding.reload();
          },
          collapse : function (field){            
            updateprices30(field);
          }
        }
      })]
    },{
      columnWidth:.5,
      layout: 'form',
      defaultType: 'textfield',
      defaults:{
        allowBlank: false,
        anchor: '50%'
      },
      items: [{
        fieldLabel: 'Efternavn(e)',
        name: 'surname',
        id: 'surname30',
        //vtype:'alphadk',
        anchor:'95%',
        tabIndex: 2
      },{
        xtype:'datefield',
        fieldLabel: 'Fødselsdag',
        name: 'birthday',
        id: 'birthday30',
        vtype:'date',
        maxValue: '08-05-2011',
        minValue: '08-05-1911',
        format: 'd-m-Y',
        tabIndex: 5,
        listeners: {
          change : function( field, newval,oldval ){
            startpris30=newval>agelimit?0:30;
            updateprices30(Ext.getCmp('teamcombo30'));
          }
        }
      },{
        fieldLabel: 'Telefon',
        name: 'phone',
        id: 'phone30',
        vtype:'phone',
        tabIndex: 6
      }, {
        fieldLabel: 'e-mail adresse',
        vtype:'email',
        id: 'email30',
        name: 'email',
        anchor:'95%',
        tabIndex: 7,
        disabled: true
      }]
    }]
  },{
    checkboxToggle:true,
    title: 'Opret hold',
    defaults: {
      anchor: '47.5%'
    },
    defaultType: 'textfield',
    collapsed: true,
    collapsible: false,
    items :{
      fieldLabel: 'Holdnavn',
      name: 'newteam',
      id: 'newteam30',
      disabled: true,
      allowBlank: false,
      tabIndex: 7
    },
    listeners: {
      beforeexpand : function( p, animate ){
        Ext.getCmp('teamcombo30').disable()
        Ext.getCmp('newteam30').enable()
      },
      beforecollapse : function( p, animate ){
        Ext.getCmp('teamcombo30').enable()
        Ext.getCmp('newteam30').disable()
      },
      expand : function(p ){
        tilmelding[0].getForm().isValid()
      },
      collapse : function(p ){
        tilmelding[0].getForm().isValid()
      }      
    }
  },{
    title: 'Prisoplysninger (Indbetaling til Vestjysk Bank registrerings nr. 7605 kontonr. 1091486)',
    defaults: {
      width: 100
    },
    defaultType: 'textfield',
    items :[{
      fieldLabel: 'Startpris',
      name: 'startpris',
      id: 'startpris30',
      readOnly: true,
      submitValue: false
    },{
      fieldLabel: 'Gebyr ved tilmelding efter 1. maj '+year,
      name: 'gebyr',
      id: 'gebyr30',
      readOnly: true,
      submitValue: false
    },{
      fieldLabel: 'Samlet startpris',
      name: 'ialt',
      id: 'ialt30',
      readOnly: true
    }
    ]
  },{
    title: 'Erklæringer',
    items :[{
      xtype: 'checkboxgroup',
      allowBlank: false,
      width: '90%',
      blankText: 'Du skal acceptere betingelserne',
      items: [
      {
        height: 30,
        boxLabel: 'Jeg erklærer med min tilmelding at min deltagelse i løbet sker på eget ansvar.<br>Jeg er indforstået med, at jeg med min tilmelding accepterer at foto, filmoptagelser, interviews o.l. frit kan benyttes.',
        name: 'accept',
        id: 'accept30',
        submitValue : false,
        tabIndex: 9,
        listeners: {
          check : function( b, checked ){
            Ext.getCmp('Tilmeld30').setDisabled(!checked)
            tilmelding[0].getForm().isValid()
          }
        }
      }
      ]
    },{
      xtype: 'checkboxgroup',
      items: [
      {
        boxLabel: 'Ja tak, jeg vil gerne modtage e-mails med information fra Viborg Classic.',
        name: 'acceptmail',
        id: 'acceptmail30',
        listeners: {
          check : function( b, checked ){
            Ext.getCmp('email30').setDisabled(!checked)
            Ext.getCmp('email30').validate()
          }
        }
      }
      ]
    }
    ]
  }
  ],

  buttons: [{
    text: 'Tilmeld',
    id: 'Tilmeld30',
    disabled: true,
    tabIndex: 10,
    handler: function(){
      if(tilmelding[0].getForm().isValid()){
        Ext.Msg.confirm('Bekræft din Viborg Classic tilmelding',
          'Jeg bekræfter min tilmelding til Viborg Classic',
          processResult30)
      }
    }

  },{
    text: 'Fortryd',
    id: 'Fortryd30',
    handler: function(){
      tilmelding[0].getForm().reset();
    }
  }],
  listeners: {
    expand : function( p ){
      myBorderPanel.doLayout();
    }
  }
});

function processResult30(btn)
{
  if(btn=='yes')
  {
    tilmelding[0].getForm().submit({
      url:'php/tilmeldinghandle.php',
      params:{
        distance:30,
        year:year
      },
      success:function(form,action){
        Ext.Msg.alert('Tilmelding gennemført', action.result.msg);
        grid[0][year-2006].getStore().reload();
        reloadStoresAfterSubmit();
      },
      failure:function(form,action){
        Ext.Msg.alert('Tilmelding fejlet', action.result.msg);
      },
      clientValidation : false
    })     
  }
}

function updateprices30(teamco)
{
  Ext.getCmp('startpris30').setValue(krformat(startpris30));
  var gebyr30 = new Date()<deadline?0:findGebyr(teamco);
  Ext.getCmp('gebyr30').setValue(krformat(gebyr30))
  Ext.getCmp('ialt30').setValue(krformat(startpris30+gebyr30))
}
//Initialize price textfields

