//Ballpark Leasehold Valuation Calculator witten by Pro-Leagle, Copyright 2010+
//Unauthorised usage of this code on any third party website for any purpose is prohibited
//Please contact Pro-Leagle at info@proleagle.com if you would like to use this calculator on
//your website or if you would like to commission a similar calculator.

function leasevalcalc(form) {

var x;
var y;
var z;
var a;
var b;
var c;
var d;
var e;
var f;
var g;
var h;
var i;
var j;
var k;
var l;
var m;
var calc1;
var calc2;
var calc3;
var calc4;

x=form.a.value;

      if (x=="")
         {
         alert("Please enter the current value of your property.");
         return (false);
         }

      if (isNaN(x))
         {
         alert("Please enter numbers only. Do not include the pound sign or commas.");
         return (false);
         }
      else
         {
         a = eval(form.a.value);
         }

y=form.b.value;

      if (y=="")
         {
         alert("Please enter the projected improved value of your property after Lease Extension.");
         return (false);
         }

      if (isNaN(y))
         {
         alert("Please enter numbers only. Do not include the pound sign or commas.");
         return (false);
         }
      else
         {
         b = eval(form.b.value);
         }

      if (b<=a)
         {
         alert("Please ensure that the projected value of your property after lease extension/freehold purchase is greater than the current value");
         return (false);
         }

years=form.c.value;

      if (years=="")
         {
         alert("Please enter the years remaining on your lease.");
         return (false);
         }

      if (isNaN(years))
         {
         alert("Please enter numbers only. Do not include the pound sign or commas.");
         return (false);
         }
      else
         {
         c = eval(form.c.value);
         }

z=form.d.value;

      if (z=="")
         {
         alert("Please enter your ground rent.");
         return (false);
         }

      if (isNaN(z))
         {
         alert("Please enter numbers only. Do not include the pound sign or commas.");
         return (false);
         }
      else
         {
         d = eval(form.d.value);
         }

if (form.yieldRateBox.checked == 1)
{
e=5.5;
}
else
{
e=7;
}
calc1 = 1+(e/100); 
calc2 = e/100;
calc3 = Math.pow(calc1,-c);
f = (1-calc3)/calc2;

g = f * d;

h = Math.pow((1+calc2),-c);
i = b * h;

j = g + i;

if (c<80)
	{
	calc4 = b-(a+j);
		if (calc4<0)
		{
		k = 0;
		}
      else
		{
		k = (calc4/2);
		}
	}
else
	{
	k = 0;
	}

l = j + k;

m = Math.round(l/100)*100;

form.ansa.value = m;
}

// End

