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"; 
		}
	}
}

function hoverMouseOver(e) {
	this.src = this.overSrc;
}

function hoverMouseOut(e) {
	this.src = this.outSrc;
}

function hoverImages() {
	if (!document.getElementsByTagName) return; 
	var images = document.getElementsByTagName("img");
	if (images != undefined) hoverize(images);
	var inputs = document.getElementsByTagName("input");
	if (inputs != undefined) hoverize(inputs);
}

function isClass(e, className) {
	var classes = e.className.split(' ');
	for (var i = 0; i < classes.length; i++) {
		if (classes[i] == className) return true;
	}
	return false;
}

function hoverize(elements) {
	for (var i = 0; i < elements.length; i++) {
		var image = elements[i];
		if(isClass(image, 'hover_image')) {
			var n = image.src.lastIndexOf('.');
			var prefix = image.src.substring(0, n);
			var postfix = image.src.substring(n);
			image.outSrc = image.src;
			image.overSrc = prefix + '_over' + postfix;

			image.onmouseover = hoverMouseOver;
			image.onmouseout = hoverMouseOut;
		}
	}
}

String.prototype.isEmail = function() {
	var emailTestRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	return this.match(emailTestRegex) != null;
};

String.prototype.isNumeric = function() {
	return this.match('^[0-9]+$') != null;
};


// two string methods from http://www.ditchnet.org/wp/2005/04/04/i-want-my-javalang/

/**
 *  String convenience method to trim leading and
 *  trailing whitespace.
 *  @returns string
 */
String.prototype.trim = function () {
    return this.replace(/^s*/,'')
                     .replace(/s*$/,'');
};

/**
 *  String convenience method for checking if the
 *  end of this string equals a given string.
 *
 *  @returns boolean
 *  @throws IllegalArgumentException for parameters
 *                          not of type String
 */
String.prototype.endsWith = function (s) {
    if ('string' != typeof s) {
        throw('IllegalArgumentException: Must pass a ' +
            ' string to String.prototype.endsWith()');
    }
    var start = this.length - s.length;
    return this.substring(start) == s;
};

function popup(pageUrl, width, height) {
	var left = screen.width / 2 - width / 2;
	var top = screen.height / 2 - height / 2;
	
	window.open(pageUrl, '', 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ",scrollbars=yes,resizable=no");
}
