var map;
var geo = new GClientGeocoder;
geo.setBaseCountryCode('uk');
var clubs = [];
var sessions = [];
var attributes = [];
var teachers = [];

var marker_width = 17;
var marker_height = 25;


// Initialise markers
var baseIcon = new GIcon();
baseIcon.shadow = "icons/marker_shadow.png";
baseIcon.iconSize = new GSize(16, 28);
baseIcon.shadowSize = new GSize(40, 28);
baseIcon.iconAnchor = new GPoint(8, 28);
baseIcon.infoWindowAnchor = new GPoint(8, 2);
baseIcon.infoShadowAnchor = new GPoint(16, 28);

var cobaseIcon = new GIcon();
cobaseIcon.shadow = "icons/co_shadow.png";
cobaseIcon.iconSize = new GSize(28, 28);
cobaseIcon.shadowSize = new GSize(40, 28);
cobaseIcon.iconAnchor = new GPoint(8, 28);
cobaseIcon.infoWindowAnchor = new GPoint(8, 2);
cobaseIcon.infoShadowAnchor = new GPoint(28, 28);

var icon_red = new GIcon(baseIcon); 
var icon_red_p = new GIcon(baseIcon); 
var icon_yellow = new GIcon(baseIcon);
var icon_blue = new GIcon(baseIcon);
var icon_green = new GIcon(cobaseIcon);
icon_red.image = "icons/marker_r.png";
icon_red_p.image = "icons/marker_rp.png";
icon_yellow.image = "icons/marker_y.png";
icon_blue.image = "icons/marker_b.png";
icon_green.image = "icons/co_green.png";


function add_marker(icon, point, key, tab_func, args, zoom, title) {
  var marker;
  var opts = {"title" : title,
              "icon"  : icon};
  var opts_np = {"title" : title + " (Nat Pairs)",
                 "icon"  : icon};

  if (args[0].getAttribute("npyear") > 2005) {
    marker = new GMarker(point, opts_np);  
  }
  else {
    marker = new GMarker(point, opts);  
  }


  GEvent.addListener(marker, "click", function() {
    var tabs = tab_func(args);
    if (tabs.length < 1) return;
    if (tabs.length == 1) {
      marker.openInfoWindow(tabs[0]);
      return;
    }
    marker.openInfoWindowTabsHtml(tabs);
  });

  if (args[0].getAttribute("npyear") < 2005) {
    GEvent.addListener(map, "hideNP", function() {
      marker.hide();
    });

    GEvent.addListener(map, "showNP", function() {
      marker.show();
    });
  }

  if (key != null) {
    GEvent.addListener(map, "zoom " + key, function() {
      map.setZoom(zoom);
      map.panTo(point);
      var shunt_point = new GLatLng(point.lat() + 0.0006, point.lng());
      var tabs = tab_func(args);
      if (tabs.length < 1) return;
      if (tabs.length == 1) {
        map.openInfoWindow(shunt_point, tabs[0]);
	return;
      }
      map.openInfoWindowTabsHtml(shunt_point, tabs);
    });
  }

  return marker;
}

function add_co_marker(icon, point, key, tab_func, args) {
  var marker;
  var opts = {"icon": 		icon,
              "clickable":	true,
	      "title":		args[0].getAttribute("name"),
	      "labelText":	args[0].getAttribute("id"),
	      "labelOffset":	new GSize(-4, -22)
	}      

//  var newIcon = MapIconMaker.createFlatIcon({width: 25, height: 21, primaryColor: "#baeeba", shape: "roundrect", label: args[0].getAttribute("id")});

//  marker = new GMarker(point, {icon: newIcon});
	   
  marker = new LabeledMarker(point, opts);

  GEvent.addListener(marker, "click", function() {
    var tabs = tab_func(args);
    if (tabs.length < 1) return;
    if (tabs.length == 1) {
      marker.openInfoWindow(tabs[0]);
      return;
    }
    marker.openInfoWindowTabsHtml(tabs);
  });


  return marker;
}

