addLoadEvent(setEvents);

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

function getElementsByClass(theClass) {
	var gotCollection = new Array();
	var gotAll = new Array();
	gotAll = document.getElementsByTagName("*");
	j=0;
	for (i=0; i<gotAll.length; i++) {
		if ((gotAll[i].className==theClass)||(gotAll[i].className.search(" " + theClass)!=-1)||(gotAll[i].className.search(" " + theClass + " ")!=-1)||(gotAll[i].className.search(theClass + " ")!=-1)) {
			gotCollection[j]=gotAll[i];
			j++;
		}
	}
	return gotCollection;
}

function toggleShowHideDivs(e,a) {
	var theElement = document.getElementById(e);
	var theAnchor = document.getElementById(a);
	if (theElement.style.visibility == "hidden") {
		theElement.style.visibility = "visible";
		theElement.style.position = "static";
		theAnchor.className = "toggleImageLinkOn";
		theAnchor.title = "click to close";
	}
	else {
		theElement.style.visibility = "hidden";
		theElement.style.position = "absolute";
		theAnchor.className = "toggleImageLinkOff";
		theAnchor.title = "click to open";
	}
}
function setShowHideDivs() {
	var anchors = getElementsByClass("toggleImageLinkOff");
	for(var i=0; i < anchors.length; i++) {
		//update links
		var a = anchors[i];
		var href = a.href;
		var index = href.indexOf("#") + 1;
		var divIdValue = href.substring(index);
		var anchorLink = "anchorLink" + i;
		a.setAttribute("id",anchorLink);
		a.setAttribute("title","click to open");
		href = "javascript:toggleShowHideDivs('" + divIdValue + "','" + anchorLink + "');";
		a.setAttribute("href",href);
		//hide DIVs
		document.getElementById(divIdValue).style.visibility = "hidden";
		document.getElementById(divIdValue).style.position = "absolute";
	}
}

//email validation
function validEmail(email) {
	invalidChars = " /:,;"
	if (email == "") {
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) != -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}


