-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathlookup.js
More file actions
executable file
·1504 lines (1359 loc) · 87.6 KB
/
lookup.js
File metadata and controls
executable file
·1504 lines (1359 loc) · 87.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var PCNL_START_FUNCTION;
document.observe("dom:loaded", PCNL_START_FUNCTION = function()
{
// If we have no configuration, do not do anything
if (typeof PCNLAPI_CONFIG == 'undefined')
return;
if (typeof String.prototype.trim !== 'function')
{
String.prototype.trim = function()
{
return this.replace(/^\s+|\s+$/g, '');
}
}
function pcnlFireEvent(element,event)
{
if (element.dispatchEvent)
{
// dispatch for chrome, firefox + others + IE 9+
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true); // event type, bubbling, cancelable
return !element.dispatchEvent(evt);
}
else if (document.createEventObject)
{
// dispatch for IE 8-
var evt = document.createEventObject();
return element.fireEvent('on'+event, evt)
}
}
var PostcodeNl_Api = {
/**
* Cache requests to improve multiple identical requests (billing / shipping, etc)
*/
requestCache: {},
/*
* Regular expressions for matching address parts
*/
REGEXP_STREET: '[^0-9].*?|.*?[^0-9]',
REGEXP_HOUSENUMBER: '[0-9]+',
REGEXP_HOUSENUMBER_ADDITION: '[^\\s]+|[^\\s]\\s+[^\\s]{1,4}',
/*
* The 'item' parent element signature in the address form
*/
parentElementType: 'li',
/*
* Keep track of what kind of checkout/address page we are enriching
*/
enrichType: 'Unknown',
/*
* List of supported / recognized checkout extensions.
*/
enrichTypes: {
'Unknown': 0,
'Basic': 1,
'Admin': 2,
'OneStepCheckout.com': 3,
'Apptha One Step Checkout': 4,
'MageStore One Step Checkout': 5,
'GoMage LightCheckout': 6,
'MageWorld One Step Checkout Pro': 7,
'AheadWorks One Step Checkout': 8,
'J2T OneCheckout': 9,
'Aitoc One Step Checkout Manager': 10,
'Magento Templates - OnePage Magento Checkout': 11,
'EcommerceTeam Easy Checkout 2': 12,
'GrafischDirect One Step Checkout': 13,
'FME One Step Checkout': 14,
'IWD Free One Page / Step Checkout v2': 15,
'IWD Free One Page / Step Checkout v3': 16,
'Fire Checkout': 17,
'Quick One Page Checkout (by KAM)': 18,
'MAGExtended MasterCheckout': 19,
'Customer Address Form': 20,
'Lotusbreath One Step Checkout': 21,
'IWD Checkout Suite': 22,
},
enrichHint: null,
/**
* Hide multiple field-rows in forms
*/
hideFields: function (fields)
{
var pcnl = this;
fields.each(function (fieldId)
{
if ($(fieldId) && $(fieldId).up(pcnl.parentElementType))
{
$(fieldId).up(pcnl.parentElementType).addClassName('pcnl-hidden-field')
}
});
},
/**
* Un-hide multiple field-rows in forms
*/
showFields: function (fields)
{
var pcnl = this;
fields.each(function (fieldId)
{
if ($(fieldId) && $(fieldId).up(pcnl.parentElementType))
{
$(fieldId).up(pcnl.parentElementType).removeClassName('pcnl-hidden-field')
}
});
},
/**
* Remove all validation messages
*/
removeValidationMessages: function (prefix)
{
var advice = Validation.getAdvice('invalid-postcode', $(prefix +'postcode_housenumber'));
if (advice)
{
Validation.hideAdvice($(prefix +'postcode_housenumber'), advice, 'invalid-postcode');
$(prefix +'postcode_housenumber').removeClassName('validation-failed');
}
var advice = Validation.getAdvice('invalid-postcode', $(prefix +'postcode_input'));
if (advice)
{
Validation.hideAdvice($(prefix +'postcode_input'), advice, 'invalid-postcode');
$(prefix +'postcode_input').removeClassName('validation-failed');
}
var advice = Validation.getAdvice('address-is-postofficebox', $(prefix +'postcode_input'));
if (advice)
{
Validation.hideAdvice($(prefix +'postcode_input'), advice, 'address-is-postofficebox');
$(prefix +'postcode_input').removeClassName('validation-failed');
}
if ($(prefix +'postcode_housenumber_addition'))
{
var additionAdvice = Validation.getAdvice('invalid-addition', $(prefix +'postcode_housenumber_addition'));
if (additionAdvice)
{
Validation.hideAdvice($(prefix +'postcode_housenumber_addition'), additionAdvice, 'invalid-addition');
$(prefix +'postcode_housenumber_addition').removeClassName('validation-failed');
}
}
},
/**
* Remove housenumber addition selectbox, and any related elements / classes.
*/
removeHousenumberAddition: function (prefix)
{
if ($(prefix +'postcode_housenumber_addition'))
{
Element.remove($(prefix +'postcode_housenumber_addition'));
if ($(prefix +'postcode_housenumber_addition:wrapper'))
{
Element.remove($(prefix +'postcode_housenumber_addition:wrapper'));
}
if ($(prefix + 'postcode_housenumber').up(this.parentElementType))
{
$(prefix + 'postcode_housenumber').up(this.parentElementType).removeClassName('pcnl-with-addition');
}
}
},
/**
* Get HTML format for info. (used in Showcode / Debug)
*/
getFieldListHtml: function (data, className)
{
var toType = function(obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
}
var html = '';
if (toType(data) == 'object' ) {
if (className) {
html = '<dl class="'+ String(className).escapeHTML() +'">';
} else {
html = '<dl>';
}
for (var prop in data)
{
var name = prop.charAt(0).toUpperCase() + prop.slice(1);
if (prop == 'modules') {
html += '<dt>'+ name.escapeHTML() +'</dt><dd>';
for (var moduleName in data[prop]) {
html += String(moduleName +'-'+ data[prop][moduleName].codePool + (data[prop][moduleName].version !== undefined ? '-' + data[prop][moduleName].version : '') + (data[prop][moduleName].active ? '' : ' (inactive)')).escapeHTML() +'<br />';
}
html += '</dd>';
}
else {
html += '<dt>'+ name.escapeHTML() +'</dt><dd>'+ this.getFieldListHtml(data[prop]) +'</dd>';
}
if (prop == 'longitude') {
html += '<dt>See in map</dt><dd><a href="https://www.google.nl/maps/?q=loc:'+ data.latitude +','+ data.longitude +'">Google maps</a></dd>';
}
}
html += '</dl>';
} else {
html = String(data === null ? '- none -' : data).escapeHTML();
}
return html;
},
/**
* Toggle 'readonly' on multiple fields. Sets class, attribute.
*/
setFieldsReadonly: function (fields, readonly)
{
fields.each(function (fieldId)
{
if ($(fieldId))
{
if (readonly)
{
if ($(fieldId).nodeName == 'SELECT')
{
$(fieldId).disabled = true;
}
else
{
$(fieldId).setAttribute('readonly', true);
}
$(fieldId).addClassName('pcnl-readonly');
if ($(fieldId).hasClassName('required-entry'))
{
$(fieldId).removeClassName('required-entry');
$(fieldId).addClassName('pcnl-disabled-required-entry');
}
}
else
{
if ($(fieldId).nodeName == 'SELECT')
{
$(fieldId).disabled = false;
}
else
{
$(fieldId).removeAttribute('readonly');
}
$(fieldId).removeClassName('pcnl-readonly');
if ($(fieldId).hasClassName('pcnl-disabled-required-entry'))
{
$(fieldId).addClassName('required-entry');
$(fieldId).removeClassName('pcnl-disabled-required-entry');
}
}
}
});
},
/**
* Look up the address for a form, validate & enrich target form.
*/
lookupPostcode: function (prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, event)
{
var pcnlapi = this;
if (!$(prefix + 'postcode_housenumber'))
{
return;
}
var postcode = $(prefix + 'postcode_input').getValue();
postcode = postcode.replace(/\s+/, '');
var housenumber_mixed = $(prefix + 'postcode_housenumber').getValue().trim();
// Number, followed by non alphanumberic chars, and then additional number ("123 A", "123-rood", etc)
// or: Number, followed directly by a letter and then alphanumeric/space charcters ("123b3", "123berk 23", etc)
var housenumber_match = housenumber_mixed.match('^('+ this.REGEXP_HOUSENUMBER +')([^0-9a-zA-Z]*('+ this.REGEXP_HOUSENUMBER_ADDITION +'))?\\s*$');
var housenumber_addition_select = $(prefix +'postcode_housenumber_addition') ? $(prefix +'postcode_housenumber_addition').getValue() : null;
var housenumber = housenumber_match ? housenumber_match[1].trim() : housenumber_mixed;
var housenumber_addition = '';
if (!housenumber_match)
housenumber_addition = '';
else if (housenumber_match[3] !== undefined)
housenumber_addition = housenumber_match[3].trim();
if (housenumber_addition == '' && housenumber_addition_select != '__none__' && housenumber_addition_select != '__select__' && housenumber_addition_select != null)
housenumber_addition = housenumber_addition_select;
if ($(prefix + countryFieldId).getValue() != 'NL' || postcode == '' || housenumber_mixed == '')
return;
// Make uppercase to prevent double, but identical, requests
postcode = postcode.toUpperCase();
var et = this.enrichTypes[this.enrichType] ? this.enrichTypes[this.enrichType] : this.enrichHint;
var url = PCNLAPI_CONFIG.baseUrl +'lookup?postcode=' + postcode + '&houseNumber=' + housenumber + '&houseNumberAddition=' + housenumber_addition + '&et=' + encodeURIComponent(et);
if (this.requestCache[url] === undefined)
{
new Ajax.Request(url,
{
method: 'get',
onException: function(transport, e)
{
var json = {
'useManual' : true,
'messageTarget' : 'housenumber',
'message' : Translator.translate('Validation error, please use manual input.')
};
pcnlapi.updatePostcodeLookup(json, housenumber_addition, housenumber_addition_select, prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, event);
},
onComplete: function(transport)
{
var json = transport.responseText.evalJSON();
if (!PCNLAPI_CONFIG.debug) {
pcnlapi.requestCache[url] = json;
}
pcnlapi.updatePostcodeLookup(json, housenumber_addition, housenumber_addition_select, prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, event);
}
});
}
else
{
this.updatePostcodeLookup(this.requestCache[url], housenumber_addition, housenumber_addition_select, prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, event);
}
},
/**
* Update the address fields, given the validated data.
*/
updatePostcodeLookup: function(data, housenumber_addition, housenumber_addition_select, prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, event)
{
if (PCNLAPI_CONFIG.showcase && data.showcaseResponse)
{
if ($(prefix +'showcase'))
$(prefix +'showcase').remove();
var info = this.getFieldListHtml(data.showcaseResponse, 'pcnl-showcase');
if ($(prefix + street1).up(this.parentElementType))
{
if (this.parentElementType == 'li')
{
$(prefix + street1).up(this.parentElementType).insert({before: '<li id="' + prefix +'showcase" class="wide"><div class="input-box"><h4 class="pcnl-showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</h4>'+ info + '</div></li>'});
}
else if (this.parentElementType == 'tr')
{
// We're probably in the admin
$(prefix + street1).up(this.parentElementType).insert({before: '<tr id="' + prefix + 'showcase"><td class="label">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</label></td><td class="value"><h4 class="pcnl-showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</h4>'+ info + '</td></tr>'});
}
else
{
// Assume 'div' elements
$(prefix + street1).up(this.parentElementType).insert({before: '<div id="' + prefix + 'showcase"><h4 class="pcnl-showcase">'+ PCNLAPI_CONFIG.translations.apiShowcase.escapeHTML() +'</h4>'+ info + '</div>'});
}
}
}
if (PCNLAPI_CONFIG.debug)
{
if ($(prefix +'debug'))
$(prefix +'debug').remove();
if (data.debugInfo !== undefined)
{
// Add enrich type
data.debugInfo.enrichType = this.enrichType;
// It could be that we have no debug info, even if it is switched on
var info = this.getFieldListHtml(data.debugInfo, 'pcnl-debug');
if ($(prefix + street1).up(this.parentElementType))
{
if (this.parentElementType == 'li')
{
$(prefix + street1).up(this.parentElementType).insert({before: '<li id="' + prefix +'debug" class="wide"><div class="input-box"><h4 class="pcnl-debug">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</h4>'+ info + '</div></li>'});
}
else if (this.parentElementType == 'tr')
{
// We're probably in the admin
$(prefix + street1).up(this.parentElementType).insert({before: '<tr id="' + prefix + 'debug"><td class="label">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</label></td><td class="value"><h4 class="pcnl-debug">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</h4>'+ info + '</td></tr>'});
}
else
{
// Assume 'div' elements
$(prefix + street1).up(this.parentElementType).insert({before: '<div id="' + prefix +'debug" class="full"><div class="input-box"><h4 class="pcnl-debug">'+ PCNLAPI_CONFIG.translations.apiDebug.escapeHTML() +'</h4>'+ info + '</div></div>'});
}
}
}
}
// Remove any existing error messages
this.removeValidationMessages(prefix);
if (data.postcode !== undefined)
{
// Set data from request on form fields
var postcodeChange = false;
if ($(prefix + postcodeFieldId).getValue() != data.postcode)
postcodeChange = true;
$(prefix + postcodeFieldId).setValue(data.postcode);
if (postcodeChange)
pcnlFireEvent($(prefix + postcodeFieldId), 'change');
$(prefix + 'postcode_input').setValue(data.postcode);
if (PCNLAPI_CONFIG.useStreet2AsHouseNumber && $(prefix + street2))
{
$(prefix + street1).setValue((data.street).trim());
if (PCNLAPI_CONFIG.useStreet3AsHouseNumberAddition && $(prefix + street3))
{
$(prefix + street2).setValue(data.houseNumber);
$(prefix + street3).setValue((data.houseNumberAddition ? data.houseNumberAddition : housenumber_addition).trim());
}
else
{
$(prefix + street2).setValue((data.houseNumber +' '+ (data.houseNumberAddition ? data.houseNumberAddition : housenumber_addition)).trim());
}
}
else
{
$(prefix + street1).setValue((data.street +' '+ data.houseNumber +' '+ (data.houseNumberAddition ? data.houseNumberAddition : housenumber_addition)).trim());
}
$(prefix +'city').setValue(data.city);
if ($(prefix +'region'))
{
$(prefix +'region').setValue(data.province);
}
$(prefix +'postcode_housenumber').setValue(data.houseNumber);
// Update address result text block
if ($(prefix + 'postcode_output'))
{
this.showFields([prefix +'postcode_output']);
$(prefix + 'postcode_output').update((data.street +' '+ data.houseNumber +' '+ (data.houseNumberAddition ? data.houseNumberAddition : housenumber_addition)).trim() + "<br>" + data.postcode + " " + data.city);
}
var hasAdvice = false;
// Handle all housenumber addition possiblities
if (data.houseNumberAddition == null && (housenumber_addition_select == housenumber_addition || (housenumber_addition_select == '__none__' && housenumber_addition == '')))
{
// Selected housenumber addition is not known, and the select dropdown already contains that value
var additionSelect = this.createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, data.houseNumberAdditions, housenumber_addition_select);
// Re-select value if it was selected through the selectbox
if (event && event.element().id == prefix +'postcode_housenumber_addition')
additionSelect.setValue(housenumber_addition_select);
if (additionSelect.getValue() != housenumber_addition_select)
{
newAdvice = Validation.createAdvice('invalid-addition', $(prefix +'postcode_housenumber_addition'), false, (housenumber_addition != '' ? PCNLAPI_CONFIG.translations.houseNumberAdditionUnknown.replace('{addition}', housenumber_addition) : PCNLAPI_CONFIG.translations.houseNumberAdditionRequired));
Validation.showAdvice($(prefix +'postcode_housenumber_addition'), newAdvice, 'invalid-addition');
$(prefix +'postcode_housenumber_addition').removeClassName('validation-passed');
$(prefix +'postcode_housenumber_addition').addClassName('validation-failed');
hasAdvice = true;
}
else
{
$(prefix + 'postcode_housenumber_addition').addClassName('validation-passed');
}
}
else if (data.houseNumberAddition == null)
{
// Selected housenumber addition is not known, and the select dropdown does not contain that value
var additionSelect = this.createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, data.houseNumberAdditions, housenumber_addition);
newAdvice = Validation.createAdvice('invalid-addition', $(prefix +'postcode_housenumber_addition'), false, (housenumber_addition != '' ? PCNLAPI_CONFIG.translations.houseNumberAdditionUnknown.replace('{addition}', housenumber_addition) : PCNLAPI_CONFIG.translations.houseNumberAdditionRequired));
Validation.showAdvice($(prefix +'postcode_housenumber_addition'), newAdvice, 'invalid-addition');
$(prefix +'postcode_housenumber_addition').removeClassName('validation-passed');
$(prefix +'postcode_housenumber_addition').addClassName('validation-failed');
hasAdvice = true;
}
else if (data.houseNumberAdditions.length > 1 || (data.houseNumberAdditions.length == 1 && data.houseNumberAdditions[0] != ''))
{
// Address has multiple housenumber additions
var additionSelect = this.createPostcodeHouseNumberAddition(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4, data.houseNumberAdditions);
additionSelect.setValue(data.houseNumberAddition);
$(prefix + 'postcode_housenumber_addition').addClassName('validation-passed');
}
else
{
// Address has only one valid addition, and it is the 'no addition' option
this.removeHousenumberAddition(prefix);
}
if (data.street == 'Postbus' && PCNLAPI_CONFIG.blockPostOfficeBoxAddresses)
{
newAdvice = Validation.createAdvice('address-is-postofficebox', $(prefix + 'postcode_input'), false, PCNLAPI_CONFIG.translations.postOfficeBoxNotAllowed);
Validation.showAdvice($(prefix + postcodeFieldId), newAdvice, 'address-is-postofficebox');
$(prefix + postcodeFieldId).removeClassName('validation-passed');
$(prefix + postcodeFieldId).addClassName('validation-failed');
hasAdvice = true;
}
if (!hasAdvice)
{
$(prefix + postcodeFieldId).addClassName('validation-passed');
$(prefix + 'postcode_housenumber').addClassName('validation-passed');
}
}
else if (data.message !== undefined)
{
// Address check returned an error
if (typeof data.useManual !== 'undefined' && data.useManual === true) {
$(prefix + 'postcode_input_checkbox').click();
}
var target = (data.messageTarget == 'postcode' ? 'postcode_input' : 'postcode_housenumber');
newAdvice = Validation.createAdvice('invalid-postcode', $(prefix + target), false, data.message);
Validation.showAdvice($(prefix + target), newAdvice, 'invalid-postcode');
$(prefix + target).removeClassName('validation-passed');
$(prefix + target).addClassName('validation-failed');
this.removeHousenumberAddition(prefix);
}
else
{
// Address check did not return an error or a postcode result (something else wrong)
var target = (data.messageTarget == 'postcode' ? 'postcode_input' : 'postcode_housenumber');
newAdvice = Validation.createAdvice('invalid-postcode', $(prefix + target), false, '');
Validation.showAdvice($(prefix + target), newAdvice, 'invalid-postcode');
$(prefix + target).removeClassName('validation-passed');
$(prefix + target).addClassName('validation-failed');
this.removeHousenumberAddition(prefix);
}
// Add support for syncing Billing & Shipping
if (prefix == 'billing:' && $('shipping:' + postcodeFieldId)) {
// 'shipping' is a global object created on most checkout pages
if (typeof shipping != 'undefined') {
if ($('shipping:same_as_billing') && $('shipping:same_as_billing').checked) {
shipping.syncWithBilling();
}
}
this.lookupPostcode('shipping:', postcodeFieldId, countryFieldId, street1, street2, street3, street4);
}
},
/**
* Toggle country selection for a form. Only when the Netherlands is selected, add address enrichment.
*/
toggleCountryPostcode: function (prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4)
{
var pcnlapi = this;
// If we have no country set, change to NL (or forms may get confusing when 'reset')
if ($(prefix + countryFieldId).getValue() == '')
{
$(prefix + countryFieldId).setValue('NL');
pcnlFireEvent($(prefix + countryFieldId), 'change');
}
if ($(prefix + countryFieldId).getValue() == 'NL')
{
// The Netherlands is selected - add our own validated inputs.
this.enrichHint = $(document.body).className.trim().replace(' ', ',');
if (!$(prefix +'postcode_input:wrapper'))
{
if ($$('table.form-list').length > 0 && $(prefix + postcodeFieldId).parentNode.tagName == 'TD')
{
// We're probably in the admin, slightly different logic than the frontend checkout forms
this.enrichType = 'Admin';
this.parentElementType = 'tr';
$(prefix + street1).up('tr').insert({before: '<tr id="' + prefix + 'postcode_input:wrapper"><td class="label"><label for="' + prefix + 'postcode_input">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +' <span class="required">*</span></label></td><td class="value"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></td></tr><tr id="' + prefix + 'postcode_housenumber:wrapper"><td class="label"><label for="' + prefix + 'postcode_housenumber">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <span class="required">*</span></label></td><td class="value"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></td></tr>'});
$(prefix + street1).up('tr').insert({before: '<tr id="' + prefix + 'postcode_input:checkbox"><td class="label"><label for="' + prefix + 'postcode_input_checkbox"> '+ PCNLAPI_CONFIG.translations.manualInputLabel +' <span class="required">*</span></label></td><td class="value"><input type="checkbox" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox" /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></td></tr>'});
$(prefix +'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
else if ($(document.body).hasClassName('onestepcheckout-index-index') && $('onestepcheckout-form'))
{
// Support for OneStepCheckout.com extension
this.enrichType = 'OneStepCheckout.com';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:info" class="clearfix"><div class="input-box"><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></li>'});
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:wrapper" class="clearfix"><div class="field input-postcode"><label for="' + prefix + 'postcode_input">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em class="required">*</em></label><div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></div><div class="field input-postcode pcnl-input-housenumber"><label for="' + prefix + 'postcode_housenumber">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em class="required">*</em></label><div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></div></li>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:checkbox" class="clearfix"><div class="field"><div class="input-box"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox" /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></div></div></li>'});
$(prefix +'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field"><div class="input-box"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
}
else if ($(document.body).hasClassName('onestepcheckout-index-index') && $('co-form'))
{
// Support for Apptha One Step Checkout extension
this.enrichType = 'Apptha One Step Checkout';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('li').insert({before:
'<li id="' + prefix + 'postcode_input:info">'+
'<div class="input-box">'+
'<label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label>'+
'<div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div>'+
'</div>'+
'</li>'
});
}
$(prefix + street1).up('li').insert({before:
'<li id="' + prefix + 'postcode_input:wrapper">'+
'<div class="pcnl-apptha-fields">'+
'<div class="field">'+
'<label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em>*</em></label>'+
'<div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div>'+
'</div>'+
'<div class="field input-postcode pcnl-input-housenumber">'+
'<label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em>*</em></label>'+
'<div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div>'+
'</div>'+
'</div>'+
'</li>'
});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('li').insert({before:
'<li id="' + prefix + 'postcode_input:checkbox" class="pcnl-apptha-checkbox">'+
'<div class="field">'+
'<div class="input-box">'+
'<input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox" />'+
'<label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label>'+
'</div>'+
'</div>'+
'</li>'
});
$(prefix +'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('li').insert({before:
'<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field">'+
'<div class="input-box">'+
'<label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label>'+
'<div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div>'+
'</div>'+
'</li>'
});
}
else if ($(document.body).hasClassName('onestepquickcheckout_index_index') || ($(document.body).hasClassName('onestepcheckout-index-index') && $('one-step-checkout-form')))
{
// Support for MageStore One Step Checkout extension
this.enrichType = 'MageStore One Step Checkout';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:info" class="wide"><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></li>'});
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:wrapper"><div class="two-fields input-postcode"><label for="' + prefix + 'postcode_input">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +' <span class="required">*</span></label><br>'+
'<input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div>'+
'<div class="two-fields input-postcode pcnl-input-housenumber"><label for="' + prefix + 'postcode_housenumber">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <span class="required">*</span></label><br><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></li>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:checkbox" class="clearfix"><div class="input-box"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox" /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></div></li>'});
$(prefix +'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field"><div class="input-box"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
}
else if ($(document.body).hasClassName('gomage-checkout-onepage-index'))
{
// Support for GoMage LightCheckout extension
this.enrichType = 'GoMage LightCheckout';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:info" class="pcnl-info"><div class="input-box"><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></li>'});
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:wrapper" class="fields"><div class="field input-postcode"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em class="required">*</em></label><div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></div><div class="field input-postcode pcnl-input-housenumber"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em class="required">*</em></label><div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></div></li>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:checkbox" class="pcnl-manual-checkbox"><div class="field"><div class="input-box"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox " /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></div></div></li>'});
$(prefix + 'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field"><div class="input-box"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
}
else if ($(document.body).hasClassName('checkout-onepage-index') && $('mw-osc-column-container'))
{
// Support for MageWorld One Step Checkout Pro
this.enrichType = 'MageWorld One Step Checkout Pro';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('li.fields').insert({before:
'<li id="' + prefix + 'postcode_input:info">'+
'<div class="input-box">'+
'<label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label>'+
'<div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div>'+
'</div>'+
'</li>'
});
}
$(prefix + street1).up('li.fields').insert({before:
'<li id="' + prefix + 'postcode_input:wrapper">'+
'<div>'+
'<div class="field">'+
'<label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em>*</em></label>'+
'<div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div>'+
'</div>'+
'<div class="field input-postcode pcnl-input-housenumber">'+
'<label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em>*</em></label>'+
'<div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div>'+
'</div>'+
'</div>'+
'</li>'
});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('li.fields').insert({before:
'<li id="' + prefix + 'postcode_input:checkbox">'+
'<div>'+
'<div class="input-box">'+
'<input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox" />'+
'<label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label>'+
'</div>'+
'</div>'+
'</li>'
});
$(prefix +'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('li.fields').insert({before:
'<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field">'+
'<div class="input-box">'+
'<label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label>'+
'<div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div>'+
'</div>'+
'</li>'
});
}
else if ($(document.body).hasClassName('aw-onestepcheckout-index-index'))
{
// Support for AheadWorks One Step Checkout
this.enrichType = 'AheadWorks One Step Checkout';
this.parentElementType = 'div.aw-onestepcheckout-general-form-field';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('div.aw-onestepcheckout-general-form-field').insert({before:
'<div class="aw-onestepcheckout-general-form-field aw-onestepcheckout-general-form-field-wide" id="' + prefix + 'postcode_input:info">'+
'<label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label>'+
'<div class="input-box">'+
'<div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div>'+
'</div>'+
'<div style="clear:both;"></div>'+
'</div>'
});
}
$(prefix + street1).up('div.aw-onestepcheckout-general-form-field').insert({before:
'<div id="' + prefix + 'postcode_input:wrapper">'+
'<div class="aw-onestepcheckout-general-form-field aw-onestepcheckout-general-form-field-left">'+
'<label for="' + prefix + 'postcode_input" class="required"><em>*</em>'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'</label>'+
'<div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div>'+
'<div style="clear:both;"></div>'+
'</div>'+
'<div class="aw-onestepcheckout-general-form-field aw-onestepcheckout-general-form-field-right input-postcode pcnl-input-housenumber">'+
'<label for="' + prefix + 'postcode_housenumber" class="required"><em>*</em>'+ PCNLAPI_CONFIG.translations.houseNumberLabel +'</label>'+
'<div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div>'+
'<div style="clear:both;"></div>'+
'</div>'+
'</div>'
});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('div.aw-onestepcheckout-general-form-field').insert({before:
'<div id="' + prefix + 'postcode_input:checkbox">'+
'<div class="aw-onestepcheckout-general-form-field">'+
'<div class="control">'+
'<input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox" />'+
'<label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label>'+
'</div>'+
'</div>'+
'<div style="clear:both;"></div>'+
'</div>'
});
$(prefix +'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('div.aw-onestepcheckout-general-form-field').insert({before:
'<div class="aw-onestepcheckout-general-form-field aw-onestepcheckout-general-form-field-wide" id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field">'+
'<div class="input-box">'+
'<label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label>'+
'<div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div>'+
'</div>'+
'</div>'
});
}
else if ($(document.body).hasClassName('checkout-onepage-index') && $('j2t-onecheckout-main'))
{
// Support for J2T OneCheckout
this.enrichType = 'J2T OneCheckout';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:info" class="pcnl-info"><div><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></li>'});
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:wrapper" class="fields"><div class="field input-postcode"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em class="required">*</em></label><div class="input-box"><div class="field-wrapper"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></div></div><div class="field input-postcode pcnl-input-housenumber"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em class="required">*</em></label><div class="input-box"><div class="field-wrapper"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></div></div></li>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:checkbox" class="control pcnl-manual-checkbox"><div class="fields"><div class="input-box"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox " /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></div></div></li>'});
$(prefix + 'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field"><div><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
}
else if ($(document.body).hasClassName('aitcheckout-checkout-index'))
{
// Support for Aitoc One Step Checkout Manager
this.enrichType = 'Aitoc One Step Checkout Manager';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:info" class="pcnl-info"><div><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></li>'});
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:wrapper" class="fields"><div class="field compact input-postcode"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em class="required">*</em></label><div class="input-box"><div class="field-wrapper"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></div></div><div class="field compact input-postcode pcnl-input-housenumber"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em class="required">*</em></label><div class="input-box"><div class="field-wrapper"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></div></div></li>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:checkbox" class="control pcnl-manual-checkbox"><div class="fields"><div class="input-box"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox " /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></div></div></li>'});
$(prefix + 'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field"><div><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
}
else if ($(document.body).hasClassName('checkout-onepage-index') && $(document.body).hasClassName('layout-3columns'))
{
// Support for Magento Templates - OnePage Magento Checkout
this.enrichType = 'Magento Templates - OnePage Magento Checkout';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:info" class="pcnl-info"><div><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></li>'});
}
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:wrapper" class="fields"><div class="field input-postcode"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em class="required">*</em></label><div class="input-box"><div class="field-wrapper"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></div></div><div class="field input-postcode pcnl-input-housenumber"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em class="required">*</em></label><div class="input-box"><div class="field-wrapper"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></div></div></li>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:checkbox" class="control pcnl-manual-checkbox"><div class="fields"><div class="input-box"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox " /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></div></div></li>'});
$(prefix + 'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field"><div><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
}
else if ($(document.body).hasClassName('checkout-onepage-index') && $('easycheckout-form-wrap'))
{
// Support for EcommerceTeam Easy Checkout 2
this.enrichType = 'EcommerceTeam Easy Checkout 2';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:info" class="pcnl-info"><div><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></li>'});
}
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:wrapper" class="fields"><div class="field input-postcode"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em class="required">*</em></label><div class="input-box"><div class="field-wrapper"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></div></div><div class="field input-postcode pcnl-input-housenumber"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em class="required">*</em></label><div class="input-box"><div class="field-wrapper"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></div></div></li>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:checkbox" class="pcnl-manual-checkbox"><div class="field"><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox " /></div></li>'});
$(prefix + 'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + 'country_id').up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field"><div><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
}
else if ($(document.body).hasClassName('checkout-onestep-index') && $('easycheckout-login-form'))
{
// GrafischDirect One Step Checkout
this.enrichType = 'GrafischDirect One Step Checkout';
this.parentElementType = 'div.line';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('div.line').insert({before: '<div id="' + prefix + 'postcode_input:info" class="pcnl-info line"><div class="input-box"><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></div>'});
}
$(prefix + street1).up('div.line').insert({before: '<div id="' + prefix + 'postcode_input:wrapper" class="line"><div class="input-postcode left"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<span class="required">*</span></label><div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></div><div class="input-postcode pcnl-input-housenumber right"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <span class="required">*</span></label><div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></div></div>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('div.line').insert({before: '<div id="' + prefix + 'postcode_input:checkbox" class="pcnl-manual-checkbox line"><div class="full"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox " /><label for="' + prefix + 'postcode_input_checkbox"><label for="' + prefix + 'postcode_input:checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></div></div>'});
$(prefix + 'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('div.line').insert({before: '<div id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field line"><div class="input-box"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></div>'});
}
else if ($(document.body).hasClassName('checkout-onestep-index'))
{
// FME One Step Checkout
this.enrichType = 'FME One Step Checkout';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:info" class="pcnl-info d_3"><div class="input-box"><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></li>'});
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:wrapper" class="d_2"><div class="input-postcode d_1"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em class="required">*</em></label><div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></div><div class="input-postcode pcnl-input-housenumber d_4"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em class="required">*</em></label><div class="input-box"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></div></li>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:checkbox" class="pcnl-manual-checkbox d_3"><div><div class="input-box"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox " /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></div></div></li>'});
$(prefix + 'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="pcnl-hidden-field d_3"><div class="input-box"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
}
else if ($(document.body).hasClassName('onepagecheckout-index-index'))
{
// IWD Free One Page / Step Checkout v2
this.enrichType = 'IWD Free One Page / Step Checkout v2';
this.parentElementType = 'div.full, div.two_fields, ul.pcnl-manual-checkbox';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('div.full').insert({before: '<div id="' + prefix + 'postcode_input:info" class="full"><div><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></div>'});
}
$(prefix + street1).up('div.full').insert({before: '<div id="' + prefix + 'postcode_input:wrapper" class="two_fields"><div class="input-postcode short"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'</label> <sup>*</sup><div class="data_area"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input" value="" class="t1 required-entry" /></div></div>' +
'<div class="input-postcode pcnl-input-housenumber short"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +'</label> <sup>*</sup><div><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="billing[postcode_housenumber]" id="' + prefix + 'postcode_housenumber" value="" class="t1 pcnl-input-text-half required-entry" /></div></div></div>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('div.full').insert({before: '<ul id="' + prefix + 'postcode_input:checkbox" class="pcnl-manual-checkbox"><li class="options"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox" /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></li></ul>'});
$(prefix + 'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('div.full').insert({before: '<div id="' + prefix + 'postcode_input:output" class="full pcnl-hidden-field"><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div class="data_area"><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></div>'});
// Relocate telephone field, if it exists
if ($(prefix + 'telephone'))
{
var clone = $(prefix + 'telephone').up('div.short').clone(true);
$(prefix + 'telephone').up('div.short').remove();
// Move to after country selector
$(prefix + countryFieldId).up('div.full').insert({after: '<div class="two_fields" id="'+prefix + 'telephone-moved"></div><div class="clr"></div>'});
$(prefix + 'telephone-moved').insert(clone);
}
}
else if ($(document.body).hasClassName('opc-index-index'))
{
// IWD Free One Page / Step Checkout v3
this.enrichType = 'IWD Free One Page / Step Checkout v3';
if (!$(prefix +'postcode_input:info'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:info" class="wide pcnl-info"><div><label class="pcnl-info-label">'+ PCNLAPI_CONFIG.translations.infoLabel +'</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">'+ PCNLAPI_CONFIG.translations.infoText +'</div></div></li>'});
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:wrapper" class="fields"><div class="field input-postcode"><label for="' + prefix + 'postcode_input" class="required">'+ PCNLAPI_CONFIG.translations.postcodeInputLabel +'<em class="required">*</em></label><div class="input-box"><div class="field-wrapper"><input type="text" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" name="' + prefix + 'postcode_input" id="' + prefix + 'postcode_input" value="" class="input-text required-entry" /></div></div></div><div class="field input-postcode pcnl-input-housenumber"><label for="' + prefix + 'postcode_housenumber" class="required">'+ PCNLAPI_CONFIG.translations.houseNumberLabel +' <em class="required">*</em></label><div class="input-box"><div class="field-wrapper"><input type="text" title="'+ PCNLAPI_CONFIG.translations.houseNumberTitle +'" name="' + prefix + 'postcode_housenumber" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry" /></div></div></div></li>'});
if (!$(prefix +'postcode_input:checkbox'))
{
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:checkbox" class="wide control pcnl-manual-checkbox"><div class="fields"><div class="input-box"><input type="checkbox" title="'+ PCNLAPI_CONFIG.translations.postcodeInputTitle +'" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox " /><label for="' + prefix + 'postcode_input_checkbox">'+ PCNLAPI_CONFIG.translations.manualInputText +'</label></div></div></li>'});
$(prefix + 'postcode_input_checkbox').observe('click', function () { pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4); });
}
$(prefix + street1).up('li').insert({before: '<li id="' + prefix + 'postcode_input:output" class="wide pcnl-hidden-field"><div><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></li>'});
}
else if ($(document.body).hasClassName('iwd-opc-index-index'))
{
// IWD Checkout Suite
this.enrichType = 'IWD Checkout Suite';
type = prefix.replace(":", "");
street_lines = $$('input[name="' + type + '[street][]"');
var i = 1;
street_lines.each(function (element) {
$(element).writeAttribute("id", type + ":street" + i);
i++;
});
$$('input[name="' + type + '[city]"')[0].writeAttribute("id", type + ":city");
$$('input[name="' + type + '[postcode]"')[0].writeAttribute("id", type + ":postcode");
if (!$(prefix + 'postcode_input:info'))
{
$(prefix + street1).up('div').insert({before: '<div id="' + prefix + 'postcode_input:info" class="wide pcnl-info"><div><label class="pcnl-info-label">' + PCNLAPI_CONFIG.translations.infoLabel + '</label><div class="pcnl-info-text" id="' + prefix + 'postcode_input:info-text">' + PCNLAPI_CONFIG.translations.infoText + '</div></div></div>'});
}
$(prefix + street1).up('div').insert({before: '<div id="' + prefix + 'postcode_input:wrapper" class="fields "><div class="field input-postcode pcnl-wrapper-half"><label for="' + prefix + 'postcode_input" class="required">' + PCNLAPI_CONFIG.translations.postcodeInputLabel + '<em class="required">*</em></label><div class="iwd_opc_universal_wrapper"><input type="text" title="' + PCNLAPI_CONFIG.translations.postcodeInputTitle + '" name="' + prefix + 'postcode_input" id="' + prefix + 'postcode_input" value="" class="input-text required-entry iwd_opc_field iwd_opc_input" /></div></div><div class="field input-postcode pcnl-input-housenumber"><label for="' + prefix + 'postcode_housenumber" class="required">' + PCNLAPI_CONFIG.translations.houseNumberLabel + ' <em class="required">*</em></label><div class="input-box"><div class="iwd_opc_universal_wrapper"><input type="text" title="' + PCNLAPI_CONFIG.translations.houseNumberTitle + '" name="' + prefix + 'postcode_housenumber" id="' + prefix + 'postcode_housenumber" value="" class="input-text pcnl-input-text-half required-entry iwd_opc_field iwd_opc_input" /></div></div></div></div>'});
if (!$(prefix + 'postcode_input:checkbox'))
{
$(prefix + street1).up('div').insert({before: '<div id="' + prefix + 'postcode_input:checkbox" class="wide control pcnl-manual-checkbox"><div class="fields"><input type="checkbox" title="' + PCNLAPI_CONFIG.translations.postcodeInputTitle + '" id="' + prefix + 'postcode_input_checkbox" value="" class="checkbox " /><label for="' + prefix + 'postcode_input_checkbox">' + PCNLAPI_CONFIG.translations.manualInputText + '</label></div></div>'});
$(prefix + 'postcode_input_checkbox').observe('click', function () {
pcnlapi.toggleCountryPostcode(prefix, postcodeFieldId, countryFieldId, street1, street2, street3, street4);
});
}
$(prefix + street1).up('div').insert({before: '<div id="' + prefix + 'postcode_input:output" class="wide pcnl-hidden-field"><div><label>'+ PCNLAPI_CONFIG.translations.outputLabel +'</label><div id="' + prefix + 'postcode_output" class="pcnl-address-text"></div></div></div>'});
}
else
{
// Support for regular Magento 'one page' checkout
// + Fire Checkout
// + Quick One Page Checkout (by KAM)
// + MAGExtended MasterCheckout
// + Lotusbreath One Step Checkout
if ($(document.body).hasClassName('firecheckout-index-index'))
this.enrichType = 'Fire Checkout';
else if ($(document.body).hasClassName('checkout-onepage-index') && $$('.qocadvanced-threecolumns').length > 0)
this.enrichType = 'Quick One Page Checkout (by KAM)';
else if ($(document.body).hasClassName('mastercheckout-index-index'))
this.enrichType = 'MAGExtended MasterCheckout';
else if ($(document.body).hasClassName('lotusbreath-onestepcheckout-index-index'))
this.enrichType = 'Lotusbreath One Step Checkout';