function clrHeaderSearch(inp) {
	if (inp.value == 'Neue Suche') {
		inp.value = '';
	}
}
function clrInput(inp) {
	if (inp.value == inp.defaultValue) {
		inp.value = '';
	}
}
function switchBlock(control,id,show){
    if (document.getElementById(control).checked){
        document.getElementById(id).style.display=show;
        document.getElementById(id).disabled=false;
      
    } else {
        document.getElementById(id).style.display='none';
        document.getElementById(id).disabled=true;
    }
}
function switchCheckbox(box, form) {
	if (document.forms[form].elements[box].type == 'radio' && document.forms[form].elements[box].checked)
		return false;
	document.forms[form].elements[box].checked = !document.forms[form].elements[box].checked;
	return false; 
}
function clr(field) {
	field.value = '';
}
function ref(field) {
	if (field.value == '')
		field.value = field.defaultValue;
}
function resizeToImg(imgId) {
	self.resizeTo(window.document.getElementById(imgId).width + 8, window.document.getElementById(imgId).height + 50);
}
function saalplan(win) {
	window.open('', win, 'height=200,width=300,resizable=1,location=0,menubar=0,toolbar=0,status=0');
}
function popup(win) {
	var w = window.open('', win, 'height=400,width=560,resizable=1,scrollbars=1,location=0,menubar=0,toolbar=0,status=0');
	w.focus();
}
function bigPopup(win) {
	var x = Math.min(screen.availWidth - 200, 750);
	var y = Math.min(screen.availHeight - 300, 750);
	var w = window.open('', win, 'height=' + y + ',width=' + x + ',resizable=1,scrollbars=1,location=0,menubar=0,toolbar=0,status=0');
	w.focus();
}
function changeInput(e, field, next, maxlength) {
	var key = e.keyCode;
	if ((key >= 65 && key <= 90) || (key >= 48 && key <= 57)) {
		if (field.value.length == maxlength) {
			next.focus();
		}
	}
}
function allowSubmit(form) {
	if (form.elements["allowSubmit"].value == "1")
		return true;
	form.elements["allowSubmit"].value = "0";
	return false;
}
function showSkyscraper(url, img, alt) {
	var w, h;
	if (self.innerHeight) {
		w = self.innerWidth;
		h = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	} else if (document.body) {
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	if (w >= 1140) {
		document.write('<div id="skyscraper"><a href="' + url + '"><img src="' + img + '" alt="' + alt + '" title="" /></a></div>');
	}
}
function framebreaker() {
	if (top.location.href != self.location.href) {
		top.location.href = self.location.href;
	}
}
function checkQuantity(sel) {
	if (sel.options[sel.options.selectedIndex].value == 'mehr') {
		q = window.prompt(unescape("Bitte geben Sie die gew%FCnschte Anzahl ein"), 11);
		q = parseInt(q);
		if (isNaN(q)) {
			sel.options.selectedIndex = 0;
		} else {
			neu = new Option(q, q, false, true);
			sel.options[sel.length] = neu;
			sel.options.selectedIndex = sel.length - 1;
		}
	}
}
function cartUpdateItem(itemId, quantity, singlePrice, input) {
	var quantity = parseInt(quantity, 10);
	if (isNaN(quantity) || isNaN(singlePrice)) {
		quantity = 0;
	}
	var price = quantity * singlePrice;
	document.getElementById(itemId).value = price;
	var td = document.getElementById(itemId + '_td');
	if (td) {
		td.replaceChild(document.createTextNode(price.toFixed(2).replace(/^(\d+)\.(\d+)$/, '$1,$2 EUR')), td.firstChild);
	}
	if (input.value) {
		input.value = quantity;
	}
	cartUpdateTotal1();
}
function togglePriceTag(itemId, priceTag) {
	var old = document.getElementById('active_' + itemId).value;
	if (old != '') {
		document.getElementById(old).setAttribute('style', 'text-decoration:line-through');
	}
	document.getElementById('active_' + itemId).value = priceTag;
	if (priceTag != '') {
		document.getElementById(priceTag).setAttribute('style', '');
	}
}
function cartUpdateTotal1() {
	var total = 0;
	var items = document.getElementsByName('__cart_item');
	for (var i = 0; i < items.length; i++) {
		var price = parseFloat(items[i].value);
		if (isNaN(price)) {
			return false;
		}
		total = total + price;
	}
	var td = document.getElementById('total_td');
	td.replaceChild(document.createTextNode(total.toFixed(2).replace(/^(\d+)\.(\d+)$/, '$1,$2 EUR')), td.firstChild);
}
function cartInsuranceUpdate(itemId, quantity, maxQuantity, singlePrice) {
	var quantity = parseInt(quantity, 10);
	if (isNaN(quantity) || isNaN(singlePrice)) {
		quantity = 0;
	}
	document.getElementById('insurance_' + itemId + '_table_row').setAttribute('style', 'display:' + ((quantity > 0) ? 'table-row' : 'none'));
	for (var i = 1; i <= maxQuantity; i++) {
		document.getElementById('insurance_' + itemId + '_row_' + i).setAttribute('style', 'display:' + ((i <= quantity) ? 'table-row' : 'none'));
	}
	document.getElementById('insurance_' + itemId + '_count').value = quantity;
	var price = quantity * singlePrice;
	document.getElementById('insurance_' + itemId + '_input').value = price;
	var td = document.getElementById('insurance_' + itemId + '_quantity');
	td.replaceChild(document.createTextNode(quantity), td.firstChild);
	var td = document.getElementById('insurance_' + itemId + '_price');
	td.replaceChild(document.createTextNode(price.toFixed(2).replace(/^(\d+)\.(\d+)$/, '$1,$2 EUR')), td.firstChild);
	cartUpdateTotal4();
}
function cartUpdateTotal4() {
	var total = 0;
	var items = document.getElementsByName('__cart_item');
	for (var i = 0; i < items.length; i++) {
		var price = parseFloat(items[i].value);
		if (isNaN(price)) {
			return false;
		}
		total = total + price;
	}
	var td = document.getElementById('subtotal_td');
	td.replaceChild(document.createTextNode(total.toFixed(2).replace(/^(\d+)\.(\d+)$/, '$1,$2 EUR')), td.firstChild);
	var delivery = parseFloat(document.getElementsByName('__delivery_price')[0].value);
	var payment = parseFloat(document.getElementsByName('__payment_price')[0].value);
	total = total + delivery + payment;
	
	var td = document.getElementById('total_td');
	td.replaceChild(document.createTextNode(total.toFixed(2).replace(/^(\d+)\.(\d+)$/, '$1,$2 EUR')), td.firstChild);
	
	var items = document.getElementsByName('__coupon_value');
	if (items && items.length) {
		for (var i = 0; i < items.length; i++) {
			var value = parseFloat(items[i].value);
			if (isNaN(value)) {
				return false;
			}
			total = total - value;
		}
		if (total < 0) {
			total = total * -1;
			var txt = document.getElementsByName('__coupon_get_change_txt')[0].value;
		} else {
			var txt = document.getElementsByName('__coupon_get_no_change_txt')[0].value;
		}
		var td = document.getElementById('get_change_txt_td');
		td.replaceChild(document.createTextNode(txt), td.firstChild);
		var td = document.getElementById('total_coupon_td');
		td.replaceChild(document.createTextNode(total.toFixed(2).replace(/^(\d+)\.(\d+)$/, '$1,$2 EUR')), td.firstChild);
	}
	var items = document.getElementsByName('__insurance_count');
	if (items) {
		var insurance = 0;
		for (var i = 0; i < items.length; i++) {
			var value = parseInt(items[i].value, 10);
			if (isNaN(value)) {
				return false;
			}
			insurance = insurance + value;
		}
		var style = (insurance > 0) ? 'display:block' : 'display:none';
		document.getElementById('insurance_agreement').setAttribute('style', style);
	}
}
