function getAmt1 (form, button, v_type) {
	
	if (!c_num(form.v_amt)) return;
	if (!c_num(form.v_rate)) return;
	if (form.v_per.value != null) {
		if (!c_num(form.v_per)) return;    
	}

	v_amt = form.v_amt.value;
	v_rate = form.v_rate.value / 100;
	if (form.v_per.value != null) {
		v_per = form.v_per.value;		
	}
	else{
		v_per = form.v_per.options[form.v_per.selectedIndex].value;
	}

	if (v_type == "getPV"){
		v_rate = v_rate / 12;
		v_per = v_per * 12;
		v_amt1 = (v_amt * (Math.pow((1 + v_rate), v_per) - 1)) / (v_rate * Math.pow((1 + v_rate), v_per));
	}
	else if (v_type == "getAmt"){
		v_rate = v_rate / 12;
		v_per = v_per * 12;
		v_amt1 = (v_amt * v_rate * Math.pow((1 + v_rate), v_per)) / (Math.pow((1 + v_rate), v_per) - 1);	
	}
	else if (v_type == "getTPV"){
		v_amt1 = (v_amt * v_per) / (1 + (v_rate * v_per));
	}
	else if (v_type == "getTAmt"){
		v_amt1 = v_amt * (1 + v_rate * v_per) / v_per;
	}
	else if (v_type == "getZPV"){
		v_amt1 = v_amt * 12 * (Math.pow((1 + v_rate), v_per) - 1) / v_rate * (24 + (13 * v_rate)) / 24;
	}
	else if (v_type == "getZAmt"){
		v_amt1 = v_amt / 12 / (Math.pow((1 + v_rate), v_per) - 1) * v_rate / (24 + (13 * v_rate)) * 24;
	}

	v_amt1 = round(v_amt1, 2);
	form.v_amt1.value = v_amt1;
	return;
}

function c_num(text) {
	// Ctrl = form.v_amt;
	if (isNaN (parseInt(text.value))) {
		validatePrompt (text, "ERROR: Please input a number!");
		return (false);
	}
	else
		return (true);
}

function validatePrompt (Ctrl, PromptStr) {
	alert (PromptStr)
	Ctrl.focus();
	return;
}

function round(v_num, v_dec){
	return Math.round(v_num * Math.pow(10, v_dec)) / Math.pow(10, v_dec)
}

function formatDecimalNumber(x, dec) {
    x = round(x, dec);
    return formatNumber(x);
}

function formatNumber(x){
    var sign; 

    if (x < 0) { 
       y = String(x);
       x = String(y.substring(1,y.length));
       sign = "-";
    } else {
       x = String(x);
       sign = String("");
    }

    var idx = x.indexOf(".");
    var head, tail;
   
    if (idx > -1) {
        head = String(x.substring(0,idx));
        tail = "."+String(x.substring(idx+1, x.length));
    } else {
        head = x;
        tail = String("");
    }

    var neval = String()
    var i = 0
    for (var ct = (head.length-1) ; ct >= 0 ; ct --)
    {
        if (((i%3) == 0) && (i != 0))
            neval += String(",")
        neval += String(head.substring(ct,ct+1))
        i++
    }

    head = new String("")
    for (var ca = (neval.length-1) ; ca >= 0 ; ca --)
        head += neval.substring(ca,ca+1)

    return (sign+head+tail)
}
