
// Online Calculator, Copyright 2002 George J. Paulos

var x=""
var memory="0"
var out=""
var power="0"



function check(x) {
if (x == ''){
out="0"
return out
}
else {
switch (x.charAt(x.length - 1)) {
 		case "+" :
 		out= x.substring(0,x.length-1)
 		break
 		case "-" :
 		out= x.substring(0,x.length-1)
 		break
 		case "*" :
 		out= x.substring(0,x.length-1)
 		break
 		case "/" :
 		out= x.substring(0,x.length-1)
 		break
 		default :
 		out=x
 	 }
 }
if (out == "0") return out
if (out.substring(0,1) == "0") out = out.substring(1,out.length)
return out
}

function doit(x) {
x=check(x)
if (x.substring(0,1) == "^") out = Pwr(power,x.substring(1,x.length));
else out = eval(x);
x="";
return out
}

function Pi(x) {
 if (x == '') {
	out=Math.PI
	}
 else {
	switch (x.charAt(x.length - 1)) {
 		case "+" :
 		out= x + Math.PI
 		break
 		case "-" :
 		out= x + Math.PI
 		break
 		case "*" :
 		out= x + Math.PI
 		break
 		case "/" :
 		out= x + Math.PI
 		break
 		case "^" :
 		out= x + Math.PI
 		break
 		case "(" :
 		out= x + Math.PI
 		break
 		default :
 		out=Math.PI
 	 }
 }
return out
}

function Euler(x) {
 if (x == '') {
	out=Math.E
	}
 else {
	switch (x.charAt(x.length - 1)) {
 		case "+" :
 		out= x + Math.E
 		break
 		case "-" :
 		out= x + Math.E
 		break
 		case "*" :
 		out= x + Math.E
 		break
 		case "/" :
 		out= x + Math.E
 		break
 		case "^" :
 		out= x + Math.E
 		break
 		case "(" :
 		out= x + Math.E
 		break
 		default :
 		out=Math.E
 	 }
 }	
return out
}

function Golden(x) {
 if (x == '') {
	out="1.6180339887498948"
	}
 else {
	switch (x.charAt(x.length - 1)) {
 		case "+" :
 		out= x + "1.6180339887498948"
 		break
 		case "-" :
 		out= x + "1.6180339887498948"
 		break
 		case "*" :
 		out= x + "1.6180339887498948"
 		break
 		case "/" :
 		out= x + "1.6180339887498948"
 		break
 		case "^" :
 		out= x + "1.6180339887498948"
 		break
 		case "(" :
 		out= x + "1.6180339887498948"
 		break 		
 		default :
 		out= "1.6180339887498948"
 	 }
 }	
return out
}

function Pct(x) {
x=check(x)
if (x == '');
else out = eval(x)/100;
x="";
return out
}

function Exp(x) {
x=check(x)
if (x == '');
else out = Math.exp(x);
x="";
return out
}

function Inv(x) {
x=check(x)
if (x == '');
else out = 1/eval(x);
x="";
return out
}

function Cos(x) {
x=check(x)
if (x == '');
else out = Math.cos(x);
x="";
return out
}

function Sin(x) {
x=check(x)
if (x == '');
else out = Math.sin(x);
x="";
return out
}

function Ln(x) {
x=check(x)
if (x == '');
else out = Math.log(x);
x="";
return out
}

function Root(x) {
x=check(x)
if (x == '');
else out = Math.sqrt(x);
x="";
return out
}

function Tan(x) {
x=check(x)
if (x == '');
else out = Math.tan(x);
x="";
return out
}

function Icos(x) {
x=check(x)
if (x == '');
else out = Math.acos(x);
x="";
return out
}

function Isin(x) {
x=check(x)
if (x == '');
else out = Math.asin(x);
x="";
return out
}

function Itan(x) {
x=check(x)
if (x == '');
else out = Math.atan(x);
x="";
return out
}

function Round(x) {
x=check(x)
if (x == '');
else out = Math.round(x);
x="";
return out
}

function Ran(x) {
x=check(x)
if (x == '');
else out = Math.random(x);
x="";
return out
}

