var contentLang = 'de';
var dateFieldFormat = 'dd.mm.yyyy';

var translations = [];
translations['january'] = 'Januar';
translations['february'] = 'Februar';
translations['march'] = 'M&auml;rz';
translations['april'] = 'April';
translations['mai'] = 'Mai';
translations['june'] = 'Juni';
translations['july'] = 'Juli';
translations['august'] = 'August';
translations['september'] = 'September';
translations['october'] = 'Oktober';
translations['november'] = 'November';
translations['december'] = 'Dezember';
translations['su'] = 'So';
translations['mo'] = 'Mo';
translations['tu'] = 'Di';
translations['we'] = 'Mi';
translations['th'] = 'Do';
translations['fr'] = 'Fr';
translations['sa'] = 'Sa';
translations['today'] = 'Heute';
translations['clear'] = 'L&ouml;schen';
translations['next'] = 'Vor';
translations['prev'] = 'Zur&uuml;ck';
translations['close'] = 'Schliessen';



function Translator(key) {
    skey  = key.replace(/ /g,'').toLowerCase();
    if(translations && translations[skey]) {
        return translations[skey];
    }
    return key;
}

/* MarcGrabanski.com v2.5 */
/* Pop-Up Calendar Built from Scratch by Marc Grabanski */
/* Enhanced by Keith Wood (kbwood@iprimus.com.au). */
/* Under the Creative Commons Licence http://creativecommons.org/licenses/by/3.0/
	Share or Remix it but please Attribute the authors. */
