// JScript source code
function house_fees_Validator(theForm){
    var checkOK = "0123456789-.,";
    var checkStr = theForm.finaltotal.value;
    var allValid = true;
    var decPoints = 0;
    var allNum = "";
    for (i = 0; i < checkStr.length; i++){
        ch = checkStr.charAt(i);
        for (j = 0; j < checkOK.length; j++)
        if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length){
            allValid = false;
            break;
        }
        if (ch == "."){
            allNum += ".";
            decPoints++;
        }
        else if (ch != ",")
            allNum += ch;
        }
        if (!allValid){
            alert("Please enter only digit characters in the \"finaltotal\" field.");
            theForm.finaltotal.focus();
            return (false);
        }

        if (decPoints > 1){
            alert("Please enter a valid number in the \"finaltotal\" field.");
            theForm.finaltotal.focus();
            return (false);
        }
   return (true);
}


function compute(form){
//setup variables - used for purchase
var val1 = parseInt(form.house.value, 10)
var kstfee = 0
var stp = 0
var landregistry = 0
var moneytransfer = 20.00
var landregistrysearch = 6.19
var bankruptcysearch = 6.10
var VAT = 17.5

//KST fee Function
if (val1 <= 250000) {kstfee = 250.00;}
if ((val1 >= 250001) && (val1<=350000)) {kstfee = 275.00;}
if ((val1 >= 350001) && (val1<=450000)) {kstfee = 350.00;}
if ((val1 > 450000)) {alert("Please ring us for a personalised quote");}

if ((val1 <= 450000)) {    
    //calculate Stamp Duty
    if (val1 <= 125000) {stp = 0;}
    if ((val1 > 125000) && (val1<=250000)) {stp = (form.house.value)*0.01;}
    if ((val1 > 250000) && (val1<=500000)) {stp = (form.house.value)*0.03;}
    // end of stamp duty function

    //Land Registry function
    if ((val1 <= 50000)){landregistry = 50}
    if ((val1 > 50000) && (val1<=80000)){landregistry = 80}
    if ((val1 > 80000) && (val1<=100000)){landregistry = 130}
    if ((val1 > 100000) && (val1<=200000)){landregistry = 200}
    if ((val1 > 200000) && (val1<=500000)){landregistry = 280}
    //end of land registry function
        
    //kst fee inc VAT
    kstfee = kstfee + kstfee * VAT / 100
    form.result1.value=Math.round(kstfee*100)/100
    form.result2.value=Math.round(stp*100)/100

    // round down to the nearest 5 pounds
    //stp=form.result2.value;
    //stp=Math.floor((stp / 5)) * 5;
    //form.result2.value=stp

    form.result3.value=Math.round(landregistry*100)/100
    form.result4.value=Math.round(moneytransfer*100)/100
    form.result5.value=Math.round(landregistrysearch*100)/100
    form.result6.value=Math.round(bankruptcysearch*100)/100

    //calculate kstfee+stp+landregistry+moneytransfer+landregistrysearch+bankruptcysearch
    form.finaltotal.value=parseFloat(form.result1.value) + parseFloat(form.result2.value) + parseFloat(form.result3.value) + parseFloat(form.result4.value) + parseFloat(form.result5.value) + parseFloat(form.result6.value);
    form.finaltotal.value =Math.round(form.finaltotal.value*100)/100;
    }
}




function computesale(form)
{
//setup variables

var val1 = parseInt(form.house.value, 10)

var kstfee = 0
var officecopyentries = 9.91
var bankcharge = 20.00
var VAT = 17.5

//KST fee Function

if ((val1 <= 250000) ){kstfee = 200.00}
if ((val1 >= 250001) && (val1<=350000)){kstfee = 250.00}
if ((val1 >= 350001) && (val1<=450000)){kstfee = 350.00}
if ((val1 > 450000)){alert("Please ring us for a personalised quote")}
//End of KST fee Function

if (val1 <= 450000)
{
    //kst fee inc VAT
    kstfee = kstfee + kstfee * VAT / 100
    form.result1.value=Math.round(kstfee*100)/100

    form.result7.value=bankcharge
    form.result7.value =(Math.round(form.result7.value*100)/100);

    form.result4.value=officecopyentries
    form.result4.value =(Math.round(form.result4.value*100)/100);

    // calculate KST+VAT+officecopy + bank charge
    form.finaltotal.value=parseFloat(form.result1.value) + parseFloat(form.result7.value) + parseFloat(form.result4.value) 
    form.finaltotal.value =Math.round(form.finaltotal.value*100)/100;
} //else {
  //form.result4.value = '';
  //form.finaltotal.value = '';
 //}
}
 //--end hiding here -->
 
