<!-- // Hide the script from browsers which don't support it.

// This function is to perform the sizing calculations for the UN-5700 line of products
//
// Copyright (c) 2003 by Robert L. Curtis. All rights reserved.
//

var headStyle; var studPart; var studPartDFCI;
var studSize ;
var receStyle; var recePart; var recePartDFCI;
var retaStyle; var retaPart; var retaPartDFCI; retaThick = 0;
var panel    ;
var gap      ;
var support  ;
var pileup   ;
var undercut   = "";
var valid = true;
var inch = true;

// This function is to clear the part numbers when an error is encountered during the build.  
// This will prevent partial part numbers from being presented to the user.
//
function resetPartNumbers() { studPart = ""; studPartDFCI = "";
                              recePart = ""; recePartDFCI = "";
                              retaPart = ""; retaPartDFCI = "";
                              undercut = ""; 
                              valid    = false; }

// This function is to determine and set the part numbers
//
function calculatePartNumbers() {

resetPartNumbers();
document.inParms.Notes.value = "";  // Clear the notes
valid = true;

    // Determine the size which was selected. 
if      (document.inParms.Size[0].checked) studSize  = 3;
else if (document.inParms.Size[1].checked) studSize  = 4;
else if (document.inParms.Size[2].checked) studSize  = 5;

    // Get the Stud and Receptacle Finishes
//studFinish = '';
//receFinish = '';
//alert ("document.inParms.stuFinish.length = " + document.inParms.stuFinish.length);
//if (document.inParms.stuFinish.length) {
//  for (i = 0 ; i < document.inParms.stuFinish.length ; ++i ) {
//    alert ("document.inParms.stuFinish["+i+"].checked = " + document.inParms.stuFinish[i].checked);
//    if (document.inParms.stuFinish[i].checked) {
//      alert ("document.inParms.stuFinish["+i+"].value = " + document.inParms.stuFinish[i].value);
//      studFinish = '-' + document.inParms.stuFinish[i].value;
//    } 
//  }
//}
//else {
  studFinish = "-Z2CT";
//}
//alert ("Stud Finish: " + studFinish);

//if (document.inParms.recFinish.length) {
//  for (i = 0 ; i < document.inParms.recFinish.length ; ++i ) {
//    if (document.inParms.recFinish[i].checked) {
//      receFinish = '-' + document.inParms.recFinish[i].value;
//    }
//  }
//}
//else {
  receFinish = "-ACNC";
//}
//alert ("Receptacle Finish: " + receFinish);

    // Determe the head style which was selected.
if      (document.inParms.Head[0].checked) { 
  headStyle="Oval";             
  studPart="UA";   
  studPartDFCI = "571" + studSize + "-";
}
else if (document.inParms.Head[1].checked) { 
  headStyle="Hex";              
  studPart="UH";   
  studPartDFCI = "578" + studSize + "-";
}
else if (document.inParms.Head[2].checked) { 
  headStyle="Flush Straight";   
  studPart="UF";   
  studPartDFCI = "576" + studSize + "-";
}
else if (document.inParms.Head[3].checked) { 
  headStyle="Flush Hex Recess"; 
  studPart="UFSH"; 
  studPartDFCI = "576" + studSize + "-";
}

if (studPart == "UFSH") { 
  studPartDFCI += "S";
}
studPartDFCI += "20-";

    // Determine the retainer which was selected and 
    // whether or not it is to be nested.
//-----------------
// There is only one retainer available for new applications.
//-----------------
//if      (document.inParms.Retainer[0].checked) { 
//  retaStyle="Half Grommet";   
//  retaPart="GH"; 
//  retaPartDFCI="127H-" + studSize;
//}
//else if (document.inParms.Retainer[1].checked) { 
  retaStyle="Retaining Ring"; 
  retaPart="WA"; 
  retaPartDFCI = "5723-A";
//}

    // Determine the type of receptacle which was selected.
if      (document.inParms.Receptacle[0].checked) { 
  receStyle="Rigid";     
  recePart="A";  
  recePartDFCI = "5718-";
  if (studSize != 5) { recePartDFCI += "A"; }
  recePartDFCI += studSize + receFinish;
}
else if (document.inParms.Receptacle[1].checked) { 
  receStyle="Floating";  
  recePart="FA"; 
  recePartDFCI = "5718-F"; 
  if (studSize != 5) { recePartDFCI += "A"; }
  recePartDFCI += studSize + receFinish +" and 5718-F" + studSize + "-3-Z3CT (2)";
}
else if (document.inParms.Receptacle[2].checked) { 
  receStyle="Press Fit"; 
  recePart="FP"; 
  recePartDFCI = "5718-FP" + studSize + receFinish;
}

    // read in the panel, gap, and support values.
panel   = document.inParms.Panel.value;
gap     = document.inParms.Gap.value;
support = document.inParms.Support.value;

    // set the information which was entered in the display.
document.inParms.studSpec.value = headStyle + " Size " + studSize;
document.inParms.retaSpec.value = retaStyle;
document.inParms.receSpec.value = receStyle;
setPileText(0,0);

    // do some validation on the input information.
    // 1. A panel thickness is required.  
if (panel   == "") { displayErrorMessage(8); resetPartNumbers(); }
else               { panel = eval(panel);                        }
if (gap     == "") { gap = 0;                                    }
else               { gap = eval(gap);                            }
if (support == "") { support = 0;                                }
else               { support = eval(support);                    }

if      (document.inParms.UOM[0].checked) { inch = true;  }
else if (document.inParms.UOM[1].checked) { inch = false; }

if (!inch) {
  panel   *= .03937;
  gap     *= .03937;
  support *= .03937;
}

if (valid) setPileUp();

    // 2. Validate the receptacle
if (valid) validateReceptacle();

    // 3. Validate everything else
if (valid) validateBalance();

    // 4. Set the Retainer Part Number
if (valid) setRetainerPartNumber();

    // 5. Set the Receptacle Part Number
if (valid) setReceptaclePartNumber();
 
    // 6. Set the Stud Part Number
if (valid)
  switch(studSize) {
    case 3 : { setSize3(); break; }
    case 4 : { setSize4(); break; }
    case 5 : { setSize5(); break; }
  }

    // Set the part numbers in the display
    // if there is an error, the fields will be blank
document.inParms.studPart.value   = studPartDFCI; 
document.inParms.retaPart.value   = retaPartDFCI;
document.inParms.recePart.value   = recePartDFCI;
if (inch) {
  document.inParms.Undercut.value   = undercut;
}
else {
  var temp = undercut /.03937;
  temp = parseInt((temp * 100) + .5) / 100;
  document.inParms.Undercut.value = temp + " mm";
}
}

    // This function is to validate the receptacle
