function map_location (count) { var address = ""; if (document.getElementById("edit-locations-"+count+"-country") && document.getElementById("edit-locations-"+count+"-country").type != 'hidden') { var country_object = document.getElementById("edit-locations-"+count+"-country"); switch (country_object.options[country_object.selectedIndex].value) { case 'uk': address = address_to_string_uk(count); break case 'at': address = address_to_string_country_override(count, 'Austria'); break case 'li': address = address_to_string_country_override(count, 'Liechtenstein'); break default: address = address_to_string_default(count); } } else { address = address_to_string_default(count); } place_marker_at_address (address, count); } function place_marker_at_address (address, count) { var map = new GMap2(document.getElementById("gmap-loc1-gmap"+count)); var geocoder = new GClientGeocoder(); geocoder.getLatLng( address, function(point) { if (!point) { alert(address + " not found"); } else { map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(point, 13); var marker = new GMarker(point); map.addOverlay(marker); var coords = marker.getPoint(); document.getElementById("gmap-loc1-locpick_latitude"+count).value = coords.lat(); document.getElementById("gmap-loc1-locpick_longitude"+count).value = coords.lng(); /*marker.openInfoWindowHtml(address);*/ GEvent.addListener(map, "click", function(click_marker, click_point) { if (click_marker) { document.getElementById("gmap-loc1-locpick_latitude"+count).value = ''; document.getElementById("gmap-loc1-locpick_longitude"+count).value = ''; map.removeOverlay(click_marker); marker = null; } else { if (marker != null) { map.removeOverlay(marker); } marker = new GMarker(click_point); map.addOverlay(marker); var click_coords = marker.getPoint(); document.getElementById("gmap-loc1-locpick_latitude"+count).value = click_coords.lat(); document.getElementById("gmap-loc1-locpick_longitude"+count).value = click_coords.lng(); } }); } } ); } function translate_province(province_token) { var a = get_province_array(); for (var i = 1; i < a.length; ++i) if (a[i][1] == province_token) {var province_name = a[i][2];} return province_name; } function get_province_array() { var a = new Array(16); for (var i = 1; i < a.length; ++i) a[i] = new Array(2); a[1][1] = "de-BB"; a[1][2] = "Brandenburg"; a[2][1] = "de-BE"; a[2][2] = "Berlin"; a[3][1] = "de-BW"; a[3][2] = "Baden-Württemberg"; a[4][1] = "de-BY"; a[4][2] = "Bayern"; a[5][1] = "de-HB"; a[5][2] = "Bremen"; a[6][1] = "de-HE"; a[6][2] = "Hessen"; a[7][1] = "de-MV"; a[7][2] = "Mecklenburg-Vorpommern"; a[8][1] = "de-NI"; a[8][2] = "Niedersachsen"; a[9][1] = "de-NW"; a[9][2] = "Nordrhein-Westfalen"; a[10][1] = "de-RP"; a[10][2] = "Rheinland-Pfalz"; a[11][1] = "de-SH"; a[11][2] = "Schleswig-Holstein"; a[12][1] = "de-SL"; a[12][2] = "Saarland"; a[13][1] = "de-SN"; a[13][2] = "Sachsen"; a[14][1] = "de-ST"; a[14][2] = "Sachsen-Anhalt"; a[15][1] = "de-TH"; a[15][2] = "Thüringen"; return a; } function address_to_string_default(count) { var address = ''; if (document.getElementById("edit-locations-"+count+"-street") && document.getElementById("edit-locations-"+count+"-street").type != 'hidden' && document.getElementById("edit-locations-"+count+"-street").value != '') { address = address+document.getElementById("edit-locations-"+count+"-street").value; } if (document.getElementById("edit-locations-"+count+"-city") && document.getElementById("edit-locations-"+count+"-city").type != 'hidden' && document.getElementById("edit-locations-"+count+"-city").value != '') { if (document.getElementById("edit-locations-"+count+"-street") && document.getElementById("edit-locations-"+count+"-street").type != 'hidden' && document.getElementById("edit-locations-"+count+"-street").value != '') { address = address+", "; } address = address+document.getElementById("edit-locations-"+count+"-city").value; } if (document.getElementById("edit-locations-"+count+"-province") && document.getElementById("edit-locations-"+count+"-province").type != 'hidden') { var province_object = document.getElementById("edit-locations-"+count+"-province"); if (province_object.options[province_object.selectedIndex].value != '') { if ((document.getElementById("edit-locations-"+count+"-street") && document.getElementById("edit-locations-"+count+"-street").type != 'hidden' && document.getElementById("edit-locations-"+count+"-street").value != '') || (document.getElementById("edit-locations-"+count+"-city") && document.getElementById("edit-locations-"+count+"-city").type != 'hidden' && document.getElementById("edit-locations-"+count+"-city").value != '')) { address = address+", "; } var province_old = province_object.options[province_object.selectedIndex].value; var province = translate_province(province_old); address = address+province; } } if (document.getElementById("edit-locations-"+count+"-postal-code") && document.getElementById("edit-locations-"+count+"-postal-code").type != 'hidden' && document.getElementById("edit-locations-"+count+"-postal-code").value != '') { if (address != '') { address = address+" "; } address = address+document.getElementById("edit-locations-"+count+"-postal-code").value; } if (document.getElementById("edit-locations-"+count+"-country") && document.getElementById("edit-locations-"+count+"-country").type != 'hidden') { var country_object = document.getElementById("edit-locations-"+count+"-country"); if (country_object.options[country_object.selectedIndex].value != '') { address = address+", "+country_object.options[country_object.selectedIndex].value; } } return address; } function address_to_string_country_override(count, country) { var address = ''; if (document.getElementById("edit-locations-"+count+"-street") && document.getElementById("edit-locations-"+count+"-street").type != 'hidden' && document.getElementById("edit-locations-"+count+"-street").value != '') { address = address+document.getElementById("edit-locations-"+count+"-street").value; } if (document.getElementById("edit-locations-"+count+"-city") && document.getElementById("edit-locations-"+count+"-city").type != 'hidden' && document.getElementById("edit-locations-"+count+"-city").value != '') { if (document.getElementById("edit-locations-"+count+"-street") && document.getElementById("edit-locations-"+count+"-street").type != 'hidden' && document.getElementById("edit-locations-"+count+"-street").value != '') { address = address+", "; } address = address+document.getElementById("edit-locations-"+count+"-city").value; } if (document.getElementById("edit-locations-"+count+"-province") && document.getElementById("edit-locations-"+count+"-province").type != 'hidden') { var province_object = document.getElementById("edit-locations-"+count+"-province"); if (province_object.options[province_object.selectedIndex].value != '') { if ((document.getElementById("edit-locations-"+count+"-street") && document.getElementById("edit-locations-"+count+"-street").type != 'hidden' && document.getElementById("edit-locations-"+count+"-street").value != '') || (document.getElementById("edit-locations-"+count+"-city") && document.getElementById("edit-locations-"+count+"-city").type != 'hidden' && document.getElementById("edit-locations-"+count+"-city").value != '')) { address = address+", "; } var province_old = province_object.options[province_object.selectedIndex].value; var province = translate_province(province_old); address = address+province; } } if (document.getElementById("edit-locations-"+count+"-postal-code") && document.getElementById("edit-locations-"+count+"-postal-code").type != 'hidden' && document.getElementById("edit-locations-"+count+"-postal-code").value != '') { if (address != '') { address = address+" "; } address = address+document.getElementById("edit-locations-"+count+"-postal-code").value; } address = address+", "+country; return address; } function address_to_string_uk(count) { var address = ''; if (document.getElementById("edit-locations-"+count+"-street") && document.getElementById("edit-locations-"+count+"-street").type != 'hidden' && document.getElementById("edit-locations-"+count+"-street").value != '') { address = address+document.getElementById("edit-locations-"+count+"-street").value; } if (document.getElementById("edit-locations-"+count+"-city") && document.getElementById("edit-locations-"+count+"-city").type != 'hidden' && document.getElementById("edit-locations-"+count+"-city").value != '') { if (document.getElementById("edit-locations-"+count+"-street") && document.getElementById("edit-locations-"+count+"-street").type != 'hidden' && document.getElementById("edit-locations-"+count+"-street").value != '') { address = address+", "; } address = address+document.getElementById("edit-locations-"+count+"-city").value; } if (document.getElementById("edit-locations-"+count+"-province") && document.getElementById("edit-locations-"+count+"-province").type != 'hidden') { var province_object = document.getElementById("edit-locations-"+count+"-province"); if (province_object.options[province_object.selectedIndex].value != '') { if ((document.getElementById("edit-locations-"+count+"-street") && document.getElementById("edit-locations-"+count+"-street").type != 'hidden' && document.getElementById("edit-locations-"+count+"-street").value != '') || (document.getElementById("edit-locations-"+count+"-city") && document.getElementById("edit-locations-"+count+"-city").type != 'hidden' && document.getElementById("edit-locations-"+count+"-city").value != '')) { address = address+", "; } var province_old = province_object.options[province_object.selectedIndex].value; var province = translate_province(province_old); address = address+province; } } if (document.getElementById("edit-locations-"+count+"-country") && document.getElementById("edit-locations-"+count+"-country").type != 'hidden') { var country_object = document.getElementById("edit-locations-"+count+"-country"); if (country_object.options[country_object.selectedIndex].value != '') { address = address+", "+country_object.options[country_object.selectedIndex].value; } } return address; }