var product_prop = new Array();
product_prop[0] = '<tr bgcolor=f3f3f3><td width="45%">Длина:</td><td bgcolor=D1E3EB><input type="text" size="10" class="form" id="lenght"> мм</td></tr>';
						
product_prop[1] = '<tr valign=top bgcolor=f3f3f3><td width="45%">Ширина:</td><td bgcolor=D1E3EB><input type="text" size="10" class="form" id="width"> мм</td></tr>';

product_prop[2] = '<tr valign=top bgcolor=f3f3f3><td width="45%">Толщина:</td><td bgcolor=D1E3EB><input type="text" size="10" class="form" id="thickness"> мм</td></tr>';

product_prop[3] = '<tr valign=top bgcolor=f3f3f3><td width="45%">Диаметр:</td><td bgcolor=D1E3EB><input type="text" size="10" class="form" id="diameter"> мм</td></tr>';

product_prop[4] = '<tr valign=top bgcolor=f3f3f3><td width="45%">Сторона квадрата:</td><td bgcolor=D1E3EB><input type="text" size="10" class="form" id="width"> мм</td></tr>';

product_prop[5] = '<tr valign=top bgcolor=f3f3f3><td width="45%">Наружный диаметр:</td><td bgcolor=D1E3EB><input type="text" size="10" class="form" id="diameter"> мм</td></tr>';

product_prop[6] = '<tr valign=top bgcolor=f3f3f3><td width="45%">Диаметр вписанного круга:</td><td bgcolor=D1E3EB><input type="text" size="10" class="form" id="diameter"> мм</td></tr>';

product_prop[7] = '<tr valign=top bgcolor=f3f3f3><td width="45%">Толщина стенки:</td><td bgcolor=D1E3EB><input type="text" size="10" class="form" id="thickness"> мм</td></tr>';

product_prop[8] = '<tr valign=top bgcolor=f3f3f3><td style="border-top: 1px solid #000; border-bottom: 1px solid #000;" width="45%"><br></td><td style="border-top: 1px solid #000; border-bottom: 1px solid #000;" bgcolor=D1E3EB><input type="button" value="Рассчитать массу" class="form" onClick="calculate();"></td></tr>';

var Hash = new Array();

function newproduct(){
	Hash['lenght']='';
	Hash['width']='';
	Hash['thickness']='';
	Hash['diameter']='';
};

function calculate()
{
	if(document.getElementById("material2").value!="")
	{
		r = parseFloat(document.getElementById("material2").value.replace(",", "."));
		mat_name = "неизвестен";
	}
	else
	{
		r = parseFloat(document.getElementById("material1").value);
		mat_name = document.getElementById("material1").options[document.getElementById("material1").selectedIndex].text;
	}

	
	product = document.getElementById("product");
	switch(parseInt(product.value))
	{
		case 1:
			l = parseFloat(document.getElementById("lenght").value.replace(",", "."));
			a = parseFloat(document.getElementById("thickness").value.replace(",", "."));
			b = parseFloat(document.getElementById("width").value.replace(",", "."));
			Hash['lenght'] = document.getElementById("lenght").value;
			Hash['thickness'] = document.getElementById("thickness").value;
			Hash['width'] = document.getElementById("width").value;
				if(!l || !a || !b || isNaN(l) || isNaN(a) || isNaN(b))
				{
					alert("Не все поля заполнены или  введены не числовые значения!");
					return;
				}
			y = (r*a*b)/1000000;
			info = "<b>Рассчитанная масса: <span id='weight'>-</span>&nbsp;кг.</b><br><br><div class='gray'>	Вид проката: <b>" + product.options[product.selectedIndex].text + "</b>.<br>Материал: <b>" + mat_name + "</b> (плотность: " + replacePoint(r) + "&nbsp;т/м&#179;).<br>Длина: " + replacePoint(l) + "&nbsp;мм.<br>Ширина: " + replacePoint(b) + "&nbsp;мм.<br>Толщина: " + replacePoint(a) + "&nbsp;мм.</div>";
			break;
		case 2:
			l = parseFloat(document.getElementById("lenght").value.replace(",", "."));
			d = parseFloat(document.getElementById("diameter").value.replace(",", "."));
			Hash['lenght'] = document.getElementById("lenght").value;
			Hash['diameter'] = document.getElementById("diameter").value;
				if(!l || !d || isNaN(l) || isNaN(d))
				{
					alert("Не все поля заполнены или  введены не числовые значения!");
					return;
				}

			//y = (r * Math.PI * ((d*2)/4))/100000;
			y = (r * Math.PI * ((d*d)/4))/1000000;
			info = "<b>Рассчитанная масса: <span id='weight'>-</span>&nbsp;кг.</b><br><br><div class='gray'>	Вид проката: <b>" + product.options[product.selectedIndex].text + "</b>.<br>Материал: <b>" + mat_name + "</b> (плотность: " + replacePoint(r) + "&nbsp;т/м&#179;).<br>Длина: " + replacePoint(l) + "&nbsp;мм.<br>Диаметр: " + replacePoint(d) + "&nbsp;мм.</div>";
			break;
		case 3:
			l = parseFloat(document.getElementById("lenght").value.replace(",", "."));
			a = parseFloat(document.getElementById("width").value.replace(",", "."));
			Hash['lenght'] = document.getElementById("lenght").value;
			Hash['width'] = document.getElementById("width").value;
				if(!l || !a || isNaN(l) || isNaN(a))
				{
					alert("Не все поля заполнены или  введены не числовые значения!");
					return;
				}
			y = (r * a * a)/1000000;
			info = "<b>Рассчитанная масса: <span id='weight'>-</span>&nbsp;кг.</b><br><br><div class='gray'>	Вид проката: <b>" + product.options[product.selectedIndex].text + "</b>.<br>Материал: <b>" + mat_name + "</b> (плотность: " + replacePoint(r) + "&nbsp;т/м&#179;).<br>Длина: " + replacePoint(l) + "&nbsp;мм.<br>Сторона квадрата: " + replacePoint(a) + "&nbsp;мм.</div>";
			break;
		case 4:
			l = parseFloat(document.getElementById("lenght").value.replace(",", "."));
			d = parseFloat(document.getElementById("diameter").value.replace(",", "."));
			s = parseFloat(document.getElementById("thickness").value.replace(",", "."));
			Hash['lenght'] = document.getElementById("lenght").value;
			Hash['diameter'] = document.getElementById("diameter").value;
			Hash['thickness'] = document.getElementById("thickness").value;
				if(!l || !d || !s || isNaN(l) || isNaN(d) || isNaN(s))
				{
					alert("Не все поля заполнены или  введены не числовые значения!");
					return;
				}
			y = (r * Math.PI * s * (d-s))/1000000;
			info = "<b>Рассчитанная масса: <span id='weight'>-</span>&nbsp;кг.</b><br><br><div class='gray'>	Вид проката: <b>" + product.options[product.selectedIndex].text + "</b>.<br>Материал: <b>" + mat_name + "</b> (плотность: " + replacePoint(r) + "&nbsp;т/м&#179;).<br>Длина: " + replacePoint(l) + "&nbsp;мм.<br>Наружный диаметр: " + replacePoint(d) + "&nbsp;мм.<br>Толщина стенки: " + replacePoint(s) + "&nbsp;мм.</div>";
			break;
		case 5:
			l = parseFloat(document.getElementById("lenght").value.replace(",", "."));
			d = parseFloat(document.getElementById("diameter").value.replace(",", "."));
			Hash['lenght'] = document.getElementById("lenght").value;
			Hash['diameter'] = document.getElementById("diameter").value;
				if(!l || !d || isNaN(l) || isNaN(d))
				{
					alert("Не все поля заполнены или  введены не числовые значения!");
					return;
				}
			//y = (r * d * 2 * Math.sqrt(3)*2)/100000;
			y = (r * Math.sqrt(3)/2 * (d*d))/1000000;
//Y = 7,9 х 1,732/2 х (50х50) = 17103,5
//М = 1500 (длина в мм) х 17103,5 = 25655250
//25655250/1000000 (для перевода в кг) = 25,655кг 				
			info = "<b>Рассчитанная масса: <span id='weight'>-</span>&nbsp;кг.</b><br><br><div class='gray'>	Вид проката: <b>" + product.options[product.selectedIndex].text + "</b>.<br>Материал: <b>" + mat_name + "</b> (плотность: " + replacePoint(r) + "&nbsp;т/м&#179;).<br>Длина: " + replacePoint(l) + "&nbsp;мм.<br>Диаметр вписанного круга: " + replacePoint(d) + "&nbsp;мм.</div>";
			break;
		default:
			return;
	}
	//w = (parseInt((l * y)*100))/100;
		w = Math.round((l * y)*1000)/1000;
	document.getElementById("par_info").innerHTML = info;
	document.getElementById("weight").innerHTML = replacePoint(w);
}

