/************************************
 JPure JavaScript Framework
 ************************************
 Copyright: Robert Engelhardt
 Email: engelhardt@more-style.de
 Version: 1.2
 ************************************/

var JPure = {

	Version : '1.2',

	Load : function () {

		/********************************
		 Load Moduls
		 ********************************/

		var offset = null;
		var script = document.getElementsByTagName('script');

		for (var x = 0; x < script.length; ++x) {

			if ((offset = script[x].src.indexOf('JPure.js?')) > -1) {

				var path   = script[x].src.substr(0, offset);
				var moduls = script[x].src.split('?')[1].split(',')

				for (var y = 0; y < moduls.length; ++y) {

					var head  = document.getElementsByTagName('head')[0];
					var modul = document.createElement('script');

					with (modul) {

						src  = path + moduls[y] + '/' + moduls[y] + '.js';
						type = 'text/javascript';

					} head.appendChild(modul);
				
				} break;
			}
		}


		/********************************
		 Core Function Class
		 ********************************/

		window.Class = function(name, properties) {

			if (this[name] == null) {

				if (properties[name] != null && properties[name] instanceof Function) {
				
					this[name] = properties[name];
				
				} else this[name] = function() {};
				
				this[name].prototype = {

					Set : function (property, value) {

						if (!(this[property] instanceof Function)) {

							this[property] = value;
						}

						return this[property];
					},

					Get : function (property) {

						return this[property];
					},

					Unset : function () {

						for (var x = 0; x < arguments.length; ++x) {

							
							if ((this[arguments[x]] instanceof Function) && !this.MethodExists(x)) {

								delete this[arguments[x]];
								
							} else delete this[arguments[x]];
						}
					},
					
					MethodExists : function (method) {
						
						for (var x = 0; x < this.Methods.length; ++x) {
						
							if (this.Methods[x] == method) {
							
								return true;	
							}	
							
						} return false;
					}
					
				}; this[name].prototype.Methods = ['Set', 'Get', 'Unset', 'MethodExists'];

				if (properties instanceof Object) {

					for (var x in properties) {

						if (this[name].prototype[x] == null) {

							if (name != x) {

								this[name].prototype[x] = properties[x];
							}
							
							if ((properties[x] instanceof Function)) {
							
								this[name].prototype.Methods[this[name].prototype.Methods.length] = x;
							}
						}
					}

				} return true;

			} else {

				window.Extends(this[name].prototype, {

					Set : function (property, value) {

						if (!(this[property] instanceof Function)) {

							this[property] = value;
						}

						return this[property];
					},

					Get : function (property) {

						return this[property];
					},

					Unset : function () {

						for (var x = 0; x < arguments.length; ++x) {

							if ((this[arguments[x]] instanceof Function) && !this.MethodExists(x)) {

								delete this[arguments[x]];
								
							} else delete this[arguments[x]];
						}
					},
					
					MethodExists : function (method) {
						
						for (var x = 0; x < this.Methods.length; ++x) {
						
							if (this.Methods[x] == method) {
							
								return true;	
							}	
							
						} return false;
					}

				}); this[name].prototype.Methods = ['Set', 'Get', 'Unset', 'MethodExists'];
				
				return window.Extends(this[name].prototype, properties);
			}
		};



		/********************************
		 Core Function Objects
		 ********************************/

		window.Objects = function(name, properties) {

			if (this[name] == null) {

				this[name] = {
					
					Set : function (property, value) {

						if (!(this[property] instanceof Function)) {

							this[property] = value;
						}

						return this[property];
					},

					Get : function (property) {

						return this[property];
					},

					Unset : function () {

						for (var x = 0; x < arguments.length; ++x) {

							if ((this[arguments[x]] instanceof Function) && !this.MethodExists(x)) {

								delete this[arguments[x]];
								
							} else delete this[arguments[x]];
						}
					},
					
					MethodExists : function (method) {
						
						for (var x = 0; x < this.Methods.length; ++x) {
						
							if (this.Methods[x] == method) {
							
								return true;	
							}	
							
						} return false;
					}
					
				}; this[name]['Methods'] = ['Set', 'Get', 'Unset', 'MethodExists'];

				if (properties instanceof Object) {

					for (var x in properties) {

						if (this[name][x] == null) {

							if (this[name][x] instanceof Function) {
							
								this[name]['Methods'][this[name]['Methods'].length] = x;
								
							} this[name][x] = properties[x];
						}
					}

				} return true;

			} else {

				window.Extends(eval(name), {

					Set : function (property, value) {

						if (!(this[property] instanceof Function)) {

							this[property] = value;
						}

						return this[property];
					},

					Get : function (property) {

						return this[property];
					},

					Unset : function () {

						for (var x = 0; x < arguments.length; ++x) {

							if ((this[arguments[x]] instanceof Function) && !this.MethodExists(x)) {

								delete this[arguments[x]];
								
							} else delete this[arguments[x]];
						}
					},
					
					MethodExists : function (method) {
						
						for (var x = 0; x < this.Methods.length; ++x) {
						
							if (this.Methods[x] == method) {
							
								return true;	
							}	
							
						} return false;
					}

				});  this[name]['Methods'] = ['Set', 'Get', 'Unset', 'MethodExists'];
				
				return window.Extends(eval(name), properties);
			}
		};



		/********************************
		 Core Function Extends
		 ********************************/

		window.Extends = function (object, properties, restriction) {

			if (object != null) {

				for (var x in properties) {

					if (restriction instanceof Array) {

						for (var y = 0; y < restriction.length; ++y) {

							if (x == restriction[y] && object[x] == null) {

								if (object['Methods'] != null && (properties[x] instanceof Function)) {
								
									object['Methods'][object['Methods'].length] = x;
										
								} object[x] = properties[x];
							}
						}

					} else {

						if (object['Methods'] != null && (properties[x] instanceof Function)) {
								
							object['Methods'][object['Methods'].length] = x;
										
						} object[x] = properties[x];
					}

				} return true;

			} return false;
		};
	}

}; JPure.Load();

