<!--------- calculations for affordability -------

	var WGdc=".";  
	var WGgc=",";
	var WGnc="-";
	var WGcs="";
function WGformatMoney(A,W) 
{  
// Author   : Jonathan Weesner (http://cyberstation.net/~jweesner/)
// Copyright: Use freely. Keep Author and Copyright lines intact.
	var N=Math.abs(Math.round(A*100));
   var S=((N<10)?"00":((N<100)?"0":""))+N;

   S=WGcs+((A<0)?WGnc:"")+WGgroup(S.substring(0,(S.length-2)))+WGdc+
      S.substring((S.length-2),S.length)+((A<0&&WGnc=="(")?")":"");
   return (S.length>W)?"Over":S;
}

// WGgroup inspired by Bill Dortch's usenet post (www.hidaho.com)
function WGgroup(S) 
{
   return (S.length<4)?S:(WGgroup(S.substring(0,S.length-3))+
      WGgc+S.substring(S.length-3,S.length));
}

function roundOff(value, precision) {	// Precision = 2 decimal places
		if(parseInt(value) <= 0) {
			// Incorrect Value
			return 0;
			}
		
        value = "" + value //convert value to string
        precision = parseInt(precision);
        var whole = "" + Math.round(value * Math.pow(10, precision));
        var decPoint = whole.length - precision;        if(decPoint != 0)
        {                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);        }
        else        {                result = whole;        }
        return result;
}


function removeComma( inVal ){
	var rVal = inVal.replace(",", "");
	return rVal;
	}


function calc1(form) {

	form.aaa.value = roundOff(removeComma(form.aa.value)*form.a.value, 1);
	form.bbb.value = roundOff(removeComma(form.bb.value)*form.b.value, 1);
	form.ccc.value = roundOff(removeComma(form.cc.value)*form.c.value, 1);
	form.ddd.value = roundOff(removeComma(form.dd.value)*form.d.value, 1);
	form.eee.value = roundOff(removeComma(form.ee.value)*form.e.value, 1);
	form.fff.value = roundOff(removeComma(form.ff.value)*form.f.value, 1);
	form.ggg.value = roundOff(removeComma(form.gg.value)*form.g.value, 1);
	form.hhh.value = roundOff(removeComma(form.hh.value)*form.h.value, 1);
	form.iii.value = roundOff(removeComma(form.ii.value)*form.i.value, 1);
	form.jjj.value = roundOff(removeComma(form.jj.value)*form.j.value, 1);
	form.kkk.value = roundOff(removeComma(form.kk.value)*form.k.value, 1);
	form.lll.value = roundOff(removeComma(form.ll.value)*form.l.value, 1);
	
	}
	
function calc2(form) {

	form.aaa1.value = roundOff(removeComma(form.aa1.value)*form.a1.value, 1);
	form.bbb1.value = roundOff(removeComma(form.bb1.value)*form.b1.value, 1);
	form.ccc1.value = roundOff(removeComma(form.cc1.value)*form.c1.value, 1);
	form.ddd1.value = roundOff(removeComma(form.dd1.value)*form.d1.value, 1);
	form.eee1.value = roundOff(removeComma(form.ee1.value)*form.e1.value, 1);
	form.fff1.value = roundOff(removeComma(form.ff1.value)*form.f1.value, 1);
	form.ggg1.value = roundOff(removeComma(form.gg1.value)*form.g1.value, 1);
	form.hhh1.value = roundOff(removeComma(form.hh1.value)*form.h1.value, 1);
	
	}
	
function calc3(form) {

	form.aaa2.value = roundOff(removeComma(form.aa2.value)*form.a2.value, 1);
	form.bbb2.value = roundOff(removeComma(form.bb2.value)*form.b2.value, 1);
	form.ccc2.value = roundOff(removeComma(form.cc2.value)*form.c2.value, 1);
	form.ddd2.value = roundOff(removeComma(form.dd2.value)*form.d2.value, 1);
	form.eee2.value = roundOff(removeComma(form.ee2.value)*form.e2.value, 1);
	form.fff2.value = roundOff(removeComma(form.ff2.value)*form.f2.value, 1);
	form.ggg2.value = roundOff(removeComma(form.gg2.value)*form.g2.value, 1);
	form.hhh2.value = roundOff(removeComma(form.hh2.value)*form.h2.value, 1);
	form.iii2.value = roundOff(removeComma(form.ii2.value)*form.i2.value, 1);
	
	}	
	
