    window.resizeTo(800,800); //resizes a window
    var frm=document.forms[0], no=1, newno=0, isEdit=false, Rsi=0.13, Rse=0.00, peri=0, area=0;
    function calcUVal(){
      var tab=document.getElementById("calctab"), tot=0, correct=parseFloat(frm.correction.value), sel=frm.ElemSelection, rest;
      if (sel.value >= 2){
        for (var x=0; x<18; x++){
          pc=parseFloat(tab.childNodes[x].childNodes[2].innerHTML)/100;
          rest=parseFloat(tab.childNodes[x].childNodes[3].innerHTML);
          tot += isNaN(rest)? 0: rest*pc;
        }
        document.getElementById("thick").innerHTML=tot.toFixed(1);
        var tab=document.getElementById("calctab"), tot=0, correct=parseFloat(frm.correction.value), rest;
        for (var x=0; x<18; x++){
          rest=parseFloat(tab.childNodes[x].childNodes[4].innerHTML);
          tot += isNaN(rest)? 0: rest;
        }
        frm.perimeter.style.background = 'Grey';
        frm.area.style.background = 'Grey';
        document.getElementById("pa_ratio").innerHTML="N/A";
        document.getElementById("totres").innerHTML=tot.toFixed(3);
        document.getElementById("uval").innerHTML=(1/tot).toFixed(3);
        document.getElementById("ucval").innerHTML=((1/tot)+correct).toFixed(3);
        }else{
        calcGRD();
      }
    }
    function calcGRD(){
      var tab=document.getElementById("calctab"), tot=0, correct=parseFloat(frm.correction.value), rest;
        for (var x=0; x<18; x++){
          rest=parseFloat(tab.childNodes[x].childNodes[3].innerHTML);
          tot += isNaN(rest)? 0: rest;
        }
        document.getElementById("thick").innerHTML=tot.toFixed(1);
        var tab=document.getElementById("calctab"), tot=0, correct=parseFloat(frm.correction.value), rest;
        for (var x=0; x<18; x++){
          rest=parseFloat(tab.childNodes[x].childNodes[4].innerHTML);
          tot += isNaN(rest)? 0: rest;
        }
        document.getElementById("totres").innerHTML=tot.toFixed(3);
        document.getElementById("uval").innerHTML=(1/tot).toFixed(3);
        validateEmpty(frm.perimeter)
        validateEmpty(frm.area)
        var peri=parseFloat(frm.perimeter.value), area=parseFloat(frm.area.value);
        var pa_ratio=(peri/area), Uo=(0.05+(1.65*pa_ratio)-(0.6*(pa_ratio*pa_ratio)));
        if (isNaN(parseFloat(pa_ratio))) {
          document.getElementById("pa_ratio").innerHTML="<b><font color=#FF0000 size=3>Please enter values for Perimeter & Area</font></b>";
         } else { 
          document.getElementById("pa_ratio").innerHTML=pa_ratio.toFixed(3);
        }
        if (isNaN(parseFloat(pa_ratio))) {
          frm.correction.value="";
         } else { 
          frm.correction.value=Uo.toFixed(4);
        }
        if (isNaN(parseFloat(pa_ratio))) {
          document.getElementById("ucval").innerHTML="";
         } else { 
          document.getElementById("ucval").innerHTML=(1/(tot+(1/Uo))).toFixed(3);
        }
    }
    function addToTable(){
      var num=(isEdit)? newno: no;
      var row=document.getElementById("r"+num);
      row.childNodes[0].innerHTML=frm.material.value;
      row.childNodes[1].innerHTML=frm.termres.value;
      row.childNodes[2].innerHTML=frm.percent.value;
      row.childNodes[3].innerHTML=frm.thickness.value;
      row.childNodes[4].innerHTML=frm.resistance.value;
      if (isEdit){
        isEdit=false;
      }else{
        row.childNodes[5].innerHTML='<INPUT TYPE="button" style="width: 40px" value="Edit" onClick="javascript:editEntry('+no+');"><INPUT TYPE="button" style="width: 40px" value="Del" onClick="javascript:delEntry('+no+');">';
        no++;
      }
      clearBoxes();
      calcUVal();
    }
    function clearBoxes(){
      frm.material.value="";
      frm.termres.value="";
      frm.percent.value="100";
      frm.thickness.value="";
      frm.resistance.value="";
      frm.mats.selectedIndex=0;
    }
    function popInputs(){
      var sel=frm.mats; //
      frm.material.value=sel.options[sel.selectedIndex].text;
      frm.termres.value=sel.value;
    }
    function editEntry(num){
      newno=num;
      var row=document.getElementById("r"+num);
      frm.material.value=row.childNodes[0].innerHTML;
      frm.termres.value=row.childNodes[1].innerHTML;
      frm.percent.value=row.childNodes[2].innerHTML;
      frm.thickness.value=row.childNodes[3].innerHTML;
      frm.resistance.value=row.childNodes[4].innerHTML;
      isEdit=true;
      for (y=0;y<5;y++){
        row.childNodes[y].innerHTML="";
      }
    }
    function delEntry(num){
      var row, row2, lastrow=document.getElementById("r16");
      for (var x=num;x<16;x++){
        row=document.getElementById("r"+x);
        row2=document.getElementById("r"+(x+1));
        if (row.childNodes[0].innerHTML != ""){
          for (y=0;y<6;y++){
            row.childNodes[y].innerHTML=row2.childNodes[y].innerHTML;
          }
        }
      }
      if (lastrow.childNodes[0].innerHTML != ""){
        for (y=0;y<6;y++){
          lastrow.childNodes[y].innerHTML="";
        }
      }
      no--;
      calcUVal();
    }
    function updateRes(){
      if (frm.material.value != "Cavity"){
        var pc=parseFloat(frm.percent.value)/100;
        var res=(parseFloat(frm.thickness.value)/1000)/parseFloat(frm.termres.value)*pc;
        frm.resistance.value=res.toFixed(4);
      }else{
        frm.resistance.value="0.18";
      }
    }
    function updateUcval(){
      var tab=document.getElementById("calctab"), tot=0, rest;
      for (var x=0; x<17; x++){
        rest=parseFloat(tab.childNodes[x].childNodes[4].innerHTML);
        tot += isNaN(rest)? 0: rest;
      }
      var corval=parseFloat(frm.correction.value);
      var newu=(1/tot);
      var newu1=corval+newu;
      document.getElementById("ucval").innerHTML=newu1.toFixed(4);
    }
    function popType(){
      var sel=frm.ElemSelection, elem1=sel.options[sel.selectedIndex].text, result=parseFloat(sel.value);
        if (result >= 9) {
            var Rs0=0.13, Rs1=0.04, MaxU=0.00, DeltaU=0.00;
        } else if (result >= 8) {
            var Rs0=0.13, Rs1=0.04, MaxU=0.28, DeltaU=0.00;
        } else if (result >= 7) {
            var Rs0=0.13, Rs1=0.12, MaxU=0.30, DeltaU=0.00;
        } else if (result >= 6) {
            var Rs0=0.10, Rs1=0.04, MaxU=0.16, DeltaU=0.00;
        } else if (result >= 5) {
            var Rs0=0.10, Rs1=0.04, MaxU=0.18, DeltaU=0.00;
        } else if (result >= 4) {
            var Rs0=0.10, Rs1=0.04, MaxU=0.16, DeltaU=0.00;
        } else if (result >= 3) {
            var Rs0=0.10, Rs1=0.04, MaxU=0.18, DeltaU=0.00;
        } else if (result >= 2) {
            var Rs0=0.17, Rs1=0.12, MaxU=0.22, DeltaU=0.00;
        } else if (result >= 1) {
            var Rs0=0.17, Rs1=0.02, MaxU=0.22, DeltaU=0.00;
        } else {
            var Rs0=0.17, Rs1=0.04, MaxU=0.22, DeltaU=0.00;
        }
      var row=document.getElementById("r0");
      row.childNodes[4].innerHTML=Rs0.toFixed(4);
      var row=document.getElementById("r17");
      row.childNodes[4].innerHTML=Rs1.toFixed(4);
      document.getElementById("maxuval").innerHTML=MaxU.toFixed(2);
      frm.correction.value=DeltaU.toFixed(4);
      if (sel.value >= 2){
        document.getElementById("UcName").innerHTML="Total &Delta;U";
        document.getElementById("Ucalc1").innerHTML="<i>U = <sup>1</sup>/<sub>RT</sub>+ &Delta;U =</i>";
        calcUVal();
      }else{
        document.getElementById("UcName").innerHTML="Total U<sub>o</sub>      <font size=1><i>=0.05+1.65(P/A)-0.6(P/A)<sup>2</sup></i>";
        document.getElementById("Ucalc1").innerHTML="<i>1/(1/U<sub>o</sub> + R ) =</i>";
        calcGRD();
      }
   }
function validateEmpty(fld) {
    if (fld.value.length == 0) {
        fld.style.background = 'Red'; 
    } else if (isNaN(fld.value)) {
         fld.style.background = 'Yellow'; 
    } else {   	
        fld.style.background = 'White';
    }
}
