/**
 * berliner-kaffeeroesterei.de
 */
// //BOD 
function ccb() {
	// MEMBERS
	this.mahlgrad = "ungemahlen";/* defaultwert */
	this.ccb_id = 0;/* Mysql-ID ist zu setzen bei bereits vorhandenen Mischungen */
	this.gewicht = 500;/* initial Wert 250g - kann geändert werden */
	this.preis = 0;/* wird errechnet */
	this.preis_base = 250;/* basis-grammzahl */
	this.titel = "Neue Kaffeemischung";
	this.currentID = "";/* gerade bearbeitete-ID */
	this.s_id = new Array();/* Sorten-ID==ArtikelID */
	this.s_menge = new Array();/* Prozent-Wert */
	this.s_gewicht = new Array();/* Anteilsgewicht der Sorte */
	this.s_name = new Array();/* Sorten Name */
	this.s_preis = new Array();/* Sortenpreis */
	this.s_fix = new Array();/*
								 * boolscher wert - Anteil vor Veränderung
								 * schützen
								 */
	this.s_taste = new Array();/*
								 * Zahlenwert zwischen 1 und 5 - entspricht
								 * Bohnensystem im shop
								 */
	this.c_preis = new Array();/* current Preis... Preis pro Anteil */
	this.max_s = 10;/* maximale Anzahl Sorten*/
	this.tableheigth = 460;/*Höhe der Tabelle(Mühle)*/
}
// METHODS
// //
ccb.prototype.init = function(c_id, c_gewicht, c_titel, c_mahlgrad) {
	// Wiederherstellung der Mischung bei Rückkehr auf die Seite
	this.ccb_id = (typeof c_id != 'number') ? 0 : c_id;
	this.gewicht = (typeof c_gewicht != 'number') ? this.gewicht : c_gewicht;
	this.titel = (typeof c_titel != 'string')? "Neue Kaffeemischung": c_titel;
	this.mahlgrad = (typeof c_mahlgrad != 'string')? "ungemahlen": c_mahlgrad;

};
// //
ccb.prototype.init_values = function(args) {
	// ID,name,preis,menge,taste
	// Wiederherstellung der Mischung bei Rückkehr auf die Seite
	if (args.length > 0) {
		for (var i = 0; i < args.length - 4; i++) {
			// erstes Element : 0
			this.s_id.push(args[i]);
			i++;
			this.s_name.push(args[i]);
			i++;
			this.s_preis.push(args[i]);
			i++;
			this.s_taste.push(parseInt(args[i]));
			// Element 3 (viertes!)
			i++;
			this.s_menge.push(parseInt(args[i]));
			// letztes Element 4 (fünftes!)
			this.s_gewicht.push(0);
			this.c_preis.push(0);
			this.s_fix.push(false);
		}

		this.recalc();
	}
};
// //
ccb.prototype.setmenge = function(m) {
	if (m > 0)
		this.gewicht = m;
	//while (this.get_summe() != 100)
		this.recalc();

	aktualisiere_alles();
}
// //
ccb.prototype.setmahlgrad = function(m) {
	this.mahlgrad = m;
	// this.recalc();
	aktualisiere_alles();
}
// //
ccb.prototype.fix = function(fID) {
	this.s_fix[this.geti(fID)] = true;
	this.currentID ="";
	aktualisiere_alles();
}
// //
ccb.prototype.unfix = function(fID) {
	this.s_fix[this.geti(fID)] = false;
	this.currentID ="";
	aktualisiere_alles();
}
// //
ccb.prototype.notthere = function(tID) {
	var tt = true;
	for (i = 0; i < this.s_id.length; i++) {
		if (this.s_id[i] == tID) {
			var tt = false;
		}
	}
	return tt;
};

// //
ccb.prototype.geti = function(ID) {
	var tut = true;
	var ka = 0;
	while (tut) {

		if (this.s_id[ka] == ID)
			tut = false;
		ka++;
		if (ka == (this.s_id.length + 1)) {
			tut = false;
			ka = 0;
		}
	}
	return ka - 1;
};

