<!--Begin

//Copyright © 2004 Global Aircraft


var exempt = 0;

function calcFact(n){ 
if (n > 0) {return n*calcFact(n - 1);}
else {return 1;}} 


function helpMe() {
var helpWin = window.open("http://www.globalaircraft.org/expArchHelp.htm","helpMeForGodsSake","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=400");
try{helpWin.document.focus();}catch(e){}
helpWin.document.close();}


var atomicWeightTable = new Array(0,
1.00794,4.002602,6.941,9.012182,10.811,12.0107,14.00674,15.9994,18.9984032,20.1797,22.989770,24.3050,26.981538,28.0855,30.973761,32.066,35.4527,
39.948,39.0983,40.078,44.955910,47.867,50.9415,51.9961,54.938049,55.8457,58.933200,58.6934,63.546,65.39,69.723,72.61,74.92160,78.96,79.904,83.80,
85.4678,87.62,88.90585,91.224,92.90638,95.94,98,101.07,102.90550,106.42,107.8682,112.411,114.818,118.710,121.760,127.60,126.90447,131.29,132.90545,
137.327,138.9055,140.116,140.90765,144.24,145,150.36,151.964,157.25,158.92534,162.50,164.93032,167.26,168.93421,173.04,174.967,178.49,180.9479,
183.84,186.207,190.23,192.217,195.078,196.96655,200.59,204.3833,207.2,208.98038,209,210,222,223,226,227,232.0381,231.03588,238.0289,237,244,243,
247,247,251,252,257,258,259,262,261,262,263,262,265,266);

var primeAry = new Array(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,
79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,
181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,
283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,
409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,
523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,
647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,
773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,
911,919,929,937,941,947,953,967,971,977,983,991,997,1009);


function showAllFuncs() {
var myArray = new Array();var tmpSto;
//var winFuncs = window.open("","newwin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=180,height=265");
//winFuncs.document.open();
var winFuncs = popupOld;
winFuncs.document.write("<html><head><title>Master Index</title></head><body>");

winFuncs.document.write("<form name='popFunction' target='_parent'>");
winFuncs.document.write("<select multiple size='9' name='ecks' style='font-family: verdana, times new roman;font-size:10px;");
winFuncs.document.write("width:160;height:200;' target='_top' onchange=\"if ");
winFuncs.document.write("(this.options[this.selectedIndex].value.indexOf('()') == -1 && ");
winFuncs.document.write("this.options[this.selectedIndex].value != '') {top.location");
winFuncs.document.write("='javascript:addnum(\\''+this.options[this.selectedIndex].value+'\\')';");
winFuncs.document.write("this.options[this.selectedIndex].selected=false;this.blur();}else if (this.options[this.selectedIndex].value != '')");
winFuncs.document.write("{top.location='javascript:'+this.options[this.selectedIndex].value+'';");
winFuncs.document.write("this.options[this.selectedIndex].selected=false;this.blur();}else {this.options[this.selectedIndex].selected=false;this.blur();}\">");

// CONVERSIONS
winFuncs.document.write("<option value=''>--- Conversions ---</option>");
winFuncs.document.write("<option value='binDec('>binDec(#)</option>");
winFuncs.document.write("<option value='decBin('>decBin(#)</option>");
winFuncs.document.write("<option value='decHex('>decHex(#)</option>");
winFuncs.document.write("<option value='decOct('>decOct(#)</option>");
winFuncs.document.write("<option value='hexDec('>hexDec(#)</option>");
winFuncs.document.write("<option value='octDec('>octDec(#)</option>");
winFuncs.document.write("<option value='toDec('>toDec(#)</option>");
winFuncs.document.write("<option value='toFrac('>toFrac(#)</option>");
winFuncs.document.write("<option value='pToZ('>pToZ(#)</option>");
winFuncs.document.write("<option value='zToP('>zToP(#)</option>");

// DISTR
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Distributions ---</option>");
winFuncs.document.write("<option value='binomcdf('>binomcdf(num,p,k)</option>");
winFuncs.document.write("<option value='binompdf('>binompdf(num,p,k)</option>");
winFuncs.document.write("<option value='poissoncdf('>poissoncdf(&mu;,k)</option>");
winFuncs.document.write("<option value='poissonpdf('>poissonpdf(&mu;,k)</option>");

// LISTS
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Lists ---</option>");
winFuncs.document.write("<option value='add('>add(#,#[,#...])</option>");
winFuncs.document.write("<option value='avg('>avg(#,#[,#...])</option>");
winFuncs.document.write("<option value='div('>div(#,#[,#...])</option>");
winFuncs.document.write("<option value='max('>max(#,#[,#...])</option>");
winFuncs.document.write("<option value='median('>median(#,#[,#...])</option>");
winFuncs.document.write("<option value='min('>min(#,#[,#...])</option>");
winFuncs.document.write("<option value='mult('>mult(#,#[,#...])</option>");
winFuncs.document.write("<option value='percentile('>percentile(list, p-val)</option>");
winFuncs.document.write("<option value='rVal('>rVal(list, list)</option>");
winFuncs.document.write("<option value='stDev('>stDev(#,#[,#...])</option>");
winFuncs.document.write("<option value='sub('>sub(#,#[,#...])</option>");
winFuncs.document.write("<option value='mklist('>mklist(List, #,#[,#...])</option>");
winFuncs.document.write("<option value='shoMeState()'>Add List</option>");
winFuncs.document.write("<option value='dumpArray()'>Paste List</option>");
winFuncs.document.write("<option value='showTrees()'>View List</option>");
winFuncs.document.write("<option value='regLine()'>Linear Regression</option>");
winFuncs.document.write("<option value='linTrans()'>Linear Transformation</option>");
winFuncs.document.write("<option value='oneVarExec()'>One List Stats</option>");
winFuncs.document.write("<option value='genResids()'>Residuals</option>");
winFuncs.document.write("<option value='doTheGraph()'>Stats Graph</option>");
winFuncs.document.write("<option value='testNormlity()'>Test Normality</option>");
winFuncs.document.write("<option value='PValueZscore()'>X Val. Stats</option>");



// LOGS
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Logarithms ---</option>");
winFuncs.document.write("<option value='log('>log(#)</option>");
winFuncs.document.write("<option value='ln('>ln(#)</option>");

// MATRICES
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Matrices ---</option>");
winFuncs.document.write("<option value='add('>add([A-Z],[A-Z])</option>");
winFuncs.document.write("<option value='div('>div([A-Z],[A-Z])</option>");
winFuncs.document.write("<option value='det('>det([A-Z])</option>");
winFuncs.document.write("<option value='inv('>inv([A-Z])</option>");
winFuncs.document.write("<option value='mult('>mult([A-Z],[A-Z])</option>");
winFuncs.document.write("<option value='sub('>sub([A-Z],[A-Z])</option>");
winFuncs.document.write("<option value='tpose('>tpose([A-Z])</option>");
winFuncs.document.write("<option value='mkmatrix('>mkmatrix([A-Z],[#,#;])</option>");
winFuncs.document.write("<option value='addMatrix()'>Create Matrix</option>");
winFuncs.document.write("<option value='editMatrix()'>Edit Matrix</option>");
winFuncs.document.write("<option value='matrixRand()'>Random Matrix</option>");
winFuncs.document.write("<option value='viewMatrix()'>View Matrix</option>");

// PRIMES
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Primes ---</option>");
winFuncs.document.write("<option value='getFactors('>getFactors(#)</option>");
winFuncs.document.write("<option value='getPrimes('>getPrimes(lower,upper)</option>");
winFuncs.document.write("<option value='isPrime('>isPrime(#)</option>");

// SCIENCE
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Science ---</option>");
winFuncs.document.write("<option value='atomWt('>atomWt(atomic #)</option>");

// TRIG
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Trigonometric ---</option>");
winFuncs.document.write("<option value='cos('>cos(#)</option>");
winFuncs.document.write("<option value='sin('>sin(#)</option>");
winFuncs.document.write("<option value='tan('>tan(#)</option>");
winFuncs.document.write("<option value='sec('>sec(#)</option>");
winFuncs.document.write("<option value='csc('>csc(#)</option>");
winFuncs.document.write("<option value='cot('>cot(#)</option>");
winFuncs.document.write("<option value='acos('>acos(#)</option>");
winFuncs.document.write("<option value='asin('>asin(#)</option>");
winFuncs.document.write("<option value='atan('>atan(#)</option>");

// MISC MATH
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Misc ---</option>");
winFuncs.document.write("<option value='abs('>abs(#)</option>");
winFuncs.document.write("<option value='ceil('>ceil(#)</option>");
winFuncs.document.write("<option value='fact('>fact(#)</option>");
winFuncs.document.write("<option value='floor('>floor(#)</option>");
winFuncs.document.write("<option value='gcd('>gcd(#,#)</option>");
winFuncs.document.write("<option value='int('>int(#)</option>");
winFuncs.document.write("<option value='lcm('>lcm(#,#)</option>");
winFuncs.document.write("<option value='loop('>loop(#, ... )</option>");
winFuncs.document.write("<option value='max('>max(#,#[,#...])</option>");
winFuncs.document.write("<option value='min('>min(#,#[,#...])</option>");
winFuncs.document.write("<option value='modulus('>modulus(#,#)</option>");
winFuncs.document.write("<option value='nCr('>nCr(n,r)</option>");
winFuncs.document.write("<option value='nPr('>nPr(n,r)</option>");
winFuncs.document.write("<option value='randInt('>randInt(low,high,amt)</option>");
winFuncs.document.write("<option value='randNorm('>randNorm(&mu;,&sigma;,amt)</option>");
winFuncs.document.write("<option value='revPol('>revPol( equation )</option>");
winFuncs.document.write("<option value='round('>round(#[,decimal])</option>");
winFuncs.document.write("<option value='sqrt('>sqrt(#)</option>");
winFuncs.document.write("<option value='test('>test(= != >=, ..., ...)</option>");
winFuncs.document.write("<option value='pow('>pow(#,#)</option>");
winFuncs.document.write("<option value='solveForX('>solveForX(eq1=eq2)</option>");

// CALC CONTROLS
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Controls ---</option>");
winFuncs.document.write("<option value='append()'>Append Data</option>");
winFuncs.document.write("<option value='paste()'>Paste Data</option>");


// USER FUNCTIONS
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- User Functions ---</option>");
winFuncs.document.write("<option value=\"mkFunc();alert('Restarting program to reflect changes.');showAllFuncs();\">Create Function</option>");
for (var e=1; e <= 5; e++) {var tmp="func"+e+"";
if (document.Calulator[tmp].value != null && document.Calulator[tmp].value != '') {
tmpSto = document.Calulator[tmp].value;
myArray = tmpSto.split("=");
myArray[0] = myArray[0].replace(/\(x\)/g, "");
var name = myArray[0];
winFuncs.document.write("<option value='"+name+"('>"+name+"(#)</option>");}}

winFuncs.document.write("<option value=''> </option></select>");



winFuncs.document.write("<br><br><select multiple size='5' name='ecks2' style='font-family: verdana, times new roman;font-size:10px;");
winFuncs.document.write("width:160;height:100;' target='_top' onchange=\"if ");
winFuncs.document.write("(this.options[this.selectedIndex].value.indexOf('()') == -1 && ");
winFuncs.document.write("this.options[this.selectedIndex].value != '') {top.location");
winFuncs.document.write("='javascript:addnum(\\''+this.options[this.selectedIndex].value+'\\')';");
winFuncs.document.write("this.options[this.selectedIndex].selected=false;this.blur();}else if (this.options[this.selectedIndex].value != '')");
winFuncs.document.write("{top.location='javascript:'+this.options[this.selectedIndex].value+'';");
winFuncs.document.write("this.options[this.selectedIndex].selected=false;this.blur();}else {this.options[this.selectedIndex].selected=false;this.blur();}\">");

// SYMBOLS
winFuncs.document.write("<option value=''>--- Symbols ---</option>");
winFuncs.document.write("<option value=' '>space</option>");
winFuncs.document.write("<option value='^'>^</option>");
winFuncs.document.write("<option value=';'>;</option>");
winFuncs.document.write("<option value=','>,</option>");
winFuncs.document.write("<option value=')'>)</option>");
winFuncs.document.write("<option value='('>(</option>");
winFuncs.document.write("<option value='='>=</option>");
winFuncs.document.write("<option value='!='>!=</option>");
winFuncs.document.write("<option value='>'>&gt;</option>");
winFuncs.document.write("<option value='<'>&lt;</option>");
winFuncs.document.write("<option value='>='>&gt;=</option>");
winFuncs.document.write("<option value='<='>&lt;=</option>");

// VARS
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Variables ---</option>");
winFuncs.document.write("<option value='x'>x</option>");
winFuncs.document.write("<option value='addAns();'>ans</option>");
winFuncs.document.write("<option value='slapInListVar()'>L#</option>");
winFuncs.document.write("<option value='L1'>L1</option>");
winFuncs.document.write("<option value='L2'>L2</option>");
winFuncs.document.write("<option value='L3'>L3</option>");
winFuncs.document.write("<option value='L4'>L4</option>");
winFuncs.document.write("<option value='L5'>L5</option>");
winFuncs.document.write("<option value='L6'>L6</option>");
winFuncs.document.write("<option value='slapInMatrixVar()'>[#]</option>");
winFuncs.document.write("<option value='[A]'>[A]</option>");
winFuncs.document.write("<option value='[B]'>[B]</option>");
winFuncs.document.write("<option value='[C]'>[C]</option>");
winFuncs.document.write("<option value='[D]'>[D]</option>");
winFuncs.document.write("<option value='[E]'>[E]</option>");
winFuncs.document.write("<option value='[F]'>[F]</option>");

// CONSTANTS
winFuncs.document.write("<option value=''> </option>");
winFuncs.document.write("<option value=''>--- Constants ---</option>");
winFuncs.document.write("<option value='Na'>Na</option>");
winFuncs.document.write("<option value='C'>C</option>");
winFuncs.document.write("<option value='E'>E</option>");
winFuncs.document.write("<option value='eV'>eV</option>");
winFuncs.document.write("<option value='G'>G</option>");
winFuncs.document.write("<option value='H'>H</option>");
winFuncs.document.write("<option value='Infinity'>Infinity</option>");
winFuncs.document.write("<option value='pi'>pi</option>");

winFuncs.document.write("<option value=''> </option></select>");




winFuncs.document.write("<br /><font size=-3 face=verdana color=blue><i><u>(<a onclick=\"javascript:top.location='javascript:helpMe()'\" style='cursor:pointer;cursor:hand;'>Help</a>)</u></i></font>");

winFuncs.document.write("</form></body></html>");
winFuncs.document.close();
}

