/**
 * Javascript functionality; Fundynamic.com
 * 
 * @author Stefan Hendriks
 * 
 */

/**
 * Remove text from an input tag. The element is given with
 * 'object'.
 * 
 * @param initial The value that is default (and will be removed, ie
 * 					"Enter your name")
 * @param object  The element where this applies to (an input element)
 */
function removeText(initial, object) {
	//var object = returnObjById(id, this.document);
	if (object.value == initial) {
		object.value = "";
	}
}


///** 
// * Return object by id; from root document.
// * 
// * @param id
// */
//function returnObjById(id) {
//	return returnObjById( id , document)
//}

/**
 * Return object by id; from given document.
 * 
 * @param id 
 * @param document
 */
function returnObjById( id , theDocument)	
{
	// when no document given; use default
	if (theDocument == null ||
		theDocument == "undefined") theDocument = document;

	var returnVar = null;		
    if (theDocument.getElementById) {
        returnVar = theDocument.getElementById(id);
    } else if (theDocument.all) {
        returnVar = theDocument.all[id];
    } else if (theDocument.layers) {
        returnVar = theDocument.layers[id];
    }
    
    return returnVar;
}

/**
 * Toggle visibility of element, set display to none if it is not none. Else
 * set it to block.
 */
function toggleElementVisibilityById(id) {
	var el = returnObjById(id);
	
	if (el != null) {
		if (el.style.display != "none") {
			el.style.display = "none";
		} else {
			el.style.display = "block";
		}
	} else {
		alert("Element with id '" + id + "' not found");
	}
}

function showElementById(id) {
	var el = returnObjById(id);
	if (el != null) {
		el.style.display = 'block';
	} else {
		alert("Element with id '" + id + "' not found");
	}
}

function hideElementById(id) {
	var el = returnObjById(id);
	if (el != null) {		el.style.display = 'none';
	} else {
		alert("Element with id '" + id + "' not found");
	}
}

// Add load event, to load a function after page has loaded.
// from: http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/**
 * Method to go one step back in history
 */
function goBack() {
	history.go(-1);
}
