if (typeof SAB === 'undefined' || !SAB) {
	var SAB = {};
}

if (typeof SAB.widget === 'undefined' || !SAB.widget) {
	SAB.widget = {};
}


(function () {

	var Dom = YAHOO.util.Dom;

	SAB.Dom = {
		getObject : function (node) {
			if (typeof node === 'string') {
				return Dom.get(node);
			}
			return node;
		}
		, deleteNode : function (node) {
			node = this.getObject(node);
			return node.parentNode.removeChild(node);
		}
		, replaceNode : function (oldNode, newNode) {
			oldNode = this.getObject(oldNode);
			newNode = this.getObject(newNode);
			return oldNode.parentNode.replace(oldNode, newNode);
		}
		, copyStyle : function (dest, src, style) {
			dest = this.getObject(dest);
			src = this.getObject(src);
			Dom.setStyle(dest, style, Dom.getStyle(src, style));
		}
		, createNode : function (type, id) {
			var node = document.createElement(type);
			node.setAttribute('id', id);
			return node;
		}
	};

})();


// allgemeine Arrayfunktionen
(function () {
	
	if (Array.remove === 'undefined' || !Array.remove) {
		Array.prototype.remove = function (elem) {
			var stack = [];
			var popElem = null;
			while (this.length > 0) {
				popElem = this.pop();
				if (popElem === elem) {
					break;
				}
				stack.push(popElem);
			}
			while (stack.length > 0) {
				popElem = stack.pop();
				this.push(popElem);
			}
		};
	}
	
	if (Array.inArray === 'undefined' || !Array.inArray) {
		Array.prototype.inArray = function (elem) {
			var retVal = false;
			for (var i = 0; i < this.length; i++) {
				if (this[i] === elem) {
					retVal = true;
					break;
				}
			}
			return retVal;
		};
	}
	
})();


// allgemeine Stringfunktionen
(function (){
	
	if (String.ltrim === 'undefined' || !String.ltrim) {
	 	String.prototype.ltrim = function() {
	 		var a = this + '';
	 		a = a.replace(/^\s+/g, '');
	 		return a;
	 	};
	}
	
	if (String.rtrim === 'undefined' || !String.rtrim) {
		String.prototype.rtrim = function () {
			var a = this + '';
			a = a.replace(/\s+$/g, '');
			return a;
		};
	}

	if (String.trim === 'undefined' || !String.trim) {
		String.prototype.trim = function () {
		 	return this.rtrim().ltrim();
		};
	}

	if (String.isEMail === 'undefined' || !String.isEMail) {
		String.prototype.isEMail = function () {
			var mail_check = /^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/;
			return this.match(mail_check)!== null; 
		};
	}

	if (typeof String.utf8_encode === 'undefined' || !String.utf8_encode) {
		String.prototype.utf8_encode = function() {
  			return unescape(encodeURIComponent(this));
		};
	}

	if (typeof String.utf8_decode === 'undefined' || !String.utf8_decode) {
		String.prototype.utf8_decode = function() {
  			return decodeURIComponent(escape(this));
		};
	}
})();