function slapInListVar() {var xx = window.prompt('Please enter a list (L0 - L99).','L1');addnum(xx);}

function slapInMatrixVar() {var xx = window.prompt('Please enter a matrix ([A] -[Z]).','[A]');addnum(xx);}

function append(data) {
var whichMat=prompt('Dump appended data into the calculator: ','');
if (document.Calulator.screen.value == "0") {document.Calulator.screen.value=""+whichMat;}
else {document.Calulator.screen.value+=""+whichMat;}}

function paste(data) {
var whichMat=prompt('Dump data into the calculator: ','');
document.Calulator.screen.value=whichMat;}


function parseAdvs(toEval) {
var holdMe = toEval;
var holdMeholdMe = "";


// PUT TRAILING ) IN FOR THEM 
if (holdMe.match(/\(/g) != null && ((holdMe.match(/\)/g) == null && holdMe.match(/\(/g).length > 0) || (holdMe.match(/\(/g).length > holdMe.match(/\)/g).length))) {
var stoMM = 0;try{if (holdMe.match(/\)/g).length > 0) {stoMM = holdMe.match(/\)/g).length;}}catch(e){}
var storeMisMatch = eval(holdMe.match(/\(/g).length - stoMM);
while (storeMisMatch > 0) {holdMe = holdMe+ ")";storeMisMatch--;}}


holdMeholdMe = holdMe;
if (holdMe.charAt(0) == "(") {holdMe = "1*(" + holdMe + ")";} //fix leading nested parenthesis
holdMe = replaceLetters(holdMe);
holdMe = holdMe.replace(/([0-9\.]+)\^([0-9]+)/g, "pow($1,$2)");

holdMe = holdMe.replace(/(\[[A-Z]\])\*(\[[A-Z]\])/g, "mult($1,$2)");
holdMe = holdMe.replace(/(\[[A-Z]\])\/(\[[A-Z]\])/g, "div($1,$2)");
holdMe = holdMe.replace(/(\[[A-Z]\])\+(\[[A-Z]\])/g, "add($1,$2)");
holdMe = holdMe.replace(/(\[[A-Z]\])\-(\[[A-Z]\])/g, "sub($1,$2)");

holdMe = holdMe.replace(/L([0-9]+)\+L([0-9]+)/g, "add([$1],[$2])");
holdMe = holdMe.replace(/L([0-9]+)\-L([0-9]+)/g, "sub([$1],[$2])");
holdMe = holdMe.replace(/L([0-9]+)\*L([0-9]+)/g, "mult([$1],[$2])");
holdMe = holdMe.replace(/L([0-9]+)\/L([0-9]+)/g, "div([$1],[$2])");

holdMe = holdMe.replace(/(add|sub|mult|div)\(L([0-9]+)\,L([0-9]+)\)/g, "$1([$2],[$3])");

holdMe = holdMe.replace(/([0-9]+)\*(\[[A-Z]\])/g, "mult($1,$2)");
holdMe = holdMe.replace(/([0-9]+)\/(\[[A-Z]\])/g, "div($1,$2)");
holdMe = holdMe.replace(/([0-9]+)\+(\[[A-Z]\])/g, "add($1,$2)");
holdMe = holdMe.replace(/([0-9]+)\-(\[[A-Z]\])/g, "sub($1,$2)");

holdMe = holdMe.replace(/([0-9]+)\+L([0-9]+)/g, "add([$1],[$2])");
holdMe = holdMe.replace(/([0-9]+)\-L([0-9]+)/g, "sub([$1],[$2])");
holdMe = holdMe.replace(/([0-9]+)\*L([0-9]+)/g, "mult([$1],[$2])");
holdMe = holdMe.replace(/([0-9]+)\/L([0-9]+)/g, "div([$1],[$2])");

holdMe = holdMe.replace(/(\[[A-Z]\])\*([0-9]+)/g, "mult($1,$2)");
holdMe = holdMe.replace(/(\[[A-Z]\])\/([0-9]+)/g, "div($1,$2)");
holdMe = holdMe.replace(/(\[[A-Z]\])\+([0-9]+)/g, "add($1,$2)");
holdMe = holdMe.replace(/(\[[A-Z]\])\-([0-9]+)/g, "sub($1,$2)");

holdMe = holdMe.replace(/L([0-9]+)\+([0-9]+)/g, "add([$1],[$2])");
holdMe = holdMe.replace(/L([0-9]+)\-([0-9]+)/g, "sub([$1],[$2])");
holdMe = holdMe.replace(/L([0-9]+)\*([0-9]+)/g, "mult([$1],[$2])");
holdMe = holdMe.replace(/L([0-9]+)\/([0-9]+)/g, "div([$1],[$2])");


while (holdMe.indexOf("mklist(L")>-1) {var pos=holdMe.indexOf("mklist(L");var holdMe=""+holdMe.substring(0, pos)+"MKLIST(#"+holdMe.substring((pos + 8), holdMe.length);}
while (holdMe.indexOf("percentile(L")>-1) {var pos=holdMe.indexOf("percentile(L");var holdMe=""+holdMe.substring(0, pos)+"PERCENTILE(#"+holdMe.substring((pos + 12), holdMe.length);}
holdMe = holdMe.replace(/rVal\(L([0-9]+)\,L([0-9]+)\)/g, "rVal(X$1,X$2)");
for(var ebb in listStorage){while (holdMe.indexOf(ebb)>-1) {var pos=holdMe.indexOf(ebb);var holdMe=""+holdMe.substring(0, pos)+""+reqList(ebb)+""+holdMe.substring((pos + ebb.length), holdMe.length);}}
while (holdMe.indexOf("MKLIST(#")>-1) {var pos=holdMe.indexOf("MKLIST(#");var holdMe=""+holdMe.substring(0, pos)+"mklist(L"+holdMe.substring((pos + 8), holdMe.length);}
while (holdMe.indexOf("PERCENTILE(#")>-1) {var pos=holdMe.indexOf("PERCENTILE(#");var holdMe=""+holdMe.substring(0, pos)+"percentile(L"+holdMe.substring((pos + 12), holdMe.length);}
holdMe = holdMe.replace(/rVal\(X([0-9]+)\,X([0-9]+)\)/g, "rVal(L$1,L$2)");




// TAKE CARE OF EQUATION SOLVER //
if (holdMe.match(/solveForX\(/gi)) {var saveMe=0;
while (holdMe.match(/solveForX\(/gi)) {
if (saveMe > 100) {alert("ERROR: Solve Loop Overflow");break;}

var parSrtIndex=holdMe.lastIndexOf("solveForX(");
var beforeLoop=holdMe.substring((parSrtIndex+10), holdMe.length);

var opAft=0;var opTtl=0;var save=1;
for (var i=0;i<beforeLoop.length-1;i++) {
if (opAft == 0 && save != 1) {break;}if (beforeLoop.charAt(i) == "(") {opAft++;opTtl++;}
if (beforeLoop.charAt(i) == ")") {opAft--;save++;}}

for (var i=opTtl;i>0;i--) {
parSrtIndex=beforeLoop.indexOf(")");
beforeLoop = beforeLoop.replace(/\)/, "!");}

parSrtIndex=beforeLoop.indexOf(")");
beforeLoop=beforeLoop.substring(0, parSrtIndex);
beforeLoop = beforeLoop.replace(/\!/g, ")");

var identifier = "solveForX("+beforeLoop+")";
while (holdMe.indexOf(identifier)>-1) {var pos=holdMe.indexOf(identifier);var holdMe=""+holdMe.substring(0, pos)+"AABB"+holdMe.substring((pos + identifier.length), holdMe.length);}

try {var toto = doItDoItDoIt(beforeLoop);} catch(e) {alert("Please only use trig functions, sqrt, log, and ln inside your solveForX function!");toto = "NaN";}

toto = toto.replace(/Roughly around\: /, "");
toto = toto.replace(/No numbers found\!/, "NaN");
toto = toto.replace(/Exact number found\: /, "");

holdMe = holdMe.replace(/AABB/g, toto);


saveMe++;}}
///





// TAKE CARE OF LOOPS //
if (holdMe.match(/loop\(/gi)) {var saveMe=0;
while (holdMe.match(/loop\(/gi)) {
if (saveMe > 100) {alert("ERROR: Loop Overflow");break;}

var parSrtIndex=holdMe.lastIndexOf("loop(");
var beforeLoop=holdMe.substring((parSrtIndex+5), holdMe.length);

var opAft=0;var opTtl=0;var save=1;
for (var i=0;i<beforeLoop.length-1;i++) {
if (opAft == 0 && save != 1) {break;}if (beforeLoop.charAt(i) == "(") {opAft++;opTtl++;}
if (beforeLoop.charAt(i) == ")") {opAft--;save++;}}

for (var i=opTtl;i>0;i--) {
parSrtIndex=beforeLoop.indexOf(")");
beforeLoop = beforeLoop.replace(/\)/, "!");}

parSrtIndex=beforeLoop.indexOf(")");
beforeLoop=beforeLoop.substring(0, parSrtIndex);
beforeLoop = beforeLoop.replace(/\!/g, ")");

var identifier = "loop("+beforeLoop+")";
while (holdMe.indexOf(identifier)>-1) {var pos=holdMe.indexOf(identifier);var holdMe=""+holdMe.substring(0, pos)+"AABB"+holdMe.substring((pos + identifier.length), holdMe.length);}

var numIndex = beforeLoop.indexOf(",");
var loopTimes = beforeLoop.substring(0,numIndex);
beforeLoop = beforeLoop.substring(numIndex+1,beforeLoop.length);
loopTimes = eval(loopTimes*1);
if (loopTimes > 500) {loopTimes = 500;}

//beforeLoop=parens(beforeLoop);
var loopArray = new Array();
for (x=0;x<loopTimes;x++) {
var tmp01 = kernel(beforeLoop);
var temp = new Array();
tmp = tmp01.split(':');
tmp01 = tmp[0];
loopArray.push(tmp01);}

holdMe = holdMe.replace(/AABB/g, loopArray);

saveMe++;}}
///



holdMe=parens(holdMe);


var ecks1 = kernel(holdMe);
var temp = new Array();
temp = ecks1.split(':');
holdMe = temp[0];exempt = temp[1];


///////alert(holdMe);

if (holdMe.indexOf(",") == -1 && exempt != 1 && holdMe.indexOf("[") == -1) {
document.Calulator.screen.value=toEval+"\n         "+eval(holdMe)+"\n";
if (isNaN(eval(holdMe))){document.Calulator.screen.value=toEval+"\n         "+"Impossible function\n";}
else {document.Calulator.answer.value=eval(holdMe);}}
else {
for(var ebb in matrixStorage){while (holdMe.indexOf(ebb)>-1) {var pos=holdMe.indexOf(ebb);var holdMe=""+holdMe.substring(0, pos)+""+reqMat(ebb)+""+holdMe.substring((pos + ebb.length), holdMe.length);}}
document.Calulator.answer.value=holdMe;

if (holdMe.indexOf("[") > -1 && holdMe.indexOf(";") > -1) {
holdMe = holdMe.replace(/\;/g, "]\n[");
holdMe = holdMe.replace(/\,/g, "\t");
holdMe = holdMe.replace(/\n\[]$/g, "");
document.Calulator.screen.value=toEval+"\n         \n"+holdMe+"\n";
} else {document.Calulator.screen.value=toEval+"\n         "+holdMe+"\n";}

}
}



// TAKE CARE OF NESTED PARENTHESIS //
function parens(cutMe) {
if (cutMe.match(/([^A-Za-z]|^)\(([0-9\*\+\-\/\.]+)\)/ig)) {
var saveMe = 0;
while (cutMe.match(/([^A-Za-z]|^)\(([0-9\*\+\-\/\.]+)\)/ig)) {
if (saveMe > 100) {alert("ERROR: Overflow");break;}
tmpSto = cutMe.match(/([^A-Za-z]|^)\(([0-9\*\+\-\/\.]+)\)/ig);
if (tmpSto.length >= 1) {var cutMe2 = tmpSto[0];}else {var cutMe2 = tmpSto;}
cutMe2 = cutMe2.replace(/^./, '');
while (cutMe.indexOf(cutMe2)>-1) {var pos=cutMe.indexOf(cutMe2);var cutMe=""+cutMe.substring(0, pos)+"XXYY"+cutMe.substring((pos + cutMe2.length), cutMe.length);}
var ecksX = kernel(cutMe2);
var temp = new Array();
tmp = ecksX.split(':');
ecksX = tmp[0];
cutMe = cutMe.replace(/XXYY/g, ecksX);
saveMe++;}}
return cutMe;}
///


function kernel(holdMe) {

if (holdMe.match(/([A-Za-z]+)\(([0-9A-Za-z\,\[\]\*\+\-\/\.\=\!\>\< \s\^\;\(\)]+)\)/gi)) {var exempt = 0;
var saveMe = 0;
while (holdMe.match(/([A-Za-z]+)\(([0-9A-Za-z\,\[\]\*\+\-\/\.\=\!\>\< \s\^\;\(\)]+)\)/gi)) {
if (saveMe > 100) {alert("ERROR: Overflow");break;}

holdMe=parens(holdMe);

tmpSto = holdMe.match(/([A-Za-z]+)\(([0-9A-Za-z\,\[\]\*\+\-\/\.\=\!\>\< \s\^\;]+)\)/gi);

///////alert(tmpSto);

if (tmpSto.length >= 1) {var holdMe2 = tmpSto[0];}else {var holdMe2 = tmpSto;}
while (holdMe.indexOf(holdMe2)>-1) {var pos=holdMe.indexOf(holdMe2);var holdMe=""+holdMe.substring(0, pos)+"AABB"+holdMe.substring((pos + holdMe2.length), holdMe.length);}

///////alert(holdMe2+"    "+holdMe);

var tipi = holdMe2;
var sheesh = new Array();
sheesh = tipi.split('(');
sheesh[1] = sheesh[1].replace(/\)/, "");


if (sheesh[1].indexOf(",") == -1 && sheesh[1].indexOf("[") == -1 && (!sheesh[1].match(/L([0-9]+)/)) && sheesh[1].indexOf("^") == -1 && sheesh[1].indexOf(" ") == -1) {sheesh[1] = eval(sheesh[1]);}


// CHECK FOR TRIG ERRORS //
if (sheesh[0] == "tan") {
if (document.Calulator.type[1].checked == true) {
if (sheesh[1] == 90 || sheesh[1] == 270 || sheesh[1] == 450 || sheesh[1] == 630 || sheesh[1] == "-90" || sheesh[1] == "-270" || sheesh[1] == "-450" || sheesh[1] == "-630"){document.Calulator.screen.value=toEval+"\n         Invalid tangent input.\n";return;} 
else if (sheesh[1] == 180 || sheesh[1] == 360 || sheesh[1] == 540 || sheesh[1] == 720){holdMe2 = "0";} 
else if (sheesh[1] == 45 || sheesh[1] == 225 || sheesh[1] == "-315" || sheesh[1] == "-135"){holdMe2 = 1;} 
else if (sheesh[1] == "-45" || sheesh[1] == 315 || sheesh[1] == 135 || sheesh[1] == "-225"){holdMe2 = "-1";} else{}}
else {
if (sheesh[1] == "1.5707963267948965" || sheesh[1] == "4.71238898038469" || sheesh[1] == "7.853981633974483" || sheesh[1] == "10.995574287564276" || sheesh[1] == "-1.5707963267948965" || sheesh[1] == "-4.71238898038469" || sheesh[1] == "-7.853981633974483" || sheesh[1] == "-10.995574287564276"){document.Calulator.screen.value=toEval+"\n         Invalid tangent input.\n";return;} 
else if (sheesh[1] == "3.141592653589793" || sheesh[1] == "6.283185307179586" || sheesh[1] == "9.42477796076938" || sheesh[1] == "12.566370614359172"){holdMe2 = "0";} 
else if (sheesh[1] == "0.7853981633974483" || sheesh[1] == "3.9269908169872414"){holdMe2 = 1;} 
else if (sheesh[1] == "-0.7853981633974483" || sheesh[1] == "2.356194490192345" || sheesh[1] == "5.497787143782138"){holdMe2 = "-1";} else{}}
}
else if (sheesh[0] == "sin") {
if (document.Calulator.type[1].checked == true) {if (sheesh[1] == 180 || sheesh[1] == 360 || sheesh[1] == 540 || sheesh[1] == 720 || sheesh[1] == "-180" || sheesh[1] == "-360" || sheesh[1] == "-540" || sheesh[1] == "-720"){holdMe2 = 0;} else{}}
else {if (sheesh[1] == "3.141592653589793" || sheesh[1] == "6.283185307179586" || sheesh[1] == "9.42477796076938" || sheesh[1] == "12.566370614359172" || sheesh[1] == "-3.141592653589793" || sheesh[1] == "-6.283185307179586" || sheesh[1] == "-9.42477796076938" || sheesh[1] == "-12.566370614359172"){holdMe2 = 0;} else{}}
}
else if (sheesh[0] == "cos") {
if (document.Calulator.type[1].checked == true) {if (sheesh[1] == 90 || sheesh[1] == 270 || sheesh[1] == 450 || sheesh[1] == 630 || sheesh[1] == "-90" || sheesh[1] == "-270" || sheesh[1] == "-450" || sheesh[1] == "-630"){holdMe2 = 0;} else{}}
else {if (sheesh[1] == "1.5707963267948965" || sheesh[1] == "4.71238898038469" || sheesh[1] == "7.853981633974483" || sheesh[1] == "10.995574287564276" || sheesh[1] == "-1.5707963267948965" || sheesh[1] == "-4.71238898038469" || sheesh[1] == "-7.853981633974483" || sheesh[1] == "-10.995574287564276"){holdMe2 = 0;} else{}}
}
else {}
///


// USER FUCTIONS //
var nmA = "";var eqt = "";
for (var e=1; e <= 5; e++) {var tmp="func"+e+"";
if (document.Calulator[tmp].value != null && document.Calulator[tmp].value != '') {
tmpSto = document.Calulator[tmp].value;
myArray = tmpSto.split("=");
myArray[0] = myArray[0].replace(/\(x\)/g, "");
var name = myArray[0];
if (sheesh[0] == name) {nmA=name;eqt=myArray[1];}}}
if (nmA != "") {
eqt=deFuncToJscript(eqt);
eqt = eqt.replace(/x/gi, sheesh[1]);
holdMe2=eval(eqt);}
///


// MATRICIES / LISTS //
if (sheesh[0] == "add") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var first = doubleArr[0];var secnd = doubleArr[1];
if (sheesh[1].indexOf(";") > -1) {
var doubleArr2 = sheesh[1].split("],[");
doubleArr2[0] = doubleArr2[0]+"]";
doubleArr2[1] = "["+doubleArr2[0];
var joint = doubleArr2[0]+"C"+doubleArr2[1];
holdMe2=matrixAdd(joint,"+","A");}//giveBack
else if (first.match(/\[[A-Z]\]/) || secnd.match(/\[[A-Z]\]/)) {var joint = first+"C"+secnd;
holdMe2=matrixAdd(joint,"+","A");}//giveBack
else if (first.match(/\[[0-9]+\]/) || secnd.match(/\[[0-9]+\]/)) {
first=first.replace(/\[/g,"");first=first.replace(/\]/g,"");
secnd=secnd.replace(/\[/g,"");secnd=secnd.replace(/\]/g,"");first="L"+first;secnd="L"+secnd;
holdMe2=listCmb(first,secnd,"add");}
else {var sum = 0;for (var x=0;x<doubleArr.length;x++) {sum = eval(sum+doubleArr[x]*1);}holdMe2=eval(sum*1);}}

if (sheesh[0] == "div") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var first = doubleArr[0];var secnd = doubleArr[1];
if (sheesh[1].indexOf(";") > -1) {
var doubleArr2 = sheesh[1].split("],[");
doubleArr2[0] = doubleArr2[0]+"]";
doubleArr2[1] = "["+doubleArr2[0];
var joint = doubleArr2[0]+"C"+doubleArr2[1];
holdMe2=matrixDiv(joint,"A");}//giveBack
else if (first.match(/\[[A-Z]\]/)) {var joint = first+"C"+secnd;
holdMe2=matrixDiv(joint,"A");}//giveBack
else if (first.match(/\[[0-9]+\]/) || secnd.match(/\[[0-9]+\]/)) {
first=first.replace(/\[/g,"");first=first.replace(/\]/g,"");
secnd=secnd.replace(/\[/g,"");secnd=secnd.replace(/\]/g,"");first="L"+first;secnd="L"+secnd;
holdMe2=listCmb(first,secnd,"div");}
else {var sum = doubleArr[0];for (var x=1;x<doubleArr.length;x++) {sum = eval(sum/doubleArr[x]*1);}holdMe2=eval(sum*1);}}

if (sheesh[0] == "sub") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var first = doubleArr[0];var secnd = doubleArr[1];
if (sheesh[1].indexOf(";") > -1) {
var doubleArr2 = sheesh[1].split("],[");
doubleArr2[0] = doubleArr2[0]+"]";
doubleArr2[1] = "["+doubleArr2[0];
var joint = doubleArr2[0]+"C"+doubleArr2[1];
holdMe2=matrixAdd(joint,"-","A");}//giveBack
else if (first.match(/\[[A-Z]\]/) || secnd.match(/\[[A-Z]\]/)) {var joint = first+"C"+secnd;
holdMe2=matrixAdd(joint,"-","A");}//giveBack
else if (first.match(/\[[0-9]+\]/) || secnd.match(/\[[0-9]+\]/)) {
first=first.replace(/\[/g,"");first=first.replace(/\]/g,"");
secnd=secnd.replace(/\[/g,"");secnd=secnd.replace(/\]/g,"");first="L"+first;secnd="L"+secnd;
holdMe2=listCmb(first,secnd,"sub");}
else {var sum = doubleArr[0];for (var x=1;x<doubleArr.length;x++) {sum = eval(sum-doubleArr[x]*1);}holdMe2=eval(sum*1);}}

if (sheesh[0] == "mult") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var first = doubleArr[0];var secnd = doubleArr[1];
if (sheesh[1].indexOf(";") > -1) {
var doubleArr2 = sheesh[1].split("],[");
doubleArr2[0] = doubleArr2[0]+"]";
doubleArr2[1] = "["+doubleArr2[1];
var joint = doubleArr2[0]+"C"+doubleArr2[1];
holdMe2=matrixMult(joint,"A");}//giveBack
else if (first.match(/\[[A-Z]\]/) || secnd.match(/\[[A-Z]\]/)) {var joint = first+"C"+secnd;
holdMe2=matrixMult(joint,"A");}//giveBack
else if (first.match(/\[[0-9]+\]/) || secnd.match(/\[[0-9]+\]/)) {
first=first.replace(/\[/g,"");first=first.replace(/\]/g,"");
secnd=secnd.replace(/\[/g,"");secnd=secnd.replace(/\]/g,"");first="L"+first;secnd="L"+secnd;
holdMe2=listCmb(first,secnd,"mult");}
else {var sum = doubleArr[0];for (var x=1;x<doubleArr.length;x++) {sum = eval(sum*doubleArr[x]*1);}holdMe2=eval(sum*1);}}

