/*--------------------------------------------------------*/
/* Act3PoleLP.js by Uwe Beis                   UB@Beis.de */
/* Written and authorized for ESP - Elliot Sound Products */
/* 02.03.04 - 11.08.04                                    */
/* ------------------ Please do not rip  -----------------*/

/*-----------------------------------------------------------------------------------------------*/
/* Component Values for Single Stage, 3rd Order, Active LP-Filter */

CompVals = new Array (5)
//                             C2    C4    C6                   R1a                  R3a                  R5a                    R1b                   R3b                   R5b
// Bessel (FilterType = 0)
CompVals[0] = new Array(3)
CompVals[0][0] = new Array(2);
CompVals[0][0][0] = new Array(3.3,  4.7,  1.0,  0.2661102290605628,   0.38326675068875965,  0.22805926435082227,  0.2360786912397083,   0.5665576383658243,   0.17390398930343065);
CompVals[0][0][1] = new Array( 10,   10,  2.2,  0.09675495339183021,  0.11886352626315282,  0.1425862776548807,   0.07383196164698236,  0.31892750680563536,  0.06964070587928099);
CompVals[0][0][2] = new Array( 15,   22,  4.7,  0.05671741785865744,  0.09047216047652859,  0.045329300839311616, 0.05320771017661344,  0.11119973131605827,  0.039312632411753444);
CompVals[0][1] = new Array(2);
CompVals[0][1][0] = new Array(2.2,  3.3,  1.0,  0.35166127216964166,  0.43049094927175874,  0.24999297978538737,  0.2906940668956131,   0.6857186458133919,   0.18986034012064543);
CompVals[0][1][1] = new Array(6.8,  6.8,  2.2,  0.1300393128508392,   0.13509470390781578,  0.15374447079329495,  0.08815959838336647,  0.37941869350283924,  0.08074658583793491);
CompVals[0][1][2] = new Array( 10,   15,  4.7,  0.07265922525389154,  0.10668007774554307,  0.05027936667313691,  0.06696427455826445,  0.13000353021889993,  0.04476778126908162);
CompVals[0][2] = new Array(2);
CompVals[0][2][0] = new Array(2.2,  3.3,  1.0,  0.3505366903746446,   0.3147381599741483,   0.25164443082698673,  0.23652002418221385,  0.7809239605035431,   0.1503119621133719);
CompVals[0][2][1] = new Array(4.7,  6.8,  2.2,  0.15761464597514524,  0.15751151714791037,  0.11546982047549721,  0.11279044826632513,  0.33847750857479303,  0.07508881277173256);
CompVals[0][2][2] = new Array( 10,   15,  4.7,  0.07485910004815866,  0.07196919987575855,  0.053067231888509946, 0.05273906949407244,  0.16042932162636583,  0.033791035487917946);
CompVals[0][3] = new Array(2);
CompVals[0][3][0] = new Array(2.2,  2.2,  1.0,  0.2688348803977312,   0.4297653758510557,   0.2729630068762053,   0.2327143873528061,   0.5877381728075779,   0.23057578766344086);
CompVals[0][3][1] = new Array(4.7,  6.8,  2.2,  0.14921323111953597,  0.1334304593514371,   0.10903713395547117,  0.09863052469100739,  0.33551114820102956,  0.06560220617717422);
CompVals[0][3][2] = new Array( 10,   15,  4.7,  0.07078268275794741,  0.061138531760178715, 0.050030524294751674, 0.04616934550152696,  0.1585794930483229,   0.0295717029362629);
// Butterworth (FilterType = 1
CompVals[1] = new Array(3);
CompVals[1][0] = new Array(2);
CompVals[1][0][0] = new Array(6.8,   10,  1.0,  0.18376135513431482,  0.2991176288103759,   0.26754380114196835,  0.15691653238597744,  0.6264493948325075,   0.14960165255686864);
CompVals[1][0][1] = new Array( 15,   22,  2.2,  0.08334759523700616,  0.1355043805235559,   0.12195987489621514,  0.07110469492328436,  0.28527701220210155,  0.06790446385222064);
CompVals[1][0][2] = new Array( 33,   47,  4.7,  0.038082893558463796, 0.061200525668716504, 0.0588579664261594,   0.0321766709194693,   0.13611160644961107,  0.03132233106868867);
CompVals[1][1] = new Array(2);
CompVals[1][1][0] = new Array(3.3,  3.3,  1.0,  0.3798761230782089,   0.5170444981075408,   0.4675221614060568,   0.3003555785143774,   1.0295516037971797,   0.2969533973408918);
CompVals[1][1][1] = new Array(6.8,  6.8,  2.2,  0.1720615827552763,   0.28720436600281657,  0.19892279033918636,  0.1518321481825686,   0.41157888025289463,  0.15730505388655072);
CompVals[1][1][2] = new Array( 15,   15,  4.7,  0.0810536848311425,   0.12036722524191852,  0.09692562530624849,  0.06716962610267709,  0.20770948203969186,  0.06777825296608468);
CompVals[1][2] = new Array(2);
CompVals[1][2][0] = new Array(2.2,  3.3,  1.0,  0.5580814290751006,   0.6142998786182958,   0.40177728414621816,  0.430445710971844,    1.1450511757997088,   0.27946028489523056);
CompVals[1][2][1] = new Array(4.7,  6.8,  2.2,  0.24632737625530082,  0.3213821658643836,   0.17965367033709734,  0.20899278567739382,  0.47480503144249186,  0.14332565702606262);
CompVals[1][2][2] = new Array( 10,   15,  4.7,  0.11772326388854494,  0.14467715359177358,  0.0832815180344463,   0.0971410983314555,   0.22840227488311435,  0.06393040391102293);
CompVals[1][3] = new Array(2);
CompVals[1][3][0] = new Array(2.2,  3.3,  1.0,  0.5980656180604598,   0.5354466351348663,   0.4301286286434782,   0.4021699748364633,   1.3361028108612545,   0.25633851123387913);
CompVals[1][3][1] = new Array(4.7,  6.8,  2.2,  0.2689552770153792,   0.26783642574340705,  0.1974334970591829,   0.19175709687337517,  0.5793774809129215,   0.12801400688049946);
CompVals[1][3][2] = new Array( 10,   15,  4.7,  0.1277355689550979,   0.12239512118058116,  0.09072666135811659,  0.08966788300407937,  0.2745718893386428,   0.05761265564260268);
// Chebychev 0.5 dB (FilterType = 2)
CompVals[2] = new Array(3);
CompVals[2][0] = new Array(2);
CompVals[2][0][0] = new Array( 22,   33,  1.0,  0.0930883513212198,   0.18127067740258354,  0.18149724220936306,  0.08632972479389146,  0.4370441383955743,   0.08117219134492284);
CompVals[2][0][1] = new Array( 47,   68,  2.2,  0.043232161315699444, 0.08988265218803139,  0.08137992202450922,  0.04052955208205772,  0.19081228855308766,  0.040890455793621217);
CompVals[2][0][2] = new Array(100,  150,  4.7,  0.020378652834510638, 0.04111605097324476,  0.03764034226648625,  0.01903780578720296,  0.09027507148348982,  0.01835082938456343);
CompVals[2][1] = new Array(2);
CompVals[2][1][0] = new Array( 10,   15,  1.0,  0.31382840997401373,  0.4466924280016572,   0.32719506228419165,  0.2914930198072516,   0.8299908409635292,   0.1895859411566965);
CompVals[2][1][1] = new Array( 22,   33,  2.2,  0.14264927726091703,  0.20304201272796726,  0.14872502831103818,  0.1324968271851127,   0.3772685640743357,   0.0861754277985152);
CompVals[2][1][2] = new Array( 47,   68,  4.7,  0.0664184830349695,   0.09861782774188843,  0.06992779504365568,  0.06214334281362436,  0.17295735320182132,  0.04261481201852257);
CompVals[2][2] = new Array(2);
CompVals[2][2][0] = new Array( 10,   10,  1.0,  0.4199801508893696,   0.7128842493048815,   0.5613340909120562,   0.3984626529052453,   1.1413791703444112,   0.3695316476979056);
CompVals[2][2][1] = new Array( 22,   22,  2.2,  0.19090006858607803,  0.32403829513856125,  0.25515185950549424,  0.1811193876842013,   0.5188087137929142,   0.1679689307717788);
CompVals[2][2][2] = new Array( 47,   47,  4.7,  0.0893574789126336,   0.15167749985202955,  0.11943278530048719,  0.08477928785217814,  0.24284663198818915,  0.07862375482933996);
CompVals[2][3] = new Array(2);
CompVals[2][3][0] = new Array( 10,   10,  1.0,  0.5433822713242742,   0.8046350651832084,   0.7782599502497912,   0.5026034216793787,   1.6112867709611125,   0.4201755905657285);
CompVals[2][3][1] = new Array( 22,   22,  2.2,  0.246991941511035,    0.36574321144684385,  0.35375452284086945,  0.22845610076335268,  0.7324030777095967,   0.19098890480261768);
CompVals[2][3][2] = new Array( 47,   47,  4.7,  0.11561324921793102,  0.17119895003895463,  0.1655872234574153,   0.10693689822965464,  0.34282697254491434,  0.08939906182250512);
// Chebychev 1.0 dB (FilterType = 3)
CompVals[3] = new Array(3);
CompVals[3][0] = new Array(2);
CompVals[3][0][0] = new Array( 33,   33,  1.0,  0.07009174472098408,  0.21012741528963058,  0.16655326419691358,  0.06846201922609825,  0.3201860557403378,   0.11190529057232679);
CompVals[3][0][1] = new Array( 68,  100,  2.2,  0.034824149292742065, 0.07314601250518407,  0.07010158733550126,  0.03304751424157802,  0.1677226371998045,   0.03221577200075027);
CompVals[3][0][2] = new Array(150,  150,  4.7,  0.015303176502622228, 0.05133118825664157,  0.03215787451875002,  0.015149234043272434, 0.06139726448555862,  0.027158797962474432);
CompVals[3][1] = new Array(2);
CompVals[3][1][0] = new Array( 15,   22,  1.0,  0.25278285985570337,  0.3504874757673049,   0.30408676654144423,  0.23673226601868588,  0.7620419717889645,   0.1493417719120614);
CompVals[3][1][1] = new Array( 33,   47,  2.2,  0.11458825678182201,  0.163301750507282,    0.13924068643811913,  0.1076831056253283,   0.34234707255317404,  0.07067778289613354);
CompVals[3][1][2] = new Array( 68,  100,  4.7,  0.05540380550731791,  0.08025668764033078,  0.06256104419328162,  0.05233387010653032,  0.15629438344131233,  0.0340093704427848);
CompVals[3][2] = new Array(2);
CompVals[3][2][0] = new Array( 15,   15,  1.0,  0.34467993568101746,  0.5403435915986543,   0.530577437505038,    0.32646951466909885,  1.0827296335859689,   0.27955813170845856);
CompVals[3][2][1] = new Array( 33,   33,  2.2,  0.15667269803682593,  0.24561072345398116,  0.2411715625022584,   0.1483952339404997,   0.492149833448215,    0.12707187804925194);
CompVals[3][2][2] = new Array( 68,   68,  4.7,  0.07550033049205224,  0.1248874319500131,   0.1085010729920688,   0.07218728930645327,  0.22030424616066385,  0.06433066180121648);
CompVals[3][3] = new Array(2);
CompVals[3][3][0] = new Array( 15,   15,  1.0,  0.4447011733873651,   0.6295605015473479,   0.7219207242547815,   0.4157254503451859,   1.4884680066131404,   0.32662478786389815);
CompVals[3][3][1] = new Array( 33,   33,  2.2,  0.20213689699425752,  0.28616386433960733,  0.32814578375227915,  0.18896611379326567,  0.6765763666423026,   0.14846581266544603);
CompVals[3][3][2] = new Array( 68,   68,  4.7,  0.09751680317685801,  0.14358466055065638,  0.14944266052219352,  0.09181798367340638,  0.3069265639692802,   0.0742505821888859);
// Chebychev 2.0 dB (FilterType = 4)
CompVals[4] = new Array(3);
CompVals[4][0] = new Array(2);
CompVals[4][0][0] = new Array( 47,   68,  1.0,  0.0617908772942547,   0.1487021071119832,   0.1147357827637967,   0.06025187994112324,  0.2732838464735981,   0.06402591635248121);
CompVals[4][0][1] = new Array(100,  150,  2.2,  0.029005491884199187, 0.07064286298378766,  0.0498292867593201,   0.0283526562214034,   0.12105023538835495,  0.02974909832645279);
CompVals[4][0][2] = new Array(220,  330,  4.7,  0.013220263891839652, 0.03086853558036012,  0.024196720484244236, 0.012867324907997536, 0.058912586432926455, 0.01302615679536034);
CompVals[4][1] = new Array(2);
CompVals[4][1][0] = new Array( 22,   33,  1.0,  0.2162774887248483,   0.34879555402263207,  0.2203222053058611,   0.21084160318323236,  0.5511058657739183,   0.1430372610117324);
CompVals[4][1][1] = new Array( 47,   68,  2.2,  0.10014633944100293,  0.18989768381913907,  0.09023872504569953,  0.09935401061265745,  0.21897594848539245,  0.07887981417699817);
CompVals[4][1][2] = new Array(100,  150,  4.7,  0.04725031931082806,  0.08352309064527703,  0.04336873236669128,  0.04657509627656223,  0.10786490912195484,  0.034068584461861354);
CompVals[4][2] = new Array(2);
CompVals[4][2][0] = new Array( 22,   22,  1.0,  0.29799584961587094,  0.5772918898700309,   0.3706035689649327,   0.2942504094028204,   0.7420542372466166,   0.2919863464885499);
CompVals[4][2][1] = new Array( 47,   68,  2.2,  0.14288182091103255,  0.18383555047580746,  0.16708009096838858,  0.13651454648452357,  0.41603992579447274,  0.07727112555163568);
CompVals[4][2][2] = new Array(100,  150,  4.7,  0.06726633400386767,  0.08436066370132823,  0.07713185327633744,  0.06413817178039916,  0.1964372136341973,   0.03474010861946516);
CompVals[4][3] = new Array(2);
CompVals[4][3][0] = new Array( 22,   22,  1.0,  0.3860218525456847,   0.6293340898264745,   0.5418633016227488,   0.37538434122248815,  1.0958584651588867,   0.3200016867238751);
CompVals[4][3][1] = new Array( 47,   47,  2.2,  0.17989124248848012,  0.3097134841469393,   0.23530963838342844,  0.17603072409441442,  0.4743501534622521,   0.1570081986081057);
CompVals[4][3][2] = new Array(100,  100,  4.7,  0.08448938321830436,  0.14681068166627378,  0.10928752621532449,  0.08276202466820513,  0.22019012056340115,  0.07438775544488317);
// Chebychev 3.0 dB (FilterType = 5)
CompVals[5] = new Array(3);
CompVals[5][0] = new Array(2);
CompVals[5][0][0] = new Array( 68,  100,  1.0,  0.050548538567119945, 0.12379806001592415,  0.09385277885277979,  0.0496541424482785,   0.22733486287052015,  0.052029308198250426);
CompVals[5][0][1] = new Array(150,  220,  2.2,  0.022916953758730003, 0.05607315763849645,  0.04280849596208879,  0.022508447362064834, 0.10353835417987588,  0.023604514680914318);
CompVals[5][0][2] = new Array(330,  470,  4.7,  0.010424155818867074, 0.025288206742394976, 0.020783079943814814, 0.010224527002759698, 0.049452110977291436, 0.010835295868738246);
CompVals[5][1] = new Array(2);
CompVals[5][1][0] = new Array( 33,   47,  1.0,  0.17400663753165896,  0.2845861162587127,   0.19458820766482834,  0.17069525170461652,  0.4722156753211188,   0.11954576672190105);
CompVals[5][1][1] = new Array( 68,  100,  2.2,  0.083822264943089,    0.15581934445648762,  0.07648838326856984,  0.08320934073478425,  0.18800457845157592,  0.06386100355666538);
CompVals[5][1][2] = new Array(150,  220,  4.7,  0.0381946895899039,   0.06433459966993495,  0.03921465999854643,  0.037598746102865475, 0.09664709762569663,  0.026517578520407176);
CompVals[5][2] = new Array(2);
CompVals[5][2][0] = new Array( 33,   33,  1.0,  0.24267495458677674,  0.4332207825586535,   0.3381307614908988,   0.23894567695292074,  0.6790637092521057,   0.219083274348625);
CompVals[5][2][1] = new Array( 68,  100,  2.2,  0.1192802586099752,   0.1545474224641071,   0.14037341643576168,  0.11552233905317173,  0.3510180802595733,   0.06381455540740187);
CompVals[5][2][2] = new Array(150,  150,  4.7,  0.05315322492376277,  0.10367717669176359,  0.06642837741333467,  0.052694638147686594, 0.13294478968736145,  0.05225509936644105);
CompVals[5][3] = new Array(2);
CompVals[5][3][0] = new Array( 33,   33,  1.0,  0.31365166341274814,  0.4937199733425543,   0.4765234706239883,   0.3065313838918992,   0.9621210741720808,   0.2502118735033309);
CompVals[5][3][1] = new Array( 68,   68,  2.2,  0.15125850333037896,  0.264077930987691,    0.19776437183383866,  0.14909693663498205,  0.39754060807244296,  0.13327532293858477);
CompVals[5][3][2] = new Array(150,  150,  4.7,  0.06880227352051208,  0.11331486549034858,  0.09746987629193876,  0.06749755133523366,  0.1964089135034683,   0.05732062020701674);

