function searchFocus(el) {
	if (el.value == 'Search') {
		el.value = '';
	}
}
function searchBlur(el) {
	if (el.value == '') {
		el.value = 'Search';
	}
}
function searchSubmit() {
	var searchfor = document.searchfm.search.value;
	if (searchfor=='Search' || searchfor=='') {
		alert('Please enter a search term.');
		return false;
	} else if (searchfor.length < 2) {
		alert('Search terms must be at least 2 letters long.');
		return false;
	}
	return true;
}

function disableEnter(e) {
	var key = (window.event ? window.event.keyCode : e.which);
	return (key != 13);
}

function processclick(e) {
	e = e || (window.event || {});
	var rel, el = e.srcElement || e.target;
	while (el && el.tagName != 'BODY') {
		if (rel = el.getAttribute('rel')) {
			location.href = rel;
			break;
		}
		el = el.parentNode;
	}
}
	
onload = function() {
	document.getElementsByTagName('body').item(0).onclick = processclick;
}

function formatNum(n, dp, commas) {
	if (dp == 0) {
		return Math.round(n).toString();
	}
	var bNeg = (n < 0);
	if (bNeg) {
		n = Math.abs(n);
	}
	n = Math.round(n*Math.pow(10,dp));
	n = n.toString();
	while(n.length < dp+1) {
		n = '0'+n;
	}
	var preDP = n.substring(0, n.length-dp);
	if (commas) {
		var commaBits = '';
		while (preDP.length > 3) {
			commaBits = ',' + preDP.substr(preDP.length-3, 3) + commaBits;
			preDP = preDP.substring(0, preDP.length-3);
		}
		preDP += commaBits;
	}
	n = preDP+'.'+n.substring(n.length-dp);
	if (bNeg) {
		return '-'+n;
	} else {
		return n;
	}
}

String.prototype.trim = function (what) {
	if (typeof what == 'undefined') {
		return this.replace(/^\s*/,"").replace(/\s*$/,"");
	} else {
		var reg1 = new RegExp('^'+what+'*');
		var reg2 = new RegExp(what+'*$');
		return this.replace(reg1,"").replace(reg2,"");
	}
}

var debug_init = new Array();
/* Outputs a string in top left of browser window */
/* Optionally <line> specifies a line offset */
function debugOut(str, line) {
	line = (line == null) ? 0 : line;
	if (!debug_init[line]) {
		var el = document.createElement('div'); 
		el.id = 'debug_div_'+line;     
		with(el.style) {
			if (document.all) {
				position = 'absolute';
			} else {
				position = 'fixed';
			}
			top = (5+40*line)+'px';
			left = '5px';
			backgroundColor = '#FF0000';
			color = '#FFFFFF';
			padding = '5px';
			border = 'solid 1px #000000';
		}
		el.innerHTML = '&nbsp;';
		document.body.appendChild(el); 
		debug_init[line] = true;
	} else {
		var el = document.getElementById('debug_div_'+line);
	}
	el.innerHTML = str;
}