function validateReceptacle() {
  switch (studSize) {
    case 3 : { if (recePart != "A"  && 
                   recePart != "FA" && 
                   recePart != "FP") 
                 displayErrorMessage(1);
               break; }
    case 4 : { if (recePart != "A"  && 
                   recePart != "FA" && 
                   recePart != "FP")
                 displayErrorMessage(2);
               break; }
    case 5 : { if (recePart != "A" && 
                   recePart != "FA")
                 displayErrorMessage(3);
               break; }
  }
}

    // This function is to validate the configuration
function validateBalance() {
  switch (studSize) {
    case 3 : { // Press Fit Receptacles require a minimum support of .050"
               if (recePart == "FP") {
                 if (support < 0.050) { support = 0.050; displayErrorMessage(9); }
                     // if the support is less than 0.070", press fit receptacles
                     // require a retaining ring
                 if ((support < 0.070) && (retaPart != "WA")) {
                   displayErrorMessage(11);
                   document.inParms.Retainer[0].checked = false;
                   document.inParms.Retainer[1].checked = true;
                   retaStyle="Retaining Ring";
                   retaPart="WA";
                   retaPartDFCI = "5723-A";
                   setRetainerPartNumber();
                   document.inParms.retaSpec.value = retaStyle;
                 }
               }
               if (studPart == "UF") { // size 3 flush heads are hex recess
                 displayErrorMessage(4); 
                 document.inParms.Head[2].checked = false;
                 document.inParms.Head[3].checked = true;
		         headStyle="Flush Hex Recess"; 
                 studPart="UFSH"; 
                 studPartDFCI = "5763-S20-";
                 document.inParms.studSpec.value = headStyle + " Size " + studSize;
               }
                  // flush heads require a min of 0.125 total pileup
               if ((studPart == "UFSH") && (pileup < 0.125)) displayErrorMessage(5);
               break; }
    case 4 : { // Press Fit Receptacles require a minimum support of 0.065"
               if (recePart == "FP"){
                 if (support < 0.065) { support = 0.065; displayErrorMessage(10); } 
                     // if the support is less than 0.094", Press Fit Receptacles
                     // require the retaining ring
                 if ((retaPart != "WA") && (support < 0.094)) {
                   displayErrorMessage(12);
                   document.inParms.Retainer[0].checked = false;
                   document.inParms.Retainer[1].checked = true;
                   retaStyle="Retaining Ring";    
                   retaPart="WA"; 
                   retaPartDFCI = "5723-A";
                   setRetainerPartNumber();
                   document.inParms.retaSpec.value = retaStyle;
                 }
               }
               if (studPart == "UFSH") {
                 displayErrorMessage(6);
                 document.inParms.Head[2].checked = true;
                 document.inParms.Head[3].checked = false;
                 headStyle="Flush Straight";   
                 studPart="UF";
                 studPartDFCI = "5764-20-";
                 document.inParms.studSpec.value = headStyle + " Size " + studSize;
               }
               break; }
    case 5 : { if (studPart == "UFSH") {
                 displayErrorMessage(6);
                 document.inParms.Head[2].checked = true;
                 document.inParms.Head[3].checked = false;
                 headStyle="Flush Straight";   
                 studPart="UF";
                 studPartDFCI = "5765-20-";
                 document.inParms.studSpec.value = headStyle + " Size " + studSize;
               }
               break; }
  }
  setPileUp();
  if (valid) 
    switch (studSize) {
      case 3 : { if (pileup < 0 || pileup > 0.400) displayErrorMessage(13); break; }
      case 4 : { if (pileup < 0 || pileup > 0.800) displayErrorMessage(14); break; }
      case 5 : { if (pileup < 0 || pileup > 0.800) displayErrorMessage(15); break; }
    }
}

    // This function is to set the receptacle part number.