if (sheesh[0] == "tpose") {
holdMe2=matrixTrans(sheesh[1],"A");}//giveBack
/// || first.match(/\[(\-)?[0-9]+(\,|\;)(\-)?[0-9]+/) || secnd.match(/\[[A-Z]\]/) || secnd.match(/\[(\-)?[0-9]+(\,|\;)(\-)?[0-9]+/)

if (sheesh[0] == "det") {holdMe2=getDet(sheesh[1]);}

if (sheesh[0] == "inv") {holdMe2=getInv(sheesh[1],"A");}//giveBack


// BASE CONVERSIONS //
var newNum="";
if (sheesh[0] == 'decBin') {holdMe2 = sheesh[1].toString(2);}
else if (sheesh[0] == 'decOct') {holdMe2 = sheesh[1].toString(8);}
else if (sheesh[0] == 'decHex') {holdMe2 = ("0x" +  sheesh[1].toString(16));}
else if (sheesh[0] == 'binDec') {holdMe2 = parseInt(sheesh[1], 2);}
else if (sheesh[0] == 'octDec') {holdMe2 = parseInt(sheesh[1], 8);}
else if (sheesh[0] == 'hexDec') {holdMe2 = parseInt(sheesh[1], 16);}else{}
///



// REVPOL NOTATION //
if (sheesh[0] == "revPol") {sheesh[1]=""+sheesh[1]+"";holdMe2 = revPol(sheesh[1]);}
///


