/* This handy function from Simon Willison allows you to stack up 'window.onload' events <br />
without them stepping on each other's toes. It's explained here - http://www.sitepoint.com/blog-post-view.php?id=171578 */

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


/* popup code.. modify to your needs*/
function popup(strURL,strType,strHeight,strWidth) {
var strOptions="";
if (strType=="console") strOptions="resizable,scrollbars,height="+strHeight+",width="+strWidth;
window.open(strURL, '', strOptions);
}


/* unobtrusive javascript links for popups, and target=_blank */
function windowLinks() {
    if(!document.getElementsByTagName) {
         return;
    }
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
         var anchor = anchors[i];
         var relIndex = anchor.rel;
	if (relIndex){
		var relSplit = relIndex.split("|");
		/* XHTML compliant target attribute */
		 if (relSplit[0] == "external") {
			anchor.target = "_blank";
			//anchor.className = "external";
			cssjs('add',anchor,'external');
			anchor.title = "Load in new window: "+ anchor.href;
			/* XHTML compliant popup attribute */
   		} else if (relSplit[0] == "popup") {
			//anchor.className = "popup";
			cssjs('add',anchor,'popUp');
			anchor.title = "Link loads in Popup Window";
			anchor.popupWidth = relSplit[1];
			anchor.popupHeight = relSplit[2];
			anchor.onclick = function() {
				popup(this.href,'console',this.popupWidth,this.popupHeight);return false;};
			}
		}
	}
}

addLoadEvent(function() {
	windowLinks();	
	TB_init();
	//otherFunctions();
	//goHere();
});

/*
    * cssjs
    * written by Christian Heilmann (http://icant.co.uk) :: Modified by Mike Marsh
    * eases the dynamic application of CSS classes via DOM
    * parameters: action a, object o and class names c1 and c2 (c2 optional)
    * actions: swap exchanges c1 and c2 in object o
    *       add adds class c1 to object o
    *       remove removes class c1 from object o
    *       check tests if class c1 is applied to object o
    * example: cssjs('swap',document.getElementById('foo'),'bar','baz');
    */
function cssjs(a,o,c1,c2) {
	switch (a){
		case 'swap':
		/*	o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);*/
			o.className=o.className.replace(c1,c2);
         break;
		case 'add':
			if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
			break;
		case 'replace':
			o.className=c1;
			break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
			break;
		case 'check':
			return new RegExp('\\b'+c1+'\\b').test(o.className)
			break;
	}
}
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

