Subversion Repositories wpShopGermany4

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5873 hartmut 1
/**
2
 * Globale Funktionen zur Adressvalidation
3
 */
4
 
5
function validateAddressBind(data) {
6
	jQuery(data.PLZ).on("input", function () {
7
		validateAddress(data);
8
	});
9
	jQuery(data.Ort).on("input", function () {
10
		validateAddress(data);
11
	});
12
	jQuery(data.Strasse).on("input", function () {
13
		validateAddress(data);
14
	});
15
	jQuery(data.Land).on("input", function () {
16
		validateAddress(data);
17
	});
18
}
19
 
20
// Adress-Validation
21
function validateAddress(data) {
22
	var
23
		plz,
24
		ort,
25
		strasse,
26
		astr1,
27
		land = 'de',
28
		rw;
29
	plz = jQuery(data.PLZ).val();
30
	ort = jQuery(data.Ort).val();
31
	strasse = jQuery(data.Strasse).val();
32
	nr = jQuery(data.Nr).val();
33
	if (nr !== undefined) {
34
		strasse = strasse + ' ' + nr;
35
	}
36
	land = jQuery(data.Land + ' option:selected').val();
37
	land = jQuery(data.Land + ' option:selected').attr('data-land');
38
 
39
	astr1 = localStorage.getItem(data.StorageKey);
40
	if ((plz.length > 3) && (ort.length > 3) && (strasse.length > 3) &&
41
		(astr1 != (strasse + plz + ort + land)))
42
	{
43
 
44
		astr1 = strasse + plz + ort + land;
45
		localStorage.setItem(data.StorageKey, astr1);
46
	    jQuery.ajax({
47
	        url: 'http://api.address-validator.net/api/verify',
48
	        type: 'POST',
49
	        data: { StreetAddress: strasse,
50
	                City: ort,
51
	                PostalCode: plz,
52
	                //State: State,
53
	                CountryCode: land,
54
	                //Locale: land,
55
	                APIKey: data.Key},
56
	        dataType: 'json',
57
	        success: function (json) {
58
	            // check API result
59
	            if (typeof(json.status) != "undefined") {
60
	                status = json.status;
61
	                formattedaddress = json.formattedaddress;
62
	                if (json.status === 'VALID') {
63
 
64
 
65
	                } else if ((json.status === 'INVALID') || (json.status === 'SUSPECT')) {
66
 
67
	                	alert(data.MsgTeil1 + '-Validation fehlerhaft. Bitte Straße, Hausnummer, PLZ, Ort und Land überprüfen.');
68
 
69
	                } else {
70
 
71
						alert('Adress-Validation Serverproblem: ' + json.status);
72
 
73
	                }
74
	            }
75
 
76
	        }
77
	    });
78
 
79
	}
80
 
81
}
82