// RVAL //
if (sheesh[0] == "rVal") {var list = new Array();list = sheesh[1].split(',');sheesh[1]=""+sheesh[1]+"";holdMe2 = twoVarExec(list[0],list[1]);}
///


// PERCENTILE //
if (sheesh[0] == "percentile") {var list = new Array();list = sheesh[1].split(',');if (isNaN(list[0])) {list[2]=list[1];list[1]='';}sheesh[1]=""+sheesh[1]+"";holdMe2 = percentiles(list[0],list[1],list[2]);}
///



// ATOMWT //
if (sheesh[0] == "atomWt") {
var temp = "";
temp = sheesh[1];
temp=Math.floor(temp);
if (temp > 109 || temp < 1) {temp = 1;}
holdMe2=atomicWeightTable[temp];
}
///




// MKMATRIX //
if (sheesh[0] == "mkmatrix") {sheesh[1]=""+sheesh[1]+"";
var doubleArr = new Array();
doubleArr = sheesh[1].split(',');
var listname = doubleArr.shift();
var a;var temp = "";
temp = doubleArr.join(',');
if (listname.match(/\[([A-Za-z]+)\]/)) {
listname=listname.replace(/\]/g,"");listname=listname.replace(/\[/g,"");
if (temp.indexOf(";") > -1) {matrixStorage[listname]=temp;}
else {temp=reqMat(one);matrixStorage[listname]=temp;}}
holdMe2=temp;
}
///