function club_popup(args) {
  var club = args[0];
  var num = args[1];
  var zoom_in = '<img class="icon" src="icons/zoom_in.png" title="Zoom In" alt="Zoom In" onmouseover="this.style.cursor=\'pointer\'" onmouseout="this.style.cursor=\'default\'" onclick="GEvent.trigger(map, \'zoom venue' + num + '\');"/>';
  var zoom_out = '<img class="icon" src="icons/zoom_out.png" title="Zoom Out" alt="Zoom Out" onmouseover="this.style.cursor=\'pointer\'" onmouseout="this.style.cursor=\'default\'" onclick="map.returnToSavedPosition();"/>';
  var website = "";
  var email = "";
  if (club.getAttribute("website").length > 0)
    website = '<a target="ebu" href="http://' + club.getAttribute("website").replace(/http:\/\/(.*)/i, '$1') + '"><img class="icon" src="icons/web.png" title="Go to Club Website" alt="Go to Club Website""/></a> ';

  if (club.getAttribute("email").length > 0)
    email = '<a href="mailto:' + club.getAttribute("email") + '"><img class="icon" src="icons/email.png" alt="Email" title="' + club.getAttribute("email") + '"/></a> ';

  var tabs = [];
  var address = "";
  if (club.getAttribute("address1").length > 0)
    address += club.getAttribute("address1") + '<br/>';
  if (club.getAttribute("address2").length > 0)
    address += club.getAttribute("address2") + '<br/>';
  if (club.getAttribute("address3").length > 0)
    address += club.getAttribute("address3") + '<br/>';
  if (club.getAttribute("town").length > 0)
    address += club.getAttribute("town") + '<br/>';
  if (club.getAttribute("acounty").length > 0)
    address += club.getAttribute("acounty") + '<br/>';
  if (club.getAttribute("postcode").length > 0)
    address += club.getAttribute("postcode") + '<br/>';

  var phone = "";
  if (club.getAttribute("tel1").length > 0)
    phone += club.getAttribute("tel1");
  if (club.getAttribute("tel2").length > 0)
    phone += '<br/>' + club.getAttribute("tel2");

  var details = '<div style="width: 264px;"><table style="width: 100%;">';
  details += '<tr><td/><td>' + zoom_in + zoom_out + website + email + '</td></tr><tr><td/><td><b>' + club.getAttribute("name") + '</b></td></tr>';
  if (club.getAttribute("contact").length > 0)
    details += '<tr><td><img src="icons/contact.png" title="Contact" alt="Contact"/></td><td>' + club.getAttribute("contact") + '</td></tr>';
  details += '<tr><td style="vertical-align: top;"><img src="icons/mail.png" title="Address" alt="Address"/></td><td>' + address + '</td></tr>';
  if (phone.length > 0)
    details += '<tr><td style="vertical-align: top;"><img src="icons/phone.png" title="Telephone" alt="Telephone"/></td><td>' + phone + '</td></tr>';
  details += '<tr><td colspan="2">County of Affiliation: <a onmouseout="this.style.cursor=\'default\';" onmouseover="this.style.cursor=\'pointer\';" onclick="document.getElementById(\'searchinput\').value = \'county:' + club.getAttribute("county") + '\'; searchclubs(0);">' + club.getAttribute("county") + '</a></td></tr>';
  details += '</table></div>';

  tabs.push(new GInfoWindowTab('Venue', details));

  var slist = '<table class="session" style="width: 264px;">';
  for (var i = 0; i < sessions.length; i++) {
    if (sessions[i].getAttribute("id") == club.getAttribute("id")) {
      slist += '<tr><td>' + sessions[i].getAttribute("description") + '</td><td>'
            + sessions[i].getAttribute("time") + '</td><td>'
            + sessions[i].getAttribute("value") + '</td><td>'
            + sessions[i].getAttribute("location") + '</td><td>'
            + sessions[i].getAttribute("other") + '</td></tr>';
    }
  }
  slist += "</table>";

  if (club.getAttribute("npyear") > 2005) {
    slist += "<br/> National Pairs Heat: " + Number(club.getAttribute("npday")).toFixed(0) +
             "." + Number(club.getAttribute("npmonth")).toFixed(0) + "." + Number(club.getAttribute("npyear")).toFixed(0);
  }

  var alist = '<table style="width: 264px; padding: 5px;"><tr>';
  var as = 0;
  for (var i = 0; i < attributes.length; i++) {
    if (attributes[i].getAttribute("id") == club.getAttribute("id")) {
      if (as == 5) {
        alist += '</tr><tr>';
        as = 0;
      }
      var desc = attributes[i].getAttribute("description");
      var pic = 'icons/' + attributes[i].getAttribute("image");
      alist += '<td><img class="icon" src="' + pic + '" onmouseover="document.getElementById(\'tooltip\').innerHTML = \'' + desc + '\';" onmouseout="document.getElementById(\'tooltip\').innerHTML = \'&nbsp;\';"/></td>';
      as++;
    }
  }
  var info = "";
  if (club.getAttribute("precise") == 1)
    info = '<img src="icons/marker_r.png" class="icon" title="Accurate marker" alt="Accurate marker"/> The location of red markers is, as far as the EBU knows, accurate and can usually be relied upon for directions etc.';
  else
    info = '<img src="icons/marker_rp.png" class="icon" title="Inaccurate marker" alt="Inaccurate marker"/> The location of pink markers is an approximation of a club\'s location and should not be relied upon for directions. You can suggest a better position by ticking the box below the map.';
  alist += '</tr></table><table style="width: 264px;"><tr><td align="center" id="tooltip" colspan="5" style="height: 3em;">&nbsp;</td></tr><tr><td style="border-top: 1px solid black; padding-top: 4px; text-align: justify;" colspan="5">' + info + '</td></tr></table>';

  tabs.push(new GInfoWindowTab('Sessions', '<div style="font-size: 0.7em;">' + slist + '</div>'));
  tabs.push(new GInfoWindowTab('Facilities', '<div style="font-size: 0.7em;">' + alist + '</div>'));

  return tabs;
}

