<!-- Original:  Mike McGrath (mike_mcgrath@lineone.net) -->
<!-- Web Site:  http://website.lineone.net/~mike_mcgrath/index.htm  -->
var computed = false;
var memory = 0;
var	bin = 0;

function addChar(input, character)
{
	if (computed) reset();
	if (input.value == null || input.value == '0') input.value = character;
	else
	{
	input.value += character;
	computed = false;
	}
}

function reset()
{
	document.f.display.value=0;
	document.f.stack.value=0;
	computed = false;
}

function swipe()
{
	document.f.stack.value=0;
	computed=true;
}

function wipe()
{
	document.f.display.value='';
	computed=false;
}

function newSlate()
{
	reset();
	memory=0;
	bin=0;
}

function deleteChar(input)
{
	input.value = input.value.substring(0, input.value.length - 1);
	computed = false;
}

function changeSign(input)
{
	if(input.value.substring(0, 1) == '-')
	input.value = input.value.substring(1, input.value.length);
  else
  input.value = '-' + input.value;
	computed = false;
}

function testFirst()
{
	var a = (document.f.stack.value.substring(0,1));
	if (a == '-' || a == '.' || a == '0'  || a== '1' || a == '2' || a =='3' || a == '4' || a == '5' || a == '6' || a == '7' || a == '8' || a == '9')
	testLast()
	else
	alert('Error...\n\nEnter Number First!');
	computed = true;
}

function testLast()
{
	var b = (document.f.stack.value.substring(document.f.stack.value.length,document.f.stack.value.length-1))
	if (b == '0' || b == '1' || b == '2' || b =='3' || b == '4' || b == '5' || b == '6' || b == '7' || b == '8' || b == '9')
	goOperation()
	else
	alert('Error...\n\nEntry Incomplete!');
	computed = true;
}

function goOperation()
{
	document.f.display.value=eval(document.f.stack.value) * 100.00 /100.00;
	computed = true;
}

function cos()
{
	document.f.display.value=Math.cos(document.f.display.value);
	swipe();
	computed=true;
}

function acos()
{
	document.f.display.value=Math.acos(document.f.display.value);
	swipe();
	computed=true;
}

function sin()
{
	document.f.display.value=Math.sin(document.f.display.value);
	swipe();
	computed=true;
}

function asin()
{
	document.f.display.value=Math.asin(document.f.display.value);
	swipe();
	computed=true;
}

function tan()
{
	document.f.display.value=Math.tan(document.f.display.value);
	swipe();
	computed=true;
}

function atan()
{
	document.f.display.value=Math.atan(document.f.display.value);
	swipe();
	computed=true;
}

function log()
{
	document.f.display.value=Math.log(document.f.display.value);
	swipe();
	computed=true;
}

function exp()
{
	document.f.display.value=Math.exp(document.f.display.value);	
	swipe();
	computed=true;
}

function sqrt()
{
	document.f.display.value=Math.sqrt(document.f.display.value);
	swipe();
	computed=true;
}

function abs()
{
	document.f.display.value=Math.abs(document.f.display.value);
	swipe();
	computed=true;
}

function square()
{
	document.f.display.value=Math.pow((document.f.display.value), 2);
	swipe();
	computed=true;
}

function cube()
{
	document.f.display.value=Math.pow((document.f.display.value), 3);
	swipe();
	computed=true;
}

function perCent()
{
	addChar(document.f.stack,'/100');
	wipe();
	computed=false;
}

function round()
{
	document.f.display.value=Math.round(document.f.display.value);
	swipe(this.form);
	computed=true;
}

random.m=714025; random.a=4096; random.c=150889;
random.seed= (new Date()).getTime()%random.m;

function random()
{
	random.seed = (random.seed*random.a + random.c) % random.m;
	mikesnum=(random.seed/random.m);
	computed=true;
}

function mem(c)
{
	if (c == 1)
	{
		memory =(document.f.display.value * 1);
		document.f.display.value='';
		swipe(this.form);
		computed = false;
	}
	
	if (c == -1)
	{
		document.f.display.value = memory ;
		document.f.stack.value = document.f.display.value;
		computed = false;
	}
	
	if (c == 0)
	{
		document.f.display.value = 0;
		document.f.stack.value=0; memory = 0;
		computed = false;
	}
	
	if (c == 2)
	{
		bin = (document.f.display.value * 1);
		document.f.display.value='';
		swipe(this.form);
		computed = false;
	}
	
	if (c == -2)
	{
		document.f.display.value = bin ;
		document.f.stack.value = document.f.display.value; bin = 0;
		computed = false;
	}
	
	if (c == 3)
	{
		document.f.display.value = 0; 	
		document.f.stack.value=0;
		bin = 0;
		computed = false;
	}
}	

function onlyTwo()
{
	document.f.display.value=(document.f.display.value * 100);
	document.f.display.value=Math.round(document.f.display.value)/100;
	swipe();
	computed=true;
}

function helpFile()
{
  var content="KEY     FEATURES\n\n"+
              "< - >     Rounds up or down to nearest integer\n"+
              "<00>    Rounds up or down to 2 decimal places\n"+
              "Num     Generates psuedo-random non-cryptograhic number\n"+
              "M+        Adds single entry only to memory bin no.1\n"+
              "MR       Recalls stored single item from memory bin no.1\n"+
              "MC       Clears item from memory bin no.1\n"+
              "M2+      Adds single entry only to memory bin no.2\n"+
              "M2R     Recalls single item from memory bin no.2\n"+
              "M2C     Clears item from memory bin no.2\n"+
              "C          Clears all, except memory no.1 and memory no.2\n"+
              "Clear    Resets all features to zero\n"+
              "+-         Inverts value positive/negative of current display value       \n"+
              "<-         Deletes last digit of current display\n"+
              "X2        Returns value of current display to power 2\n"+
              "X3        Returns value of current display to power 3\n"+
              "%          Divides entry by 100 to return per centage\n"+
              "Sqrt      Returns the square root of display value\n\n"+
              "E1/2 Pi Ln2 Ln10    Return Mathematic constants\n\n"+
              "Log Abs Atan Tan\n"+
              "Acos Cos Asin Sin   Return Math calculation of display value:"
              
  alert(content);
}



