/* Hackish form handling system. */ function hasClass(e, cl) { return (" "+e.className+" ").match(" "+cl+" "); } function stopPropagation(e) { e.preventDefault && e.preventDefault(); e.cancelBubble = true; } /* proxy for a form object, with appropriate encoder/decoder */ function formElement(el) { this.el = el; } formElement.prototype = { get: function() { var el = this.el; if (el.type == "checkbox") { return el.checked; } else if (hasClass(el, "numeric")) { return parseInt(el.value); } else if (hasClass(el, "hex")) { return sjcl.codec.hex.toBits(el.value); } else if (hasClass(el, "base64")) { return sjcl.codec.base64.toBits(el.value); } else { return el.value; } }, set: function(x) { var el = this.el; if (el.type == "checkbox") { el.checked = x; return; } else if (hasClass(el, "hex")) { if (typeof x !== 'string') { x = sjcl.codec.hex.fromBits(x); } x = x.toUpperCase().replace(/ /g,'').replace(/(.{8})/g, "$1 ").replace(/ $/, ''); } else if (hasClass(el, "base64")) { if (typeof x !== 'string') { x = sjcl.codec.base64.fromBits(x); } x = x.replace(/\s/g,'').replace(/(.{32})/g, "$1\n").replace(/\n$/, ''); } el.value = x; } } function radioGroup(name) { this.name = name; } radioGroup.prototype = { get: function() { var els = document.getElementsByName(this.name), i; for (i=0; i