function setReceptaclePartNumber() {
  switch (studSize) {
    case 3 : { recePart = "UR" + recePart + studSize; break; }
    case 4 : { recePart = "UR" + recePart + studSize; break; }
    case 5 : { if (recePart == "FA") recePart = "URF5";
               else                  recePart = "UR5";
               break; }
  }
}

    // This function is to set the retainer part number
function setRetainerPartNumber() { 
  if (retaPart.substring(0,2) == "GH") { retaPart += studSize + "S"; retaPartDFCI += "S-Z3CT"; }
  else switch (studSize) {
         case 3 : { retaPart = "Y166";  retaPartDFCI = "5725-166-Z3CT";  break; }
         case 4 : { retaPart = "WA514"; retaPartDFCI = "5723-A514-Z3CT"; break; }
         case 5 : { retaPart = "WA516"; retaPartDFCI = "5723-A516-Z3CT"; break; }
       }
}

    // This function is to calculate the pileup allowing for the min gap required
    //      If the retainer is tagged as nested in the panel or support, there is
    //      no minimum gap required.
function setPileUp() {
  pileup   = panel + gap + support;
  pileup *= 1000;
  pileup = parseInt(pileup);
  pileup /= 1000;
  setPileText(pileup);
}

    // This function is to set the "panel / max(gap,gmin) / support = pileup" display
