var CONTACT_ADDRESS_1 = 10;
var CONTACT_ADDRESS_2 = 11;
var CONTACT_ADDRESS_3 = 12;
var ACCOUNT_ADDRESS_1 = 20;
var ACCOUNT_ADDRESS_2 = 21;
var ACCOUNT_ADDRESS_3 = 22;
var ORGANISATION_NAME = “CRMORGANISATION”;
var SERVER_URL = “http://crm.dev.intra/”;
// —————————————–
// Validate Address with webservices.nl
// —————————————–
function AddressWebservice(i_Land, i_Postcode, i_Huisnummer, i_Toevoeging, i_Straat, i_Plaats, FORM_ADRES) {
/*
Examples for calling the webservice
https://ws1.webservices.nl/rpc/get-simplexml/UTF-8/addressReeksFullParameterSearch/WebService_User/****************/////93//2991/KK//
https://ws1.webservices.nl/rpc/get-simplexml/UTF-8/internationalAddressSearchV2/WebService_User/***********************///unter%20den%20eichen/1//wiesbaden///de//
*/
// Pre-checks
this._debug = false;
if (this._debug) {
debugger;
}
// For dutch addrress postocde and huisnummer is required.
// For international adresses al least 3 out of 4, when postcode is not filled
if (i_Land == ‘NETHERLANDS’ || _IsNull(i_Land)) {
if (_IsNull(i_Postcode) || _IsNull(i_Huisnummer)) { return true; }
}
else {
if ((_IsNull(i_Postcode)) && (_IsNull(i_Straat))) {
return true; }
else {
if ((_IsNull(i_Huisnummer)) && (_IsNull(i_Plaats))) {
return true;
}
}
}
// Set the credentials to successfully logon to the webservice
this._auth_username = ‘Webservice_User’;
this._auth_password = ‘*********************’;
/*
Interface for addressReeksFullParameterSearch method
*/
this._N6L_province = ”; // string
this._N6L_district = ”; // string
this._N6L_city = ”; //i_Plaats; // string
this._N6L_street = ”; //i_Straat; // string
this._N6L_houseNo = i_Huisnummer // int
this._N6L_houseNoAddition = i_Toevoeging; // string
this._N6L_nbcode = Left(i_Postcode.toUpperCase(),4); // string
this._N6L_lettercombination = Right(i_Postcode.toUpperCase(), 2); // string
this._N6L_addresstype = ”; // string
this._N6L_page = ”; // int
/*
Interface for the internationalAddressSearchV2 method
*/
this._I11L_organization = ”; // string
this._I11L_building = ”; // string
this._I11L_street = i_Straat; // string
this._I11L_housenr = i_Huisnummer + i_Toevoeging; // string
this._I11L_pobox = ”; // string
this._I11L_locality = i_Plaats; // string
this._I11L_postcode = i_Postcode.toUpperCase(); // string
this._I11L_province = ”; // string
this._I11L_country = i_Land // string
this._I11L_language = ‘NL’; // string
this._I11L_country_format = ‘iso_2’ // string
var _baseurl = ‘https://ws1.webservices.nl/rpc/get-simplexml/UTF-8’;
var _webmethod_international = ‘internationalAddressSearchV2’;
var _webmethod_national = ‘addressReeksFullParameterSearch’;
var _webservicecall = ”;
this.items = new Array();
// Check address for the Netherlands
if (i_Land == ‘NETHERLANDS’ || _IsNull(i_Land)) {
_webservicecall = _baseurl + ‘/’ + _webmethod_national + ‘/’ + this._auth_username + ‘/’ + this._auth_password + ‘/’ +
this._N6L_province + ‘/’ + this._N6L_district + ‘/’ + this._N6L_city + ‘/’ + this._N6L_street + ‘/’ + this._N6L_houseNo + ‘/’ +
this._N6L_houseNoAddition + ‘/’ + this._N6L_nbcode + ‘/’ + this._N6L_lettercombination + ‘/’ + this._N6L_addresstype + ‘/’ + this._N6L_page;
}
else {
_webservicecall = _baseurl + ‘/’ + _webmethod_international + ‘/’ + this._auth_username + ‘/’ + this._auth_password + ‘/’ +
this._I11L_organization + ‘/’ + this._I11L_building + ‘/’ + this._I11L_street + ‘/’ + this._I11L_housenr + ‘/’ +
this._I11L_pobox + ‘/’ + this._I11L_locality + ‘/’ + this._I11L_postcode + ‘/’ + this._I11L_province + ‘/’ +
this._I11L_country + ‘/’ + this._I11L_language + ‘/’ + this._I11L_country_format;
}
var xmlhttp = GetXmlHttp();
if (xmlhttp) {
xmlhttp.open(“POST”, _webservicecall, true);
xmlhttp.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);
try
{
xmlhttp.send(_webservicecall);
}
catch(ex)
{
alert(ex);
//succesFullTransformation = false;
}
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState==4 && xmlhttp.responseXML)
{
var response = xmlhttp.responseXML;
//var errorCode = response.documentElement.selectSingleNode(“ErrorCode”);
//var errorMessage = response.documentElement.selectSingleNode(“ErrorMessage”);
if (this._debug) {
debugger;
}
if (response == null || response.documentElement == null) {
var _msg = “Fout bij het ophalen van de postcde.\nControleer of de volgende combinatie een juist adres kan opleveren: \n”;
_msg += ((_IsNull(i_Land))?””:”Land: ” + i_Land + “,\n”);
_msg += ((_IsNull(i_Postcode))?””:”Postcode: ” + i_Postcode + “,\n”);
_msg += ((_IsNull(i_Huisnummer))?””:”Huisnummer: ” + i_Huisnummer + “,\n”);
_msg += ((_IsNull(i_Toevoeging))?””:”Toevoeging: ” + i_Toevoeging + “,\n”);
_msg += ((_IsNull(i_Straat))?””:”Straat: ” + i_Straat + “,\n”);
_msg += ((_IsNull(i_Plaats))?””:”Plaats: ” + i_Plaats);
alert(_msg);
return null;
}
else {
if (i_Land == ‘NETHERLANDS’ || _IsNull(i_Land)) {
this.items = NationalAddresObject(response); }
else {
this.items = InternationalAddresObject(response); }
}
SetAddressFields(FORM_ADRES, this.items);
}
}
}
}
function InternationalAddresObject(xmlResponse) {
//alert(‘Under Construction’);
var _resultcount = xmlResponse.documentElement.selectSingleNode(“/response/result”).childNodes.length;
this.items = new Array();
// adresregel 1, huisnummer, toevoeging, adresregel 2, adresregel 3, plaats, postcode, provincie, land
switch(_resultcount)
{
case 0 :
alert(‘Ongeldig huisnummer en postcode combinatie voor een buitenlands adres. Voer een geldig huisnummer en postcode combinatie in.’ );
break;
case 1 :
this.items[0] = xmlResponse.documentElement.selectSingleNode(“/response/result/entry/address/street”).text;
this.items[1] = xmlResponse.documentElement.selectSingleNode(“/response/result/entry/address/housenr”).text;
this.items[2] = ”;
this.items[3] = ”;
this.items[4] = xmlResponse.documentElement.selectSingleNode(“/response/result/entry/address/province”).text;
this.items[5] = xmlResponse.documentElement.selectSingleNode(“/response/result/entry/address/locality”).text;
this.items[6] = xmlResponse.documentElement.selectSingleNode(“/response/result/entry/address/postcode”).text;
this.items[7] = xmlResponse.documentElement.selectSingleNode(“/response/result/entry/address/province”).text;
this.items[8] = xmlResponse.documentElement.selectSingleNode(“/response/result/entry/address/country”).text;
break;
default :
//if (_resultcount == 20) {
//alert(‘Er zijn 20 adressen of meer gevonden voor deze dit huisnummer en postcode combinatie.’);
var arrAddresses = new Array();
var _results = xmlResponse.selectNodes(‘/response/result/entry/address’);
for (i=0; i<_resultcount; i++)
{
arrAddresses[i] = _results[i].getElementsByTagName(‘street’)[0].text + ” ” +
_results[i].getElementsByTagName(‘housenr’)[0].text + ” ” +
_results[i].getElementsByTagName(‘countryspecific_locality’)[0].text + ” (” +
_results[i].getElementsByTagName(‘province’)[0].text + “) ” +
_results[i].getElementsByTagName(‘country’)[0].text
}
var props = ‘dialogHeight:400px;dialogWidth:730px;center:yes;resizable:no;status:no;scroll:no’;
retval = null;
retval = window.showModalDialog(‘/_static/_common/scripts/qnh/addresslist.html’, arrAddresses, props);
if (this._debug) {
debugger;
}
if (retval != null) {
this.items[0] = xmlResponse.getElementsByTagName(‘result’)(0).getElementsByTagName(‘entry’)(retval).getElementsByTagName(‘address’)(0).getElementsByTagName(‘street’)(0).text
this.items[1] = xmlResponse.getElementsByTagName(‘result’)(0).getElementsByTagName(‘entry’)(retval).getElementsByTagName(‘address’)(0).getElementsByTagName(‘housenr’)(0).text
this.items[2] = ”;
this.items[3] = xmlResponse.getElementsByTagName(‘result’)(0).getElementsByTagName(‘entry’)(retval).getElementsByTagName(‘address’)(0).getElementsByTagName(‘province’)(0).text;
this.items[4] = ”;
this.items[5] = xmlResponse.getElementsByTagName(‘result’)(0).getElementsByTagName(‘entry’)(retval).getElementsByTagName(‘address’)(0).getElementsByTagName(‘locality’)(0).text
this.items[6] = xmlResponse.getElementsByTagName(‘result’)(0).getElementsByTagName(‘entry’)(retval).getElementsByTagName(‘address’)(0).getElementsByTagName(‘postcode’)(0).text
this.items[7] = xmlResponse.getElementsByTagName(‘result’)(0).getElementsByTagName(‘entry’)(retval).getElementsByTagName(‘address’)(0).getElementsByTagName(‘province’)(0).text
this.items[8] = xmlResponse.getElementsByTagName(‘result’)(0).getElementsByTagName(‘entry’)(retval).getElementsByTagName(‘address’)(0).getElementsByTagName(‘country’)(0).text
}
break;
}
if (this._debug) {
debugger;
}
return this.items;
}
function NationalAddresObject(xmlResponse) {
//alert(xmlResponse.xml);
var _resultcount = xmlResponse.documentElement.selectSingleNode(“/response/results”).childNodes.length;
this.items = new Array();
switch(_resultcount)
{
case 0 :
alert(‘Ongeldig huisnummer en postcode combinatie voor een adres in Nederland. Voer een geldig huisnummer en postcode combinatie in.’ );
break;
case 1 :
this.items[0] = xmlResponse.documentElement.selectSingleNode(“/response/results/entry/straatnaam”).text;
this.items[1] = ”;
this.items[2] = ”;
this.items[3] = ”;
this.items[4] = ”;
this.items[5] = xmlResponse.documentElement.selectSingleNode(“/response/results/entry/plaatsnaam”).text;
this.items[6] = xmlResponse.documentElement.selectSingleNode(“/response/results/entry/wijkcode”).text +
xmlResponse.documentElement.selectSingleNode(“/response/results/entry/lettercombinatie”).text;
this.items[7] = xmlResponse.documentElement.selectSingleNode(“/response/results/entry/provincienaam”).text;
this.items[8] = ”;
break;
default :
alert(‘Er zijn meer adressen gevonden voor deze dit huisnummer en postcode combinatie’);
break;
}
return this.items;
}
function SetAddressFields(i_Address, arrAddress) {
// fill the form fields with
}
//——————–
// Common scripts
//——————–
function _IsNull( value ) {
return ( “undefined” == typeof( value ) || “unknown” == typeof( value ) || null == value || ”==value );
}
function xreplace(checkMe,toberep,repwith){
var temp = checkMe;
var i = temp.indexOf(toberep);
while(i > -1)
{
temp = temp.replace(toberep, repwith);
i = temp.indexOf(toberep, i + repwith.length + 1);
}
return temp;
}
function Left(str, n){
if (n <= 0)
return “”;
else if (n > String(str).length)
return str;
else
return String(str).substring(0,n);
}
function Right(str, n){
if (n <= 0)
return “”;
else if (n > String(str).length)
return str;
else {
var iLen = String(str).length;
return String(str).substring(iLen, iLen – n);
}
}
function GetXmlHttp() {
var x = null;
try
{
x = new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
try
{
x = new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch (e)
{
x = null;
}
}
if (!x && typeof XMLHttpRequest != “undefined”)
{
x = new XMLHttpRequest();
}
return x;
} |