LibManager.require("Scheduler");LibManager.require("frame.prototype.ajax");LibManager.require("frame.prototype.form");LibManager.require("frame.scriptaculous.effects"); var TheatreReviewRatingController={ajaxRequest:null,ajaxTimeout:null,ajaxReqTime:null,ajaxMaxReqTime:1E4,ajaxCheckInterval:500,ajaxBaseUrl:"/HolidayReview/AddRatingToReview",init:function(){Scheduler.schedule("reviewListingEnd","TheatreReviewRatingController.attach()")},attach:function(){for(i=0;i<=document.forms.length-1;i++)document.forms[i].className=="reviewRating"&&Event.observe(document.forms[i],"submit",this.validate.bindAsEventListener(this))},validate:function(a){var b=Event.element(a),c= Form.getInputs(b,"radio","rating");b=Form.getInputs(b,"hidden","reviewId")[0].value;var e=0,d=$("ratingWrapper_"+b),f=$("ratingMsg_"+b);if(c[0].checked||c[1].checked){e=c[0].checked?c[0].value:c[1].value;this.rateReview(b,e,f,d)}else{f.firstChild.nodeValue="You have not selected whether the review was helpful or not helpful.";this.doHighlight(d);this.styleMsgBox(f)}Event.stop(a)},callInProgress:function(){switch(this.ajaxRequest.transport.readyState){case 1:case 2:case 3:return true;default:return false}}, rateReview:function(a,b,c,e){a={content:"rateTheatreReviewAjax",rating:b,reviewId:a,reviewType:"theatre"};this.styleMsgBox(c);this.createAjaxUpdater(e,c,a,"Error: no data received. Please try again.")},checkResponse:function(){var a=this;this.ajaxReqTime+=this.ajaxCheckInterval;if(this.callInProgress()&&this.ajaxReqTime>=this.ajaxMaxReqTime){this.ajaxRequest.transport.abort();this.ajaxRequest.options.onFailure&&this.ajaxRequest.options.onFailure()}else this.ajaxTimeout=window.setTimeout(function(){a.checkResponse()}, this.ajaxCheckInterval)},doHighlight:function(a){new Effect.Highlight(a,{startcolor:"#ffffff",endcolor:"#ffffcc",duration:0.5})},styleMsgBox:function(a){a.style.padding="1em 0 1em 0"},createAjaxUpdater:function(a,b,c,e){var d=this;this.ajaxReqTime=0;this.ajaxTimeout=window.setTimeout(function(){d.checkResponse()},d.ajaxCheckInterval);this.ajaxRequest=new Ajax.Updater(b,d.ajaxBaseUrl,{method:"get",parameters:$H(c).toQueryString(),onComplete:function(f){window.clearTimeout(d.ajaxTimeout);!f.responseText.length|| f.status!=200?alert(e):d.doHighlight(a)},onFailure:function(){window.clearTimeout(d.ajaxTimeout);alert("Error: Cannot contact database. Please try again.")}})}};LibManager.isLoaded(["scheduler"],TheatreReviewRatingController.init());