
var a={b:function(){document.write('&#64;')},c:function(){document.write('&#46;')}};

//MooTools, <http://mootools.net>, My Object Oriented (JavaScript) Tools. Copyright (c) 2006-2009 Valerio Proietti, <http://mad4milk.net>, MIT Style License.


/**
 * Simple Validator
 * Replaces the text of an element with an error message if the given validation fails and adds and class to this element.
 * When an Element is focused again, the class is removed and the wrong value (if there was one) is restored
 */
var Validator = new Class({

	fields:    [],
	backups:   [],
	form:      null,
	error:     false,
	lastValue: '',


	regexp : {
		alpha : /^[a-z ._-]+$/i,
		alphanum : /^[a-z0-9 ._-]+$/i,
		digit : /^[-+]?[0-9]+$/,
		nodigit : /^[^0-9]+$/,
		number : /^[-+]?\d*\.?\d+$/,
		email : /^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i,
		phone : /^[\d\s \/().-]+$/
		//url : /^(http|https|ftp)\:\/\/[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z0-9\-\._\?\,\'\/\\\+&amp;%\$#\=~])*$/i
	},

	initialize: function(options) {

		this.options = $merge({
			text: { // Text of the Error Message; The key must be the ID of an element with class="validate[xy]" 
				name: "Name fehlt",
				first_name: "Vorname fehlt",
				last_name: "Nachname fehlt",
				firma: "Firma fehlt",
				adresse: "Adresse fehlt",
				plz: "PLZ fehlt",
				ort: "Stadt fehlt",
				telefon: "Telefon fehlt",
				fax: "Telefax fehlt",
				email: "eMail Adresse fehlt"
			},
			selector: "error",
			form: "",
			event: "submit" // Valid are "submit" and "blur"
		}, options || {});


		var formName = '#' + this.options.form;
		this.form = $(this.options.form);
		this.options.form = this.form.id;

		if ($type(this.form) != "element") return;

			// Push all Elements
		$$(formName + ' input', formName + ' textarea').each(function(element) {
			if (element.className.search(/^validate\[(.+)\]/i) != -1) { // Is a form
				this.fields.push({
					"el": element,
					"tests": element.className.match(/^validate\[(.+)\]/i)[1].split(",")
				});
			}
		}, this);

		if (this.fields.length < 1) {
			return;
		}
		
			// Bind validation to form
		this.form.addEvent("submit", this.validate.bind(this));

			// Remove Messages on exit so they are not filled in by the 
			// Browser on next visit
		window.addEvent('unload', this.removeAllErrors.bind(this));

	},

	validate: function(e) {

		this.error = false;

		this.fields.each(function(field) {

			if (!this.form.getElements('input').contains(field.el)) return;

			field.tests.each(function(test) {
				this.validateSingeItem(test, field);
			}, this);

		}, this);


		if (this.error) {
			e = new Event(e);
			e.stop();
			return false;
		}
		return true;
	},

	validateSingeItem: function(test, field) {
		test = test.split('-');
		this.currentElement = field;
		valid = true;

		switch(test[0]) {

			case 'email':
			case 'mail':
				valid = this._regexp(this.regexp.email);
				break;

			case 'number':
			case 'zahl':
				valid = this._regexp(this.regexp.number);
				break;

			case 'zip':
			case 'plz': // Contains 4, 5, or 6 numeric characters
				valid = (this._regexp(this.regexp.number) && this._length(4, 6));
				break;

			case 'length':
				valid = this._length(test[1], test[2]);
				break;

			case 'phone':
			case 'tel':
			case 'telefon':
				valid = this._regexp(this.regexp.phone);
				break;
		}

			// Test fails, or value is the error message -> throw an error
		if (!valid || this.lastValue == this.options.text[this.currentElement.el.id]) this.setError();

	},

	setError: function() {
		el = this.currentElement.el;
		options = this.options;

		if (options.text[el.id] != this.lastValue.clean()) this.backups[ el.id ] = this.lastValue;
		el.setProperty('value', options.text[el.id]).addClass(options.selector).addEvent("focus", this.removeError.bind(this));
		this.error = true;
	},

	removeAllErrors: function() {
		this.fields.each(function(item) {
			item.el.value = "";
		});
	},

	removeError: function(e) {

		var currentEl = this.currentElement = new Event(e).target;

		this.fields.each(function(field) {

			if (currentEl == field.el && currentEl.hasClass(this.options.selector)) {
				currentEl.removeClass(this.options.selector).setProperty("value", (this.backups[ currentEl.id ] ? this.backups[ currentEl.id ] : ''));
			}

		}, this);

	},

	_regexp: function(exp) {
		return (this.last().search(exp) != -1);
	},


	_length: function(min, max) {
		min = min.toInt();
		max = (max == 'x') ? 999999 : max.toInt();
		val = this.last();

		return (val.length >= min && val.length <= max);
	},

	last: function() {
		this.lastValue = (" " + this.currentElement.el.getProperty('value')).trim();
		return this.lastValue;
	}

});

