   function round(value,digits)
   {
    mult = Math.pow(10,digits);
    return Math.round(value*mult)/mult;
   }

   function compute(form)
   {
    if ( document.getElementById("I").value == "" )
    {
        alert( 'Please enter current throuch PCB trace.' );
    }

    var Decimals = 4;                         

	var h_ozft2=parseFloat(document.getElementById("h").value); // Cu thickness in oz/ft2
    switch (document.getElementById("h_Factor").value)
	{
		case "mil"  :h_ozft2*=0.7441412868;break;
		case "mm"   :h_ozft2*=29.29690105;break;
		case "ozft2":h_ozft2*=1;break;
		case "um"   :h_ozft2*=29296.90105;break;
	}
	
	var Length_m = parseFloat(document.getElementById("Length").value); // track length in m
	switch (document.getElementById("T_Length_Unit").value)
	{
		case "mm"     :Length_m/=1000;break;	
		case "inches" :Length_m/=39.3700787;break; 
		case "cm"     :Length_m/=100;break;	
		case "mil"    :Length_m/=39370.0787;break; 		
	}
	
	var Length_mm=Length_m*1000;

    var I  = parseFloat(document.getElementById("I").value);// Current in A
	if(document.getElementById("I_Factor").value=="mA")
   	{
		I/=1000;	
	}	
    var T  = parseFloat(document.getElementById("T").value);
	if (document.getElementById("TA_Unit").value == "F")
	{
		T=(T-32)*5/9;
	}
		
    var dT = parseFloat(document.getElementById("dT").value);     // Temperature change in C
	if (document.getElementById("dT_Unit").value == "F")
	{
		dT=dT*5/9;
	}
	
	var V  = parseFloat(document.getElementById("V").value); 	// peak V in Volts
	if (document.getElementById("V_Unit").value == "mV")
	{
		V/=1000;
	}	

	var Clearance_int_mm=0;//in mm (B1)
	var Clearance_ext_mm=0;//in mm (A7)
	if (V>0 && V<=30)
	{
		Clearance_int_mm=0.05;
		Clearance_ext_mm=0.13;
	}else if(V<=100)
	{
		Clearance_int_mm=0.1;
		Clearance_ext_mm=0.13;	
	} else if(V<=250)
	{
		Clearance_int_mm=0.2;
		Clearance_ext_mm=0.4;	
	}	
	
	var Aint   = Math.pow(I / (0.015 * Math.pow(dT, 0.5453)), 1.0 / 0.7349);
	    
	var k_inner = 0.024;
	var k_outer = 0.048;
	
	//const Cu_Resistivity = 16.78; // pure coppor nano Ohm * meter @ 20 deg.C
	var Cu_Resistivity_half_oz = 19.2; // nano Ohm * meter @ 25 deg.C //from IPC-2152 draft
	var Cu_Resistivity_over_one_oz = 18.0; // nano Ohm * meter @ 25 deg.C //from IPC-2152 draft
	var Cu_TempCoEff = 0.0039;  //K-1
	var Cu_Density = 8940; //kg/m3 @ 20 Deg.c
	var h_kgm2 = ((h_ozft2*Math.pow(3.2808399,2))/35.2739619);
	
	if (h_ozft2<1)
	{
		Cu_Resistivity=Cu_Resistivity_half_oz;	
	}
	else
	{
		Cu_Resistivity=Cu_Resistivity_over_one_oz;
	}
	
	var W_inner_mils = (1/(1.4 * h_ozft2)) * (Math.pow((I/(k_inner * Math.pow(dT,0.421))),1.379));
	var W_inner_m=W_inner_mils/39370.0787;
	
	var R_inner_nano_ohm = ((Cu_Resistivity*Length_m) / ( W_inner_m * h_kgm2/Cu_Density))*(1+(Cu_TempCoEff*(T +dT-25)));

	var W_outer_mils = (1/(1.4 * h_ozft2)) * (Math.pow((I/(k_outer * Math.pow(dT,0.421))),1.379));
	var W_outer_m=W_outer_mils/39370.0787;

	var R_outer_nano_ohm = ((Cu_Resistivity*Length_m) / ( W_outer_m * h_kgm2/Cu_Density))*(1+(Cu_TempCoEff*(T +dT-25)));

	
	document.getElementById("Pint").value=round(Math.pow(I, 2) * R_inner_nano_ohm/1000000000,Decimals);
	
	switch (document.getElementById("W_Unit").value)
	{
		case "mm" :document.getElementById("Wint").value=round(W_inner_mils*0.0254,Decimals);
				   document.getElementById("Wext").value=round((W_outer_mils*0.0254 ),Decimals);
				   break; 
		case "um" :document.getElementById("Wint").value=round(W_inner_mils*25.4,Decimals);
				   document.getElementById("Wext").value=round((W_outer_mils*25.4 ),Decimals);
				   break; 	
		case "mil":document.getElementById("Wint").value=round(W_inner_mils,Decimals);
				   document.getElementById("Wext").value=round(W_outer_mils,Decimals);
				   break;  	
	}
	
	switch (document.getElementById("C_Unit").value)
	{
		case "mm" :document.getElementById("Cint").value=round(Clearance_int_mm,Decimals);
				   document.getElementById("Cext").value=round(Clearance_ext_mm,Decimals);
				   break; 
		case "um" :document.getElementById("Cint").value=round(Clearance_int_mm*1000,Decimals);
				   document.getElementById("Cext").value=round(Clearance_ext_mm*1000,Decimals);
				   break; 	
		case "mil":document.getElementById("Cint").value=round(Clearance_int_mm*39.3700787,Decimals);
				   document.getElementById("Cext").value=round(Clearance_ext_mm*39.3700787,Decimals);
				   break;  	
	}
	
	if (document.getElementById("R_Unit").value=="Ohm")
	{
		document.getElementById("Rint").value=round((R_inner_nano_ohm / 1000000000 ), Decimals ); 
		document.getElementById("Rext").value=round((R_outer_nano_ohm / 1000000000 ), Decimals );
	}
	else
	{
		document.getElementById("Rint").value=round((R_inner_nano_ohm / 1000000 ), Decimals ); 
		document.getElementById("Rext").value=round((R_outer_nano_ohm / 1000000 ), Decimals );		
	}

	if (document.getElementById("V_Drop_Unit").value=="Volts")
	{
		document.getElementById("Vint").value=round(I * R_inner_nano_ohm / 1000000000,Decimals);
		document.getElementById("Vext").value=round(I * R_outer_nano_ohm / 1000000000,Decimals);
	}
	else
	{
		document.getElementById("Vint").value=round(I * R_inner_nano_ohm / 1000000,Decimals);
		document.getElementById("Vext").value=round(I * R_outer_nano_ohm / 1000000,Decimals);
	}
	
	if (document.getElementById("P_Unit").value=="W")
	{
		document.getElementById("Pint").value=round(Math.pow(I, 2) * R_inner_nano_ohm/1000000000,Decimals);;
		document.getElementById("Pext").value=round(Math.pow(I, 2) * R_outer_nano_ohm/1000000000,Decimals);;
	}
	else
	{
		document.getElementById("Pint").value=round(Math.pow(I, 2) * R_inner_nano_ohm/1000000,Decimals);;
		document.getElementById("Pext").value=round(Math.pow(I, 2) * R_outer_nano_ohm/1000000,Decimals);;
	}
	if(W_inner_mils>400)
	{
		form.Wint.value="Error. TraceWidth>400mils";
		form.Rint.value="Error. TraceWidth>400mils";
		form.Vint.value="Error. TraceWidth>400mils";
		form.Pint.value="Error. TraceWidth>400mils";
		form.Cint.value="Error. TraceWidth>400mils";
	}
  	if(W_outer_mils>400)
	{
		form.Wext.value="Error. TraceWidth>400mils";
		form.Rext.value="Error. TraceWidth>400mils";
		form.Vext.value="Error. TraceWidth>400mils";
		form.Pext.value="Error. TraceWidth>400mils";
		form.Cext.value="Error. TraceWidth>400mils";
	}
	
	
   }
   
