String.prototype.trim = function() {
  return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""));
}
String.prototype.startsWith = function(prefix) {
return (this.indexOf(prefix) == 0);
};
String.prototype.endsWith = function(suffix) {
var startPos = this.length - suffix.length;
if (startPos < 0) {
    return false;
}
return (this.lastIndexOf(suffix, startPos) == startPos);
};


//Submit the form if the key that fired this
//  was the 'Enter' key
// In the Input field just add onKeyPress="return SubmitOnEnter(this,event);"
function SubmitOnEnter(buttonId,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13){
		var btn = Get(buttonId);
		if(btn && btn.click){
			btn.click();
			return false;
		}	
	}

	return true;
}

function Get(id){
	return document.getElementById(id);
}

function Hide(id){
	var el = Get(id);
	if(el)
		el.style.display = 'none';
}

function Show(id){
	var el = Get(id);
	if(el)
		el.style.display = 'inline';			
}

function exists(object){
	return (typeof object != 'undefined');
}

function HasValidImageExtension(fileNm){
	var validExts = new Array(5);
	validExts[0] = '.jpg';
	validExts[1] = '.jpeg';
	validExts[2] = '.tif';
	validExts[3] = '.tiff';
	validExts[4] = '.jif';
	
	for(var ext in validExts){
		if(fileNm.toLowerCase().endsWith(validExts[ext]))
			return true;
	}
	
	return false;
}
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function GoToURL(sUrl){
	document.location.href = sUrl;
}

function SetTextAreaMaxLength(el,maxlength){
	if(el.value.length > maxlength) 
		el.value = el.value.substr(0,maxlength);
}

function getElementAttribute(elid,attribute){
	var el = Get(elid);
	if(!el) return null;
	
	if(typeof eval('el.' + attribute) != 'undefined') return eval('el.' + attribute);
	if(typeof el.getAttribute(attribute) != 'undefined') return el.getAttribute(attribute);
	//if those didn't work it ain't there
	return null;
}