function Flr(x) {
x=check(x)
if (x == '');
else out = Math.floor(x);
x="";
return out
}

function Neg(x) {
x=check(x)
if (x == '');
else out = parseFloat(x) * -1;
x="";
return out
}

function xy(x) {
power = doit(x)
out = "^"
return out
}

function Pwr(x,y) {
if (x == '');
else out = Math.pow(x,y);
x="";
return out
}

function Store(x) {
x=check(x)
memory=eval(x);
}

function Recall (x) {
 if (x == '') {
	out=memory
	}
 else {
	switch (x.charAt(x.length - 1)) {
 		case "+" :
 		out= x + memory
 		break
 		case "-" :
 		out= x + memory
 		break
 		case "*" :
 		out= x + memory
 		break
 		case "/" :
 		out= x + memory
 		break
 		default :
 		out=memory
 	 }
 }
return out
}

function clr() {
out = "0"
return out
}

function numb(x,y) {
if (x=="0") {
out = y
}
else {
out = x + y
}
return out
}

function fclr() {
document.form.num.value = ""
document.form.rate.value = ""
document.form.pv.value = ""
document.form.fv.value = ""
document.form.pmt.value = ""
}

function number(a,b,c,d,e) {
a=0
b=doit(b)/100
c=doit(c)
d=doit(d)
e=doit(e)
nh=1000
nl=1
pp=document.form.period.value
	for (k=1; k<=100;k++) {
	a=(nh+nl)/2
	t1=(e*(1-1/Math.pow(1+b/pp,pp*a))/(b/pp))+d*(1/Math.pow(1+(b/pp),pp*a))-c
	if (t1 > 0) {
	nh=(nh+nl)/2
	}
	else {
	nl=(nh+nl)/2
	}
 }
out = Math.round(a*100)/100
if (out == 1000) out = 0
return out
}

function irate(a,b,c,d,e) { 
a=doit(a)
b=0
c=doit(c)
d=doit(d)
e=doit(e)
nh=1
nl=0
pp=document.form.period.value
	for (k=1; k<=100;k++) {
	b=(nh+nl)/2
	t1=(e*(1-1/Math.pow(1+b/pp,pp*a))/(b/pp))+d*(1/Math.pow(1+(b/pp),pp*a))-c
	if (t1 < 0) {
	nh=(nh+nl)/2
	}
	else {
	nl=(nh+nl)/2
	}
 }
out = Math.round(b*100000)/1000
return out
}

function pvalue(a,b,c,d,e){
a=doit(a)
b=doit(b)/100
c=doit(c)
d=doit(d)
e=doit(e)
pp=document.form.period.value
out=(e*(1-1/Math.pow(1+b/pp,pp*a))/(b/pp))+d*(1/Math.pow(1+(b/pp),pp*a))
out=Math.round(out*100)/100
return out
}

function fvalue(a,b,c,d,e){
a=doit(a)
b=doit(b)/100
c=doit(c)
d=doit(d)
e=doit(e)
pp=document.form.period.value
out=(c-(e*(1-1/Math.pow(1+b/pp,pp*a))/(b/pp)))/(1/Math.pow(1+(b/pp),pp*a))
out=Math.round(out*100)/100
return out 
}

function payment(a,b,c,d,e) {
a=doit(a)
b=doit(b)/100
c=doit(c)
d=doit(d)
e=doit(e)
pp=document.form.period.value
out=(c-d*(1/Math.pow(1+(b/pp),pp*a)))/((1-1/Math.pow(1+b/pp,pp*a))/(b/pp))
out=Math.round(out*100)/100
return out
}

function ex(x,y) {
x=doit(x)
switch (y.charAt(y.length - 1)) {
 		case "+" :
 		out= y + x
 		break
 		case "-" :
 		out= y + x
 		break
 		case "*" :
 		out= y + x
 		break
 		case "/" :
 		out= y + x
 		break
 		case "^" :
 		out= y + x
 		break
 		case "(" :
 		out= y + x
 		break
 		default :
 		out=x
 	 }
return out
}
//  End -->
