function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent){
  var r = obj.attachEvent("on"+evType, fn);
  return r;
  } else {
    return false;
  }
}
      
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && (
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}

function setInputBehavior(id, behavior) {
  if (!document.getElementById) return;
  var inputBox = document.getElementById(id);
  if (inputBox) {
    if (inputBox.tagName.toLowerCase() == 'input') {
      if (inputBox.value.length > 0) {
        if (behavior == 'show-hide') setInputBehaviorShowHide(inputBox);
        else if (behavior == 'hide') setInputBehaviorHide(inputBox);
        else if (behavior = 'highlight') setInputBehaviorHighlight(inputBox);
      }
    }
  }
}

function setInputBehaviorShowHide (inputBox) { /* should not be called directly, needs to go through setInputBehavior to be unobtrusive */
  var defaultString = inputBox.value;
  inputBox.onfocus = 
    function() {
      if(this.value == defaultString) {
        this.value = "";
      }
    };
  inputBox.onblur = 
    function updateSearchFieldOnBlur() {
      if(this.value.length == 0) {
        this.value = defaultString;
      }
    };
}

function setInputBehaviorHide (inputBox) { /* should not be called directly, needs to go through setInputBehavior to be unobtrusive */
  var defaultString = inputBox.value;
  inputBox.onfocus = 
    function() {
      if(this.value == defaultString) {
        this.value = "";
      }
    };
}

function setInputBehaviorHighlight (inputBox) {
  var defaultString = inputBox.value;
  inputBox.onfocus = 
    function() {
      if(this.value == defaultString) {
        this.select();
      }
    };
}

function inputBehaviors() {
	if (!document.getElementsByTagName) return;
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i < inputs.length; i++) {
		var input = inputs[i];
    if (input.type == 'text') {
      if (input.className == 'behavior-show-hide') setInputBehaviorShowHide(input);
      else if (input.className == 'behavior-hide') setInputBehaviorHide(input);
      else if (input.className == 'behavior-highlight') setInputBehaviorHighlight(input);
    }
	}
}

function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}

function openBannerWindow(url,width,height) {
  var bannerWindow = window.open(url,'','scrollbars=yes,menubar=yes,height='+height+',width='+width+',resizable=yes,toolbar=no,location=yes,status=yes');
}

function openWindow(theSite) {
  newwin = window.open(theSite,"","height=550,width=600,scrollbars=no,resizable=no,toolbar=no,status=no,fullscreen=no");
  return false;
}

window.onload = function() {
  inputBehaviors();
  externalLinks();
}