
//this function use to display cat product using on chnage 
function check_numeric_value(getValue) {

	getValue = document.getElementById(getValue);
	if(numValue(getValue)== false) return false;

}

function check_present_value() {

	future_value = document.getElementById("future_value");
	if(blankValidation(future_value,"Future value cannot be blank.")== false) return false;

	years = document.getElementById("years");
	if(blankValidation(years,"Year value cannot be blank.")== false) return false;

	discount_rate = document.getElementById("discount_rate");
	if(blankValidation(discount_rate, "Discount Rate value cannot be blank.")== false) return false;

}

function isNum(x){
	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){
	prefix = ""
	wd = "w"
	var tempnum = passedVal.toString()
	for (i=0; i < tempnum.length; i++){
		if (tempnum.charAt(i)=="."){
			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 amort_calc() {
	// Validate the P field
	if (!isNum(a1_form.P.value)) {
		alert("Please enter a valid number for the Loan Amount (P).")
		document.a1_form.P.focus()
		return false
	}
	// Validate the r field
	if (!isNum(a1_form.r.value)) {
		alert("Enter an Interest Rate (r) as 0.01 for 1%.")
		document.a1_form.r.focus()
		return false
	}
	// Validate the N field
	if (!isNum(a1_form.N.value)) {
		alert("Please enter the Total Number of Payments (N).")
		document.a1_form.N.focus();
		return false
	}

	var P = parseFloat(a1_form.P.value)
	var r = parseFloat(a1_form.r.value)
	var N = parseFloat(a1_form.N.value)
	var A = P*(r*Math.pow(1+r,N))/(Math.pow(1+r,N)-1)

	a1_form.A.value = tocurrency(A)
	return true
}
