function komma2punkt(str)
{
	str = str.replace(/,/,".");
	return str;
}

function kvfluid()
{
	x = document.fluid1.q.value;
	x = komma2punkt(x);
	Qf1 = parseFloat(x);
	if(isNaN(Qf1) || Qf1<0)
	{
		alert("incorrect input for Q!");
		document.fluid1.q.select();
		return(0);
	}
	
	x = document.fluid1.rho.value;
	x = komma2punkt(x);
	rf1 = parseFloat(x);
	if(isNaN(rf1) || rf1<0)
	{
		alert("incorrect input for rho1!");
		document.fluid1.rho.select();
		return(0);
	}
	
	x = document.fluid1.deltap.value;
	x = komma2punkt(x);
	pf1 = parseFloat(x);
	if(isNaN(pf1) || pf1<0)
	{
		alert("incorrect input for Delta p!");
		document.fluid1.deltap.select();
		return(0);
	}
	
	yf1 = Math.round(Qf1*Math.sqrt(rf1/(1000*pf1))*100)/100;
	document.fluid1.ergebnis1.value = yf1;
	document.fluid1.print.disabled = false;
}



function qfluid()
{
	x = document.fluid2.kv.value;
	x = komma2punkt(x);
	kf2 = parseFloat(x);
	if(isNaN(kf2) || kf2<0)
	{
		alert("incorrect input for kV!");
		document.fluid2.kv.select();
		return(0);
	}
	
	x = document.fluid2.rho.value;
	x = komma2punkt(x);
	rf2 = parseFloat(x);
	if(isNaN(rf2) || rf2<0)
	{
		alert("incorrect input for rho1!");
		document.fluid2.rho.select();
		return(0);
	}
	
	x = document.fluid2.deltap.value;
	x = komma2punkt(x);
	pf2 = parseFloat(x);
	if(isNaN(pf2) || pf2<0)
	{
		alert("incorrect input for Delta p!");
		document.fluid2.deltap.select();
		return(0);
	}
	
	yf2 = Math.round(kf2*Math.sqrt((1000*pf2)/rf2)*100)/100;
	document.fluid2.ergebnis2.value = yf2;
	document.fluid2.print.disabled = false;
}

function pfluid()
{
	x = document.fluid3.kv.value;
	x = komma2punkt(x);
	kf3 = parseFloat(x);
	if(isNaN(kf3) || kf3<0)
	{
		alert("incorrect input for kV!");
		document.fluid3.kv.select();
		return(0);
	}
	
	x = document.fluid3.rho.value;
	x = komma2punkt(x);
	rf3 = parseFloat(x);
	if(isNaN(rf3) || rf3<0)
	{
		alert("incorrect input for rho1!");
		document.fluid3.rho.select();
		return(0);
	}
	
	x = document.fluid3.q.value;
	x = komma2punkt(x);
	Qf3 = parseFloat(x);
	if(isNaN(Qf3) || Qf3<0)
	{
		alert("incorrect input for Q!");
		document.fluid3.q.select();
		return(0);
	}
	
	yf3 = Math.round(rf3*(Qf3/kf3)*(Qf3/kf3)/10)/100;
	document.fluid3.ergebnis3.value = yf3;
	document.fluid3.print.disabled = false;
}

function kvgas()
{
	x = document.gas1.q.value;
	x = komma2punkt(x);
	Qg1 = parseFloat(x);
	if(isNaN(Qg1) || Qg1<0)
	{
		alert("incorrect input for Q!");
		document.gas1.q.select();
		return(0);
	}
	
	x = document.gas1.rho.value;
	x = komma2punkt(x);
	rg1 = parseFloat(x);
	if(isNaN(rg1) || rg1<0)
	{
		alert("incorrect input for rho1!");
		document.gas1.rho.select();
		return(0);
	}
	
	x = document.gas1.deltap.value;
	x = komma2punkt(x);
	pg1 = parseFloat(x);
	if(isNaN(pg1) || pg1<0)
	{
		alert("incorrect input for Delta p!");
		document.gas1.deltap.select();
		return(0);
	}
	
	x = document.gas1.p2.value;
	x = komma2punkt(x);
	P2g1 = parseFloat(x);
	if(isNaN(P2g1) || P2g1<0)
	{
		alert("incorrect input for p2!");
		document.gas1.p2.select();
		return(0);
	}
	
	x = document.gas1.t1.value;
	x = komma2punkt(x);
	
	if(document.gas1.temp[1].checked == true)
	{
		zwischen = x;
		x = (5/9)*(zwischen - 32);
	}
	
	T1g1 = parseFloat(x)+273;
	
	if(isNaN(T1g1) || T1g1<0)
	{
		alert("incorrect input for T1!");
		document.gas1.t1.select();
		return(0);
	}
	
	if(1 >= (pg1/P2g1))	// unterkritisch
	{
		y1g1 = Math.round((Qg1/514) * Math.sqrt((rg1 * T1g1)/(pg1 * P2g1)) * 100)/100;
		document.gas1.ergebnis1.value = y1g1;
		document.gas1.ergebnis2.value = "";
		y2g1 = "";
		document.gas1.print.disabled = false;
	}
	
	else		// ueberkritisch
	{
		y2g1 = Math.round((Qg1/(257 * (P2g1+pg1))) * Math.sqrt(rg1 * T1g1) * 100)/100;
		document.gas1.ergebnis1.value = "";
		y1g1 = "";
		document.gas1.ergebnis2.value = y2g1;
		document.gas1.print.disabled = false;
	}
}