ResG2Vals = new Array(5);
ResG2Vals[0] = new Array(1.4089406937600581, 0.7386295089352195, 0.3466593062399419);
ResG2Vals[1] = new Array(1.5651977173836393, 1.4693964245699935, 0.43480228261636067);
ResG2Vals[2] = new Array(2.1908408647763595, 3.2428815166833753, 0.3129591352236406);
ResG2Vals[3] = new Array(2.491027136379584,  3.9899434487281638, 0.26877286362041597);
ResG2Vals[4] = new Array(3.0155058964669994, 5.223819267093709,  0.21389410353300045);
ResG2Vals[5] = new Array(3.5280037672251225, 6.377644564657769,  0.17749623277487764);

function DrawSchematic()
{
  var Stages = parseInt(document.InputForm.FilterOrder.value) + 2;
  var FirstSchematicGIF = 2;   /* English and German Flag GIFs precede */
  if (Stages <= 2)
  {
    document.images[2 + FirstSchematicGIF].src = "Images/SKOutput.GIF";  
    document.images[3 + FirstSchematicGIF].src = "Images/Dummy.GIF";
    document.images[6 + FirstSchematicGIF].src = "Images/TxtOutput.GIF";
    document.images[7 + FirstSchematicGIF].src = "Images/TxtDummy.GIF";
   }
  else
  {
    document.images[2 + FirstSchematicGIF].src = "Images/RefLPStage" + String.fromCharCode(Stages + 48) + ".GIF";
    document.images[3 + FirstSchematicGIF].src = "Images/SKOutput.GIF";
    document.images[6 + FirstSchematicGIF].src = "Images/TxtEmpty.GIF";
    document.images[7 + FirstSchematicGIF].src = "Images/TxtOutput.GIF";
  }
  CalcNewResult();
}

