
function recalcRow(row,single)
{
	recalcFormat(row,single)
	recalcOptions(row,single)
	recalcPrice(row,single)
	if (single == 1)
	{
		document.forms[0].submit()
	}
}

function recalcAll()
{
	var product_all = document.getElementById('product_all_id').value

	// neu f. disabled Select Field - his 06.12.2006
	if (product_all == 0)
	{
		document.forms[0].go_0_0.value = document.getElementById('option_0_all_id').value
	}

	var format_all = document.getElementById('format_all_id').value
	var count_option_all_id = 'count_option_' + product_all.toString() + '_id'
	var count_option_all = document.getElementById(count_option_all_id).value
	var number_all = formatNumber('all')
	var my_nof = document.getElementById('my_nof_id').value
	for (var row=0; row < my_nof; row++)
	{
		var product_id = 'product_' + row.toString() + '_id'
		document.getElementById(product_id).value = product_all
		recalcFormat(row,0)
		var format_id = 'format_' + row.toString() + '_id'
		document.getElementById(format_id).value = format_all
		recalcOptions(row,0)
		//var link_text = ''
		for(var pos=0;pos<count_option_all;pos++)
		{
			var option_all_id = 'option_' + pos.toString() + '_all_id'
			var option_all = document.getElementById(option_all_id).value
			var option_id = 'option_' + pos.toString() + '_' + row.toString() + '_id'
			document.getElementById(option_id).value = option_all

			//neu f. Links - hiss - 03.12.2006
			//var sel_options_id = 'sel_options_' + product_all + '_' + pos.toString() + '_id'
			//var list = document.getElementById(sel_options_id).value.split(',')
			//var option_text_id = 'option_text_' + pos.toString() + '_' + row.toString() + '_id'
			//document.getElementById(option_text_id).innerHTML = list[option_all]
			//link_text = link_text + list[option_all] + ', '
		}

		//var option_text_id = 'option_text_' + row.toString() + '_id'
		//document.getElementById(option_text_id).innerHTML = link_text

		var number_id = 'number_' + row.toString() + '_id'
		document.getElementById(number_id).value = number_all
		recalcPrice(row,0)
	}
}


function recalcFormat(row,single)
{
	var product_id = 'product_' + row.toString() + '_id'
	var product = document.getElementById(product_id).value
	var format_id = 'format_' + row.toString() + '_id'
	var sel_formats_id = 'sel_formats_' + product + '_id'
	var el = document.getElementById(format_id)
	var list = document.getElementById(sel_formats_id).value.split(',')
	el.options.length = 0;
	for(i=0;i<list.length;i++)
	{
		el.options[i] = new Option(list[i],i);
	}
	var std_format = document.getElementById('std_format_id').value
	el.selectedIndex = parseInt(std_format)
	el['onchange']=new Function('recalcPrice("' + row + '",' + single + ')');
	recalcFormatPrice(row,single)
}

