$(document).ready(function(){function EditComment(t){var n=t.split('_');var c="#cb_"+n[1];var h=$(c).css("height");var a=h.replace('px','');var w=$(c).css("width");var b=w.replace('px','');var d=w.search('%');if(d>0)b='auto';var d=h.search('%');if(d>0)a='auto';if(b!='auto'){var e=b-2;b=(b-2)+"px"}else{b='99.75%';var e=b}if(a!='auto'){var f=a-(-20);a=(a-11)+"px"}else{a='60px';var f='1%'}var g=b+"_"+a;$("#com_serv").html($("#bc_"+n[1]).html());$(c).animate({opacity:0.01,height:f,width:e},200,function(){$(c).load("/inc/comment/gcbody.php?q="+t+"&g="+g+"&pi="+Math.random(100000),function(){$("#comments .ct_a").animate({opacity:'hide'},200,function(){$(c).animate({opacity:1.0},200)})})})}function AlarmComment(t){var n=t.split('_');var c="#cb_"+n[1];$(c).animate({opacity:0.01,height:'50'},300,function(){$(c).html('<div class="small" style="text-align:center;padding-top:17px;"><span class="red">Жалоба отправлена</span></div>');$("#"+t+" .c_am").animate({opacity:'hide'});$(c).animate({opacity:1.0},200);$.get("/inc/comment/alarm.php",{t:t,pi:Math.random(100000)})})}function DeleteComment(t){var n=t.split('_');var c="#com_"+n[1];$(c).animate({opacity:'hide'},600,function(){$.get("/inc/comment/delete.php",{t:t,pi:Math.random(100000)})})}$("#comments .c_ed").live("click",function(){var t=$(this).parent().attr("id");EditComment(t);return false});$("#comments .c_am").live("click",function(){var t=$(this).parent().attr("id");AlarmComment(t);return false});$("#comments .c_dl").live("click",function(){var t=$(this).parent().attr("id");DeleteComment(t);return false});$("#comments .ct_a").animate({opacity:0.4},200);$("#comments .ct_a").hover(function(){$(this).animate({opacity:1},200)},function(){$(this).animate({opacity:0.4},200)});$("#comments #com_can").live("click",function(){var t=$(this).parent().attr("id");var n=t.split('_');var c="#cb_"+n[1];$(c).animate({opacity:0.01},100,function(){$(c).html('<div id="bc_'+n[1]+'" class="bc_com">'+$("#com_serv").html()+'</div>')});$(c).animate({opacity:1,width:"+=2"},100);$("#comments .ct_a").animate({opacity:'show'},200);return false});$("#com_sub").live("click",function(){var t=$(this).parent().attr("id");var n=t.split('_');var c="#cb_"+n[1];var a=$("#tar_"+n[1]).val();if(trim(a)=="")alert('Комментарий не может быть пустым');else{ComSub(t,a)}return false});function ComSub(b,d){var e=$("#com_object").text();var n=b.split('_');var c="#cb_"+n[1];var s=$("#com_sect").text();$.post("/inc/comment/upd.php",{obj:e,s:s,id:b,msg:d},function(a){$(c).animate({opacity:1,width:"+=2"},100);$(c).html('<div id="bc_'+n[1]+'" class="bc_com">'+a+'</div>')});$("#comments .ct_a").animate({opacity:'show'},200);return false}$('#comments .comms').live("keypress",function(e){if((e.ctrlKey)&&((e.keyCode==0xA)||(e.keyCode==0xD))){var a=$(this).val();var b=$(this).parent().attr("id");if(trim(a)=="")alert('Комментарий не может быть пустым');else{ComSub(b,a)}}});$('#com_txtar').keypress(function(e){if((e.ctrlKey)&&((e.keyCode==0xA)||(e.keyCode==0xD))){var a=$(this).val();var b=$(this).parent().attr("id");if(trim(a)=="")alert('Комментарий не может быть пустым');else{var b=$("#com_append").attr("class");SubmitComment(b)}}});$('#com_append').click(function(){var a=$("#com_txtar").val();if(trim(a)=="")alert('Комментарий не может быть пустым');else{var b=$(this).attr("class");SubmitComment(b)}return false});function SubmitComment(b){var h=$('#handler_'+b).text();$.post(h,encodeURI($('#'+b).serialize()),function(a){$("#comments").append(a);$("#comments .ct_a").animate({opacity:0.4},200);$("#comments .ct_a").hover(function(){$(this).animate({opacity:1},200)},function(){$(this).animate({opacity:0.4},200)})});$("#com_txtar").val('');return false}$('#bbcode .com_but').click(function(){$('#com_txtar').focus();var a=$(this).attr("alt");if(a=='i'||a=='b'||a=='u'||a=='s'){BBcode(a)}if(a=='smile'){GetSmiles()}if(a=='href'){inpit_href()}return false});$('#com_smiles .cfsm').click(function(){$('#com_txtar').focus();var a=$(this).attr("alt");InsertSmile(a);return false});function inpit_href(){var a=prompt("Вставить URL ссылки","");var b=prompt("Вставить текст ссылки","");if(!b)b=a;if(a){var c=$("#com_txtar");c.val(c.val()+" [a url="+a+"]"+b+"[/a] ");return true}else return false}function GetSmiles(){var c=$("#allsmiles");if(c.html()==''){c.animate({opacity:1,height:"+=32"},300,function(){c.html('<div style="text-align:center"><img src="/i/roter.gif" alt="" /></div>');$(c).load("/inc/comment/smiles.html",function(){c.animate({opacity:1,height:"+=380"},300)})})}else{c.toggle('fast')}}$('#allsmiles .sml').live("click",function(){var a=$(this).attr("title");InsertSmile(a);return false});function InsertSmile(a){var c=$("#com_txtar");var a=" "+a+" ";var b=0;var d;var e;if(typeof document.selection!='undefined'){c.focus();var f=document.selection;var g=f.createRange();g.colapse;if((f.type=="Text"||f.type=="None")&&g!=null){g.text=a}else{c.val(c.val()+a)}}else{d=c.val().substr(0,c.attr("selectionStart"));e=c.val().substr(c.attr("selectionEnd"));c.val(d+a+e);d=d.length+a.length;document.getElementById('com_txtar').setSelectionRange(d,d)}}function BBcode(t){var a=$('#com_txtar');var s;if(typeof document.selection!='undefined'){s=document.selection.createRange().text;if(s!=''){a.caretPos=document.selection.createRange().duplicate();document.selection.createRange().text="["+t+"]"+s+"[/"+t+"]";s='';return}}else if(a.attr("selectionEnd")&&(a.attr("selectionEnd")-a.attr("selectionStart")>0)){var b=a.attr("textLength");var c=a.attr("selectionStart");var d=a.attr("selectionEnd");if(d==1||d==2)d=b;var e=(a.val()).substring(0,c);var f=(a.val()).substring(c,d);var g=(a.val()).substring(d,b);a.val(e+"["+t+"]"+f+"[/"+t+"]"+g);return}}function Quotes(a){var b=$('#com_txtar');var s;if(typeof document.selection!='undefined'){s=document.selection.createRange().text;b.caretPos=document.selection.createRange().duplicate()}else{s=window.getSelection().getRangeAt(0)}if(s!=''){var c=$("#uc_"+a).text();var d=$("#com_txtar");var e=d.val();if(e!='')e=e+"\n";e=e+"[cit][user]"+c+"[/user]\n"+s+"[/cit]";d.val(e)}s=''}$("#comments .bc_com").live("mouseup",function(){var a=$(this).attr("id");var n=a.split('_');Quotes(n[1])})});