// This option removes all elements from a JavaScript Select Box
function removeAllOptions(selectbox){
   var i;
   for(i=selectbox.options.length-1;i>=0;i--){
      selectbox.remove(i);
   }
}

function addOption(selectbox,text,value )
{
   var optn = document.createElement("OPTION");
   optn.text = text;
   optn.value = value;
   selectbox.options.add(optn);
}

/**
   This method is what performs the model -> part number mapping
   Fujitsu requested. I have made it general enough to function 
   exactly as-is for the webview content, as well as for the 
   stand alone web site. 

   It would be nice to consider some kind of a way to avoid all 
   these IF checks. What I really would like is a hash key'd on 
   the model, with the part numbers stored as the value, as a list. 
   JSON would probably be good for this. If I created it in a very
   readable way, our customers could just approve the JSON file. 
 
   Then, I could write a routine which takes a selection box and a 
   list, and populates the selection box with the values from the list.

   This will be for version 2.0. 

      -Brian J. Stinar-
      Leader Technologies 
      2010-05-20
**/
function populatePTRNSelect(model, selectBox, PNFI_textbox){

    if ((model == null) || (model == "")){
        // alert('issue with model - exiting');
        return;
    }

    // Get rid of the whitespace on the model, there is some when multiple models
    // are passed by the app. 
    model = model.replace(/^\s+|\s+$/g, '') ;

    // We need to first clear the drop-down of all existing elements.
    // I did not forsee this in the beginning, but Fujitsu has an option
    // by which they can pass in multiple models, and the user will select
    // which one is theirs. After they select the model, (even multiple times)
    // I need to zero-out and repopulate the list.   

    removeAllOptions(selectBox);

    selectBox.style.display = "block";
    //selectBox.disabled = 'null'; 

    // Hide the fill-in  
    PNFI_textbox.style.display = 'none';

    // Clear it's value 
    PNFI_textbox.value = "";

    // ScanSnap S300 -- 000 
    if (model == "S300"){
       addOption(selectBox, "Click to Select", "");  
       addOption(selectBox, "PA03541-B005", "PA03541-B005");
       addOption(selectBox, "PA03541-B015", "PA03541-B015"); 
       addOption(selectBox, "PA03541-B205", "PA03541-B205"); 
       return;
    }

    // ScanSnap S300M -- 000
    if (model == "S300M"){
       addOption(selectBox, "PA03541-B105", "PA03541-B105"); 
       return;
    }

    // ScanSnap S510 -- 000 
    if (model == "S510"){
       addOption(selectBox, "Click to Select", "");
       addOption(selectBox, "PA03360-B515", "PA03360-B515");
       addOption(selectBox, "PA03360-B525", "PA03360-B525");
       addOption(selectBox, "PA03360-B535", "PA03360-B535");
       return; 
    }

    // S510M
    if (model == "S510M"){
       addOption(selectBox, "PA03360-B615", "PA03360-B615");
       return;  
    }

    // ScanSnap S1300 -- second most reg's seen so far
    if(model == "S1300"){
       addOption(selectBox, "Click to Select", "");
       addOption(selectBox, "PA03603-B005", "PA03603-B005");
       addOption(selectBox, "PA03603-B015", "PA03603-B015");
       addOption(selectBox, "PA03603-B205", "PA03603-B205");
       addOption(selectBox, "PA03603-B101", "PA03603-B101"); 
       return;
    }

    // ScanSnap S1500 -- most reg's seen so far
    if (model == "S1500"){
       addOption(selectBox, "Click to Select", "");  
       addOption(selectBox, "PA03586-B005", "PA03586-B005");
       addOption(selectBox, "PA03586-B015", "PA03586-B015"); 
       addOption(selectBox, "PA03586-B105", "PA03586-B105");
       return;
    }

    // ScanSnap S1500M -- 000
    if (model == "S1500M"){
       addOption(selectBox, "PA03586-B105", "PA03586-B105");
       return;
    }

    // fi-60F 
    if (model == "fi-60F"){
       addOption(selectBox, "PA03420-B005", "PA03420-B005");
       return;
    }
 
    // fi-5015C
    if (model == "fi-5015C"){
       addOption(selectBox, "Click to Select", "");
       addOption(selectBox, "PA03209-B505", "PA03209-B505");
       addOption(selectBox, "PA03209-B515", "PA03209-B515");
       return;
    }

    // fi-5110C
    if (model == "fi-5110C"){
       addOption(selectBox, "Click to Select", "");
       addOption(selectBox, "PA03360-B055", "PA03360-B055");
       addOption(selectBox, "PA03360-B255", "PA03360-B255"); 
       return;
    }

    // fi-6130
    if (model == "fi-6130"){
       addOption(selectBox, "PA03540-B055", "PA03540-B055"); 
       return;
    }

    // fi-6230
    if (model == "fi-6230"){
       addOption(selectBox, "PA03540-B555", "PA03540-B555");
       return;
    }

    // fi-6140
    if (model == "fi-6140"){
       addOption(selectBox, "PA03540-B005", "PA03540-B005"); 
       return;
    }

    // fi-6240
    if (model == "fi-6240"){
       addOption(selectBox, "PA03540-B505", "PA03540-B505");
       return;
    }

    // fi-5530C2
    if (model == "fi-5530C2"){
       addOption(selectBox, "PA03334-B605", "PA03334-B605"); 
       return;
    }

    // fi-4340C
    if (model == "fi-4340C"){
       addOption(selectBox, "PA03277-B015", "PA03277-B015");
       return;
    }

    // fi-6670 and fi-6670A 
    if (model == "fi-6670" || model =="fi-6670A"){
       addOption(selectBox, "Click to Select", "");
       addOption(selectBox, "PA03576-B505", "PA03576-B505");
       addOption(selectBox, "PA03576-B535", "PA03576-B535"); 
       return;
    }

    // fi-6770 and fi-6770A
    if (model == "fi-6770" || model == "fi-6770A"){
       addOption(selectBox, "Click to Select", "");
       addOption(selectBox, "PA03576-B005", "PA03576-B005"); 
       addOption(selectBox, "PA03576-B035", "PA03576-B035"); 
       return;
    }

    // fi-4860C2
    if (model == "fi-4860C2"){
       addOption(selectBox, "PA03296-B075", "PA03296-B075"); 
       return;
    }

    // fi-6010N  
    if (model == "fi-6010N "){
       addOption(selectBox, "PA03544-B205", "PA03544-B205");
    }

    // fi-5900C
    if (model == "fi-5900C"){
       addOption(selectBox, "Click to Select", "");
       addOption(selectBox, "PA03450-B005", "PA03450-B005"); 
       addOption(selectBox, "PA03450-B055", "PA03450-B055"); 
       return;
    }

    // fi-6800 
    if (model == "fi-6800"){
       addOption(selectBox, "PA03575-B005", "PA03575-B005");
       return;
    }

   /* Requested by Michael Sidejas 2010-05-20 */

   // Rack2-Filer V5.0
   if (model == "Rack2-Filer V5.0"){
      addOption(selectBox, "Click to Select", "");
      addOption(selectBox, "PA43201-K087", "PA43201-K087"); 
      addOption(selectBox, "PA43403-E703", "PA43403-E703"); 
      addOption(selectBox, "PA43403-E705", "PA43403-E705");
      return;
   }

   // If none of these happened, let's hide the drop-down and put a text box in it's place. 
   // Hide the drop-down
   selectBox.style.display = "none";
   PNFI_textbox.style.display = 'block';
   
}