// //
ccb.prototype.allow_add = function() {
	if(this.s_id.length == this.max_s){
	alert("Es duerfen maximal " + this.max_s + " Kaffeesorten in einer\n Mischung enthalten sein.");
	return false;
	}
	if (this.s_id.length > 0) {
		var test = false;
		for (var h = 0; h < this.s_id.length; h++) {
			if (!this.s_fix[h])
				test = true;
		}
		return test;
	} else {
		return true;
	}
}

// //
ccb.prototype.gh = function(v_h) {
	cell=46;/*minimale Zellenhoehe */
	t_h = cell * this.s_id.length;
	t_h = this.tableheigth - t_h;
	hoehe= cell + Math.round(v_h / 100  * t_h);
	return hoehe;
}
//
ccb.prototype.free_amount = function(boo/*
										 * d=Durchschnitt m=Maximum
										 * a=SummeAllerFreienWerte t=freieTeile
										 */) {
	if (this.s_id.length > 1) {
		var anteile = 0;// Anteile = d
		var ges = 0;// gesamtwert = m
		var max = 0;
		for (var u = 0; u < this.s_id.length; u++) {
			if ((this.s_fix[u] == false) && (this.currentID != this.s_id[u])) {
				anteile++;
				if (this.s_menge[u] > max)
					max = this.s_menge[u];
				ges += this.s_menge[u];
			}// endif
		}// endfor
		if (boo == "d") {
			if (anteile > 0)
				var t = ges / anteile;
			return t;
		}
		if (boo == "m") {
			return max;
		}
		if (boo == "a") {
			return ges;
		}
		if (boo == "t") {
			return anteile;
		}
	}// endif
	return 0;
}
//
ccb.prototype.add_amount = function(ID, amo) {
	this.currentID = ID;
	pao = parseInt(amo);
	// Provisoriumsvar
	var fixit = false;
	var ji = this.geti(this.currentID);
	// alert(ji+"ist der index");
	if ((this.s_menge[ji] < (100 - amo)) && (this.get_summe() == 100)
			&& (!this.s_fix[ji]) && (this.free_amount("m") > amo)) {
		this.s_menge[ji] += pao;
		// Provisorium mit FIX
		this.s_fix[ji] = true;
		fixit = true;
	}
	while (this.get_summe() != 100)
		this.recalc();

	// zum Provisorium
	if (fixit)
		this.s_fix[ji] = false;
	// alert(this.get_summe()+"summe nach test++");

}
//
ccb.prototype.sub_amount = function(ID, amo) {
	pao = parseInt(amo);
	// Provisoriumsvar
	var fixit = false;
	this.currentID = ID;
	var ji = this.geti(this.currentID);
	// alert(ji+"ist der index");
	if ((this.s_menge[ji] < 100) && (this.s_menge[ji] > pao)
			&& (this.get_summe() == 100) && (!this.s_fix[ji])) {
		this.s_menge[ji] -= pao;

		// Provisorium mit FIX
		this.s_fix[ji] = true;
		fixit = true;
		// alert(this.s_menge[ji]+" inside level");
	}
	while (this.get_summe() != 100)
		this.recalc();
	// alert('sub_done');
	// zum Provisorium
	if (fixit)
		this.s_fix[ji] = false;

}

ccb.prototype.set_amount = function(ID, amo) {
	// alert (amo);
	pao = parseInt(amo);
	changeable=this.allow_add();
	var fixit = false;
	this.currentID = ID;
	ji = this.geti(this.currentID);
	frei = parseInt(this.free_amount('a')) + parseInt(this.s_menge[ji])
			- parseInt(this.free_amount('t'));
	// alert (this.free_amount('m')+ " ergibt summe"+ frei);
	if ((frei > (pao)) && (!this.s_fix[ji]) && changeable) {
		this.s_menge[ji] = pao;
		this.s_fix[ji] = true;
		while (this.get_summe() != 100)
			this.recalc();
		this.s_fix[ji] = false;
	}

}

// //
ccb.prototype.get_new_amount = function(py) {
	if (isNaN(py))
		py = 0;
	var merk = 0;
	var zahl = py;
	for (var i = 0; i < (this.s_id.length - py); i++) {
		if (!this.s_fix[i]) {
			merk += this.s_menge[i]
			zahl++;
		}
	}
	if (zahl != 0)
		merk = merk / zahl;
	else
		merk = 0;
	merk = Math.floor(merk);
	return merk;
}

