//Napa County - Buyer pays all escrow/title fees

//var legaldocfee = document.netOut.legaldocfee.value;
//var recordingfee = document.netOut.recordingfee.value;
//var courierfee = document.netOut.courierfee.value;
//var insurancebinder = document.netOut.insurancebinder.value;


function RoundPrice()
{
    var theprice = document.netOut.SalesPrice.value;
    theprice = theprice.replace(/\$/g,'');
    theprice = theprice.replace(/\,/g,'');
    var computedprice = theprice;
    newprice = theprice.split(".");
    if (newprice[1] > 0)
    {
     var roundedprice = ++newprice[0];
    }else{
        var roundedprice = newprice[0];
    }
    var finalprice = roundedprice%1000;
    if ((finalprice != 0) && (finalprice > 0))
    {
        var tempprice = Math.round(roundedprice/1000);
        roundedprice = ++tempprice;
    }else{
        roundedprice = Math.round(roundedprice/1000);
    }
    roundedprice = roundedprice*1000;
    return (roundedprice);
}

function findOwner(tpo)
{
    
   if (tpo == 0)
    {
    var theowner = "Seller";
    }else if (tpo == 1){
        var theowner = "Buyer";
    }else{
        var theowner = "Both";
    }
   return theowner;
}

// Added computePremiumS function for Short-Term rates

function computePremiumS(newprice)
{
    var premium = new Array();
premium[20000]=0
premium[100000000]=0

var computedprice = premium[newprice];
while (computedprice == undefined)
    {
        newprice = (+(newprice)+1000);
        if (newprice > 100000000)
        {
            window.alert("Sorry, for amounts over $1,000,000 please contact your representative for assistance.");
            alert(msg);
        }
        computedprice = premium[newprice];
    }

return (computedprice);
}

function computePremium(newprice)
{
    var premium = new Array();
premium[20000]=0
premium[100000000]=0

var computedprice = premium[newprice];
while (computedprice == undefined)
    {
        newprice = (+(newprice)+1000);
        if (newprice > 100000000)
        {
            window.alert("Sorry, for amounts over $1,000,000 please contact your representative for assistance.");
            alert(msg);
        }
        computedprice = premium[newprice];
    }

return (computedprice);
}

function computedEscrow(newprice)
{
        var escrow = new Array();
        
escrow[20000] = 0
escrow[100000000] = 0

var computedprice = escrow[newprice];
while (computedprice == undefined)
    {
        newprice = (+(newprice)+1000);
        computedprice = escrow[newprice];
    }
    
return (computedprice);

}

function computeSellerCosts(commission,printTransferTaxSeller,titlePremium,escrowFee,withholding)
{
 var sellertitlecosts = (+(titlePremium)+
    (+(document.netOut.insurancebinder.value))+
    (+(escrowFee))+
    (+(document.netOut.legaldocfee.value))+
    (+(document.netOut.recordingfee.value))+
    (+(document.netOut.courierfee.value)+
    (+(document.netOut.SpecialAssessmentsSeller.value))+
    (+(document.netOut.LoanTieIn.value))+
    (+(document.netOut.WireFee.value))+
    (+(printTransferTaxSeller))+
    (+(document.netOut.NotaryFees.value))+
    (+(document.netOut.OtherTitleFee1Seller.value))+
    (+(document.netOut.OtherTitleFee2Seller.value))
    ));


 var sellerrepairs = (
     (+(document.netOut.SurveySeller.value))+
     (+(document.netOut.HomeWarrantySeller.value))+
     (+(document.netOut.StructuralInspectionSeller.value))+
     (+(document.netOut.PestInspectionSeller.value))+
     (+(document.netOut.PoolSpaInspectionSeller.value))+
     (+(document.netOut.RoofInspectionSeller.value))+
     (+(document.netOut.WellInspectionSeller.value))+
     (+(document.netOut.WellWaterSeller.value))+
     (+(document.netOut.WellEquipmentSeller.value))+
     (+(document.netOut.SepticInspectionSeller.value))+
     (+(document.netOut.Repairs.value))+
     (+(document.netOut.NaturalHazardDisclaimer.value))+
     (+(document.netOut.OtherInspectionRepair1Seller.value))
    );
 
 
 var sellerother = commission;
 var sellerwithholding = withholding;
 var sellerlendercharges = document.netOut.OtherOther2Seller.value;
  
//var sellerclosingcosts = (
//     (+sellerrepairs)+
//     (+sellertitlecosts)
//     (+sellerother)
//   );

var sellerclosingcosts = (
     (+sellerother)+
     (+sellerwithholding)+
     (+sellerrepairs)+
     (+sellerlendercharges)+
     (+sellertitlecosts)
    );

 return sellerclosingcosts;
 
}



