// Global Javascript functions

// April 2006

// If you want to support IE 5 with the getElementsByClassName function you will need to add the following to your js file
Array.prototype.push = ArrayPush;
function ArrayPush(value){
	this[this.length] = value;
}

// Opens a link in a new window when class = linkExternal

function doPopups() {
  if (!document.getElementsByTagName) return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("linkExternal")) {
      links[i].onclick = function() {
        window.open(this.href);
        return false;
      }
    }
  }
}


// Sets the class of an input field to "fieldFocus" on focus or removes the className on blur.
// Will also clear the default field contents

function findField() {
  if (!document.getElementsByTagName) return false;
  //var fieldList = document.getElementsByTagName("input");
  var fieldList = document.getElementById("GeoSearchForm").getElementsByTagName('input');
  for ( var i=0; i < fieldList.length; i++) {
    fieldList[i].onfocus = function() {
      this.className ="fieldFocus";
	  this.value = "";
    }
	fieldList[i].onblur = function() {
      this.className ="";
    }
  }
}


// apply a rounded corner effect specified photos

function roundedImages() {
 var content = document.getElementById('content');
 var imgs = content.getElementsByTagName('img');


 for (var i = 0; i < imgs.length; i++) {         // start loop 
 
// get the src of the image, and find out the file extension
var strSrc = imgs[i].src;
var filetype = strSrc.substring(strSrc.lastIndexOf('.'), strSrc.length);

// only apply the rounding effect to photos
if (filetype == '.jpg') {

   var wrapper = document.createElement('div');  // Create the outer-most div (wrapper)
   wrapper.className = 'wrapper';                // Give it a classname - wrapper
   wrapper.style.width = imgs[i].width+'px';     // give wrapper the same width as the current img
   var original = imgs[i];                       // take the next image  
   /* Swap out the original img with our wrapper div (we'll put it back later) */
   if(original.parentNode.tagName.toUpperCase()=='A') original = original.parentNode; // if you link the image this will help the script find the right parent wrapper
   original.parentNode.replaceChild(wrapper, original);
   // IE crash fix - c/o Joshua Paine - http://fairsky.us/home


   /* Create the four other inner nodes and give them classnames */
   var tl = document.createElement('div');
   tl.className = 'tl';
   var br = document.createElement('div');
   br.className = 'br';
   var tr = document.createElement('div');
   tr.className = 'tr';
   var bl = document.createElement('div');
   bl.className = 'bl';
   /* Glue the nodes back inside the wrapper */
   wrapper.appendChild(tl);
   wrapper.appendChild(tr);
   wrapper.appendChild(bl);
   wrapper.appendChild(br);
   /* And glue the img back in after the DIVs */
   
   wrapper.appendChild(original);
 }
}
}
/* Run the functions once the page has loaded: */

window.onload=function(){
	roundedImages();
	doPopups();
	findField();
}