Pacsoft = function(){ this.prefix = "pacsoft-"; this.methodcode = "postdk_postdk"; this.checkDroppointShipping = function() { var show = false; var showid = false; $$("input[name='shipping_method']").each(function(v) { if (v.checked) { if (v.value.search(pacsoft.methodcode) >= 0) { id = v.value.split("_"); id = id[id.length - 1]; var i = 0; while (i < pacsoft.idArrayDroppoints.length) { if (id == pacsoft.idArrayDroppoints[i]) { show = true; showid = i; break; } i++; } } } var addEvent = true; try { if(Element && typeof Element.getStorage == 'function') { var elementEventRegistry = Element.getStorage($(v.id)).get('prototype_event_registry'); } if(typeof elementEventRegistry != 'undefined'){ var elementChangeEvents = elementEventRegistry.get('change'); if(typeof elementChangeEvents != 'undefined' && elementChangeEvents[0] != 'undefined'){ var i = 0; while(i < elementChangeEvents.length){ var elementChangeEventName = elementChangeEvents[i].handler.name; if(elementChangeEventName == 'pacsoft_droppoint_form_change'){ addEvent = false; break; } i++; } } } } catch(err) { var addEvent = true; } if(addEvent){ Event.observe($(v.id), 'change', function pacsoft_droppoint_form_change(event) { if (this.value.search(pacsoft.methodcode) >= 0) { var id = v.value.split("_"); var id = id[id.length - 1]; if (this.checked && pacsoft.idArrayDroppoints.indexOf(id) >= 0) { if (this.parentNode.className == 'no-display') { this.parentNode.parentNode.appendChild($(pacsoft.prefix+'droppoint-form')); } else { this.parentNode.appendChild($(pacsoft.prefix+'droppoint-form')); } $(pacsoft.prefix+'droppoint-form').style.display = "block"; } else { $(pacsoft.prefix+'droppoint-form').style.display = "none"; } } else { $(pacsoft.prefix+'droppoint-form').style.display = "none"; } }); } }); if (show && showid !== false) { var input = $('s_method_'+pacsoft.methodcode+'_' + pacsoft.idArrayDroppoints[showid]); if (input.parentNode.className == 'no-display') { input.parentNode.parentNode.appendChild($(pacsoft.prefix+'droppoint-form')); } else { input.parentNode.appendChild($(pacsoft.prefix+'droppoint-form')); } $(pacsoft.prefix+'droppoint-form').style.display = "block"; pacsoft.setDroppointFromLocalStorage(); } else { $(pacsoft.prefix+'droppoint-form').style.display = "none"; } }; this.setDroppointFromLocalStorage = function () { if(typeof localStorage != 'undefined'){ if(localStorage.getItem(pacsoft.prefix+'servicepoint') != null){ var servicePoint = JSON.parse(localStorage.getItem(pacsoft.prefix+'servicepoint')); var servicePointId = servicePoint.servicePointId; var radio = {value:servicePointId}; servicePointsLocal = [servicePoint]; pacsoft.setAddress(radio,servicePointsLocal); if(!lastUpdatedDroppointId || lastUpdatedDroppointId != servicePointId){ pacsoft.updateShippingAddress(); } } } }; this.saveFlexmessageInLocalStorage = function() { var flexElement = document.getElementById(pacsoft.prefix+"flexmessage"); if(typeof localStorage != 'undefined' && typeof flexElement != 'undefined'){ try { localStorage.setItem(pacsoft.prefix+'flexmessage',flexElement.value); } catch(e) {} } }; this.checkFlexShipping = function() { var show = false; var showid = false; $$("input[name='shipping_method']").each(function(v) { if (v.checked) { if (v.value.search(pacsoft.methodcode) >= 0) { id = v.value.split("_"); id = id[id.length - 1]; var i = 0; while (i < pacsoft.idArrayFlexs.length) { if (id == pacsoft.idArrayFlexs[i]) { show = true; showid = i; break; } i++; } } } var addEvent = true; try { if(Element && typeof Element.getStorage == 'function') { var elementEventRegistry = Element.getStorage($(v.id)).get('prototype_event_registry'); } if(typeof elementEventRegistry != 'undefined'){ var elementChangeEvents = elementEventRegistry.get('change'); if(typeof elementChangeEvents != 'undefined' && elementChangeEvents[0] != 'undefined'){ var i = 0; while(i < elementChangeEvents.length){ var elementChangeEventName = elementChangeEvents[i].handler.name; if(elementChangeEventName == 'pacsoft_flex_form_change'){ addEvent = false; break; } i++; } } } } catch(err) { var addEvent = true; } if(addEvent){ Event.observe($(v.id), 'change', function pacsoft_flex_form_change(event) { if (this.value.search(pacsoft.methodcode) >= 0) { var id = v.value.split("_"); var id = id[id.length - 1]; if (this.checked && pacsoft.idArrayFlexs.indexOf(id) >= 0) { if (this.parentNode.className == 'no-display') { this.parentNode.parentNode.appendChild($(pacsoft.prefix+'flex-form')); } else { this.parentNode.appendChild($(pacsoft.prefix+'flex-form')); } $(pacsoft.prefix+'flex-form').style.display = "block"; } else { $(pacsoft.prefix+'flex-form').style.display = "none"; } } else { $(pacsoft.prefix+'flex-form').style.display = "none"; } }); } }); if (show && showid !== false) { var input = $('s_method_'+pacsoft.methodcode+'_'+pacsoft.idArrayFlexs[showid]); if (input.parentNode.className == 'no-display') { input.parentNode.parentNode.appendChild($(pacsoft.prefix+'flex-form')); } else { input.parentNode.appendChild($(pacsoft.prefix+'flex-form')); } $(pacsoft.prefix+'flex-form').style.display = "block"; pacsoft.setFlexFromLocalStorage(); } else { $(pacsoft.prefix+'flex-form').style.display = "none"; } }; this.setFlexFromLocalStorage = function() { if(typeof localStorage != 'undefined'){ if(localStorage.getItem(pacsoft.prefix+'flexmessage') != null){ var flexmessage = localStorage.getItem(pacsoft.prefix+'flexmessage'); document.getElementById(pacsoft.prefix+'flexmessage').value = flexmessage; } } }; this.loadDroppoints = function() { postalCode = document.getElementById(pacsoft.prefix+'postalCode'); countryCode = document.getElementById(pacsoft.prefix+'countryCode'); pacsoft.getJson(postalCode.value, countryCode.value); }; this.setMobileHeight = function() { return true; // deprecated /* currentScrollPosition = document.viewport.getScrollOffsets()[1]; $(document.body).setStyle({ position: 'fixed', top: -currentScrollPosition+'px', width: '100%' }); */ }; this.onEnterGetJson = function(e) { if (e.keyCode == 13) { pacsoft.loadDroppoints(); return false; } }; this.setDroppointSizes = function() { var viewHeight = document.viewport.getHeight(); var wrapperHeight = $(pacsoft.prefix+'droppoint-wrapper').getHeight(); var headerHeight = $(pacsoft.prefix+'droppoint-header').getHeight(); var buttonsHeight = $(pacsoft.prefix+'droppoint-buttons-set').getHeight(); var containerHeight = wrapperHeight-headerHeight-buttonsHeight; var containerWidthHalf = $(pacsoft.prefix+'address-container').getWidth(); $(pacsoft.prefix+'droppoint-wrapper').setStyle({ top: ((viewHeight-wrapperHeight)/2)+'px', }); $(pacsoft.prefix+'droppoint-result').setStyle({ height: containerHeight+'px' }); $(pacsoft.prefix+'droppoint-result').down('.map').setStyle({ height: containerHeight+'px' }); $(pacsoft.prefix+'address-container').setStyle({ height: containerHeight+'px' }); $(pacsoft.prefix+'opening-container').setStyle({ height: containerHeight+'px', }); } this.getJson = function(postalCode, countryCode) { $(pacsoft.prefix+'loading').style.display = "inline"; if(typeof baseUrl == 'undefined'){ baseUrl = '/'; } new Ajax.Request(baseUrl+'pacsoft/droppoint/getDroppointsFromPostalCode', { method: 'get', parameters: { 'postalCode': postalCode, 'countryCode': countryCode }, onComplete: function(transport) { $(pacsoft.prefix+'loading').style.display = "none"; jsonResponse = transport.responseText.evalJSON(); if (jsonResponse && typeof jsonResponse.servicePointInformationResponse.compositeFault == "undefined") { if($(pacsoft.prefix+'droppoint-select').getStyle('display') == 'none') { $(pacsoft.prefix+'droppoint-overlay').style.display = 'block'; } else { $(pacsoft.prefix+'droppoint-overlay').style.display = 'none'; } pacsoft.setDroppointSizes(); var addEvent = true; try { if(Element && typeof Element.getStorage == 'function') { var elementEventRegistry = Element.getStorage($(pacsoft.prefix+'close-droppoint-selector-save')).get('prototype_event_registry'); } if(typeof elementEventRegistry != 'undefined'){ var elementChangeEvents = elementEventRegistry.get('click'); if(typeof elementChangeEvents != 'undefined' && elementChangeEvents[0] != 'undefined'){ var i = 0; while(i < elementChangeEvents.length){ var elementChangeEventName = elementChangeEvents[i].handler.name; if(elementChangeEventName == 'pacsoft_move_overlay_click'){ addEvent = false; break; } i++; } } } } catch(err) { var addEvent = true; } if(addEvent){ Event.observe($(pacsoft.prefix+'close-droppoint-selector-save'), 'click', function pacsoft_move_overlay_click(event) { $(pacsoft.prefix+'droppoint-overlay').style.display = "none"; $(pacsoft.prefix+'droppoint-form').style.display = "block"; pacsoft.moveOverlayIn(); $(document.body).setStyle({ position: 'inherit' }); }); Event.observe($(pacsoft.prefix+'close-droppoint-selector-remove'), 'click', function(event) { $(pacsoft.prefix+'droppoint-overlay').style.display = "none"; $(pacsoft.prefix+'droppoint-form').style.display = "block"; if($$("input:checked[id^='"+pacsoft.prefix+"servicePointId'][type='radio']").length) { $$("input:checked[id^='"+pacsoft.prefix+"servicePointId'][type='radio']")[0].checked = false; } pacsoft.selectedServicePoint = null; pacsoft.setAddress(false,pacsoft.servicePoints); pacsoft.moveOverlayIn(); $(document.body).setStyle({ position: 'inherit' }); }); Event.observe($(pacsoft.prefix+'droppoint-select'), 'change', function select_update_droppoint(event) { pacsoft.setAddress(this,pacsoft.servicePoints); pacsoft.updateShippingAddress(); }); } pacsoft.moveOverlayOut(); pacsoft.handleJson(jsonResponse); pacsoft.setMobileHeight(); } else { alert('Ingen afhentningssteder fundet for det indtastede postnummer, prøv venligst igen...'); $(pacsoft.prefix+'postalcode').focus(); } } }); }; this.updateShippingAddress = function() { if(typeof localStorage != 'undefined' && typeof pacsoft.selectedServicePoint != 'undefined' && pacsoft.selectedServicePoint != null){ try { localStorage.setItem(pacsoft.prefix+'servicepoint',JSON.stringify(pacsoft.selectedServicePoint)); } catch(e){}; pacsoft.selectedServicePoint = null; } if(typeof baseUrl == 'undefined'){ baseUrl = '/'; } new Ajax.Request(baseUrl+'pacsoft/droppoint/update', { method: 'post', parameters: { 'droppoint': $(pacsoft.prefix+"droppoint-id").value, 'droppoint-name': $(pacsoft.prefix+"droppoint-name").value, "droppoint-city": $(pacsoft.prefix+"droppoint-city").value, "droppoint-postalcode": $(pacsoft.prefix+"droppoint-postalcode").value, "droppoint-streetname": $(pacsoft.prefix+"droppoint-streetname").value, "droppoint-streetnumber": $(pacsoft.prefix+"droppoint-streetnumber").value }, onComplete: function(transport) { $(pacsoft.prefix+'loading').style.display = "none"; lastUpdatedDroppointId = $(pacsoft.prefix+"droppoint-id").value; } }); }; this.moveOverlayOut = function() { $(document.body).appendChild($(pacsoft.prefix+'droppoint-overlay')); }; this.moveOverlayIn = function() { $(pacsoft.prefix+'droppoint-form').appendChild($(pacsoft.prefix+'droppoint-overlay')); pacsoft.updateShippingAddress(); }; this.handleJson = function(jsonResponse) { if(typeof google === 'object' && typeof google.maps === 'object') { mapCenterCoords = pacsoft.getMapBound(jsonResponse.servicePointInformationResponse.servicePoints); sw = mapCenterCoords[0]; ne = mapCenterCoords[1]; mapOptions = { //center: ne, zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP, draggable: true, zoomControl: true, scrollwheel: false, disableDoubleClickZoom: true, keyboardShortcuts: false, streetViewControl: false }; map = new google.maps.Map(document.getElementById(pacsoft.prefix+"map-canvas"), mapOptions); map.fitBounds(new google.maps.LatLngBounds(sw, ne)); } else { map = false; } pacsoft.servicePoints = jsonResponse.servicePointInformationResponse.servicePoints; pacsoft.markers = pacsoft.addDroppointMarkers(jsonResponse.servicePointInformationResponse.servicePoints, map); }; this.addDroppointMarkers = function(servicePoints, map) { var markers = []; $(pacsoft.prefix+'addresses').update(""); $(pacsoft.prefix+'droppoint-select').update(''); var x = 0; while (x < servicePoints.length) { var classname = ""; if(x%5 == 0) { classname = " first"; } else if((x+1)%5 == 0) { classname = " last"; } if(map) { var marker = pacsoft.addMarker(servicePoints[x], map); markers.push(marker); } pacsoft.addAddress(servicePoints[x],classname); x++; } return markers; }; this.addAddress = function(servicePoint,classname) { var servicePointId = servicePoint.servicePointId; if (servicePoint.name.search("Handikapvenlig") >= 0) { servicePointId += "-Handikapvenlig"; } var isChecked = false; if ($(pacsoft.prefix+'droppoint-id').value == servicePointId) { isChecked = true; pacsoft.setOpeningHours(servicePointId); } var container = new Element('li', { 'id': servicePointId }); container.addClassName(pacsoft.prefix+"container" + classname); var radio = new Element('input', { 'type': "radio", 'id': pacsoft.prefix+"servicePointId-" + servicePointId, 'value': servicePointId }); radio.addClassName(pacsoft.prefix+"radio"); radio.name = "droppoint"; if (isChecked) { radio.checked = "checked"; } var address = new Element('div'); address.addClassName(pacsoft.prefix+"address"); var label = new Element('label', { 'for' : pacsoft.prefix+"servicePointId-" + servicePointId }); var name = new Element('h4').update(servicePoint.name); var droppointaddress = new Element('div').update('
' + servicePoint.deliveryAddress.streetName + " " + servicePoint.deliveryAddress.streetNumber + "
" + servicePoint.deliveryAddress.postalCode + " " + servicePoint.deliveryAddress.city + '
'); droppointaddress.addClassName(pacsoft.prefix+"content"); Event.observe(radio, 'change', function(event) { pacsoft.bounceMarkerOnRadioClick(this); pacsoft.setAddress(this,pacsoft.servicePoints); }); label.appendChild(name); label.appendChild(droppointaddress); address.appendChild(label); container.appendChild(radio); container.appendChild(address); $(pacsoft.prefix+'addresses').appendChild(container); var option = new Element('option', { 'value': servicePointId, 'data-name' : servicePoint.name, 'data-address' : servicePoint.deliveryAddress.streetName + " " + servicePoint.deliveryAddress.streetNumber, 'data-postcode' : servicePoint.deliveryAddress.postalCode, 'data-city' : servicePoint.deliveryAddress.city, }); option.innerHTML = servicePoint.name + ', ' + servicePoint.deliveryAddress.streetName + " " + servicePoint.deliveryAddress.streetNumber + ', ' + servicePoint.deliveryAddress.postalCode + ' ' + servicePoint.deliveryAddress.city; $(pacsoft.prefix+'droppoint-select').appendChild(option); }; this.addMarker = function(servicePoint, map) { var servicePointId = servicePoint.servicePointId; if (servicePoint.name.search("Handikapvenlig") >= 0) { servicePointId += "-Handikapvenlig"; } var myLatlng = new google.maps.LatLng(servicePoint.coordinate.northing, servicePoint.coordinate.easting); var marker = new google.maps.Marker({ position: myLatlng, title: servicePoint.name, servicePointId: pacsoft.prefix+'servicePointId-' + servicePointId }); marker.setMap(map); google.maps.event.addListener(marker, 'click', pacsoft.toggleBounce); return marker; }; this.toggleBounce = function() { var x = 0; while (x < pacsoft.markers.length) { pacsoft.markers[x].setAnimation(null); x++; } this.setAnimation(google.maps.Animation.BOUNCE); pacsoft.selectRadioOnMarkerClick(this); }; this.selectRadioOnMarkerClick = function(marker) { $(marker.servicePointId).checked = true; pacsoft.setAddress($(marker.servicePointId),pacsoft.servicePoints); pacsoft.setOpeningHours(marker.servicePointId.replace(pacsoft.prefix+"servicePointId-","")); var x = 0; while (x < pacsoft.markers.length) { pacsoft.markers[x].setAnimation(null); x++; } marker.setAnimation(google.maps.Animation.BOUNCE); }; this.bounceMarkerOnRadioClick = function(radio) { var bouncex = false; var x = 0; while (x < pacsoft.markers.length) { pacsoft.markers[x].setAnimation(null); if (pacsoft.markers[x].servicePointId == radio.id) { bouncex = x; pacsoft.setOpeningHours(radio.value); } x++; } if (bouncex !== false) { pacsoft.markers[bouncex].setAnimation(google.maps.Animation.BOUNCE); } }; this.setOpeningHours = function(servicePointId) { var handikapvenlig = ""; if (servicePointId.search("Handikapvenlig") >= 0) { servicePointId = servicePointId.replace("-Handikapvenlig",""); handikapvenlig = " Handikapvenlig"; } var openingheader = new Element('div'); openingheader.addClassName(pacsoft.prefix+"opening-header"); openingheader.innerHTML = $(pacsoft.prefix+"opening-header-text").innerHTML; $(pacsoft.prefix+'opening-container').innerHTML = ""; $(pacsoft.prefix+'opening-container').appendChild(openingheader); if(pacsoft.servicePoints) { var x = 0; while (x < pacsoft.servicePoints.length) { if (pacsoft.servicePoints[x].servicePointId == servicePointId) { var droppointaddress = new Element('div').update(''+pacsoft.servicePoints[x].name+handikapvenlig+'