function calc4(form) {

	
	form.aaa.value = roundOff(removeComma(form.aa.value)*form.a.value, 1);
	form.bbb.value = roundOff(removeComma(form.bb.value)*form.b.value, 1);
	form.ccc.value = roundOff(removeComma(form.cc.value)*form.c.value, 1);
	form.ddd.value = roundOff(removeComma(form.dd.value)*form.d.value, 1);
	form.eee.value = roundOff(removeComma(form.ee.value)*form.e.value, 1);
	form.fff.value = roundOff(removeComma(form.ff.value)*form.f.value, 1);
	form.ggg.value = roundOff(removeComma(form.gg.value)*form.g.value, 1);
	form.hhh.value = roundOff(removeComma(form.hh.value)*form.h.value, 1);
	form.iii.value = roundOff(removeComma(form.ii.value)*form.i.value, 1);
	form.jjj.value = roundOff(removeComma(form.jj.value)*form.j.value, 1);
	form.kkk.value = roundOff(removeComma(form.kk.value)*form.k.value, 1);
	form.lll.value = roundOff(removeComma(form.ll.value)*form.l.value, 1);
	form.aaa1.value = roundOff(removeComma(form.aa1.value)*form.a1.value, 1);
	form.bbb1.value = roundOff(removeComma(form.bb1.value)*form.b1.value, 1);
	form.ccc1.value = roundOff(removeComma(form.cc1.value)*form.c1.value, 1);
	form.ddd1.value = roundOff(removeComma(form.dd1.value)*form.d1.value, 1);
	form.eee1.value = roundOff(removeComma(form.ee1.value)*form.e1.value, 1);
	form.fff1.value = roundOff(removeComma(form.ff1.value)*form.f1.value, 1);
	form.ggg1.value = roundOff(removeComma(form.gg1.value)*form.g1.value, 1);
	form.hhh1.value = roundOff(removeComma(form.hh1.value)*form.h1.value, 1);
	form.aaa2.value = roundOff(removeComma(form.aa2.value)*form.a2.value, 1);
	form.bbb2.value = roundOff(removeComma(form.bb2.value)*form.b2.value, 1);
	form.ccc2.value = roundOff(removeComma(form.cc2.value)*form.c2.value, 1);
	form.ddd2.value = roundOff(removeComma(form.dd2.value)*form.d2.value, 1);
	form.eee2.value = roundOff(removeComma(form.ee2.value)*form.e2.value, 1);
	form.fff2.value = roundOff(removeComma(form.ff2.value)*form.f2.value, 1);
	form.ggg2.value = roundOff(removeComma(form.gg2.value)*form.g2.value, 1);
	form.hhh2.value = roundOff(removeComma(form.hh2.value)*form.h2.value, 1);
	form.iii2.value = roundOff(removeComma(form.ii2.value)*form.i2.value, 1);
	
	aaa = form.aaa.value*1;
	aaa = aaa + form.bbb.value*1;
	aaa = aaa + form.ccc.value*1;
	aaa = aaa + form.ddd.value*1;
	aaa = aaa + form.eee.value*1;
	aaa = aaa + form.fff.value*1;
	aaa = aaa + form.ggg.value*1;
	aaa = aaa + form.hhh.value*1;
	aaa = aaa + form.iii.value*1;
	aaa = aaa + form.jjj.value*1;
	aaa = aaa + form.kkk.value*1;
	aaa = aaa + form.lll.value*1;
	aaa = aaa + form.aaa1.value*1;
	aaa = aaa + form.bbb1.value*1;
	aaa = aaa + form.ccc1.value*1;
	aaa = aaa + form.ddd1.value*1;
	aaa = aaa + form.eee1.value*1;
	aaa = aaa + form.fff1.value*1;
	aaa = aaa + form.ggg1.value*1;
	aaa = aaa + form.hhh1.value*1;
	aaa = aaa + form.aaa2.value*1;
	aaa = aaa + form.bbb2.value*1;
	aaa = aaa + form.ccc2.value*1;
	aaa = aaa + form.ddd2.value*1;
	aaa = aaa + form.eee2.value*1;
	aaa = aaa + form.fff2.value*1;
	aaa = aaa + form.ggg2.value*1;
	aaa = aaa + form.hhh2.value*1;
	aaa = aaa + form.iii2.value*1;
	
	form.subtotal.value = roundOff(aaa, 1);
	form.factor.value = form.subtotal.value*.2;
	form.total.value = roundOff((form.subtotal.value*1.2), 1);

	
	}
	
	
