Subversion Repositories wpShopGermany4

Rev

Blame | Last modification | View Log | RSS feed

/**
 * 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);
                                                
                        }
                    }

                }
            });
                
        }

}