var popUpCal = {
	selectedDay: 0,
	selectedMonth: 0, // 0-11
	selectedYear: 0, // 4-digit year
	clearText: 'Clear', // Display text for clear link
	closeText: 'Close', // Display text for close link
	prevText: 'Prev', // Display text for previous month link
	nextText: 'Next', // Display text for next month link
	currentText: 'Today', // Display text for current month link
	appendText: '', // Display text following the input box, e.g. showing the format
	buttonText: '&nbsp;', // Text for trigger button
	buttonImage: '', // URL for trigger button image
	buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
	dayNames: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Names of days starting at Sunday
	monthNames: ['Januar','Februar','M&auml;rz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'], // Names of months
	dateFormat: 'DMY/', // First three are day, month, year in the required order, fourth is the separator, e.g. US would be 'MDY/'
	yearRange: '1960:2009', // Range of years to display in drop-down, either relative to current year (-nn:+nn) or absolute (nnnn:nnnn)
	changeMonth: true, // True if month can be selected directly, false if only prev/next
	changeYear: true, // True if year can be selected directly, false if only prev/next
	firstDay: 1, // The first day of the week, Sun = 0, Mon = 1, ...
	changeFirstDay: true, // True to click on day name to change, false to remain as set
	showOtherMonths: false, // True to show dates in other months, false to leave blank
	minDate: null, // The earliest selectable date, or null for no limit
	maxDate: null, // The latest selectable date, or null for no limit
	speed: 'fast', // Speed of display/closure
	autoPopUp: 'button', // 'focus' for popup on focus, 'button' for trigger button, or 'both' for either
	closeAtTop: false, // True to have the clear/close at the top, false to have them at the bottom
	customDate: null, // Function that takes a date and returns an array with [0] = true if selectable, false if not,
		// [1] = custom CSS class name(s) or '', e.g. popUpCal.noWeekends
	fieldSettings: null, // Function that takes an input field and returns a set of custom settings for the calendar
  calTarget:null,
	/* Initialisation. */
	init: function() {
		this.popUpShowing = false;
		this.lastInput = null;
		this.disabledInputs = [];
		jQuery('body').append('<div id="calendar_div"></div>');
		jQuery(document).mousedown(popUpCal.checkExternalClick);
	},
	
	/* Pop-up the calendar for a given input field. */
	showFor: function(target) {
		var input = (target.nodeName && target.nodeName.toLowerCase() == 'input' ? target : this);
		if (input.nodeName.toLowerCase() != 'input') { // find from button/image trigger
		  var cp = jQuery(input).parents('span');
			input = jQuery('input',cp)[0];
		}
		if (popUpCal.lastInput == input) { // already here
			return;
		}
		
		for (var i = 0; i < popUpCal.disabledInputs.length; i++) {  // check not disabled
			if (popUpCal.disabledInputs[i] == input) {
				return;
			}
		}
		popUpCal.input = jQuery(input);
		popUpCal.hideCalendar();
		popUpCal.lastInput = input;
		popUpCal.setDateFromField();
		
    
    popUpCal.setPos(input, jQuery('#calendar_div'));
		jQuery.extend(popUpCal, (popUpCal.fieldSettings ? popUpCal.fieldSettings(input) : {}));
		popUpCal.showCalendar(); 
        return false;
	},
	
	/* Handle keystrokes. */
	doKeyDown: function(e) {
		if (popUpCal.popUpShowing) {
			switch (e.keyCode) {
				case 9:  popUpCal.hideCalendar(); break; // hide on tab out
				case 13: popUpCal.selectDate(); break; // select the value on enter
				case 27: popUpCal.hideCalendar(popUpCal.speed); break; // hide on escape
				case 33: popUpCal.adjustDate(-1, (e.ctrlKey ? 'Y' : 'M')); break; // previous month/year on page up/+ ctrl
				case 34: popUpCal.adjustDate(+1, (e.ctrlKey ? 'Y' : 'M')); break; // next month/year on page down/+ ctrl
				case 35: if (e.ctrlKey) jQuery('#calendar_clear').click(); break; // clear on ctrl+end
				case 36: if (e.ctrlKey) jQuery('#calendar_current').click(); break; // current on ctrl+home
				case 37: if (e.ctrlKey) popUpCal.adjustDate(-1, 'D'); break; // -1 day on ctrl+left
				case 38: if (e.ctrlKey) popUpCal.adjustDate(-7, 'D'); break; // -1 week on ctrl+up
				case 39: if (e.ctrlKey) popUpCal.adjustDate(+1, 'D'); break; // +1 day on ctrl+right
				case 40: if (e.ctrlKey) popUpCal.adjustDate(+7, 'D'); break; // +1 week on ctrl+down
			}
		}
		else if (e.keyCode == 36 && e.ctrlKey) { // display the calendar on ctrl+home
			popUpCal.showFor(this);
		}
	},
		
	/* Filter entered characters. */
	doKeyPress: function(e) {
		var chr = String.fromCharCode(e.charCode == undefined ? e.keyCode : e.charCode);
		return (chr=='.' || chr < ' ' || chr == popUpCal.dateFormat.charAt(3) || (chr >= '0' && chr <= '9')); // only allow numbers and separator
	},
	
	/* Attach the calendar to an input field. */
	connectCalendar: function(target) {
		var $input = jQuery(target);
		this.calTarget = target;
		$input.after('<span class="calendar_append">' + this.appendText + '</span>');
		if (this.autoPopUp == 'focus' || this.autoPopUp == 'both') { // pop-up calendar when in the marked fields
			$input.focus(this.showFor);
		}
		if (this.autoPopUp == 'button' || this.autoPopUp == 'both') { // pop-up calendar when button clicked
			$input.wrap('<span class="calendar_wrap"></span>').
				after(this.buttonImageOnly ? '<img class="calendar_trigger" src="' + 
				this.buttonImage + '" alt="' + this.buttonText + '" title="' + this.buttonText + '"/>' :
				'<button class="calendar_trigger">' + (this.buttonImage != '' ? 
				'<img src="' + this.buttonImage + '" alt="' + this.buttonText + '" title="' + this.buttonText + '"/>' : 
				this.buttonText) + '</button>');
			jQuery((this.buttonImageOnly ? 'img' : 'button') + '.calendar_trigger', $input.parent('span')).click(this.showFor);
		}
		$input.keydown(this.doKeyDown).keypress(this.doKeyPress);
	},
	
	/* Enable the input field(s) for entry. */
	enableFor: function(inputs) {
		inputs = (inputs.jquery ? inputs : jQuery(inputs));
		inputs.each(function() {
			this.disabled = false;
			jQuery('../button.calendar_trigger', this).each(function() { this.disabled = false; });
			jQuery('../img.calendar_trigger', this).each(function() { jQuery(this).css('opacity', '1.0'); });
			var $this = this;
			popUpCal.disabledInputs = jQuery.map(popUpCal.disabledInputs, 
				function(value) { return (value == $this ? null : value); }); // delete entry
		});
		return false;
	},
	
	/* Disable the input field(s) from entry. */
	disableFor: function(inputs) {
		inputs = (inputs.jquery ? inputs : jQuery(inputs));
		inputs.each(function() {
			this.disabled = true;
			jQuery('../button.calendar_trigger', this).each(function() { this.disabled = true; });
			jQuery('../img.calendar_trigger', this).each(function() { jQuery(this).css('opacity', '0.5'); });
			var $this = this;
			popUpCal.disabledInputs = jQuery.map(popUpCal.disabledInputs, 
				function(value) { return (value == $this ? null : value); }); // delete entry
			popUpCal.disabledInputs[popUpCal.disabledInputs.length] = this;
		});
		return false;
	},
	
	/* Construct and display the calendar. */
	showCalendar: function() {
		this.popUpShowing = true;
		// build the calendar HTML
		var html = (this.closeAtTop ? '<div id="calendar_control">' +
			'<a id="calendar_clear">' + Translator(this.clearText) + '</a>' +
			'<a id="calendar_close">' + Translator(this.closeText) + '</a></div>' : '') +
			'<div id="calendar_links"><a id="calendar_prev">' + Translator(this.prevText) + '</a>' +
			'<a id="calendar_current">' + Translator(this.currentText) + '</a>' +
			'<a id="calendar_next">' + Translator(this.nextText) + '</a></div>' +
			'<div id="calendar_header">';
		if (!this.changeMonth) {
			html += Translator(this.monthNames[this.selectedMonth]) + '&nbsp;';
		}
		else {
			var inMinYear = (this.minDate && this.minDate.getFullYear() == this.selectedYear);
			var inMaxYear = (this.maxDate && this.maxDate.getFullYear() == this.selectedYear);
			html += '<select id="calendar_newMonth">';
			for (var month = 0; month < 12; month++) {
				if ((!inMinYear || month >= this.minDate.getMonth()) &&
						(!inMaxYear || month <= this.maxDate.getMonth())) {
					html += '<option value="' + month + '"' + 
						(month == this.selectedMonth ? ' selected="selected"' : '') + 
						'>' + Translator(this.monthNames[month]) + '</option>';
				}
			}
			html += '</select>';
		}
		if (!this.changeYear) {
			html += this.selectedYear;
		}
		else {
			// determine range of years to display
			var y = this.yearRange;
			var ct = jQuery(this.input).attr('id');
      if(this.ct && ct=='releasedate') {
          y = calcSettingsRelease.yearRange;
      }else if(ct && ct=='birthday') {
          y = calcSettingsBirthday.yearRange;
          
      }
      var years = y.split(':');
      var year = 0;
			var endYear = 0;
			if (years.length != 2) {
				year = this.selectedYear - 10;
				endYear = this.selectedYear + 10;
			}
			else if (years[0].charAt(0) == '+' || years[0].charAt(0) == '-') {
				year = this.selectedYear + parseInt(years[0]);
				endYear = this.selectedYear + parseInt(years[1]);
			}
			else {
				year = parseInt(years[0]);
				endYear = parseInt(years[1]);
			}
			year = (this.minDate ? Math.max(year, this.minDate.getFullYear()) : year);
			if(ct && ct=='birthday') { 
        year -=1;
      }
			
      endYear = (this.maxDate ? Math.min(endYear, this.maxDate.getFullYear()) : endYear);
			html += '<select id="calendar_newYear">';
			for (; year <= endYear; year++) {
				html += '<option value="' + year + '"' + 
					(year == this.selectedYear ? ' selected="selected"' : '') + 
					'>' + year + '</option>';
			}
			html += '</select>';
		}
		html += '</div><div id="calbox"><table id="calendar" cellpadding="0" cellspacing="0"><thead>' +
			'<tr class="calendar_titleRow">';
		for (var dow = 0; dow < 7; dow++) {
			html += '<td>' + (this.changeFirstDay ? '<a>' : '') + 
				Translator(this.dayNames[(dow + this.firstDay) % 7]) + (this.changeFirstDay ? '</a>' : '') + '</td>';
		}
		html += '</tr></thead><tbody>';
		var daysInMonth = this.getDaysInMonth(this.selectedYear, this.selectedMonth);
		this.selectedDay = Math.min(this.selectedDay, daysInMonth);
		var leadDays = (this.getFirstDayOfMonth(this.selectedYear, this.selectedMonth) - this.firstDay + 7) % 7;
		var currentDate = new Date(this.currentYear, this.currentMonth, this.currentDay);
		var selectedDate = new Date(this.selectedYear, this.selectedMonth, this.selectedDay);
		var printDate = new Date(this.selectedYear, this.selectedMonth, 1 - leadDays);
		var numRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
		var today = new Date();
		today = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // clear time
		for (var row = 0; row < numRows; row++) { // create calendar rows
			html += '<tr class="calendar_daysRow">';
			for (var dow = 0; dow < 7; dow++) { // create calendar days
				var customSettings = (this.customDate ? this.customDate(printDate) : [true, '']);
				var otherMonth = (printDate.getMonth() != this.selectedMonth);
				var unselectable = otherMonth || !customSettings[0] || 
					(this.minDate && printDate < this.minDate) || 
					(this.maxDate && printDate > this.maxDate);
				html += '<td class="calendar_daysCell' + 
					((dow + this.firstDay + 6) % 7 >= 5 ? ' calendar_weekEndCell' : '') + // highlight weekends
					(otherMonth ? ' calendar_otherMonth' : '') + // highlight days from other months
					(printDate.getTime() == selectedDate.getTime() ? ' calendar_daysCellOver' : '') + // highlight selected day
					(unselectable ? ' calendar_unselectable' : '') +  // highlight unselectable days
					(!otherMonth || this.showOtherMonths ? ' ' + customSettings[1] : '') + '"' + // highlight custom dates
					(printDate.getTime() == currentDate.getTime() ? ' id="calendar_currentDay"' : // highlight current day
					(printDate.getTime() == today.getTime() ? ' id="calendar_today"' : '')) + '>' + // highlight today (if different)
					(otherMonth ? (this.showOtherMonths ? printDate.getDate() : '&nbsp;') : // display for other months
					(unselectable ? printDate.getDate() : '<a>' + printDate.getDate() + '</a>')) + '</td>'; // display for this month
				printDate.setDate(printDate.getDate() + 1);
			}
			html += '</tr>';

		}
		html += '</tbody></table></div><!--[if lte IE 6.5]><iframe src="javascript:false;" id="calendar_cover"></iframe><![endif]-->' +

			(this.closeAtTop ? '' : '<div id="calendar_control"><a id="calendar_clear">' + Translator(this.clearText) + '</a>' +

			'<a id="calendar_close">' + Translator(this.closeText) + '</a></div>');
		// add calendar to element to calendar Div
		jQuery('#calendar_div').empty().append(html).show();
		this.input[0].focus();
		this.setupActions();
	}, // end showCalendar
	
	/* Connect behaviours to the calendar. */
	setupActions: function() {
		jQuery('#calendar_clear').click(function() { // clear button link
			popUpCal.clearDate();
		});
		jQuery('#calendar_close').click(function() { // close button link
			popUpCal.hideCalendar(popUpCal.speed);
		});
		jQuery('#calendar_prev').click(function() { // setup navigation links
			popUpCal.adjustDate(-1, 'M'); 
		});
		jQuery('#calendar_next').click(function() {
			popUpCal.adjustDate(+1, 'M'); 
		});
		jQuery('#calendar_current').click(function() { // back to today
			popUpCal.selectedDay = new Date().getDate();
			popUpCal.selectedMonth = new Date().getMonth();
			popUpCal.selectedYear = new Date().getFullYear();
			popUpCal.adjustDate(); 
		});
		jQuery('#calendar_newMonth').change(function() { // change month
			popUpCal.selecting = false;
			popUpCal.selectedMonth = this.options[this.selectedIndex].value - 0;
			popUpCal.adjustDate(); 
		}).click(this.selectMonthYear);
		jQuery('#calendar_newYear').change(function() { // change year
			popUpCal.selecting = false;
			popUpCal.selectedYear = this.options[this.selectedIndex].value - 0;
			popUpCal.adjustDate(); 
		}).click(this.selectMonthYear);
		jQuery('.calendar_titleRow a').click(function() { // change first day of week
			for (var i = 0; i < 7; i++) {
				if (popUpCal.dayNames[i] == this.firstChild.nodeValue) {
					popUpCal.firstDay = i; 
				}
			}
			popUpCal.showCalendar();
		});
		jQuery('.calendar_daysRow td').hover( // highlight current day
			function() {
				jQuery(this).addClass('calendar_daysCellOver');
			}, function() {
				jQuery(this).removeClass('calendar_daysCellOver');
		});
		jQuery('.calendar_daysRow td').click(function() { // select day
			popUpCal.selectedDay = jQuery("a",this).html();
			popUpCal.selectDate();
		});
		
	},
	
	/* Hide the calendar from view. */
	hideCalendar: function(speed) {
		if (this.popUpShowing) {
			jQuery('#calendar_div').hide(speed);
			this.popUpShowing = false;
			this.lastInput = null;
		}
	},
	
	/* Restore input focus after not changing month/year. */
	selectMonthYear: function() { 
		if (popUpCal.selecting) {
			popUpCal.input[0].focus(); 
		}
		popUpCal.selecting = !popUpCal.selecting;
	},
	
	/* Update the input field with the selected date. */
	selectDate: function() {
		this.hideCalendar(this.speed);
		this.input.val(this.formatDate(this.selectedDay, this.selectedMonth, this.selectedYear));
	},

	/* Erase the input field and hide the calendar. */
	clearDate: function() {
		this.hideCalendar(this.speed);
		this.input.val('');		
	},
	
	/* Close calendar if clicked elsewhere. */
	checkExternalClick: function(event) {
		if (popUpCal.popUpShowing) {
			var node = event.target;
			var cal = jQuery('#calendar_div')[0];
			while (node && node != cal && node.className != 'calendar_trigger') {
				node = node.parentNode;
			}
			if (!node) {
				popUpCal.hideCalendar();
			}
		}
	},
	
	/* Set as customDate function to prevent selection of weekends. */
	noWeekends: function(date) {
		var day = date.getDay();
		return [(day > 0 && day < 6), ''];
	},
	
	/* Format and display the given date. */
	formatDate: function(day, month, year) {
		var delim = (dateFieldFormat.indexOf('.')!=-1) ? '.'  : '/';
        month++; // adjust javascript month
		var dateString = '';
		for (var i = 0; i < 3; i++) {
			dateString += delim + 
				(this.dateFormat.charAt(i) == 'D' ? (day < 10 ? '0' : '') + day : 
				(this.dateFormat.charAt(i) == 'M' ? (month < 10 ? '0' : '') + month : 
				(this.dateFormat.charAt(i) == 'Y' ? year : '?')));
		}
		return dateString.substring(1);
	},
	
	/* Parse existing date and initialise calendar. */
	setDateFromField: function() {
        var delim = (dateFieldFormat.indexOf('.')!=-1) ? '.'  : '/';
		var currentDate = this.input.val().split(delim);
		if (currentDate.length == 3) {
			this.currentDay = parseInt(this.trimNumber(currentDate[this.dateFormat.indexOf('D')]));
			this.currentMonth = parseInt(this.trimNumber(currentDate[this.dateFormat.indexOf('M')])) - 1;
			this.currentYear = parseInt(this.trimNumber(currentDate[this.dateFormat.indexOf('Y')]));
		} else {
			this.currentDay = new Date().getDate();
			this.currentMonth = new Date().getMonth();
			this.currentYear = new Date().getFullYear();
		}
		this.selectedDay = this.currentDay;
		this.selectedMonth = this.currentMonth;
		this.selectedYear = this.currentYear;
		this.adjustDate(0, 'D', true);
	},

	/* Ensure numbers are not treated as octal. */
	trimNumber: function(value) {
		if (value == '')
			return '';
		while (value.charAt(0) == '0') {
			value = value.substring(1);
		}
		return value;
	},
	
	/* Adjust one of the date sub-fields. */
	adjustDate: function(offset, period, dontShow) {
		var date = new Date(this.selectedYear + (period == 'Y' ? offset : 0), 
			this.selectedMonth + (period == 'M' ? offset : 0), 
			this.selectedDay + (period == 'D' ? offset : 0));
		// ensure it is within the bounds set
		date = (this.minDate && date < this.minDate ? this.minDate : date);
		date = (this.maxDate && date > this.maxDate ? this.maxDate : date);
		this.selectedDay = date.getDate();
		this.selectedMonth = date.getMonth();
		this.selectedYear = date.getFullYear();
		if (!dontShow) {
			this.showCalendar();
		}
	},

	/* Find the number of days in a given month. */
	getDaysInMonth: function(year, month) {
		return 32 - new Date(year, month, 32).getDate();
	},
	
	/* Find the day of the week of the first of a month. */
	getFirstDayOfMonth: function(year, month) {
		return new Date(year, month, 1).getDay();
	},
	
	/* Set an object's position on the screen. */
	setPos: function(targetObj, moveObj) {
		var coords = this.findPos(targetObj);
		moveObj.css('position', 'absolute').css('left', coords[0] + 'px').
			css('top', (coords[1] + targetObj.offsetHeight) + 'px');
	},
	
	/* Find an object's position on the screen. */
	findPos: function(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft;
			curtop = obj.offsetTop;
			while (obj = obj.offsetParent) {
				var origcurleft = curleft;
				curleft += obj.offsetLeft;
				if (curleft < 0) { 
					curleft = origcurleft;
				}
				curtop += obj.offsetTop;
			}
		}
		return [curleft,curtop];
	}
};

