/* 	misc.js - General usefule js functions
------------------------------------------------------------------------*/


// addLoadEvent function as seen at http://simon.incutio.com/archive/2004/05/26/addLoadEvent
// allows you to stack functions and apply them to the onload event and also means you 
// can abstract onload functions from the html
// I've added an argument 'arg' for onload functions with an argument
// Could probably be better implemented with 'arguments[]'
function addLoadEvent(func,arg) {
	
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func(arg);
    }
  }
}


/* Get current page URL */
function getPageUrl(){
 	if (!document.getElementById("pageurl")) return false;
	var field = document.getElementById("pageurl");
	field.value = document.location.href.replace(/\&/g,'&amp;');
	if (!document.getElementById("pageurl2")) return false;
	var field2 = document.getElementById("pageurl2");
	field2.value = document.location.href.replace(/\&/g,'&amp;');
 	if (!document.getElementById("forwardurl")) return false;
	var forwardfield = document.getElementById("forwardurl");
	var url = forwardfield.value+document.location.href;
	forwardfield.value = url.replace(/\&/g,'&amp;');
}



/* Toggle the visibility of an element */
function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = 'block';
	}
}



