function BuildHome()
{
	document.write('<div class="tables">');
	document.write('<h1 class="int_head">Willkommen bei XIBAKON!</h1>');
	var colnum = 3;
	BuildDimTable(colnum, 0);
	BuildDimTable(colnum, 1);
	BuildQuickCalc();
	document.write('</div>');
	BuildInfoBox();
}

function BuildDimTable(cn, typ)
{
	if (typ == 0){document.write('<p class="home_text">Wähle eine Einheit über die Größe</p>');}
	if (typ == 1){document.write('<p class="home_text">oder ein Fachgebiet aus,</p>');}
	document.write('<table class="home_table">');
	var j = 0;
	for (var i = 0; i < DimDB.length; i++)
	{
		if (DimDB[i].Typ == typ)
		{
			if (j == 0){document.write('<tr>');}
			document.write('<td><a href="index.php?page=calc&dime=' + (i) + '">' + DimDB[i].Name + '</td>'); j++;
			if (j == cn){document.write('</tr>'); j = 0;}
		}
	}
	if (j != 0){document.write('</tr>');}
	document.write('</table>');
}

function BuildQuickCalc()
{
	document.write('<p class="home_text">oder rechne zwei Einheiten direkt ineinander um:</p>');
	document.write('<form name="qc" style="display:inline; padding:0px; margin:0px">');
	BuildDimList();
	var qcdim = document.qc.qc_dimlist.options[document.qc.qc_dimlist.selectedIndex].value;
	BuildQuickUnitList(qcdim, 0);
	BuildQuickUnitList(qcdim, 1);
	document.write('</form>');
	ChangeQuickUnit(0);
}

function BuildDimList()
{
	document.write('<p class="int_text" style="font-weight:bold">Größe:');
	document.write('<select name="qc_dimlist" class="dimlist" size="1" onchange="ChangeQuickUnit(); NumberQuickChange(0, 1)">');
	document.write('<option selected value=0>' + DimDB[0].Name + '</option>');
	for (var i = 1; i < 14; i++)//Keine Temperaturumrechnung im QuickCalculator (nur ein Wert kann in der OptionList gespeichert werden)
		{
			document.write('<option value=' + i + '>' + DimDB[i].Name + '</option>');
		}
	document.write('</select></p>');
}

function BuildQuickUnitList(dim, qn)
{
	document.write('<table class="unit_section_table" name="OwnUnitTable" cellspacing="0" cellpadding="0"><tr>');
	document.write('<td class="unit_name_ou">');
	document.write('<select class="qc_unitlist" name="qc_unitlist" size="1" onchange="NumberQuickChange(' + qn + ', 1)">');
	document.write('</select>');
	document.write('</td>');
	document.write('<td class="input_table"><input class="input_unit_ou" name="UnitField" maxlength="20" onkeyup="NumberQuickChange(' + qn + ', 0)"></td>');
	document.write('<td class="unit_abbr"></td>');
	document.write('</tr></table>');
}

function ChangeQuickUnit(dim)
{
	var dim = document.qc.qc_dimlist.options[document.qc.qc_dimlist.selectedIndex].value;
	DeleteUnitList(document.qc.qc_unitlist[0]);
	DeleteUnitList(document.qc.qc_unitlist[1]);
	FillUnitList(document.qc.qc_unitlist[0], dim);
	FillUnitList(document.qc.qc_unitlist[1], dim);
}

function DeleteUnitList(f)
{
	//f.length = 0;
	while (f.hasChildNodes()) {f.removeChild(f.firstChild);}
}

function FillUnitList(f, dim)
{
	for (var wsec = 0; wsec < SecName[dim].length; wsec++)
	{
		var og = document.createElement('optgroup');
		og.setAttribute('label', SecName[dim][wsec]);
		og.setAttribute('style', "font-style:normal");
		f.appendChild(og);
		for (var w = 0; w < UnitDB[dim][wsec].length; w++)
		{
			if (wsec == 0 && w == BoSelecta[dim])
				{f.options[f.length] = new Option(UnitDB[dim][wsec][w].Name, UnitDB[dim][wsec][w].Umrech, false, true);}
			else
				{f.options[f.length] = new Option(UnitDB[dim][wsec][w].Name, UnitDB[dim][wsec][w].Umrech, false, false);}
		}
	}

}
/*evtl. nötig für IE/Opera-Kompatibilität
function create_optgroup(){
objSelect=document.forms(0).elements(0);
optGroup = document.createElement('optgroup')
optGroup.label = "New Group"

objOption=document.createElement("option")
objOption.innerHTML = "Sample1"
objOption.value = "sample1"

objSelect.appendChild(optGroup)
optGroup.appendChild(objOption)
}
*/

function NumberQuickChange(qn, listchange)
{
	val = new Array();
	val[0] = document.qc.qc_unitlist[0].options[document.qc.qc_unitlist[0].selectedIndex].value;
	val[1] = document.qc.qc_unitlist[1].options[document.qc.qc_unitlist[1].selectedIndex].value;
	CheckCell(document.qc.UnitField[qn], listchange);
	if(!isNaN(document.qc.UnitField[qn].value))
	{
		factor = document.qc.UnitField[qn].value * val[qn];
		for (var q = 0; q < 2; q++)
		{
			if (q != qn)
				{document.qc.UnitField[q].value = SciNot(factor / val[q], 8);}
		}
	}
}