function CalcNewResult()
{
  // Recalculate Table
  document.OutputFormSK.reset();
  document.OutputFormSK2.reset();
  var FilterType = GetFilterType();
  var FilterOrder = GetFilterOrder();
  var ScaleOffset = GetScaleOffset();
  var Stages = Math.floor((FilterOrder + 1) / 2);
  var Frequency = GetFrequency();
  var ImpScale = 6;     // So that resistor values become a couple of kOhm
  var Scale = ScaleOffset + Math.floor(3 * Math.log(Frequency) / Math.log(10));  // Manual modification of resistors
  var Decade = Math.floor(Scale / 3); // Capacitor decades appropriate to the frequencies
  var Index = 2 - (Scale - 3 * Decade);  // 1 - 2.2 - 4.7 values appropriate to the frequencies
  var CG2 = GetCG2();

  C2 = CompVals[FilterType][FilterOrder][Index][0] / Math.pow(10,ImpScale) / Math.pow(10,Decade);
  C4 = CompVals[FilterType][FilterOrder][Index][1] / Math.pow(10,ImpScale) / Math.pow(10,Decade);
  C6 = CompVals[FilterType][FilterOrder][Index][2] / Math.pow(10,ImpScale) / Math.pow(10,Decade);
  R1a = CompVals[FilterType][FilterOrder][Index][3] * Math.pow(10,ImpScale) * Math.pow(10,Decade) / (2 * Math.PI * Frequency);
  R3a = CompVals[FilterType][FilterOrder][Index][4] * Math.pow(10,ImpScale) * Math.pow(10,Decade) / (2 * Math.PI * Frequency);
  R5a = CompVals[FilterType][FilterOrder][Index][5] * Math.pow(10,ImpScale) * Math.pow(10,Decade) / (2 * Math.PI * Frequency);
  R1b = CompVals[FilterType][FilterOrder][Index][6] * Math.pow(10,ImpScale) * Math.pow(10,Decade) / (2 * Math.PI * Frequency);
  R3b = CompVals[FilterType][FilterOrder][Index][7] * Math.pow(10,ImpScale) * Math.pow(10,Decade) / (2 * Math.PI * Frequency);
  R5b = CompVals[FilterType][FilterOrder][Index][8] * Math.pow(10,ImpScale) * Math.pow(10,Decade) / (2 * Math.PI * Frequency);
  R1G2 = ResG2Vals[FilterType][0] / (2 * Math.PI * Frequency * CG2);
  R3G2 = ResG2Vals[FilterType][1] / (2 * Math.PI * Frequency * CG2);
  R5G2 = ResG2Vals[FilterType][2] / (2 * Math.PI * Frequency * CG2);
  /*---- Sallen-Key output ----*/
  document.OutputFormSK.Result[0].value = "  " + Disp3Dec(C2);
  document.OutputFormSK.Result[1].value = "  " + Disp3Dec(C4);
  document.OutputFormSK.Result[2].value = "  " + Disp3Dec(C6);
  document.OutputFormSK.Result[3].value = "  " + Disp3Dec(R1a);
  document.OutputFormSK.Result[4].value = "  " + Disp3Dec(R3a);
  document.OutputFormSK.Result[5].value = "  " + Disp3Dec(R5a);
  document.OutputFormSK.Result[6].value = "  " + Disp3Dec(R1b);
  document.OutputFormSK.Result[7].value = "  " + Disp3Dec(R3b);
  document.OutputFormSK.Result[8].value = "  " + Disp3Dec(R5b);
  /*---- Sallen-Key output, Gain = 2 ----*/
  document.OutputFormSK2.CapG2.value = "  " + Disp3Dec(CG2);
  document.OutputFormSK2.Result[0].value = "  " + Disp3Dec(R1G2);
  document.OutputFormSK2.Result[1].value = "  " + Disp3Dec(R3G2);
  document.OutputFormSK2.Result[2].value = "  " + Disp3Dec(R5G2);
}