/* Attach the calendar to a jQuery selection. */
jQuery.fn.calendar = function(settings) {
	// customise the calendar object
	jQuery.extend(popUpCal, settings || {});
	// attach the calendar to each nominated input element
	return this.each(function() {
		if (this.nodeName.toLowerCase() == 'input') {
			popUpCal.connectCalendar(this);
		}
	});
};

/* Initialise the calendar. */
jQuery(document).ready(function() {
   popUpCal.init();
});


function isValidEmail (value, level) {
	if (typeof level == "undefined") {
		level = 0;
	}
	var emailPatterns = [/.+@.+\..+$/i, /^\w.+@\w.+\.[a-z]+$/i,
/^\w[-_a-z~.]+@\w[-_a-z~.]+\.[a-z]{2}[a-z]*$/i,
/^\w[\w\d]+(\.[\w\d]+)*@\w[\w\d]+(\.[\w\d]+)*\.[a-z]{2,7}$/i];
	if (!emailPatterns[level].test(value)) {
		return false;
	}
	return true;
};

function isValidDate (value) {
	var PDate = new String(value);
	PDate = PDate.replace(/(?:(\.|,|\s))/g, "/");
	
	var regex = /(^\d{1,2})\/(\d{1,2})\/(\d{4,4})|(^\d{1,2})\/(\d{1,2})\/(\d{2,2})/;
	if (regex.test(PDate)) {
		regex.exec(PDate);
		var day = new String(RegExp.$1);
		var month = new String(RegExp.$2);
		var year = new String(RegExp.$3);
		if (month.length == 0) {
			day = new String(RegExp.$4);
			month = new String(RegExp.$5);
			year = new String(RegExp.$6);
		}
		var today = new Date();
		var thisYear = new String(today.getFullYear());
		if (year.length == 2) {
			year = (year > 50) ? (new String(Number(thisYear.substring(0, 2)) - 1) + year) : (thisYear.substring(0, 2) + year);
		}
		if (month < 1 || month > 12) {
			return false;
		}
		if (day < 1 || day > 31) {
			return false;
		}
		if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30) {
			return false;
		}
		if (month == 2) {
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day == 29 && !isleap)) {
				return false;
			}
		}
		return true;
	}
	return false;
}

