var newwindow = '';

function popitup(url)
{
	if (!newwindow.closed && newwindow.location)
	{
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url,'name','height=600,width=600,resizable=yes,scrollbars=yes');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}

function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}

function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

function addBehaviors(){
	//find all of the links with a class of popup and
	//make their onclick action to open in a popup window
	var aryPopupLinks = getElementsByClassName( document , 'popup' );
	
	for(linkIdx = 0; linkIdx < aryPopupLinks.length; ++linkIdx ){
		var popupLink = aryPopupLinks[linkIdx].href;
		
		aryPopupLinks[linkIdx].href = "javascript:void(0);";
		
		addEvent( aryPopupLinks[linkIdx] , 'click' , function(){popitup(popupLink)} );
	}
}


//run the addBehaviors function when the page loads
addLoadEvent(addBehaviors);

