// JScript source code
// plik jest integralną częścią strony HTML - m_obwody.html:
// "łączenie równolege i szeregowe elementów biernych"
//Dodanie funkcji prototypowej TRIM

String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing 
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}


							function PolClick()
							{
							var item=0;
							var sr="";
							var evl="";
							var jed="";
							var mnw=0;
							var polwyn=0;
							var si=document.polform.p1.selectedIndex;
							var sj=document.polform.p2.selectedIndex;
							var rown=0;
							if (CheckURL()==false) {return;}
								if (si==0)
								{
								 if (sj==0) {item=1};
								 if (sj==1) {item=3};
								 if (sj==2) {item=5};
								}

								if (si==1)
								{
								 if (sj==0) {item=2}; 
								 if (sj==1) {item=4}; 
								 if (sj==2) {item=6}; 
								}
								switch(item)
								{
								case 1: sr="../images/con_rr.gif"; break;
								case 2: sr="../images/con_rs.gif"; break;
								case 3: sr="../images/con_cr.gif"; break;
								case 4: sr="../images/con_cs.gif"; break;
								case 5: sr="../images/con_lr.gif"; break;
								case 6: sr="../images/con_ls.gif"; break;
								}
							document.polpict.src=sr;

							 if (sj==0) {
							 	evl="R";
							 	jed="Ohm";
							 	}
							 if (sj==1) {
							 	evl="C";
							 	jed="F";
							 	}
							 if (sj==2) {
							 	evl="L";
							 	jed="H"
							 	}
							document.polform.element1.value=evl+"1";
							document.polform.element2.value=evl+"2";
							evx=evl+"z";

							document.polform.dj1.value=jed;
							document.polform.dj2.value=jed;
							//document.polform.wj.value=jed;

							da1=document.polform.dana1.value*1;
							da2=document.polform.dana2.value*1;							
							if ((da1<0) || (da2<0))
								{
								alert("Dane nie mogą być ujemne !");
								da1=0;
								da2=0;
								document.polform.dana1.value=da1;
								document.polform.dana2.value=da2;							
								}
							if ((da1>999999) || (da2>999999))
								{
								alert("Zbyt duża wartość w danych !");
								da1=0;
								da2=0;
								document.polform.dana1.value=da1;
								document.polform.dana2.value=da2;							
								}
															
							mn1=document.polform.dm1.value*1;
							mn2=document.polform.dm2.value*1;
							
							mn12=mn1-mn2;
							mn21=mn2-mn1;
							if (mn12>0) 
								{
								da1=da1*(Math.pow(10,mn1));
								mn1=mn2;
								}
							if (mn21>0) 
								{
								da2=da2*(Math.pow(10,mn2));
								mn2=mn1;
								}
							
							if ((da1+da2)==0) {polwyn=0} 
							else {
								if (((sj==0) & (si==1)) || ((sj==1) & (si==0)) || ((sj==2) & (si==1))){polwyn=da1+da2}
								if (((sj==0) & (si==0)) || ((sj==1) & (si==1)) || ((sj==2) & (si==0))){polwyn=(da1*da2)/(da1+da2)}
								}
								
							if (mn1==mn2) {mnw=mn1}
							else
								{
								if (((sj==0) & (si==1)) || ((sj==1) & (si==1)) || ((sj==2) & (si==0)))
									{
									if (mn1<mn2) {mnw=mn2; polwyn=da2;} else {mnw=mn1; polwyn=da1;};								
									}
								if (((sj==0) & (si==0)) || ((sj==1) & (si==0)) || ((sj==2) & (si==1)))
									{
									if (mn1>mn2) {mnw=mn2; polwyn=da2;} else {mnw=mn1; polwyn=da1;};
									}
								}

							if ((polwyn>=1000000) & (mnw<=0)) 
								{
								polwyn=polwyn/1000000;
								mnw=mnw+6;
								}
							
							if ((polwyn>=1000) & (mnw<=3))
								{
								polwyn=polwyn/1000;
								mnw=mnw+3;
								}

							if (mnw==0) {mnws=""};
							if (mnw==3) {mnws="k"};
							if (mnw==6) {mnws="M"};
							if (mnw==-3) {mnws="m"};
							if (mnw==-6) {mnws="u"};
							if (mnw==-9) {mnws="n"};
							if (mnw==-12) {mnws="p"};							
							//document.polform.wm.value=mnws;
							polwyn=Math.round(polwyn*100)/100;
							document.polform.element4.value=evx+" = "+polwyn+" "+mnws+jed;

							}								