// MKLIST //
if (sheesh[0] == "mklist") {sheesh[1]=""+sheesh[1]+"";
var doubleArr = new Array();
doubleArr = sheesh[1].split(',');
var listname = doubleArr.shift();

if (doubleArr.length == 1 && isNaN(doubleArr[0])) {
var myArray = new Array();
var a;var temp = "";
var whichList=doubleArr[0];

if (whichList.match(/L([0-9]+)/)) {
myArray = reqList(whichList,1);
temp = myArray.join(',');
listStorage[listname]=temp;}
} else {
var myArray = new Array();
var a;var temp = "";
var temp=doubleArr.join(',');;
if (listname.match(/L([0-9]+)/)) {listStorage[listname]=temp;}
}

holdMe2=temp;
}
///



// RANDINT //
if (sheesh[0] == "randInt") {sheesh[1]=""+sheesh[1]+"";
var doubleArr = new Array();
doubleArr = sheesh[1].split(',');
var lowest = eval(doubleArr[0]*1);
var highest = eval(doubleArr[1]*1);
var number = eval(doubleArr[2]*1);
if (number == undefined || number == "") {number=1;}
if (number >= 500) {number=500;}
var i=number;holdMe2="";
while (i>0) {
var add = Math.floor(Math.random() * (1 + highest - lowest) + lowest);
if (i==1){holdMe2=holdMe2+""+add+"";}
else {holdMe2=holdMe2+""+add+",";}
i--;}}
///