function ScaleIncDec(Step)
{ 
  document.InputForm.ScaleOffset.value = GetScaleOffset() + Step;
  CalcNewResult();
}

function Disp3Dec(Value)
{
  /* Convert numeric values to strings including conventional units */
  if (Value != 0)
  {
    /* Round off the numeric value for 5-digit display at its 6th digit */
    var Decade1 = Math.floor(Math.log(Value) / Math.log(10));
    Value = Value / Math.pow(10,Decade1);   /* 0.000 <= Value < 9.999999 */
    Value = Value + 0.00005;                /* Rounding for 5 digit values */
    Value = Value * Math.pow(10,Decade1);   /* Former value rounded */
    /* Convert values to 1.00 - 999.999 */
    var Decade3 = Math.floor(Math.log(Value) / Math.log(1000));
    if (Decade3 < -6) ValueString = "too low";
    else if (Decade3 > 4) ValueString = "too high";
    else
    {
      var Dec3Char = "afpnum kMGT".substring(Decade3 + 6, Decade3 + 7);
      Value = Value / Math.pow(1000,Decade3); /* 0.00 <= Value3 < 999.999 */
      /* If necessary cut off digit at the end of the string resulting from Java rounding error */
      var ValueString = String(Value);
      ValueString = ValueString.substring(0, 6);
      Value = Number(ValueString);
      ValueString = String(Value);
      /* Display values >= 100 as 3 digits without decimal point and all others as 4 characters */
      if (ValueString.substring(5, 6) == ".") /* 100.0 <= Value <= 999.999 */
        ValueString = ValueString.substring(0, 5);
      else                                    /* 1.00 <= Value <= 99.9999 */
        ValueString = ValueString.substring(0, 6);
      ValueString = ValueString + Dec3Char;
    }
  }
  else var ValueString = "-";
  return ValueString;
}

