function trimmed(sText) {
	var tmpStr=new String(sText);
	return tmpStr.strip();
}

function equalsIgnoreCase(arg1, arg2) {
	return ( (new String(trimmed(arg1))).toLowerCase() == (new String(trimmed(arg2))).toLowerCase());
}

function isEmpty(sText) {
	return trimmed(sText)=="";
}

validNumericChars = "0123456789";

function isNumeric(sText,allowMinus) {
	var tmpStr=trimmed(sText);
	for(var i=0; i < tmpStr.length; i++) {
		var char = tmpStr.charAt(i);
		if(allowMinus && i==0 && char=='-') {
			continue;
		}
 		if(validNumericChars.indexOf(char) == -1) {
 			return false;
		}
	}
	return true;
}

// @param radioGroupName - the name of the radiobox inputs group
// @param formName       - form's name, is optional, otherwise the documents first form is used
// @return the value if the selected radiobox or null if none is selected
function getCheckedRadio(radioGroupName,formName) {
	if(typeof formName == "undefined") {
		var form=$(document.forms[0]);
	} else {
		var form=$(document.forms[formName]);
	}
	var radios=form.getInputs("radio",radioGroupName);
	for(var i=0;i<radios.length;i++) {
		if(radios[i].checked==true) {
			return radios[i].value
		}
	}
	return null;
}

Element.addMethods({
	scrollTo: function(element, left, top){
		var element = $(element);
		if (arguments.length == 1){
			var pos = element.cumulativeOffset();
			window.scrollTo(pos[0], pos[1]);
		} else {
			element.scrollLeft = left;
			element.scrollTop  = top;
		}
		return element;
	}
});

Effect.Scroll = Class.create();
Object.extend(Object.extend(Effect.Scroll.prototype, Effect.Base.prototype), {
	initialize: function(element) {
		this.element = $(element);
		if(!this.element) throw(Effect._elementDoesNotExistError);
		this.start(Object.extend({x: 0, y: 0}, arguments[1] || {}));
	},
	setup: function() {
		var scrollOffsets = (this.element == window) 
			? document.viewport.getScrollOffsets() 
			: Element._returnOffset(this.element.scrollLeft, this.element.scrollTop) ;
		this.originalScrollLeft = scrollOffsets.left;
		this.originalScrollTop  = scrollOffsets.top;
	},
	update: function(pos) {
		this.element.scrollTo(Math.round(this.options.x * pos + this.originalScrollLeft), Math.round(this.options.y * pos + this.originalScrollTop));
	}
});
document.observe('dom:loaded', function(event) {
	$$('a[href*="#"]').each(function(anchor){
		anchor.observe('click', function(event) {
			var anchorName=this.href.split('#')[1];
			var anchors=$$("a");
			for(var i=0;i<anchors.length;i++) {
				var name=new String(anchors[i].name);
				if(name.endsWith(anchorName)) {
					var delta = anchors[i].offsetTop - document.viewport.getScrollOffsets().top;
					var updateUrl = function(){ location.href = this.href }.bind(this);
					new Effect.Scroll(window, { y: delta, afterFinish: updateUrl, duration: 0.7 });
					Event.stop(event);
					break;
				}
			}
		});
	});
});