// RAND GAUSS //
if (sheesh[0] == "randNorm") {sheesh[1]=""+sheesh[1]+"";
var doubleArr = new Array();var u1,u2;
doubleArr = sheesh[1].split(',');
var mean = eval(doubleArr[0]*1);
var stdev = eval(doubleArr[1]*1);
var number = eval(doubleArr[2]*1);
if (number == undefined || number == "") {number=1;}
if (number >= 500) {number=500;}
var i=number;holdMe2="";
while (i>0) {u1 = u2 = 0.0;while (u1 * u2 == 0.0) {u1 = Math.random();u2 = Math.random();}
var ecks = Math.sqrt(-2.0 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
var add = stdev * ecks + 1.0 * mean;
if (i==1){holdMe2=holdMe2+""+add+"";}
else {holdMe2=holdMe2+""+add+",";}
i--;}}
///


// ROUND //
if (sheesh[0] == "round") {
var doubleArr = new Array();var pr = 0;sheesh[1]=""+sheesh[1]+"";
if (sheesh[1].indexOf(",") != -1) {doubleArr = sheesh[1].split(',');var number = eval(doubleArr[0]*1);pr = eval(doubleArr[1]*1);}
else {var number=eval(sheesh[1]*1);}
if (pr == 0 || pr == "") {holdMe2 = Math.round(number);}
else if (pr == 1) {holdMe2 = Math.round(number*10)/10;}
else if (pr == 2) {holdMe2 = Math.round(number*100)/100;}
else if (pr == 3) {holdMe2 = Math.round(number*1000)/1000;}
else if (pr == 4) {holdMe2 = Math.round(number*10000)/10000;}
else if (pr == 5) {holdMe2 = Math.round(number*100000)/100000;}
else {holdMe2 = Math.round(number);}}
///


// AVERAGE //
if (sheesh[0] == "avg") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
if (sheesh[1].indexOf("[") != -1) {sheesh[1] = sheesh[1].replace(/\[/, "");sheesh[1] = sheesh[1].replace(/\]/, "");}
if (sheesh[1].indexOf(",") != -1) {var doubleArr = sheesh[1].split(",");}
else {var doubleArr = reqList(sheesh[1]);}
var sum = 0;for (var i=0; i<doubleArr.length; i++) {sum = eval(sum + eval(doubleArr[i]*1));}
var holdMe2 = eval(sum / doubleArr.length);}
///


// IS PRIME //
if (sheesh[0] == "isPrime") {var holdMe2 = 1;
if (sheesh[1] != 1 && sheesh[1] != 2) {
for (var i=2;i<sheesh[1];i++) {if (sheesh[1] % i == 0) {holdMe2 = 0;}}}}
///


// POWER //
if (sheesh[0] == "pow") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var base = doubleArr[0];var expo = doubleArr[1];
var holdMe2 = eval(Math.pow(base,expo));}
///


// TEST //
if (sheesh[0] == "test") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var cmp = doubleArr[0];
var part1 = eval(doubleArr[1])*1;
var part2 = eval(doubleArr[2])*1;
if (cmp == "=") {var holdMe2 = (part1 == part2?1:0);}
else if (cmp == "!=") {var holdMe2 = (part1 != part2?1:0);}
else if (cmp == ">") {var holdMe2 = (part1 > part2?1:0);}
else if (cmp == ">=") {var holdMe2 = (part1 >= part2?1:0);}
else if (cmp == "<") {var holdMe2 = (part1 < part2?1:0);}
else if (cmp == "<=") {var holdMe2 = (part1 <= part2?1:0);}
else {var holdMe2 = -1;}}
///


// MODULUS //
if (sheesh[0] == "modulus") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var numer = doubleArr[0];var denom = doubleArr[1];
numer = parseInt(numer);
denom = parseInt(denom);
var holdMe2 = eval(numer % denom);}
///


// GIMME PRIMES //
if (sheesh[0] == "getPrimes") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var min = doubleArr[0];var max = doubleArr[1];
var holdMe2 = "";
min = parseInt(min);
max = parseInt(max);
var a = min;
var b = 1;
while (a >= min && a <= max) {
var returned = 1;
if (a != 1 && a != 2) {
for (var i=2;i<a;i++) {if (a % i == 0) {returned = 0;}}}
if (returned == 1) {
if (b==1){holdMe2=holdMe2+""+a+"";}
else {holdMe2=holdMe2+","+a+"";}b++;}a++;}
if (holdMe2 == "") {holdMe2="-1";}
holdMe2=holdMe2+"";}
///



// GIMME FACTORS //
if (sheesh[0] == "getFactors") {
var holdMe2 = "";
myNum = parseInt(sheesh[1]);
if (myNum > 1000000) {holdMe2 = -1;}
else {holdMe2 = getFactorsFunc(myNum);}
holdMe2=holdMe2+"";}
///



// ABS //
if (sheesh[0] == "abs") {holdMe2 = Math.abs(sheesh[1]);}
///


// nPr //
if (sheesh[0] == "nPr") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var nVal = doubleArr[0];var rVal = doubleArr[1];
var nMr = eval(nVal-rVal);
holdMe2 = eval( calcFact(nVal) / calcFact(nMr) );}
///


// nCr //
if (sheesh[0] == "nCr") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var nVal = doubleArr[0];var rVal = doubleArr[1];
var nMr = eval(nVal-rVal);
holdMe2 = eval(calcFact(nVal)/(calcFact(nMr)*calcFact(rVal)));}
///


// INT //
if (sheesh[0] == "int") {sheesh[1]=""+sheesh[1]+"";var doubleArr = sheesh[1].split(".");holdMe2 = eval(doubleArr[0]);}
///


// FACTORIAL //
if (sheesh[0] == "fact") {holdMe2 = calcFact(sheesh[1]);}
///


// GCD //
if (sheesh[0] == "gcd") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var first = eval(doubleArr[0]*1);
var second = eval(doubleArr[1]*1);
var saveFirst = first;
var saveSecond = second;var de;
while (second != 0) {de = first % second;first = second;second = de;}
holdMe2=first;}
///


// LCM //
if (sheesh[0] == "lcm") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var first = eval(doubleArr[0]*1);
var second = eval(doubleArr[1]*1);
var saveFirst = first;
var saveSecond = second;
var numbera = ""+first+"C"+second+"";
var GCD = doGCD(numbera,"heyhey");
holdMe2 = eval((first * second) / GCD);}
///


// BINOMPDF //
if (sheesh[0] == "binompdf") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var numtrials = eval(doubleArr[0]*1);
var p = eval(doubleArr[1]*1);
var x = eval(doubleArr[2]*1);
if (x > numtrials)  {x = numtrials;}
holdMe2 = binpdf(p,numtrials,x);
if (holdMe2 > 1) {holdMe2 = 1;}}
///


// BINOMCDF //
if (sheesh[0] == "binomcdf") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var numtrials = eval(doubleArr[0]*1);
var p = eval(doubleArr[1]*1);
var x = eval(doubleArr[2]*1);
if (x > numtrials)  {x = numtrials;}
holdMe2 = bincdf(p,numtrials,x);
if (holdMe2 > 1) {holdMe2 = 1;}}
///


// POISSPDF //
if (sheesh[0] == "poissonpdf") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var mu = eval(doubleArr[0]*1);
var k = eval(doubleArr[1]*1);
holdMe2 = posspdf(mu,k);}
///


// POISSCDF //
if (sheesh[0] == "poissoncdf") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
var doubleArr = sheesh[1].split(",");
var mu = eval(doubleArr[0]*1);
var k = eval(doubleArr[1]*1);
holdMe2 = posscdf(mu,k);}
///


