..........
Please wait
for the
wheel to
disappear
before
beginning.
Environmental Benefit calculator

First find the highest EB score that your property can earn,
then try different tank and rain-garden set-ups


L Stringybark Project main page Calculator main page

About this page...
This calculator works out the environmental benefit (EB) that you can achieve
using tanks or rain-gardens to keep stormwater on your property.
  • Start on the Property tab to find the maximum EB your property can score.
  • Then try different tank or rain-garden set-ups on the next two tabs.
  • The summary tab allows you to export a table that can be used to submit your
    stormwater tender.
  • The comparison tab allows you to compare the effects of varying tank size
    or tank-water uses on your EB score and the amount of water the tank will provide.
  • Fill in these details for your property and press the 'Step 1' button below:
    More info... If your property is part of the Stormwater Tender program (in the Little Stringybark Creek catchment,
    the NE part of Mt Evelyn, Melbourne, Victoria, Australia), we can give you estimates for your property,
    calculated from aerial photos and council records: contact Darren Bos: dbos@unimelb.edu.au
    Ph: 8344 9248 Mobile: 0447 551 522
    1. Hard surfaces that are connected to underground street drainage:
    Need help?
    Connected or unconnected?
    See the FAQ page for help
    
    #     if(sum(ls() %in% c("roofarea", "pavearea", "roofarea1", "hasseptic"))==0){  #, "pavearea1"
    #        roofarea <- pavearea <- roofarea1 <- ""                     #pavearea1 <- 
    #        hasseptic <- 0
    #                                                          }
         roofarea <- pavearea <- roofarea1 <- hasseptic <- hastank <- tab1 <- 0
         HTMLon()
         HTMLtag("table style='font-family:Arial; font-size:10pt'"); 
         HTMLtag("tr"); HTMLtag("td")
         cat("Roof area:"); HTMLtag("/td"); HTMLtag("td")
         HTMLinput("roofarea", roofarea, size = 5, id = "roof")
         cat("sq m")
         HTMLtag("/td"); HTMLtag("/tr");HTMLtag("tr"); HTMLtag("td")
         cat("Paved area:"); HTMLtag("/td"); HTMLtag("td")
         HTMLinput("pavearea", pavearea, size = 5, id = "pave")
         cat("sq m")
         HTMLtag("/td"); HTMLtag("/tr");HTMLtag("/table")
         HTMLoff()
        
    Tip...

    To calculate area, divide the roof or paving into rectangles;
    multiply the length and width (in metres) of each rectangle
    together to get the area in sq m; and add all the areas together
    2. Hard surfaces that drain to land (e.g. your garden),
    or are piped to an earthen, table drain in the street:


         HTMLon()
         HTMLtag("table style='font-family:Arial; font-size:10pt'"); 
         HTMLtag("tr"); HTMLtag("td")
         cat("Roof area:"); HTMLtag("/td"); HTMLtag("td")
         HTMLinput("roofarea1", roofarea1, size = 5, id = "roof1")
         cat("sq m")
         HTMLtag("/td"); HTMLtag("/tr"); HTMLtag("/table")
    #    HTMLtag("tr"); HTMLtag("td")
    #     cat("Paved area:"); HTMLtag("/td"); HTMLtag("td")
    #     HTMLinput("pavearea1", pavearea1, size = 5, id = "pave1")
    #     cat("sq m")
        HTMLoff()
        
    What about paving?

    Paved areas that drain to the underground street drainage are a
    problem for Little Stringybark Creek, and draining them to a
    rain-garden will reduce their impact. Paved areas that drain to
    your lawn or garden have virtually no impact on the creek (and
    are not a problem as long as they don't cause you a flooding
    problem). As a result, we do not include 'unconnected' paved
    areas in our Environmental Benefit calculations.
         HTMLon()
         cat("Does the property have a septic tank?  "); BR
         if(is.na(hasseptic)) hasseptic <- 0
         hasseptic <- as.numeric(hasseptic)
         if(hasseptic == 1){
         cat(HTMLradio(1, commonName = "hasseptic", text = "Yes", checked = TRUE), 
             HTMLradio(0, commonName = "hasseptic", "No, the property is connected to the sewer", id = "sep0"))
                               } else {
         cat(
             HTMLradio(1, commonName = "hasseptic", text = "Yes", id = "sep1"),
            HTMLradio(0, commonName = "hasseptic", "No, the property is connected to the sewer", checked = TRUE))
                                      }
         hasseptic <- as.logical(hasseptic)
          HTMLoff()
        
    Why this matters...

    We aim to keep nitrogen out of the creek. If you are connected to the sewer,
    any water that goes down your toilet etc. stays out of the creek because it
    goes to the sewage treatment plant.
    Unfortunately septic tanks convert nitrogen to a very mobile form that means
    that water used inside houses with septic tanks will likely end up in the creek.
    So a septic tank reduces (a little) the environmental benefit of using tank water.

         tab1 <- 1
         require(chron)
         if(roofarea == "" | roofarea1 == "" | pavearea == "" )  #| pavearea1 == "" 
          stop("Please enter a value in all boxes (can be zero).", call. = FALSE)
         if(sum(ls() == "hasseptic") == 0)
          stop("Please indicate if the property is connected to the sewer or has a septic tank.", call. = FALSE)
         hasseptic <- as.numeric(hasseptic)
         hasseptic <- ifelse(hasseptic,1,0)
         options(chron.origin = c(month = 1, day = 1, year = 1960))
         #hourly runoff data for 1965, 1967 and 1970
         #calculated using ...
         hro3y <- read.csv("/var/www/Rpad/Croydon hrly rainrunoff 656770.csv")
         hro3y <- data.frame(datetime = chron(as.character(hro3y$date), 
                                              as.character(hro3y$time),
                                              format = c(dates = "d/m/y", times = "h:m:s")),
                             date = chron(as.character(hro3y$date),
                                    format = c(dates = "d/m/y")),
                             year = hro3y$year, month = NA,
                             runoff.mm = hro3y$ir11,
                             daten = as.numeric(chron(as.character(hro3y$date),
                                    format = c(dates = "d/m/y"))))
         #ir11 rainfall with 1st mm of each event removed with at least 1h separating events
         hro3y$month <- month.day.year(hro3y$date)$month
         hro3y$year[hro3y$year == 1966] <- 1965  #the first year goes from April to March
         monthly.ET <- read.csv("/var/www/Rpad/monthly ET.csv")
         monthly.ET$ETmmh <- monthly.ET$ETmm.d/24
         hro3y$ETmmh <- monthly.ET$ETmmh[match(hro3y$month, monthly.ET$month)]
         dro3y <- read.csv("/var/www/Rpad/Croydon daily rainrunoff 656770.csv")
         dro3y <- data.frame(date = chron(as.character(dro3y$date),
                                          format = c(dates = "d/m/y")),
                             year = NA,
                             runoff.mm.d = dro3y$ir11, 
                             daten = as.numeric(chron(as.character(dro3y$date),
                                          format = c(dates = "d/m/y"))))
         dro3y$year <- month.day.year(dro3y$date)$year
         dro3y$year[dro3y$year == 1966] <- 1965   
         ann.harvestable <- aggregate(dro3y$runoff.mm.d*(roofarea + roofarea1)/1000,
                                 by = list(year = dro3y$year), sum)
         dro1y <- dro3y[dro3y$year < 1967,]
         hro1y <- hro3y[hro3y$year < 1967,]
         maxEBI <- round((0.2*(roofarea + roofarea1 + pavearea) +  #potential water index
                         0.3*((roofarea + pavearea) -
                         0.5*(hasseptic*(roofarea + roofarea1))) + #potential N index
                         0.5*(roofarea + pavearea))/100 ,2)  #potential stream index
         results <- data.frame(Summary = 
                               c("Tank","Rain-garden", "Total","Maximum achievable for this property"),
                               EB.score = c(0,0,0,maxEBI),
                               Water.savings.in.kL = c(0,0,0,round( mean(ann.harvestable[,2]),0)))
         HTMLon()
         HTMLtag("span style='font-size:11pt;'"); HTMLtag("b")
         cat("Your property has the potential to earn", maxEBI, "Environmental Benefit Units.")
         HTMLtag("/b"); HTMLtag("/span"); BR; BR
         #this assumes that half of water consumed goes to sewer/septic, and that if it goes to 
         #septic all of the nitrogen will be converted to nitrate and end up in the stream
         cat("An average Mt Evelyn house could earn ~2 units.")
         BR
         cat("To find how much of this potential you can achieve with a rainwater tank, go to the tank tab", BR,
             "or with a raingarden, go to the rain-garden tab",
             BR, "or with both a tank and a rain-garden, start by filling in tank details on the tank tab.")
         BR
         BR
         HTMLh5("More information on the potential environmental benefit of your property")
         cat("In an average year (with 901 mm of rainfall),  ")
         cat(round( mean(ann.harvestable[,2]),0))
         cat(" kilolitres (i.e.", round(mean(ann.harvestable[,2])*1000,-3), "litres) of water runs off a ")
         cat(roofarea + roofarea1, "sq.m. roof in Mt. Evelyn.")
         BR
         cat("Even in dry years, substantial volumes run off our roofs.  In a year with just 660 mm of rainfall - a possible future average with climate change -,
             your roof produces ", round(ann.harvestable[ann.harvestable$year == 1967,2],0),
              "kilolitres of water.  In Melbourne, average water consumption is 73 kilolitres per year per person, so there is great 
              potential for reducing our mains water usage, by collecting and using rainwater from our roofs.")
         BR; BR
         cat("Currently stormwater runoff from ",roofarea,"sq.m. of your roof, and",
         pavearea,"sq.m. of your paved area drains straight to Little Stringybark Creek on an average of 121 days a year.")
         BR
         cat("If runoff could be kept on the property for all but the biggest storms (12 or fewer days a year, 
              like before Mt Evelyn was developed), then your property's impact on the creek will be greatly reduced.")
         BR
         BR
         cat("You also have the potential to keep", round(2.2 * mean(ann.harvestable[,2])*(roofarea + pavearea)/((roofarea + roofarea1)*1000),2),
         "kg of the nitrogen in rainwater on your property each year, which helps protect the 
                     Yarra and  Port Phillip Bay.")
         BR
          HTMLtag("hr size=1 width='100%' align=center color='#008CD6'")
         HTMLoff()
           

         HTMLon()
         H("input", type="button", value="Step 1: Find the potential environmental benefit this property can earn",
           onclick= "javascript:thisPage.calcTab1()" )
        HTMLoff()
        


    Tank, rain-garden tabs?... Before going on to the tank and rain-garden tabs, make sure you press the
    'step 1' button to refresh any new information entered on this tab.

         HTMLon()
         HTMLtag("span style='font-size:10pt; color:red;'")
         H("input", type="button", value="Before using this tab, refresh it by clicking here",
           onclick= "javascript:thisPage.refreshTab2()" )
         HTMLtag("/span")
        HTMLoff()
        
            if(sum(ls() %in% c("percroof", "percroof1", "firstflush", "tankvol", "isgarden", "garden.area", "npeople",
                            "carfreq", "iscar", "istoilet", "iswmac", "ishw"))  == 0){
            firstflush <- tankvol <- carfreq <- garden.area <- percroof <- percroof1 <- npeople <- ""
            isgarden <- iscar <- istoilet <- iswmac <- ishw <- 0
                                                                           }
            if(sum(ls() %in% c("Af", "Ap", "perim")) == 0){Af <- NA; Ap <- NA; perim <- NA}
            ffto <- "land- not a rain-garden"
        
         source("/var/www/Rpad/tankmodel.R")
         HTMLon()
    #     if(sum(ls() %in% c("roofarea", "pavearea", "roofarea1", "hasseptic")) < 4 ){  #"pavearea1", 
    #     cat("Before filling in this form, you need to have filled in your property details on the
    #          Property tab", BR, "(If you have already filled in the
    #          property tab, press the 'refresh this tab' button.)", BR, BR)
    #                                                                                            }
    #     if(sum(ls() %in% c("roofarea", "pavearea", "roofarea1", "hasseptic")) < 4 ){  #"pavearea1", 
    #     stop("Please go to the Property tab", call. = FALSE)}
         if((roofarea == "0" & pavearea == "0" & roofarea1 == 0) | is.na(hasseptic)){  #pavearea1 == ""|
         cat("Before filling in this form, you need to have filled in all your property details on the 
                   Property tab", BR, "(If you have already filled in the
              property tab, press the above 'refresh tab' button.)", BR, BR)
                                                          }
    #     if(roofarea == "" | pavearea == "" | roofarea1 == "" | is.na(hasseptic)){  #pavearea1 == ""| 
    #               stop("Please go to the Property tab", call. = FALSE)}
    
         HTMLtag("b")
         cat("Roof area:")
         HTMLtag("/b")
         BR
    
         if(roofarea > 0 & roofarea1 == 0){
         percroof1 <- 0
         type <- "text"; type1 <- "hidden"
         cat("You estimated that your property has", roofarea, 
                   "sq m of roof connected to underground street drainage.", BR, 
                   "Enter the percentage of this 'connected' roof area that will drain to your tank below", BR,
                   "(Enter zero for the 'unconnected' roof area)." )
                             }
    
         if(roofarea1 > 0 & roofarea > 0){
         type <- "text"; type1 <- "text"
         cat("You estimated that your property has", roofarea, 
                   "sq m of roof connected to underground street drainage,", 
            BR,
            "and", roofarea1, 
                    "sq m of roof that drains to land or to an earthen drain (i.e. 'unconnected').", BR, 
            "Enter the percentage of 'connected' and 'unconnected' roof areas that will drain to your tank below." )
                           }
    
         if(roofarea1 > 0 & roofarea == 0){
         percroof <- 0
         type1 <- "text"; type <- "hidden"
         cat("You estimated that your property has", roofarea1, 
                    "sq m of roof that drains to land or to an earthen drain.", BR, 
                   "Enter the percentage of this 'unconnected' roof area that will drain to your tank below", BR, 
                   "(Enter zero for the 'connected' roof area)." )
                                    }                                
    
         HTMLoff()
    


    Tip... The larger the area you can capture
    with your tank, the better
         HTMLon()
         cat("Percentage of 'connected' roof area draining to tank:")
         HTMLinput("percroof", percroof, size = 3, type = "text", id="inpr")
         cat("%")
         BR
         cat("Percentage of 'unconnected' roof area draining to tank:")
         HTMLinput("percroof1", percroof1, size = 3, type = "text", id="inpr1")
         cat("%")
         BR; BR
         HTMLtag("b")
         cat("The tank:")
         HTMLtag("/b")
         cat(BR, "Volume of tank to be installed: ",
             HTMLinput("tankvol", tankvol, size = 6, id="intv"), "litres", BR, 
             "Volume of first flush")
         HTMLinput("firstflush", firstflush, size = 3, id="inff")
         cat("litres, to be diverted to ")
         HTMLselect("ffto", id = "selectffto", text = c("land- not a rain-garden",
                                                        "a rain-garden",
                                                        "the stormwater drain"), optionvalue = "" )
     
         HTMLoff()
    

    Tip...
    Tanks are typically 2000 to 10000 litres.
    While bigger tanks have bigger yields,
    the increase in yield diminishes as tanks get
    bigger. You can create some graphs (on the
    Tank comparisons tab) to explore this once
    you have pressed the button below.

    Tip...
  • First-flush diverters are common plumbing options for rainwater tanks
    They help keep contaminants out of the tank. Typically, they are diverted
    straight to the stormwater system, but to be eligible for Stormwater Tender
    first-flush diverters must drain to land or perhaps a rain-garden.
  • If you don't want a first-flush diverter, then set the 1st-flush volume to zero.
  • You can set the tank volume to zero if you have downpipes that you can't
    drain to a tank, but can have a first-flush diverter attached.
    This still has some environmental benefit.
  •       isgarden <- as.logical(isgarden); istoilet <- as.logical(istoilet)
          iswmac <- as.logical(iswmac); ishw <- as.logical(ishw)
         HTMLon()
         HTMLtag("b")
         cat("Uses:")
         HTMLtag("/b")
         cat(BR, "Check the uses that the tank water will be for:",BR)
             HTMLcheckbox("isgarden", text = "Garden watering") 
    #            HTMLcheckbox("iscar", text = "Car washing")                           
             HTMLcheckbox("istoilet", text = "Toilet flushing")
             BR
             HTMLcheckbox("iswmac", text = "Washing machine")
             HTMLcheckbox("ishw", text = "Hot water system,") 
          HTMLoff()
          isgarden <- as.numeric(isgarden); istoilet <- as.numeric(istoilet)
          iswmac <- as.numeric(iswmac); ishw <- as.numeric(ishw)
         

    Tip... These are the most common options that use a lot of water.
    Drinking water and water for car washing make very little
    difference to annual water yields, so we have left them out.
    There are some tips on using this calculator to test the
    effects of different uses on the tips and hints page.
    If you have an additional use for large volumes of water,
    that you would like to be included in your EB score for the
    Stormwater Tender program, please contact Darren Bos:
    dbos@unimelb.edu.au
    Ph: 8344 9248 Mobile: 0447 551 522
          HTMLon()
          HTMLtag("b")
          cat("Factors affecting usage patterns:")
          HTMLtag("/b")
          BR 
          cat("Number of people living on the property:  ")
          HTMLinput("npeople", npeople, size = 2, id="innp"); BR
          cat("Area of garden to be watered (not including any rain-gardens)")
          HTMLinput("garden.area", garden.area, size = 4, id="inga")
          cat("sq m"); BR
    #     cat("Number of car washes per year"); HTMLinput("carfreq", carfreq, value = 6, size = 4)
        

            if(tab1 == 0) {
            stop("Please fill in the Property tab, and press the step 1 button on that tab, before using this tab.", call. = FALSE)
                                           }
          if(length(ls()[ls() == "params"]) == 0){
            params <- c(1,0,999,432,100,1, 9) }
         if((percroof == "" & roofarea > 0) | (percroof1 == "" & roofarea1 >0))
          stop("Please enter a value in all boxes.", call. = FALSE)
         if(tankvol == 0){
          istoilet <- iswmac <- ishw <- garden.area <- 0; isgarden <- npeople <- 1
                  cat("Note: tank volume is zero.
                     These results model the effect of a first-flush diverter by itself.
                       ")
                         }
         if(tankvol == "" | firstflush == "" | npeople == "" |  garden.area == "") 
          stop("Please enter a value in all boxes.", call. = FALSE)
         if(sum(isgarden, istoilet, iswmac, ishw) == 0 & tankvol > 0)
          stop("Please select at least one use for your tank.", call. =  FALSE) 
            if(roofarea1 == 0 & percroof1 == "") percroof1 <- 0
            if(roofarea == 0 & percroof == "") percroof <- 0
          isgarden <- as.logical(isgarden); istoilet <- as.logical(istoilet)
          iswmac <- as.logical(iswmac); ishw <- as.logical(ishw)
          iscar <- 0
          if(npeople == 1)  npeople <- 2
          if(sum(c(tankvol, 
               (roofarea*percroof + roofarea1*percroof1)/100, firstflush, npeople, garden.area, hasseptic) != params) > 0){
          if(length(ls()[ls() == "garden.area"]) == 0 | garden.area == "") 
             stop("Please enter a value for garden area- zero if the tank won't be used for garden watering", call. = FALSE)
    #      if(length(ls()[ls() == "carfreq"]) == 0 | carfreq == "") 
    #         stop("Please enter a value for car washing frequency between 0 and 26", call. = FALSE)
          if(percroof > 100 | percroof < 0 | percroof1 > 100 | percroof1 <0)
             stop("Please make sure that percentage values are between 0
               and 100", call. =  FALSE)
                                                                                                                            }
    #      hasseptic <- ifelse(hasseptic,1,0)
          hastank <- TRUE
    #      carfreq <- as.numeric(carfreq)
          firstflush <- as.numeric(firstflush)
          propcon <- (roofarea*percroof)/(roofarea*percroof + roofarea1*percroof1)
    #      startvol <- tankstats(dailyrunoff = burninrain, tankvol = tankvol, tankbegin = tankvol/2, propcon=propcon,
    #                            firstflush =  firstflush, carea = (roofarea*percroof + roofarea1*percroof1)/100, 
    #                               npeople = npeople, garden.area = garden.area)$budget$store
    #      startvol <- startvol[dim(startvol)[1],]
          temp <- tankstats(dailyrunoff = dro3y, tankvol = tankvol, propcon=propcon,
                            carea = (roofarea*percroof + roofarea1*percroof1)/100, #tankbegin = startvol, 
                            npeople = npeople, firstflush =  firstflush, garden.area = garden.area)
    
          klsum <- function(x) {round(sum(x)/1000,1)}
          n.uses <- dim(temp$EBstats)[1]
          temp1 <- aggregate(temp$budget$use, by = list(dro3y$year), klsum)
          yieldrange <- data.frame(t(temp1[c(2,1,3),2:(n.uses + 1)])); 
          names(yieldrange) <- c("low","av","high")
          yieldrange$usage <- temp$EBstats$usage
          yieldrange$consumption <- temp$EBstats$consumption.kL.y
          row.names(yieldrange) <- NULL
    #we assume that tank water used indoor goes to sewer - if a property has a septic tank all the N in sewage
    # is assumed to make it to the stream as nitrate, so indoor uses are not included in the N index for 
    # unsewered properties
              if(hasseptic == 1){
          temp$EBstats$N.index <-  temp$EBstats$N.index*temp$EBstats$outdoor.consumption/temp$EBstats$consumption.kL.y
                                 }
          uses <- c(1*isgarden, 2*iscar, 3*istoilet, 4*iswmac, 5*ishw)
          match.use <- sum(uses[order(uses)] != temp$uses.matrix[1,order(temp$uses.matrix[1,])])
          for(i in 2:dim(temp$uses.matrix)[1]){
          match.use <- c(match.use,sum(uses[order(uses)] != temp$uses.matrix[i,order(temp$uses.matrix[i,])]))
          prefindex <- which(match.use == 0)
                                          }
    
          Nloadredn <- round(roofarea*percroof*temp$EBstats[prefindex,]$yield.kL.y*2.2/
                                        (1000*(roofarea*percroof + roofarea1*percroof1)),2)
    
          if(ffto == "the stormwater drain"){
          temp$EBstats$N.index <- round((temp$EBstats$yield.kL.y - (firstflush*121)/1000)/(0.7614*roofarea),2)/100
          temp$EBstats$stream.index <- ifelse(firstflush > 0, temp$EBstats$stream.index) 
                   if(roofarea == 0 & firstflush > 0){
                    temp$EBstats$N.index <- -1*firstflush*121/(761.4*roofarea1)
                    temp$EBstats$stream.index <- -roofarea1/100
                                       }
          Nloadredn <- round(Nloadredn - 2.2*firstflush*121/1000000, 2)
                                               }
          EBS <- ifelse(temp$EBstats$days.runoff[prefindex]>114, 0,
                        min(temp$EBstats$EBI[prefindex], (0.2*(roofarea + roofarea1) + 0.8*roofarea)/100))
                        #the ifelse is to account for the av days of runoff being 115 for the three years.
                        #ideally N.urban would be changed to 115 in tankmodel...but problem was discovered
                        #after tender process began (the difference in result is minor for most cases.
          results$EB.score[1:3] <- c(round(EBS,2),0,round(EBS,2))
          results$Water.savings.in.kL[c(1,3)] <- round(min(temp$EBstats[prefindex,]$yield.kL.y,
                                                           mean(ann.harvestable[,2])),0)
    
          HTMLon() # switch to html mode
         HTMLtag("span style='font-size:11pt;'"); HTMLtag("b")
         cat("This tank will earn an Environmental Benefit Score of",round(EBS,2))
         HTMLtag("/b"); HTMLtag("/span"); BR; BR
          cat("Your results so far.")
          Html(results)
         if(ffto == "the stormwater drain"){
               cat(BR, "Your score has been handicapped by diverting the
          first flush to the stormwater system, which doesn't reduce the
          number of days that stormwater runs to the creek from your
          property each year.", HTMLtag("b"),  "(This type of set-up is ineligible for
          stormwater tender.)", HTMLtag("/b"), " Try diverting the first flush to land or to a
          rain-garden.", BR)
                                             }
         if(ffto == "a rain-garden"){
               cat(BR, "You have opted to divert your first-flush to a
          rain-garden. This tab assumes that this first
          flush has no environmental impact, but it will be included as
          part of the inflow into your raingarden on the next tab.", BR)
                                     }
           if(temp$EBstats[prefindex,]$yield.kL.y < 0.8*mean(ann.harvestable[,2])){
                cat(BR, "To increase the yield of water you can harvest from this tank, try more uses or a bigger tank ")
                                                                                 }
          if(temp$EBstats[prefindex,]$yield.kL.y < 0.8*mean(ann.harvestable[,2]) & percroof + percroof1 < 200){
                cat("or try connecting more of your available roof area")
                                                                                                             }
          if(temp$EBstats[prefindex,]$EBI < 0.85*maxEBI & percroof*roofarea > 0){
                cat(BR, "To increase your property's EB score, 
               try adding a raingarden to take", ifelse(pavearea > 0, "runoff from paved areas and",""),
               "overflow from your tank:  see the rain-garden tab") 
                                                                                } 
          if(temp$EBstats[prefindex,]$EBI > 0.95*maxEBI & percroof*roofarea > 0){
                cat(BR, "It doesn't get much better than that, but you might want to check if you can achieve nearly as 
                       good an EB score for less cost")} else {
          if(temp$EBstats[prefindex,]$EBI >= 0.85*maxEBI & percroof*roofarea > 0){
              cat("This system captures", round(100*temp$EBstats[prefindex,]$yield.kL.y/mean(ann.harvestable[,2],0)), 
               "% of runoff from your roof, and gives you ",
               round(100*temp$EBstats[prefindex,]$EBI/maxEBI,0), 
               "% of your property's potential EB score. That's good, but if you're not satisfied with that, try adding a raingarden to see if you can improve your score.  See the rain garden tab")
                                                                                  }
                                                                                 }
           if(percroof*roofarea == 0 & pavearea == 0){
            cat(BR, BR, "As no roof or paving on your property is connected to the underground
                 street drainage, a rain-garden is not recommended for your property.")
                                      }
           if(pavearea > 0) {
            cat(BR,BR, "A rain-garden is a great way to retain runoff from your paved areas: see the rain-garden tab")
                              }
          cat(BR, BR, "To visualize the effects of usage and tank size on water yield and EB score, try the Comparison tab.")
           BR; BR
          cat("This tank will improve the environment by:")
           BR
          cat("supplying", round(temp$EBstats[prefindex,]$yield.kL.y,0),"kilolitres of water per year;", 
              "which is about", round(100*temp$EBstats[prefindex,]$yield.kL.y/mean(ann.harvestable[,2],0)), 
               "% of runoff from your roof.")
          if(percroof*roofarea > 0){
          cat(BR, "reducing runoff to Little Stringybark Creek by ",
                    121 - temp$EBstats[prefindex,]$days.runoff, "days each year;",
           BR,
          "and keeping", Nloadredn,
                     "kg of nitrogen out of the creek each year;")
                                             }
          BR
          HTMLtag("hr size=1 width='100%' align=center color='#008CD6'")
          HTMLoff()
         


         HTMLon()
         H("input", type="button", value="Before using this tab, refresh it by clicking here",
           onclick= "javascript:thisPage.refreshTab3()" )
        HTMLoff()
        
                  if(sum(ls() %in% c("carea.garden", "carea.garden1","isveg", "Hp", "Hf",
                            "medium", "isoutlet", "Ho", "lined.bottom", "lined.side", "perc.pavearea", 
                            "perc.roofarea", "shape", "dim1", "dim2", "deltaAp", "shapesel"))  == 0){
            if(roofarea1 == 0 & percroof1 == "") percroof1 <- 0
            if(roofarea == 0 & percroof == "") percroof <- 0
            carea.garden <- carea.garden1 <- Ap <- Af <- Hp <- Hf <- medium <- Ho <- perc.pavearea <- ""
            shape <- dim1 <- dim2 <- deltaAp <- perc.roofarea <- ""
            lengtha <- lengthb <- shapesel <- ""
            isveg <- currentshape <- 1
            isoutlet <- lined.bottom <- lined.side <- lined.walls <- 0
                                                                           }
            shapes <- data.frame(n = 1:4, 
                                 shape.desc = c("Select the shape that best describes the surface of your raingarden",
                                                "rectangular","circular or oval","irregular"),
                                 shape = c("","rectangle", "circle", "irreg"))
         
    The rain-garden's catchment


            HTMLon()
              HTMLcheckbox(name = "overflow", text="")
         BR
            HTMLoff()
         
         source("/var/www/Rpad/gardenmodel.R")
         HTMLon()
         if(sum(ls() == "hastank") == 0)  hastank <- 0
             if(hastank == 0) {
                               percroof <- 0; overflow <- 0
                               }
         if(sum(ls() %in% c("roofarea", "pavearea", "roofarea1", "hasseptic")) < 4 ){
         cat("Before filling in this tab, you need to have filled in your
              property details on the Property tab", BR, "(If you have already filled in the
              property tab, press the 'refresh this tab' button.)",BR, BR)
                                                                                                }
    #     if(sum(ls() %in% c("roofarea", "pavearea", "roofarea1", "hasseptic")) < 4 ){
    #     stop("Please go to the property details page", call. = FALSE)}
         if(roofarea == "" | pavearea == "" | roofarea1 == "" ){  #| is.na(hasseptic) | is.na(hastank)){
         cat("Before filling in this tab, you need to have filled in all
              your property details on the Property tab", BR, "(If you have already filled in the
              property tab, press the 'refresh this tab' button.)",BR, BR)
                                                                                                }
    #     if(roofarea == "" | pavearea == "" | roofarea1 == "" | is.na(hasseptic)){
    #               stop("Please go to the Property tab", call. = FALSE)}
    
         if(hastank == 1){
         cat("You chose a tank that will receive runoff from", round((roofarea*percroof + roofarea1*percroof1)/100,0), 
             "sq m of roof.", BR, "Check the box on the left if the tank will overflow into the rain-garden", BR)
                    } else {
         cat(HTMLtag("i"),"You have chosen a rain-garden and no rainwater tank.", HTMLtag("/i"), BR, BR,     
         "You listed the following 'connected' surfaces.", BR, 
         "The checkbox on the left is only relevant if you selected a tank
            and completed the Tank tab: please ignore (or revisit the tank
            tab).", BR)
                           }
    
        if(hastank & pavearea + roofarea*(percroof - 100) == 0){
         cat("The only runoff the rain-garden will receive is overflow
         from the tank. The next two boxes can be left as they are.", BR)
       } else {
         cat("You listed the following 'connected' surfaces that do not drain to
          the tank.",BR)}
    
        if(roofarea > 0 & percroof < 100) {
         cat(round(roofarea*(100-percroof)/100,0), "sq m of roof.", BR)
       } else {cat("")}
        if(pavearea > 0){
          cat(round(pavearea,0), "sq m of paved area", BR)
          }else {cat("")}
    
         if(roofarea1 > 0 & roofarea == 0 & pavearea == 0){
            cat("The Property tab lists no roof or paved area that are connected to the underground street drainage.", BR,
                "If this is correct, a rain-garden will not reduce your property's impact on Little Stringybark Ck.", BR,
                "You can only earn an Environmental Benefit score with a rainwater tank (see the Tank tab)", ".", BR)
                                                         } else {
         if(roofarea1 > 0 & percroof1 < 100){
               cat(BR, "There are", paste(round(roofarea1*(100-percroof1)/100,0)), 
             "sq m of roof area not going to the tank not connected to the underground street drainage.",
              "A rain-garden will not reduce the impact of these surfaces on Little Stringybark Ck,",
              "and this calculator does not allow the option of draining these sorts of surfaces to a rain-garden.",
            BR,BR)
                                            }
                                                                  }
    
        if((hastank & pavearea + roofarea*(percroof - 100) > 0) | !hastank )
        cat("Enter the percentage of each area that will drain
         to the rain-garden in the boxes below. (Leave as 100 if not
         relevant.)", BR)
         HTMLoff()
        
             HTMLon()
             cat("Percentage of 'connected' roof area (not draining to a tank) that will drain to rain-garden: ") 
             HTMLinput("perc.roofarea", perc.pavearea, size = 3, value= 100, id="prain")
             cat("%"); BR
             cat("Percentage of 'connected' paved area draining to rain-garden: ") 
             HTMLinput("perc.pavearea", perc.pavearea, size = 3, value= 100, id="ppain")
             cat("%")
             HTMLoff()
          

    The rain-garden's design

     #       system(paste("cp /var/www/Rpad/images/rectangle.png", RpadURL(), sep=" "))
           HTMLon()
            HTMLselect("shapesel", as.vector(shapes$shape.desc), id="shapeSelect" ,value = currentshape)
            HTMLoff()
        
    Tip... The size of your raingarden is one of the most important features that affect its performance.
    From the dropdown list, choose the shape that best describes the raingarden at its surface.
    If you are unsure, select one, and drawings will appear to help you decide.
    Once you have decided on a shape, fill in the dimension values in the boxes next to the drawing.
            currentshape <- which(shapes$shape.desc == shapesel)
            shape <- shapes$shape[shapes$shape.desc == shapesel]
             HTMLon()
            HTMLtag("table"); HTMLtag("tr"); HTMLtag("td"); HTMLtag("span style='font-size:10pt;'")
           if(shapesel == "Select the shape that best describes the surface of your raingarden"){
            cat(
            "Select a shape from the dropdown", BR, "box above before putting numbers", BR, 
            "in these boxes")
                              }
            if(shapesel == "rectangular"){
            HTMLembed("rectangle.png", ALT = "Rectangular raingardens",
            width=153, height=207)
                                      }
            if(shapesel == "circular or oval"){
            HTMLembed("ellipse.png", ALT = "Oval or circular raingardens",
            width=153, height=207) 
                                      }
            if(shapesel == "irregular"){
             HTMLembed("irreg.png", ALT = "Irregular raingardens",
            width=153, height=207)
                                        }
            HTMLtag("/td"); HTMLtag("td valign='center'"); HTMLtag("/span")
            HTMLtag("span style='font-family:Arial; font-size:10pt';")
            if(shapesel == "Select the shape that best describes the surface of your raingarden"){
            cat("")
                              }
            if(shapesel == "rectangular"){
            cat(
            "Length in metres", BR, "Width in metres")
                                      }
            if(shapesel == "circular or oval"){
            cat(
            "Length a in metres", BR, "Length b in metres")
                                      }
            if(shapesel == "irregular"){
            cat(
            "Area in sq metres", BR, "Perimeter in metres")
                                       }
            HTMLtag("/span")
            HTMLtag("/td"); HTMLtag("/tr"); HTMLtag("/table")
            HTMLoff()
         
            HTMLon()
            HTMLinput("dim1", dim1, size = 3, id = "ddim1")
            BR
            HTMLinput("dim2", dim2, size = 3, id = "ddim2")
            HTMLoff()
        
         HTMLon()
         cat("How much bigger is the area at the top of the basin than at its bottom?")
         HTMLinput("deltaAp", deltaAp, size = 3, id = "dAp")
         cat("%")
         HTMLoff()
        
    Tip...
    See the drawing below for a plan of a typical raingarden.
    The filter is the main part of the garden filled with sand, soil or gravel (the filter medium).
    The basin is the top, walled bit above the filter that will occasionally fill with water.
    Enter 0% if there is no basin (e.g. if you are building an infiltration system under your lawn)
    Enter 0% if the basin walls are vertical, and the basin is the same area as the filter.
    Enter 10% if the basin area is 10% bigger than the filter area.
            HTMLon()
            cat("Check here if the rain-garden has plants:")
            HTMLcheckbox("isveg", text = "")
            HTMLoff()
       
    Tip... See the drawing below for a plan of a typical raingarden.
    Most raingardens will have plants, but infiltration systems won't.
    If you are building an infiltration system below your lawn, select 'No' here,
    because the filter will be separated from the lawn by a geotextile layer.
    Stormwater tender requires that at least half of the plants in rain-gardens
    are from the recommended list of plants (See the FAQ page)

    Plan of generic raingarden
            lined.side <- lined.bottom <- 0
            HTMLon()
            isoutlet <- as.numeric(isoutlet)
            isoutlet <- as.numeric(isveg)
            lined.bottom <- as.numeric(lined.bottom)
            lined.side <- as.numeric(lined.side)
            cat("How deep is the basin?  ")
            HTMLinput("Hp", Hp, size = 4, id = "inHp")
            cat("cm"); BR
            cat("How deep is the filter?")
            HTMLinput("Hf", Hf, size = 4, id = "inHf")
            cat("cm"); BR; BR
            cat("What medium is the filter filled with?"); BR
            HTMLselect("medium", text = c("sand", "loamy sand",
                       "gravel (scoria)"), id="selectmedium", optionvalue = "1" ); BR; BR
            cat("Check here if the rain-garden has an outlet pipe:")
            HTMLcheckbox("isoutlet", text = ""); BR
            cat("If so, how high from the bottom is it?")
            HTMLinput("Ho", Ho, size = 3, id = "inHo")
            cat("cm"); BR; BR
            cat("Check here if the bottom of the rain-garden is lined:")
            HTMLcheckbox("lined.bottom", text = ""); BR
            cat("Check here if the sides of the rain-garden are lined:")
            HTMLcheckbox("lined.side", text = ""); BR
            HTMLoff()
        
    Tip... Basins are typically 10-30 cm deep,
    to allow for a short period of ponding during heavy rain.
    Filters are typically 50-100 cm deep






    Tip... The effect of an outlet pipe on EB score depends on the size of the rain-garden
    (relative to its catchment area). An outlet pipe will generally reduce the
    EB for large rain-gardens, but can improve EB for smaller rain-gardens (if they
    placed high in the filter).
    If the rain-garden is lined, they will need an outlet pipe.





    Tip... Generally, rain-gardens will perform better if they are unlined,
    but if the rain-garden is built very close to a building or road, then the sides
    and bottom should be lined. If you plan to build the raingarden within 5 metres of
    a building, seek advice.


            if(tab1 == 0) {
            stop("Please fill in the Property tab, and press the step 1 button on that tab, before using this tab.", call. = FALSE)
                                           }
            if(shape == "")
            stop("You must select a shape for your raingarden from the dropdown box above", call. = FALSE)
             if(dim1 == "" | dim2 == "" | Hp == "" |Hf == "" | 
               medium == ""| ((Ho == "" | is.na(Ho)) & isoutlet == 1))
             stop("Please enter a value in all boxes.", call. = FALSE) 
             if(pavearea == 0) {perc.pavearea <- 0} else {perc.pavearea <- as.numeric(perc.pavearea)}
             if(roofarea*(100-percroof)/100 == 0) {perc.roofarea <- 0} else {perc.roofarea <- as.numeric(perc.roofarea)}
             carea.garden <- perc.roofarea*roofarea*(100-percroof)/10000 + pavearea*perc.pavearea/100
          if(perc.roofarea > 100 | perc.roofarea < 0 | perc.pavearea > 100 | perc.pavearea <0)
             stop("Please make sure that percentage values are between 0
            and 100", call. =  FALSE)
          if(hastank == 0) overflow <- 0
          tankoverflow <- as.numeric(overflow); Ho <- as.numeric(Ho); Hp <- as.numeric(Hp); Hf <- as.numeric(Hf)
          if(carea.garden == 0 & tankoverflow == 0)
           stop("No 'connected' roof area or paved area has been identified as draining to this rain-garden", call. = FALSE)
          if(carea.garden == 0 & tankoverflow == 1)
           cat("Note: you have opted for the raingarden to only receive
            overflow from the tank, and no other runoff.")
          deltaAp <- as.numeric(deltaAp); lined.bottom <- as.numeric(lined.bottom); lined.side <- as.numeric(lined.side)
          if(lined.bottom == 1 & lined.side == 0)
             stop("If the sides are unlined, the bottom should be too", call. = FALSE)
          if(isveg & medium == "gravel (scoria)")
             stop("Sorry: the calculator does not allow vegetated gravel systems", call. = FALSE)
          isveg <- as.numeric(isveg)
          if(isveg) {ET <- hro1y$ETmmh} else {ET <- rep(0,length(hro1y$ETmmh))}
          if(tankoverflow == 0 | ffto != "a rain-garden"){ firstflushtorg <- 0} else {firstflushtorg <- firstflush}
          if(shape == "circle"){
              Af <- round(pi*dim1*dim2*0.25,1)
              perim <- round(pi*(3*(dim1*0.5 + dim2*0.5) - ((1.5*dim1 + 0.5*dim2)*(0.5*dim1 + 1.5*dim2))^0.5),1) 
                           #Ramanujan's approximation formula from Wikepedia
                                }
          if(shape == "rectangle"){
              Af <- dim1*dim2; perim <- 2*dim1 + 2*dim2
                                   }
          if(shape == "irreg"){
              Af <- dim1; perim <- dim2
                                    }
          Ap <- (100 + deltaAp)*Af/100
          isoutlet <- as.numeric(isoutlet)
          if(isoutlet == 1 & Ho > Hf)
            stop("Outlet pipe height cannot be greater than filter depth", call. = FALSE)
          if(isoutlet == 0) 
              Ho <-  Hf + Hp
      ctank <- ifelse(tankoverflow, (roofarea*percroof + roofarea1*percroof1)/100, 0) 
      prop.pave <- ifelse(carea.garden == 0, 0, pavearea*perc.pavearea*0.01/carea.garden)
          if(tankoverflow){
                  gardenQin <- compile.inflow(hrunoff = hro1y,
                                      carea = carea.garden,
                                      doverflow = data.frame(date = dro1y$daten,
                                                             Qover = temp$budget$overflow[dro3y$year < 1967,prefindex]), 
                                      firstflush = firstflushtorg, 
                                      carea.tank = ctank)
                  Qin <- gardenQin$inflow
                           } else {
                  Qin <- data.frame(datetime = hro1y$datetime,
                                date = hro1y$date,
                                year = hro1y$year,
                                month = hro1y$month,
                                Qin = hro1y$runoff.mm * carea.garden)
                                   }
          gardenstats <- gardenmodel(inflow = Qin,
                         hrunoff = hro1y,
                         et = ET,
                         Af = Af, Pf = perim,   #sq m and m
                         Hf = Hf/100,   #m converted from cm
                         Ap = Ap,       #sq m
                         Hp = Hp/100,
                         isveg = isveg,   #m converted from cm
                         Ho = Ho/100,   #m converted from cm
                         medium = medium,
                         lined.bottom = lined.bottom, lined.side = lined.side,
                         Vstart = 0.5*0.4*Hf*Af*10,   #L, converted from cm and  sq m, assumes half-full and porosity of 0.4
                         carea = carea.garden, 
                         carea.tank = ctank,
                         prop.pave = prop.pave)
    
             if(tankoverflow == 1){
         N.index.garden <- gardenstats$EBstats$N.index - temp$EBstats$N.index[prefindex]
          #16/5/08 term '- temp$EBstats$N.index[refindex]' in above line replaces '*carea.garden/(carea.garden + ctank)'
           if(gardenstats$EBstats$days.runoff > temp$EBstats$days.runoff[prefindex]){
         stream.index.garden <- gardenstats$EBstats$stream.index*carea.garden/(carea.garden + ctank)
         #ie if the tank works better than the raingarden, then the tank's stream index takes priority
         #and the garden stream index is weighted to include on the area not treated by the tank
         #the total stream index is the tank's stream index + plus this weighted index
                                   } else {
         stream.index.garden <- gardenstats$EBstats$stream.index - temp$EBstats$stream.index[prefindex]
         #ie if the tank works worse than the garden, the garden's stream index takes priority
         #and the total stream index is the garden's index.
                                           }
         EBI.total <- (1- prop.pave)*(0.5*(stream.index.garden + temp$EBstats$stream.index[prefindex])
                                 + 0.3*gardenstats$EBstats$N.index
                                 + 0.2*temp$EBstats$water.index[prefindex]) + 
                      (prop.pave)*(0.625*(stream.index.garden + temp$EBstats$stream.index[prefindex]) +
                                       0.375*gardenstats$EBstats$N.index)       
    #     EBI.garden <- prop.pave*(0.625*stream.index.garden + 0.375*N.index.garden) + 
    #                   (1 - prop.pave)*(0.5*stream.index.garden + 0.3*N.index.garden)       
         results$EB.score[1:3] <- c(round(EBS,2),
                                    round(EBI.total - EBS, 2),
                                    round(EBI.total, 2))
    #                                round(EBI.garden, 2), 
    #                                round(EBI.garden + EBS, 2))
           }else{
         results$EB.score[2:3] <- c(round(gardenstats$EBstats$EBI,2), round(gardenstats$EBstats$EBI + results$EB.score[1],2))
                            }
          HTMLon() # switch to html mode
          HTMLtag("hr size=1 width='100%' align=center color='#008CD6'")
          HTMLtag("span style='font-size:11pt;'"); HTMLtag("b")
          cat(ifelse(hastank == 1, 
                  paste("This combined rainwater tank and rain-garden system will earn", BR, "a total 
                        Environmental Benefit Score for your property of", round(results$EB.score[3],2)), 
                  paste("This rain-garden will earn an 
                        Environmental Benefit Score of", round(results$EB.score[3],2))))
         HTMLtag("/b"); HTMLtag("/span"); BR; BR
         cat("The results for your property so far")
         Html(results)
          BR
          if(hastank == 0){
          cat("(This EB score includes no rainwater tank.  To include a tank, see the Tank tab", ".)", BR, BR, 
              "This rain-garden will improve the environment by:", BR,
              "producing runoff to Little Stringybark Creek ",  121 - gardenstats$EBstats$days.runoff, 
              "fewer days each year;", BR,
              "and keeping",round(gardenstats$EBstats$Nkg.reduction, 2),
              "kg of nitrogen out of the creek each year.", BR, BR)
                         }  else {
          if(overflow == 0){
          cat("This combined rainwater tank and rain-garden system will improve the environment by:", BR,
              "supplying", round(temp$EBstats[prefindex,]$yield.kL.y,0),"kilolitres of water per year;", BR,
             "keeping",round(gardenstats$EBstats$Nkg.reduction, 2),"kg of nitrogen out of the creek each year;",BR,
             " and producing runoff to Little Stringybark Creek from the property ",
             121 - max(gardenstats$EBstats$days.runoff, temp$EBstats$days.runoff[prefindex]), "fewer days each year.", BR)
                                  } else {
          cat("This combined rainwater tank and rain-garden system will improve the environment by:", BR,
              "supplying", round(temp$EBstats[prefindex,]$yield.kL.y,0),"kilolitres of water per year;", BR,
             "keeping",round(gardenstats$EBstats$Nkg.reduction, 2),"kg of nitrogen out of the creek each year;",BR,
             " and producing runoff to Little Stringybark Creek from the property ",
             121 - gardenstats$EBstats$days.runoff, "fewer days each year.", BR)
                                          }
                                  }
          if(medium == "loamy sand" & isveg == 0 & isoutlet == 1){
              cat("Unvegetated rain-gardens with soil like loamy sand actually leak more nitrogen than drains into them, 
                  so they should be avoided.  You will score a much better EB score with recommended vegetation in your
                  raingarden, or if you do not have an outlet pipe.  Try each solution separately and together.")
                                                                   } 
          if(hastank == 1 & overflow == 1){
              cat(ifelse(gardenstats$EBstats$days.runoff > temp$EBstats[prefindex,]$days.runoff,
             paste(BR, "Note that the raingarden produces runoff from the property more frequently (", gardenstats$EBstats$days.runoff,
             " days per year) than the rainwater tank does (", temp$EBstats[prefindex,]$days.runoff,
              " days per year).  This is because the raingarden is having to deal with runoff from a greater area than
              the rainwater tank. A larger rain-garden might improve this performance, or you might get a higher score 
              for this rain-garden by not directing the tank overflow into it.", BR, BR),
              paste(BR, "The raingarden is improving the performance of your tank, by retaining overflow from the tank and
              runoff from other surfaces", temp$EBstats[prefindex,]$days.runoff - gardenstats$EBstats$days.runoff, 
              "more days than the tank alone.  ")))
                      }
              if(hastank == 1 & gardenstats$EBstats$days.runoff > 12){ 
                 cat("A larger", ifelse(lined.bottom | lined.side, ", unlined", ""), "rain-garden might improve performance even more.", BR, BR)
                                                                   }
          BR
          BR
         HTMLoff()
         


         oldpercroof <- percroof
         oldoverflow <- overflow
         hastank <- 0; overflow <- 0
         oldresults <- results
         results[1,2:3] <- c(0,0); results[3,3] <- 0;
         HTMLon()
         HTMLtag("b")
         HTMLtag("span style='color:red; font-size:10pt'")
         cat("NOTE: tank details have been cleared.")
         HTMLtag("/b")
         HTMLtag("/span")
         HTMLoff()
        
         percroof <-  oldpercroof
         overflow <- oldoverflow  
         results <- oldresults
         hastank <- 1
         HTMLon()
         HTMLtag("b"); HTMLtag("i")
         HTMLtag("span style='color:green; font-size:10pt'")
         cat("and now  tank details have been restored.")
         HTMLtag("/b"); HTMLtag("/i")
         HTMLtag("/span")
         HTMLoff()
     
        

    To clear your rainwater tank details and calculate the benefit of the raingarden
    without a tank, press this button
    To restore your tank details and recalculate this page


           HTMLon()
           cat("For your selected uses and other set-up details, compare your selected tank size with the following tank
           sizes (you can change these values, but keep commas separating
           them)")
           BR; BR
           H("input", type="text", name="tanklist", value="1000, 2500, 5000, 10000, 20000", id= "tl", size="50")
           BR
          HTMLoff()
           

    tanklist <- as.numeric(strsplit(tanklist,",")[[1]]) tanklist <- unique(c(round(tankvol/5,-2)*5,tanklist)); tanklist <- tanklist[order(tanklist)] EBtanks <- data.frame(tankvol = NA, EBI = NA, yieldav = NA, yielddry = NA, yieldwet = NA) for(i in 1:length(tanklist)){ EBtanks[i,1] <- tanklist[i] EB <- tankstats(dailyrunoff = dro3y, tankvol = tanklist[i], carea = (roofarea*percroof + roofarea1*percroof1)/100, #tankbegin = startvol, npeople = npeople, firstflush = firstflush, garden.area = garden.area) klsum <- function(x) {round(sum(x)/1000,1)} EBtanks[i,3:5] <- aggregate(EB$budget$use[,prefindex], by = list(dro3y$year), klsum)[,2] #we assume that unconnected surfaces have no existing impact on streams or on N export, so discount #these areas in calculation of stream and N indices if(roofarea1*percroof1 >0){ EB$EBstats$stream.index <- percroof*roofarea*EB$EBstats$stream.index/(percroof*roofarea + percroof1*roofarea1) EB$EBstats$N.index <- percroof*roofarea*EB$EBstats$N.index/(percroof*roofarea + percroof1*roofarea1) } #we assume that tank water used indoor goes to sewer - if a property has a septic tank all the N in sewage # is assumed to make it to the stream as nitrate, so indoor uses are not included in the N index for # unsewered properties if(hasseptic == 1){ EB$EBstats$N.index <- EB$EBstats$N.index*EB$EBstats$outdoor.consumption/EB$EBstats$consumption.kL.y } EB$EBstats$EBI <- apply(cbind(EB$EBstats$N.index,EB$EBstats$water.index,EB$EBstats$stream.index),1,mean) EBtanks[i,2] <- EB$EBstats$EBI[prefindex] } par(mar = c(3.6,3.6,2,2)) plot(EBtanks$tankvol/1000, EBtanks$yieldav, ylim = c(0,max(ann.harvestable[,2])), las = 1, type= 'b',,col="blue", xlab = "Tank volume (kL)", ylab = "Annual yield from tank (kL)") ebars(x = EBtanks$tankvol/1000, y0 = EBtanks$yieldav, y1 = EBtanks$yielddry, y2 = EBtanks$yieldwet, col="blue") abline(h = mean(ann.harvestable[,2]), col = "red") mtext(paste("Yields from tanks draining", (roofarea*percroof + roofarea1*percroof1)/100,"sq m roof in a",npeople,"person house", sep = " "), cex= 0.75, padj = -1,col="blue") mtext(paste("used for",temp$EBstats$usage[prefindex], sep = " "), cex= 0.75, padj = 1,col="blue") text(mean(range(EBtanks$tankvol))/1000,mean(ann.harvestable[,2]),"Max. yield from full roof area (in an average year)", col="red", cex=0.6, adj = c(0.5,1)) text(7,0.14*max(ann.harvestable[,2]),"Tops of ranges: yield in a wet year (1970)", col="blue", cex=0.6, pos = 4) text(7,0.07*max(ann.harvestable[,2]),"Points: yield in an average year (1965)", col="blue", cex=0.6, pos = 4) text(7,0,"Bottoms of ranges: yield in a dry year (1967)", col="blue", cex=0.6, pos = 4) plot(EBtanks$tankvol/1000, EBtanks$EBI, ylim = c(0,maxEBI), las = 1, type= 'b',,col="blue", xlab = "Tank volume (kL)", ylab = "Environmental Benefit score") abline(h = maxEBI, col = "red") mtext("EB score earned in relation to tank size",cex= 0.75, padj = -1,col="blue") text(mean(range(EBtanks$tankvol))/1000,maxEBI,"Maximum EB score that this property can earn", col="red", cex=0.75, adj = c(0.5,1)) HTMLon() # switch to html mode showgraph() HTMLoff()
           HTMLon()
           BR
           H("input", type="button", value="Show effect of different tank sizes on your  property",
              onclick= "javascript:rpad.calculateTree(dojo.byId('tab5b'))")
           BR; BR
          HTMLtag("i")
          cat("Warning: these plots will take at least 10 seconds to calculate")
          HTMLtag("/i")
          BR; BR
          HTMLoff()
           
    #      carfreq <- as.numeric(carfreq)
          ann.harvestable <- aggregate(dro3y$runoff.mm.d*(roofarea + roofarea1)/1000,
                                 by = list(year = dro3y$year), sum)
          rankcons <- order(temp$EBstats$consumption.kL.y)
          EBstats <- temp$EBstats[rankcons,]
          yieldrange <- yieldrange[match(EBstats$usage,yieldrange$usage),]
          plot.new() 
          n.uses1 <- length(-grep("other", EBstats$usage))  
          legend("bottomright",legend = yieldrange$usage[-grep("other", EBstats$usage)],pch = c(letters,1:8)[1:n.uses1],col="blue",cex = 0.6, 
               title = "average(1965) - dry(1967) + wet year(1970)")
          par(mar = c(3.6,3.6,2,2))
          plot(yieldrange$consumption[-grep("other", EBstats$usage)], yieldrange$av[-grep("other", EBstats$usage)], 
             ylim = c(0,ceiling(max(ann.harvestable[,2]))),
             pch = c(letters,1:8)[1:n.uses1], las = 1, col = "blue", cex = 0.8,
             xlab = "Total annual demand (kL)", ylab = "Annual yield from tank (kL)")
          mtext(paste("Yield from",tankvol/1000,"kL tank draining",
                   round((roofarea*percroof + roofarea1*percroof1)/100,0),"sq m roof in a",npeople,"person house", sep = " "), cex= 0.75, padj = -1,col="blue")  
          ebars(x = yieldrange$consumption[-grep("other", EBstats$usage)], 
                y0 = yieldrange$av[-grep("other", EBstats$usage)], 
                y1 = yieldrange$high[-grep("other", EBstats$usage)], 
                y2 = yieldrange$low[-grep("other", EBstats$usage)], col="blue")
          abline(h = mean(ann.harvestable[,2]), col = "red")
          text(mean(range(yieldrange$consumption)),mean(ann.harvestable[,2]),"Max. yield from full roof area (av. for 3 years)",
               col="red",cex=0.6,adj = c(0.5,1))
          plot(EBstats$consumption.kL.y[-grep("other", EBstats$usage)],EBstats$EBI[-grep("other", EBstats$usage)],ylim = c(0,maxEBI),
             pch = c(letters,1:8)[1:n.uses1], las = 1, col = "blue", lwd = 2, cex = 0.8,
              xlab = "Total annual demand (kL)", ylab = "Environmental benefit score", type = 'b')
          abline(h = maxEBI, col = rainbow(6)[1])
          text(mean(range(yieldrange$consumption)),maxEBI,
             paste("Max EBI from",roofarea + pavearea,"sq m (to pipes), ", roofarea1, "sq m (to land)", sep = " "),
               col=rainbow(6)[1],cex=0.6,adj = c(0.5,1))
           mtext("Environmental benefit score", cex= 0.75, padj = -1,col="blue")      
          HTMLon()
          showgraph()
          BR
          HTMLtag("i")
          cat("You might get different relationships between different uses if you change percentage of roof area, tank size and 
          other factors on the tank calculator page")
          HTMLtag("/i")
          HTMLoff()
             

           HTMLon()
           H("input", type="button", value="Compare water savings with different uses of your tank water",
              onclick= "javascript:rpad.calculateTree(dojo.byId('tab5a'))")
           BR
           HTMLoff()
           
    Display a table summarizing results, and a second summarizing values entered for this property on the other tabs of this page. You will find a link to download the second table below it.


        summ <- read.csv("/var/www/Rpad/summarytemplate.csv")
        if(sum(ls() %in% c("percroof", "percroof1", "firstflush", "tankvol", "isgarden", "garden.area", "npeople",
                            "carfreq", "iscar", "istoilet", "iswmac", "ishw"))  == 0)
        summ[c(2,3,5,15),3] <- c(hasseptic, roofarea, roofarea1, pavearea)#, pavearea1) ,18
    
        if(sum(ls() %in% c("carea.garden", "carea.garden1","isveg", "Hp", "Hf",  
                            "medium", "isoutlet", "Ho", "lined.bottom", "lined.side", "perc.pavearea", 
                            "perc.roofarea", "shape", "dim1", "dim2", "deltaAp", "shapesel"))  == 0){
        summ[c(2:16),3] <- c(hasseptic, roofarea, percroof, roofarea1, percroof1, 
                                    npeople, tankvol, firstflush, ffto, isgarden, garden.area,
                                    istoilet, iswmac, ishw, pavearea)
        } else {
        if(hastank){
        summ[c(2:30),3] <- c(hasseptic, roofarea, percroof, roofarea1, percroof1, 
                             npeople, tankvol, firstflush, ffto, isgarden, garden.area,
                             istoilet, iswmac, ishw, pavearea, overflow, perc.pavearea, 
                             perc.roofarea, Ap, Af, perim, Hp, Hf, medium,
                             isoutlet, Ho, lined.bottom, lined.side, isveg)
                    } else {
        summ[c(2,3,4,5,16:30),3] <- c(hasseptic, roofarea, percroof, roofarea1, 
                             pavearea,overflow, perc.pavearea, perc.roofarea, 
                             Ap, Af, perim, Hp, Hf, medium,
                             isoutlet, Ho, lined.bottom, lined.side, isveg)
                             }
                    }
        write.csv(summ, "results.csv", row.names = FALSE)
        HTMLon()
        Html(results)
        BR
        Html(summ[-1,-1])
        cat("(True-False values are 1 if true, and 0 if false)")
        BR; BR
        HTMLlink(url = paste(substr(getwd(),15,40), "/results.csv", sep = ""), text = "Save a version of the summary table to your computer")
        HTMLtag("i")
        cat(BR, BR, "You can use this file as part of your bid to Stormwater Tender.", BR, 
            "Please use your address as the file name: e.g. '3BrownSt.csv'.", BR, 
            "If you have different parts to your bid, or multiple bids, 
             number each file like this: '3BrownSt1.csv', '3BrownSt2.csv', etc.")
        HTMLtag("/i")
        HTMLoff()
        
    
    dojo.event.connect(dojo.byId("roof"), "onchange",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("roof1"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("pave"), "onchange",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("inpr"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("inpr1"), "onchange",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("intv"), "onchange",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("istoilet"), "onclick",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("isgarden"), "onclick",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("iswmac"), "onclick",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("ishw"), "onclick",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("inff"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("selectffto"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("overflow"), "onclick",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("ppain"), "onchange",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("prain"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("innp"), "onchange",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("inga"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("inHo"), "onchange",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("inHp"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("inHf"), "onchange",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("dAp"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("shapeSelect"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("shapeSelect"), "onReceive",  
                       dojo.widget.byId("shapefigs"), "calculate");
    
    dojo.event.connect(dojo.byId("ddim1"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("ddim2"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("selectmedium"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("isveg"), "onclick",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("lined.bottom"), "onclick",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("lined.side"), "onclick",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("isoutlet"), "onclick",
                      function(e) {rpad.calculateNode(e.target, true);});
    
    dojo.event.connect(dojo.byId("tl"), "onchange",
                       function(e) {rpad.calculateNode(e.target, true);});
    
    // this makes all Rpad updates to output boxes "yellowfade" in
    // make the street select box auto update
    dojo.event.connect(rpad, "updateResults", 
        function (rpadResults, data) {
            dojo.lfx.html.highlight(rpadResults, 
                dojo.gfx.color.extractRGB("#FFFF40")).play(1000);  // from color - bright yellow
            // #FFFFE0
    
       });
    dojo.debug("hello");
    " ";