var nLastInputTimestamp; var nRedrawRouteTimestamp; var oMap; // open street map var sPreviousRouteInput; var sPreviousEventLine = ' '; var sUpdateAction; var sSelf; sSelf = '/routeplanner/index.php'; function ajap(sUrl) { var oHead; var oOldScript; var oScript; oHead = document.getElementsByTagName('head').item(0); oOldScript = document.getElementById('lastLoadedScript'); if (oOldScript) { oHead.removeChild(oOldScript); } oScript = document.createElement('script'); oScript.src = sUrl; oScript.type = 'text/javascript'; oScript.id = 'lastLoadedScript'; void(oHead.appendChild(oScript)); } function getAutoComplete() { return document.getElementById('autocomplete'); } function getInputDiv() { return document.getElementById('postcodesinputdiv'); } function getInputForm() { return document.getElementById('postcodesInput'); } function getLastInputTimestamp() { return nLastInputTimestamp; } function weg_getNumberOfLines(sLines) { var aLines; aLines = sLines.split('\n'); return aLines.length; } function getOsMapHeight() { var nWindowHeight; var nMapTop; var nMapHeight; var oAutoComplete; nWindowHeight = getWindowHeight(); oAutoComplete = getAutoComplete(); nMapTop = parseInt(oAutoComplete.offsetTop); nMapHeight = nWindowHeight - nMapTop - 45; nMapHeight = Math.max(nMapHeight, 300); return nMapHeight; } function getOsMapWidth() { var nMapLeft; var nMapWidth; var nWindowWidth; var oAutoComplete; oAutoComplete = getAutoComplete(); nMapLeft = parseInt(oAutoComplete.offsetLeft) + oAutoComplete.offsetWidth + 15; nWindowWidth = getWindowWidth(); nMapWidth = nWindowWidth - nMapLeft - 25; nMapWidth = Math.max(nMapWidth, 250); return nMapWidth; } function getPostcodeMapHeight() { var oInputDiv; var nFormHeight; var nFormTop; var nWindowHeight; var nMapHeight; oInputDiv = getInputDiv(); nFormHeight = oInputDiv.offsetHeight; nFormTop = oInputDiv.offsetTop; nWindowHeight = getWindowHeight(); nMapHeight = nWindowHeight - nFormTop - 90; nMapHeight = Math.max(nMapHeight, 200); return nMapHeight; } function getPostcodeMapWidth() { var nWindowWidth; var nMapWidth; var oInputDiv oInputDiv = getInputDiv(); nWindowWidth = getWindowWidth(); nInputWidth = oInputDiv.offsetWidth; nMapWidth = nWindowWidth - nInputWidth - 70; return nMapWidth; } function getPostcodeInput() { return document.getElementById('postcodeInput'); } function getPreviousEventLine() { return sPreviousEventLine; } function getUpdateAction() { return sUpdateAction; } function getWindowHeight() { if( typeof( window.innerHeight ) == 'number' ) { //Non-IE return window.innerHeight; } if( document.documentElement && ( document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' return document.documentElement.clientHeight; } return document.body.clientHeight; } function getWindowWidth() { if( typeof( window.innerWidth ) == 'number' ) { //Non-IE return window.innerWidth; } if( document.documentElement && ( document.documentElement.clientWidth ) ) { //IE 6+ in 'standards compliant mode' return document.documentElement.clientWidth; } return document.body.clientWidth; } function init() { redrawRoute(); } function initOpenStreetMap() { var oLayerMapnik; oMap = new OpenLayers.Map('osmap', { maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), numZoomLevels: 19, maxResolution: 156543.0399, units: 'm', projection: new OpenLayers.Projection("EPSG:900913"), displayProjection: new OpenLayers.Projection("EPSG:4326") }); oLayerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik"); oMap.addLayers([oLayerMapnik]); setOsMapDimensions(); setMapCenter(5, 52, 7); } function redrawRoute() { var nDay; var nHours; var nMapHeight; var nMapWidth; var nMinutes; var nMonth; var nSeconds; var nYear; var oDate; var oMap; oMap = document.getElementById('map'); nMapWidth = getPostcodeMapWidth(); nMapHeight = getPostcodeMapHeight(); oDate = new Date(); nYear = oDate.getFullYear(); nMonth = 1 + oDate.getMonth(); nDay = oDate.getDate(); nHours = oDate.getHours(); nMinutes = oDate.getMinutes(); nSeconds = oDate.getSeconds(); sNow = '' + nYear + nMonth + nDay + nHours + nMinutes + nSeconds; oMap.src = sSelf + '?act=img.map' + '&time=' + sNow + '&width=' + nMapWidth + '&height=' + nMapHeight; oMap.className = 'map'; } function redrawRouteIfNoChangeSince(nEventTimestamp) { if (nEventTimestamp == nRedrawRouteTimestamp) { redrawRoute(); } } function refreshAutoComplete() { var oPostcodeInput; var sLine; var sUrl; oPostcodeInput = getPostcodeInput(); sLine = oPostcodeInput.value; sUrl = sSelf + '?act=sea.mat' + '&line=' + sLine ; ajap(sUrl); } function setCity(sCity) { var oCity; oCity = document.getElementById('city'); if (oCity.value == '') { oCity.value = sCity; } } function setInputMandatory(oField) { var sValue; sValue = oField.value; if (sValue == "") { oField.className = "mandatory"; } else { oField.className = ""; } } function setLastInputTimestamp(nTimestamp) { nLastInputTimestamp = nTimestamp; } function setPostcodeInputClass(sClass) { var oPostcodeInput; oPostcodeInput = getPostcodeInput(); oPostcodeInput.className = sClass; } function setPostcodeInputSize() { var oPostcodeInput; var oAutoComplete; var nSize; var nCurrentSize; var sLine; oAutoComplete = getAutoComplete(); oPostcodeInput = getPostcodeInput(); sLine = oPostcodeInput.value; nSize = sLine.length + 3; nSize = Math.max(nSize, 25); nSize = Math.min(nSize, 65); nCurrentSize = oPostcodeInput.size; if (nSize != nCurrentSize) { oPostcodeInput.size = nSize; } } function setMapCenter(nLongitude, nLatitude, nZoomLevel) { var oLonLat; oLonLat = new OpenLayers.LonLat(nLongitude, nLatitude).transform(oMap.displayProjection, oMap.projection); oMap.setCenter(oLonLat, nZoomLevel); } function setOsMapDimensions() { var nMapWidth; var nWindowWidth; var oMapDiv; oMapDiv = document.getElementById('osmapdiv'); nMapWidth = getOsMapWidth(); oMapDiv.style.width = "" + nMapWidth + "px"; nMapHeight = getOsMapHeight(); oMapDiv.style.height = "" + nMapHeight + "px"; } function setPreviousEventLine(sLine) { sPreviousEventLine = sLine; } function setRedrawRouteTimer() { var oDate; var nHeight; var nWidth; var oMap; // resize image by brute browser force nWidth = getPostcodeMapWidth(); nHeight = getPostcodeMapHeight(); oMap = document.getElementById('map'); oMap.width = nWidth; oMap.height = nHeight; oMap.className = 'map busy'; // redraw sharp new map if no changes in next few seconds oDate = new Date(); nRedrawRouteTimestamp = oDate.getTime(); sMessage = 'redrawRouteIfNoChangeSince(' + nRedrawRouteTimestamp + ')'; setTimeout(sMessage, 1200); } function setStreet(sStreet) { var oStreet; oStreet = document.getElementById('street'); if (oStreet.value == '') { oStreet.value = sStreet; } } function setStreetAndCity() { var sPostcode; sPostcode = document.getElementById("postcode").value; sUrl = sSelf + '?act=sub.mat' + '&postcode=' + sPostcode ; ajap(sUrl); } function setUpdateAction(sAction) { sUpdateAction = sAction; } function setUpdateTimer() { var nNow; var oDate; var oPostcodeInput; var sMessage; oPostcodeInput = getPostcodeInput(); sLine = oPostcodeInput.value; sPreviousLine = getPreviousEventLine(); if (sLine != sPreviousLine) { setPostcodeInputSize(); // adjust width immediately // remember till next event setPreviousEventLine(sLine); oDate = new Date(); nNow = oDate.getTime(); setLastInputTimestamp(nNow); nLength = sLine.length; if (nLength == 0) { sHtml = "Bijvoorbeeld:"; showAutoComplete(sHtml); } else if (nLength < 3) { sHtml = 'Typ wat meer letters
van postcode of straat en stad.'; showAutoComplete(sHtml); } else { sHtml = "Even geduld...

