function setElementClass(obj, classText) 
{ 
	if(identity = document.getElementById(obj))
		identity.className = classText;
}

function externalAndPopUpLinks()
{
	var defW = 660;
	var defH = 490;
	/* todo - check for missing or invalid width and height settings and set a default value for the popup*/
	var popupTitle = 'popup';
	var scrW = screen.availWidth;
    var scrH = screen.availHeight;
    var anchors = document.getElementsByTagName("a"); 
    var theAnchor, i, target, relIndex, relSplit, linkDest; 
    for (i=0;i<anchors.length;i++)
	{
		theAnchor = anchors[i];
		/* does this anchor have a rel attribute set? */
		if( theAnchor.getAttribute("href") && theAnchor.getAttribute("rel") != null)
		{
			linkDest = theAnchor.getAttribute("href"); 
			relIndex = theAnchor.getAttribute("rel"); 
			relSplit = relIndex.split(" ");
			switch(relSplit[0]) 
			{
				case 'external' :
					// Set to open the page in a new window
					applyBlankTarget(theAnchor);
				break;
				case 'popup' :
					/* if popup parameters missing fill in with defaults */
					if(relSplit[1]==null){relSplit[1]='popup';}
					if(relSplit[2]==null){relSplit[2]=defW;}
					if(relSplit[3]==null){relSplit[3]=defH;}
					theAnchor.setAttribute("rel" , relSplit[0] + ' ' + relSplit[1] + ' ' + relSplit[2] + ' ' + relSplit[3]);
					theAnchor.title+=relSplit[1];
					theAnchor.title+=' (popup that opens in new window)';
					popupW=relSplit[2];
					popupH=relSplit[3];
					theAnchor.title+=' ' + popupW + 'x' + popupH;
					theAnchor.onclick=function() {newWin=window.open(this.href,this.rel.split(" ")[1],'location=no,menubar=no,status=no,resizable=yes,toolbar=no,scrollbars=yes,width=' + this.rel.split(" ")[2] + ',height=' + this.rel.split(" ")[3]);if(window.focus){newWin.focus()} return false;}
				break;
			}
		}
	}
}

function applyBlankTarget(elementRef)
{
	// Put a span after the a and put the external bg image in it
	var externalSpan = document.createElement('span');
	var spanTextNode = document.createTextNode(' ');
	externalSpan.appendChild(spanTextNode);
	externalSpan.className = 'external';
	elementRef.parentNode.insertBefore(externalSpan, elementRef.nextSibling);
	
	// Set to open the page in a new window
	elementRef.title +=' (Opens in a new window)';
	elementRef.target = '_blank';
}