// MAX //
if (sheesh[0] == "max") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
if (sheesh[1].indexOf(",") != -1) {var doubleArr = sheesh[1].split(",");}
else {var doubleArr = reqList(sheesh[1]);}
var evaMe="Math.max(";
for (i=0;i<(doubleArr.length-1);i++) {evaMe+="doubleArr["+i+"],";}
evaMe+="doubleArr["+(doubleArr.length-1)+"]";
evaMe+=");";
holdMe2 = eval(evaMe);}
///


// MIN //
if (sheesh[0] == "min") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
if (sheesh[1].indexOf(",") != -1) {var doubleArr = sheesh[1].split(",");}
else {var doubleArr = reqList(sheesh[1]);}
var evaMe="Math.min(";
for (i=0;i<(doubleArr.length-1);i++) {evaMe+="doubleArr["+i+"],";}
evaMe+="doubleArr["+(doubleArr.length-1)+"]";
evaMe+=");";
holdMe2 = eval(evaMe);}
///


// FLOOR //
if (sheesh[0] == "floor") {holdMe2 = Math.floor(sheesh[1]);}
///


// CEILING //
if (sheesh[0] == "ceil") {holdMe2 = Math.ceil(sheesh[1]);}
///


// TO FRAC //
if (sheesh[0] == "toFrac") {sheesh[1]=""+sheesh[1]+"";exempt=1;
if (sheesh[1].indexOf("/") != -1 && sheesh[1].indexOf(" ") != -1) {
var leftRight = sheesh[1].split(" ");
var whole=leftRight[0]+" ";
var toEval2=leftRight[1];

var topBottom = toEval2.split("/");
var topNum = topBottom[0];
var bottomNum = topBottom[1];
var temp = ""+topNum+"C"+bottomNum+"";
var GCD = doGCD(temp,"heyhey");
var topNow = topNum/GCD;
var bottomNow = bottomNum/GCD;

if (whole != "" && whole != " " && whole != "0 " && whole != "0") {holdMe2=whole+""+topNow+"/"+bottomNow;}
else {holdMe2=""+topNow+"/"+bottomNow;}
}
else if (sheesh[1].indexOf("/") != -1) {
var topBottom = sheesh[1].split("/");
var topNum = topBottom[0];
var bottomNum = topBottom[1];
var temp = ""+topNum+"C"+bottomNum+"";
var GCD = doGCD(temp,"heyhey");
var topNow = topNum/GCD;
var bottomNow = bottomNum/GCD;
holdMe2=""+topNow+"/"+bottomNow;
}
else if (sheesh[1].indexOf(".") != -1) {

var leftRight = sheesh[1].split(".");
var whole=leftRight[0]+" ";
var dec=leftRight[1];
var tenPlace = dec.length;
var bottomNum = eval(Math.pow(10,tenPlace));

if (bottomNum != 5) {
var fractIon = ""+dec+"/"+bottomNum;
var topBottom = fractIon.split("/");
var topNum = topBottom[0];
var bottomNum = topBottom[1];
var temp = ""+topNum+"C"+bottomNum+"";
var GCD = doGCD(temp,"heyhey");
var topNow2 = topNum/GCD;
var bottomNow2 = bottomNum/GCD;
if (whole != "" && whole != " " && whole != "0 " && whole != "0") {holdMe2=whole+""+topNow2+"/"+bottomNow2;}
else {holdMe2=""+topNow2+"/"+bottomNow2;}
}
else {
topNow2 = "ERROR";
holdMe2=""+topNow2;
}

}
else {holdMe2 = sheesh[1]+"/1";}}
///


// TO DEC //
if (sheesh[0] == "toDec") {sheesh[1]=""+sheesh[1]+"";
if (sheesh[1].indexOf("/") != -1 && sheesh[1].indexOf(" ") != -1) {
var leftRight = sheesh[1].split(" ");
var whole=leftRight[0];
var toEval2=leftRight[1];
holdMe2 = eval(toEval2);
holdMe2 = ""+holdMe2+"";
var leftRight2 = holdMe2.split(".");
var leftofDec=leftRight2[0];
var rightofDec=leftRight2[1];
if (leftofDec != 0) {var newie = leftofDec*whole;}
else {var newie = whole;}
holdMe2 = newie+"."+rightofDec;}
else {holdMe2 = eval(sheesh[1]);}}
///


// STD DEV //
if (sheesh[0] == "stDev") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
if (sheesh[1].indexOf("[") != -1) {sheesh[1] = sheesh[1].replace(/\[/, "");sheesh[1] = sheesh[1].replace(/\]/, "");}
if (sheesh[1].indexOf(",") != -1) {var doubleArr = sheesh[1].split(",");}
else {var doubleArr = reqList(sheesh[1]);}
var sum = 0;for (var i=0; i<doubleArr.length; i++) {sum = eval(sum + eval(doubleArr[i]*1));}
var mean = eval(sum / doubleArr.length);
var sum = 0;for (var i=0; i<doubleArr.length; i++) {sum = eval(sum + eval(  Math.pow( ((doubleArr[i]*1) - mean), 2)   ));}
var sSqr = eval(sum / (doubleArr.length - 1));
holdMe2 = eval(Math.sqrt(sSqr));}
///


// Z SCORE TO P VALUE //
if (sheesh[0] == "zToP") {holdMe2 = zToPVal(sheesh[1]);}
///


// P VALUE TO Z SCORE //
if (sheesh[0] == "pToZ") {holdMe2 = pToZSco(sheesh[1]);}
///


// MEDIAN //
if (sheesh[0] == "median") {
var doubleArr = new Array();sheesh[1]=""+sheesh[1]+"";
if (sheesh[1].indexOf("[") != -1) {sheesh[1] = sheesh[1].replace(/\[/, "");sheesh[1] = sheesh[1].replace(/\]/, "");}
if (sheesh[1].indexOf(",") != -1) {var doubleArr = sheesh[1].split(",");}
else {var doubleArr = reqList(sheesh[1]);}
doubleArr = doubleArr.sort(numberSort);
var medcnt = eval((doubleArr.length + 1) / 2);
medcnt = ""+medcnt+"";
var num_pieces = medcnt.split(".");
if (num_pieces.length > 1) {
var oddEven = "even";
medcnt = medcnt*1;
medcnt = Math.floor(medcnt);
holdMe2 = eval((((doubleArr[medcnt - 1]*1) + (doubleArr[medcnt]*1)) / 2));}
else {var oddEven = "odd";holdMe2 = eval(doubleArr[medcnt - 1]*1);}}
///




holdMe2 = ""+holdMe2+"";
holdMe2 = holdMe2.replace(/pow/, "Math.pow");
holdMe2 = holdMe2.replace(/asin/, "Math.ASIN");
holdMe2 = holdMe2.replace(/acos/, "Math.ACOS");
holdMe2 = holdMe2.replace(/atan/, "Math.ATAN");
holdMe2 = holdMe2.replace(/sin/, "Math.sin");
holdMe2 = holdMe2.replace(/cos/, "Math.cos");
holdMe2 = holdMe2.replace(/tan/, "Math.tan");
holdMe2 = holdMe2.replace(/csc/, "1/Math.sin");
holdMe2 = holdMe2.replace(/sec/, "1/Math.cos");
holdMe2 = holdMe2.replace(/cot/, "1/Math.tan");
holdMe2 = holdMe2.replace(/ASIN/, "asin");
holdMe2 = holdMe2.replace(/ACOS/, "acos");
holdMe2 = holdMe2.replace(/ATAN/, "atan");
holdMe2 = holdMe2.replace(/log/, "Math.log");
holdMe2 = holdMe2.replace(/Math\.log\((.*)\)/, "(Math.log($1)/Math.log(10))");
holdMe2 = holdMe2.replace(/ln/, "Math.log");
holdMe2 = holdMe2.replace(/sqrt/, "Math.sqrt");

