
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}

String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}

function submitForm(formIndex, action) {
	var actionField = document.forms[formIndex].elements["action"];
	if (actionField) {
		actionField.value = action;
	}
	document.forms[formIndex].submit();
}

function submitOnchange(form, action) {
	var actionField = form.elements["action"];
	if (actionField) {
		actionField.value = action;
	}
	form.submit();
}

function isTextareaFocused(formIndex) {
	var arrElements = document.getElementsByTagName("textarea");
	if (arrElements != null) {
		if (arrElements.length > 0) {
			// as far as there is no simple way to get the currently focused
			// object, always return true if a textarea exists.
			return true;
		}
	}
	return false;
}

function changeLanguage( toLanguage )
{	
	var loc = document.location.toString();
	
	if (loc.search(/.locale=../) > -1) {
		loc = loc.replace(/.locale=../g, "");
	}
	
	if (loc.indexOf("?") > -1 || loc.indexOf("&") > -1) {
		document.location = loc + "&locale=" + toLanguage;
	} else {
		document.location = loc + "?locale=" + toLanguage;
	}
}

function removeUrlParameter(url, parameterName) {
	
	if (url.indexOf("?") > -1) {
		var indexParameters = url.indexOf('?');
		var oldUrl = url.substring(0, indexParameters);
		var args = url.substring(indexParameters + 1);
		var arrArgs = args.split('&');
		
		var newArgs = '';
		var isFirst = true;
		for (var i = 0; i < arrArgs.length; i++) {
			
			if (arrArgs[i].indexOf(parameterName) == -1) {
				if (isFirst == false) {
					newArgs = newArgs + '&';
				}
				
				newArgs = newArgs + arrArgs[i];
				
				isFirst == false;
			}
			
		}
		
		url = oldUrl + '?' + newArgs;
		
	}
	return url;
}

function startList() {
	if (document.all && document.getElementById) {
	
		var navIdx = 0;
		while (document.getElementById("navi" + navIdx) != null) {
			navRoot = document.getElementById("navi" + navIdx);
		
			if (null != navRoot) {
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" over";
						}
						node.onmouseout=function() {
							this.className=this.className.replace(" over", "");
						}
					}
				}
			}
			navIdx++;
		}
		
	}
}
