var i=0,option={init:function(){$("#options tr").find("img").show().css("visibility","visible");$("#options tr:first-child").find("img:nth-child(2)").css("visibility","hidden");$("#options tr:last-child").find("img:nth-child(1)").css("visibility","hidden")},add:function(a,b,d,e){i++;if(typeof a==="undefined")a="";if(typeof b==="undefined")b="";if(typeof d==="undefined")d=i;if(typeof e==="undefined")e="";html='<tr id="'+i+'">';html+='<td class="t_c"><input type="hidden" name="option['+i+'][optionid]" id="optionid_'+
i+'" value="'+e+'"/><input type="text" name="option['+i+'][sort]" id="sort_'+i+'" value="'+d+'" size="1" onchange="option.order_sort('+i+', this.value)"/></td>';html+='<td><input type="text" name="option['+i+'][name]" id="name_'+i+'" value="'+a+'" size="50" maxlength="100" uncount="1" style="width:98%" /></td>';html+='<td class="t_c"><input type="text" name="option['+i+'][votes]" id="votes_'+i+'" value="'+b+'" size="4" /></td>';html+='<td style="padding:5px 0px">';html+='<img src="images/down.gif" alt="\u4e0b\u79fb" title="\u4e0b\u79fb" width="16" height="16" onclick="option.down('+
i+')" class="hand" style="margin-left:8px"/>\u3000';html+='<img src="images/up.gif" alt="\u4e0a\u79fb" title="\u4e0a\u79fb" width="16" height="16" onclick="option.up('+i+')" class="hand" />\u3000';html+='<img src="images/del.gif" height="16" width="16" alt="\u5220\u9664" title="\u5220\u9664" onclick="option.remove('+i+')" class="hand" />';html+="</td></tr>";$("#options").append(html);option.init()},up:function(a){var b=$("#"+a);if(b.prev().is("tr")){var d=b.prev().attr("id"),e=$("#sort_"+a).val(),
c=$("#sort_"+d).val();$("#sort_"+a).val(c);$("#sort_"+d).val(e);b.insertBefore(b.prev());option.init()}},down:function(a){var b=$("#"+a);if(b.next().is("tr")){var d=b.next().attr("id"),e=$("#sort_"+a).val(),c=$("#sort_"+d).val();$("#sort_"+a).val(c);$("#sort_"+d).val(e);b.insertAfter(b.next());option.init()}},remove:function(a){if($("#options>tr").length<3){ct.error("\u81f3\u5c11\u5f97\u4fdd\u7559\u4e24\u4e2a\u6295\u7968\u9009\u9879");return false}$("#"+a).remove();option.init()},order_sort:function(a,
b){if(isNaN(b)){ct.warn("\u8bf7\u8f93\u5165\u963f\u62c9\u4f2f\u6570\u5b57\uff01");$("#sort_"+a).val("0")}else{var d=[];$("#options>tr").each(function(e){var c=$(this).attr("id");d[e]=[$("#name_"+c).val(),$("#votes_"+c).val(),$("#sort_"+c).val(),$("#optionid_"+c).val()]});d.sort(function(e,c){return e[2]-c[2]});$("#options").empty();$.each(d,function(e,c){option.add(c[0],c[1],c[2],c[3])})}}};
