    top.phoneAttr = 'phone';
    PhoneUID = 0;
    PhonesInList = 0;
    var noWriteFeature = "<BR />"+"This device support is read-only! Writing data to it is not available yet.";

    function GetClassWeight(value){
     if (value == '-') {return -1;}
     if (value == 'C') {return 0;}
     if (value == 'B') {return 1;}
     if (value == 'A') {return 2;}
     if (value == 'A+') {return 3;}
     if (value == 'B+') {return 4;}
    }

    function ComboChanged(obj){
       var tbElm = document.getElementById("tbdy");
       PhonesInList = tbElm.childNodes.length;

      // hello from IE, that can not work with getElementsByName
      var x = document.getElementsByTagName('select');
      var Phones = [];
      for(var i=0;i<x.length;i++){
        if(x.item(i).getAttribute( 'name' ) == top.phoneAttr ){
            Phones.push(x.item(i));
        }
      }
      // end hello

      MaxClass = 'C';
      MinClass = 'B+'
      for (i=0; i<Phones.length; i++){
        if (GetClassWeight(Phones[i].value) > GetClassWeight(MaxClass)){
          MaxClass = Phones[i].value;
        }
        if (GetClassWeight(Phones[i].value) < GetClassWeight(MinClass)){
          MinClass = Phones[i].value;
        }
      }
     UpdateMatrix();
    }


function insertTR(){
        PhoneUID++;

        var newTR = document.createElement("tr");
        // Combo
        var newTD1 = document.createElement("TD");
        newTD1.classname = 'centered';
        var newCombo = document.createElement('SELECT');
        var phoneAttr = top.phoneAttr;
        newCombo.id = top.phoneAttr+PhoneUID;
        newCombo.name = top.phoneAttr;
        newCombo.onchange = function(){
          newLabel.innerHTML = newCombo.value;
          ComboChanged(newCombo)
          if (PhonesInfoArray[newCombo.selectedIndex][7] == 1) {WarnLabel.innerHTML = noWriteFeature;} else {WarnLabel.innerHTML = "";} 
        };

        for (i=0; i<PhonesInfoArray.length; i++){
          var objOption = document.createElement('option');
          objOption.text=PhonesInfoArray[i][0] + ' ' + PhonesInfoArray[i][1];
          objOption.value=PhonesInfoArray[i][2];
          objOption.name = i;
          newCombo.options.add(objOption) ;
        }

        var WarnLabel = document.createElement("SPAN");
        WarnLabel.style.color="red";
        WarnLabel.htmlFor = newCombo.id;
        if (PhonesInfoArray[0][7] == 1) {WarnLabel.innerHTML = noWriteFeature;} else {WarnLabel.innerHTML = "";} 


        // Label (phone class)
        var newTD2 = document.createElement("TD");
        newTD2.classname = 'centered';
        newTD2.setAttribute("align","center")
        var newLabel = document.createElement("LABEL");
        newLabel.htmlFor = newCombo.id;

        // link (delete)
        var newTD3 = document.createElement("TD");
        newTD3.classname = 'centered';
        newTD3.setAttribute("align","center")
        var newEraseLink = document.createElement('a');
        newEraseLink.className = 'removeLink';
        newEraseLink.innerHTML ='&nbsp;X&nbsp;';
        newEraseLink.onclick = function(){
            tbElm.removeChild(newTR);
            ComboChanged(null);
        }
        newLabel.innerHTML = newCombo.value;


        newTD1.appendChild(newCombo)
        newTD1.appendChild(WarnLabel)
        newTD2.appendChild(newLabel)
        newTD3.appendChild(newEraseLink)

        newTR.appendChild(newTD1);
        newTR.appendChild(newTD2);
        newTR.appendChild(newTD3);


       var tbElm = document.getElementById("tbdy");
       tbElm.appendChild(newTR);
       ComboChanged(null);
         
}

    window.onload = function(){insertTR();}
