////////////////////////////////////////////////////////////////////////
//
// Filename:    formcompinschrijven.js
// Purpose:     Create a form to subscribe to a competition
// Method:      JavaScript class
//
// Author:      J.van.der.Steen@gobase.org
// Date:        2010-03-07
//
// Note:        Requires prototype.js
//
////////////////////////////////////////////////////////////////////////

var FormCompInschrijven = Class.create( FormBase,
{

    initialize: function($super, values)
    {
        this.valAssign(values, "type", "competitie inschrijven");

        $super(values);

        /*
         * Editable properties
         */
        this.propAdd( values
                    , "aanhef"
                    , { type     : 'select'
                      , key      : 'aanhef'
                      , val      : ''
                      , valid    : 1
                      , validator: null
                      , options  : [ { key: 'dhr' , val: 'dhr'  }
                                   , { key: 'mevr', val: 'mevr' }
                                   ]
                      }
                    ) ;
        this.propAdd( values
                    , "firstname"
                    , { type     : 'text'
                      , size     : 64
                      , key      : 'voornaam'
                      , val      : ''
                      , valid    : 1
                      , validator: 'validateNonempty'
                      }
                    ) ;
        this.propAdd( values
                    , "lastname"
                    , { type     : 'text'
                      , size     : 64
                      , key      : 'achternaam'
                      , val      : ''
                      , valid    : 1
                      , validator: 'validateNonempty'
                      }
                    ) ;
        this.propAdd( values
                    , "bondsnummer"
                    , { type     : 'text'
                      , size     : 64
                      , key      : 'bondsnummer'
                      , val      : ''
                      , valid    : 1
                      , validator: 'validateNonempty'
                      }
                    ) ;
        this.propAdd( values
                    , "phone"
                    , { type     : 'text'
                      , size     : 64
                      , key      : 'telefoonnummer'
                      , val      : ''
                      , valid    : 1
                      , validator: 'validatePhone'
                      }
                    ) ;
        this.propAdd( values
                    , "email"
                    , { type     : 'text'
                      , size     : 64
                      , key      : 'e-mail adres'
                      , val      : ''
                      , valid    : 1
                      , validator: 'validateEmail'
                      }
                    ) ;
        this.propAdd( values
                    , "competitie"
                    , { type     : 'select'
                      , key      : 'competitie'
                      , val      : ''
                      , valid    : 1
                      , validator: null
                      , options  : this.getLegalCompetitionValues()
                      }
                    ) ;
        this.propAdd( values
                    , "opmerkingen"
                    , { type     : 'textarea'
                      , rows     : 5
                      , cols     : 64
                      , key      : 'opmerkingen'
                      , val      : ''
                      , valid    : 1
                      , validator: null
                      }
                    ) ;

        /*
         * System properties
         */
        this.propAdd( values
                    , "functionaris"
                    , { type     : 'hidden'
                      , size     : 64
                      , key      : 'functionaris'
                      , val      : 'competitie'
                      , valid    : 1
                      , validator: 'validateNonempty'
                      }
                    ) ;

        /*
         * Buttons
         */
        this.propAdd( values
                    , "versturen"
                    , { type     : 'button'
                      , size     : 32
                      , key      : 'versturen'
                      , val      : 'versturen'
                      , valid    : 1
                      , validator: 'validateNonempty'
                      , onclick  : 'save'
                      }
                    ) ;

    }

,   getLegalCompetitionValues: function()
    {
        var values = [];

        values.push({ key: 'driebandgroot' , val: 'A (driebanden groot)'               });
        values.push({ key: 'driebandklein1', val: 'B1 (driebanden klein)'              });
        values.push({ key: 'driebandklein2', val: 'B2 (driebanden klein)'              });
        values.push({ key: 'libre1'        , val: 'C1 (libre)'                         });
        values.push({ key: 'libre2'        , val: 'C2 (libre)'                         });
        values.push({ key: 'libre3'        , val: 'C3 (libre)'                         });
        values.push({ key: 'libre4'        , val: 'C4 (libre)'                         });
        values.push({ key: 'libre5'        , val: 'C5 (libre)'                         });

        return values;
    }

} ) ;

function emitCompinschrijven()
{
    var form = new FormCompInschrijven({});
    var html = '';

    html += "<div id='compinschrijven-header'></div>\n";
    html += form.edit();
    html += "<div id='compinschrijven-footer'></div>\n";

    Element.update('content', html);

    setTimeout( "contentLoadExec( { target  : 'compinschrijven-header'"
              + "                 , filename: 'competitie/inschrijven-header.phtml'"
              + "                 } )"
              , 250
              ) ;
    setTimeout( "contentLoadExec( { target  : 'compinschrijven-footer'"
              + "                 , filename: 'competitie/inschrijven-footer.phtml'"
              + "                 } )"
              , 250
              ) ;
}