function ageCheck(release,birthday) {
  if(!isValidDate(release) || !isValidDate(birthday)) {return false;}
  var RDate = new String(release);
	RDate = RDate.replace(/(?:(\.|,|\s))/g, "/");
	
  var BDate = new String(birthday);
	BDate = BDate.replace(/(?:(\.|,|\s))/g, "/");
	
	var regex = /(^\d{1,2})\/(\d{1,2})\/(\d{4,4})|(^\d{1,2})\/(\d{1,2})\/(\d{2,2})/;
	
  var rday = false;
	var rmonth = false;
	var ryear = false;
  var bday = false;
  var bmonth = false;
  var byear = false;
	
	if (regex.test(RDate)) {
    rday = new String(RegExp.$1);
  	rmonth = new String(RegExp.$2);
  	ryear = new String(RegExp.$3);
  	if (rmonth.length == 0) {
  		rday = new String(RegExp.$4);
  		rmonth = new String(RegExp.$5);
  		ryear = new String(RegExp.$6);
  	}
  } else {
    return false;
  }
  refill = [];
  if(rday.length < 2 && parseInt(rday,10) < 10 )  {
    refill[refill.length] = '0'+rday;
  } else {
    refill[refill.length] = rday;
  }
  if(rmonth.length < 2 && parseInt(rmonth,10) < 10)  {
    refill[refill.length]= '0'+rmonth;
  } else  {
    refill[refill.length]= rmonth;
  }
   refill[refill.length]= ryear;
   jQuery('#releasedate').val(refill.join('.'));
  
  
  if (regex.test(BDate)) {
    bday = new String(RegExp.$1);
  	bmonth = new String(RegExp.$2);
  	byear = new String(RegExp.$3);
  	if (bmonth.length == 0) {
  		bday = new String(RegExp.$4);
  		bmonth = new String(RegExp.$5);
  		byear = new String(RegExp.$6);
  	}
  } else {
    return false;
  }
  
  refill = [];
  if(bday.length < 2 && parseInt(bday,10) < 10)  {
    refill[refill.length] = '0'+bday;
  } else {
    refill[refill.length] = bday;
  }
  if(bmonth.length < 2 && parseInt(bmonth,10) < 10)  {
    refill[refill.length]= '0'+bmonth;
  } else  {
    refill[refill.length]= bmonth;
  }
   refill[refill.length]= byear;
   jQuery('#birthday').val(refill.join('.'));
  
  
  d1 = bmonth+'/'+bday+'/'+byear;
  d2 = rmonth+'/'+rday+'/'+ryear;
  var dateT = dateDiff(d1,d2);
  //alert(d1+':'+d2+':'+dateT);
  if(dateT < 0 || dateT > 34) {return false;}
  return true;
}

