﻿
function js_ClearDefault(thefield) {

    if (thefield.defaultValue == thefield.value)
        thefield.value = ""

}

function LoadMenu() {
    document.getElementById("nav").style.display = 'inline';
  }


  //--- Functions for Google Map API ---


  var mapProperties = new Array();

  function mapProperty(myLat, myLng) {  // the mapProperty Class
    this.lat = myLat;
    this.lng = myLng;
  }

  var searchCentre = new mapProperty(0, 0);

  function addMapProperty(myLat, myLng, myHTML) {  // function to create a mapProperty instance and add it to the mapProperties array
    //alert("addMapProperty " + myHTML);
    if (!isNaN(myLat) && !isNaN(myLng)) {
      mapProperties.push(new mapProperty(myLat, myLng));
    }
  }

  function clearProperties() {
    //alert("clearProperties");
    mapProperties = new Array();
    for (i = 0; i < markers.length; i++) {
      markers[i].setMap(null);
    }
  }

  var map;

  function initialise() {
    //alert("initialise");

    var myLatlng = new google.maps.LatLng(searchCentre.lat, searchCentre.lng);
    var myOptions = {
      zoom: 10,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      streetViewControl: false,
      draggable: true
    }

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    placePropertyMarkersOnMap();
  }

  function placePropertyMarkersOnMap() {

    var bounds = new google.maps.LatLngBounds();
    for (i = 0; i < mapProperties.length; i++) {

      var point = new google.maps.LatLng(mapProperties[i].lat, mapProperties[i].lng);
      var marker = new google.maps.Marker({
        position: point,
        map: map
      });

      bounds.extend(point);
    }
    if (mapProperties.length <= 1) {
      map.setZoom(6);  // avoid zooming in too far to a single property
      //map.setCenter(point);
    } else {
      map.fitBounds(bounds);
    }
  }

  function loadGoogleMapsScript() { // Google Maps 3 API - load the script dynamically then call initialise
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://maps.google.com/maps/api/js?v=3&sensor=false&callback=initialise";
    document.body.appendChild(script);
  }

  function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = func;
    } else {
      window.onload = function () {
        if (oldonload) {
          oldonload();
        }
        func();
      }
    }
  }
