summaryrefslogtreecommitdiff
path: root/views/mods/mod_addressvalidation/addressvalidation.js
blob: b74aa5b5b3fb730ecf5acbfa66715bc61d8a495e (plain)
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
/**
 * Globale Funktionen zur Adressvalidation
 */

function validateAddressBind(data) {
	jQuery(data.PLZ).on("input", function () {
		validateAddress(data);
	});
	jQuery(data.Ort).on("input", function () {
		validateAddress(data);
	});
	jQuery(data.Strasse).on("input", function () {
		validateAddress(data);
	});
	jQuery(data.Land).on("input", function () {
		validateAddress(data);
	});
}

// Adress-Validation
function validateAddress(data) {
	var
		plz,
		ort,
		strasse,
		astr1,
		land = 'de',
		rw;
	plz = jQuery(data.PLZ).val();
	ort = jQuery(data.Ort).val();
	strasse = jQuery(data.Strasse).val();
	nr = jQuery(data.Nr).val();
	if (nr !== undefined) {
		strasse = strasse + ' ' + nr;
	}
	land = jQuery(data.Land + ' option:selected').val();
	land = jQuery(data.Land + ' option:selected').attr('data-land');

	astr1 = localStorage.getItem(data.StorageKey);
	if ((plz.length > 3) && (ort.length > 3) && (strasse.length > 3) &&
		(astr1 != (strasse + plz + ort + land))) 
	{

		astr1 = strasse + plz + ort + land;
		localStorage.setItem(data.StorageKey, astr1);
	    jQuery.ajax({
	        url: 'http://api.address-validator.net/api/verify',
	        type: 'POST',
	        data: { StreetAddress: strasse,
	                City: ort,
	                PostalCode: plz,
	                //State: State,
	                CountryCode: land,
	                //Locale: land,
	                APIKey: data.Key},
	        dataType: 'json',
	        success: function (json) {
	            // check API result
	            if (typeof(json.status) != "undefined") {
	                status = json.status;
	                formattedaddress = json.formattedaddress;
	                if (json.status === 'VALID') {


	                } else if ((json.status === 'INVALID') || (json.status === 'SUSPECT')) {

	                	alert(data.MsgTeil1 + '-Validation fehlerhaft. Bitte Straße, Hausnummer, PLZ, Ort und Land überprüfen.');
		                
	                } else {

						alert('Adress-Validation Serverproblem: ' + json.status);
						
	                }
	            }

	        }
	    });
		
	}

}