function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i];
   var rel = anchor.getAttribute("rel");
   if (anchor.getAttribute("href") && rel)
	if(anchor.getAttribute("rel").match(/\bexternal\b/)) 
     anchor.target = "_blank";
 } 
} 



function elementHasClass(element, className)
{
	return element.className==className
				|| element.className.indexOf(className+' ')!=-1
				|| element.className.indexOf(' '+className)!=-1;
}

function addClassToElement(element, className)
{
	if(!elementHasClass(element, className))
	{
		if(element.className!="")
			element.className+=" "+className;
		else
			element.className=className;
	}
}

function removeClassFromElement(element, className)
{
	element.className = element.className.replace(new RegExp("^((?:.*\\s)?)"+className+"((?:\\s.*)?)$"), "$1$2");
}

function setupSelectOnFocusTextBox(textboxId, defaultText)
{
  var textbox = document.getElementById(textboxId);
  textbox.defaultText= defaultText;
  textbox.onfocus = function()
  {
    if(this.value == this.defaultText)
      this.value = "";
    else
      this.select();
  }
  textbox.onblur = function()
  {
  	if(this.value == "")
  		this.value = this.defaultText;
  }
}

function setupDropDown(parentElementId, dropDownElementId)
{
  var parentElement = document.getElementById(parentElementId);
  var dropDownElement = document.getElementById(dropDownElementId);
  parentElement.dropDownElement = dropDownElement;
  parentElement.onmouseover = function()
  {
    this.dropDownElement.style.left = (this.offsetLeft + 10) + 'px';
    removeClassFromElement(this.dropDownElement, "subnavmainhidden");
  }
  parentElement.onmouseout = function()
  {
    addClassToElement(this.dropDownElement, "subnavmainhidden");
  }
}

function setupDraw(drawElementId, openCloseLinkId, distanceToMove)
{
    var animationDuration = 0.25;
    var drawElement = document.getElementById(drawElementId);
    var openCloseElement = document.getElementById(openCloseLinkId);
    
    var openAnimation = new YAHOO.util.Motion(drawElementId, {points: { by: [0, distanceToMove] } }, animationDuration);
    var closeAnimation = new YAHOO.util.Motion(drawElementId, {points: { by: [0, -distanceToMove] } }, animationDuration);
    
    openCloseElement.openAnimation = openAnimation;
    openCloseElement.closeAnimation = closeAnimation;
    openCloseElement.drawIsOpen = false;
    openCloseElement.onclick = function()
    {
        if(this.drawIsOpen)
        {
            //Close the draw
            this.closeAnimation.animate();
            this.innerHTML = "Open Search";
            this.title = "Open the search bar";
        }
        else
        {
            //Open the draw
            this.openAnimation.animate();
            this.innerHTML = "Close Search";
            this.title="Close the search bar";
        }
        this.drawIsOpen = !this.drawIsOpen;
        return false;
    }
}

function setupExpander(expandingElementId, openCloseLinkId, noun)
{
	if(parent.document.URL.indexOf('print') > 0)
		return;
    var animationDuration = 0.25;
    var expandingElement = document.getElementById(expandingElementId);
    var openCloseElement = document.getElementById(openCloseLinkId);
    
    var openAnimation = new YAHOO.util.Anim(expandingElementId, {height: { to: 0 } }, animationDuration);
    var closeAnimation = new YAHOO.util.Anim(expandingElementId, {height: { to: 0 } }, animationDuration);
    
    expandingElement.style.height = "0";
    
    openCloseElement.openAnimation = openAnimation;
    openCloseElement.closeAnimation = closeAnimation;
    openCloseElement.expandingElement = expandingElement;
    openCloseElement.expanderIsOpen = false;
    openCloseElement.onclick = function()
    {
        if(this.expanderIsOpen)
        {
            //Close the expander
            this.closeAnimation.animate();
            this.title = "Click to view " + noun;
        }
        else
        {
            //Open the expander
            this.expandingElement.style.visibility = "hidden";
            this.expandingElement.style.height = "auto";
            var expanderHeight = this.expandingElement.offsetHeight;
            this.expandingElement.style.height = "0";
            this.expandingElement.style.visibility = "visible";
            this.openAnimation.attributes.height = { to : expanderHeight };
            this.openAnimation.animate();
            this.title = "Click to hide " + noun;
        }
        this.expanderIsOpen = !this.expanderIsOpen;
        return false;
    }
}