function centerElement(id) {

// Due to different browser naming of certain key global variables, we need to do three different tests to determine their values

// Determine how much the visitor had scrolled
var scrolledX, scrolledY;
if( self.pageYOffset ) {
  scrolledX = self.pageXOffset;
  scrolledY = self.pageYOffset;
} else if( document.documentElement && document.documentElement.scrollTop ) {
  scrolledX = document.documentElement.scrollLeft;
  scrolledY = document.documentElement.scrollTop;
} else if( document.body ) {
  scrolledX = document.body.scrollLeft;
  scrolledY = document.body.scrollTop;
}

// Determine the coordinates of the center of the page

var centerX, centerY;
if( self.innerHeight ) {
  centerX = self.innerWidth;
  centerY = self.innerHeight;
} else if( document.documentElement && document.documentElement.clientHeight ) {
  centerX = document.documentElement.clientWidth;
  centerY = document.documentElement.clientHeight;
} else if( document.body ) {
  centerX = document.body.clientWidth;
  centerY = document.body.clientHeight;
}


var leftOffset = scrolledX + (centerX - 250) / 2;
var topOffset = scrolledY + (centerY - 200) / 2;

  document.getElementById(id).style.top = topOffset + "px";
  document.getElementById(id).style.left = leftOffset + "px";
 // document.getElementById(id).style.display = "block";
}

  
function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = "";
}

function changeContent(el, newstring) {
  el.value = newstring;
}


/*
 * This function parses ampersand-separated name=value argument pairs from
 * the query string of the URL. It stores the name=value pairs in 
 * properties of an object and returns that object. Use it like this:
 * 
 * var args = getArgs();  // Parse args from URL
 * var q = args.q || "";  // Use argument, if defined, or a default value
 * var n = args.n ? parseInt(args.n) : 10; 
 */
function getArgs() {
    var args = new Object();
    var query = location.search.substring(1);     // Get query string
    var pairs = query.split("&");                 // Break at ampersand
    for(var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('=');          // Look for "name=value"
        if (pos == -1) continue;                  // If not found, skip
        var argname = pairs[i].substring(0,pos);  // Extract the name
        var value = pairs[i].substring(pos+1);    // Extract the value
        value = decodeURIComponent(value);        // Decode it, if needed
        args[argname] = value;                    // Store as a property
    }
    return args;                                  // Return the object
}


function replaceAll(checkMe,toberep,repwith){

  var temp = checkMe;
  var i = temp.indexOf(toberep);

  while(i > -1){
    temp = temp.replace(toberep, repwith);
    i = temp.indexOf(toberep, i + repwith.length + 1);
  }
  return temp;
}

function combineFields(){
	clearDefault(document.search_form.keywords);

	document.search_form.I_DSC.value = document.search_form.categories.value + ' ' + document.search_form.keywords.value + ' ' + document.search_form.organization.value + ' ' + document.search_form.photographer.value;
	return true;
}

//not sure any of these are currently used:
//Top 10 custom JavaScript functions of all time
//http://www.dustindiaz.com/top-ten-javascript

//attaches all your events to the onload event handler 
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}