function dateDiff(d1,d2) {
    date1 = new Date();
    date2 = new Date();
    diff  = false;
    date1temp = new Date(d1 + " 00:00:00");
    date1.setTime(date1temp.getTime());
    date2temp = new Date(d2 + " 00:00:00");
    date2.setTime(date2temp.getTime());
    
    var diff = date1.getTime() - date2.getTime();
    
    var years = (diff - (diff % 31557600000)) / 31557600000;
    diff = diff - (years * 31557600000);
    var months = (diff - (diff % 2628000000)) / 2628000000;
    diff = diff - (months * 2628000000);
    var days = (diff - (diff % 86400000)) / 86400000;
    //alert(Math.floor(years*-1));
    if(days==0 && months==0 && years==-35) {return 34;}
    return years*-1;

    
    
    //alert(date1.getDay()+':'+date1.getMonth()+':'+date2.getDay()+':'+date2.getMonth()+':'+date1.getFullYear()+':'+date2.getFullYear());
    
    //diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
    //timediff = diff.getTime();
    //return Math.floor(timediff / 31536000000);
  }

function timeCheck(release) {
  if(!isValidDate(release)) {return false;}
  var RDate = new String(release);
	RDate = RDate.replace(/(?:(\.|,|\s))/g, "/");
	
  var regex = /(^\d{1,2})\/(\d{1,2})\/(\d{4,4})|(^\d{1,2})\/(\d{1,2})\/(\d{2,2})/;
	
  var rday = false;
	var rmonth = false;
	var ryear = false;
  
	if (regex.test(RDate)) {
    rday = new String(RegExp.$1);
  	rmonth = new String(RegExp.$2);
  	ryear = new String(RegExp.$3);
  	if (rmonth.length == 0) {
  		rday = new String(RegExp.$4);
  		rmonth = new String(RegExp.$5);
  		ryear = new String(RegExp.$6);
  	}
  } else {
    return false;
  }
  
  //alert(rday+':'+rmonth+':'+ryear);
  
  var getMinMaxYear = calcSettingsRelease.validationRange.split(':');
  var getMinMonthYear = getMinMaxYear[0].split('.');
  var minMonth = getMinMonthYear[1];
  var minYear = getMinMonthYear[0];
  
  var getMaxMonthYear = getMinMaxYear[1].split('.');
  var maxMonth = getMaxMonthYear[1];
  var maxYear = getMaxMonthYear[0];
  
  //alert(parseInt(rmonth)+':'+parseInt(minMonth));
  
  
  if(ryear < minYear) { 
    return false;
  } 
  if((ryear==minYear) && parseInt(rmonth,10) < parseInt(minMonth,10)) {
    return false;
  }  
  if((ryear) > maxYear) { 
    return false;
  } 
  if((ryear==maxYear) && parseInt(rmonth,10) > parseInt(maxMonth,10)) {
    return false;
  }
  return true;
}


