Logo  

Home - Old Man Programmer

Displaying webapps/scheduler/element.js

function newid()
{
  var hex = "0123456789abcdef";
  var id = "id";
  for(var i = 0; i < 32; i++) {
    id += hex[Math.floor(Math.random()*16)];
  }
  return id;
}

function el(type, ca, props)
{
  var t = document.createElement(type);
  if (typeof props == "object") {
    for(p in props) {
      if (p != "innerHTML") t.setAttribute(p, props[p]);
      else t[p] = props[p];
    }
  }
  if (ca != null) {
    for(var i = 0; i < ca.length; i++)
      t.appendChild(ca[i]);
  }
  return t;
}

function hoursel(h, e, what)
{
  var s = document.createElement("select");
  var o;
  for(var i = 0; i < 24; i++) {
    o = new Option(i, i, i == 8? true: false, i == h? true: false);
    s.appendChild(o);
  }
  s.setAttribute("id", e.id + "hour-" + (what? "end" : "start"));
  s.setAttribute("onchange", "updatehour('" + e.id + "'," + what + ");");
  return s;
}

function minsel(m, e, what)
{
  var s = document.createElement("select");
  var o;
  for(var i = 0; i < 60; i+=5) {
    o = new Option(i, i, i == 0? true: false, i == m? true: false);
    s.appendChild(o);
  }
  s.setAttribute("id", e.id + "min-" + (what? "end" : "start"));
  s.setAttribute("onchange", "updatemin('" + e.id + "'," + what + ");");
  return s;
}