// This is the general JavaScript file for Berg's On-line Engineering Tools.
//   This script contains the general function used in the web pages.

  var temp;

  function FormatNumber(v, n){
    var intVal = parseInt(v);
    var decVal = v - intVal;
    var strVal = decVal.toString();
    if (strVal.length == 4) return (v.toString());

    var strInput = v.toString();

    
  }

  function RoundDown(Number, NumberOfPlaces){
    var temp2 = 10;
    var one = Number.toString();

    if ( parseFloat(one.length - InStr(one, ".") ) <= NumberOfPlaces ){
      if (InStr(one, ".") > 0) return Number;
    }

    temp2 = pow(10, NumberOfPlaces);
    temp = parseInt( parseFloat(Number) * parseFloat(temp2) );
    return (parseFloat( parseFloat(temp) / parseFloat(temp2) ) );
  }

  function RoundUp(Number, NumberOfPlaces){
    var temp2, temp3, temp4;

    temp = Number * pow(10, NumberOfPlaces);
    temp2 = parseInt(temp);
    temp3 = temp - temp2;
    temp4 = 1 / (pow(10, NumberOfPlaces));

    if (temp3 < temp4){
      return Number;
    }else{
      temp = (temp2 + 1) / (pow(10, NumberOfPlaces));
      return temp;
    }
  }

  function pow(base, exp){

    return (Math.pow(base, exp));

    // I wrote this algorithm, but then found them in Math object
    var value = base;
    for(var j = exp - 1; j > 0; j--){
      value *= base;
    }
    return value;
  }

  function InStr(inputVal, strSearch){
    var inputStr = inputVal.toString();
    for (var i = 0; i < inputStr.length; i++) {
      var oneChar = inputStr.charAt(i);
      if (oneChar == strSearch) return i;
    }
    return 0;
  }

  function validateRadioGroup(buttonGroup){
    for (var i = 0; i < buttonGroup.length; i++) {
      if (buttonGroup[i].checked) return true;
    }
    return false;
  }

  function isEmpty(inputStr) {
    if (inputStr == null || inputStr == "") return true;
    return false;
  }

  function IsNumeric(inputVal) {
    var inputStr = inputVal.toString();
    for (var i = 0; i < inputStr.length; i++) {
      var oneChar = inputStr.charAt(i)
      if ( (oneChar < "0" || oneChar > "9") && oneChar != "." ) return false;
    }
    return true;
  }

  function isPosInteger(inputVal) {
    var inputStr = inputVal.toString();
    if (isEmpty(inputStr)) return false;
    for (var i = 0; i < inputStr.length; i++) {
      if (inputStr.charAt(i) < "0" || inputStr.charAt(i) > "9") return false;
    }
    return true;
  }

  function Disclaimer(){
    var t = "<table cellspacing=0 cellpadding=0 border=0 align=center width=78%>";
    t += "<tr><td><p class=\"disclaimer\">";
    var e = "</p></td></tr></table><br><br>";
    var d = "*Disclaimer: W. M. Berg and the programmer cannot be held responsible for any calculations ";
    d += "presented; all results should be verified through your own calculations (this program may contain ";
    d += "errors).  The results presented are guidelines only.  Please send all questions and any other feedback ";
    d += "to the Engineering Department at the <a href=\"mailto:WMBergTechSupport@wmberg.com\">Technical ";
    d += "Support</a> mailbox. &nbsp;This web application is in beta testing currently and has only been ";
    d += "tested under Microsoft Internet Explorer 5.5. &nbsp;Thank You for using W. M. Berg, Inc. for ";
    d += "all your mechanical needs. Come back soon!";
    return (t + d + e);
  }