// //
ccb.prototype.add_sorte = function(ID, name, preis, taste) {
	this.currentID = ID;
	if (this.notthere(ID) && this.allow_add()) {
		this.s_id.push(ID);
		// value ermitteln!
		var value = this.get_new_amount(1);
		this.s_menge.push(value);
		this.s_gewicht.push(0);
		this.s_name.push(name);
		this.s_preis.push(parseFloat(preis));
		this.s_taste.push(parseInt(taste));
		this.c_preis.push(0);
		this.s_fix.push(true);
		while (this.get_summe() != 100)
			this.recalc();
		this.s_fix[this.geti(ID)] = false;
		set_added(this.currentID);
		return true;
	}
};
// //
ccb.prototype.get_summe = function() {
	// alle s_menge addiert
	var delta = 0;
	for (ide = 0; ide < this.s_id.length; ide++) {
		delta = delta + this.s_menge[ide];
	}
	return delta;
}
// //
ccb.prototype.recalc = function() {
	if (this.s_id.length > 0) {
		var faktor = this.get_faktor("fak");
		var modulchen = this.get_faktor("mod");
		var gesamt = this.get_summe();
		// alert(faktor + " : faktor\n das ist der Wert!\n" + modulchen
		// + " : Modulo-Operations-Ergebnis\n\n" + gesamt
		// + " : Summe gesamt");

		for (var i = 0; i < this.s_id.length; i++) {
			if (this.s_id.length == 1) {
				this.s_menge[i] = 100;
			} else {
				if (gesamt < 100) {
					if (!this.s_fix[i]) {
						this.s_menge[i] = this.s_menge[i] + faktor + modulchen;
						modulchen = 0;
					}
				}

				if (gesamt > 100) {
					if (!this.s_fix[i]) {
						if ((this.s_menge[i] + faktor + modulchen) > 0) {
							this.s_menge[i] = this.s_menge[i] + faktor
									+ modulchen;
							modulchen = 0;
						}
					}
				}

				if (gesamt == 100) {
					if (!this.s_fix[i]) {
						if ((this.s_menge[i] + faktor + modulchen) > 0) {
							this.s_menge[i] = this.s_menge[i] + faktor
									+ modulchen;
							modulchen = 0;
						}
					}
					// keine Änderung
				}
			}
			var rohpreis = (Math.round(this.gewicht / this.preis_base
					* this.s_menge[i] / 100 * this.s_preis[i] * 100))
					/ 100;
			this.c_preis[i] = (Math.round(rohpreis * 100)) / 100;
			this.s_gewicht[i] = Math
					.round(this.gewicht / 100 * this.s_menge[i]);
		}
		// Preise berechnen!
	}

	// alle Werte berechnet...
	// return true;
}
// //
ccb.prototype.get_faktor = function(strii) {
	if (this.s_id.length == 1) {
		return 0;
	} else {
		var summe = 100 - this.get_summe();// <0 wenn summe > 100
		// >0 wenn summe < 100
		//if (Math.abs(summe) > 100 ){ alert (this.get_summe());}
		var teile = 0;
		for (var d = 0; d < this.s_id.length; d++) {
			if (!this.s_fix[d])
				teile++;
		}

		if (teile > 0) {
			if (strii == "mod") {
				var modulq = summe % teile;
				return modulq;
			} else if (strii == "fak") {
				if (summe > 0)
					summe = Math.floor(summe / teile);
				else
					summe = Math.ceil(summe / teile);
				return summe;
			}
		} else {
			return 0;
		}

	}
};
// //
ccb.prototype.del_item = function(ID) {
	this.currentID = ID;
	var laenge = this.s_id.length;
	for (var j = 0; j < laenge; j++) {
		if (this.s_id[0] != ID) {
			this.s_id.push(this.s_id.shift());
			this.s_menge.push(this.s_menge.shift());
			this.s_gewicht.push(this.s_gewicht.shift());
			this.s_name.push(this.s_name.shift());
			this.s_taste.push(this.s_taste.shift());
			this.s_preis.push(this.s_preis.shift());
			this.c_preis.push(this.c_preis.shift());
			this.s_fix.push(this.s_fix.shift());
		} else {
			this.s_id.shift();
			this.s_menge.shift();
			this.s_gewicht.shift();
			this.s_name.shift();
			this.s_taste.shift();
			this.s_preis.shift();
			this.c_preis.shift();
			this.s_fix.shift();

		}
		set_deleted(ID);
	}
	// wenn nach Löschen ein Loch entsteht
	if (!(this.allow_add())) {
		for (var ru = 0; ru < this.s_id.length; ru++)
			this.s_fix[ru] = false;
	}

	this.recalc();
	aktualisiere_alles();
	// return true;
}
// //
ccb.prototype.make_html = function() {
	if (this.s_id.length == 0) {
		tableheight = 250;
		shub=0;
	} else {
		tableheight = this.tableheigth;
		shub=98;
	}

	var wrap_open = "<table name='muehle' height='"
			+ (tableheight + shub)
			+ " ' width='342' style='padding:0px;margin:0 5px 5px 5px;border-collapse:collapse;border-top:5px solid rgb(159,76,9);"
			+ "border-bottom:15px solid rgb(159,76,9);'><colgroup><col width='11'><col width='320'><col width='11'></colgroup>"
			+ "<tr><td width='11' style='padding:0;margin:0;min-width:11px;background: url(includes/modules/ccb/icons/left_p.png) repeat-y;'></td>"
			+ "<td width='320' style='padding:0;margin:0;min-width:320px;background:rgb(90, 52,22);'>\n<!- --------------------HEAD------------------------------ ->\n";
	var wrap_close = "</td><td width='11'  style='padding:0;margin:0;min-width:11px;background: url(includes/modules/ccb/icons/right_p.png) repeat-y;'></td>" +
			"</tr></table>";
	var ausgabe = "<form name='sorts' action='ccb-app.php?salve=1"+add_req+"' method='post' onsubmit='return sendertest()'>"
			+ "<table width='352' height='100' style='min-height:100px;padding:0px;text-align:center;margin0px;border-collapse:collapse;"
			+ "background: url(includes/modules/ccb/icons/header_wi.gif) no-repeat;'><tr><td style='padding-bottom:30px;'>"
			+ "<select name='mahlgrad' size='1'onchange='t.setmahlgrad(this.form.mahlgrad.options[this.form.mahlgrad.selectedIndex].value)' "
			+ "style='background: rgb(159,76,9);color:white;'>\n"
			+ "<option value='ungemahlen' "
			+ ((t.mahlgrad == "ungemahlen") ? "selected='selected'" : "")
			+ ">ungemahlen</option>\n<option value='Espressomaschine' "
			+ ((t.mahlgrad == "Espressomaschine") ? "selected='selected'" : "")
			+ ">Espressomaschine</option>\n<option value='Kaffeemaschine' "
			+ ((t.mahlgrad == "Kaffeemaschine") ? "selected='selected'" : "")
			+ ">Kaffeemaschine</option>\n</select> <br />"
			+ "<select name='menge' size='1'onchange='t.setmenge(this.form.menge.options[this.form.menge.selectedIndex].value)' "
			+ "style='background: rgb(159,76,9);color:white;'>\n<option value='500' "
			+ ((t.gewicht == 500) ? "selected='selected'" : "")
			+ ">500 g</option>\n" 
			+ "<option value='1000' "
			+ ((t.gewicht == 1000) ? "selected='selected'" : "")
			+ ">1000 g</option>\n"
			+ "<option value='2000' "
			+ ((t.gewicht == 2000) ? "selected='selected'" : "")
			+ ">2000 g</option>\n"
			+ "<option value='5000' "
			+ ((t.gewicht == 5000) ? "selected='selected'" : "")
			+ ">5000 g</option>\n"
			+ "</select> "

			+ "</td></tr></table>\n<!-- switch -->\n" + wrap_open;

	if (this.s_id.length == 0) {
		ausgabe += "\n\n<!- inner Table ->\n<table width='320' height='"
				+ tableheight
				+ "' style='table-layout:fixed;	border:0px #633000 solid;"
				+ "padding:0px;margin0px;border-collapse:collapse;min-width:320px;max-height:"
				+ tableheight + "px;'>\n";// hier
		ausgabe += "<tr><td style='background:url(includes/modules/ccb/icons/bg.jpg);color:#241206;text-align:center;vertical-align:middle;"
				+ " font-weight:600;'>Bitte w&auml;hlen Sie auf der linken Seite mehrere Kaffeesorten aus, indem Sie jeweils auf den Namen klicken</td></tr>"
				+ '<tr><td height="45" style="padding:0;margin:0;border:2px rgb(80,28,00) solid;">'
				+ "<div style='position:relative;text-align:center;border:8px #70470d solid;"
				+ "padding:3px 0;margin:0;background:url(includes/modules/ccb/icons/bg.jpg);font-weight:600;'>"
				+ '<input type="text" maxlength="40" name="ccb_name" value="Keine Kaffees ausgew&auml;hlt" '
				+ 'style="border: 1px rgb(99,77,77) outset;border-left: 3px dotted rgb(99,77,77);border-right: 3px dotted rgb(99,77,77);font-weight:600;font-size:14px;'
				+ 'background:rgb(249,223,155);padding:3px 0;margin:0;margin-top:3px;width:250px;text-align:center;"'
				+ " readonly='readonly' ><br>"
				+ "<br>"
				+ "<br>"
				+ "<input type='button' value='Zur&uuml;ck' onclick='javascript:history.back()'> "
				+ "</div>"
				+ '</td></tr>';""
	}else{
		ausgabe += "\n<table width='320' height='"+tableheight+"' style='table-layout:fixed; border:0px #633000 solid;"
				+ "padding:0px;margin0px;border-collapse:collapse;min-width:320px;max-height:"+tableheight+"px;min-height:"+tableheight+"px;'>\n\n<!- INNER TABLE ->";
	}


	/* wenn nur eine der Sorten frei ist : true sonst false */
	this.currentID="";
	var alla = true;
	if (this.free_amount('t') > 1)
		alla = false;

	/** ****************MAIN LOOP****************** */
	/** ******************************************* */
	for (var y = 0; y < this.s_id.length; y++) {
		/* BGCOL - Hintergrundfarbe */
		if (y % 2 == 0) {
			bgcol = "url(includes/modules/ccb/icons/k"+this.s_taste[y]+"-a.jpg) no-repeat";
			bgt="includes/modules/ccb/icons/k"+this.s_taste[y]+"-a.jpg";
			//bgcol = "rgb(102, 68, 34)";
		} else {
			bgcol = "url(includes/modules/ccb/icons/k"+this.s_taste[y]+"-b.jpg) no-repeat";
			bgt="includes/modules/ccb/icons/k"+this.s_taste[y]+"-b.jpg";
			//bgcol = "rgb(88, 68, 30)";
		}

		/* Hinweistext */
		subtext = (this.s_fix[y])
				? " - bitte entsperren"
				: " es werden mindestens zwei ungesperrte Anteile ben&ouml;tigt";

		titel 	= '\n<!- ----------ENTRY '
				+ y
				+ 'BEGIN---------------->\n'
				+ '<tr><td background="'+bgt+'" height='+ this.gh(this.s_menge[y])+' style="margin:0;padding:0;">'
				+ '\n<table cellpadding="0" cellspacing="0" border="0" style="table-layout:fixed;margin:0px;width:320px;height:'
				+ '100%;'
//				+ this.gh(this.s_menge[y])+ 'px'
//				+ ';background: '
//				+ bgcol + ';'
				+ 'padding:0px;border-left:1px solid rgb(90, 52,22);border-right:2px solid rgb(90, 52,22);'
				+ 'border-top:1px solid rgb(90, 52,22);border-bottom:1px solid rgb(90, 52,22);">\n'
				+ '<colgroup>\n<col width="120"/>\n<col width="40" />\n<col width="24" />\n<col width="78" />\n</colgroup>\n<tr>'
				+ /* ZELLE1-4: */
				'<td colspan="4" style="line-height:14px;color: rgb(253, 252, 200); width:320px; height:16px; font-weight: 600; font-size: 13px;'
				+ 'font-family: arial, sans; text-align: center; margin: 0px;'
				+ 'vertical-align:top;">';
		titel 	+= this.s_name[y] // + ' Grad: ' + this.s_taste[y] // Geschmack??
				+ "<input type='hidden' name='item[]' value='"+ this.s_id[y] +"' />"
				+ "<input type='hidden' name='name[]' value='"+ this.s_name[y] +"' />"
				+ "<input type='hidden' name='preis[]' value='"+ this.s_preis[y] +"' />"
				+ "<input type='hidden' name='menge[]' value='"+ this.s_menge[y] +"' />"
				+ "<input type='hidden' name='taste[]' value='"+ this.s_taste[y] +"' />";
// ID,name,preis,menge,geschmack Hidden Fields!!
		titel += '</td></tr>\n';
		// UMBRUCH

		// ZELLE1
		titel += '<tr><td style="color: black; font-weight: 500; font-size: 12px; font-family: arial, sans;padding: 0 0 0 24px'
				+ '; width:120px;overflow:hidden;';
		titel += 'vertical-align:top; text-align: center;margin: 0px;">'
				+ '<span style="background: rgb(248, 180, 112);padding:1px 3px;margin-top:0px;">';
		titel += this.s_gewicht[y] + "g ";
		titel += " - ";
		titel += number_format(this.c_preis[y], 2, ',', '') + " &euro; ";// Preis
		titel += '</span></td>\n\n';

		// ZELLE2
		// INPUT
		inpa = '<td style="border:0px;vertical-align:top; overflow:hidden;'
				+ ';/*height:16px;*/ width:40px; padding: 0px;';
		inpa += 'text-align: center; margin: 0px;">';
		inpa += '<input name="f_' + this.s_id[y]
				+ '" size="3" type="text"	maxlength="2" ';
		inpa += (this.s_fix[y] || alla) ? "value = '" + this.s_menge[y]
				+ "' disabled='disabled'" : "value='" + this.s_menge[y] + "'";
		inpa += 'style="top:-2px;padding: 0px;margin: 0px; border: 1px dotted rgb(23,12,0)'
				+ ';background-color: rgb(248, 180, 112);';
		inpa += 'text-align: right;max-width: 28px; margin:0px;padding:0px;height: 16px; ';
		inpa += (this.s_fix[y] || alla) ?'color: rgb(200, 200, 200);':'color: rgb(30, 30, 30);';
		inpa += 'font-weight: 600;"';
		inpa += "onchange='set_value(" + this.s_id[y] + ")' />";
		inpa += '<span style="color: black;font-weight: 600">%</span></td>\n\n';

		// ZELLE3
		// ADDIERER ++
		adda = '<td	style="vertical-align:top; overflow:hidden; border: 0px'
				+ ';/*height:16px;*/ width:24px; padding: 0px;'
				+ 'text-align: left; margin-bottom: 0px;">';
		adda += (this.s_fix[y] || alla) ? '' : '<a	href="javascript:add_value('
				+ this.s_id[y] + ')">';
		adda += '<img src="includes/modules/ccb/icons/arrow-up0.gif"  style=" vertical-align: middle;border: 0px none;padding: 0px; vertical-align: top; margin-right: 1px;"';
		adda += (this.s_fix[y] || alla)
				? " title='gesperrt" + subtext + "'>"
				: " title='Prozentualen Anteil erh&ouml;hen'></a>";
		adda += '';
		// SUBTRAHIERER --
		suba = '';
		suba += (this.s_fix[y] || alla) ? '' : '<a href="javascript:sub_value('
				+ this.s_id[y] + ')">';
		suba += '<img src="includes/modules/ccb/icons/arrow-down0.gif"	 style=" vertical-align: middle;border: 0px none; padding: 0px; margin-left: 1px;"';
		suba += (this.s_fix[y] || alla)
				? " title='gesperrt" + subtext + "' >"
				: " title='Prozentualen Anteil verringern'></a>";
		suba += '</td>\n';
		// ZELLE4
		// REST!
		resa = '<td style="border: 0px; vertical-align: top; overflow:hidden; '
				+ ';/*height:16px;*/ width:78px; padding:0px;'
				+ 'text-align: left;margin: 0px;">'
				+ '\n<div style="position: relative; top: 0px;">';
		if (this.s_fix[y]) {
			resa += '<a href="javascript:t.unfix('
					+ this.s_id[y]
					+ ')"><img src="includes/modules/ccb/icons/lock_16x16.gif" style="border: 0px; '
					+ ' vertical-align: middle; padding-right: 5px;" title="Anteil der Kaffeesorte entsperren"></a>'
		} else {
			resa += '<a href="javascript:t.fix('
					+ this.s_id[y]
					+ ')"><img src="includes/modules/ccb/icons/unlock_16x16.gif" style="border: 0px; '
					+ ' vertical-align: middle; padding-right: 5px;" title="Anteil der Kaffeesorte fixieren"></a>'
		}
		resa += '<a href="javascript:t.del_item('
				+ this.s_id[y]
				+ ')"><img src="includes/modules/ccb/icons/delete_16x16.gif" style="border: 0px none; padding-top: 0px;'
				+ ' vertical-align: middle; padding-right: 2px;"	title="Diese Kaffeesorte aus der Mischung entfernen">' +
						'</a></div>\n</td></tr>\n<!- ----CELL 4 END------ ->\n';

		restheight = this.gh(this.s_menge[y]) - 46;
		if (restheight > 1) {
			resa += '<tr><td colspan="4" height="' + restheight
					+ '" style="width:320px;max-height:' + restheight
					+ '"></td></tr>\n';
		}
		resa += '</table></td></tr>\n<!- --------------ENTRY ' + y
				+ '  END------------------- ->\n';

		c_content = titel + inpa + adda + suba + resa;

		ausgabe += c_content; // Inhalt

	}// LOOP
	// Tabelle Ende
	if (this.s_id.length > 0 ){
	ausgabe +='<tr><td height="45" style="padding:0;margin:0;border:2px rgb(80,28,00) solid;">'
			+ "<div style='position:relative;text-align:center;border:8px #70470d solid;"
			+ "padding:3px 0;margin:0;background:url(includes/modules/ccb/icons/bg.jpg);font-weight:600;'>"
			+ '<input type="text" maxlength="40" name="ccb_name" value="'+this.titel+'" '
			+ 'style="border: 1px rgb(99,77,77) outset;border-left: 3px dotted rgb(99,77,77);border-right: 3px dotted rgb(99,77,77);font-weight:600;font-size:14px;'
			+ 'background:rgb(249,223,155);padding:3px 0;margin:0;margin-top:3px;width:250px;text-align:center;"'
			+ "onchange='set_name()'  /><br />"
			//+ this.get_summe() + "% - "
			+ number_format(this.get_preis(), 2, ',', '') + " &euro; - "
			//+ this.get_gewicht() + "g <br />"
			+ "Mahlgrad: "+this.mahlgrad
			+ "<br />"
			+ "<input type='hidden' name='ccb_weight' value='"+ this.get_gewicht() +"' />"
			+ "<input type='hidden' name='ccb_ID' value='"+ this.ccb_id +"' />"
			+ "<input type='hidden' name='ccb_preis' value='"+ this.get_preis() +"' />"
			+ "<input type='button' value='speichern' onkeyup='setsender()' onClick='document.forms[\"sorts\"].submit();'/> "
			+ "</div>"
			+ '</td></tr>';
			}
	ausgabe += "</table> \n ";// Zelle zu

	ausgabe += wrap_close
			+ "</form>";
	return ausgabe;
}

