function click_section(d, section_name) { var section = null; var i, len = sections.length; var x, perm_len = permissions.length; var div, chk, label, td = document.getElementById("perm_list"); if (open_section) section = open_section; open_section = d; td.innerHTML = ""; for (i = 0; i < len; i++) { div = document.createElement("DIV"); div.className = "perm_list"; chk = document.createElement("INPUT"); chk.type = "checkbox" chk.setAttribute("name", "perm_"+ sections[i].id); chk.setAttribute("id", "perm_"+ sections[i].id); chk.onclick = function() { alert("you clicked me"); } label = document.createElement("label"); label.appendChild( document.createTextNode( sections[i].name ) ); label.attributes["for"].value = "perm_"+ sections[i].id; div.appendChild( chk ); div.appendChild( label ); td.appendChild( div ); for (x = 0; x < perm_len; x++) { if (permissions[x] == sections[i].id) { chk.checked = true; break; } } } if (section) roll_off_section( section ); }