function openWindow(url, width, height) {
 openNamedWindow(url, width, height, "Beaver_Village");
}

function openNamedWindow(url, width, height,name) {
        height += 50;          
	var sFeatures = "top=50,left=50,height=" + height + ",width=" + width + ",status=yes,scrollbars=yes,resizable=1,menubar=";
	var win = window.open(url,name,sFeatures);
        if (win != null) {
 	 win.focus();
 	 win.resizeTo(width, height);
        }
}

/* Google Maps
 * Nothing here needs to be customized, just drop this code into an external js file.
 */
var map;
var geocoder;

function initGMap(lat, long, zoom, type) {
/* create a new map centered at lat, long */
  map = new GMap2(document.getElementById("map"));
  map.setCenter(new GLatLng(lat, long), zoom);
  map.setMapType(type);
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());
}

function someFn() {
/* create a new map centered at lat, long */
  map = new GMap2(document.getElementById("map"));
  map.setCenter(new GLatLng("0","0"), 8);
  map.setMapType(G_HYBRID_MAP);
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());
}

function showAddress(address, html, zoom) {
  if (!map) {
    geocoder = new GClientGeocoder();
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());    
  }

  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        if (zoom != -1) {
         //map.setCenter(point, zoom);
        }
        map.setCenter(point, zoom);
        map.setMapType(G_HYBRID_MAP);
        
        var marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml(html);
      }
    }
  );
}

/*
function createMarker(point, html) {
     var marker = new GMarker(point);
     GEvent.addListener(marker, 'click', function() {
       marker.openInfoWindowHtml(html);
     });
     map.addOverlay(marker);
     marker.openInfoWindowHtml(html);
}*/

function createMarker(lat, long, html) {
     var marker = new GMarker(new GLatLng(lat, long));
     GEvent.addListener(marker, 'click', function() {
       marker.openInfoWindowHtml(html);
     });
     map.addOverlay(marker);
     marker.openInfoWindowHtml(html);
}


function addPointToMap(lat, lon, html, zoom) {

    map = new GMap(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());

    //map.centerAndZoom(point, zoom);
    map.setCenter(new GLatLng(lat, lon),zoom,G_HYBRID_MAP) ; 

    // Can't set map type unless set center is called
    //map.setMapType(G_HYBRID_MAP);
    //var marker = createMarker(point, html);
    var marker = createMarker(lat, lon, html);
}
/* Greather than or equal to search
 *
 * Step 1: Add this code to an external js file called in the head of your
 * document.
 *
 * Step 2: Build out your form as if it were using the second smc
 * form option - either or logic. Add the field number to the end
 * of the fieldoptionid in the select name: fieldoptionid_103[]. Don't
 * set your select fields to multiple, this defeats the purpose. (If you
 * want to perform an inclusive search using <select multiple> fields, you
 * don't need this js file.) For more information see smc docs:
 * http://help.intrcomm.net/sitepages/pid112.php
 *
 * Step 3: Add a call to your expandSearchOnId to your search form, passing
 * in an array of fields you want to search on:
 * onsubmit="expandSearch([39,91,103])"
 *
 * Additional notes: this script does nothing to sort - you have to do that
 * in your smc preview or search results template. Any manual ordering will
 * break during pagination. This code should not require any customization.
 */

function expandSearch(ids) {
 // Clear out hidden fields to prevent previous searches from interfering.
 clearDynamicForm();

 // Perform search expansion on each id in the array passed to this function. 
 for (var a = 0; a < ids.length; a++) {
  expandSearchOnId(ids[a]);
 }
}

function expandSearchOnId(id) {
 // Look for the form and select box targeted by the id that has been passed in. 
 // We'll perform search expansion based on those options.
 var name = 'fieldoptionid_' + id + '[]';
 
 var forms = document.forms;
 for(var a = 0; a < forms.length; a++) {
  var form = forms[a];
  var elements = form.elements;
  
  for (var b = 0; b < elements.length; b++) {
   var select = elements[b];
   if (select.name ==  name) {
    expandSearchOnSelect(select, form);
   }
  }

  // This forces IE to reprocess form.
  if (form.normalize) {
   form.normalize();
  }   
 }
}


function expandSearchOnSelect(select, form) {
 var selected = false;
 var options = select.options;
 if (options) {
 for (var c = 0; c < options.length; c++) {
  var option = options[c];
  if (option.selected && option.value != "") {
   // If an option is selected, set selected flag so that all options
   // that follow will be added as hidden fields.
   selected = true;
  } else if (selected) {
   // If a selected option was encountered, create a hidden field containing expanded
   // search parameters.
   var input = document.createElement("input");
   input.type = "hidden";
   input.name = select.name;
   input.value = option.value;

   // Set className so that next time this form is submitted we can make sure
   // the last round of hidden fields are removed.
   input.className = "dynamicInput";

   // Add the new hidden field to the form.
   form.appendChild(input);
  }
 }
 }
}

function clearDynamicForm() {
 // Clear the form by searching for input fields with a class name of 
 // dynamicInput. This clears previous search parameters from the form.
 var forms = document.forms;
 for (var a = 0; a < forms.length; a++) {
  var form = forms[a];
  var inputs = form.getElementsByTagName('input');
  for (var b = 0; b < inputs.length; b++) {  
   if (inputs[b].className == 'dynamicInput') {
    alert('Removing: ' + inputs[b].name + ":" + inputs[b].value);
    inputs[b].name = "";
    inputs[b].value = "";
    inputs[b].className = "";
   }
  }
 }
}