function qgas()
{
	x = document.gas2.kv.value;
	x = komma2punkt(x);
	kvg2 = parseFloat(x);
	if(isNaN(kvg2) || kvg2<0)
	{
		alert("incorrect input for kv!");
		document.gas2.kv.select();
		return(0);
	}
	
	x = document.gas2.rho.value;
	x = komma2punkt(x);
	rg2 = parseFloat(x);
	if(isNaN(rg2) || rg2<0)
	{
		alert("incorrect input for rho1!");
		document.gas2.rho.select();
		return(0);
	}
	
	x = document.gas2.deltap.value;
	x = komma2punkt(x);
	pg2 = parseFloat(x);
	if(isNaN(pg2) || pg2<0)
	{
		alert("incorrect input for Delta p!");
		document.gas2.deltap.select();
		return(0);
	}
	
	x = document.gas2.p2.value;
	x = komma2punkt(x);
	P2g2 = parseFloat(x);
	if(isNaN(P2g2) || P2g2<0)
	{
		alert("incorrect input for p2!");
		document.gas2.p2.select();
		return(0);
	}
	
	x = document.gas2.t1.value;
	x = komma2punkt(x);
	
	if(document.gas2.temp[1].checked == true)
	{
		zwischen = x;
		x = (5/9)*(zwischen - 32);
	}
	
	T1g2 = parseFloat(x)+273;
	if(isNaN(T1g2) || T1g2<0)
	{
		alert("incorrect input for T1!");
		document.gas2.t1.select();
		return(0);
	}
	
	if(1 >= (pg2/P2g2))	// unterkritisch
	{
		y1g2 = Math.round(kvg2 * 514 * Math.sqrt((pg2 * P2g2) / (rg2 * T1g2)) * 100)/100;
		document.gas2.ergebnis1.value = y1g2;
		document.gas2.ergebnis2.value = "";
		y2g2 = "";
		document.gas2.print.disabled = false;
	}
	
	else		// ueberkritisch
	{
		y2g2 = Math.round(kvg2 * 257 * (P2g2+pg2) * (1 / Math.sqrt(rg2 * T1g2)) * 100)/100;
		document.gas2.ergebnis1.value = "";
		y1g2 = "";
		document.gas2.ergebnis2.value = y2g2;
		document.gas2.print.disabled = false;
	}
}

function pgas()
{
	x = document.gas3.kv.value;
	x = komma2punkt(x);
	kvg3 = parseFloat(x);
	if(isNaN(kvg3) || kvg3<0)
	{
		alert("incorrect input for kv!");
		document.gas3.kv.select();
		return(0);
	}
	
	x = document.gas3.rho.value;
	x = komma2punkt(x);
	rg3 = parseFloat(x);
	if(isNaN(rg3) || rg3<0)
	{
		alert("incorrect input for rho1!");
		document.gas3.rho.select();
		return(0);
	}
	
	x = document.gas3.q.value;
	x = komma2punkt(x);
	Qg3 = parseFloat(x);
	if(isNaN(Qg3) || Qg3<0)
	{
		alert("incorrect input for Q!");
		document.gas3.q.select();
		return(0);
	}
	
	x = document.gas3.p2.value;
	x = komma2punkt(x);
	P2g3 = parseFloat(x);
	if(isNaN(P2g3) || P2g3<0)
	{
		alert("incorrect input for p2!");
		document.gas3.p2.select();
		return(0);
	}
	
	x = document.gas3.t1.value;
	x = komma2punkt(x);
	
	if(document.gas3.temp[1].checked == true)
	{
		zwischen = x;
		x = (5/9)*(zwischen - 32);
	}
	
	T1g3 = parseFloat(x)+273;
	if(isNaN(T1g3) || T1g3<0)
	{
		alert("incorrect input for T1!");
		document.gas3.t1.select();
		return(0);
	}
	
	yg3 = Math.round((Qg3*Qg3*rg3*T1g3) / (kvg3*kvg3*514*514*P2g3)*100)/100;
	document.gas3.ergebnis1.value = yg3;
	document.gas3.print.disabled = false;
}



