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+$/,"");
}

function jumpToLocation(location) {
	if (location.length == 0) {
		alert("Please select a value from the list.");
		return;
	}
	document.location.href = location;
}

var windowMap = new Array();

function popupWindow(url, targetId, width, height, toolbar, scrollbars, location, statusbar, menubar, resizable) {
	var oldWindow = windowMap[targetId];
	if ((oldWindow != null) && (window != oldWindow)) {
		oldwindow.close();
	}
	if (targetId == null) {
		targetId = 'default_' + (new Date()).getTime();
	}
	if (width == null) {
		width = window.width;
	}
	if (height == null) {
		height = window.height;
	}
	if (toolbar == null) {
		toolbar = 0;
	} 
	if (scrollbars == null) {
		scrollbars = 0;
	}
	if (location == null) {
		location = 0;
	}
	if (statusbar == null) {
		statusbar = 0;
	}
	if (menubar == null) {
		menubar = 0;
	}
	if (resizable == null) {
		resizable = 0;
	}
	windowMap[targetId] = window.open(
		url, 
		targetId, 
		'toolbar=' + toolbar + ',' +
			'scrollbars=' + scrollbars + ',' +
			'location=' + location + ',' +
			'statusbar=' + statusbar + ',' +
			'menubar=' + menubar + ',' +
			'resizable=' + resizable + ',' +
			'width=' + width + ',' +
			'height=' + height
	);
}

function validEmail(emailString) {
	if (emailString.trim().length > 0) {
		if (emailString.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
			// The email is OK.
			return true;
		} else {
			return false;
		}
	}
}

function isNumeric(inputString) {
	var numbers = "0123456789";
	var s = inputString.trim();
	var c = "";
	for (i = 0; i < s.length; i++) {
		c = s.charAt( i );
		if (numbers.indexOf(c) == -1) {
			return false;
		}
	}
	return true;
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		
		alert("Due to system requirements, you cannot enter more than " + maxlimit + " characters\n\nWe apologize for any inconvenience.");
	}
	
	// update 'characters left' counter
	countfield.value = maxlimit - field.value.length;
}
	

