// ==================================================================================================
// ON LOAD EVENT LOADER
// ==================================================================================================
// enabling multiple onload functions via addLoadEvent method 
// courtesy of Simon Willison: 
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
// --------------------------------------------------------------------------------------------------
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// add functions you want to call with window.onload
addLoadEvent(function() {
	initPopupLinks();
});

// ==================================================================================================
// POP-UPS
// ==================================================================================================
// causes all links inside a div id="GridView1" to open in a new
// window depending on whether or not a check box (openWindow) is checked
// --------------------------------------------------------------------------------------------------
function initPopupLinks(){
	if(document.getElementById("GridView1")){
		var linkContainer = document.getElementById("GridView1");
		var links = linkContainer.getElementsByTagName("a");
		for (var i = 0; i < links.length; i++){
			if(links[i].target != "_self" && (links[i].href).search("javascript") == -1){
				links[i].onclick = popUp;
			}
		}
		
		// temporary hack to stop the first column from wrapping
		// incredibly fragile...!!!!
		links = linkContainer.getElementsByTagName("tr");
		links[3].cells[0].style.whiteSpace="nowrap";
		return true;
	}
}

// creates a popup window
function popUp(){
	var state = new Boolean();
	
	if(!document.getElementById("openWindow").checked) {
		popUp = window.open(this.href);
		if (window.focus) {popUp.focus()}
		state = false;
	} else {
		state = true;
	}
	
	return state;
}