		
	function RTrim(str) {
		return str.replace(/\s+$/,"");
	}

	function Trim(str) {
		return str.replace(/^\s+|\s+$/g,"");
	}

	function LTRim(str) {
		return str.replace(/^\s+/,"");
	}

	function inKey(ev) {
		ev = ev || window.event
		return ev.keyCode || ev.which;
	}	

	function isCurrencyKey(ev, e) {
		if (isNumberKey(ev, e)) {
			return true; 		
		} else {
			char = String.fromCharCode(inKey(ev));
			if (char == '$') {
				return true;
			}
		}	
		return false;		
	}
	
	function isNumberKey(ev, e) {
		char = String.fromCharCode(inKey(ev));
		if (isDigit(char)) {
			return true;
		} else {
			if (char == '.') {
				alert("char is .");
				if (!(/\./.test(e.value))) {
					return true;
				} else {
					// if char under cursor is . then move right
					npos = getCaretPos(e);

					if (e.value.charAt(npos) == '.') {
						ev.keyCode = null;
						setCaretPos(e);
						return true;
					}	
				}
			}
			return false;
		}		
	}


	function isDigit(str) {
		return /\d/.test(str);
	}
	
	function isNumber(str) {
	// accept 239, 321.99, .923, 333.	
		return /^\d*[\.]?\d*$/.test(str);
	}	


	function isCurrency(str) {
	// accept 239, 321.99, .923, 333. or $233, $321.00....etc	
		return /^\$\d*[\.]?\d*$/.test(str) || isNumber(str);
	}	

	function getCaretPos(e){
		if (typeof e.selectionStart != "undefined") {
			return e.selectionStart;
		} else if (document.selection) {
			return Math.abs(document.selection.createRange().moveStart("character",-1000000));
		}
	}	

	function setCaretPos(e) {
		var range = e.createTextRange();
		range.collapse(true);
		range.moveEnd('character', npos+1);
		range.moveStart('character', npos+1);
		range.select();
	}	


	function fmtround(num,noofdec) {
		return Math.round(num*Math.pow(10,noofdec))/Math.pow(10,noofdec);
	}

	function fmtcurrency(num,noofdec) {
		return "$"+Math.round(num*Math.pow(10,noofdec))/Math.pow(10,noofdec);
	}

	function openWindow(theURL,winName,features) { //v2.0
		window.open(theURL,winName,features);
	}	
	
	function show(title, item, outputid) {
		if (!outputid) outputid = "divshow";
		outdiv = document.getElementById(outputid);
		if (clear) {
			show.clear(outputid) }
		if (typeof(item) == 'object') {
			detail = PEMStatus(item);
		} else {
			detail = item;
		}
		lccontent = "<b>"+title+"</b><br />" + detail;	
		outdiv.innerHTML = outdiv.innerHTML + "<br />" + lccontent;	
		}
		
	show.clear = function(outputid) { 
		//outdiv = document.getElementById(outputid);
		outdiv.innerHTML = "";
	}

	function PEMStatus(obj) {
		var lcpem = ""	
		for ( name in obj) {
			lcpem = lcpem + name + " " + obj[name] + "<br />";
		}
		return lcpem
	}

	$e = function(id) {
		return (document.getElementById) ? document.getElementById(id): document.all[id];
		}

	form = function(id) {
		this.id = id;
		this.serialize = function() {
			elms = $e(this.id).getElementsByTagName('input');
			//this.elms = nodeListArr(elms,ctrlfilter);
			this.elms = nodeListTrans(elms,ctrlfilter,serialize);
			serialstr = this.elms.join('&');
			return serialstr;
		}
		return ;
	}

	function ctrlfilter(elm) {
		if (elm.type == 'text' || elm.type == 'hidden') {
			return true;
		} else {
			return false;
		}		
	}	
	
	function serialize(elm) {
		if (elm.id) { 
			return encodeURIComponent(elm.id)+'='+encodeURIComponent(elm.value); 
		} else {
			if (elm.name) { 
				return encodeURIComponent(elm.name)+'='+encodeURIComponent(elm.value); 
			} else {
			 	return null; 
			} 	
		};
	}	


	function nodeListArr(ndlist,filter) {
		arry = [];
		if (filter) { 
			for(var i=0;i<ndlist.length;i++) { 
				if (filter(ndlist[i])) {
					arry.push(ndlist[i]);
				}
			}
		} else {
			for(var i=0;i<ndlist.length;i++) { 
				arry.push(ndlist[i]);
			}
		}			
		return arry;		
	}

	function nodeListTrans(ndlist,filter,transform) {
		arry = [];
		if (filter) { 
			for(var i=0;i<ndlist.length;i++) { 
				if (filter(ndlist[i])) {
					arry.push(transform(ndlist[i]));
				}
			}
		} else {
			for(var i=0;i<ndlist.length;i++) { 
				arry.push(transform(ndlist[i]));
			}
		}			
		return arry;		
	}