function recalcOptions(row,single)
{

	if (single == 1)
	{
		var tbl = document.getElementById( 'tbl_id');
		tbl.rows[4].deleteCell(0)
		tbl.rows[4].insertCell(0)
		tbl.rows[4].deleteCell(1)
		tbl.rows[4].insertCell(1)
		var cell = tbl.rows[4].cells[0]
	}
	else if (row == 'all')
	{
		var tbl = document.getElementById( 'tbl_id_head');
		tbl.rows[1].deleteCell(3)
		tbl.rows[1].insertCell(3)
		var cell = tbl.rows[1].cells[3]
	}
	else
	{
		var tbl = document.getElementById( 'tbl_id');
		tbl.rows[row].deleteCell(3)
		tbl.rows[row].insertCell(3)
		var cell = tbl.rows[row].cells[3]
	}
	cell.setAttribute( 'align', 'right');
	var product_id = 'product_' + row.toString() + '_id'
	var product = document.getElementById(product_id).value
	var format_id = 'format_' + row.toString() + '_id'
	var format = document.getElementById(format_id).value
	var count_option_id = 'count_option_' + product.toString() + '_id'
	var count_option = document.getElementById(count_option_id).value
	var ogprice = parseFloat(0.00)
	var link_text = ''
	for(var pos=0;pos<count_option;pos++)
	{
		if (single == 1)
		{
			var cell = tbl.rows[4].cells[0]
		}
		else if (row == 'all')
		{
			var cell = tbl.rows[1].cells[3]
		}
		else
		{
			var cell = tbl.rows[row].cells[3]
		}
		var option_name = 'option_' + pos.toString() + '_' + row.toString()
		var option_id = 'option_' + pos.toString() + '_' + row.toString() + '_id'
		var el = document.createElement('select')
		el.setAttribute( 'class', 'tnb');
		el.setAttribute( 'name', option_name);
		el.setAttribute( 'id', option_id);
		var sel_options_id = 'sel_options_' + product + '_' + pos.toString() + '_id'
		var list = document.getElementById(sel_options_id).value.split(',')
		el.options.length = 0;
		for(var i=0;i<list.length;i++)
		{
			el.options[i] = new Option(list[i],i);
		}
		el.selectedIndex = parseInt(0)
		el['onchange']=new Function('recalcPrice("' + row + '",' + single + ')');//('recalcOptionPrice(' + row + ',' + pos + ')');
		//el.style.visibility = 'hidden'
		cell.appendChild(el);

		//neu f. "Select disabled bei eco / 24h" his - 06.12.2006
		if (product == 0 && pos == 0)
		{
			var go_0_0 = document.forms[0].go_0_0.value
			el.selectedIndex = parseInt(go_0_0)
			el.style.visibility = 'hidden'

			var el = document.createElement('select')
			el.setAttribute( 'class', 'tnb');
			el.setAttribute( 'name', option_name);
			el.setAttribute( 'id', option_id);
			var sel_options_id = 'sel_options_' + product + '_' + pos.toString() + '_id'
			var list = document.getElementById(sel_options_id).value.split(',')
			el.options.length = 0;
			for(var i=0;i<list.length;i++)
			{
				el.options[i] = new Option(list[i],i);
			}
			el.selectedIndex = parseInt(go_0_0)
			el['onchange']=new Function('recalcPrice("' + row + '",' + single + ')');//('recalcOptionPrice(' + row + ',' + pos + ')');
			el.disabled = 'true'
			cell.appendChild(el);
		}


		//neu f. Link - hiss - 03.12.2006
		//link_text = link_text + list[0] + ', '
		//if (single != 1 && row != 'all')
		//{
		//	var option_text_name = 'option_text_' + pos.toString() + '_' + row.toString()
		//	var option_text_id = 'option_text_' + pos.toString() + '_' + row.toString() + '_id'
		//	var el_text = document.createElement('a')
		//	el_text.setAttribute( 'href', 'javascript:openRow(' + row.toString() + ')');
		//	el_text.setAttribute( 'name', option_text_name);
		//	el_text.setAttribute( 'id', option_text_id);
		//	cell.appendChild(el_text);
		//	el_text.innerHTML = list[0]
		//}

		var oprice_name = 'oprice_' + pos.toString() + '_' + row.toString()
		var oprice_id = 'oprice_' + pos.toString() + '_' + row.toString() + '_id'
		var el = document.createElement('input')
		el.setAttribute( 'type', 'hidden');
		el.setAttribute( 'name', oprice_name);
		el.setAttribute( 'id', oprice_id);
		el.setAttribute( 'size', 5);

		var count_option_value_id = 'count_option_value_' + product.toString()+ '_' + pos.toString() + '_id'
		var count_option_value = document.getElementById(count_option_value_id).value
		var option = document.getElementById(option_id).value
		var sel_oprices_id = 'sel_oprices_' + product.toString() + '_' + pos.toString()+ '_' + option.toString() + '_id'
		var list = document.getElementById(sel_oprices_id).value.split(',')
		cell.appendChild(el);
		el.value = list[format]
		el = document.createElement('br')
		cell.appendChild(el);

		if (single == 1)
		{
			var cell = tbl.rows[4].cells[1]
			cell.setAttribute( 'align', 'right');
			var oprice_text_name = 'oprice_text_' + pos.toString() + '_' + row.toString()
			var oprice_text_id = 'oprice_text_' + pos.toString() + '_' + row.toString() + '_id'
			var el_text = document.createElement('div')
			el_text.setAttribute( 'name', oprice_text_name);
			el_text.setAttribute( 'id', oprice_text_id);
			cell.appendChild(el_text);
			el_text.innerHTML = list[format] + ' EUR'
		}

		ogprice = ogprice + recalcOptionPrice(row,pos,single)
	}

	//neu f. Link - hiss - 03.12.2006
	//if (single != 1 && row != 'all')
	//{
	//	var option_text_name = 'option_text_' + row.toString()
	//	var option_text_id = 'option_text_' + row.toString() + '_id'
	//	var el_text = document.createElement('a')
	//	el_text.setAttribute( 'href', 'javascript:openRow(' + row.toString() + ')');
	//	el_text.setAttribute( 'name', option_text_name);
	//	el_text.setAttribute( 'id', option_text_id);
	//	cell.appendChild(el_text);
	//	el_text.innerHTML = link_text
	//}


	var ogprice_name = 'ogprice_' + row.toString()
	var ogprice_id = 'ogprice_' + row.toString() + '_id'
	var el = document.createElement('input')
	el.setAttribute( 'type', 'hidden');
	el.setAttribute( 'name', ogprice_name);
	el.setAttribute( 'id', ogprice_id);
	el.setAttribute( 'size', 5);
	cell.appendChild(el);
	el.value = ogprice

	//var ogprice_text_name = 'ogprice_text_' + row.toString()
	//var ogprice_text_id = 'ogprice_text_' + row.toString() + '_id'
	//var el_text = document.createElement('div')
	//el_text.setAttribute( 'name', ogprice_text_name);
	//el_text.setAttribute( 'id', ogprice_text_id);
	//cell.appendChild(el_text);
	//el_text.innerHTML = ogprice + ' EUR'
}


