
function tcCalc(id) {
	var addid='';
	if (id) {
		addid=id;
	}
	var tcwidth=document.getElementById('tcwidth'+addid).value;
	var tcheight=document.getElementById('tcheight'+addid).value;
	var tcqmprice=document.getElementById('tcqmprice'+addid).value;
	var tcminwidth=parseInt(document.getElementById('tcminwidth'+addid).value);
	var tcminheight=parseInt(document.getElementById('tcminheight'+addid).value);
	var tcmaxwidth=parseInt(document.getElementById('tcmaxwidth'+addid).value);
	var tcmaxheight=parseInt(document.getElementById('tcmaxheight'+addid).value);
	var tccurrency=document.getElementById('tccurrency'+addid).value;
	var msg='';
	var ok='';
	var price=0;
	if (tcwidth) {
		if (tcwidth.match(/^\d{1,3}$/)) {
			tcwidth=parseInt(tcwidth);
			if (!tcminwidth || tcwidth>=tcminwidth) {
				if (!tcmaxwidth || tcwidth<=tcmaxwidth) {
					if (tcheight) {
						if (tcheight.match(/^\d{1,3}$/)) {
							tcheight=parseInt(tcheight);
							if (!tcminheight || tcheight>=tcminheight) {
								if (!tcmaxheight || tcheight<=tcmaxheight) {
									var qm=tcwidth/100*tcheight/100;
									price=qm*tcqmprice;
									if (price<tcqmprice) {
										price=tcqmprice*1;
									}
									ok='Ihr Preis: '+priceToString(formatPrice(price))+' '+tccurrency;
								} else {
									msg='Maximale Höhe von '+tcmaxheight+' cm überschritten';
								}
							} else {
								msg='Minimale Höhe von '+tcminheight+' cm unterschritten';
							}
						} else {
							msg='Höhe ungültig! Bitte nur ganze Zahlen eingeben.';
						}
					} else {
						msg='';
					}
				} else {
					msg='Maximale Breite von '+tcmaxwidth+' cm überschritten';
				}
			} else {
				msg='Minimale Breite von '+tcminwidth+' cm unterschritten';
			}
		} else {
			msg='Breite ungültig! Bitte nur ganze Zahlen eingeben.';
		}
	} else {
		msg='';
	}
	if (ok) {
		msg='<span class="tc_calc_ok">'+ok+'</span>';
		document.getElementById('tcbasketsubmit'+addid).disabled=false;
	} else {
		msg='<span class="tc_calc_error">'+msg+'</span>';
		document.getElementById('tcbasketsubmit'+addid).disabled=true;
	}
	document.getElementById('tcprice'+addid).value=formatPrice(price);
	document.getElementById('tcshowprice'+addid).innerHTML=msg;

}


function formatPrice(price) {
	price+=0.000001;
	price=price.toFixed(2);
	return price;
}

function priceToString(price) {
	price=price.toString();
	if (price.match(/\./)) {
		price=price.replace(/\./, ',');
	}
	return price;
}

function tcBasketSubmit(frm) {
        showBasketWnd();
      	frm.submit()
}

