jQuery.noConflict();
var JQSummCheckHelperInt = 0;
var JQSummTimeOut = false;
function jqcalcsummcheck (id) {
	JQSummCheckHelperInt = 0;
	var myval = 0;
	jQuery('input.jqsummtgt[rel="'+id+'"]').each(function()  {
		myval = parseInt(jQuery(this).val());
		JQSummCheckHelperInt = JQSummCheckHelperInt+myval;
	});
	if (JQSummCheckHelperInt > 0) {
		myval = parseInt(jQuery('input#'+id).val());
		var testval = Math.ceil(JQSummCheckHelperInt/2);
		if (myval < testval) {
			jQuery('input#'+id).val(testval);
		}
	}
	
	
}

jQuery(document).ready(function() {
	
	jQuery('input.jqsummtgt').keyup(function() {
		
		var myval = jQuery(this).val();
		if (myval.length > 0) {
			myval = parseInt(myval);		
			if (isNaN(myval)) {
				jQuery(this).val(0);
				return;
			}
			jQuery(this).val(myval);
			jqcalcsummcheck(jQuery(this).attr('rel'));
		}
	}).blur(function() {
		var myval = jQuery(this).val();  
		if (myval.length < 1) jQuery(this).val(0);
		jqcalcsummcheck(jQuery(this).attr('rel'));
	});
	jQuery('input.jqsummcheck').keyup(function() {
		if (JQSummTimeOut) window.clearTimeout(JQSummTimeOut);
		JQSummTimeOut = false;
		myval = jQuery(this).val();
		if (myval.length > 0) {
			myval = parseInt(myval);		
			if (isNaN(myval)) {
				jQuery(this).val(0);
				return;
			}
			jQuery(this).val(myval);
			JQSummTimeOut = window.setTimeout('jqcalcsummcheck("'+this.id+'")',500);
		}
		
	}).blur(function() {
		var myval = jQuery(this).val();  
		if (myval.length < 1) jQuery(this).val(0);
		if (JQSummTimeOut) window.clearTimeout(JQSummTimeOut);
		JQSummTimeOut = false;
		jqcalcsummcheck(this.id);
	});
	
	jQuery('a[href^="system/reservierungsformular.html"]').attr('target','_blank').nyroModal({
		width: 600,
		padding: 20,
		/*height: 400*/
		windowResize: true
	});
	
	jQuery('#modal .withoutspace').blur(function() {
		var dirty = jQuery(this).val();
		var clean = dirty.replace(/\s/g, "");
		jQuery(this).val(clean);
	});
	
});



