<!--
/*
http://www.vertex42.com/Calculators/scripts/simpleinterest.js

Copyright (c) 2008 Vertex42, LLC. All Rights Reserved.
This script is also used for the Simple Interest Calculator Google gadget, created by Vertex42.com, hosted on CalcNexus.com

isBlank function from: http://www.mattkruse.com/javascript/validations/source.html

Except for the isBlank function, which you can get from the above site, you may not copy or use this code anywhere for any reason. It took me time to create it and it wouldn't be fair if you just copied it.

*/
//-->

//You Need a Javascript Enabled Browser// <script> 
<!-- Hide Script from Old Browsers

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null) { return true; }
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	}
	return true;
}
	
function isNum(x){
	/* Tests for Numeric, and does not fail on blank */
	filter = /(^\d+\.?$)|(^\d*\.\d+$)/
	if (filter.test(x)) {return true;}
	return false;
}

//Remove the $ sign if you wish the parse number to NOT include it
function tocurrency(passedVal){
	var prefix = "";
	var wd = "w";
	var tempnum = passedVal.toString();
	for (i=0; i < tempnum.length; i++){
		if (tempnum.charAt(i)=="."){
			var wd = "d";
			break;
		}
	}
	if (wd=="w") {
		return prefix+tempnum+".00";
	}
	else{
		if (tempnum.charAt(tempnum.length-2)=="."){
			return prefix+tempnum+"0";
		}
		else{
			tempnum = Math.round(tempnum*100)/100;
			return prefix+tempnum;
		}
	}
}

function clear_results(form) {
	form.I.value = "";
}

function si_calc(form) {
// Validate the P field
	if (!isNum(form.P.value)) { 
		alert("Enter a valid Principal amount (P).");
		form.P.focus();
		return false;
	}
// Validate the r field which is a %
	if (!isNum(form.r.value)) {
		alert("Enter a valid Annual Interest Rate (enter 6 for 6%).");
		form.r.focus();
		return false;
	}
// Validate the Time fields
	if (!isNum(form.ty.value) && !isNum(form.tm.value) && !isNum(form.td.value)) {
		alert("Enter a Time in years, months, and/or days.");
		form.ty.focus();
		return false;
	}
	if (!isNum(form.ty.value) && !isBlank(form.ty.value)) {
		alert("Please enter a Valid number of Years.");
		form.ty.focus();
		return false;
	}
	if (!isNum(form.tm.value) && !isBlank(form.tm.value)) {
		alert("Please enter a Valid number of Months.");
		form.tm.focus();
		return false;
	}
	if (!isNum(form.td.value) && !isBlank(form.td.value)) {
		alert("Please enter a Valid number of Days.");
		form.td.focus();
		return false;
	}

// Proceed with Calculation
	var P = parseFloat(form.P.value);
	var r = parseFloat(form.r.value);
	if (isBlank(form.ty.value)) { var ty = 0; } else { var ty = parseFloat(form.ty.value); }
	if (isBlank(form.tm.value)) { var tm = 0; } else { var tm = parseFloat(form.tm.value); }
	if (isBlank(form.td.value)) { var td = 0; } else { var td = parseFloat(form.td.value); }
	var diy = parseFloat(form.diy.value)
	var t = ty + tm/12 + td/diy;
	var I = P*(r/100)*t;
	
	form.I.value = tocurrency(I);
	return true;
}

// </script>
// End Hiding Script -->