if (document.Calulator.type[1].checked == true) {
holdMe2 = holdMe2.replace(/sin\(/, "sin((Math.PI/180)*");
holdMe2 = holdMe2.replace(/cos\(/, "cos((Math.PI/180)*");
holdMe2 = holdMe2.replace(/tan\(/, "tan((Math.PI/180)*");}

if (holdMe2.indexOf(",") == -1 && exempt != 1 && holdMe2.indexOf("[") == -1) {holdMe2=eval(holdMe2);}
holdMe = holdMe.replace(/AABB/g, holdMe2);

///////alert(holdMe2+"    "+holdMe);

saveMe++;}}
else {if (holdMe.indexOf(",") == -1 && holdMe.indexOf("[") == -1) {holdMe = holdMe.replace(/([0-9\.]+)\^([0-9]+)/g, "Math.pow($1,$2)");holdMe=eval(holdMe);}holdMe=""+holdMe+"";}

return (""+holdMe+":"+exempt+"");
}




function primeCheckFactor(sheesh) {holdMe2 = 1;for (var i=2;i<sheesh;i++) {if (sheesh % i == 0) {holdMe2 = 0;break;}}return holdMe2;}

function getFactorsFunc(numberTrack) {
	if (numberTrack == 1) {aryFactors = new Array('1');}
	else {
		theirNumber=numberTrack;
		aryFactors = new Array();

		TIMEOUT: for (maxout=1; maxout<=10; maxout++) {

		x=-1;
		while (x<primeAry.length) {x++;
			if (theirNumber < primeAry[x]) {break TIMEOUT;}

			if (Math.round(theirNumber/primeAry[x]) == theirNumber/primeAry[x]) {
				aryFactors.push(primeAry[x]);
				theirNumber = (theirNumber/primeAry[x]);
				x=-1;
			}
		}
		}
		if (theirNumber != 1 && theirNumber <= 1000000  && (!primeCheckFactor(theirNumber))) {aryFactors.push("(" + theirNumber + ")");}
		else if (theirNumber != 1 && theirNumber <= 1000000 && primeCheckFactor(theirNumber)) {aryFactors.push(theirNumber);}
		else {if (theirNumber != 1) {aryFactors.push("(" + theirNumber + ")?");}}
	}
	if (aryFactors.length == 0) {aryFactors.push(numberTrack);}
	return aryFactors.join(',');
}



// REVERSE POLISH NOTATION
function revPol(eq) {
var stack = new Array();
var number = new Array();
var len = eq.length;
var nextChar;var thisChar;
var topStack;var secStack;
if (len == 0) {return "0";}
for (var x = 0; x < len;x++) {
thisChar = eq.charAt(x);
if (thisChar == " ") {continue;}
nextChar = eq.charAt(x+1);
if (nextChar == " " && thisChar != "+" && thisChar != "-" && thisChar != "*" && thisChar != "/" && thisChar != "^" && number.length == 0) {stack.push(thisChar);}
else if (thisChar == "+" || thisChar == "-" || thisChar == "*" || thisChar == "/"  || thisChar == "^") {
if (stack.length < 2) {alert("NO STACK");break;}
secStack=stack.pop();
topStack=stack.pop();
if (thisChar == "+") {stack.push(eval(topStack*1 + secStack*1));}
else if (thisChar == "-") {stack.push(eval(topStack*1 - secStack*1));}
else if (thisChar == "*") {stack.push(eval(topStack*1 * secStack*1));}
else if (thisChar == "/") {stack.push(eval(topStack*1 / secStack*1));}
else if (thisChar == "^") {stack.push(eval(Math.pow((topStack*1),(secStack*1))));}
else {alert("danger will robinson!");}}
else {number.push(thisChar);if (nextChar == " ") {num = number.join('');num = eval(num);stack.push(num);number = [];}}
} return(stack);}



function listCmb(which,whichEls,what) {
var myArray = new Array();
var myArray2 = new Array();
myArray=reqList(which,'skip');
myArray2=reqList(whichEls,'skip');
var tmpArr = new Array(myArray.length);
if (myArray.length != myArray2.length) {alert("ERROR: Your lists are not of equal size.");}
else {for (var i=0; i<myArray.length; i++) {
if (what == "add") {tmpArr[i] = eval((myArray[i]*1)+(myArray2[i]*1));}
else if (what == "sub") {tmpArr[i] = eval((myArray[i]*1)-(myArray2[i]*1));}
else if (what == "mult") {tmpArr[i] = eval((myArray[i]*1)*(myArray2[i]*1));}
else if (what == "div") {tmpArr[i] = eval((myArray[i]*1)/(myArray2[i]*1));}else {}}
var sum = tmpArr.join(',');
return sum;}}

// REQ FOR BINOM CDF
function bincdf(p,numtrials,x) {
if ((x > numtrials) || (p >= 1))  {return 1;}
else {var  q = 1 - p;
var  n1p = (numtrials+1)*p;
var  t = numtrials * Math.log(q);  // x = 0
var  r = Math.exp(t);var  j = 1;
while (j <= x) {t += Math.log( 1 + (n1p - j) / (j * q) );r += Math.exp(t);j++;}
return  r;}}

// REQ FOR BINOM PDF
function binpdf(p,numtrials,x) {var lncomb;
if ((x == 0) || (x == numtrials))  {lncomb = 0;}
else {if ((x > numtrials) || (x < 0))  {lncomb = -1E38;}
else{lncomb =  (lnFact(numtrials) - lnFact(x) - lnFact(numtrials-x));}}
return Math.exp(lncomb + x * Math.log(p)+ (numtrials-x) * Math.log(1-p));}

// SUB REQ FOR BINOM PDF
function lnFact(x) {
if (x <= 1) {x = 1;}
if (x < 12) {return Math.log(calcFact(x));}
else {var invx = 1 / x;
var invx2 = invx * invx;
var invx3 = invx2 * invx;
var invx5 = invx3 * invx2;
var invx7 = invx5 * invx2;
var sum = ((x + 0.5) * Math.log(x)) - x;
sum += Math.log(2*Math.PI) / 2;
sum += (invx / 12) - (invx3 / 360);
sum += (invx5 / 1260) - (invx7 / 1680);
return sum;}}

// REQ FOR POISS PDF AND CDF
function posspdf(mu,k) {return  Math.exp((k * Math.log(mu)) - mu - lnFact(k));}

// REQ FOR POISS CDF
function posscdf(mu,k) {var  sum = 0.0, j = 0;
while (j <= k) {sum += posspdf( mu, j++ );}
if (sum > 1)  {sum = 1;}return  sum;}


function iAmMaster(chk) {
if (document.Calulator.altSix.value != 'exit') {
document.getElementById('popupOld').width=180;
document.getElementById('popupOld').height=360; //256
swapup();
//document.Calulator.screen.readOnly=false;
document.Calulator.secondBtn.disabled=true;
document.Calulator.altOne.disabled=true;
document.Calulator.altTwo.disabled=true;
document.Calulator.altThree.disabled=true;
document.Calulator.altFour.disabled=true;
document.Calulator.altFive.disabled=true;
document.Calulator.altSix.value='exit';
document.Calulator.altSeven.disabled=true;
document.Calulator.enterMem.disabled=true;
document.Calulator.posneg.value=',';
document.Calulator.screen.value="GAC Expert Architecture v1.0\n\n'*' is required for multiplication!\nDo NOT enter 16=5x+3, enter 16=5*x+3 instead.\n\n                Click to continue\n\n\n         Copyright © 2005 Global Aircraft";
//var ready=setTimeout("readState()",30000);
//if (chk == '' || chk == undefined || chk == null) {top.popup = 
showAllFuncs();
//}
//else {document.Calulator.screen.value=0;}
}
else if (document.Calulator.altSix.value == 'exit') {
document.getElementById('popupOld').width=0;
document.getElementById('popupOld').height=0;
document.getElementById('popupOld').src='';
document.getElementById('graphSTD').width=0;
document.getElementById('graphSTD').height=0;
document.getElementById('graphSTD').src='';
graphController.style.display = "none";
graphOpts.style.display = "none";
//if (chk == '' || chk == undefined || chk == null) {closeDep(top.popup);}else {
//document.Calulator.screen.readOnly=true;
document.Calulator.secondBtn.disabled=false;
document.Calulator.altOne.disabled=false;
document.Calulator.altTwo.disabled=false;
document.Calulator.altThree.disabled=false;
document.Calulator.altFour.disabled=false;
document.Calulator.altFive.disabled=false;
document.Calulator.altSix.value='6';
document.Calulator.altSeven.disabled=false;
document.Calulator.enterMem.disabled=false;
document.Calulator.screen.value="0";
document.Calulator.posneg.value='+/-';
enterPrgms();iWorkNow();
//}
}
else {}


}


// END -->
