31cc8e3f79265ec907d8dbffaafabc85532b670e
[namibia] / public / js / app / brochure-workspace / register.js
1 ;(function(){
2
3         window._w.register = {
4
5                 itemId     : null,
6                 itemData   : null,
7                 formMeta   : null,
8                 ti         : null,
9                 counter    : 0,
10                 ownerCount : 0,
11                 owners     : {},
12
13                 onTemplateReady : function( template, event, eventData )
14                 {
15                         _w.register.ti = _t[template];
16                         _w.register.limited = ('limitedregister' == template)
17                                 ? true
18                                 : false;
19
20                         //App.DataStore.setData('companytypes', [
21                      //      {"value":"Limited", "label":"Limited"},
22                      //      {"value":"PTY Limited", "label":"PTY Limited"},
23                      //      {"value":"Closed Corporation", "label":"Closed Corporation"},
24                      //      {"value":"Sole Proprietor", "label":"Sole Proprietor"}
25                      //      ]);
26                         //App.DataStore.setData('dealertypes', [
27                      //      {"value":"Dealer", "label":"Dealer"},
28                      //      {"value":"Wholesale / Trader", "label":"Wholesale / Trader"},
29                      //      {"value":"Trade Center", "label":"Trade Center"}
30                      //      ]);
31                         //App.DataStore.setData('clienttypes', [
32              //     {"value":"Buyer", "label":"Buyer"},
33              //     {"value":"Buyer & Seller", "label":"Buyer & Seller"}
34              //     ]);
35                         //App.DataStore.setData('companyturnover', [
36              //     {"value":"Turnover > R500,000", "label":"Turnover > R500,000"},
37              //     {"value":"Turnover > R2,000,000", "label":"Turnover > R2,000,000"},
38              //     {"value":"Turnover > R3,000,000", "label":"Turnover > R3,000,000"}
39              //     ]);
40                         App.DataStore.loadSelectListData('permissions', true, 'User', 'Permissions.SelectList');
41                         //App.DataStore.loadSelectListData('countries', true, 'Location', 'Country.SelectList');
42                         //App.DataStore.loadSelectListData('groups', true, 'Company', 'Group.SelectList');
43                         //App.DataStore.loadSelectListData('foundmethods', true, 'Company', 'FoundMethod.SelectList');
44
45
46
47                         _w.register.setRegisterViewFormMeta();
48                         _w.register.ti.hydrate(_w.register.formMeta);
49                         App.API.getTask(
50                                 'register', 'User', 'Registration.RegisterFull', null,
51                                 {}, function() {}, _w.taskContractError
52                         );
53
54                 },
55
56                 onTemplatePublished : function( template, event, eventData )
57                 {
58                         _w.register.ti = _t[template];
59                         _w.register.setRegisterViewFormMeta();
60                         _w.register.ti.hydrate(_w.register.formMeta);
61                         _w.register._setupValidation();
62                         $('#btnAddOwner').click(_w.register.addOwner);
63                 },
64
65                 setRegisterViewFormMeta : function( data )
66                 {
67                         if (!data)
68                         {
69                                 data = {};
70                         }
71                         _w.register.formMeta = {
72                                 // User details
73                                 'firstName' : {
74                                         type  : 'input',
75                                         id    : 'firstName',
76                                         title : 'Name',
77                                         value : '',
78                                         maxlength : 100
79                                 },
80                                 'familyName' : {
81                                         type  : 'input',
82                                         id    : 'familyName',
83                                         title : 'Surname',
84                                         value : '',
85                                         maxlength : 100
86                                 },
87                                 'permissions' : {
88                                         type        : 'select',
89                                         id          : 'permissions',
90                                         title       : 'User type',
91                                         value       : '12',
92                                         dataStoreId : 'permissions',
93                                         disabled    :true
94                                 },
95                                 'email' : {
96                                         type  : 'input',
97                                         id    : 'email',
98                                         title : 'Email address',
99                                         value : '',
100                                         maxlength : 255
101                                 },
102                                 'confirmEmail' : {
103                                         type  : 'input',
104                                         id    : 'confirmEmail',
105                                         title : 'Confirm email address',
106                                         value : '',
107                                         maxlength : 255
108                                 },
109                                 'pin' : {
110                                         type  : 'input',
111                                         id    : 'pin',
112                                         title : '4 Digit pin',
113                                         value : '',
114                                         maxlength : 5
115                                 },
116                                 'confirmPin' : {
117                                         type  : 'input',
118                                         id    : 'confirmPin',
119                                         title : 'Confirm 4 digit pin',
120                                         value : '',
121                                         maxlength : 5
122                                 },
123                                 'idNumber' : {
124                                         type  : 'input',
125                                         id    : 'idNumber',
126                                         title : 'ID Number',
127                                         value : '',
128                                         maxlength : 13,
129                                         onChange  : function() {
130                                                 var dig = $(this).val().substring(0, 6);
131                                                 $('#dateOfBirth').val(
132                                                                 '19' + dig.substring(0, 2) +
133                                                                 '-' + dig.substring(2, 4) +
134                                                                 '-' + dig.substring(4, 6)
135                                                                 );
136                                         }
137                                 },
138                                 'dateOfBirth' : {
139                                         type  : 'date',
140                                         id    : 'dateOfBirth',
141                                         title : 'Date of birth',
142                                         style : 'datepicker',
143                                         value : ''
144                                 },
145                                 'mobile' : {
146                                         type  : 'mobile',
147                                         id    : 'mobile',
148                                         title : 'Mobile number',
149                                         value : '',
150                                         maxlength : 20
151                                 },
152
153                                 // Dealership contact
154                                 //'contactFirstName' : {
155                                 //      type  : 'input',
156                                 //      id    : 'contactFirstName',
157                                 //      title : 'Name',
158                                 //      value : '',
159                                 //      maxlength : 50
160                                 //},
161                                 //'contactFamilyName' : {
162                                 //      type  : 'input',
163                                 //      id    : 'contactFamilyName',
164                                 //      title : 'Surname',
165                                 //      value : '',
166                                 //      maxlength : 50
167                                 //},
168                                 //'contactOffice' : {
169                                 //      type  : 'input',
170                                 //      id    : 'contactOffice',
171                                 //      title : 'Landline',
172                                 //      value : '',
173                                 //      maxlength : 20
174                                 //},
175                                 //'contactMobile' : {
176                                 //      type  : 'mobile',
177                                 //      id    : 'contactMobile',
178                                 //      title : 'Mobile number',
179                                 //      value : '',
180                                 //      maxlength : 20
181                                 //},
182                                 //'contactEmail' : {
183                                 //      type  : 'input',
184                                 //      id    : 'contactEmail',
185                                 //      title : 'Email',
186                                 //      value : '',
187                                 //      maxlength : 255
188                                 //},
189                 //
190                                 //// Dealership details
191                                 //'dealerType' : {
192                                 //      type  : 'select',
193                                 //      id    : 'dealerType',
194                                 //      title : 'Registration type',
195                                 //      value : '',
196                                 //      dataStoreId : 'dealertypes'
197                                 //},
198                                 //'clientType' : {
199                                 //      type  : 'select',
200                                 //      id    : 'clientType',
201                                 //      title : 'Register as',
202                                 //      value : '',
203                                 //      dataStoreId : 'clienttypes'
204                                 //},
205                                 //'group' : {
206                                 //      type  : 'select',
207                                 //      id    : 'group',
208                                 //      title : 'Group Member',
209                                 //      value : '',
210                                 //      dataStoreId : 'groups',
211                                 //      onChange    : function () {
212                                 //              if (!App.DataStore.getItem('BuildSelect:group', false))
213                                 //              {
214                                 //                      var groupId = $('#group').val();
215                                 //                      App.DataStore.loadSelectListData(
216                                 //                                      'groupdivisions', false, 'Company', 'GroupDivision.SelectList',
217                                 //                                      null, {Filter: {group: groupId}}
218                                 //                                      );
219                                 //              }
220                                 //      }
221                                 //},
222                                 //'groupDivision' : {
223                                 //      type  : 'select',
224                                 //      id    : 'groupDivision',
225                                 //      title : 'Group Division',
226                                 //      value : '',
227                                 //      dataStoreId : 'groupdivisions'
228                                 //},
229                                 //'companyType' : {
230                                 //      type  : 'select',
231                                 //      id    : 'companyType',
232                                 //      title : 'Company type',
233                                 //      value : '',
234                                 //      dataStoreId : 'companytypes',
235                                 //      onChange    : function() {
236                                 //              if (!App.DataStore.getItem('BuildSelect:companyType', false))
237                                 //              {
238                                 //                      if ('Sole Proprietor' == $(this).val())
239                                 //                      {
240                                 //                              $('#' + _w.register.ti.tid + '_docCopyOfDirectorId').hide();
241                                 //                              $('#' + _w.register.ti.tid + '_docCompanyRegistration').hide();
242                                 //                              $('#' + _w.register.ti.tid + '_docStockCertificate').show();
243                                 //                              $('#' + _w.register.ti.tid + '_docCopyOfId').show();
244                                 //                              $('#' + _w.register.ti.tid + '_docAddressProof').show();
245                                 //                      }
246                                 //                      else
247                                 //                      {
248                                 //                              $('#' + _w.register.ti.tid + '_docStockCertificate').hide();
249                                 //                              $('#' + _w.register.ti.tid + '_docCopyOfId').hide();
250                                 //                              $('#' + _w.register.ti.tid + '_docAddressProof').show();
251                                 //                              $('#' + _w.register.ti.tid + '_docCopyOfDirectorId').show();
252                                 //                              $('#' + _w.register.ti.tid + '_docCompanyRegistration').show();
253                                 //                      }
254                                 //              }
255                                 //      }
256                                 //},
257                                 //'businessName' : {
258                                 //      type  : 'input',
259                                 //      id    : 'businessName',
260                                 //      title : 'Registered business name',
261                                 //      value : '',
262                                 //      maxlength : 100
263                                 //},
264                                 //'name' : {
265                                 //      type  : 'input',
266                                 //      id    : 'name',
267                                 //      title : 'Trading name',
268                                 //      value : '',
269                                 //      maxlength : 100
270                                 //},
271                                 //'companyRegistrationNumber' : {
272                                 //      type  : 'input',
273                                 //      id    : 'companyRegistrationNumber',
274                                 //      title : 'Company Reg no',
275                                 //      value : '',
276                                 //      mask  : '9999/999999/99',
277                                 //      maxlength : 14
278                                 //},
279                                 //'vatNumber' : {
280                                 //      type  : 'input',
281                                 //      id    : 'vatNumber',
282                                 //      title : 'Vat no',
283                                 //      value : '',
284                                 //      maxlength : 20
285                                 //},
286                                 //'turmiNumber' : {
287                                 //      type  : 'input',
288                                 //      id    : 'turmiNumber',
289                                 //      title : 'TransUnion membership no',
290                                 //      value : '',
291                                 //      maxlength : 50
292                                 //},
293                                 //'dealerStockNumber' : {
294                                 //      type  : 'input',
295                                 //      id    : 'dealerStockNumber',
296                                 //      title : 'Dealer stock no',
297                                 //      value : '',
298                                 //      maxlength : 50
299                                 //},
300                                 //'turnover' : {
301                                 //      type  : 'select',
302                                 //      id    : 'turnover',
303                                 //      title : 'Turnover',
304                                 //      value : '',
305                                 //      dataStoreId : 'companyturnover'
306                                 //},
307                                 //'foundMethod' : {
308                                 //      type  : 'select',
309                                 //      id    : 'foundMethod',
310                                 //      title : 'Where did you find us?',
311                                 //      value : '',
312                                 //      dataStoreId : 'foundmethods',
313                                 //      onChange    : function () {
314                                 //              if (!App.DataStore.getItem('BuildSelect:foundMethod', false))
315                                 //              {
316                                 //                      var foundId = $('#foundMethod').val();
317                                 //                      App.DataStore.loadSelectListData(
318                                 //                                      'foundmethoddetails', false, 'Company', 'FoundMethodDetail.SelectList',
319                                 //                                      null, {Filter: {foundMethod: foundId}}
320                                 //                                      );
321                                 //              }
322                                 //      }
323                                 //},
324                                 //'foundMethodDetail' : {
325                                 //      type  : 'select',
326                                 //      id    : 'foundMethodDetail',
327                                 //      title : 'Details',
328                                 //      value : '',
329                                 //      dataStoreId : 'foundmethoddetails'
330                                 //},
331                 //
332                 //
333                                 //// Adresses and billing contact
334                                 //'country' : {
335                                 //      type        : 'select',
336                                 //      id          : 'country',
337                                 //      title       : 'Country',
338                                 //      dataStoreId : 'countries',
339                                 //      value       : '',
340                                 //      onChange    : function () {
341                                 //              if (!App.DataStore.getItem('BuildSelect:country', false))
342                                 //              {
343                                 //                      App.DataStore.loadSelectListData(
344                                 //                                      'regions', false, 'Location', 'Region.SelectList', null,
345                                 //                                      {"Filter": {
346                                 //                                              "country" : $(this).val()
347                                 //                                              }}
348                                 //                                      );
349                                 //                      App.DataStore.setData('cities', []);
350                                 //                      if ($('#sameAsBusinessAddress').prop('checked'))
351                                 //                      {
352                                 //                              $('#billingCountry').selectpicker('val', $('#country').val());
353                                 //                      }
354                                 //              }
355                                 //      }
356                                 //},
357                                 //'region' : {
358                                 //      type        : 'select',
359                                 //      id          : 'region',
360                                 //      title       : 'Region',
361                                 //      dataStoreId : 'regions',
362                                 //      value       : '',
363                                 //      onChange    : function () {
364                                 //              if (!App.DataStore.getItem('BuildSelect:region', false))
365                                 //              {
366                                 //                      App.DataStore.loadSelectListData(
367                                 //                                      'cities', false, 'Location', 'Town.SelectList', null,
368                                 //                                      {"Filter": {
369                                 //                                              "region" : $(this).val()
370                                 //                                              }}
371                                 //                                      );
372                                 //                      if ($('#sameAsBusinessAddress').prop('checked'))
373                                 //                      {
374                                 //                              $('#billingRegion').selectpicker('val', $('#region').val());
375                                 //                      }
376                                 //              }
377                                 //      }
378                                 //},
379                                 //'city' : {
380                                 //      type        : 'select',
381                                 //      id          : 'city',
382                                 //      title       : 'Town',
383                                 //      dataStoreId : 'cities',
384                                 //      value       : ''
385                                 //},
386                                 //'street' : {
387                                 //      type  : 'input',
388                                 //      id    : 'street',
389                                 //      title : 'Street',
390                                 //      value : '',
391                                 //      maxlength : 75
392                                 //},
393                                 //'postalCode' : {
394                                 //      type  : 'input',
395                                 //      id    : 'postalCode',
396                                 //      title : 'Code',
397                                 //      value : '',
398                                 //      maxlength : 10
399                                 //},
400                                 //'sameAsBusinessAddress' : {
401                                 //      type  : 'checkbox',
402                                 //      id    : 'sameAsBusinessAddress',
403                                 //      title : 'Same as business address',
404                                 //      value : '',
405                                 //      onChange : function() {
406                                 //              if ($(this).prop('checked'))
407                                 //              {
408                                 //                      App.DataStore.setItem('BuildSelect:migrateCountry', true);
409                                 //                      $('#billingCountry').selectpicker('val', $('#country').val());
410                                 //                      App.DataStore.removeItem('BuildSelect:migrateCountry');
411                                 //                      App.DataStore.setItem('BuildSelect:migrateRegion', true);
412                                 //                      App.DataStore.loadSelectListData(
413                                 //                                      'billregions', false, 'Location', 'Region.SelectList', null,
414                                 //                                      {"Filter": {
415                                 //                                              "country" : $('#country').val()
416                                 //                                      }}, {}, function() {
417                                 //                                              $('#billingRegion').selectpicker('val', $('#region').val());
418                                 //                                              App.DataStore.removeItem('BuildSelect:migrateRegion');
419                                 //                                      }
420                                 //                      );
421                                 //                      App.DataStore.setItem('BuildSelect:migrateTown', true);
422                                 //                      App.DataStore.loadSelectListData(
423                                 //                                      'billcities', false, 'Location', 'Town.SelectList', null,
424                                 //                                      {"Filter": {
425                                 //                                              "region" : $('#region').val()
426                                 //                                      }}, {}, function() {
427                                 //                                              $('#billingCity').selectpicker('val', $('#city').val());
428                                 //                                      }
429                                 //                      );
430                                 //                      $('#billingStreet').val($('#street').val());
431                                 //                      $('#billingPostalCode').val($('#postalCode').val());
432                                 //              }
433                                 //              else
434                                 //              {
435                                 //                      $('#billingCountry').selectpicker('val', '');
436                                 //                      App.DataStore.setData('billregions', []);
437                                 //                      App.DataStore.setData('billcities', []);
438                                 //                      $('#billingStreet').val('');
439                                 //                      $('#billingPostalCode').val('');
440                                 //              }
441                                 //      }
442                                 //},
443                                 //'billingCountry' : {
444                                 //      type        : 'select',
445                                 //      id          : 'billingCountry',
446                                 //      title       : 'Country',
447                                 //      dataStoreId : 'countries',
448                                 //      value       : '',
449                                 //      onChange    : function () {
450                                 //              if (!App.DataStore.getItem('BuildSelect:billingCountry', false)
451                                 //                              && !App.DataStore.getItem('BuildSelect:migrateCountry', false))
452                                 //              {
453                                 //                      App.DataStore.loadSelectListData(
454                                 //                                      'billregions', false, 'Location', 'Region.SelectList', null,
455                                 //                                      {"Filter": {
456                                 //                                              "country" : $(this).val()
457                                 //                                              }}
458                                 //                                      );
459                                 //                      App.DataStore.setData('billcities', []);
460                                 //              }
461                                 //      }
462                                 //},
463                                 //'billingRegion' : {
464                                 //      type        : 'select',
465                                 //      id          : 'billingRegion',
466                                 //      title       : 'Region',
467                                 //      dataStoreId : 'billregions',
468                                 //      value       : '',
469                                 //      onChange    : function () {
470                                 //              if (!App.DataStore.getItem('BuildSelect:billingRegion', false)
471                                 //                              && !App.DataStore.getItem('BuildSelect:migrateRegion', false))
472                                 //              {
473                                 //                      App.DataStore.loadSelectListData(
474                                 //                                      'billcities', false, 'Location', 'Town.SelectList', null,
475                                 //                                      {"Filter": {
476                                 //                                              "region" : $(this).val()
477                                 //                                              }}
478                                 //                                      );
479                                 //              }
480                                 //      }
481                                 //},
482                                 //'billingCity' : {
483                                 //      type        : 'select',
484                                 //      id          : 'billingCity',
485                                 //      title       : 'Town',
486                                 //      dataStoreId : 'billcities',
487                                 //      value       : ''
488                                 //},
489                                 //'billingStreet' : {
490                                 //      type  : 'input',
491                                 //      id    : 'billingStreet',
492                                 //      title : 'Street',
493                                 //      value : '',
494                                 //      maxlength : 75
495                                 //},
496                                 //'billingPostalCode' : {
497                                 //      type  : 'input',
498                                 //      id    : 'billingPostalCode',
499                                 //      title : 'Code',
500                                 //      value : '',
501                                 //      maxlength : 10
502                                 //},
503                 //
504                                 //'sameAsDealerContact' : {
505                                 //      type  : 'checkbox',
506                                 //      id    : 'sameAsDealerContact',
507                                 //      title : 'Same as dealership contact',
508                                 //      value : '',
509                                 //      onChange : function() {
510                                 //              if ($(this).prop('checked'))
511                                 //              {
512                                 //                      $('#billingFirstName').val($('#contactFirstName').val());
513                                 //                      $('#billingFamilyName').val($('#contactFamilyName').val());
514                                 //                      $('#billingOffice').val($('#contactOffice').val());
515                                 //                      $('#billingMobile').val($('#contactMobile').val());
516                                 //                      $('#billingEmail').val($('#contactEmail').val());
517                                 //              }
518                                 //              else
519                                 //              {
520                                 //                      $('#billingFirstName').val('');
521                                 //                      $('#billingFamilyName').val('');
522                                 //                      $('#billingOffice').val('');
523                                 //                      $('#billingMobile').val('');
524                                 //                      $('#billingEmail').val('');
525                                 //              }
526                                 //      }
527                                 //},
528                                 //'billingFirstName' : {
529                                 //      type  : 'input',
530                                 //      id    : 'billingFirstName',
531                                 //      title : 'Name',
532                                 //      value : '',
533                                 //      maxlength : 50
534                                 //},
535                                 //'billingFamilyName' : {
536                                 //      type  : 'input',
537                                 //      id    : 'billingFamilyName',
538                                 //      title : 'Surname',
539                                 //      value : '',
540                                 //      maxlength : 50
541                                 //},
542                                 //'billingOffice' : {
543                                 //      type  : 'input',
544                                 //      id    : 'billingOffice',
545                                 //      title : 'Landline',
546                                 //      value : '',
547                                 //      maxlength : 20
548                                 //},
549                                 //'billingMobile' : {
550                                 //      type  : 'mobile',
551                                 //      id    : 'billingMobile',
552                                 //      title : 'Mobile number',
553                                 //      value : '',
554                                 //      maxlength : 20
555                                 //},
556                                 //'billingEmail' : {
557                                 //      type  : 'input',
558                                 //      id    : 'billingEmail',
559                                 //      title : 'Email',
560                                 //      value : '',
561                                 //      maxlength : 255
562                                 //},
563                 //
564                                 //// Owners
565                                 //'ownerFirstName' : {
566                                 //      type  : 'input',
567                                 //      id    : 'ownerFirstName',
568                                 //      title : 'Name',
569                                 //      value : '',
570                                 //      maxlength : 100
571                                 //},
572                                 //'ownerFamilyName' : {
573                                 //      type  : 'input',
574                                 //      id    : 'ownerFamilyName',
575                                 //      title : 'Surname',
576                                 //      value : '',
577                                 //      maxlength : 100
578                                 //},
579                                 //'ownerIdNumber' : {
580                                 //      type  : 'input',
581                                 //      id    : 'ownerIdNumber',
582                                 //      title : 'ID Number',
583                                 //      value : '',
584                                 //      maxlength : 13
585                                 //},
586                                 //'owners' : {
587                                 //      type  : 'collector',
588                                 //      id    : 'owners',
589                                 //      value : []
590                                 //},
591                 //
592                                 //// Documents
593                                 //'docStockCertificate' : {
594                                 //      type  : 'document',
595                                 //      id    : 'docStockCertificate',
596                                 //      title : 'Dealer stock certificate',
597                                 //      value : null
598                                 //},
599                                 //'docAddressProof' : {
600                                 //      type  : 'document',
601                                 //      id    : 'docAddressProof',
602                                 //      title : 'Proof of business address',
603                                 //      value : null
604                                 //},
605                                 //'docCopyOfId' : {
606                                 //      type  : 'document',
607                                 //      id    : 'docCopyOfId',
608                                 //      title : 'Copy of ID document',
609                                 //      value : null
610                                 //},
611                                 //'docCopyOfDirectorId' : {
612                                 //      type  : 'document',
613                                 //      id    : 'docCopyOfDirectorId',
614                                 //      title : 'Copy of directors ID document',
615                                 //      value : null
616                                 //},
617                                 //'docCompanyRegistration' : {
618                                 //      type  : 'document',
619                                 //      id    : 'docCompanyRegistration',
620                                 //      title : 'Company registration document',
621                                 //      value : null
622                                 //},
623
624                                 'subscribeNewsletter' : {
625                                         type  : 'checkbox',
626                                         id    : 'subscribeNewsletter',
627                                         title : 'Sign me up for the monthly newsletter and Bid4Cars updates.',
628                                         value : false
629                                 },
630                                 'acceptTermsAndConditions' : {
631                                         type  : 'checkbox',
632                                         id    : 'acceptTermsAndConditions',
633                                         title : 'I agree to the Terms & Conditions, Website Terms & Conditions and Privacy Policy of Bid4Cars.',
634                                         value : false,
635                                         onChange : function() {
636                                                 $('#btnUpdate').prop('disabled', !$(this).prop('checked'));
637                                         }
638                                 }
639                         };
640                 },
641
642                 addOwner : function()
643                 {
644                         var name    = $('#ownerFirstName').val();
645                         var surname = $('#ownerFamilyName').val();
646                         var idnum   = $('#ownerIdNumber').val();
647                         if ('' == name || '' == surname || !$('#ownerIdNumber').valid())
648                         {
649                                 alert('Please provide Name, Surname and ID number.');
650                                 return;
651                         }
652                         _w.register.owners['colItem' + _w.register.counter] = {
653                                         firstName  : name,
654                                         familyName : surname,
655                                         idNumber   : idnum
656                         };
657                         var html = '<div class="accordion-group" id="colItem' + _w.register.counter + '">';
658                         html += '<div class="accordion-heading">';
659                         html += '<a class="accordion-toggle" data-toggle="collapse" data-parent="#owners" href="#collapse' + _w.register.counter + '">';
660                         html += name + ' ' + surname;
661                         html += '</a>';
662                         html += '</div>';
663                         html += '<div id="collapse' + _w.register.counter + '" class="accordion-body collapse in">';
664                         html += '<div class="accordion-inner">';
665                         html += name + ' ' + surname + ' (' + idnum + ')';
666                         html += '<br/><button type="button" class="btn pull-right" onClick="_w.register.removeOwner(' + _w.register.counter + ');">Remove</button>';
667                         html += '</div>';
668                         html += '</div>';
669                         html += '</div>';
670                         $('#owners').append(html);
671                         $('#collapse' + _w.register.counter).collapse('toggle');
672                         _w.register.counter++;
673                         _w.register.ownerCount++;
674
675                         $('#ownerFirstName').val('');
676                         $('#ownerFamilyName').val('');
677                         $('#ownerIdNumber').val('');
678                 },
679
680                 removeOwner : function( id )
681                 {
682                         delete _w.register.owners['colItem' + id];
683                         $('#colItem' + id).remove();
684                         _w.register.ownerCount--;
685                 },
686
687                 _setupValidation : function ()
688                 {
689                         $('#frmRegister').validate({
690                                 rules: {
691                                         firstName: {required: true},
692                                         familyName: {required: true},
693                                         permissions: {required: false},
694                                         email: {required: true, email: true, remote: {
695                                         url: "/workspace/check-unique-email",
696                                         type: "post"
697                                       }},
698                                         confirmEmail: {required: true, email: true, equalTo: "#email"},
699                                         pin: {required: true, digits: true},
700                                         confirmPin: {required: true, digits: true, equalTo: "#pin"},
701                                         idNumber: {required: true, minlength: 13, maxlength: 13, digits: true},
702                                         dateOfBirth: {required: true, dateISO: true},
703                                         mobile: {required: true, mobile: true},
704
705                                         //contactFirstName: {required: true},
706                                         //contactFamilyName: {required: true},
707                                         //contactOffice: {required: true, digits: true},
708                                         //contactMobile: {required: true, mobile: true},
709                                         //contactEmail: {required: true, email: true},
710
711                                         //dealerType: {required: true},
712                                         //clientType: {required: true},
713                                         //companyType: {required: true},
714                                         //businessName: {required: true},
715                                         //name: {required: true, remote: {
716                                      //   url: "/workspace/check-unique-company",
717                                      //   type: "post"
718                                      // }},
719                                         //companyRegistrationNumber: {companyReg: true},
720                                         //vatNumber: {digits: true},
721
722                                         //country: {required: true},
723                                         //region: {required: true},
724                                         //city: {required: true},
725                                         //street: {required: true},
726                                         //postalCode: {required: true, digits: true},
727                                         //billingCountry: {required: true},
728                                         //billingRegion: {required: true},
729                                         //billingCity: {required: true},
730                                         //billingStreet: {required: true},
731                                         //billingPostalCode: {required: true, digits: true},
732                                         //billingFirstName: {required: true},
733                                         //billingFamilyName: {required: true},
734                                         //billingOffice: {required: true, digits: true},
735                                         //billingMobile: {required: true, mobile: true},
736                                         //billingEmail: {required: true, email: true},
737                     //
738                                         //ownerIdNumber: {minlength: 13, maxlength: 13, digits: true}
739                                 },
740                                 messages: {
741                                         email: { email: "Must be a valid email address.", remote: "Email address already in use."},
742                                         confirmEmail: { equalTo: "Values are not the same." },
743                                         confirmPin: { equalTo: "Values are not the same." },
744                                         contactEmail: { email: "Must be a valid email address." },
745                                         billingEmail: { email: "Must be a valid email address." },
746                                         country : "This field is required.",
747                                         region : "This field is required.",
748                                         city : "This field is required.",
749                                         billingCountry : "This field is required.",
750                                         billingRegion : "This field is required.",
751                                         billingCity : "This field is required.",
752                                         permissions : "This field is required.",
753                                         companyType : "This field is required.",
754                                         dealerType : "This field is required.",
755                                         clientType : "This field is required."
756                                 },
757                                 submitHandler: function( form ) {
758                                         if (0 == _w.register.ownerCount) {
759                                                 $('#ownerFirstName').addClass('error');
760                                                 $('#ownerFamilyName').addClass('error');
761                                                 $('#ownerIdNumber').addClass('error');
762                                             alert('At least 1 owner / director required.');
763                                             return false;
764                                     } else {
765                                                 $('#ownerFirstName').removeClass('error');
766                                                 $('#ownerFamilyName').removeClass('error');
767                                                 $('#ownerIdNumber').removeClass('error');
768                                     }
769                                         $('#btnUpdate').prop('disabled', true);
770                                         var data = _w.register._prepRegisterUpdateData();
771                                         App.API.execTask(
772                                                         'register', data, {},
773                                                         _w.register._onRegisterUpdated, _w.taskExecError
774                                                 );
775                                 }
776                         });
777                         $('#frmRegister').valid();
778                         $('label.error').remove();
779                         $('.valid').removeClass('valid');
780                 },
781
782                 _prepRegisterUpdateData : function()
783                 {
784                         var data = _w.register.ti.harvest();
785                         var postData = {
786                                         Company:{},
787                                         Profile:{},
788                                         Contact:{},
789                                         BillingContact:{}
790                                         };
791                         var profileFields = [
792                  "firstName","familyName","permissions","email","confirmEmail",
793                  "pin","confirmPin","idNumber","dateOfBirth","mobile", "subscribeNewsletter"
794                  ];
795                         var companyFields = [
796                  "dealerType","clientType","group","groupDivision","companyType",
797                  "businessName","name","companyRegistrationNumber","vatNumber","turmiNumber",
798                  "dealerStockNumber","turnover","foundMethod","foundMethodDetail",
799                  "country","region","city","street","postalCode",
800                  "billingCountry","billingRegion","billingCity","billingStreet","billingPostalCode",
801                  "docStockCertificate","docAddressProof","docCopyOfId",
802                  "docCopyOfDirectorId","docCompanyRegistration"
803                  ];
804                         var contactFields = {
805                  "contactFirstName"  : "firstName",
806                  "contactFamilyName" : "familyName",
807                  "contactOffice"     : "office",
808                  "contactMobile"     : "mobile",
809                  "contactEmail"      : "email"
810                         };
811                         var billingContactFields = {
812                  "billingFirstName"  : "firstName",
813                  "billingFamilyName" : "familyName",
814                  "billingOffice"     : "office",
815                  "billingMobile"     : "mobile",
816                  "billingEmail"      : "email"
817                         };
818                         for (var field in data)
819                         {
820                                 if (-1 != companyFields.indexOf(field))
821                                 {
822                                         postData.Company[field] = '' != data[field] ? data[field] : null;
823                                 }
824                                 else if (-1 != profileFields.indexOf(field))
825                                 {
826                                         postData.Profile[field] = '' != data[field] ? data[field] : null;
827                                 }
828                                 else if (contactFields[field])
829                                 {
830                                         postData.Contact[contactFields[field]] = '' != data[field] ? data[field] : null;
831                                 }
832                                 else if (billingContactFields[field])
833                                 {
834                                         postData.BillingContact[billingContactFields[field]] = '' != data[field] ? data[field] : null;
835                                 }
836                         }
837                         postData.Profile.password = postData.Profile.pin;
838                         postData.Company.owners = _w.register.owners;
839                         return postData;
840                 },
841
842                 _onRegisterUpdated : function( response )
843                 {
844                         window.location.hash = '/registered';
845                 }
846
847         };
848
849 })();