Op zoek naar " + sLine; showAutoCompleteBusy(sHtml); setUpdateAction('showAutoComplete'); sMessage = 'updateIfNoChanceSince(' + nNow + ')'; setTimeout(sMessage, 750); } } } function showAutoComplete(sHtml) { var oAutoComplete; oAutoComplete = getAutoComplete(); oAutoComplete.innerHTML = sHtml; oAutoComplete.className = 'autocomplete'; setOsMapDimensions(); } function showAutoCompleteBusy(sHtml) { var oAutoComplete; oAutoComplete = getAutoComplete(); oAutoComplete.innerHTML = sHtml; oAutoComplete.className = 'autocomplete busy'; setOsMapDimensions(); } function submitForm() { oInputForm = getInputForm(); oInputForm.className = "busy"; oInputForm.submit(); } function updateIfNoChanceSince(nEventTimestamp) { var nLastInputTimestamp; var sAction; nLastInputTimestamp = getLastInputTimestamp(); if (nEventTimestamp < nLastInputTimestamp) { // do nothing, wait till next event return; } sAction = getUpdateAction(); switch (sAction) { case 'showAutoComplete': refreshAutoComplete(); break; } setUpdateAction(''); } function updateMapWithPostcodesFromInput() { var aLines; var nHeight; var nLineLength; var nMaximumLineLength; var nPostcodeIndex; var nWidth; var oPostcodesInput; var sFourNumericsPattern; var sLine; var sLines; var sPostcode; var sUrl; sFourNumericsPattern = /[1-9]\d{3}/; // four digits, first one not zero // get postcodes from input oPostcodesInput = document.getElementById('postcodes'); sLines = oPostcodesInput.value; aLines = sLines.split('\n'); sUrl = sSelf + '?act=img.pcd' + '&postcodes=' ; nMaximumLineLength = 8; for(var nIndex in aLines) { sLine = aLines[nIndex]; nLineLength = sLine.length; nMaximumLineLength = Math.max(nMaximumLineLength, nLineLength); nPostcodeIndex = sLine.search(sFourNumericsPattern); if (nPostcodeIndex != -1) { sPostcode = sLine.substr(nPostcodeIndex, 4) sUrl += sPostcode; sUrl += ':'; } } nMaximumLineLength = Math.min(nMaximumLineLength, 35); oPostcodesInput.cols = nMaximumLineLength; nRows = aLines.length + 1; nRows = Math.min(nRows, 20); nRows = Math.max(nRows, 5); oPostcodesInput.rows = nRows; nHeight = getPostcodeMapHeight(); nWidth = getPostcodeMapWidth(); sUrl += '&width=' + nWidth + '&height=' + nHeight oMap = document.getElementById('map'); oMap.src = sUrl; }