var tmr;

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

window.onload = function() {

	modifyNewWindowLinks();
	hideDottedLines();
	setModalHeight();
}

function modifyNewWindowLinks() {
	//This function looks for all the links with a class of "NewWindow"
	//and will cause them to open in a new window.

	var aTags = document.getElementsByTagName("a");
	for (var x = 0; x < aTags.length; x++) {
		var currTag = aTags[x];
		if (String(currTag.className).indexOf('NewWindow') > -1) {
			currTag.onclick = function(){ window.open(this.href); return false;}
		}
	}
}

function findPos(obj) {
// gets the 'top' and 'left' positions of the object.

  var curtop = 0;
  var curleft = 0;
  if (obj.offsetParent) {
	  while (obj.offsetParent) {
		  curtop += obj.offsetTop;
		  curleft += obj.offsetLeft;
		  obj = obj.offsetParent;
	  }
  }
  else {
	  if (obj.y) curtop += obj.y;
	  if (obj.x) curleft += obj.x;
  }
  var r=Array();
  r[0]=curtop;
  r[1]=curleft;
  return r;
}

function setModalHeight() {
	var o=document.getElementById("modalDiv");
	if (o) {
		var eop1=document.getElementById("eopDiv_lhs");
		var eop2=document.getElementById("eopDiv_rhs");
		var pos1=(eop1)?findPos(eop1):0;
		var pos2=(eop2)?findPos(eop2):0;
		var max=(pos1[0]>pos2[0])?pos1[0]:pos2[0];
		//alert(pos1[0]+' '+pos2[0]+' = '+max);

		o.style.height=(max+50)+"px";
	}
}

function hideDottedLines() {
// hide the 'dotted lines' around the link for links with image-replacement.

	var theahrefs = document.getElementsByTagName("a");

	// fix dotted line thing when link is OnClicked
	for(var x=0;x!=theahrefs.length;x++) {
		//if (theahrefs[x].className!="") alert(theahrefs[x].className);
		if (theahrefs[x].className.indexOf("hideOutline")>-1) {
			theahrefs[x].onfocus = function stopLinkFocus(){ this.hideFocus=true; };
		}
	}
}

function form_autoSubmit() {
// used to submit the "event type" select-box on the schedule page...

	f=document.forms["modeSel"];
	if (f) f.submit();
}