// Disable right click
if (window.addEventListener){
  window.addEventListener("load", disableRightClick, false);
} else if (window.attachEvent){
  window.attachEvent("onload", disableRightClick);
}

var clickmessage="Use of site images withough explicit permission from Healdsburg Property Management is prohibited.";

function disableelementclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (true){
alert(clickmessage);
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
else if (document.getElementById)
if (e.which==3&&true) {
setTimeout("alert(clickmessage)",0)
}
}


function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName=="IMG"){
alert(clickmessage);
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
else if (document.getElementById)
if (e.which==3&&e.target.tagName=="IMG")
setTimeout("alert(clickmessage)",0)
}

function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

function disableRightClick() {
if (document.all){
document.onmousedown=disableclick
for (var i_tem = 0; i_tem < document.images.length; i_tem++)
document.images[i_tem].galleryimg='no'
}
else if (document.getElementById)
document.onmouseup=disableclick
else if (document.layers)
associateimages()

var header = document.getElementById('header');
if (header) {
 header.onmouseup=disableelementclick;
}

}
// Popup window functions

function openWindow(url, width, height) {
 openNamedWindow(url, width, height, "Sonoma_County_Vacations");
}

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 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);
        }
        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 addPointToMap(lat, lon, html, zoom) {

    map = new GMap(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());

    // Old API seems to have zoom constants backwards from new one.
    zoom = 17 - zoom;

    var point = new GPoint(lon, lat);
    map.centerAndZoom(point, zoom);

    var marker = createMarker(point, 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 = "";
   }
  }
 }
}