function sendEmailFormular(nachname,vorname,strasse,plz,email,to,subject,form,message) {
	validity = true; // assume valid
	if (nachname == "") { 
		validity = false;
		alert('Bitte geben Sie ihren Nachnamen ein!');
	}
	if (vorname == "") {
		validity = false;
		alert('Bitte geben Sie ihren Vorname ein!'); 
	}
	if (strasse == "") {
		validity = false;
		alert('Bitte geben Sie eine Strasse ein!');
	}
	if (plz == "") {
		validity = false;
		alert('Bitte geben Sie eine Plz und/oder einen Ort ein!');
	}
	if (email) {
		var check = checkEmail(email);
		if (!check) {
			alert("Bitte geben Sie eine gültige Email-Adresse ein.");
		}
		validity = check;
	}
	if (validity) {
		var action = "mailto:"+to;
		if(subject != null) {
			action += '?subject=';
			action += subject;
		}
		form.action = action;
		form.encoding = 'text/plain';
		form.submit();
		alert(message);
	}
}
function sendEmailForm_Newsletter(name,email,to,subject,form,message) {
	validity = true; // assume valid
	if (name == "") {
		validity = false;
		alert('Bitte geben Sie Ihren Vor- und Nachnamen ein!'); 
	}
	
	if (email == "") {
		validity = false;
		alert('Bitte geben Sie eine Email-Adresse ein!');
	}

	if (email) {
		var check = checkEmail(email);
		if (!check) {
			alert("Email-Adresse ungültig. Bitte geben Sie eine gültige Email-Adresse ein!");
		}
		validity = check;
	}
	if (validity) {
		var action = "mailto:"+to;
		if(subject != null) {
			action += '?subject=';
			action += subject;
		}
		form.action = action;
		form.encoding = 'text/plain';
		form.submit();
		alert(message);
	}
}
function checkEmail(email) {
	var usr = "([a-zA-Z0-9][a-zA-Z0-9_.-]*|\"([^\\\\\x80-\xff\015\012\"]|\\\\[^\x80-\xff])+\")";
	var domain = "([a-zA-Z0-9][a-zA-Z0-9._-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9._-]*\\.[a-zA-Z]{2,5}";
	var regex = "^"+usr+"\@"+domain+"$";
	var myrxp = new RegExp(regex);
	var check = (myrxp.test(email));
	return check;
}