function DivClick()
{							
	if (CheckURL()==false) {return;}
	if (document.divform.ddana1.value.trim()=="" || document.divform.ddana2.value.trim()=="" || document.divform.ddana3.value.trim()=="")
		{
		alert("Wprowadź dane: Uwe, Uwy, Iwy");
		DivClear();
		return;
		}

	var uwe=parseFloat(document.divform.ddana1.value);
	var uwy=parseFloat(document.divform.ddana2.value);
	var iwy=parseFloat(document.divform.ddana3.value)/1000;

	if ((uwe<=0) || (uwy<=0) || (iwy<=0))
								{
								alert("Dane nie mogą być ujemne i/lub równe zero !");
								DivClear();
								return;
								}
	if ((Math.round(uwe)>999) || (Math.round(uwy)>999) || (Math.round(iwy)>99))
								{
								alert("Zbyt duże wartości w danych !");
								DivClear();
								return;
								}

	if (uwe<=uwy)
								{
								alert("Napięcie wejściowe nie może być mniejsze ani równe napięciu wyjściowemu !");
								DivClear();
								return;
								}
// r2=1/Iwy, r1=(Uwe-Uwy)/(Iwy*Uwy)

var r2=Math.round(100/iwy)/100;
var r1=Math.round(((uwe-uwy)*100)/(iwy*uwy))/100;
var iwe=Math.round(uwe*100/(r1+r2))*10;
var p1=Math.round((100*(uwe-uwy)*(uwe-uwy))/r1)/100;
var p2=Math.round((100*uwy*uwy)/r2)/100;

var wynik="R1="+r1+" Ohm, R2="+r2+" Ohm, Iwe="+iwe+"mA";
var moce="moc R1="+p1+"W, moc R2="+p2+"W";
document.divform.delement4.value=wynik;
document.divform.delement5.value=moce;
}								

function DivClear()
{
	document.divform.ddana1.value=0;
	document.divform.ddana2.value=0;							
	document.divform.ddana3.value=0;							
	document.divform.delement4.value="";
	document.divform.delement5.value="";
}

function Div2Click()
{							
	if (CheckURL()==false) {return;}
	if (document.divform2.d2dana1.value.trim()=="" || document.divform2.d2dana2.value.trim()=="" || document.divform2.d2dana3.value.trim()=="")
		{
		alert("Wprowadź dane: R1, R2, Uwe");
		Div2Clear();
		return;
		}

	var R1=parseFloat(document.divform2.d2dana1.value);
	var R2=parseFloat(document.divform2.d2dana2.value);
	var Uwe=parseFloat(document.divform2.d2dana3.value);

	if ((R1<=0) || (R2<=0) || (Uwe<=0))
								{
								alert("Dane nie mogą być ujemne i równe zero !");
								Div2Clear();
								return;
								}
	if ((Math.round(R1)>10000000) || (Math.round(R2)>10000000) || (Math.round(Uwe)>999))
								{
								alert("Zbyt duże wartości w danych !");
								Div2Clear();
								return;
								}

// Uwy=(Uwe*R2)/(R1+R2), Iwy=1/R2

var Uwy=Math.round((Uwe*R2)/(R1+R2));
var Iwe=Math.round(Uwe*100/(R1+R2))*10;
var Iwy=Math.round(1000/R2);

var P1=Math.round((100*(Uwe-Uwy)*(Uwe-Uwy))/R1)/100;
var P2=Math.round((100*Uwy*Uwy)/R2)/100;

var wynik="Uwy="+Uwy+"V, Iwe="+Iwe+"mA, Iwy="+Iwy+"mA";
var moce="moc R1="+P1+"W, moc R2="+P2+"W";
document.divform2.d2element4.value=wynik;
document.divform2.d2element5.value=moce;
}								

function CheckURL()
{
	if (document.domain=="www.elserw.com.pl")
		{return true;}
	else
		{return false;}
}

function Div2Clear()
{
	document.divform2.d2dana1.value=0;
	document.divform2.d2dana2.value=0;							
	document.divform2.d2dana3.value=0;							
	document.divform2.d2element4.value="";
	document.divform2.d2element5.value="";
}

//--></SCRIPT>

//KONIEC