function teacher_popup(args) {
  var teacher = args[0];
  var num = args[1];

  var zoom_in = '<img class="icon" src="icons/zoom_in.png" title="Zoom In" alt="Zoom In" onmouseover="this.style.cursor=\'pointer\'" onmouseout="this.style.cursor=\'default\'" onclick="GEvent.trigger(map, \'zoom teacher' + num + '\');"/>';
  var zoom_out = '<img class="icon" src="icons/zoom_out.png" title="Zoom Out" alt="Zoom Out" onmouseover="this.style.cursor=\'pointer\'" onmouseout="this.style.cursor=\'default\'" onclick="map.returnToSavedPosition();"/>';

  var email = "";
  var website = "";
  if (teacher.getAttribute("website").length > 0)
    website = '<a target="ebu" href="http://' + teacher.getAttribute("website").replace(/http:\/\/(.*)/i, '$1') + '"><img class="icon" src="icons/web.png" title="Go to Teacher Website" alt="Go to Teacher Website""/></a> ';

  if (teacher.getAttribute("email").length > 0)
    email = '<a href="mailto:' + teacher.getAttribute("email") + '"><img class="icon" src="icons/email.png" title="' + teacher.getAttribute("email") + '"/></a> ';

  var phone = "";
  if (teacher.getAttribute("tel1").length > 0)
    phone = '<tr><td><img src="icons/phone.png" title="Telephone" alt="Telephone"/></td><td>' + teacher.getAttribute("tel1") + '</td></tr>';
  var pro = "";
  if (teacher.getAttribute("type") == "Pro")
    pro = '<img src="icons/scroll.png" title="Professional Qualification" alt="Professional Qualification" class="icon"/>';

  var tabs = [];

  var data = '<div style="width: 200px;"><table><tr><td/><td>' + zoom_in + zoom_out + website + email + pro + '</td></tr>';
  data += '<tr><td><img src="icons/teacher.png" title="Teacher Name" alt="Teacher Name"/></td><td>' + teacher.getAttribute("forename") + ' ' + teacher.getAttribute("surname") + '</td></tr>';
  data += phone;
  data += '</table></div>';

  tabs.push(new GInfoWindowTab('Teacher', data));
  tabs.push(new GInfoWindowTab('Info', '<div style="width: 200px; font-size: 0.8em; text-align: justify;"><img src="icons/information.png" title="Information" alt="info" class="icon"/>Please note: the location of blue markers is an approximation of the teacher\'s location only. If it happens to appear on a building then it is purely coincidental and offers no indication of their address.</div>'));

  return tabs;
}

function county_popup(args) {
  var co = args[0];

  var tabs = [];
  var info = "";
  if (co.getAttribute("website").length > 0) 
    info += '<a target="ebu" href="http://' + co.getAttribute("website").replace(/http:\/\/(.*)/i, '$1') + '"><img src="icons/web.png" title="Go to ' + co.getAttribute("name") + ' website" alt="Go to county\'s website" class="icon"/></a>';
  info += '<img src="icons/clubs.png" title="Search for ' + co.getAttribute("name") + ' clubs" alt="List this county\'s clubs" onmouseout="this.style.cursor=\'default\';" onmouseover="this.style.cursor=\'pointer\';" onclick="document.getElementById(\'searchinput\').value = \'county:' + co.getAttribute("name") + '\'; searchclubs(0);" class="icon"/><br/>';
  info += '<b>' + co.getAttribute("name") + '</b>';
  tabs.push(info);

  return tabs;
}