function calc5(form) {

	form.aaa.value = roundOff(removeComma(form.aa.value)*form.a.value, 1);
	form.bbb.value = roundOff(removeComma(form.bb.value)*form.b.value, 1);
	form.ccc.value = roundOff(removeComma(form.cc.value)*form.c.value, 1);
	form.ddd.value = roundOff(removeComma(form.dd.value)*form.d.value, 1);
	form.eee.value = roundOff(removeComma(form.ee.value)*form.e.value, 1);
	form.fff.value = roundOff(removeComma(form.ff.value)*form.f.value, 1);
	form.ggg.value = roundOff(removeComma(form.gg.value)*form.g.value, 1);
	form.hhh.value = roundOff(removeComma(form.hh.value)*form.h.value, 1);
	form.iii.value = roundOff(removeComma(form.ii.value)*form.i.value, 1);
	
	}
	
function calc6(form) {

	form.aaa2.value = roundOff(removeComma(form.aa2.value)*form.a2.value, 1);
	form.bbb2.value = roundOff(removeComma(form.bb2.value)*form.b2.value, 1);
	form.ccc2.value = roundOff(removeComma(form.cc2.value)*form.c2.value, 1);
	form.ddd2.value = roundOff(removeComma(form.dd2.value)*form.d2.value, 1);
	form.eee2.value = roundOff(removeComma(form.ee2.value)*form.e2.value, 1);
	form.fff2.value = roundOff(removeComma(form.ff2.value)*form.f2.value, 1);
	form.ggg2.value = roundOff(removeComma(form.gg2.value)*form.g2.value, 1);
	form.hhh2.value = roundOff(removeComma(form.hh2.value)*form.h2.value, 1);
	form.iii2.value = roundOff(removeComma(form.ii2.value)*form.i2.value, 1);
	
	}	
	
	
function calc7(form) {

	
	form.aaa.value = roundOff(removeComma(form.aa.value)*form.a.value, 1);
	form.bbb.value = roundOff(removeComma(form.bb.value)*form.b.value, 1);
	form.ccc.value = roundOff(removeComma(form.cc.value)*form.c.value, 1);
	form.ddd.value = roundOff(removeComma(form.dd.value)*form.d.value, 1);
	form.eee.value = roundOff(removeComma(form.ee.value)*form.e.value, 1);
	form.fff.value = roundOff(removeComma(form.ff.value)*form.f.value, 1);
	form.ggg.value = roundOff(removeComma(form.gg.value)*form.g.value, 1);
	form.hhh.value = roundOff(removeComma(form.hh.value)*form.h.value, 1);
	form.iii.value = roundOff(removeComma(form.ii.value)*form.i.value, 1);
	form.aaa2.value = roundOff(removeComma(form.aa2.value)*form.a2.value, 1);
	form.bbb2.value = roundOff(removeComma(form.bb2.value)*form.b2.value, 1);
	form.ccc2.value = roundOff(removeComma(form.cc2.value)*form.c2.value, 1);
	form.ddd2.value = roundOff(removeComma(form.dd2.value)*form.d2.value, 1);
	form.eee2.value = roundOff(removeComma(form.ee2.value)*form.e2.value, 1);
	form.fff2.value = roundOff(removeComma(form.ff2.value)*form.f2.value, 1);
	form.ggg2.value = roundOff(removeComma(form.gg2.value)*form.g2.value, 1);
	form.hhh2.value = roundOff(removeComma(form.hh2.value)*form.h2.value, 1);
	form.iii2.value = roundOff(removeComma(form.ii2.value)*form.i2.value, 1);
	
	aaa = form.aaa.value*1;
	aaa = aaa + form.bbb.value*1;
	aaa = aaa + form.ccc.value*1;
	aaa = aaa + form.ddd.value*1;
	aaa = aaa + form.eee.value*1;
	aaa = aaa + form.fff.value*1;
	aaa = aaa + form.ggg.value*1;
	aaa = aaa + form.hhh.value*1;
	aaa = aaa + form.iii.value*1;
	
	aaa2 = form.aaa2.value*1;
	aaa2 = aaa2 + form.bbb2.value*1;
	aaa2 = aaa2 + form.ccc2.value*1;
	aaa2 = aaa2 + form.ddd2.value*1;
	aaa2 = aaa2 + form.eee2.value*1;
	aaa2 = aaa2 + form.fff2.value*1;
	aaa2 = aaa2 + form.ggg2.value*1;
	aaa2 = aaa2 + form.hhh2.value*1;
	aaa2 = aaa2 + form.iii2.value*1;
	
	form.subtotal.value = roundOff(aaa, 1);
	form.factor.value = roundOff(aaa2, 1);

	
	}	
