
function display_calc(price) {
	document.write("<style type=\"text/css\">");
	document.write("#contact{margin:5px 20px;padding:10px 5px 10px 5px;border:1px solid #ddd;background:#eee}");
	document.write("#contact legend{border:1px solid #ddd;padding:2px 5px;background:#fff;color:#912c3a}");
	document.write("#contact fieldset{border:1px solid #ddd;padding:10px;background:#fff;margin-bottom:10px}");
	document.write("#contact *{font-size:1.1em;font-family:arial,helvetica,sans-serif}");
	document.write("#contact label{clear:both;width:115px;float:left;margin-top:5px;margin-right:5px;background:#eee;text-indent:3px}");
	document.write(".input{float:left;width:120px;margin-top:5px;border:1px solid #999}");
	document.write(".submit{margin-left:120px;clear:both;color:#fff;font-weight:bold;border:1px solid #912c3a;background:url(images/red.gif) 0 50% #912c3a;color:#fff}");
	document.write("</style>");
	
	document.write("<form name=\"MortgageMinder\" id=\"contact\">");
	document.write("<fieldset>");
	document.write("<legend>Mortgage Details</legend>");
	document.write("<label>House Price</label>");
	document.write("<input type=\"text\" name=\"price\" value=\"" + price + "\" onBlur=\"checkForZero(this)\" onChange=\"checkForZero(this)\" class=\"input\" /><br />");
	document.write("<label>Down Payment</label>");
	document.write("<input type=\"text\" name=\"dp\" value=\"0\" onChange=\"calculatePayment(this.form)\" class=\"input\" /><br />");
	document.write("<label>Interest Rate</label>");
	document.write("<input type=\"text\" name=\"ir\" value=\"6\" onBlur=\"checkForZero(this)\" onChange=\"checkForZero(this)\" class=\"input\" /><br />");
	document.write("<label>Term (Years)</label>");
	document.write("<input type=\"text\" name=\"term\" value=\"30\" onBlur=\"checkForZero(this)\" onChange=\"checkForZero(this)\" class=\"input\" /><br />");
	document.write("</fieldset>");
	document.write("<fieldset>");
	document.write("<legend>Your Results</legend>");
	document.write("<label>Mortgage Payable</label>");
	document.write("<input type=\"text\" name=\"principle\" class=\"input\" /><br />");
	document.write("<label>No Of Payments</label>");
	document.write("<input type=\"text\" name=\"payments\" class=\"input\" /><br />");
	document.write("<label>Monthly Payment</label>");
	document.write("<input type=\"text\" name=\"pmt\" class=\"input\" />");
	document.write("<input type=\"button\" name=\"btn_process\" class=\"input\" value=\"Calculate\" onClick=\"calculatePayment(this.form)\"  />");
	document.write("</fieldset>");
	document.write("</form>");
}
function checkForZero(field)
{
    if (field.value == 0 || field.value.length == 0) {
        alert ("This field can't be 0!");
        field.focus(); }
    else
        calculatePayment(field.form);
}

function cmdCalc_Click(form)
{
    if (form.price.value == 0 || form.price.value.length == 0) {
        alert ("The Price field can't be 0!");
        form.price.focus(); }
    else if (form.ir.value == 0 || form.ir.value.length == 0) {
        alert ("The Interest Rate field can't be 0!");
        form.ir.focus(); }
    else if (form.term.value == 0 || form.term.value.length == 0) {
        alert ("The Term field can't be 0!");
        form.term.focus(); }
    else
        calculatePayment(form);
}

function calculatePayment(form)
{
    princ = form.price.value - form.dp.value;
    intRate = (form.ir.value/100) / 12;
    months = form.term.value * 12;
    form.pmt.value = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
    form.principle.value = princ;
    form.payments.value = months;
}



