//String Trims (http://www.somacon.com/p355.php) Public Domain
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

//http://www.thescripts.com/forum/thread89672.html
String.prototype.isNumeric = function() {
	return typeof this != "boolean" && this !== null && !isNaN(+ this); //why not regex?  Scientific notation, pi, e, etc...
}
String.prototype.isInteger = function() {
	if (this.isNumeric()) {
		if (Math.round(this) == this) return true;
	}
	return false;
}

function gid(id) {
	return document.getElementById(id);
}

function fraction_popup(url) {
	var ratio = 0.75;
	var def_x = 800;
	vardef_y = 600;
	parent_x = document.documentElement.clientWidth;
	if (!parent_x) parent_x = document.body.clientWidth;
	if (!parent_x) parent_x = window.innerWidth;
	if (!parent_x) parent_x = def_x;
	parent_y = document.documentElement.clientHeight;
	if (!parent_y) parent_y = document.body.clientHeight;
	if (!parent_y) parent_y = window.innerHeight;
	if (!parent_y) parent_y = def_y;
	var child_x = ratio * parent_x;
	var child_y = ratio * parent_y;
	window.open(url, "pop_window", "status=1, scrollbars=1, width="+child_x+", height="+child_y);
	return false;
}

function colHeightBalance() {
	var height = 0;
	var col;
	var index;
	for (index = 0; index < arguments.length; index++) {
		col = gid(arguments[index]);
		height = Math.max(height, col.offsetHeight);
  }
	for (index = 0; index < arguments.length; index++) {
		col = gid(arguments[index]);
		col.style.height = height+'px';
	}
}

//returns window dimensions as x,y array
//based on code from http://www.javascripter.net/faq/browserw.htm
function windowDimensions() {
	var winW = 1014, winH = 748; //default values
	if (document.body && document.body.offsetWidth) {
		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;
	}
	if (document.compatMode=='CSS1Compat' &&
    document.documentElement &&
			document.documentElement.offsetWidth ) {
		winW = document.documentElement.offsetWidth;
		winH = document.documentElement.offsetHeight;
	}
	if (window.innerWidth && window.innerHeight) {
		winW = window.innerWidth;
		winH = window.innerHeight;
	}
	return { width: winW, height: winH };
}

//function to get the document's height
//from http://james.padolsey.com/javascript/get-document-height-cross-browser/
function getDocHeight() {
  var D = document;
	return Math.max(
									Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
									Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
									Math.max(D.body.clientHeight, D.documentElement.clientHeight)
									);
}

//get an element's position within the document
//taken from http://stackoverflow.com/questions/442404/dynamically-retrieve-html-element-x-y-position-with-javascript
function getOffset( el ) {
	var _x = 0;
	var _y = 0;
	while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
		_x += el.offsetLeft - el.scrollLeft;
		_y += el.offsetTop - el.scrollTop;
		el = el.parentNode;
	}
	return { top: _y, left: _x };
}

