// Clear Input Value After Search
function eraseVal() {
document.getElementById('gsearch-input').value="";
}

// Image Rollovers
// An alternate to using the recommended CSS functionality
// when the latter is not a possibility for some reason.

// The JavaScript remembers the original image URL, and thus a file
// does not need to be passed unless you're rolling out to an image
// that is different from the one originally loaded.

var oldImages = new Array();
var imgPath   = 'images/'; // a path to the images if all the same (else blank)

function imageSwap(imgName, newImage, setPath) {

  if( newImage != undefined && newImage != null ) {
  // Store the old image for when it needs to be reverted
  var oldImageParts  = new Array();

    oldImageURL        = document.getElementsByName(imgName)[0].src;
    oldImageParts      = oldImageURL.split('/');
    oldImages[imgName] = oldImageParts[oldImageParts.length - 1];

  } else {
  // Set the image to be loaded to the old (original) value
    if( oldImages[imgName] != undefined ) {
      newImage = oldImages[imgName];
    } else {
      // Not enough data to work with
      return false;
    }
  }

  // Swap the path if requested
  imgPath = (setPath != undefined) ? setPath : imgPath;

  // Swap the image with another
  document.getElementsByName(imgName)[0].src = imgPath + newImage;

} // ! imageSwap function




// Preload Images
// Works in most browsers

// First load an array with all the images we want to preload
function preloadImages(imageArray, imageFolder) {

  // Count how many items there are to preload
  var numPreload = imageArray.length;

  // Loop through all the items and preload them
  for(loops = 0; loops < numPreload; loops++) {
    thisImage     = new Image();
    thisImage.src = imageFolder + imageArray[loops];
  }

} // ! image preloader


// Google Copyright for Search Engine

function clearText(thefield) {
  thefield.style.backgroundImage = "url(http://www.santa-barbara-wineries.com/images/input-bg.gif)";
} 
function replaceText(thefield) {
   thefield.style.backgroundImage = "url(http://www.santa-barbara-wineries.com/images/bg-input-google.gif)";
}

// Preload Second Search Background Image
var loadImages = new Array();

imgPath = 'http://www.santa-barbara-wineries.com/images/';

loadImages[0]  = 'input-bg.gif';

preloadImages(loadImages, imgPath);


// New Window (Pop-up)
// Opens a new window to the passed specifications

var defaultwidth  = 500;
var defaultheight = 350;

function newWindow(url, name, width, height, settings) {

  // URL is required
  if( url == 'undefined' ) { return false; }

  // Set defaults (if data has not been passed)
  name     = (name     == 'undefined') ? 'window' : name;
  width    = (width    == 'undefined') ? defaultwidth  : width;
  height   = (height   == 'undefined') ? defaultheight : height;
  settings = (settings != 'undefined') ? settings : 'toolbar=0';

  // Open the window
  window.open(url, name, 'width=' + width + ', height=' + height + ', ' + settings);

} // ! newWindow