(function() {
	
	
	var WindowHeight, LayerHeight;
	var aktiv;
	function OnloadAbstand() {
		/*
			if(window.innerHeight) {
			
				var WindowHeight = window.innerHeight;
				var LayerHeight = $('main-start').offsetHeight;
				
				var margin = (WindowHeight - LayerHeight)/2;
			
			}
			else if(document.body && document.body.offsetHeight) {
			
				var WindowHeight = document.body.offsetHeight;
				var LayerHeight = $('main-start').offsetHeight;	

			
				var margin = (WindowHeight - LayerHeight)/2;
			
			}
			*/
			
			WindowHeight = window.getSize().y;
			
				
			if($("main-start") || $('main-start') != null) {
				
					aktiv = 1;
					LayerHeight = $("main-start").getSize().y;
			}
			else if($("main") || $('main') != null) {
				
				aktiv = 0;
				LayerHeight = $("main").getSize().y;	
			}
			
			
			var margin = (WindowHeight - LayerHeight) / 2;
			
			//console.log("(" + WindowHeight+" - " + LayerHeight+") / 2 = " +margin);
			
			if(aktiv == 1) {
				//$("main-start").style.height = LayerHeight + "px";
			
				if(margin <= 0) { 
					//$('startseite').style.marginTop = 0 + "px";
					//$("main-start").style.paddingTop = 0 + "px";
					$('startseite').style.paddingTop = 0 + "px";
				}
				else {
					//$('startseite').style.marginTop = margin + "px";
					//$("main-start").style.paddingTop = margin + "px";				
					$('startseite').style.paddingTop = margin + "px";
				}
				
			}
			/*
			else if(aktiv == 0) {
				//$("main").style.height = LayerHeight + "px";
				
				if(margin <= 0) { 
					//$('content-header').style.marginTop = 0 + "px";
					$("main").style.paddingTop = 0 + "px";
				}
				else {
					//$('content-header').style.marginTop = margin + "px";
					$("main").style.paddingTop = margin + "px";	
				}
				
			}
			*/
	}

	function ResizeAbstand() {
		
		var WindowHeight = window.getSize().y;
		
		
		var margin = (WindowHeight - LayerHeight) / 2;
		
		//console.log("(" + WindowHeight+" - " + LayerHeight+") / 2 = " +margin);
		if(aktiv == 1) {
			
				if(margin <= 0) { 
					//$('startseite').style.marginTop = 0 + "px";
					//$("main-start").style.paddingTop = 0 + "px";
					$('startseite').style.paddingTop = 0 + "px";
				}
				else {
					//$('startseite').style.marginTop = margin + "px";
					//$("main-start").style.paddingTop = margin + "px";				
					$('startseite').style.paddingTop = margin + "px";
				}
				
			}
		/*
		else if(aktiv == 0) {
				
				if(margin <= 0) {
					//$('content-header').style.marginTop = 0 + "px";
					$("main").style.paddingTop = 0 + "px";
				}
				else {
					//$('content-header').style.marginTop = margin + "px";
					$("main").style.paddingTop = margin + "px";	
				}
				
			}
			*/
		
	}
	
	
	window.addEvent('load',OnloadAbstand).addEvent('resize', ResizeAbstand);
	
	
	window.addEvent('load',moving) //.addEvent('resize', ResizeAbstand).addEvent('resize', moving).addEvent('load',OnloadAbstand);
	
	function moving() {

		if($('contentsite')) {
			var Remover = $('contentsite').getSize().y;
			
			if($('submenu')) {
				var Menu = $('submenu').getSize().y;
			} 
			else { var Menu = 0; } 
			
			var Infos = $('mover').getSize().y;
			
					
			
			if(Menu > 345) {
				var abstand = 0;	
			}
			else if(Remover < (Infos+345)) {
					var abstand = (((Remover-Infos)-Menu)-5);
			}
			else {
				var abstand = (345-Menu);
			}
			
			//abstand = (abstand - 5);
		/*
			console.log('Remover: ' + Remover);
			console.log('Infos: ' + Infos);
			console.log('Menue: ' + Menu);
			console.log('abstand: ' + abstand);
		*/
			if(abstand <= 0) {
				$('mover').style.marginTop = 0 + "px";
			} else 	{
				$('mover').style.marginTop = abstand + "px";
			}
		}
	}
	
	
	/*
	
	window.addEvent("domready", function() {
		$$(document.links).filter(function(el) {
			return el.rel && el.rel.test(/^lightbox/i);
		}).slimbox({counterText: "Bild {x} von {y}"}, null, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
		});
	});
	*/	
	
})();
