// obtained from: "JavaScript The Definitive Guide" (5th edition) from David Flanagan published by O'Reilly; Example 22-9

var hbSVG = {};

hbSVG.ns = "http://www.w3.org/2000/svg";
hbSVG.xlinkns = "http://www.w3.org/1999/xlink";

hbSVG.makeCanvas = function (id, pixelWidth, pixelHeight, userWidth, userHeight)
{
  var svg = document.createElementNS (hbSVG.ns, "svg:svg");
  svg.setAttribute ("id", id);
  svg.setAttribute ("width", pixelWidth + "px");
  svg.setAttribute ("height", pixelHeight + "px");
  svg.setAttribute ("viewBox", "0 0 " + userWidth + " " + userHeight);
  svg.setAttributeNS ("http://www.w3.org/2000/xmlns/", "xmlns:xlink", hbSVG.xlinkns);
  return svg;
}

hbSVG.addCanvasToParent = function (canvas, parent, left, top, pixelWidth, pixelHeight, userWidth, userHeight)
{
  canvas.setAttribute ("width", pixelWidth + "px");
  canvas.setAttribute ("height", pixelHeight + "px");
  canvas.setAttribute ("viewBox", left + " " + top + " " + userWidth + " " + userHeight);
  parent.appendChild (canvas);
}

hbSVG.transformCanvas = function (canvas, left, top, pixelWidth, pixelHeight, userWidth, userHeight)
{
  canvas.setAttribute ("width", pixelWidth + "px");
  canvas.setAttribute ("height", pixelHeight + "px");
  canvas.setAttribute ("viewBox", left + " " + top + " " + userWidth + " " + userHeight);
}
