$(function(){ var opros_selected = 0; var navRoot = $("#oprelements"); var multiple = Number($("#multiple").val()); var other_text = $('#other_text'); var form = $("#voteForm"); $('#oprelements li').click(function(){ $('#oprelements').find('a').removeClass('selected'); $(this).find('a').addClass('selected'); }); $('#vote_sub').click(function(){ answer(3); }); function answer(id) { var all_empty = false; if(multiple){ if(navRoot.find('li.selected').length == 0) { var all_empty = true; } if($('#other_link').parent().parent().hasClass('selected') == false) { other_text.remove(); } }else { if(opros_selected > 0) { var node = navRoot.children('li:eq(' + Number(opros_selected - 1) + ')').attr('id'); if(!node) {node = 'other';} $('#variant').val(node); }else { var all_empty = true; } } if(all_empty) { alert("\u0432\u044B \u043D\u0438\u0447\u0435\u0433\u043E \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043B\u0438!"); }else { form.submit(); } } function start_opros() { if(navRoot) { if(multiple) { var val = 0; navRoot.find('li').each(function(i) { $(this).attr('rid', Number(i + 1)) $(this).click(function() { if($(this).hasClass('field') == false) { if($(this).hasClass('selected')) { $(this).removeClass('selected'); } else { $(this).addClass('selected'); val = 1; } $(this).find('input:hidden').val(val); } }); }); }else { navRoot.find('li a').each(function(i) { $(this).attr('rid', Number(i + 1)) if($(this).hasClass('field') == false) { $(this).click(function() { navRoot.children('li').removeClass('selected'); opros_selected = $(this).attr('rid'); $(this).addClass('selected'); }); } }); other_text.focus(function() { $('#other_link').parent().parent().addClass('selected'); }); other_text.blur(function() { if($(this).val().length == 0) { $('#other_link').parent().parent().removeClass('selected'); } }); } } } $('#vote').click(function() { answer(opros_selected); return false; }); start_opros(); });