PortalReviewSubmit=function(){var
$=jQuery,form=$('#review_form'),validations={require:[['review_stars','Choose a star rating for this submission.'],['review_body','You must write a review!']]};form.off();if(form.find('#review_agreed').length){validations.require.push(['review_agreed','You must agree to the terms and conditions']);}
var validator=new NgFormValidator(form,validations);this.init=function(){$('#review_form_show').off();$('#review_form_show').click(function(e){var self=$(this);if(self.text()=='Cancel Review'){self.text('Write a Review');}else{self.text('Cancel Review');}
form.toggle();return false;});var reenable=function(){form.enableSubmit();};form.submit(function(e){if(validator.validate()){form.ajaxSubmit(function(text){$('#portal_reviews_container').replaceWith($('#portal_reviews_container',text));form.toggle();$('#review_form_show').hide();});return false;}else{alert(validator.getErrorMessages().join("\n"));}
e.preventDefault();});};};PortalReview=(function($){var instance,container;var portal_review=function(){var initialized=false,voteOnReview=function(e){var label=$(e.target);if(label.is('label')){var
radio=$('#'+ e.target.htmlFor),form_class_names={y:'yes',n:'no',x:'x'},form=label.up('form');;if(!radio.attr('disabled')){radio.attr('checked',true);form.ajaxSubmit(function(response){form.disable().down('span').html(response.message);});return false;}}},showResponseForm=function(){var self=$(this);$(this.href.substr(this.href.indexOf('#'))).toggle();if(-1===self.html().indexOf('Cancel')){self.data('original text',self.html());self.html('Cancel');}else{self.html(self.data('original text'));}
return false;},submitResponse=function(e){var $this=$(this);$this.ajaxSubmit(function(response){var
resp=$(response),authresponse=resp.find('div.authresponse'),modlinks=resp.find('div.modlinks');$this.enable().hide();var review_div=$this.prev('div');review_div.down('div.authresponse').remove();review_div.down('div.modlinks').before(authresponse).replaceWith(modlinks);},{dataType:'html'});return false;},changePage=function(){if(this.href){$.get(this.href,null,function(response){$('#portal_reviews').replaceWith(response);$('#portal_reviews').scrollTo();});return false;}},listenOnReviews=function(){container.off();container.delegate('form.helpful','click',voteOnReview).delegate('a.respond_to_review','click',showResponseForm).delegate('div.pagenav a','click',changePage).delegate('form[id^="review-response"]','submit',submitResponse);};this.init=function(){if(!initialized){listenOnReviews();initialized=true;}};};return{_:function(reviews_container,reset){instance=new portal_review();container=reviews_container||$('#portal_reviews');return instance;}};})(jQuery);