Enquete = { setChecked: function(numeroQuestao, quantidade, outro, numeroRelativo){ retorno = ''; for(item = 1; item <= quantidade; item++){ if($('item'+item+'resposta'+numeroQuestao).checked){ retorno += item+','; if(item == quantidade && outro != null){ if(!this.setOutro(this.data, numeroQuestao, item, numeroRelativo)) return null; } } } this.data['resposta'+numeroQuestao] = (retorno!=''?retorno.substr(0,retorno.length-1):null); if(this.data['resposta'+numeroQuestao] == null){ $('item1resposta'+numeroQuestao).focus(); alert('Escolha pelo menos um item na questao '+ numeroRelativo+'!'); return null; } return this.data['resposta'+numeroQuestao]; }, setOutro: function(data, questao, itemAssociado, numeroRelativo){ elText = $('text'+itemAssociado+'resposta'+questao); if(elText.value.trim() == ''){ elText.focus(); alert('Você selecionou a opção de outros na questão '+numeroRelativo+', e não preencheu o campo'); return false; }else{ data['outro'+questao] = elText.value.trim(); return true; } }, setSelected: function(numeroQuestao, prefixo, quantidade, outro, modificador,numeroRelativo){ for(item = modificador; item <= quantidade-(1-modificador); item++){ if($(prefixo+item+'resposta'+numeroQuestao).checked){ if(item == quantidade && outro != null){ if(!this.setOutro(this.data, numeroQuestao, item, numeroRelativo)) return null; } return item; }; } if(numeroRelativo != null){ $(prefixo+'1resposta'+numeroQuestao).focus(); alert('Selecione uma alternativa para a questão '+ numeroRelativo); } return null; }, setNota: function(numeroQuestao, data, tamanho, questaoReal , modificadorMensagem){ nota = this.setSelected(numeroQuestao,'nota',tamanho, null,0, null); if(nota == null){ $('nota0resposta'+numeroQuestao).focus(); alert('Escolha uma resposta para o item '+questaoReal+'.'+(numeroQuestao-modificadorMensagem)+'!'); return false; }else{ data['resposta'+numeroQuestao] = nota; return true; } }, setValue: function(questao, mensagem, data){ idElemento = 'resposta'+questao; if($(idElemento).value == ''){ $(idElemento).focus(); alert(mensagem); return false; }else{ data[idElemento] = $(idElemento).selectedIndex+1; return true; } }, enviar: function(){ this.data = {}; if(!this.setValue(1,'Selecione uma unidade na resposta 1',this.data)) return; if(!this.setValue(2,'Selecione uma categoria na resposta 2',this.data)) return; if(!this.setValue(3,'Selecione uma faixaEtária na resposta 3',this.data)) return; if(!this.setValue(4,'Selecione uma categoria na resposta 4',this.data)) return; for(i = 5; i < 23; i++){ if(!this.setNota(i,this.data,4,5,4)) return; } if(this.setChecked(23, 6, true, 6) == null ) return ; if(this.setChecked(24, 9, true, 7) == null ) return ; if(this.setSelected(25, 'item', 6, true, 1,8) == null) return else this.data['resposta25'] = this.setSelected(25, 'item', 6, true, 1,8); this.data['resposta26'] = $('text26').value; if(this.setSelected(27, 'item', 3, null, 1,9) == null) return else this.data['resposta27'] = this.setSelected(27, 'item', 3, null, 1,9); for(i = 28; i < 38; i++){ if(!this.setNota(i,this.data,3,11,27)) return; } if(this.setChecked(38, 7, true, 12) == null ) return ; this.data['resposta39'] = $('text39').value; this.data['method'] = 'doSaveEnquete'; new Ajax('/IP/dosaveenquete.serv',{ method: 'POST', data: this.data, evalScripts: true, onComplete: function(response){ $('tablePrincipal').setStyle('display','none'); document.body.innerHTML += response; } }).request(); } }