function LoadComments(a){$("#area_comments").html('<img src="/images/loading.gif" />');$("#area_comments").load("/comments.php?fid="+work_id+"&type="+work_type+"&page="+a)}function LoadMoreComment(a){$("#comments_"+a).append('<img src="/images/loading.gif" />');$("#comments_"+a).load("/comments.php?act=loadmore&id="+a)}function GetPageUrl(){return location.href}function OpenPostDialog(b,c){if(b>0){var a="Post a reply"}else{var a="Post a comment"}Boxy.load("/comments.php?act=show_post&replay_to="+b,{fixed:false,cache:false,modal:true,borderWidth:0,title:a,unloadOnHide:true,afterShow:function(){var d={url:"/comments.php?act=post&fid="+work_id+"&type="+work_type,type:"post",dataType:"json",timeout:30000,beforeSubmit:ValidatePost,success:function(e){AfterPost(e,c)}};$("#formPostComment").submit(function(){tinyMCE.triggerSave();$(this).ajaxSubmit(d);return false});$("#send_to_facebook").click(function(){if($(this).attr("checked")&&!FB.Connect){fb_init()}})}})}function ValidatePost(d,b,a){var c=b[0];if(c.not_login.value=="none"){if(!c.email_address.value||c.email_address.value==c.email_address.title){$("#error_msg").html("Please enter your email address.");return false}if($("#panel_hasnot_login input:radio:checked").val()=="1"){if(!c.password.value){$("#error_msg").html("Please enter your password.");return false}}else{if(!c.full_name.value||c.email_address.value==c.full_name.title){$("#error_msg").html("Please enter your full name.");return false}if(!c.screen_name.value||c.email_address.value==c.screen_name.title){$("#error_msg").html("Please enter your screen name.");return false}}}if(!c.contents.value||c.contents.value==c.contents.title){$("#error_msg").html("Please enter your comments / feedback.");return false}$("#post_comment").attr("disabled",true);if($("#send_to_facebook").attr("checked")&&!FB.Connect){fb_init()}return true}function AfterPost(a,b){$("#post_comment").attr("disabled",false);switch(a.status){case -1:$("#panel_already_login").hide();$("#panel_hasnot_login").show();$("#has_account_1").attr("checked","checked");$("#error_msg").html(a.msg.replace(/\n/g,"<br />"));SwitchHasAccountOrNot();break;case -2:alert(a.msg);Boxy.get(".close").hide();break;case 1:$("#post_comment").attr("disabled",true);if($$("send_to_facebook").checked){if(b){b(a)}else{LoadComments(1)}fb_init(function(){PostToFBWall(a.commentId)})}else{alert(a.msg);if(b){b(a)}else{LoadPage(1)}Boxy.get(".close").hide()}break;default:$("#error_msg").html(a.msg.replace(/\n/g,"<br />"));break}}function SwitchHasAccountOrNot(){if($("#panel_hasnot_login input:radio:checked").val()=="1"){$(".show_no_account").hide();$(".show_has_account").show()}else{$(".show_no_account").show();$(".show_has_account").hide()}}function Request(c,d){if(d==null){d=window.location.href}var a="";if(d.search(/\?/)!=-1){d=d.substr(d.search(/\?/)+1);d=d.split(/&/);for(var b=0;b<d.length;b++){if(d[b].search("^"+c+"=")!=-1){a=d[b].substr(c.length+1)}}return(a)}else{return 0}}function SetQuery(d,a,b){if(b==null){b=location.href}if(d.constructor==Array){for(var c=0;c<d.length;c++){if(!Request(d[c],b)){if(b.indexOf("?")<1){b+="?"+d[c]+"="+a[c]}else{b=b.replace("&"+d[c]+"=","");b+="&"+d[c]+"="+a[c]}}else{b=b.replace(d[c]+"="+Request(d[c],b),d[c]+"="+a[c])}}}else{if(!Request(d,b)){if(b.indexOf("?")<1){b+="?"+d+"="+a}else{b=b.replace("&"+d+"=","");b+="&"+d+"="+a}}else{b=b.replace(d+"="+Request(d,b),d+"="+a)}}return b}function PostToFBWall(e,a){var d={1:"Article",2:"Image",3:"Summer program"};var h=$("#word_title").html();var i=$($("#comment_content").val()).text();var j=GetPageUrl().replace(/#.*/g,"");var g=j+"#comment"+e;var f={};var b=d[work_type];f[b]={text:h,href:j};var c={method:"stream.publish",message:"",attachment:{name:b+" comments on: "+h,href:g,description:i,properties:f,media:[{type:"image",src:"http://www.teenink.com/images/logo_for_fb_large.gif",href:"http://www.teenink.com"}]},action_links:[{text:"Check out Teenink",href:"http://www.teenink.com"}],user_prompt_message:"Share the comments to your facebook wall."};FB.ui(c,function(k){if(k){alert("Thanks! Your comment has been submitted successfully. Please note that some comments are subject to prior approval by our editors, and we thank you for your patience.")}Boxy.get(".close").hide()})}function RequestDelete(b){if(!confirm("Are you sure you want to request deletion of this comment?\n\nTeen Ink moderators will review your request and remove\nthe comment if it contains offensive content.")){return}var a={url:"/comments.php?act=req_delete&fid="+work_id+"&type="+work_type+"&cid="+b,type:"post",timeout:30000,beforeSubmit:ValidatePost,success:function(c){alert(c);window.location.reload(false)}};jQuery.ajax(a)};