function generateUrl(onr, pnr, mnr, parameter, sessionid) {
	return generateUrlWithEnding(onr, pnr, mnr, '.html', parameter, sessionid);
}
function generateUrlWithEnding(onr, pnr, mnr, ending, parameter, sessionid) {
	var url = onr;
	if (mnr == null || mnr=='') {
		url+=',0,';
	} else {
		url+=','+mnr+',';
	}
	if (pnr!=null && pnr!='') {
		url+=pnr;
	} else {
		url+='index';
	}
	if (ending!=null && ending!='') {
		url+=ending;
	}
	if (sessionid!=null && sessionid!='') {
		url+=sessionid;
	}
	if (parameter != null) {
		url+='?'+parameter;
	}
	return url;
}
//instantSearch and autoInstantSearch for search forms
var instantSearchTimeout;
function autoInstantSearch(options,tOut) {
	clearTimeout(instantSearchTimeout);
	instantSearchTimeout = setTimeout(function() {instantSearch(options);},tOut==undefined?500:tOut);
}
function instantSearch(searchOptions) {
	searchOptions = jQuery.extend(true, {
			validate:true,
			onValidate:function(options) {
				if (jQuery(options.valueSelector).val().length < options.minValueLength) {
					clearTimeout(instantSearchTimeout);
					return false;
				}
				return true;
			},
			minValueLength:3,
			type:'POST',
			contentType:'application/x-www-form-urlencoded;charset=UTF-8',
			beforeSubmit:function(data, jqForm, options) {
				jQuery(searchOptions.targetSelector).fadeTo("slow",0.5);
				return true;
			},
			success: function(response,status,xhr,jqForm) {
				jQuery(searchOptions.targetSelector).fadeTo("slow",1);
				return true;
			},
			beforeSerialize: function(jqForm,options){},
			invalid:function(){}
	}, searchOptions);
	if (searchOptions.validate && !searchOptions.onValidate.call(searchOptions.onValidate,searchOptions)) {
			searchOptions.invalid.call(searchOptions.invalid);
	} else {
		var submitOptions={
				target:searchOptions.targetSelector, 
				url:searchOptions.url, 
				type:searchOptions.type, 
				contentType:searchOptions.contentType,
				beforeSubmit:searchOptions.beforeSubmit,
				success:searchOptions.success,
				beforeSerialize:searchOptions.beforeSerialize
		};
		jQuery(searchOptions.formSelector).ajaxSubmit(submitOptions);
	}
	clearTimeout(instantSearchTimeout);
}
//generateSearchTerm for search forms
function generateSearchTerm(options){
	var options = jQuery.extend(true,{
		searchFieldValue: function(){
			if(jQuery("input[name='searchtext']").val()=='undefined'){
				return '';
			} else {
				return jQuery("input[name='searchtext']").val();
			}
		}
	},options);
	var searchTerm = options.searchFieldValue();
	searchTerm = searchTerm.replace(/^\s/,"").replace(/\s$/,"");
	if((options.searchTermRequired=='null' || options.searchTermRequired=='true') && (searchTerm == '' || searchTerm.length < options.minValueLength)){
		return false;
	}
	else if(options.useAllSearchTerms==true){
		var searchTerms = searchTerm.split(/\s/);
		searchTerm=splitTerm(searchTerm,'AND',options);
	} else if(options.useWildcard==true){
		searchTerm=searchTerm+'*';
	}
	if(options.useSearchItems==true){
		if(options.searchItemArray==null){
			var checkedItems = jQuery("input[name='searchitem']:checked").length;
			if(checkedItems < 1){
				return false;
			}
			searchTerm = '('+searchTerm+')';
			searchTerm = searchTerm + ' AND (';
			jQuery("input[name='searchitem']:checked").each(function(index){
				searchTerm = searchTerm + "\""+jQuery(this).val()+"\"";
				if(index < (checkedItems-1)){
					searchTerm = searchTerm + ' OR ';
				}
			});
			searchTerm = searchTerm + ')';
		}
		else {
			var i=0;
			for(i=0;i<options.searchItemArray.length;i++){
				if(options.searchItemArray[i].length>0){
					searchTerm = '('+searchTerm+')';
					break;
				}
			}
			for(i=0;i<options.searchItemArray.length;i++){
				if(options.searchItemArray[i].length<1){
					continue;
				}
				searchTerm = searchTerm + ' AND (';
				jQuery(options.searchItemArray[i]).each(function(index){
					searchTerm = searchTerm + jQuery(this).val();
					if(index < (options.searchItemArray[i].length-1)){
						searchTerm = searchTerm + ' OR ';
					}
				});
				searchTerm = searchTerm + ')';
			}
		}
	}
	jQuery("input[name='search-searchterm']").val(searchTerm);
	return true;
}
function splitTerm(term, conjunction, options){
	var terms = term.split(/\s/);
	var newTerm='';
	for(var i=0; i<terms.length; i++){
		if(terms[i]!=' ' && terms[i]!=''){
			newTerm = newTerm + terms[i];
			if(options.useWildcard==true){
				newTerm = newTerm+'*';
			} 
			if(i<terms.length-1){
				newTerm = newTerm + " " +conjunction+ " ";
			}
		}
	}
	return newTerm;
}
function TrackOptions(page){
	this.page=page;
	this.urlPattern='http://simplePageSearch?q=';
}
function trackAjaxSearchWM(trackOptions){
	if(typeof wm_custnum !== 'undefined') {
		var newPageName=wm_page_name.slice(0,wm_page_name.lastIndexOf('|'))+'|'+trackOptions.page;
		wm_page_name=newPageName;
		var q='';
		jQuery("*[tracklabel]").each(function(index){
			var value = jQuery(this).val();
			if(typeof String.prototype.trim !== 'function') {
				value = value.replace(/^\s+|\s+$/g, '');
			} else {
				value = value.trim();
			}
			if(value!=''){
				q=q+jQuery(this).attr("tracklabel")+':'+encodeURIComponent(value.replace(/(\s)+/g,'_'))+' ';
			}
		});
		//IE7 und IE8 Komp-Modus beachten
		if(q!=''){
			wm_referrer=trackOptions.urlPattern+q;
			wiredminds.count();
		}
	}
}
function setOptionSelected(element, value){
	if(element!='' && value != ''){
		element = element + '>option';
		jQuery(element).each(function(index){
			if(jQuery(this).val()==value){
				jQuery(this).attr("selected","selected");
				return;
			}
		});
	}
}
function setAllOptionsSelected(element){
	if(element!='') {
		element = element + '>option';
		jQuery(element).attr('selected','selected');
	}
}
function showSimpleDialog(dialogOptions){
	jQuery(dialogOptions.elementSelector).click(function(){
		jQuery(dialogOptions.dialogElementSelector).dialog(dialogOptions);
		jQuery(dialogOptions.dialogElementSelector).dialog("open");
		return dialogOptions.returnValue;
	});
}
function submitForm(submitOptions) {
	if (submitOptions.pnr==null||submitOptions.pnr=='') {
		submitOptions.pnr=submitOptions.requestPnr;
	}
	var action = generateUrl(submitOptions.requestOnr, submitOptions.pnr, submitOptions.requestMnr, submitOptions.parameter, submitOptions.jsessionid);
	document.forms[submitOptions.formname].action = action;
	document.forms[submitOptions.formname].target='_self';
	document.forms[submitOptions.formname].submit();
}
function submitSimpleForm(submitOptions) {
	document.forms[submitOptions.formname].action = submitOptions.action;
	document.forms[submitOptions.formname].submit();
}
function replaceWhitespaces (txt){
	while (txt.match (/\s/)){
		txt = txt.replace (' ', '');
	}
	return txt;
}
function sendFormMail(mailOptions){
	var string="mailto:"+mailOptions.mail+'?subject='+encodeMailText(mailOptions.subject)+'&body='+encodeMailText(mailOptions.body);
	window.location.href=string;
}
function encodeMailText(text,browser) {
	// geht nur in outlook besser waere eigentlich encodeURIComponent(text)
	text = escape(text);
	return text;
}
function prepareValidation(validateRules){
	jQuery.each(validateRules.fields,function(fieldkey,fieldvalue){
		var fieldclass = '{';
		var fieldmessages='messages:{';
		jQuery.each(fieldvalue.rules,function(ruleskey,rulesvalue){
			if(rulesvalue.condition=='true'){
				fieldclass += rulesvalue.name+':'+rulesvalue.condition+',';
			}else {
				fieldclass += rulesvalue.name+':'+"'"+rulesvalue.condition+"'"+',';
			}
			fieldmessages += rulesvalue.name+':'+"'"+rulesvalue.message+"'";
			if (ruleskey != fieldvalue.rules.length-1){
				fieldmessages += ',';
			}
		});
		fieldclass+=fieldmessages+'}}';
		jQuery(fieldvalue.selector).addClass(fieldclass);
	});
}
function formatAutocompletePostalCodesCallback(response, type){
	if(response.data && response.data.jsonaddress && jQuery.isArray(response.data.jsonaddress)){
		return jQuery.map(response.data.jsonaddress, function(item) {
			if(type=='pocs'){
				return {
					label: item.postalCode+' '+item.city+' '+item.urbanDistrict,
					value: item.postalCode,
					placeName: item.city,
					postalCode: item.postalCode,
					urbanDistrict: item.urbanDistrict
				}
			} else if(type=='cities'){
				return {
					label: item.postalCode+' '+item.city+' '+item.urbanDistrict,
					value: item.city,
					placeName: item.city,
					postalCode: item.postalCode,
					urbanDistrict: item.urbanDistrict
				}
			} else if(type='urbanDistricts'){
				return {
					label: item.postalCode+' '+item.city+' '+item.urbanDistrict,
					value: item.urbanDistrict,
					placeName: item.city,
					postalCode: item.postalCode,
					urbanDistrict: item.urbanDistrict
				}
			}
		});
	} else if(response.data && response.data.jsonaddress && jQuery.isArray(response.data.jsonaddress)==false){
		var fieldValue=response.data.jsonaddress.postalCode;
		if(type=='cities'){
			fieldValue=response.data.jsonaddress.city;
		} else if(type=='urbanDistricts'){
			fieldValue=response.data.jsonaddress.urbanDistrict
		}
		return ([{
			label: response.data.jsonaddress.postalCode +' '+response.data.jsonaddress.city + ' ' + response.data.jsonaddress.urbanDistrict,
			value: fieldValue,
			placeName: response.data.jsonaddress.city,
			postalCode: response.data.jsonaddress.postalCode,
			urbanDistrict: response.data.jsonaddress.urbanDistrict
		}]);
	}
}
function copySelectedFieldText(select, input){
	var element=select+'>option:selected';
	jQuery(input).val(jQuery(element).text());
}
function placeholderOnclick (element,text){
	if (element.value==text){element.value=''}
}
function placeholderOnblur (element,text){
	if (element.value==''){element.value=text}
}
function checkGruppen(control){
	name=control.name.substring(0,3);
	if( control.name.length!=3 ){
		//Gruppentyp => alle Untergruppen anchecken
		for( i=0; i<document.frmBServer.elements[name].length; i++ ){
			document.frmBServer.elements[name][i].checked=control.checked;
		}
	} else {
		//Untergruppe => wenn alle angechecked, Gruppentyp auch anchecken
		if( control.checked==true ){
			for( i=0; i<document.frmBServer.elements[name].length; i++ ){
				if( document.frmBServer.elements[name][i].checked==false ){
					return;
				}
			}
			name += document.frmBServer.elements[name][0].value.substring( document.frmBServer.elements[name][0].value.indexOf('_') );
			document.frmBServer.elements[name].checked='checked';
		} else {
			// Untergruppe abgechecked, Gruppentyp auch abchecken
			name += document.frmBServer.elements[name][0].value.substring( document.frmBServer.elements[name][0].value.indexOf('_') );
			document.frmBServer.elements[name].checked='';
		}
	}
}
function checkAllGruppen(){

	checkGruppen( document.frmBServer.elements['tec'][0] );
	checkGruppen( document.frmBServer.elements['per'][0] );
	checkGruppen( document.frmBServer.elements['bet'][0] );
	checkGruppen( document.frmBServer.elements['son'][0] );
	checkGruppen( document.frmBServer.elements['ges'][0] );
	checkGruppen( document.frmBServer.elements['edv'][0] );
}
function checkMailTo(control, form, name){
	form.elements[name].checked=control.checked;
	for( i=0; i<form.elements[name].length; i++ ){
		form.elements[name][i].checked=control.checked;
	}
}
function checkAllMailTo(control, form, name){
	if( control.checked==false ){
		form.elements[name].checked=false;
	} else {
		for( i=0; i<form.elements[control.name].length; i++ ){
			if( form.elements[control.name][i].checked==false ){
				return;
			}
		}
		form.elements[name].checked=true;
	}
}
function countChar( control, id, maxChars ){
	if( control.value.length > maxChars ){
		document.getElementById(id).style.backgroundColor='red';
	} else {
		document.getElementById(id).style.backgroundColor='white';
	}
}
function setElementValue (element,value){
	jQuery(element).val(value);
}
function charCounter( countElement, inLength, max ){
	countElement.value = (max-inLength);
}
function checkSelectValue(control, value){
	var i=0;
	for(i=0; i<control.options.length; i++){
		if(control.options[i].value==value){
			control.options[i].selected=true;
			break;
		}
	}
}
function addBookmark(bookmarkOptions){
	var bookmarkOptions = jQuery.extend(true, {
		target : '#tobookmark',
		type : 'POST', 
		contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
		autoOpen: false,
		width: '300',
		height: '100',
		title: 'Notiz',
		resizable: false,
		draggable: false,
		position: 'top',
		show: 'blind',
		hide: 'blind',
		buttons: {"speichern":function(){jQuery("input[name='bmaComment']").val(jQuery("textarea[name='bmaNotice']").val());bookmarkOptions.form.ajaxSubmit(bookmarkOptions);jQuery(this).dialog("close");},"abbrechen":function(){jQuery(this).dialog("close");}},
		modal: false
	}, bookmarkOptions); //deep copy
	bookmarkOptions.dialogElement.dialog(bookmarkOptions);
	bookmarkOptions.submitElement.click(function(){
		bookmarkOptions.dialogElement.dialog("open");
	});
}
function createJCarousel(options){
	var options = jQuery.extend(true, {
		scroll: 1,
		wrap: 'circular',
		buttonNextHTML: null,
		buttonPrevHTML: null
	},options); // deep copy
	options.element.jcarousel(options);
}