function print_fluid1()
{
	open("technik_programme_fluid1.html?q="+ Qf1 +"&rho="+ rf1 +"&deltap="+ pf1 +"&kv="+ yf1 + "","w01","height=320,width=500,scrollbars=no");
}
function print_fluid2()
{
	open("technik_programme_fluid2.html?kv="+ kf2 +"&rho="+ rf2 +"&deltap="+ pf2 +"&q="+ yf2 + "","w02","height=320,width=500,scrollbars=no");
}
function print_fluid3()
{
	open("technik_programme_fluid3.html?kv="+ kf3 +"&rho="+ rf3 +"&q="+ Qf3 +"&deltap="+ yf3 + "","w03","height=320,width=500,scrollbars=no");
}
function print_gas1()
{
	open("technik_programme_gas1.html?q="+ Qg1 +"&rho="+ rg1 +"&deltap="+ pg1 +"&p2="+ P2g1 + "&t1="+ T1g1 +"&kv1="+ y1g1 +"&kv2="+ y2g1 +"","w04","height=430,width=500,scrollbars=no");
}
function print_gas2()
{
	open("technik_programme_gas2.html?kv="+ kvg2 +"&rho="+ rg2 +"&deltap="+ pg2 +"&p2="+ P2g2 + "&t1="+ T1g2 +"&q1="+ y1g2 +"&q2="+ y2g2 +"","w05","height=430,width=500,scrollbars=no");
}
function print_gas3()
{
	open("technik_programme_gas3.html?kv="+ kvg3 +"&q="+ Qg3 +"&rho="+ rg3 +"&p2="+ P2g3 + "&t1="+ T1g3 +"&p="+ yg3 +"","w06","height=430,width=500,scrollbars=no");
}

function printversion(berechnung, lang)
{
	switch(berechnung)
	{
		case 1:
			open("berechnung_print.asp?lang="+ lang +"&berechnung="+ berechnung +"&q="+ Qf1 +"&rho="+ rf1 +"&deltap="+ pf1 +"&kv="+ yf1 + "","w01","height=320,width=500");
			break;
		case 2:
			open("berechnung_print.asp?lang="+ lang +"&berechnung="+ berechnung +"&kv="+ kf2 +"&rho="+ rf2 +"&deltap="+ pf2 +"&q="+ yf2 + "","w02","height=320,width=500,scrollbars=no");
			break;
		case 3:
			open("berechnung_print.asp?lang="+ lang +"&berechnung="+ berechnung +"&kv="+ kf3 +"&rho="+ rf3 +"&q="+ Qf3 +"&deltap="+ yf3 + "","w03","height=320,width=500,scrollbars=no");
			break;
		case 4:
			open("berechnung_print.asp?lang="+ lang +"&berechnung="+ berechnung +"&q="+ Qg1 +"&rho="+ rg1 +"&deltap="+ pg1 +"&p2="+ P2g1 + "&t1="+ T1g1 +"&kv1="+ y1g1 +"&kv2="+ y2g1 +"","w04","height=430,width=500,scrollbars=no");
			break;
		case 5:
			open("berechnung_print.asp?lang="+ lang +"&berechnung="+ berechnung +"&kv="+ kvg2 +"&rho="+ rg2 +"&deltap="+ pg2 +"&p2="+ P2g2 + "&t1="+ T1g2 +"&q1="+ y1g2 +"&q2="+ y2g2 +"","w05","height=430,width=500,scrollbars=no");
			break;
		case 6:
			open("berechnung_print.asp?lang="+ lang +"&berechnung="+ berechnung +"&kv="+ kvg3 +"&q="+ Qg3 +"&rho="+ rg3 +"&p2="+ P2g3 + "&t1="+ T1g3 +"&p="+ yg3 +"","w06","height=430,width=500,scrollbars=no");
			break;
	}
}