ccb.prototype.get_preis = function() {
	var preis = 0;
	for (var d = 0; d < this.s_id.length; d++) {
		preis += parseFloat(this.c_preis[d]);
	}
	return preis;
}
// //
ccb.prototype.get_gewicht = function() {
	var gewicht = 0;
	for (var i = 0; i < this.s_id.length; i++) {
		gewicht += this.s_gewicht[i];
	}
	return gewicht;
}
// //
//EOF CCB
// //
function set_name(){
	var nux = document.forms["sorts"].elements["ccb_name"].value;
	t.titel=nux;
	aktualisiere_alle();

}
// //
function add_item(soID, soname, sopreis, sotaste) {
	// this.currentID = soID;
	if (t.add_sorte(soID, soname, sopreis, sotaste)) {
		aktualisiere_alles();
	}

}
// //
function set_value(IT) {
	var fname = "f_" + IT;
	var loli = document.forms["sorts"].elements[fname].value;
	t.set_amount(IT, loli);
	aktualisiere_alles();
}
// //
function add_value(IT) {
	t.add_amount(IT, 1);
	aktualisiere_alles();
}
// //
function sub_value(IT) {
	t.sub_amount(IT, 1);
	aktualisiere_alles();
}
// //
function /* out: String */number_format( /* in: float */number,
/* in: integer */laenge,
/* in: String */sep,
/* in: String */th_sep) {

	number = Math.round(number * Math.pow(10, laenge)) / Math.pow(10, laenge);
	str_number = number + "";
	arr_int = str_number.split(".");
	if (!arr_int[0])
		arr_int[0] = "0";
	if (!arr_int[1])
		arr_int[1] = "";
	if (arr_int[1].length < laenge) {
		nachkomma = arr_int[1];
		for (i = arr_int[1].length + 1; i <= laenge; i++) {
			nachkomma += "0";
		}
		arr_int[1] = nachkomma;
	}
	if (th_sep != "" && arr_int[0].length > 3) {
		Begriff = arr_int[0];
		arr_int[0] = "";
		for (j = 3; j < Begriff.length; j += 3) {
			Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
			arr_int[0] = th_sep + Extrakt + arr_int[0] + "";
		}
		str_first = Begriff.substr(0, (Begriff.length % 3 == 0)
						? 3
						: (Begriff.length % 3));
		arr_int[0] = str_first + arr_int[0];
	}
	return arr_int[0] + sep + arr_int[1];
}
// //
function aktualisiere_alles() {
	$(document).ready(function() {
				$("td#sorten").html(t.make_html());
			});
}
me=0;
function openp(n) {
	if (me==n)me=0;
	if (me!=0){
	if (document.getElementById(me).style.display == "block")
		document.getElementById(me).style.display = "none";
	}
	me=n;
	if (document.getElementById(n).style.display == "block")
		document.getElementById(n).style.display = "none";
	else
		document.getElementById(n).style.display = "block";
}
//
function set_added(ID) {
	var tn = "mark" + ID;
	//document.getElementById(tn).style.background = "#ffeedd";
	document.getElementById(tn).className = "inset";
}
//
function set_deleted(ID) {
	var tn = "mark" + ID;
	//document.getElementById(tn).style.background = "#ffbb99";
	document.getElementById(tn).className = "raised";
}

