function calcTransfer(InitAmnt)
{
 var Petties = 684;
 var SearchFee = 114;
 var Levies = 5000;
 var zz = 0;
 var Tfica = 250.80;
 var Bfica = 250.80;
 var Tdocfee = 114;
 var Bdocfee = 114;
 var Aktex = 114;
 var tvat = 0;
 var bvat = 0;
 var InitFee = 0;
 var x = 0;

 x = (remComma(document.trfCosts.BondsBVF.value)*1);
 if (x>0) {
	InitFee=(x);
	//alert(x);
 }

 price=document.buyInfo.purPrice.value;
 bondUnique=document.buyInfo.bondPrice.value;

 tc=GetTxferCost(price);
 td=GetTxferDuty(price);
 bc=GetBondCost(bondUnique);
 
 tvat=GetVat(tc);
 bvat=GetVat(bc);
 
 //alert(bond);

//updated deeds office fees 9 Jan 2009	
	exam=0;
	if (price<=150000) { exam=70; }
	if ((price>150000) && (price<=300000))  { exam=300; }
	if ((price>300000) && (price<=500000))  { exam=400; }
	if ((price>500000) && (price<=1000000))  { exam=500; }
	if ((price>1000000) && (price<=2000000))  { exam=600; }
	if ((price>2000000) && (price<=3000000))  { exam=800; }
	if ((price>3000000) && (price<=5000000))  { exam=1000; }
	if (price>5000000) { exam=1200; }

//updated deeds office fees 9 Jan 2009
	deeds=0;	
	if (bondUnique<=150000) { deeds=260; }
	if ((bondUnique>150000) && (bondUnique<=300000))  { deeds=300; }
	if ((bondUnique>300000) && (bondUnique<=500000))  { deeds=400; }
	if ((bondUnique>500000) && (bondUnique<=1000000))  { deeds=500; }
	if ((bondUnique>1000000) && (bondUnique<=2000000))  { deeds=650; }
	if ((bondUnique>2000000) && (bondUnique<=5000000))  { deeds=1000; }
	if (bondUnique>5000000) { deeds=2000; }


	document.trfCosts.TransDuty.value=addComma(td);
	document.trfCosts.TransFees.value=addComma(tc);
	document.trfCosts.BondsFees.value=addComma(bc);	
	document.trfCosts.TransPP.value=addComma(Petties);
	document.trfCosts.BondsPP.value=addComma(Petties);
	document.trfCosts.TransVat.value=addComma(tvat);
	document.trfCosts.BondsVat.value=addComma(bvat);
	document.trfCosts.BondsBVF.value=addComma(InitFee);
	document.trfCosts.TransDeeds.value=addComma(exam);
	document.trfCosts.BondsDeeds.value=addComma(deeds);
	document.trfCosts.TransDeedSearch.value=addComma(SearchFee);
	document.trfCosts.BondsDeedSearch.value=addComma(Aktex);
	document.trfCosts.TransDocGen.value=addComma(Tdocfee);
	document.trfCosts.BondsDocGen.value=addComma(Bdocfee);
	document.trfCosts.TransFICA.value=addComma(Tfica);
	document.trfCosts.BondsFICA.value=addComma(Bfica);

	//z=parseFloat(txtTduty.value)+parseFloat(txtTexam.value)+parseFloat(txtTtariff.value)+parseFloat(txtTpost.value)+parseFloat(txtTsearch.value)+parseFloat(txtTvat.value)+parseFloat(txtTrates.value);
	runTransTotal=td+exam+tc+Petties+SearchFee+tvat+Tfica+Tdocfee;
	runBondsTotal=deeds+InitFee+bc+Petties+Aktex+bvat+Bfica+Bdocfee;
	document.trfCosts.TransTotal.value=addComma(RoundNumbers(runTransTotal));
	document.trfCosts.BondsTotal.value=addComma(RoundNumbers(runBondsTotal));
}

/***************************************************************************/
function GetVat(Amt) {
	var VAT_rate=14
	return RoundNumbers(Amt * (VAT_rate / 100));
}