function setPileText(pileup) {
  var work = "";
  if (inch) {
    work += panel + " / "+ gap + " / " + support;
    if (pileup > 0) work += " = " + pileup;
  }
  else {
    var temp = panel / .03937;
    temp = parseInt((temp * 100) + .5) / 100;
    work += temp + " / ";
    temp = gap / .03937;
    temp = parseInt((temp * 100) + .5) / 100;
    work += temp + " / ";
    temp = support / .03937;
    temp = parseInt((temp * 100) + .5) / 100;
    work += temp;
    if (pileup > 0) {
      temp = pileup / .03937;
      temp = parseInt((temp * 100) + .5) / 100;
      work += " = " + temp;
    }
    work += " mm";
  }
  document.inParms.pgsSpec.value = work;
}

    // This function is to set the part number for the size 3 stud.
function setSize3 () {
  var lLim    = new Array();
  var uLim    = new Array();
  var Callout = new Array();
  var bDim    = new Array();
  lLim[0] = 0;     uLim[0] = 0.050; Callout[0] =  "5"; bDim[0] = "0.160";
  lLim[1] = 0.051; uLim[1] = 0.100; Callout[1] = "10"; bDim[1] = "0.210";
  lLim[2] = 0.101; uLim[2] = 0.150; Callout[2] = "15"; bDim[2] = "0.260";
  lLim[3] = 0.151; uLim[3] = 0.200; Callout[3] = "20"; bDim[3] = "0.310";
  lLim[4] = 0.201; uLim[4] = 0.250; Callout[4] = "25"; bDim[4] = "0.360";
  lLim[5] = 0.251; uLim[5] = 0.300; Callout[5] = "30"; bDim[5] = "0.410";
  lLim[6] = 0.301; uLim[6] = 0.350; Callout[6] = "35"; bDim[6] = "0.460";
  lLim[7] = 0.351; uLim[7] = 0.400; Callout[7] = "40"; bDim[7] = "0.510";
  found = false;
  for ( i = 0 ; i < 8 ; ++i ) {
    if (lLim[i] <= pileup && uLim[i] >= pileup && !found) {
      cOut = Callout[i]; BDim = bDim[i]; found = true; }
  }
  if (found) { studPart += studSize + "T" + cOut; undercut = BDim; 
               studPartDFCI += cOut + studFinish; }
  else       { displayErrorMessage(16); }
}

    // This function is to set the part number for the size 4 stud.
function setSize4 () {
  var lLim    = new Array();
  var uLim    = new Array();
  var Callout = new Array();
  var bDim    = new Array();
  lLim[0] = 0;     uLim[0] = 0.100; Callout[0] = "10"; bDim[0] = "0.250";
  lLim[1] = 0.101; uLim[1] = 0.200; Callout[1] = "20"; bDim[1] = "0.350";
  lLim[2] = 0.201; uLim[2] = 0.300; Callout[2] = "30"; bDim[2] = "0.450";
  lLim[3] = 0.301; uLim[3] = 0.400; Callout[3] = "40"; bDim[3] = "0.550";
  lLim[4] = 0.401; uLim[4] = 0.500; Callout[4] = "50"; bDim[4] = "0.650";
  lLim[5] = 0.501; uLim[5] = 0.600; Callout[5] = "60"; bDim[5] = "0.750";
  lLim[6] = 0.601; uLim[6] = 0.700; Callout[6] = "70"; bDim[6] = "0.850";
  lLim[7] = 0.701; uLim[7] = 0.800; Callout[7] = "80"; bDim[7] = "0.950";
  found = false;
  for ( i = 0 ; i < 8 ; ++i ) {
    if (lLim[i] <= pileup && uLim[i] >= pileup && !found) {
      cOut = Callout[i]; BDim = bDim[i]; found = true; }
  }
  if (found) { studPart += studSize + "T" + cOut; undercut = BDim; 
               studPartDFCI += cOut + studFinish; }
  else       { displayErrorMessage(16); }
}

    // This function is to set the part number for the size 5 stud.
