
function title(){$('.title').each(function(){if($(this).val()==''){$(this).val($(this).attr('title'));}});$('.title').focus(function(){if($(this).val()==$(this).attr('title')){$(this).val('');}}).blur(function(){if($(this).val()==''){$(this).val($(this).attr('title'));}});}
$(function(){title();replay=submit=0;if(typeof(comment_url)=='undefined'){comment_url='/web/comments/';}
$form=$('#form_comment').html();$('.reply').live('click',function(){if(!replay){$('#form_comment').html('');replay=1;}else{$('#new_comment').parent().remove();}
$replay=$(this).attr('title');var pl=$('#'+$replay).css('padding-left');$('#'+$replay).replaceWith('<div class="comment-wrap" style="padding-left:'+pl+';">'+$form+'</div><div class="replay" id="'+$replay+'" style="padding-left:'+pl+';"></div>');$('#parent').val($replay.substring(7,$replay.length));$('#button_cancel').show();title();return false;});$('#button_cancel').live('click',function(){replay=0;$('#new_comment').parent().remove();$('#form_comment').html($form);$('#parent').val('0');$('#button_cancel').hide();title();});$('.complain').click(function(){$obj=$(this);comment=$obj.attr('comment')
$obj.html('<img src="/images/indicator.gif" />');$.post(comment_url+article_id,{act:'complain',comment:comment},function(data){if(!data.error){$obj.replaceWith('<div style="color:#F07A13">Thank you! Your complaint has been submitted to the moderator team.</div>');}else{window.location.reload();}},"json");return false;});$('.p_edit').live('click',function(){$obj=$(this);$obj.attr('title','').css('background','url(/images/indicator.gif) no-repeat');var $comment_text=$obj.parent().parent().find('.comment_text');$.post(comment_url+article_id,{act:'get_text',comment:$obj.attr('comment')},function(data){if(!data.error){$comment_text.replaceWith('<textarea name="text" class="area_comment">'+data.text+'</textarea>');$obj.attr('title','Save this comment').css('background','').removeClass('p_edit').addClass('p_save');}else{$obj.attr('title','Edit this comment').css('background','').removeClass('p_save').addClass('p_edit');}},"json");});$('.p_save').live('click',function(){$obj=$(this);$obj.attr('title','').css('background','url(/images/indicator.gif) no-repeat');$comment_text=$obj.parent().parent().find('.area_comment');comment_text=$comment_text.val();comment_text=$.trim(comment_text.substring(0,600));$comment_text.val(comment_text);if(comment_text==''){$.post(comment_url+article_id,{act:'get_text',comment:$obj.attr('comment')},function(data){if(!data.error){$obj.attr('title','Save this comment').css('background','');$comment_text.val(data.text);alert('Comment is required!');}},"json");return false;}
$.post(comment_url+article_id,{act:'save',comment:$obj.attr('comment'),text:comment_text},function(data){if(!data.error){$comment_text.replaceWith('<span class="comment_text">'+data.text+'</span>');$obj.attr('title','Edit this comment').css('background','').removeClass('p_save').addClass('p_edit');}else{$obj.attr('title','Save this comment').css('background','');$comment_text.val(data.text);alert('We are sorry, but your comment containts obscene words.');}},"json");});$('.p_reject').click(function(){$obj=$(this);if(confirm('Are you sure to delete this comment?')){$.post(comment_url+article_id,{act:'delete',comment:$obj.attr('comment')},function(data){if(!data.error){$.each(data.ids,function(i,item){$('#c_'+item).fadeOut('slow',function(){$('#c_'+item).remove()});});}},"json");}});required_text='<span class="err_text">This field is required!</span>';$('#new_comment').live("submit",function(){$('.err_text').remove();$obj=$(this);if(submit)
return true;var parent=$obj.find('input[name=parent]').val();str={act:'comment',parent:parent};var error_req=0;$text=$obj.find('#c_text');comment_text=$text.val();comment_text=$.trim(comment_text.substring(0,600));$text.val(comment_text);text_val=$.trim(comment_text);if(text_val!=''&&text_val!=$text.attr('title')){str['text']=$text.val();}else{$obj.find('#c_text').val('').after(required_text);error_req=1;}
if(!aid){$name=$obj.find('#c_name');name_val=$.trim($name.val());if(name_val!=''&&name_val!=$name.attr('title')){str['name']=$name.val();}else{$obj.find('#c_name').val('').after(required_text);error_req=1;}
$code=$obj.find('#c_code');code_val=$.trim($code.val());if(code_val!=''&&code_val!=$code.attr('title')){str['code']=$code.val();}else{$obj.find('#c_code').val('').after(required_text);error_req=1;}}
if(error_req){return false;}
$.post(comment_url+article_id,str,function(data){if(!data.error){submit=1;$obj.submit();}else{$.each(data.message,function(i,item){switch(item){case'wrong':$obj.find('#c_'+i).after('<span class="err_text">Wrong code! Please try again.</span>');break;case'required':$obj.find('#c_'+i).after(required_text);break;case'hyperlink':$obj.find('#c_'+i).after('<span class="err_text">We are sorry, but your comment containts hyperlinks that seem to be spam.</span>');break;case'obscene':$obj.find('#c_'+i).after('<span class="err_text">We are sorry, but your comment containts obscene words.</span>');break;default:$obj.find('#c_'+i).after('<span class="err_text">This field is not valid.</span>');break;}});}},"json");return false;});});