function set_menge(val) {
	t.gewicht = parseInt(val);
	t.recalc();
	aktualisiere_alles();

}
// // // // // //Hauptprogramm
var b = new Array();
b[0] = new Image(); b[0].src = "includes/modules/ccb/icons/k1-a.jpg";
b[1] = new Image(); b[1].src = "includes/modules/ccb/icons/k1-b.jpg";
b[2] = new Image(); b[2].src = "includes/modules/ccb/icons/k2-a.jpg";
b[3] = new Image(); b[3].src = "includes/modules/ccb/icons/k2-b.jpg";
b[4] = new Image(); b[4].src = "includes/modules/ccb/icons/k3-a.jpg";
b[5] = new Image(); b[5].src = "includes/modules/ccb/icons/k3-b.jpg";
b[6] = new Image(); b[1].src = "includes/modules/ccb/icons/k4-a.jpg";
b[7] = new Image(); b[2].src = "includes/modules/ccb/icons/k4-b.jpg";
b[8] = new Image(); b[3].src = "includes/modules/ccb/icons/k5-a.jpg";
b[9] = new Image(); b[4].src = "includes/modules/ccb/icons/k5-b.jpg";
b[10] = new Image(); b[4].src = "includes/modules/ccb/icons/delete_16x16.gif";
b[11] = new Image(); b[4].src = "includes/modules/ccb/icons/unlock_16x16.gif";
b[12] = new Image(); b[4].src = "includes/modules/ccb/icons/lock_16x16.gif";

var sender;
sender = false;
function setsender() {
	sender = true;
}
function sendertest() {
	return sender;
}

var t=new ccb();

if(itemi.length > 0){
	t.init(itemi.shift(),itemi.shift(),itemi.shift(),itemi.shift() );
	}else{
		t.init();
		}

if(itemarr.length > 0){
	t.init_values(itemarr);
}

aktualisiere_alles();