function setSize5 () {
  var lLim    = new Array();
  var uLim    = new Array();
  var Callout = new Array();
  var bDim    = new Array();
  lLim[0] = 0;     uLim[0] = 0.100; Callout[0] = "10"; bDim[0] = "0.360";
  lLim[1] = 0.101; uLim[1] = 0.200; Callout[1] = "20"; bDim[1] = "0.460";
  lLim[2] = 0.201; uLim[2] = 0.300; Callout[2] = "30"; bDim[2] = "0.560";
  lLim[3] = 0.301; uLim[3] = 0.400; Callout[3] = "40"; bDim[3] = "0.660";
  lLim[4] = 0.401; uLim[4] = 0.500; Callout[4] = "50"; bDim[4] = "0.760";
  lLim[5] = 0.501; uLim[5] = 0.600; Callout[5] = "60"; bDim[5] = "0.860";
  lLim[6] = 0.601; uLim[6] = 0.700; Callout[6] = "70"; bDim[6] = "0.960";
  lLim[7] = 0.701; uLim[7] = 0.800; Callout[7] = "80"; bDim[7] = "1.060";
  found = false;
  for ( i = 0 ; i < 8 ; ++i ) {
    if (lLim[i] <= pileup && uLim[i] >= pileup && !found) {
      cOut = Callout[i]; BDim = bDim[i]; found = true; }
  }
  if (found) { studPart += studSize + "T" + cOut; undercut = BDim; 
               studPartDFCI += cOut + studFinish; }
  else       { displayErrorMessage(16); }
}

    // This function is to display error messages as alerts.
function displayErrorMessage(msgno) {
var messages = new Array();
var severity = new Array();
var numberOfMessages = 16;
severity[ 0] = 2; messages[ 0] = "Undefined message number [" + msgno + "] was requested";
severity[ 1] = 2; messages[ 1] = "The receptacle which you have selected is not valid for the size 3 stud!";
severity[ 2] = 2; messages[ 2] = "The receptacle which you have selected is not valid for the size 4 stud!";
severity[ 3] = 2; messages[ 3] = "The receptacle which you have selected is not valid for the size 5 stud!";
severity[ 4] = 1; messages[ 4] = "The slotted flush head stud is for size 4 and 5 only!  Assuming hex recess flush head!";
severity[ 5] = 2; messages[ 5] = "The size 3 flush head requires a minimum total pileup of 0.125\" (3.18 mm)!";
severity[ 6] = 1; messages[ 6] = "Hex recess flush heads are for size 3 only!  Assuming slotted flush head!";
severity[ 7] = 2; messages[ 7] = "The size 4 flush head requires a minimum total pileup of 0.150\" (3.81 mm)!";
severity[ 8] = 2; messages[ 8] = "A panel thickness is required!";
severity[ 9] = 1; messages[ 9] = "The size 3 Press Fit Receptacle requires a minimum support thickness of 0.050\" (1.27 mm)!";
severity[10] = 1; messages[10] = "The size 4 Press Fit Receptacle requires a minimum support thickness of 0.065\" (1.65 mm)!";
severity[11] = 1; messages[11] = "The size 3 Press Fit Receptacle with a support thickness less than 0.070\" (1.78 mm) requires the Retaining Ring!";
severity[12] = 1; messages[12] = "The size 4 Press Fit Receptacle with a support thickness less than 0.094\" (2.39 mm) requires the Retaining Ring!";
severity[13] = 2; messages[13] = "The total pileup for the size 3 must be <= 0.400\" (10.16 mm)!";
severity[14] = 2; messages[14] = "The total pileup for the size 4 must be <= 0.800\" (20.32 mm)!";
severity[15] = 2; messages[15] = "The total pileup for the size 5 must be <= 0.800\" (20.32 mm)!";
severity[16] = 2; messages[16] = "I am unable to find a stud for your requirements.  Please call for assistance!";

if (msgno > numberOfMessages)   alert(messages[0]);
else { switch (severity[msgno]) {
         case 0: { document.inParms.Notes.value = messages[msgno];       break; }
         case 1: { alert("Warning: "+messages[msgno]);                   break; } 
         case 2: { alert("Error: "+messages[msgno]); resetPartNumbers(); break; }
       }
     }
}
// End of hiding -->