/*
CLEAR LABELS
Clears input fields with the class "hide_label" whenever a user clicks on the field.
*/

if (window.attachEvent) {window.attachEvent('onload', addActions);}
else if (window.addEventListener) {window.addEventListener('load', addActions, false);}
else {document.addEventListener('load', addActions, false);} 

function addActions() {
	var els = getElementsByClass('hide_label');
	for(i=0;i<els.length;i++) {
		var el = els[i];
		el.startValue = el.value;
		el.className = 'hide_label greyed_label';
		el.onfocus = function() {
			if(this.value == this.startValue) {
				this.value = '';
				this.className = 'hide_label';
			}
		}
		el.onblur = function() {
			if(!this.value) {
				this.value = this.startValue;
				this.className = 'hide_label greyed_label';
			}
		}
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/*
EXTERNAL LINKS
Makes links with the attribute rel="external" open a new window
*/

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.target = "_blank";
 }
}
window.onload = externalLinks;