function load() {
  var cs = document.cookie;
  var pos = cs.indexOf("txt=");
  if (pos != -1) {
    var start = pos + 4;
    var end = cs.indexOf(";", start);
    if (end == -1) end = cs.length;
    var value = cs.substring(start, end);
    if (value == 1)
      location = "?text=1";
  }

  if (GBrowserIsCompatible()) {

    // Initialise map, set start coordinates, add controls
    map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(53.1, -1.8), 6);
    //map.addControl(new GLargeMapControl());
    //map.addControl(new GMapTypeControl());
    map.enableGoogleBar();
    var uiOptions = map.getDefaultUI();
    uiOptions.controls.scalecontrol = false;
    map.setUI(uiOptions);
    
    //map.setUIToDefault();
    // map.enableScrollWheelZoom();
    map.savePosition();

    pos = cs.indexOf("scrollwheelzoom=");
    if (pos != -1) {
      var start = pos + 16;
      var end = cs.indexOf(";", start);
      if (end == -1) end = cs.length;
      var value = cs.substring(start, end);
      if (value == 1) {
        document.getElementById("mouse_wheel").checked = true;
        map.enableScrollWheelZoom();
      }
    }

    body_resize();
    map.returnToSavedPosition();
    document.getElementById('searchinput').focus();

    manager = new GMarkerManager(map);

    // Load and parse XML file of club data
    var clubs_file = { name:'Club Venues', icon:'marker_club.png'}
    file_init(clubs_file);
    GDownloadUrl("data/clubs.xml", function(data, responseCode) {
      var xml = GXml.parse(data);  
      clubs = xml.documentElement.getElementsByTagName("club");
      for (var i = 0; i < clubs.length; i++) {
        var point = new GLatLng(parseFloat(clubs[i].getAttribute("lat")),
                                parseFloat(clubs[i].getAttribute("long")));
        var icon;
        if (clubs[i].getAttribute("precise") == 1) {
	  if (clubs[i].getAttribute("npyear") > 2005) 
            icon = MapIconMaker.createMarkerIcon({primaryColor: "#ee4444", 
	                                          width:        marker_width, 
						  height:       marker_height, 
						  cornerColor:  "#333333"});
	  else
            icon = MapIconMaker.createMarkerIcon({primaryColor: "#ee4444",
	                                          width:        marker_width, 
						  height:       marker_height});
        }
        else {
	  if (clubs[i].getAttribute("npyear") > 2005) 
            icon = MapIconMaker.createMarkerIcon({primaryColor: "#eebaba", 
	                                          width:        marker_width, 
						  height:       marker_height, 
						  cornerColor:  "#333333"});
	  else
            icon = MapIconMaker.createMarkerIcon({primaryColor: "#eebaba", 
	                                          width:        marker_width, 
						  height:       marker_height});
	}

        manager.addMarker(add_marker(icon, point, 'venue' + i, club_popup, [clubs[i], i], 15, 'CLUB: ' + clubs[i].getAttribute("name")),9);  
      }
      clubs_file.records = clubs.length;
      file_loaded(clubs_file);

    });
    
    // Load and parse XML file of teacher data
    var teachers_file = { name:'Teachers', icon:'marker_b.png'};
    file_init(teachers_file);
    GDownloadUrl("data/teachers.xml", function(data, responseCode) {
      var xml = GXml.parse(data);
      teachers = xml.documentElement.getElementsByTagName("club");
      for (var i=0; i < teachers.length; i++) {
        var point = new GLatLng(parseFloat(teachers[i].getAttribute("lat")),
                                parseFloat(teachers[i].getAttribute("long")));
        icon = MapIconMaker.createMarkerIcon({primaryColor: "#0088ee", 
	                                      width:        marker_width, 
					      height:       marker_height});
        manager.addMarker(add_marker(icon, point, 'teacher' + i, teacher_popup, [teachers[i], i], 13, 'TEACHER: ' + teachers[i].getAttribute("forename") + ' ' + teachers[i].getAttribute("surname")),9);
      }
      teachers_file.records = teachers.length;
      file_loaded(teachers_file);
    });

    // Load and parse XML file of county data
    var county_file = { name:'Counties', icon:'co_green.png'};
    file_init(county_file);
    GDownloadUrl("data/county.xml", function(data, responseCode) {
      var xml = GXml.parse(data);
      counties = xml.documentElement.getElementsByTagName("detail");
      for (var i=0; i < counties.length; i++) {
        var point = new GLatLng(parseFloat(counties[i].getAttribute("lat")),
                                parseFloat(counties[i].getAttribute("long")));
        manager.addMarker(add_co_marker(icon_green, point, null, county_popup, [counties[i], i]), 6, 8);
      }
      county_file.records = counties.length;
      file_loaded(county_file);
    });

    // Load and parse XML file of session data
    var sessions_file = { name:'Club Sessions', icon:'clock.png'};
    file_init(sessions_file);
    GDownloadUrl("data/sessions.xml", function(data, responseCode) {
      var xml = GXml.parse(data);
      sessions = xml.documentElement.getElementsByTagName("club");
      sessions_file.records = sessions.length;
      file_loaded(sessions_file);
    });

    // Load and parse XML file of attribute data
    var attributes_file = { name:'Club Facilities', icon:'tea.png'};
    file_init(attributes_file);
    GDownloadUrl("data/attributes.xml", function(data, responseCode) {
      var xml = GXml.parse(data);
      attributes = xml.documentElement.getElementsByTagName("club");
      attributes_file.records = attributes.length;
      file_loaded(attributes_file);
      searchclubs(0);
    });

    // Controls the clicking of the map to generate coordinates
    GEvent.addListener(map,"click", function(overlay, point) {     
      if (document.getElementById("location").checked == true) {
        var myHtml = "The point you clicked is at...<br/><br/>";
	myHtml += "Latitude: " + point.lat() + "<br/>Longitude: " + point.lng();
	myHtml += '<br/><br/>You can use this information to<br/> fine-tune the location of your venue.<br/><a href="mailto:michael@ebu.co.uk">Email Michael</a> with the details.';
        map.openInfoWindow(point, myHtml);
      }
    });

    GEvent.addListener(manager, "changed", function() {
      np_refresh();
    });

  }

}