function addBookmarkComment(options){
	var commentOptions = jQuery.extend(true,{
		target : '#mybookmarks',
		type : 'POST',
		contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
		autoOpen: false,
		width: '300',
		height: '100',
		title: 'Notiz',
		position: 'top',
		show: 'blind',
		hide: 'blind',
		resizable: false,
		draggable: false,
		buttons: {"speichern":function(){
				jQuery("input[name='bmaComment']").val(options.commentElement.val());
				jQuery("input[name='bmaId']").val(options.id);
				jQuery(this).dialog("close");
				jQuery("form[name='bmaForm']").ajaxSubmit(commentOptions);
				},
			"abbrechen":function(){jQuery(this).dialog("close");}},
		modal: false
	},options);
	jQuery(commentOptions.submitElement).click(function(){
		jQuery(commentOptions.dialogElement).dialog(commentOptions);
		jQuery(commentOptions.dialogElement).dialog("open");
	});
}

function clearFormElements(ele) {
	jQuery(ele).find(':input').each(function() {
		switch(this.type) {
			case 'password':
			case 'select-multiple':
			case 'select-one':
			case 'text':
			case 'textarea':
				jQuery(this).val('');
				break;
			case 'checkbox':
			case 'radio':
				this.checked = false;
		}
	});
}

function submitFormOnEnter(element,options){
	jQuery(element).keydown(function(event){
		if(event.which==13){
			submitForm(options);
			return false;
		}
	});
}
