﻿function createWallpaperCalculator(addHeading) {
  try {
    document.write('<form class="extcalc" name="frmWallpaperCalc" onsubmit="return calculateWallpaper(this);"><table border="0" cellpadding="0" cellspacing="0">');
    if (addHeading) document.write('<tr><td colspan="2"><h4>Wallpaper Calculator</h4></td></tr>');
    document.write('<tr><td>What is the perimiter of the room?</td><td><input type="text" size="5" maxlength="5" name="calcPerimeter" style="width:30px;" onchange="clearWallpaperResults();" /> <b>m</b></td></tr>');
    document.write('<tr><td>How high is the wall?</td><td><input type="text" size="5" maxlength="5" name="calcWallHeight" style="width:30px;" onchange="clearWallpaperResults();" /> <b>m</b></td></tr>');
    document.write('<tr><td>How wide is each roll?</td><td><input type="text" size="5" maxlength="5" name="calcRollWidth" style="width:30px;" onchange="clearWallpaperResults();" /> <b>m</b></td></tr>');
    document.write('<tr><td>How long is each roll?</td><td><input type="text" size="5" maxlength="5" name="calcRollLength" style="width:30px;" onchange="clearWallpaperResults();" /> <b>m</b></td></tr>');
    document.write('<tr><td colspan="2" style="text-align:center;" id="calcWallpaperResult"></td></tr>');
    document.write('<tr><td colspan="2" style="text-align:center;"><input type="submit" name="go" value="Calculate Rolls" /></td></tr>');
    document.write('</table>');
    document.write('<p id="calcWallpaperNote" style="display:none;"><small>As experience often shows, it is better to over-estimate the number of rolls you may require in order to allow for any potential mishaps. Also, there is nothing worse than starting a job, finding you have under-estimated and then find that the wall paper has been discontinued.<br />Subject to retaining your receipt and the unused rolls have not been opened, the shop you bought them from should honour your receipt.<br />NB Calculations presume all walls are equal height.<br />Orchard Planning Solutions is not responsible for any disparity between the estimated cost and the actual cost paid by you.</small></p>');
    document.write('</form>');
  } catch(e) {}
}
function clearWallpaperResults() {
  try {
    var elRes = document.getElementById("calcWallpaperResult");
    var elNote = document.getElementById("calcWallpaperNote");
    elRes.innerHTML=''; elNote.style.display='none';
  } catch(e) {}
  return true;
}
function calculateWallpaper(f) {
  try {
    var elRes = document.getElementById("calcWallpaperResult");
    var elNote = document.getElementById("calcWallpaperNote");
    elRes.innerHTML=''; elNote.style.display='none';
    var p = f.calcPerimeter.value.toString();
    var h = f.calcWallHeight.value.toString();
    var w = f.calcRollWidth.value.toString();
    var l = f.calcRollLength.value.toString();
    if (!(IsNumeric(p)&&IsNumeric(h)&&IsNumeric(w)&&IsNumeric(l))) {
      alert('Please enter valid Room Perimiter, Height of Wall and Roll Size values');
      return false;
    }
    h=parseFloat(h)+0.1; //add tolerance
    var total=(parseFloat(p)/parseFloat(w))/(parseFloat(l)/parseFloat(h));
    var rolls = Math.ceil(total);
    var res='<em>'+rolls.toString()+" roll";
    if (rolls!=1) res+="s";
    res+=' required.</em>';
    elRes.innerHTML='<div class="whatthismeans">'+res+'</div>'; elNote.style.display='block';
  } catch(e) {alert('Please enter valid Room Perimiter, Height of Wall and Roll Size values');}
  return false;
}