function computeGrossEquity(saleprice)
{
    var mortgage1 = document.netOut.FirstMortgage.value;
    mortgage1 = mortgage1.replace(/\$/g,'');
    mortgage1 = mortgage1.replace(/\,/g,'');
    var mortgage2 = document.netOut.SecondMortgage.value;
    mortgage2 = mortgage2.replace(/\$/g,'');
    mortgage2 = mortgage2.replace(/\,/g,'');
    var mortgage3 = document.netOut.ThirdMortgage.value;
    mortgage3 = mortgage3.replace(/\$/g,'');
    mortgage3 = mortgage3.replace(/\,/g,'');
    
    var mortgages = (+(mortgage1)+
    (+(mortgage2))+
    (+(mortgage3)));
    
var GrossEquitySeller = (saleprice - (+mortgages));
return GrossEquitySeller;
}

 function computeCommission(saleprice)
 {
     var commissionrate = document.netOut.Commission.value;
     var thecommission = Math.round(((saleprice*commissionrate)/100));
     return thecommission;
 }

 function computeWithholding(saleprice)
 {
     var withholdingrate = document.netOut.CAWithholding.value;
     var thewithholding = Math.round(((saleprice*withholdingrate)/100));
     return thewithholding;
 }

//function computeCommissionTax(commission)
//{
//     var taxrate = document.netOut.GrossReceiptsTax.value;
//     var thesalestax = Math.round(((commission*taxrate)/100));
//     return thesalestax;    
//}

function currencyFormat(newvalue)
{
    newvalue = newvalue.replace(/\$/g,'');
    newvalue = newvalue.replace(/\,/g,'');
    newvalue = Math.round(newvalue);
    
    if ((newvalue=="0") || (isNaN(newvalue)))
    {
        var finalvalue = "-";
        return finalvalue;
    }else{
        finalvalue = newvalue.toString();
        if (finalvalue.length > 3)
            {
            var tester = finalvalue.length;
            var firststring = ((tester)%3);
            if (firststring > 0)
                {
                var i = firststring;
                var amount = finalvalue.substr(0,firststring);
                }else{
                var i = 3;
                var amount = finalvalue.substr(0,3)
            }
            while ( i < tester )
                {
                amount = amount+','+finalvalue.substr(i,3);
                i++;
                i++;
                i++;
                }
            }else{
             var amount = finalvalue;
            }
    }
    return amount;
}

function currencyFormat2(newvalue)
{
    newvalue = newvalue.replace(/\$/g,'');
    newvalue = newvalue.replace(/\,/g,'');
    newvalue = Math.round(newvalue);
    
    if ((newvalue=="0") || (isNaN(newvalue)))
    {
        var finalvalue = "-";
        return finalvalue;
    }else{
        finalvalue = newvalue.toString();
        if (finalvalue.length > 3)
            {
            var tester = finalvalue.length;
            var firststring = ((tester)%3);
            if (firststring > 0)
                {
                var i = firststring;
                var amount = finalvalue.substr(0,firststring);
                }else{
                var i = 3;
                var amount = finalvalue.substr(0,3)
            }
            while ( i < tester )
                {
                amount = amount+''+finalvalue.substr(i,3);
                i++;
                i++;
                i++;
                }
            }else{
             var amount = finalvalue;
            }
    }
    return amount;
}


function getHelp()
{
            var msg ="Thank you for using the First American Title Company of Napa's Seller's Net Proceeds Worksheet!\n"
    msg = msg+"Please be aware that the values produced are estimates that may vary from the actual title company figures.\n";
    msg = msg+"\n";
    msg = msg+"To test different scenarios, you can close the output window and edit and recalculate the values in the form until you are satisfied with the results.\n";
msg = msg+"\n";
    msg = msg+"If you have difficulty viewing the output window, please make sure that your browser is set to 'Allow Active Content' to run from your computer (Tools-Internet Options-Advanced tab-Security section in Internet Explorer). Also, please ensure that your Pop-Up Blocker is not preventing the window from opening.'\n";
msg = msg+"\n";
    msg = msg+"NOTE: Security settings will vary in other browsers, however JavaScript must be enabled."; 
msg = msg+"\n";
    msg = msg+"When printing the final output, you may want to adjust the page properties of your printer to maximize the printable area. If your printer supports advanced features and/or paper sizes, you may want to use legal-sized paper, or select \"Scale to Fit\" from the advanced output options.\n\n";
   alert(msg);
}

function getHelpTransferTax()
{
            var msg ="This value is calculated at $1.10 per $1,000 based upon Sales Price.\n"
    msg = msg+"\n";
    msg = msg+"Please be aware that the values produced are estimates that may vary from the actual title company figures.\n";

   alert(msg);
}