function handleFormNav() {
  jQuery('form.contribution div.form-steps li').click(function(){
    
    if(jQuery(this).is('.visited')) {
      jQuery('div.form-steps li.active').removeClass('active');
      jQuery(this).removeClass('visited').addClass('active');
      var r = jQuery('a',this).attr('rel');
      jQuery('form.contribution div.form-block').hide();
      jQuery('form.contribution div.form-block:eq('+r+')').show();
    }
    return false;
  });
}

function checkFields(box) {
  var errors = 0;
  var errorstr = "";
  jQuery('.error-message',box).html('<div class="e"><strong>Achtung:</strong></div>');
  var em = jQuery('.error-message',box);
  var ccchecked = false;
  jQuery('div.required:visible',box).each(function(){
      jQuery(this).removeClass('error');
      var msg ="";
      if(jQuery('.form-field-error-desc',this).size()>0) {
        msg = jQuery('.form-field-error-desc',this).html();
      } else if(jQuery('.form-field-desc',this).size()>0) {
        msg = jQuery('.form-field-desc',this).html();
      } else {
        var ltest = jQuery('label',this).text();
        msg = 'Im Feld '+ltest+' ist ein Fehler aufgetreten, bitte &uuml;berpr&uuml;fen Sie ihre Angaben';
      }
      
      var v = jQuery('input,textarea,select',this).val();
      var cid = jQuery('input,textarea,select',this).attr('id');
      
      if(!ccchecked) {
        if(cid=='salutation_2' || cid=='salutation_1') {
          if(!jQuery('#salutation_2').is(':checked') && !jQuery('#salutation_1').is(':checked')) {
            if(msg!="") {
              var m = jQuery('<div id="e_'+jQuery(this).attr('id')+'" class="e" rel="'+jQuery(this).attr('rel')+'">'+msg+'</div>').appendTo(em);
              jQuery(m).click(function(){
                var xx = jQuery(this).attr('rel');
                jQuery('#'+xx+'_2').focus();
              }).css({'cursor':'pointer'});
              msg = "";
            }
          } 
        }
      }
      if(!v || v=="" || jQuery.trim(v)=="" || v=="-") {
        errors++;
        if(msg!="") {
          var m = jQuery('<div id="e_'+jQuery(this).attr('id')+'" class="e" rel="'+jQuery(this).attr('rel')+'">'+msg+'</div>').appendTo(em);
          jQuery(m).click(function(){
            var xx = jQuery(this).attr('rel');
            jQuery('#'+xx).focus();
          }).css({'cursor':'pointer'});
          msg = "";
        }
        
        jQuery(this).addClass('error');
      } else {
        //special errors...
        if(cid=="email" && !isValidEmail(v)) {
          errors++;
          jQuery(this).addClass('error');
          if(msg!="") {
            var m = jQuery('<div id="e_'+jQuery(this).attr('id')+'" class="e" rel="'+jQuery(this).attr('rel')+'">'+msg+'</div>').appendTo(em);
            jQuery(m).click(function(){
              var xx = jQuery(this).attr('rel');
              jQuery('#'+xx).focus();
            }).css({'cursor':'pointer'});
            msg = "";
          } 
        } 
        
        if(cid=="birthday" && !ageCheck(jQuery('#releasedate').val(),v)) {
            errors++;
            jQuery(this).addClass('error');
              var xmsg = jQuery('.form-field-error-desc',jQuery('#div_birthday')).html();         
              var m = jQuery('<div id="e_'+jQuery(this).attr('id')+'" class="e" rel="'+jQuery(this).attr('rel')+'">'+xmsg+'</div>').appendTo(em);
              jQuery(m).click(function(){
                var xx = jQuery(this).attr('rel');
                jQuery('#'+xx).focus();
              }).css({'cursor':'pointer'});
          }
        if(cid=="releasedate" && !timeCheck(v)) {
            errors++;
            jQuery(this).addClass('error');
            if(msg!="") {
              var m = jQuery('<div id="e_'+jQuery(this).attr('id')+'" class="e" rel="'+jQuery(this).attr('rel')+'">'+msg+'</div>').appendTo(em);
              jQuery(m).click(function(){
                var xx = jQuery(this).attr('rel');
                jQuery('#'+xx).focus();
              }).css({'cursor':'pointer'});
              msg = "";
            }
          }
        }    
  });
  if(errors == 0) {
    jQuery('.error-message',box).html('');
  } else {
    jQuery('.error-message',box).show();
    var emB = jQuery('.error-message',box)[0];
    emB.scrollIntoView(true);

  }
  return errors;
}

