function showDetail(id, type) {
	if (type == "therapeuten")	window.location.href = "/web/Deutsch/TherapeutenDetail/?id="+id+"&action=therapeutendetail";
	if (type == "supervisoren")	window.location.href = "/web/Deutsch/SupervisorenDetail/?id="+id+"&action=supervisorendetail";
	if (type == "selbsterfahrungsleiter")	window.location.href = "/web/Deutsch/SelbsterfahrungsleiterDetail/?id="+id+"&action=supervisorendetail";
	if (type == "veranstaltungen")	window.location.href = "/web/Deutsch/Homepage/Veranstaltungen_Details/?id="+id;
}

function showMap(url, event) {
	Event.stop(event);
	window.open(url, '_blank', 'statusbar=no,location=no,left=100,top=100,width=800,height=600,scrollbars=yes,resizable=yes');
}

function mark(which) {
	which = $(which);
	which.setStyle({
		  backgroundColor: '#fbfbfb'
	});
}
function unmark(which) {
	which = $(which);
	which.setStyle({
		  backgroundColor: '#f4f4f4'
	});
}

function array_unique(ar){
	if(ar.length && typeof ar!=='string'){
		var sorter = {};
		var out = [];
		for(var i=0,j=ar.length;i<j;i++){
			if(!sorter[ar[i]+typeof ar[i]]){
				out.push(ar[i]);
				sorter[ar[i]+typeof ar[i]]=true;
			}
		}
	}
	return out || ar;
}

function submit_event_form() {
	
	error = false;
	error_message = "Bitte beachten:\n";
	
	positions = $$('.pos');

	positions_all = new Array();
	positions_unique = new Array();
			
	positions.each(function(s) {
		if(s.checked) {
			s.classNames().each(function(c) {
				if(c != "pos") positions_all.push(c);
			});
		}
	});
	positions_unique = array_unique(positions_all);
	
	if(positions_unique.length == 0) {
		error = true;
		error_message += "\n- keine Veranstaltung ausgewählt\n\n";
	}
		
	if (!$('vorname').value) {
		error = true;
		error_message += "- Vorname fehlt\n";
	}
	if (!$('name').value) {
		error = true;
		error_message += "- Nachname fehlt\n";
	}
	if (!$('email').value) {
		error = true;
		error_message += "- E-Mail fehlt\n";
	}
	if (!$('telefon').value) {
		error = true;
		error_message += "- Telefonnummer fehlt\n";
	}
	if(error) {
		alert(error_message);
	} else {
		document.forms.event_form.submit();
	}
}

function submit_payment_form() {

	error = false;
	error_message = "Bitte beachten:\n";
	if (!$('bankeinzug').checked) {
		error = true;
		error_message += "- Genehmigung zum Lastschrifteinzug fehlt\n";
	}	
	if (!$('inhaber').value) {
		error = true;
		error_message += "- Inhaber fehlt\n";
	}
	if (!$('institut').value) {
		error = true;
		error_message += "- Institut fehlt\n";
	}
	if (!$('kontonr').value) {
		error = true;
		error_message += "- Kontonr fehlt\n";
	}
	if (!$('blz').value) {
		error = true;
		error_message += "- BLZ fehlt\n";
	}
	if(error) {
		alert(error_message);
	} else {
		document.forms.payment_form.submit();
	}
}

function submit_waitlist_form() {

	error = false;

	if (!$('email').value) {
		error = true;
		error_message += "E-Mailadresse fehlt!";
	}
	if(error) {
		alert(error_message);
	} else {
		document.forms.waitlist_form.submit();
	}
}

function toggle_checkbox (obj, which, e) {

	which = $(which);
	
	if(obj.type != "checkbox"){
		if (which.checked){
			which.checked = false;
		} else {
			which.checked = true;
		}
	}
	
	toggle_position(which);

}

function toggle_position (which) {
	which = $(which);
	
	if (which.hasClassName("pos")){
		v_id = which.readAttribute('v_id');
		pos_id = which.readAttribute('pos_id');
		if (which.checked){
			// hinzufuegen zu liste
			slot = new Object();
			slot.from = which.readAttribute('from');
			slot.till = which.readAttribute('till');
			slot.pos_id = pos_id;
			time_conflict = false;
			days[v_id]['times'].each(function(el){
				if(slot.from >= el.from && slot.from < el.till) {
					time_conflict = true;
				}
				if(slot.till > el.from && slot.till <= el.till) {
					time_conflict = true;
				}
				if(slot.from <= el.from && slot.till >= el.till) {
					time_conflict = true;
				}
			});
			if(time_conflict) {
				alert('Zum Zeitpunkt der ausgewählten Position haben Sie schon eine andere Position ausgewählt. Um die Position trotzdem auswählen zu können entfernen Sie bitte die andere Position.');
				which.checked = false;
			} else {
				days[v_id]['times'].push(slot);
			}
		} else {
			// entfernen aus liste
			new_times = new Array();
			days[v_id]['times'].each(function(el){
				if(el.pos_id != pos_id){
					new_times.push(el);
				}
			});
			days[v_id]['times'] = new_times;
		}
	}
	update_sum ();
}

function update_sum () {
	
	// get all prices
	positions = $$('.pos');
	options = $$('.opt');
	
	positions_all = new Array();
	positions_unique = new Array();
			
	var positions_sum = 0.00;
	var options_sum = 0.00;
	
	positions.each(function(s) {
		if(s.checked) {
			s.classNames().each(function(c) {
				if(c != "pos") positions_all.push(c);
			});
		}
	});
	positions_unique = array_unique(positions_all);
	positions_unique.each(function(s) {
		positions_sum += parseFloat($(s+"_price").value);
	});
	options.each(function(s) {
		if(s.checked) {
			options_sum += parseFloat(s.up('.row_option').down('.col_price').down('span').innerHTML);
		}
	});
	
	//$('price_sum').innerHTML = price_format(positions_sum+options_sum); // set sum
	//$('price_vat').innerHTML = price_format((positions_sum+options_sum)*0.19); // set vat
	$('price_sum_vat').innerHTML = price_format((positions_sum+options_sum)); // set sum+vat

	$('preis_gesamt').value = positions_sum+options_sum; // set parameter

}

function price_format(price) {
	price = price.toFixed(2);
	price = price.replace(/\./,",");
    while(price.match(/^(\d+)(\d{3}\b)/)) {
    	price = price.replace(/^(\d+)(\d{3}\b)/, RegExp.$1 + '.' + RegExp.$2);
    }
    return price;
}

