function getElm(eID) {
	return document.getElementById(eID);
}

function calculateQuote(form) {
  // Get values
  var pages           = form.pages.value;
  var cms             = form.cms[0].checked;
  var hosting         = form.hosting[0].checked;
  var dotcodotuks     = form.dotcodotuks.value;
  var dotcoms         = form.dotcoms.value;
  
  // If left empty, initialise
  if (pages == "") {
    pages = 0;
  }
  if (dotcodotuks == "") {
    dotcodotuks = 0;
  }
  if (dotcoms == "") {
    dotcoms = 0;
  }  
  
  // Set default values
  var setup           = 100;
  var perPage         = 50;
  var cmsSetup        = 100;
  var cmsPerPage      = 30;
  var hostingPrice    = 30;
  var dotcodotukPrice = 10;
  var dotcomPrice     = 15;
  var total           = 0;
  
  // Calculations
  total += setup;
  total += pages * perPage;
  if (cms) {
    total += cmsSetup;
    total += pages * cmsPerPage;
  }
  if (hosting) {
    total += hostingPrice;
  }
  total += dotcodotuks * dotcodotukPrice;
  total += dotcoms * dotcomPrice;
  
  var results   = getElm("results");
  var breakdown = getElm("breakdown");
  var calculate = getElm("calculate");
  
  results.innerHTML = "Your quote: &pound;" + total;
  breakdown.style.visibility = "inherit";
  calculate.value = "Recalculate";
  calculate.style.left = "425px";
  
  window.breakdownDesc  = "<table>"
                        + "  <tr class=\"bold\">"
                        + "    <td class=\"left\">Item</td>"
                        + "    <td>Price per unit</td>"
                        + "    <td>Units</td>"
                        + "    <td>Total</td>"
                        + "  </tr>"
                        + "  <tr>"
                        + "    <td class=\"left\">Setup</td>"
                        + "    <td>&pound;" + setup + "</td>"
                        + "    <td>1</td>"
                        + "    <td>&pound;" + setup + "</td>"
                        + "  </tr>"
                        + "  <tr>"
                        + "    <td class=\"left\">Pages</td>"
                        + "    <td>&pound;" + perPage + "</td>"
                        + "    <td>" + pages + "</td>"
                        + "    <td>&pound;" + perPage * pages + "</td>"
                        + "  </tr>";
  if (cms) {
    window.breakdownDesc += "  <tr>"
                          + "    <td class=\"left\">CMS</td>"
                          + "    <td>&pound;" + cmsSetup + " setup + &pound;" + cmsPerPage + " per page</td>"
                          + "    <td>1 + " + pages + "</td>"
                          + "    <td>&pound;" + (cmsSetup + (pages * cmsPerPage)) + "</td>"
                          + "  </tr>";
  }
  if (hosting) {
    window.breakdownDesc += "  <tr>"
                          + "    <td class=\"left\">Hosting</td>"
                          + "    <td>&pound;" + hostingPrice + "</td>"
                          + "    <td>1</td>"
                          + "    <td>&pound;" + hostingPrice + "</td>"
                          + "  </tr>";
  }
  window.breakdownDesc += "  <tr>"
                        + "    <td class=\"left\">.co.uk domains</td>"
                        + "    <td>&pound;" + dotcodotukPrice + "</td>"
                        + "    <td>" + dotcodotuks + "</td>"
                        + "    <td>&pound;" + dotcodotuks * dotcodotukPrice + "</td>"
                        + "  </tr>"
                        + "  <tr>"
                        + "    <td class=\"left\">.com domains</td>"
                        + "    <td>&pound;" + dotcomPrice + "</td>"
                        + "    <td>" + dotcoms + "</td>"
                        + "    <td>&pound;" + dotcoms * dotcomPrice + "</td>"
                        + "  </tr>"
                        + "  <tr>"
                        + "    <td class=\"bold left\">Grand Total</td>"
                        + "    <td>&nbsp;</td>"
                        + "    <td>&nbsp;</td>"
                        + "    <td class=\"bold blue\">&pound;" + total + "</td>"
                        + "  </tr>"
                        + "</table>";
}

function fbDisplayBreakdown() {
  var breakdownArea = getElm("breakdown-area");
  
  breakdownArea.innerHTML = "<p class=\"bold\">Breakdown of your quote:</p>";
  breakdownArea.innerHTML += window.breakdownDesc;
  breakdownArea.innerHTML += "<br />";
  breakdownArea.innerHTML += "  <p>";
  breakdownArea.innerHTML += "    Please note that this is only an <span class=\"italic\">estimate</span> and the final cost is subject to the descretion of Web Vortex.  This quote does not take into account advanced content such as photo galleries and dynamic features.  However it does offer you an idea of our prices for comparison with other web design companies.";
  breakdownArea.innerHTML += "  </p>";
}
