
function addinput(objectinput) {
  
  var options = new Array("Front Sprocket","Chain","Front Carrier","Front Hub","Front Rim",
                          "Rear Carrier","Rear Hub","Rear Rim","Rear Sprocket",
                          "Rivet Link","Spoke","Spoke Set");
  var columns  = 5;
  var formname = "dynamic";
  var inputcount = document.forms[formname].elements.length;
  var i = 0;
  
  if(inputcount > 0) {
    var inputname = objectinput.name;
    var inputid = parseInt(inputname.substr(5,2));
    var lines = inputcount/columns;
    var inputline = Math.ceil((inputid+1)/columns);
    
    if(lines!=inputline)
      return false;  
      
    if((document.forms[formname].elements[inputcount-5].value=="") || 
       (document.forms[formname].elements[inputcount-3].value=="") )
      return false;    
  } else {
    if (document.forms["sendrequestlist"]) {
      document.forms["sendrequestlist"].name.focus();
    }
  }
                            
  for(i=0; i<columns; i++) {   
    if(i == 1) { // select
    
      var inputcount = document.forms[formname].elements.length;
      var select = document.createElement("select"); 
      
      select.setAttribute("class","column"+(inputcount%columns));
      select.setAttribute("name","input"+inputcount);
      select.setAttribute("id","input"+inputcount);
      
      
      for(j=0; j<options.length; j++) {
        var option = document.createElement('option');
        var txt = document.createTextNode(options[j]);
        
        option.setAttribute('value', options[j]);
        option.appendChild(txt);
        select.appendChild(option);
      }
      
      document.getElementById(formname).appendChild(select);
      
    } else { // text input

      var element = document.createElement("input");
      var inputcount = document.forms[formname].elements.length;
      
      element.setAttribute("id", "input"+inputcount);
      element.setAttribute("type", "text");
      
      var motorcycle = "";
      if((inputcount > 0)&&(i==0)) {
         var motorcycleinput = inputcount-columns;
         motorcycle = document.forms[formname].elements[motorcycleinput].value;
      }
      if((inputcount==0)&&(i==0))
         motorcycle = document.getElementById("motorcycle").innerHTML;    

      if(i==0) {
        element.setAttribute("size", "37");
        element.setAttribute("value", motorcycle);
      }     
      else if(i==2)
        element.setAttribute("size", "33");       
      else if(i==3) {
        element.setAttribute("size", "2");
        element.setAttribute("value", "1");
      } else if(i==4)
        element.setAttribute("size", "28");
                      
      
      element.setAttribute("name", "input"+inputcount);
      element.onkeyup = function(){ addinput(element); };
      element.setAttribute("class","column"+(inputcount%columns));
      
      document.getElementById(formname).appendChild(element);
      
    }
    
    if((inputcount%columns)==4) // new line tag
      document.getElementById(formname).appendChild(document.createElement("br"));        
  }
    if ((!document.forms["sendrequestlist"])&&inputcount==4) {
      document.forms["dynamic"].input0.focus();
    }
  
}