function file_init(obj) {
  var html = document.getElementById("info").innerHTML;
  var find = new RegExp('</table>', 'i');
  html = html.replace(find, '<tr><td align="center"><img class="icon" title="' + obj.name + '" alt="' + obj.name + '" src="icons/' + obj.icon + '"/></td><td>' + obj.name + ' loading...</td></tr></table>');
  document.getElementById("info").innerHTML = html;
}

function file_loaded(obj) {
  var html = document.getElementById("info").innerHTML;
  var find = new RegExp(obj.name + ' loading...', 'i');
  html = html.replace(find, obj.name + ' (loaded ' + obj.records + ' records)');
  document.getElementById("info").innerHTML = html;
}

// Create a search result in the search list
function create_result(icon, text, search, zoom) {
  return '<span class="searchresult" onmouseout="this.style.cursor=\'default\';" onmouseover="this.style.cursor=\'pointer\';" onclick="GEvent.trigger(map, \'' + zoom + '\');"><img src="icons/' + icon + '"/> ' + text.replace(search, '<span class="highlight">$1</span>') + '</span><br/>';
}

// Create an arrow for the search list
function create_arrow(dir, count) {
  return '<img src="icons/' + dir + '.png" onmouseout="this.style.cursor=\'default\';" onmouseover="this.style.cursor=\'pointer\';" onclick="searchclubs(' + count + ');"/><br/>';
}

// Controls the awesomely funky search box
function searchclubs(carry) {
  document.getElementById("results").innerHTML = searchclubs_a(carry);
}

