$(document).ready(function(){function EditComment(t){var n=t.split('_');var c="#cb_"+n[1];var h=$(c).css("height");var he=h.replace('px','');var w=$(c).css("width");var wi=w.replace('px','');var perc=w.search('%');if(perc>0)wi='auto';var perc=h.search('%');if(perc>0)he='auto';if(wi!='auto'){var wic=wi-2;wi=(wi-2)+"px"}else{wi='99.75%';var wic=wi}if(he!='auto'){var hec=he-(-20);he=(he-11)+"px"}else{he='60px';var hec='1%'}var g=wi+"_"+he;$("#com_serv").html($("#bc_"+n[1]).html());$(c).animate({opacity:0.01,height:hec,width:wic},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 msg=$("#tar_"+n[1]).val();if(trim(msg)=="")alert('Комментарий не может быть пустым');else{ComSub(t,msg)}return false});function ComSub(id,msg){var obj=$("#com_object").text();var n=id.split('_');var c="#cb_"+n[1];var s=$("#com_sect").text();$.post("/inc/comment/upd.php",{obj:obj,s:s,id:id,msg:msg},function(data){$(c).animate({opacity:1,width:"+=2"},100);$(c).html('<div id="bc_'+n[1]+'" class="bc_com">'+data+'</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 msg=$(this).val();var id=$(this).parent().attr("id");if(trim(msg)=="")alert('Комментарий не может быть пустым');else{ComSub(id,msg)}}});$('#com_txtar').keypress(function(e){if((e.ctrlKey)&&((e.keyCode==0xA)||(e.keyCode==0xD))){var msg=$(this).val();var id=$(this).parent().attr("id");if(trim(msg)=="")alert('Комментарий не может быть пустым');else{var id=$("#com_append").attr("class");SubmitComment(id)}}});$('#com_append').click(function(){var msg=$("#com_txtar").val();if(trim(msg)=="")alert('Комментарий не может быть пустым');else{var id=$(this).attr("class");SubmitComment(id)}return false});function SubmitComment(fid){var h=$('#handler_'+fid).text();$.post(h,encodeURI($('#'+fid).serialize()),function(data){$("#comments").append(data);$("#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('');$("#answ_c").html('');$("#anuid").val('0');return false}$('#bbcode .com_but').click(function(){$('#com_txtar').focus();var id=$(this).attr("alt");if(id=='i'||id=='b'||id=='u'||id=='s'){BBcode(id)}if(id=='smile'){GetSmiles()}if(id=='href'){AddLink()}return false});$('#com_smiles .cfsm').click(function(){$('#com_txtar').focus();var id=$(this).attr("alt");InsertSmile(id);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 id=$(this).attr("title");InsertSmile(id);return false});function AddLink(){var url=prompt("Вставить URL ссылки","");var text=prompt("Вставить текст ссылки","");if(!text)text=url;if(url){var text=" [a url="+url+"]"+text+"[/a] ";var c=$("#com_txtar");var CaretPos=0;var start;var end;if(typeof document.selection!='undefined'){c.focus();var sel=document.selection;var rng=sel.createRange();rng.colapse;if((sel.type=="Text"||sel.type=="None")&&rng!=null){rng.text=text}else{c.val(c.val()+text)}}else{start=c.val().substr(0,c[0].selectionStart);end=c.val().substr(c[0].selectionEnd);c.val(start+text+end);start=start.length+text.length;document.getElementById('com_txtar').setSelectionRange(start,start)}}return false}function InsertSmile(text){var c=$("#com_txtar");var text=" "+text+" ";var CaretPos=0;var start;var end;if(typeof document.selection!='undefined'){c.focus();var sel=document.selection;var rng=sel.createRange();rng.colapse;if((sel.type=="Text"||sel.type=="None")&&rng!=null){rng.text=text}else{c.val(c.val()+text)}}else{var start=c.val().substr(0,c[0].selectionStart);var end=c.val().substr(c[0].selectionEnd);c.val(start+text+end);start=start.length+text.length;document.getElementById('com_txtar').setSelectionRange(start,start)}}function BBcode(t){var element=$('#com_txtar');var s;if(typeof document.selection!='undefined'){s=document.selection.createRange().text;if(s!=''){element.caretPos=document.selection.createRange().duplicate();document.selection.createRange().text="["+t+"]"+s+"[/"+t+"]";s='';return}}else if(element[0].selectionEnd&&(element[0].selectionEnd-element[0].selectionStart>0)){var selLength=element[0].textLength;var selStart=element[0].selectionStart;var selEnd=element[0].selectionEnd;if(selEnd==1||selEnd==2)selEnd=selLength;var s1=(element.val()).substring(0,selStart);var s2=(element.val()).substring(selStart,selEnd);var s3=(element.val()).substring(selEnd,selLength);element.val(s1+"["+t+"]"+s2+"[/"+t+"]"+s3);return}}function Quotes(id){var element=$('#com_txtar');var s;if(typeof document.selection!='undefined'){s=document.selection.createRange().text;element.caretPos=document.selection.createRange().duplicate()}else{s=window.getSelection().getRangeAt(0)}if(s!=''){var user=$("#uc_"+id).text();var txtar=$("#com_txtar");var cnt=txtar.val();if(cnt!='')cnt=cnt+"\n";cnt=cnt+"[cit][user]"+user+"[/user]\n"+s+"[/cit]";txtar.val(cnt)}s=''}$("#comments .bc_com").live("mouseup",function(){var pr=$(this).attr("id");var n=pr.split('_');Quotes(n[1])});$(".com_answer").click(function(){var prf=$(this).attr("id").split('_');var l=$("#answ_c").length;if(l){var user=$("#hi_"+prf[1]+"_"+prf[2]).html();$("#answ_c").html('отвечает пользователю '+user);$("#anuid").val(prf[1]+"_"+prf[2])}})});
