 /**
	Uniwits System, 2011
	http://www.uniwits.com
**/ function questioninfo_add_choice() { var choices_div=document.getElementById('choices_div'); var subdivs=choices_div.getElementsByTagName('DIV'); if (subdivs.length==0) return true; var newsubdiv=UNIWITS.Toolbox.createElement('DIV'); newsubdiv.innerHTML=subdivs[0].innerHTML; newsubdiv.className=subdivs[0].className; var maxindex=questioninfo_find_max_newindex(); var maxordinal=questioninfo_find_max_ordinal(); choices_div.appendChild(newsubdiv); questioninfo_replace_properties_for_new(newsubdiv.getElementsByTagName('INPUT'),maxindex+1,maxordinal+1); return false; } function questioninfo_find_max_newindex() { var choices_div=document.getElementById('choices_div'); var inputs=choices_div.getElementsByTagName('INPUT'); var maxindex=0; for (var i=0;i<inputs.length;i++) { if (inputs[i].name.substr(0,11)=='qc_delete[_') { var numstr=inputs[i].name.substr(11,inputs[i].name.length-1); maxindex=Math.max(maxindex,parseInt(numstr,10)); } } return maxindex; } function questioninfo_find_max_ordinal() { var choices_div=document.getElementById('choices_div'); var inputs=choices_div.getElementsByTagName('INPUT'); var maxordinal=0; for (var i=0;i<inputs.length;i++) { if (inputs[i].name.substr(0,11)=='qc_ordinal[') { var numstr=inputs[i].value; maxordinal=Math.max(maxordinal,parseInt(numstr,10)); } } return maxordinal; } function questioninfo_replace_properties_for_new(inputs,useindex,useordinal) { for (var i=0;i<inputs.length;i++) { if (inputs[i].name.substr(0,10)=='qc_delete[') { inputs[i].name='qc_delete[_'+useindex+']'; inputs[i].id=inputs[i].name; inputs[i].checked=false; } else if (inputs[i].name.substr(0,11)=='qc_ordinal[') { inputs[i].name='qc_ordinal[_'+useindex+']'; inputs[i].id=inputs[i].name; inputs[i].value=useordinal; } else if (inputs[i].name.substr(0,8)=='qc_text[') { inputs[i].name='qc_text[_'+useindex+']'; inputs[i].id=inputs[i].name; inputs[i].value=""; } } } function questioninfo_ondelete(checkboxobj) { if (!checkboxobj.checked) return; var choices_div=document.getElementById('choices_div'); var subdivs=choices_div.getElementsByTagName('DIV'); var dircount=0; for (var i=0;i<subdivs.length;i++) if (subdivs[i].parentNode==choices_div) dircount++; if (dircount<2) return; var obj=checkboxobj; while (obj.parentNode!=choices_div) obj=obj.parentNode; choices_div.removeChild(obj); setTimeout("questioninfo_reorder(null)",10); } function questioninfo_find_ordinal(subdiv) { var inputs=subdiv.getElementsByTagName('INPUT'); for (var i=0;i<inputs.length;i++) { if (inputs[i].name.substr(0,11)=='qc_ordinal[') { return parseInt(inputs[i].value,10); } } return 0; } function questioninfo_set_ordinal(subdiv,useordinal) { var inputs=subdiv.getElementsByTagName('INPUT'); for (var i=0;i<inputs.length;i++) { if (inputs[i].name.substr(0,11)=='qc_ordinal[') inputs[i].value=useordinal; } return 0; } function questioninfo_reorder(focusobj) { var choices_div=document.getElementById('choices_div'); var subdivs=choices_div.getElementsByTagName('DIV'); var ordinal2choice_div=[]; var ordinals=[]; for (var i=0;i<subdivs.length;i++) if (subdivs[i].parentNode==choices_div) { var ord=questioninfo_find_ordinal(subdivs[i]); ordinals[ordinals.length++]=ord; if (typeof ordinal2choice_div[ord]=="undefined") ordinal2choice_div[ord]=[]; ordinal2choice_div[ord].push(subdivs[i]); } ordinals.sort(); var ordi=1; for (var i=0;i<ordinals.length;i++) { var cds=ordinal2choice_div[ordinals[i]]; while (cds.length>0) questioninfo_set_ordinal(choices_div.appendChild(cds.pop()),ordi++); } if (focusobj) focusobj.focus(); } function questioninfo_onchangetype() { var q_type=document.getElementById('q_type'); if (!q_type) return; var choices_container=document.getElementById('choices_container'); if (q_type.value=='STATE') choices_container.style.display='none'; else choices_container.style.display=''; }