//material1
//material2
function showFields()
{
	if((document.getElementById("material1").value!=0 || document.getElementById("material2").value!="") && document.getElementById("product").value!=0)
	{
		switch(parseInt(document.getElementById("product").value))
		{
			case 1:
				document.getElementById("parameters").innerHTML= '<table width="100%" cellpadding=3 cellspacing=1 border=0 class="normal">' + product_prop[0] + product_prop[1] + product_prop[2] + product_prop[8] +'</table>';
				document.getElementById("lenght").value=Hash['lenght'];
				document.getElementById("thickness").value=Hash['thickness'];
				document.getElementById("width").value=Hash['width'];				
				break;
			case 2:
				document.getElementById("parameters").innerHTML= '<table width="100%" cellpadding=3 cellspacing=1 border=0 class="normal">' + product_prop[0] + product_prop[3] + product_prop[8] +'</table>';
				document.getElementById("lenght").value=Hash['lenght'];
				document.getElementById("diameter").value=Hash['diameter'];
				break;
			case 3:
				document.getElementById("parameters").innerHTML= '<table width="100%" cellpadding=3 cellspacing=1 border=0 class="normal">' + product_prop[0] + product_prop[4] + product_prop[8] +'</table>';
				document.getElementById("lenght").value=Hash['lenght'];
				document.getElementById("width").value=Hash['width'];				
				break;
			case 4:
				document.getElementById("parameters").innerHTML= '<table width="100%" cellpadding=3 cellspacing=1 border=0 class="normal">' + product_prop[0] + product_prop[5] + product_prop[7] + product_prop[8] +'</table>';
				document.getElementById("lenght").value=Hash['lenght'];
				document.getElementById("diameter").value=Hash['diameter'];
				document.getElementById("thickness").value=Hash['thickness'];
				break;
			case 5:
				document.getElementById("parameters").innerHTML= '<table width="100%" cellpadding=3 cellspacing=1 border=0 class="normal">' + product_prop[0] + product_prop[6] + product_prop[8] +'</table>';
				document.getElementById("lenght").value=Hash['lenght'];
				document.getElementById("diameter").value=Hash['diameter'];				
				break;
			default:
				return;
		}
	}
	else
	{
		document.getElementById("parameters").innerHTML = "";
	}
}

function replacePoint(num)
{
	num = "" + num + "";
	num = num.replace(/\./g, ",");
	return num;
}