function searchclubs_a(carry) {
  var unit = 12;
  var count = 0;
  var find = new RegExp('(' + document.getElementById("searchinput").value + ')', 'i');

  var str = "";

  if (document.getElementById("searchinput").value.length == 0) {
    str = "<b>Welcome to the EBU Map!</b><br/><br/>";
    str += "There are three ways you can search:<br/><br/>";
    str += "1. Type your postcode into the search box above and hit return, or click the binoculars.<br/><br/>";
    str += "2. If you know the name of the club or teacher you're looking for, type it in the box and then click the links that appear.<br/><br/>";
    str += "3. Zoom in to your area of the map and click the markers that appear.<br/><br/>";
    str += 'Further information <a href="http://ebustaff.blogspot.com/2008/08/map-to-help-your-quiz-efforts.html">here</a> and <a href="http://ebustaff.blogspot.com/2008/10/ebu-map-improvements.html">here</a>.';
    return str;
  }

  if (carry > 0) {
    str += create_arrow('up', carry - unit);
  }
  else {
    str += '<span class="searchresult" onmouseout="this.style.cursor=\'default\';" onmouseover="this.style.cursor=\'pointer\';" onclick="findpostcode();"><img src="icons/search.png" title="Search for the entered text" alt="Search for the entered text"/></span><br/>';
  }

  // Search club names first
  for (var i = 0; i < clubs.length; i++) {
    if (clubs[i].getAttribute("name").match(find)) {
      count++;
      if (count == carry + unit + 1) {
        str += create_arrow('down', count - 1);
	return str;
      }
      else if (count > carry) {
        str += create_result('club_small.png', 
	                     clubs[i].getAttribute("name"), 
			     find, 
			     'zoom venue' + i);
      }
    }
  }

  // Then look for teachers' names
  for (var i = 0; i < teachers.length; i++) {
    var name = teachers[i].getAttribute("forename") + ' ' + teachers[i].getAttribute("surname");
    if (name.match(find)) {
      count++;
      if (count == carry + unit + 1) {
        str += create_arrow('down', count - 1);
	return str;
      }
      else if (count > carry) {
	str += create_result('teacher_small.png', 
	                     name, 
			     find, 
			     'zoom teacher' + i);
      }
    }
  }

  // Next, try club contact names
  for (var i = 0; i < clubs.length; i++) {
    var name = clubs[i].getAttribute("contact");
    if (name.match(find)) {
      count++;
      if (count == carry + unit + 1) {
        str += create_arrow('down', count - 1);
	return str;
      }
      else if (count > carry) {
	str += create_result('contact_small.png', name, find, 'zoom venue' + i);
      }
    }
  }

  // Finally, check whether the user entered 'county:' syntax
  for (var i = 0; i < clubs.length; i++) {
    if (!find.source.match(/^\(county:/i)) break;

    var name = 'county:' + clubs[i].getAttribute("county");
    if (name.match(find)) {
      count++;
      if (count == carry + unit + 1) {
        str += create_arrow('down', count - 1);
	return str;
      }
      else if (count > carry) {
	str += create_result('club_small.png', clubs[i].getAttribute("name"), find, 'zoom venue' + i);
      }
    }
  }
  
  return str;
}

// Function to resize the map when the user resizes the window.
// Called on load too.
function body_resize() {
  var width = 0;
  var height = 0;

  if (typeof window.innerWidth != 'undefined') {
    width = window.innerWidth;
    height = window.innerHeight;
  }
  else if (typeof document.documentElement != 'undefined'
        && typeof document.documentElement.clientWidth !=
        'undefined' && document.documentElement.clientWidth != 0) {
    width = document.documentElement.clientWidth;
    height = document.documentElement.clientHeight;
  }
  else {
    width = document.getElementsByTagName('body')[0].clientWidth;
    height = document.getElementsByTagName('body')[0].clientHeight;
  }
  
  width -= 360;
  height -= 100;
  if (width < 500) width = 500;
  if (height < 550) height = 420;
  else height -= 130;
  document.getElementById("map").style.width = width + 'px';
  document.getElementById("map").style.height = height + 'px';
  map.checkResize();
}

// Geocodes the postcode/place name that a user 
// enters into the box and zooms the map there
function findpostcode() {
  geo.getLatLng(document.getElementById("searchinput").value, function(point) {
    map.setZoom(11);
    map.panTo(point);
  });
}

function np_refresh() {
  if (document.getElementById("np").checked) {
    GEvent.trigger(map, "hideNP");
  }
  else {
    GEvent.trigger(map, "showNP");
  }
}

function mouse_wheel() {
  if (document.getElementById("mouse_wheel").checked) {
    map.enableScrollWheelZoom();
    document.cookie = "scrollwheelzoom=1; max-age=" + (60*60*24*365);
  }
  else {
    map.disableScrollWheelZoom();
    document.cookie = "scrollwheelzoom=0; max-age=" + (60*60*24*365);
  }
}
    