function checkField(field) {
  var p = jQuery(field).parents('div.field');
  if(jQuery(p).is('.required')) {
    var v = jQuery(field).val();
    if(!v || v=="" || jQuery.trim(v)=="" || v=="-") {
      jQuery(p).addClass('error');
      if(jQuery('#e_div_'+cid).size()>0) {
        jQuery('#e_div_'+cid).hide();
        var ep = jQuery('#e_div_'+cid).parents('.error-message');
        jQuery(ep).show();
      }
        
    } else {
      var cid = jQuery(field).attr('id');
      if(jQuery('#e_div_'+cid).size()>0) {
        jQuery('#e_div_'+cid).hide();
        var ep = jQuery('#e_div_'+cid).parents('.error-message');
        var t = jQuery('div:visible',ep).size();
        if(t==1) {jQuery(ep).hide();}
      }
      jQuery(p).removeClass('error');
    }
  }
}

function addToolTip(elm) {
    if(jQuery('#ToolTip').size()==0) {
      var tooltip = jQuery('<div id="ToolTip"></div>').appendTo('body');
      jQuery(tooltip).css({'position':'absolute','left':0,'top':0,'zIndex':200,'display':'none'});
    	var o = 40 / 4;
    	var pos = [[0,0],[0,-4],[-2,0],[0,-8],0,[-2,-8],[0,-2],[0,-6],[-2,-2]];
    	var dim = { 'height': (2*o) +'px', 'width': (2*o) +'px' };
    	var table = jQuery('<table border="0" cellspacing="0" cellpadding="0"><tbody></tbody></table>').appendTo(tooltip);
    	var td = [];
    	for (var i = 0; i <= 8; i++) {
    		if (i % 3 == 0) {tr = jQuery('<tr></tr>').css({'height':'auto'}).appendTo(table);}
    		var style = i != 4 ? { 'lineHeight': '0', 'fontSize': '0'} : { 'position' : 'relative' };
        td[i] = jQuery('<td></td>').css(style).appendTo(tr);
        if (pos[i]) {
    			if (jQuery.browser.msie) {
    			  var w = (i == 1 || i == 7) ? '100%' : 40 +'px';
    				var div = jQuery('<div class="xx"></div>').css({ 'width': '100%', 'height': '100%', 
            'position': 'relative', 'overflow': 'hidden'}).appendTo(td[i]); 				
    				if(i==3 || i==5) {jQuery(div).css({'height':(115)+'px'});}
    				var subdiv = jQuery('<div></div').css({ 
    						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale, src='fileadmin/template/main/css/img/rounded-white_2.png')", 
    						'position': 'absolute',
    						'width': w, 
    						'height': 3000+'px',
    						'left': (pos[i][0]*o)+'px',
    						'top': (pos[i][1]*o)+'px'
    					}).appendTo(div);
    			} else {
    			   jQuery(td[i]).css({'backgroundImage': 'url(fileadmin/template/main/css/img/rounded-white_2.png)',
             'backgroundPosition':(pos[i][0]*o)+'px '+(pos[i][1]*o)+'px'});
    			}
    			jQuery(td[i]).css(dim);
    		}
        if(i==4) {jQuery(td[i]).css({'padding':'0 5px','backgroundColor':'#eee','width':+250+'px','height':25+'px'});}
      }
      jQuery(tooltip).append('<div id="rwb"></div>')
      if (jQuery.browser.msie) {
        jQuery('#rwb').css({'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale, src='fileadmin/template/main/css/img/rounded-white_2.png')"});
      } else {
        jQuery('#rwb').css({'backgroundImage': 'url(fileadmin/template/main/css/img/rounded-white_2.png)'});
      }
  	} else {
     var tooltip = jQuery('#ToolTip');
    }
    jQuery(elm).mouseover(function(event) {
        var pcon = jQuery(this).parents('.formfield');
        if(jQuery('.form-field-desc',pcon).size()>0) {
          con = jQuery('.form-field-desc',pcon).html();
          jQuery(this).attr('title','');
          jQuery('td:eq(4)',tooltip).html(con);
          
          l = event.pageX;
  			  t = event.pageY;
  			  if (jQuery.browser.msie) {
            jQuery('td:eq(3) div.xx, td:eq(5) div.xx',tooltip).css({'height':(25)+'px'});
          }
          jQuery(tooltip).show();
          var H = jQuery(tooltip)[0].offsetHeight;
          var TTH = jQuery('td:eq(3)',tooltip)[0].offsetHeight;
          if (jQuery.browser.msie) {
            jQuery('td:eq(3) div.xx, td:eq(5) div.xx',tooltip).css({'height':(TTH)+'px'});
          }
          jQuery(tooltip).css({left:l,top:t-H});
        }
        return false;
    }).mouseout(function() {
        jQuery('td:eq(4)',tooltip).html('');
        jQuery(tooltip).hide();
        return false;
    });
}

jQuery().ready(function(){
  
  if(jQuery('form.contribution').size()>0) {
    jQuery('.filefield input').focus(function(){jQuery(this).val('')});
    jQuery('#captchareloading a').click(function(){
        var rn =Math.floor(Math.random()*1100)
        var isrc = jQuery('img.captcha-img').attr('src')+'?r='+rn;
        jQuery('img.captcha-img').attr('src',isrc);
        return false;
    });
    
    jQuery('.formfield').each(function(){
      if(jQuery('.form-field-desc',this).size() > 0) {
        jQuery('.form-field-desc').hide();
        var l = jQuery('label',this);
        var s = jQuery('<span class="addToolTip">&nbsp;&nbsp;</span>').appendTo(l);
        //jQuery(l).addClass('addToolTip');
        addToolTip(s);
      }
    });
    jQuery('#birthday').calendar(calcSettingsBirthday);
    jQuery('#releasedate').calendar(calcSettingsRelease);
    //jQuery('form.contribution div.form-steps li a').click(function(){return false;});
    jQuery('form.contribution div.form-steps li:last').addClass('last');
    jQuery('form.contribution div.form-block:gt(0)').hide();
    jQuery('form.contribution select').change(function(){
      if(jQuery(this).attr('id')=='type') {
        var _sel = this;
        var _v = jQuery(this).val();
        var _vt = _sel[_sel.selectedIndex].text;
        jQuery('#contributionHDL').text('Beitrag: '+ _vt);
        if(_vt!='Online') {
          jQuery('#div_contributionlink,#urllinktext').hide();
        }
        jQuery('.filefield input').each(function() {
           var _n = jQuery(this).attr('id');
           if(_n.indexOf('contri')!=-1) {
              var _nn = _n.split('_');
              var _p = jQuery(this).parents('.filefield');
               if(_nn[1]!=_v) {
                jQuery(_p).hide();
                jQuery(this).val('').hide();
              } else {
                jQuery(_p).show();
                jQuery(this).show();
              } 
           }
        });
        
      }
      checkField(this);}
    
    );
    jQuery('form.contribution .formfield input, form.contribution .formfield textarea').blur(function(){
      if(jQuery('.error-message:visible').size()>0) {
        checkField(this);}
      }
    );
  
    
    jQuery('button.next').click(function() {
     jQuery('#BERROR').hide();
     var r = jQuery(this).attr('rel');
      var p = jQuery(this).parents('div.form-block');
      var e = checkFields(p);
      if(e > 0) {return false;}
      var prev = r-1;
      jQuery(p).hide();
      jQuery('form.contribution div.form-steps li:eq('+r+')').addClass('active');
      jQuery('form.contribution div.form-steps li:eq('+prev+')').addClass('visited');
      jQuery('form.contribution div.form-block:eq('+r+')').show();
      // the form output...
      if(r==2) {
        var d = [];
        jQuery('form.contribution div.form-block:lt('+r+') .field').each(function(){
          var l = "";
          var v = "";
          var ppp = this;
          
          jQuery('input,textarea',this).each(function(){
            if(jQuery(this).is(':visible')) {
              l = jQuery('label',ppp).text();
              v = jQuery(this).val();
              if(!v || v=="" || jQuery.trim(v)=="" || v=="-") {
                 v = "Keine Angabe";
              }
            }
          });
          
          if(jQuery('select',this).size()>0) {
            var sel = jQuery('select',this)[0];
            v = sel[sel.selectedIndex].text;
          }
          if(l!="" && v!='Keine Angabe') {
            d[d.length] = {'label':l,'value':v};
          }
        });
        out = "";
        for(a=0; a<d.length; a++) {
          out+='<p><strong>'+d[a]['label']+'</strong>: '+d[a]['value']+'</p>';
        }
        jQuery('#FieldInfoBox').html(out);
      }
      handleFormNav();
      return false;
    });
    jQuery('button.prev').click(function() {
      var r = jQuery(this).attr('rel');
      var p = jQuery(this).parents('div.form-block');
      var prev = r;
      jQuery(p).hide();
      jQuery('form.contribution div.form-steps li:eq('+(prev-1)+')').addClass('active');
      jQuery('form.contribution div.form-steps li:eq('+(r)+')').removeClass('active').removeClass('visited');
      jQuery('form.contribution div.form-block:eq('+(prev-1)+')').show();
      handleFormNav();
      return false;
    });
    jQuery('button.submit').click(function(){
      var box = jQuery(this).parents('div.form-block');      
      var cap = jQuery('#captcha').val();
      if(!cap) {cap="";}
      if(!jQuery('#confirm').is(':checked') || !jQuery('#confirm2').is(':checked') || cap.length<5) {
        jQuery('.error-message',box).html('<div class="e"><strong>Achtung:</strong></div>');
        var em = jQuery('.error-message',box);
        if(!jQuery('#confirm').is(':checked'))  {
            var m = jQuery('<div id="e_confirm" class="e" rel="confirm">Best&auml;tigung AGBs</div>').appendTo(em);
            jQuery(m).click(function(){
              var xx = jQuery(this).attr('rel');
              jQuery('#'+xx).focus();
            }).css({'cursor':'pointer'});
        }
        if(!jQuery('#confirm2').is(':checked')) {
            var m = jQuery('<div id="e_confirm2" class="e" rel="confirm2">Best&auml;tigung Datenschutz</div>').appendTo(em);
            jQuery(m).click(function(){
              var xx = jQuery(this).attr('rel');
              jQuery('#'+xx).focus();
            }).css({'cursor':'pointer'});
        }
        if(cap.length<5) {
           var m = jQuery('<div id="e_captcha" class="e" rel="captcha">Captcha Text eingeben!</div>').appendTo(em);
            jQuery(m).click(function(){
              var xx = jQuery(this).attr('rel');
              jQuery('#'+xx).focus();
            }).css({'cursor':'pointer'});
        }
        jQuery(em).show();
        var emB = jQuery('.error-message',box)[0];
        emB.scrollIntoView(true);
        return false;
      } else {
        jQuery('#BERROR').hide();
        var em = jQuery('.error-message',box);
        jQuery(em).hide();
      }
      jQuery('.error-message, .form-steps, .form-block').hide();
      if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
    		jQuery("body","html").css({height: "100%", width: "100%"});
    		jQuery("html").css("overflow","hidden");
    		if (document.getElementById("TBX_overlay") === null) {//iframe to hide select elements in ie6
    			jQuery("body").append("<div id='TBX_overlay'></div>");
    			jQuery("#TBX_overlay").click(function() {return false;});
    		}
    	}else{//all others
    		if(document.getElementById("TBX_overlay") === null){
    			jQuery("body").append("<div id='TBX_overlay'></div>");
    			jQuery("#TBX_overlay").click(function() {return false;});
    		}
    	}
      
            
      var f = jQuery('form.contribution')[0];
      jQuery('<p><br /><br /><br /><strong>Bitte warten Sie einen Moment, Ihre Daten werden gespeichert!</strong><br /><img src="fileadmin/template/main/css/img/loader1.gif" /><br /><br /></p>').appendTo('form.contribution');
      f.submit();
      return false;
    });
    var _s = jQuery('#type')[0];
    _s[0].selected = true;
    handleFormNav();
    var cnt = 0;
  }
});