function GetFilterType()
{
  if (document.InputForm.FilterType[0].checked) var FilterType = 0
  if (document.InputForm.FilterType[1].checked) var FilterType = 1
  if (document.InputForm.FilterType[2].checked) var FilterType = 2
  if (document.InputForm.FilterType[3].checked) var FilterType = 3
  if (document.InputForm.FilterType[4].checked) var FilterType = 4
  if (document.InputForm.FilterType[5].checked) var FilterType = 5
  return FilterType;
}

function GetFilterOrder()
{
  var FilterOrder = parseInt(document.InputForm.FilterOrder.value);
  return FilterOrder;
}

function GetFrequency()
{
  var Frequency = Dec3ToFloat(document.InputForm.CutOffFrequency.value);
  if (Frequency <= 0 || isNaN(Frequency))
  {
    alert("Cutoff Frequency \nmust be a Number > 0!");
    ErrorFlag = true;
  }
  else
  {
    document.InputForm.CutOffFrequency.value = "  " + Disp3Dec(Frequency);
    return Frequency;
  }
}

function GetCG2()
{
  var CG2 = Dec3ToFloat(document.InputForm.CapG2.value);
  //var CG2 = Dec3ToFloat(document.OutputFormSK.CapG2.value);
  if (CG2 <= 0 || isNaN(CG2))
  {
    alert("Capacitor Value \nmust be a Number > 0!");
    ErrorFlag = true;
  }
  else
  {
    document.InputForm.CapG2.value = "  " + Disp3Dec(CG2);
    return CG2;
  }
}

function GetScaleOffset()
{
  var ScaleOffset = parseInt(document.InputForm.ScaleOffset.value);
  return ScaleOffset;
}

function Dec3ToFloat(ValueString)
{
  /* Remove blanks */
  while (ValueString.search(/ /) > -1)
    ValueString = ValueString.replace(/ /, "");
  /* Position of conventional unit character */
  var Dec3Pos = ValueString.length - 1;
  /* Isolate conventional unit character */
  var Dec3Char = ValueString.substring(Dec3Pos, Dec3Pos + 1);
  var Decade3 = "afpnum kMGT".indexOf(Dec3Char) - 6;
  if (Decade3 == -7)         /* No conventional unit character */ 
    var Value = Number(ValueString);
  else
    var Value = Number(ValueString.substring(0, Dec3Pos)) * Math.pow(1000,Decade3);
  return Value;
}