function GetTxferCost(Amt) {
var AmtTXfer1 = 800;
var AmtTXfer2 = 400;
var AmtTXfer3 = 200;
	
	
	txfer=0;
	if (Amt<=18000) { txfer=760; }
	if ((Amt>18000) && (Amt<=30000))  { txfer=1250; }
	if ((Amt>30000) && (Amt<=45000))  { txfer=1500; }
	if ((Amt>45000) && (Amt<=70000))  { txfer=1800; }
	if ((Amt>70000) && (Amt<=80000))  { txfer=2500; }
	if ((Amt>80000) && (Amt<=90000))  { txfer=2700; }
	if ((Amt>90000) && (Amt<=100000))  { txfer=2900; }
	if ((Amt>100000) && (Amt<=125000))  { txfer=3000; }
	if ((Amt>125000) && (Amt<=150000))  { txfer=3100; }
	if ((Amt>150000) && (Amt<=175000))  { txfer=3300; }
	if ((Amt>175000) && (Amt<=200000))  { txfer=3500; }
	if ((Amt>200000) && (Amt<=250000))  { txfer=3800; }
	if ((Amt>250000) && (Amt<=300000))  { txfer=4400; }
	if ((Amt>300000) && (Amt<=350000))  { txfer=4700; }
	if ((Amt>350000) && (Amt<=400000))  { txfer=5100; }
	if ((Amt>400000) && (Amt<=450000))  { txfer=5500; }
	if ((Amt>450000) && (Amt<=500000))  { txfer=6000; }
	
	x=0
	if (txfer==0) {
		txfer=txfer+6000;
	
		if ((Amt>500000) && (Amt<=1000000))  { 
			x=Math.ceil((Amt-500000)/100000);
			txfer=txfer+(x*AmtTXfer1);
		
		}
		if ((Amt>1000000) && (Amt<=5000000))  { 
			x=Math.ceil((Amt-1000000)/100000);
			//alert(x);		
			txfer=txfer+(5*AmtTXfer1);
			txfer=txfer+(x*AmtTXfer2);
		}
		
		if (Amt>5000000)  { 
			x=Math.ceil((Amt-5000000)/100000);		
			txfer=txfer+(5*AmtTXfer1);
			txfer=txfer+(40*AmtTXfer2);
			txfer=txfer+(x*AmtTXfer3);
		}
	}
	return txfer;			
	
}

function GetBondCost(Amt) {
var AmtBondC1 = 600;
var AmtBondC2 = 300;
var AmtBondC3 = 150;

	bond=0;
	if (Amt<=10000) { bond=550; }
	if ((Amt>10000) && (Amt<=15000))  { bond=700; }
	if ((Amt>15000) && (Amt<=20000))  { bond=750; }
	if ((Amt>20000) && (Amt<=25000))  { bond=850; }
	if ((Amt>25000) && (Amt<=30000))  { bond=900; }
	if ((Amt>30000) && (Amt<=35000))  { bond=1000; }
	if ((Amt>35000) && (Amt<=40000))  { bond=1100; }
	if ((Amt>40000) && (Amt<=45000))  { bond=1150; }
	if ((Amt>45000) && (Amt<=50000))  { bond=1200; }
	if ((Amt>50000) && (Amt<=60000))  { bond=1300; }
	if ((Amt>60000) && (Amt<=70000))  { bond=1400; }
	if ((Amt>70000) && (Amt<=80000))  { bond=1600; }
	if ((Amt>80000) && (Amt<=90000))  { bond=1700; }
	if ((Amt>90000) && (Amt<=100000))  { bond=1800; }	
	if ((Amt>100000) && (Amt<=125000))  { bond=1900; }
	if ((Amt>125000) && (Amt<=150000))  { bond=2000; }	
	if ((Amt>150000) && (Amt<=175000))  { bond=2100; }
	if ((Amt>175000) && (Amt<=200000))  { bond=2200; }
	if ((Amt>200000) && (Amt<=250000))  { bond=2400; }
	if ((Amt>250000) && (Amt<=300000))  { bond=2700; }
	if ((Amt>300000) && (Amt<=350000))  { bond=3000; }
	if ((Amt>350000) && (Amt<=400000))  { bond=3400; }
	if ((Amt>400000) && (Amt<=450000))  { bond=3700; }
	if ((Amt>450000) && (Amt<=500000))  { bond=4000; }	
	
	x=0
	if (bond==0) {
		bond=bond+4000;
	
		if ((Amt>500000) && (Amt<=1000000))  { 
			x=Math.ceil((Amt-500000)/100000);		
			bond=bond+(x*AmtBondC1);
		
		}
		if ((Amt>1000000) && (Amt<=5000000))  { 
			x=Math.ceil((Amt-1000000)/100000);		
			bond=bond+(5*AmtBondC1);
			bond=bond+(x*AmtBondC2);
		}
		
		if (Amt>5000000)  { 
			x=Math.ceil((Amt-5000000)/100000);		
			bond=bond+(5*AmtBondC1);
			bond=bond+(40*AmtBondC2);
			bond=bond+(x*AmtBondC3);
		}
	}
	return bond;	
}