function recalcPrice(row,single)
{
	recalcFormatPrice(row,single)

	//var chk_comb = 'true'
	var product_id = 'product_' + row.toString() + '_id'
	var product = document.getElementById(product_id).value
	var count_option_id = 'count_option_' + product.toString() + '_id'
	var count_option = document.getElementById(count_option_id).value
	var ogprice = parseFloat(0.00)
	for(var pos=0;pos<count_option;pos++)
	{
		//if (checkCombination(row,pos,single) == 'false')
		ogprice = ogprice + recalcOptionPrice(row,pos,single)
	}
	recalcOptionGPrice(row,ogprice)
	recalcEPrice(row)
	recalcGPrice(row)

	if (single==1 && (product==5 || product==6)) //check if picture in single_format has to be reloaded
	{
		reset_picture()
	}

	if (document.forms[0].status.value != "single_format")
	{
		recalcPPrice()
	}
}

function checkCombination(row,pos,single)
{
	var product_id = 'product_' + row.toString() + '_id'
	var product = document.getElementById(product_id).value
	var format_id = 'format_' + row.toString() + '_id'
	var format = document.getElementById(format_id).value
	var option_id = 'option_' + pos.toString() + '_' + row.toString() + '_id'
	var option = document.getElementById(option_id).value
	var sel_oprices_id = 'sel_oprices_' + product.toString() + '_' + pos.toString()+ '_' + option.toString() + '_id'
	var oprice_id = 'oprice_' + pos.toString() + '_' + row.toString() + '_id'
	var oprice_text_id = 'oprice_text_' + pos.toString() + '_' + row.toString() + '_id'
	var el = document.getElementById(oprice_id)
	var list = document.getElementById(sel_oprices_id).value.split(',')
	el.value = list[format]

	if (single==1)
	{
		var el_text = document.getElementById(oprice_text_id)
		el_text.innerHTML = list[format]+ ' EUR'
	}

	if (list[format] == '-')
	{
		var sel_products_id = 'sel_products_id'
		var product_list = document.getElementById(sel_products_id).value.split(',')
		var sel_formats_id = 'sel_formats_' + product.toString() + '_id'
		var format_list = document.getElementById(sel_formats_id).value.split(',')
		var sel_options_id = 'sel_options_' + product.toString() + '_' + pos.toString() + '_id'
		var option_list = document.getElementById(sel_options_id).value.split(',')
		alert ('die Kombination: ' + product_list[product] + ' - ' + format_list[format] + ' - ' + option_list[option] + ' ist nicht möglich')
		return 'false'
	}
	else
	{
		return 'true'
	}

}

function recalcFormatPrice(row,single)
{
	var product_id = 'product_' + row.toString() + '_id'
	var product = document.getElementById(product_id).value
	var format_id = 'format_' + row.toString() + '_id'
	var format = document.getElementById(format_id).value
	var price_id = 'price_' + row.toString() + '_id'
	var sel_prices_id = 'sel_prices_' + product.toString() + '_id'
	var el = document.getElementById(price_id)
	var list = document.getElementById(sel_prices_id).value.split(',')
	el.value = list[format]

	if (single==1)
	{
		var price_text_id = 'price_text_' + row.toString() + '_id'
		var el_text = document.getElementById(price_text_id)
		el_text.innerHTML = list[format]+ ' EUR'
	}
}