Extends (window, {

	Typeof : function (object) {

		if (object == null)
			return 'null';

		if (typeof object == 'undefined')
			return 'undefined';

		if (object.nodeName && object.nodeType == 1)
			return 'element';

		if (object.nodeName && object.nodeType == 3 && (!/\S/).test(object.nodeValue))
			return 'textnode';

		if (object instanceof Function)
			return 'function';

		if (object instanceof Array)
			return 'array';

		if (typeof object == 'object')
			return 'object';

		if (typeof object == 'number' && isFinite(obj))
			return 'number';

		if (typeof object == 'string')
			return 'string';

		if (typeof object == 'boolean')
			return 'boolean';
	},

	Empty : function (value) {

		return (value == '' || value == null || value == false || value == '0' || value == 0) ? true : false;
	},

	Isset : function (variable) {

		return (this[variable] == null) ? false : true;
	},

	SetEvent : function (event, eventFunction, before) {

		switch ((event = event.toLowerCase())) {

			case 'onload' :
			case 'onunload' :
			case 'onbeforeunload' :
			case 'onbeforeprint':
			case 'onafterprint' :
			case 'ondragdrop':
			case 'onclose':
			case 'onabort' :
			case 'onerror' :
			case 'onresize' :
			case 'onblur' :
			case 'onscroll' :
			case 'onfocus' :

				var store = window[event];

				if (!Empty(store)) {

					window[event] = function () {

						if (before == null) {
							store();
							eventFunction();
						} else {
							eventFunction();
							store();
						}
					};

				} else window[event] = eventFunction;

				return true;

			break;

			default :

				if (Typeof(document[event]) != 'undefined') {

					var store = document[event];

					if (!Empty(store)) {

						document[event] = function () {

							if (before == null) {
								store();
								eventFunction();
							} else {
								eventFunction();
								store();
							}
						};

					} else document[event] = eventFunction;

				} return true;

			break;

		} return false;
	},

	EnabledFlash : function () {

		if (navigator.mimeTypes.length > 0) {

			return navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin != null;

		} else if (window.ActiveXObject) {

			try {

				return Typeof(new ActiveXObject('ShockwaveFlash.ShockwaveFlash')) == 'object';

			} catch (e) { return false; }

		} return false;
	},

	Body : function () {

		return (document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : ((document.body) ? document.body : null);
	}
});

Extends (Array.prototype, {

	Search : function (needle) {

		var x = 0;

		while (this.length > x) {

			if (this[++x] == needle) {

				return x;
			}

		} return false;
	},

	Indexof : function (needle) {

		var x = 0;

		while (this.length > x) {

			if (this[++x].indexOf(needle) > -1) {

				return x;
			}

		} return false;
	},

	Push : function () {

		for (var x = 0; x < arguments.length; ++x) {

			if (this.push instanceof Function) {

				this.push(arguments[x]);

			} else this[this.length] = arguments[x];

		} return this;
	},

	MultiConact : function () {

		var array = this;

		for (var x = 0; x < arguments.length; ++x) {

			if (arguments[x] instanceof Array) {

				array = array.concat(arguments[x]);
			}

		} return array;
	}
});

Class ('Ajax', {

	Ajax : function () {

		this.Data 		= null;
		this.AjaxFrameName 	= 'ajaxFrame';
		this.ProxyUrl 		= 'scripts/JPure/Ajax/Proxy.php?';
	},

	Send : function (url, method, type, proxy) {

		this.Set('Data', null);

		var self   	= this;
		var request 	= false;

		if (type != 'text' && type != 'xml') {

			type = 'text';
		}

		if (proxy) {

			url = this.Get('ProxyUrl') + ((type == 'text') ? 'text:' : 'xml:') + escape(url);
		}

		if (window.XMLHttpRequest) {

			request = new XMLHttpRequest();

		} else if (window.ActiveXObject) {

			try  {

				request = new ActiveXObject("Msxml2.XMLHTTP");

			} catch (e) {

				try {

					request = new ActiveXObject("Microsoft.XMLHTTP");

				} catch(e) { }
			}

		}

		if (typeof request == 'object') {
			
			request.onreadystatechange = function () {

				if (request.readyState == 4) {

					if (request.status < 400) {

						if (type == 'xml') {

							self.XMLParse(request.responseXML);

						} else if (type == 'text') {

							self.Data = {text : request.responseText};
						}

					} else return false;
				}
			};
			
			if(method.toLowerCase() == "post") {

				request.open("POST", url, true);
				request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				request.send(null);

			} else {

				request.open("GET", url, true);
				request.send(null);
			}

		} else if (document.createElement instanceof Function) {

			if (document.getElementById(this.ajaxFrameName)) {

				window.document.body.removeChild(document.getElementById(this.ajaxFrameName));
			}

			var iFrame = document.createElement('IFRAME');

			with (iFrame) {

				style.width 		= '1px';
				style.height 		= '1px';
				style.border 		= 'none';
				style.position		= 'absolute';
				style.left		= '0px';
				style.top		= '0px';
				style.visibility	= 'hidden';

				src			= url;
				id			= this.AjaxFrameName;
				name			= this.AjaxFrameName;
				frameborder		= '0';
			}

			document.body.appendChild(iFrame);

			window.clearInterval(this.ajaxFrameTimeout);
			window.onFrameLoad = {

				count 			: 0,
				tries 			: 100,
				self 			: this,
				type 			: type,
				ajaxFrameName 		: this.AjaxFrameName,

				status : function () {

					if (window.parent[this.ajaxFrameName]) {

						if (window.parent[this.ajaxFrameName].document.childNodes.length != null) {

							if (this.type == 'xml') {

								this.self.XMLParse(window.parent[this.ajaxFrameName].document.firstChild.parentNode);

							} else if (this.type == 'text') {

								this.self.Data = {text : window.parent[this.ajaxFrameName].document.innerHTML};
							}

							this.count = this.tries;
						}
					}

					if ((++this.count) > this.tries) {

						with (window) {

							clearInterval(this.self.ajaxFrameTimeout);
							document.body.removeChild(document.getElementById(this.ajaxFrameName));
							onFrameLoad = null;

						} this.self.Unset('ajaxFrameTimeout');
					}
				}
			}

			this.ajaxFrameTimeout = window.setInterval('window.onFrameLoad.status()', 500);
		}

	},

	XMLParse : function (node, xmlObject) {

		if (xmlObject == null) {

			xmlObject = this.Data = {};
		}

		for (var x = 0; x < node.childNodes.length; ++x) {

			if (node.childNodes[x].tagName != null) {

				if (xmlObject[node.childNodes[x].tagName] != null && !(xmlObject[node.childNodes[x].tagName] instanceof Array)) {

					xmlObject[node.childNodes[x].tagName] = [xmlObject[node.childNodes[x].tagName]];
				}

				var nodeValue = (node.childNodes[x].firstChild == null || node.childNodes[x].firstChild.nodeValue == null) ? '' : node.childNodes[x].firstChild.nodeValue;
				    nodeValue = nodeValue.replace(/\s\s+|\r|\n|\t/g, ' ');
				    nodeValue = (nodeValue == ' ') ? '' : nodeValue;

				if (nodeValue != '') {

					if (xmlObject[node.childNodes[x].tagName] instanceof Array) {

						xmlObject[node.childNodes[x].tagName][xmlObject[node.childNodes[x].tagName].length] = nodeValue;

					} else xmlObject[node.childNodes[x].tagName] = nodeValue;

				} else {

					if (xmlObject[node.childNodes[x].tagName] instanceof Array) {

						xmlObject[node.childNodes[x].tagName][xmlObject[node.childNodes[x].tagName].length] = (node.childNodes[x].childNodes.length) ? {} : '';

					} else xmlObject[node.childNodes[x].tagName] = (node.childNodes[x].childNodes.length) ? {} : '';
				}
			}

			if (node.childNodes[x].childNodes.length > 0)
			{

				if (xmlObject[node.childNodes[x].tagName] instanceof Array) {

					this.XMLParse(node.childNodes[x], xmlObject[node.childNodes[x].tagName][xmlObject[node.childNodes[x].tagName].length - 1]);

				} else {
					//alert(node.childNodes[x].tagName + ' - - ' + xmlObject[node.childNodes[x].tagName])
					this.XMLParse(node.childNodes[x], xmlObject[node.childNodes[x].tagName]);
				}
			}
		}
	},

	Call : function(callback) {

		window.clearInterval(this.timeout);
		window.controll = {

			count 		: 0,
			tries 		: 100,
			self 		: this,
			callback 	: callback,
			arguments 	: arguments,

			interval : function () {

				if (this.self.Data != null) {

					for (var x in this.self.Data) {

						if (x != null) {

							window.clearInterval(this.self.timeout);

							if (Function.apply instanceof Function && this.arguments.length > 1) {

								for (var parameter = [], y = 0; y < this.arguments.length; ++y) {

									parameter[parameter.length] = this.arguments[y];
								}

								eval(this.callback).apply(this.callback, parameter.slice(1));

							} else {

								eval(this.callback)();

							} break;

							this.count = this.tries;
						}
					}

					if ((++this.count) > this.tries) {

						with (window) {

							clearInterval(this.self.timeout);
							controll = null;

						} this.self.Unset('timeout');
					}
				}
			}
		};

		this.timeout = window.setInterval("window.controll.interval()", 500);
	}
});

Objects ('Mouse', {

	X : function (e) {

		var body = (document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : ((document.body) ? document.body : null);

		if(typeof body.scrollLeft == 'number' || window.opera != null) {

			if (window.event) {

				if (!event.x) {

					return event.clientX;

				} else {

					if(event.clientY > event.screenY) {

						return body.scrollLeft + event.screenX;

					} else return body.scrollLeft + event.clientX;
				}

			} else return body.scrollLeft + e.clientX;

		} else return window.pageXOffset + e.clientX;

	},

	Y : function (e) {

		var body = (document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : ((document.body) ? document.body : null);

		if(typeof body.scrollTop == 'number' || window.opera != null) {

			if (window.event) {

				if (!event.y) {

					return event.clientY;

				} else {

					if(event.clientY > event.screenY) {

						return body.scrollTop + event.screenY;

					} else return body.scrollTop + event.clientY;
				}

			} else return body.scrollTop + e.clientY;

		} else return window.pageYOffset + e.clientY;
	}
});

Objects ('Element', {

	IsElement : function (element) {

		return (element != null && element.tagName != null && element.nodeType == 1) ? true : false;
	},

	Nodes : function (element, asArray) {

		if (asArray) {

			asArray = [];
			element = Element.Find(element);

			for (var x = 0; x < element.childNodes.length; ++x) {

				if (element.childNodes[x].tagName != null) {

					asArray[asArray.length] = element.childNodes[x];
				}

			} return asArray;

		} return Element.Find(element).childNodes.length;
	},

	Chain : function (element) {

		if ((element = Element.Find(element)) != null) {

			var chain = [];

			while (element.tagName != null) {

				chain[chain.length] = element.tagName.toLowerCase() + ((element.id != '') ? '[' + element.id + ']' : '');

				element = element.parentNode;

			} return chain.reverse().join('.');

		} return false;
	},

	Find : function () {

		if (arguments.length > 1) {

			var elements = [];

			for (var x = 0; x < arguments.length; ++x) {

				if (typeof arguments[x] == 'string') {

					elements[elements.length] = document.getElementById(arguments[x]);

				} else if (arguments[x] != null && Element.IsElement(arguments[x])) {

					elements[elements.length] = arguments[x];
				}

			} return elements;

		} else if(arguments.length == 1) {

			if (typeof arguments[0] == 'string') {

				return document.getElementById(arguments[0]);

			} else if (arguments[0] != null && Element.IsElement(arguments[0])) {

				return arguments[0];
			}

		} return null;
	},
	
	FindLike : function (likeElement, target) {
		
		var target = (target == null) ? document.body : Element.Find(target);
		
		//dev
	},

	FindByTagName : function (tag, target) {
		
		if ((tag = (target ? Element.Find(target) : document).getElementsByTagName(tag)) != null) {

			var elements = [];

			for (var x = 0; x < tag.length; ++x) {

				elements[elements.length] = tag[x];

			} return elements;

		} return [];
	},

	FindByAttribut : function (attribut, value, target) {

		if (attribut == null) {

			return false;
		}

		if (Element.$$ == null) {

			if (Element.$ == null) {

				Element.$ = [];
			}

			Element.$$ = function (attribut, value, node) {

				for (var x = 0; x < node.childNodes.length; ++x) {

					if(value == null && node.childNodes[x][attribut] != null
					|| value != null && node.childNodes[x][attribut] == value) {

						Element.$[Element.$.length] = node.childNodes[x];
					}

					if (node.childNodes[x].childNodes.length > 0) {

						Element.$$(attribut, value, node.childNodes[x]);
					}
				}

			}; Element.$$(attribut, value, (target ? Element.Find(target) : document.getElementsByTagName('html')[0]));

			var elements = Element.$;

		} Element.Unset('$', '$$');

		return elements;
	},

	SetSelfOffsetWidth : function (element) {

		if (typeof element == 'string') {

			Element.SetCssProperties(Element.Find(element), {

				width : Element.Find(element).offsetWidth + 'px'

			}); return true;

		} else if (element instanceof Array) {

			for (var x = 0; x < element.length; ++x) {

				Element.SetCssProperties(Element.Find(element[x]), {

					width : Element.Find(element[x]).offsetWidth + 'px'
				});

			} return true;

		} else if (Element.IsElement(element)) {

			Element.SetCssProperties(element, {

				width : element.offsetWidth + 'px'

			}); return true;

		} return false;
	},

	SetCssProperty : function (element, properties) {

		if (typeof element == 'string') {

			for (var x in properties) {

				Element.Find(element).style[x] = properties[x];

			} return true;

		} else if (element instanceof Array) {

			for (var x = 0; x < element.length; ++x) {

				for (var y in properties) {

					Element.Find(element[x]).style[y] = properties[y];
				}

			} return true;

		} else if (Element.IsElement(element)) {

			for (var x in properties) {

				element.style[x] = properties[x];

			} return true;

		} return false;
	},

	GetCssProperty : function (element, property) {

		if ((element = Element.Find(element)) != null) {

			if (window.getComputedStyle) {

				return window.getComputedStyle(element, null).getPropertyValue(property);

			} else if (element.currentStyle) {

				property = property.split('-');

				for (var x = 1; x < property.length; ++x) {

					property[x] = property[x].substr(0, 1).toUpperCase() + property[x].substr(1);

				} return element.currentStyle[property.join('')];
			}

		} return false;
	},

	SetCssClass : function (element, className) {

		if (typeof element == 'string') {

			if ((element = Element.Find(element)) != null) {

				if (element.setAttribute instanceof Function) {

					element.setAttribute('class', className);

				} else element.className = className;

				return true;
			}

		} else if (element instanceof Array) {

			for (var x = 0; x < element.length; ++x) {

				if ((element[x] = Element.Find(element[x])) != null) {

					if (element[x].setAttribute instanceof Function) {

						element[x].setAttribute('class', className);

					} else element[x].className = className;

					return true;
				}
			}

		} else if (Element.IsElement(element)) {

			if (element.setAttribute instanceof Function) {

				element.setAttribute('class', className);

			} else element.className = className;

			return true;

		} return false;
	},

	SetEvent : function (element, event, eventFunction, before) {

		if ((element = Element.Find(element)) != null) {

			switch ((event = event.toLowerCase())) {

				case 'onblur' :
				case 'onfocus' :
				case 'onmouseover' :
				case 'onmouseout' :
				case 'onmousedown' :
				case 'onkeypress' :
				case 'onkeydown' :
				case 'onkeyup' :
				case 'onchange' :
				case 'onsubmit' :
				case 'onclick' :
				case 'onselect' :
				case 'ondblclick' :
				case 'onreset' :

					var store = element[event];

					if (store != null) {

						element[event] = function () {

							if (before == null) {
								store();
								eventFunction();
							} else {
								eventFunction();
								store();
							}
						};

					} else element[event] = eventFunction;

					return true;

				break;
			}

		} return false;
	}

});

Objects ('Formular', {

	Type : function (element, form) {

		return Formular.Find(element, form) ? Formular.Find(element, form).type : 'undefined';
	},

	Length : function () {

		return document.forms.length;
	},

	ElementsLength : function (form) {

		if (document.forms[form] != null) {

			return document.forms[form].elements.length;

		} return null;
	},

	Name : function (number) {

		if (document.forms[number] != null) {

			return document.forms[number].name;

		} return null;
	},

	Elements : function (form) {

		if (document.forms[form] != null) {

			return document.forms[form].elements;

		} return null;
	},

	Reset : function (element, form) {

		if (element instanceof Array) {

			for (var x = 0; x < element.length; ++x) {

				if ((element[x] = Formular.Find(element[x], form)) != null) {

					switch (element[x].type) {

						case 'text' 		:
						case 'hidden' 		: element[x].value = ''; break;
						case 'select-one' 	: Formular.Select.Index(element[x], 0); break;
						case 'checkbox'		:
						case 'radio'		: element[x].checked = false; break;
					}
				}

			} return true;

		} else if (typeof element == 'string') {

			if ((element = Formular.Find(element, form)) != null) {

				switch (element.type) {

					case 'text' 		:
					case 'hidden' 		:
					case 'file' 		: element.value = ''; break;
					case 'select-one' 	: Formular.Select.Index(element, 0); break;
					case 'checkbox'		:
					case 'radio'		: element.checked = false; break;

				} return true;
			}
		}
	},
	
	Disabled : function (element, status) {

		if (element instanceof Array) {

			for (var x = 0; x < element.length; ++x) {

				if ((element[x] = Formular.Find(element[x])) != null) {

					element[x].disabled = status;
				}
			}

		} else if (typeof element == 'string') {

			if ((element = Formular.Find(element)) != null) {

				element.disabled = status;
			}
		}
	},

	Find : function (element, form) {

		if (typeof element == 'string') {

			if (typeof form == 'string' || typeof form == 'number') {

				return (Formular.Elements(form) != null) ? Formular.Elements(form)[element] : null;

			} else {

				for (var x = 0; x < Formular.Length(); ++x) {

					for (var y = 0; y < Formular.ElementsLength(x); ++y) {

						if (Formular.Elements(x)[y].name == element) {

							return Formular.Elements(x)[y];
						}
					}
				}

			} return null;

		} else if (element.tagName != null && element.nodeType == 1) {

			return element;

		} return false;
	},
	
	FindLike : function (needle, form) {
	
		if (typeof needle == 'string') {
		
			var elements = [];
		
			for (var x = 0; x < Formular.Length(); ++x) {

				for (var y = 0; y < Formular.ElementsLength(x); ++y) {

					if (Formular.Elements(x)[y].name.toLowerCase().substring(0, needle.length) == needle.toLowerCase()) {

						elements[elements.length] = Formular.Elements(x)[y];
					}
				}
		
			} return elements;
		}
	},

	FindByAttribut : function (attribut, value, form) {

		var elements = [];

		if (typeof form == 'string' || typeof form == 'number') {

			for (var x = 0, fields = Formular.Elements(form); x < fields.length; ++x) {

				if (value == null && fields[x][attribut] != null
				|| value != null && fields[x][attribut] == value) {

					elements[elements.length] = fields[x];
				}
			}

		} else {

			for (var x = 0; x < Formular.Length(); ++x) {

				for (var y = 0, fields = Formular.Elements(x); y < fields.length; ++y) {

					if (value == null && fields[x][attribut] != null
					|| value != null && fields[x][attribut] == value) {

						elements[elements.length] = fields[x];
					}
				}
			}

		} return elements;
	},

	Value : function (element, form) {

		if ((element = Formular.Find(element, form))) {

			if (element.type.indexOf('select') > -1) {

				return element.options[element.selectedIndex].value;

			} else return element.value;

		} return null;
	},

	SetEvent : function (element, event, eventFunction) {

		if ((element = Formular.Find(element)) != null) {

			switch ((event = event.toLowerCase())) {

				case 'onblur' :
				case 'onfocus' :
				case 'onmouseover' :
				case 'onmouseout' :
				case 'onmousedown' :
				case 'onkeypress' :
				case 'onkeydown' :
				case 'onkeyup' :
				case 'onchange' :
				case 'onsubmit' :
				case 'onclick' :
				case 'onselect' :
				case 'ondblclick' :
				case 'onreset' :

					var store = element[event];

					if (store != null) {

						element[event] = function () {

							store();
							eventFunction();
						};

					} else element[event] = eventFunction;

					return true;

				break;
			}

		} return false;
	},

	Restrict : function (element, restrict) {

		if (typeof element == 'string') {

			element = [Formular.Find(element)];

		} else if (element instanceof Array) {

			element = element;

		} else if (element.tagName != null && element.nodeType == 1) {

			var element = [element];
		}

		for (var x = 0; x < element.length; ++x) {

			if (typeof element[x] == 'string') {

				element[x] = Formular.Find(element[x]);
			}

			if (window.opera) {

				element[x].restrict = restrict;

				Formular.SetEvent(element[x], 'onkeydown', function (e) {

					if (this.restrict.indexOf(String.fromCharCode((e.charCode) ? e.charCode : e.which)) == -1) {

						return false;
					}

				}); return true;

			} else {

				element[x].restrict = restrict;

				Formular.SetEvent(element[x], 'onkeypress', function () {

					if (this.eventKeyP != null) {

							this.eventKeyP();
					}

					if (this.restrict.indexOf(String.fromCharCode(event.keyCode)) == -1) {

						this.value = eval("this.value.replace(/" + ((String('/()?[]+*\\').indexOf(String.fromCharCode(event.keyCode)) > -1) ? "\\" : "") + String.fromCharCode(event.keyCode) + "/, '')");

						return false;
					}
				});

				Formular.SetEvent(element[x], 'onkeyup', function () {

					for (var x = 0, char = this.value.split(''); x < this.value.length; ++x) {

						if (this.restrict.indexOf(char[x]) == -1) {

							this.value = eval("this.value.replace(/" + char[x] + "/, '')");
						}
					}

				}); return true;
			}
		}
	},

	WidthToSize : function (element, width) {

		if ((element = Formular.Find(element)) != null) {

			if (element.style.width != 'auto') {

				element.style.width = 'auto';
			}

			while (element.offsetWidth < width) {

				element.size += 1;

			} element.size -= 1;

		} return false;
	}

});

Extends (Formular.Select = {}, {

	Length : function (element, form) {

		return Formular.Find(element, form) ? Formular.Find(element, form).options.length : null;
	},

	Current : function (element, form) {

		return Formular.Find(element, form) ? Formular.Find(element, form).selectedIndex : null;
	},

	Value : function (element, form, position) {

		return Formular.Find(element, form) ? Formular.Find(element, form).options[position].value : null;
	},

	Add : function (element, text, value, position) {

		var options = null;

		if ((options = Formular.Select.ToArray(element)) != null) {

			if (position != null) {

				if (position < 0) position = 0;
				if (position > options.length) position = options.length;

			} else position = options.length;

			element = Formular.Select.Options(element);
			options = options.slice(0, position).concat([{text : text, value : value}]).concat(options.slice(position, options.length));

			for (var x = 0; x < options.length; ++x) {

				if (element[x] != null) {

					element[x].text  = options[x]['text'];
					element[x].value = options[x]['value'];

				} else {

					element[x] = new Option(options[x]['text'], options[x]['value']);
				}

			} return true;
		}
	},

	Remove : function (element, position) {

		var options = null;

		if ((options = Formular.Select.ToArray(element)) != null) {

			if (position < 0) position = 0;

			options = options.slice(0, position).concat(

				options.slice(position + 1, options.length)

			); Formular.Select.Clear(element);

			for (var x = 0; x < options.length; ++x) {

				Formular.Select.Add(element, options[x]['text'], options[x]['value']);

			} return true;

		} return false;
	},

	Options : function (element, form) {

		if ((element = Formular.Find(element, form)) != null) {

			return element.options;

		} return null;
	},

	ToArray : function (element, form) {

		var options = [];

		if ((element = Formular.Select.Options(element, form)) != null) {

			for (var x = 0; x < element.length; ++x) {

				options[options.length] = {

					text  : element[x].text,
					value : element[x].value
				};

			} return options;

		} return false;
	},

	Selected : function (element, position) {

		if ((element = Formular.Select.Options(element)) != null) {

			if (typeof position == 'number') {

				return element[position].selected = true;

			} else if (position instanceof Array) {

				for (var x = 0; x < position.length; ++x) {

					element[position[x]].selected = true;

				} return true;
			}

		} return false;
	},

	Index : function (element, offset) {

		if (element instanceof Array) {

			for (var x = 0; x < element.length; ++x) {

				if ((element[x] = Formular.Find(element[x])) != null) {

					element[x].selectedIndex = offset;
				}

			} return true;

		} else {

			if ((element = Formular.Find(element)) != null) {

				return element.selectedIndex = offset;
			}
		}
	},

	Search : function (element, needle) {

		if ((element = Formular.Select.Options(element)) != null) {

			for (var x = 0; x < element.length; ++x) {

				if (element[x].value == needle) {

					return x;
				}

			} return false;

		} return null;
	},

	Clear : function (element, form) {

		if ((element = Formular.Select.Options(element, form)) != null) {

			for (var x = element.length; x >= 0; --x) {

				element[x] = null;

			} return true;

		} return false;
	}
});

Extends (String.prototype, {

	Search : function (needle) {

		if (needle == '') {

			return false;

		} return (this.toLowerCase().indexOf(needle.toLowerCase()) < 0) ? false : true;
	},

	LeftFill : function (value, length) {

		var current = this;

		while (current.length < length) {

			current = value + current;

		} return current;
	},

	RightFill : function (value, length) {

		var current = this;

		while (current.length < length) {

			current += value;

		} return current;
	},

	BothFill : function (value, length) {

		var current = this;

		while (current.length < length) {

			if (Math.ceil(length / 2) < current.length) {

				current = value + current;

			} else current += value;

		} return current;
	},

	CharCount : function () {

		return this.replace(/\W+/, '').length;
	},

	WordCount : function () {

		return this.replace(/\W/, '').split(' ').length;
	},

	UpperCaseFirst : function () {

		return this.substr(0, 1).toUpperCase() + this.substr(1, this.length);
	},
	
	StripTags : function () {
	
		var string = this;
		
		if (arguments.length > 0) {
	
			for (var x = 0; x < arguments.length; ++x) {

				string = eval("string.replace(/< ?" + arguments[x] + "([^>]+)>/gi, '')");
				string = eval("string.replace(/<" + arguments[x] + ">/gi, '')");
				string = eval("string.replace(/<\\/" + arguments[x] + ">/gi, '')");
				string = string.replace(/\s\s+/gi, ' ');
				
			} return string;
			
		} else return string.replace(/<(.*?)>/gi, '');
	}
});

Extends (Number.prototype, {

	Dec2Hex : function () {

		return (this.toString(16).length == 1) ? '0' +  this.toString(16) : this.toString(16);
	}
});

Objects ('Browser', {

	Name : function () {

		if (window.opera && navigator.userAgent.indexOf('Opera') > -1)
			return 'Opera';

		else if (navigator.userAgent.indexOf('MSIE') > -1)
			return 'Internet Explorer';

		else if (navigator.userAgent.indexOf('Firefox') > -1)
			return 'Firefox';

		else if (navigator.userAgent.indexOf('Netscape') > -1)
			return 'Netscape';

		else if (navigator.userAgent.indexOf('Gecko') > -1)
			return 'Mozilla';

		else if (navigator.userAgent.indexOf('OmniWeb') > -1)
			return 'OmniWeb';

		else if (navigator.vendor.indexOf('Apple') > -1)
			return 'Safari';

		else if (navigator.vendor.indexOf('iCab') > -1)
			return 'iCab';

		else if (navigator.vendor.indexOf('KDE') > -1)
			return 'Konqueror';

		else if (navigator.vendor.indexOf('Camino') > -1)
			return 'Camino';
	},

	Version : function () {

		if (Browser.Name() == 'Opera') {

			var agent = navigator.userAgent.split(' ');

			return (isNaN(agent[agent.length - 1])) ? agent[agent.length - 3] : agent[agent.length - 1];

		} else if (Browser.Name() == 'Internet Explorer') {

			return navigator.userAgent.split('; ')[1].split(' ')[1];

		} else if (Browser.Name() == 'Firefox') {

			var agent = navigator.userAgent.split(' ');

			return agent[agent.length - 1].split('/')[1];

		} else if (Browser.Name() == 'Netscape') {

			var agent = navigator.userAgent.split('/');

			return (agent[agent.length - 1].indexOf(' ') > -1) ? agent[agent.length - 1].split(' ')[0] : agent[agent.length - 1];

		} else if (Browser.Name() == 'Mozilla') {

			var agent = navigator.userAgent.split(' ')[7];

			return agent.substring(0, String(agent).length - 1).split(':')[1];

		} else if (Browser.Name() == 'OmniWeb') {

			var agent = navigator.userAgent.split(' ');

			return agent[agent.length - 1].split('/')[1];
		}
	}
});

Objects ('Images', {

	Length : function () {

		return document.images.length;
	},

	Find : function (image) {


		if (typeof image == 'string') {

			return eval('document.' + image);

		} else if (image instanceof Array) {

			var images = [];

			for (var x = 0; x < image.length; ++x) {

				if (eval('document.' + image).name == image[x]) {

					images[images.length] = eval('document.' + image);
				}

			} return images.length > 0 ? images : null;

		} else if (image.tagName != null && image.nodeType == 1) {

			return image;

		} return null;
	},

	FindByAttribut : function (attribut, value) {

		if (document.images) {

			var images = [];

			for (var x = 0; x < document.images.length; ++x) {

				if (value == null) {

					if (document.images[x][attribut] != null) {

						images[images.length] = document.images[x];
					}

				} else {

					if (document.images[x][attribut] == value) {

						images[images.length] = document.images[x];
					}
				}

			} return images.length > 0 ? images : null;

		} return false;
	},

	Properties : function (image) {

		if ((image = Images.Find(image)) != null) {

			var img 	= new Image();
				img.src = Images.Find(image).src;

			return {

				src					: img.src,
				width				: img.width,
				height				: img.height,
				fileSize			: img.fileSize || null,
				mimeType			: img.mimeType || null,
				fileCreatedDate		: new Date(img.fileCreatedDate).getTime() || null,
				fileModifiedDate	: new Date(img.fileModifiedDate).getTime() || null
			};
		}
	}

});


window.onerror = function () { return true; };

Objects ('Flicker', {

	Color : function (element, normal, hover) {
		
		if ((obj =  Element.Find(element)) != null) {
			
			window.clearInterval(obj.interval);
			
			obj.status  = false;
			obj.flicker = function () {
			
				Element.SetCssProperty(this, {
					
					backgroundColor : ((this.status) ? normal : hover)
					
				}); this.status = !this.status;
				
			}; obj.interval = window.setInterval('Element.Find("' + element + '").flicker()', 500);
		}
	},

	CssImage : function (element, normal, hover) {

		if ((obj =  Element.Find(element)) != null) {
			
			window.clearInterval(obj.interval);
			
			obj.status  = false;
			obj.flicker = function () {
			
				Element.SetCssProperty(this, {
					
					backgroundImage : 'url(' + ((this.status) ? normal : hover) + ')'
					
				}); this.status = !this.status;
				
			}; obj.interval = window.setInterval('Element.Find("' + element + '").flicker()', 500);
		}
	},

	Image : function (element, normal, hover) {

		if ((obj =  Element.Find(element)) != null) {
			
			window.clearInterval(obj.interval);
			
			obj.status  = false;
			obj.flicker = function () {
			
				this.src = ((this.status) ? normal : hover);
				this.status = !this.status;
				
			}; obj.interval = window.setInterval('Element.Find("' + element + '").flicker()', 500);
		}
	}
});

Objects ('Hover', {

	Image : function (element, src) {
	
		if ((element = Element.Find(element)) != null) {

			element.src = src;
		}
	}
});

Objects('Replacing', {

	Code : function (element, code) {

		if ((element = Element.Find(element))) {
		
			var selectedWord 	= '';
			var codePasage		= ''; 
			var rangeable		= true;
	
			element.focus();
			
			if (document.selection) {
				
				var range = document.selection.createRange();
				var selectedWord = range.text;
			
			} else if (element.selectionStart || element.selectionStart == '0') {
	
				var start = element.selectionStart;
				var end	= element.selectionEnd;
				var selectedWord = element.value.substring(start, end);
			
			} else {
	
				rangeable = false; 
			}
			
			switch (code.toLowerCase()) {
		
				case 'list' :
					
					if (selectedWord != '') {
					
						codePasage = '[' + code + ']\n[*]{text}[/*]\n[/' + code + ']';
					
					} else codePasage = '[' + code + ']\n[*]Text[/*]\n[*]Text[/*]\n[/' + code + ']';
					
				break;
		
				case 'link' :
		
					if (selectedWord != '') {
					
						codePasage = '[' + code + '=http://www.meinedomain.de]{text}[/' + code + ']'
					
					} else codePasage = '[' + code + '=http://www.meinedomain.de]Link Text[/' + code + ']';
		
				break;
		
				case 'email' :
	
					if (selectedWord != '') {
					
						codePasage = '[' + code + '={text}]{text}[/' + code + ']';
					
					} else codePasage = '[' + code + '=meine@email.de]E-Mail Text[/' + code + ']';
		
				break;
		
				default :
	
					if (selectedWord != '') {
					
						codePasage = '[' + code + ']{text}[/' + code + ']';
					
					} else codePasage = '[' + code + ']Text[/' + code + ']';
		
				break;
			}
			
			if (rangeable) {
					
				if (range) {
	
					range.text = (selectedWord != '') ? codePasage.replace(/\{text\}/gi, selectedWord) : codePasage;
					
				} else element.value =  element.value.substring(0, start) + ((selectedWord != '') ? codePasage.replace(/\{text\}/gi, selectedWord) : codePasage) + element.value.substring(end, element.value.length);
				
			} else element.value += codePasage;
		}
	}
});

window.SetEvent('onload', function () {

	var aTags = document.getElementsByTagName('A');
	
	for (var x = 0; x < aTags.length; ++x) {

		if (!aTags[x].href.Search('mailto') && !Empty(aTags[x].href)) {
		
			if (!aTags[x].href.Search('public-life')) {
				
				aTags[x].target = 'external';
				aTags[x].onclick = function () {
					
					window.open('/redirect.html?u=' + encodeURIComponent(this.href), 'external');
					return false;
				};
			}
			
			if (aTags[x].href.Search('rss-2.0')
			|| aTags[x].href.Search('rss-1.0')
			|| aTags[x].href.Search('rss-0.92')
			|| aTags[x].href.Search('atom-0.3')
			|| aTags[x].href.Search('.pdf')) {
			
				aTags[x].target = '_blank';
			}
		}
	}

	// LI-Tag Hover

	var ulTags = Element.FindByTagName('Ul');

	for (var x = 0; x < ulTags.length; ++x) {

		if (ulTags[x].className == 'list') {

			var liTags = Element.FindByTagName('Li', ulTags[x]);

			for (var y = 0; y < liTags.length; ++y) {

				Element.SetEvent(liTags[y], 'onmouseover', function () {

					Element.SetCssProperty(this, {

						backgroundColor : '#EAEAEA'
					});
				});

				Element.SetEvent(liTags[y], 'onmouseout', function () {

					Element.SetCssProperty(this, {

						backgroundColor : '#F5F5F5'
					});
				});
			}
		}
	}

	// File-Input fix

	if (Browser.Name() == 'Firefox' || Browser.Name() == 'Netscape') {

		var inputs = Element.FindByAttribut('type', 'file');
	
		for (var x = 0; x < inputs.length; ++x) {
		
			Formular.WidthToSize(inputs[x], 472);
		}
	}

	var pTags = Element.FindByTagName('P');

	for (var x = 0; x < pTags.length; ++x) {

		if (pTags[x].className == 'display' || pTags[x].className == 'thumbnailBar') {

			Element.SetEvent(pTags[x], 'onmouseover', function () {

				Element.SetCssProperty(this, {

					backgroundColor : '#EAEAEA'
				});
			});

			Element.SetEvent(pTags[x], 'onmouseout', function () {

				Element.SetCssProperty(this, {

					backgroundColor : '#F5F5F5'
				});
			});
		}
	}

	if (Element.Find('shopPhotoInfoBox')) {

		var shopBox = Element.FindByTagName('Form', 'shopPhotoInfoBox')[0];
	
		Element.SetEvent(shopBox, 'onmouseover', function () {
	
			Element.SetCssProperty(this, {
	
				backgroundColor : '#EAEAEA'
			});
		});
	
		Element.SetEvent(shopBox, 'onmouseout', function () {
	
			Element.SetCssProperty(this, {
	
				backgroundColor : '#F5F5F5'
			});
		});
	}

	if (Element.Find('cart')) {

		var cartItems = Element.FindByTagName('Div', 'cart');
	
		for (var x = 0; x < cartItems.length; ++x) {
		
			if (cartItems[x].className == 'cartRow') {
	
				Element.SetEvent(cartItems[x], 'onmouseover', function () {
			
					Element.SetCssProperty(this, {
			
						backgroundColor : '#EAEAEA'
					});
				});
			
				Element.SetEvent(cartItems[x], 'onmouseout', function () {
			
					Element.SetCssProperty(this, {
			
						backgroundColor : '#F5F5F5'
					});
				});
			}
		}
	}
	
	// Send process
	
	var formTags = Element.FindByTagName('Form');

	for (var x = 0; x < formTags.length; ++x) {
		
		Element.SetEvent(formTags[x], 'onsubmit', function () {

			var submitButton = Element.FindByAttribut('type', 'submit', this);
			var imageElement = Element.FindByAttribut('className', 'loadingWheel', this);

			if (!Empty(imageElement)) {

				for (var x = 0; x < submitButton.length; ++x) {
					Element.SetCssProperty(submitButton[x], {display : 'none'});
				}
				
				for (var x = 0; x < imageElement.length; ++x) {
					Element.SetCssProperty(imageElement[x], {display : 'inline'});
				}
			}
		});
	}
});