function GetTxferDuty(Amt) {
	txfd=0;
	if (document.buyInfo.Natural[0].checked) {
		//seller is a vat vendor
		return (0);		
	} else {
	//seller is a natural person
	if (document.buyInfo.Natural[1].checked) {
		x=0;
		if (Amt<=500000) { txfd=0; }
		if ((Amt>500000) && (Amt<=1000000))  { 
			x=(Amt-500000)*(5/100);		
			txfd=x; }
		if (Amt>1000000) { 
			x=(500000)*(5/100);
			x=x+(Amt-1000000)*(8/100);		
			txfd=x; }
	} else {
	//purchaser is a legal entity
		txfd=Amt*(8/100);	
	}
	return (txfd);
	}
}

function GetVat(Amt) {
	var VAT_rate=14
	return RoundNumbers(Amt * (VAT_rate / 100));
}
function addComma(TheNum)
{
    numVar=String(TheNum);
    var commaNumber = "";
    var thenumber = ""
    var thefraction = "";
    var j = numVar.indexOf(".");
    var l = numVar.length;
    
    if (j > 0)
    {    //found a period.
	 tvar=numVar+"00"; 
	 numVar=numVar.substr(0,j);
         for(i = j; i<j+3; i++) {     
               thefraction = thefraction + tvar.charAt(i); }
    }  else { //no period found
	    thefraction = ".00"; }
	j = numVar.length;

    for (i = j; i > 0; i--) {
         if ((i != j) && ((j - i) % 3 == 0))
                thenumber = thenumber + " ";
         thenumber = thenumber + numVar.charAt(i-1);
    }
    j = thenumber.length;
    for (i = j; i >= 0; i--)
        commaNumber = commaNumber + thenumber.charAt(i);
    
    commaNumber=commaNumber+thefraction; 
    return commaNumber;
}

function addCommaEx(TheNum)
{
    numVar=String(TheNum);
    var commaNumber = "";
    var thenumber = ""
    var thefraction = "";
    var j = numVar.length;

    for (i = j; i > 0; i--) {
         if ((i != j) && ((j - i) % 3 == 0))
                thenumber = thenumber + " ";
         thenumber = thenumber + numVar.charAt(i-1);
    }
    j = thenumber.length;
    for (i = j; i >= 0; i--)
        commaNumber = commaNumber + thenumber.charAt(i);

    return commaNumber;
}

function remComma(TheNum)
{
    numVar=String(TheNum);
    var thenumber = ""
    var l = numVar.length;
    
    for (i = l; i > 0; i--) {
         if (numVar.charAt(i-1) != " ")
         	thenumber = thenumber + numVar.charAt(i-1);
    }
	
	numVar=""
	j = thenumber.length;
    for (i = j; i >= 0; i--)
        numVar = numVar + thenumber.charAt(i);
		
	if ((numVar==".00")) {
		numVar="0"
	}
    return numVar;
}
function RoundNumbers(TheNum) {
	//return Math.round(TheNum);
	return TheNum;
}