function recalcOptionPrice(row,pos,single)
{
	var product_id = 'product_' + row.toString() + '_id'
	var product = document.getElementById(product_id).value
	var format_id = 'format_' + row.toString() + '_id'
	var format = document.getElementById(format_id).value
	var option_id = 'option_' + pos.toString() + '_' + row.toString() + '_id'
	var option = document.getElementById(option_id).value
	var sel_oprices_id = 'sel_oprices_' + product.toString() + '_' + pos.toString()+ '_' + option.toString() + '_id'
	var oprice_id = 'oprice_' + pos.toString() + '_' + row.toString() + '_id'
	var oprice_text_id = 'oprice_text_' + pos.toString() + '_' + row.toString() + '_id'
	var el = document.getElementById(oprice_id)
	var list = document.getElementById(sel_oprices_id).value.split(',')
	el.value = list[format]

	if (single==1)
	{
		var el_text = document.getElementById(oprice_text_id)
		el_text.innerHTML = list[format]+ ' EUR'
	}

	if (list[format] == '-')
	{
		var sel_products_id = 'sel_products_id'
		var product_list = document.getElementById(sel_products_id).value.split(',')
		var sel_formats_id = 'sel_formats_' + product.toString() + '_id'
		var format_list = document.getElementById(sel_formats_id).value.split(',')
		var sel_options_id = 'sel_options_' + product.toString() + '_' + pos.toString() + '_id'
		var option_list = document.getElementById(sel_options_id).value.split(',')
		alert ('die Kombination: ' + product_list[product] + ' - ' + format_list[format] + ' - ' + option_list[option] + ' ist nicht möglich')
		//recalcRowStandard(row,single)
		return parseFloat(0.00)
	}
	else
	{
		return parseFloat(list[format])
	}
}

function recalcOptionGPrice(row,ogprice)
{
	ogprice=formatCurrency(ogprice)
	var ogprice_id = 'ogprice_' + row.toString() + '_id'
	document.getElementById(ogprice_id).value = ogprice
	//var ogprice_text_id = 'ogprice_text_' + row.toString() + '_id'
	//document.getElementById(ogprice_text_id).innerHTML = '+' + ogprice + ' EUR'
}

function recalcEPrice(row)
{
	var price_id = 'price_' + row.toString() + '_id'
	var price = document.getElementById(price_id).value
	var ogprice_id = 'ogprice_' + row.toString() + '_id'
	var ogprice = document.getElementById(ogprice_id).value
	var eprice_id = 'eprice_' + row.toString() + '_id'
	var eprice_text_id = 'eprice_text_' + row.toString() + '_id'
	var eprice = formatCurrency(parseFloat(price) + parseFloat(ogprice))
	document.getElementById(eprice_id).value = eprice
	document.getElementById(eprice_text_id).innerHTML = eprice + ' EUR'
}


function recalcGPrice(row)
{
	var eprice_id = 'eprice_' + row.toString() + '_id'
	var eprice = document.getElementById(eprice_id).value
	var number = formatNumber(row)
	var gprice_id = 'gprice_' + row.toString() + '_id'
	var gprice_text_id = 'gprice_text_' + row.toString() + '_id'
	var gprice = formatCurrency(parseFloat(eprice) * parseInt(number))
	document.getElementById(gprice_id).value = gprice
	document.getElementById(gprice_text_id).innerHTML = gprice + ' EUR'
}

function recalcPPrice()
{
	var pprice = parseFloat(0.00)
	var my_nof = document.getElementById('my_nof_id').value

	for (var row=0; row < my_nof; row++)
	{
		var gprice_id = 'gprice_' + row.toString() + '_id'
		var gprice = document.getElementById(gprice_id).value
		pprice = pprice + parseFloat(gprice)
	}
	var pprice_id = 'pprice_id'
	var pprice_text_id = 'pprice_text_id'
	document.getElementById(pprice_id).value = formatCurrency(pprice)
	document.getElementById(pprice_text_id).innerHTML = formatCurrency(pprice) + ' EUR'
}

function openRow(row)
{
document.forms[0].status_old.value = document.forms[0].status.value;
document.forms[0].actual_row.value=row
document.forms[0].status.value="single_format"
document.forms[0].submit()
}

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + dblValue + '.' + strCents);
}

function formatNumber(row)
{
	var number_id = 'number_' + row.toString() + '_id'
	var number = document.getElementById(number_id).value
	number = Trim(number)
	if (number == "")
	{
		document.getElementById(number_id).value = parseInt(0)
		return (parseInt(0));
	}
	var checkOK = "0123456789";
	var checkStr = number;
	var allValid = true;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		if (ch != ",")
		allNum += ch;
	}
	if (!allValid)
	{
		alert("Bitte geben Sie eine Zahl im Feld \"Anzahl\" ein.");
		document.getElementById(number_id).value = parseInt(1)
		return (parseInt(1));
	}
	else
	{
	return parseInt(number)
	}
}

function Trim(TheString)
{
	if (TheString.substr(0,1) == " ")
	{
		TheString = TheString.replace(" ","")
	}
	return (TheString)
}