Flixster={};
Flixster.server="";
Flixster.container="";
Flixster.api="/api/v1";
Api={};
Api.MPT={};
Component.MptTabs=Class.create({initialize:function(A){this.element=$(A);
this.period=this.element.readAttribute("period");
this.limit=this.element.readAttribute("limit");
this.quizType=this.element.readAttribute("quizType");
this.element.observe("period:click",this.onPeriodClick.bindAsEventListener(this));
this.element.observe("limit:click",this.onLimitClick.bindAsEventListener(this));
},onPeriodClick:function(A){A.stop();
this.period=A.memo.period;
this.element.select(".subtabsLink").each(function(B){var C=B.readAttribute("period");
if(C==this.period){B.addClassName("selected");
}else{B.removeClassName("selected");
}}.bind(this));
this.refresh();
},onLimitClick:function(A){A.stop();
this.limit=A.memo.limit;
this.element.select(".subtabAction").each(function(C){var B=C.readAttribute("limit");
if(B==this.limit){C.addClassName("selected");
}else{C.removeClassName("selected");
}}.bind(this));
this.refresh();
},refresh:function(){var A={limit:this.limit,period:this.period};
new View.RemoteView(this.element.up("div").down(".quizzes"),{url:Flixster.server+"/personalities/"+this.quizType,parameters:A});
}});
Component.RandomRecentMptsLink=Class.create(Component.Link,{onClick:function(A){A.stop();
new View.RemoteView(this.element.up("div"),{url:Flixster.server+"/personalities/recent"});
}});
Component.MptBasicsForm=Class.create(Component.Form,{onSubmit:function(B){var C=this.element.down("input[name=title]");
if(!TextUtils.hasText($F(C))||$F(C)==C.readAttribute("default")){B.stop();
new View.ErrorPopup(this.element,{title:"Missing Title",content:"Don't forget to give your quiz a title."});
}else{var A=this.element.down("textarea");
if($F(A)==A.readAttribute("default")){A.value="";
}this.submit=this.element.down("input[name=submit]");
this.submit.disable();
this.submit.up("label").addClassName("loading");
}}});
Component.MptCancelLink=Class.create(Component.Link,{onClick:function(A){A.stop();
new View.ConfirmationPopup(this.element,{content:"Are you sure you want to delete this personality?",onConfirm:this.onDelete.bindAsEventListener(this),onCancel:this.onCancel.bindAsEventListener(this)});
},onCancel:function(){},onDelete:function(){new Ajax.Request("/api/v1/mpts/"+this.element.readAttribute("quiz")+".json",{parameters:{_method:"delete"},method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
},onSuccess:function(A){this.element.up("li").update("Quiz cancelled.");
},onFailure:function(A){new View.ErrorPopup(this.element,{title:"Unexpected Error",content:"Failed to delete the quiz."});
}});
Component.MptQuizCategories=Class.create(Component.Select,{onChange:function(A){switch($F(this.element)){case"G":$("asearch").hide();
$("msearch").hide();
break;
case"M":$("asearch").hide();
$("msearch").show();
break;
case"A":$("msearch").hide();
$("asearch").show();
break;
case"O":$("asearch").hide();
$("msearch").hide();
break;
}}});
Component.MptQuizImageLink=Class.create(Component.Link,{onClick:function(A){A.stop();
this.element.up("fieldset").down("input").show();
}});
Component.SubmitLabel=Class.create({initialize:function(A){this.element=$(A);
this.element.observe("button:click",this.onClick.bindAsEventListener(this));
},onClick:function(A){this.element.addClassName("submitting");
}});
Component.MptPersonalityForm=Class.create(Component.Form,{onSubmit:function(B){var C=this.element.down("input[name=title]");
var A=this.element.down("textarea");
if($F(C)==C.readAttribute("default")){C.value="";
}if($F(A)==A.readAttribute("default")){A.value="";
}if(!TextUtils.hasText($F(C))||$F(C)==C.readAttribute("default")){B.stop();
new View.ErrorPopup(this.element,{title:"Missing Title",content:"Don't forget to give your quiz a title."});
}else{this.submit=this.element.down("input[name=submit]");
this.submit.disabled=true;
this.submit.up("label").addClassName("loading");
}}});
Component.MptPersonalityDeleteForm=Class.create(Component.Form,{onSubmit:function(A){A.stop();
new View.ConfirmationPopup(this.element,{content:"Are you sure you want to delete this personality?",onConfirm:this.onConfirm.bindAsEventListener(this),onCancel:this.onCancel.bindAsEventListener(this)});
},onConfirm:function(B){var C=this.element.serialize(true);
var A={_method:"delete",_format:"json"};
new Ajax.Request("/api/v1/mpts/"+C.quiz+"/personalities/"+C.personality,{parameters:A,method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
},onCancel:function(A){},onSuccess:function(A){new Effect.Shrink(this.element.up("li"),{direction:"top-left",duration:0.5});
},onFailure:function(A){var B=A.responseText.evalJSON();
new View.ErrorPopup(this.element,{title:"Error",content:B.error});
}});
Component.MptQuestionSortableList=Class.create({initialize:function(A){this.element=$(A);
Sortable.create(this.element);
}});
Component.MptQuestionForm=Class.create(Component.Form,{onSubmit:function(B){B.stop();
var A=this.element.serialize(true);
A._format="json";
A.choice=A.choice.without("");
if(!TextUtils.hasText(A.question)){new View.ErrorPopup(this.element,{title:"Missing Question",content:"Don't forget to fill out the question."});
return ;
}if(A.choice.size()!=A.choice.uniq().size()){new View.ErrorPopup(this.element,{title:"Duplicate Answers",content:"Looks like you have a few duplicate answers, can you remove them?"});
return ;
}if(A.choice.size()<2){new View.ErrorPopup(this.element,{title:"Two Answer Choices Required",content:"You need at least two answers."});
return ;
}for(;
A.choice.size()<A.personality.size();
){A.personality.pop();
}this.submit=this.element.down("input[name=submit]");
this.submit.disabled=true;
this.submit.up("label").addClassName("loading");
new Ajax.Request("/api/v1/mpts/"+A.quiz+"/questions",{parameters:A,method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
},onSuccess:function(A){window.location.reload(true);
},onFailure:function(A){var B=A.responseText.evalJSON();
new View.ErrorPopup(this.element,{title:"Error",content:B.error});
}});
Component.MptQuestionDeleteForm=Class.create(Component.Form,{onSubmit:function(A){A.stop();
new View.ConfirmationPopup(this.element,{content:"Are you sure you want to delete this question?",onConfirm:this.onConfirm.bindAsEventListener(this),onCancel:this.onCancel.bindAsEventListener(this)});
},onConfirm:function(C){var B=this.element.serialize(true);
var A={_method:"delete",_format:"json"};
new Ajax.Request("/api/v1/mpts/"+B.quiz+"/questions/"+B.question,{parameters:A,method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
},onCancel:function(A){},onSuccess:function(A){new Effect.Shrink(this.element.up("li"),{direction:"top-left",duration:0.5});
},onFailure:function(A){var B=A.responseText.evalJSON();
new View.ErrorPopup(this.element,{title:"Error",content:B.error});
}});
Component.MptAddQuestionChoiceLink=Class.create(Component.Link,{onClick:function(B){B.stop();
var A=this.element.up("tr").previous("tr").innerHTML;
this.element.up("tr").insert({"before":A});
}});
Component.MptPublisher=Class.create(Component.Form,{onSubmit:function(A){A.stop();
this.parameters=this.element.serialize(true);
this.parameters._format="json";
this.parameters._method="put";
new Ajax.Request("/api/v1/mpts/"+this.parameters.quiz,{parameters:this.parameters,method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
},onSuccess:function(A){document.location="/personalities/share?quiz="+this.parameters.quiz;
},onFailure:function(A){var B=A.responseText.evalJSON();
new View.ErrorPopup(this.element,{title:"Error",content:B.error});
}});
Component.MptQuiz=Class.create(Component.Form,{onSubmit:function(A){var B=this.element.serialize(true);
if(!this.element.select("input[type=radio]").any(function(C){return C.checked;
})){A.stop();
new View.ErrorPopup(this.element,{title:"Whoops, you forgot something",content:"Answer at least one question to find out your personality."});
}else{this.element.down("input[type=submit]").up("label").addClassName("loading");
this.element.down("input[type=submit]").disable();
}}});
Component.MptQuizRating=Class.create(Component.Form,{initialize:function(A){this.element=$(A);
this.element.observe("button:click",this.onRating.bind(this));
},onRating:function(A){A.stop();
var B=this.element.serialize(true);
new Ajax.Request("/api/v1/mpts/"+B.quiz+"/ratings.json",{parameters:B,method:"post",onSuccess:this.onSuccess.bind(this),onFailure:this.onFailure.bind(this)});
},onSuccess:function(B){var A=B.responseText.evalJSON();
var C=new Template("<div>Average Rating #{average}</div><div>(#{ratings} ratings)</div>");
this.element.update(C.evaluate(A));
},onFailure:function(A){var B=A.responseText.evalJSON();
new View.ErrorPopup(this.element,{title:"Error",content:B.error});
}});
Component.MovieSearchForm=Class.create({STATES:{READY:0,SEARCHING:1},initialize:function(A){this.element=$(A);
this.state=this.STATES.READY;
this.element.observe("button:click",this.onSearch.bindAsEventListener(this));
this.element.observe("keypress:enter",this.onSearch.bindAsEventListener(this));
},onSearch:function(B){B.stop();
if(this.state==this.STATES.READY){this.state=this.STATES.SEARCHING;
this.element.down("input[type=button]").disable();
this.element.down("label").addClassName("loading");
this.results=this.element.down(".results");
new View.LoadingView(this.results,{message:"Searching movies..."});
var A=$F(this.element.down(".search"));
MoviesApi.findMovies(A,this.onSuccess.bind(this));
}},onSuccess:function(A){var C=$A(A.responseText.evalJSON());
var B=this.element.readAttribute("name");
new View.MovieSearchResultsView(this.results,{name:B,movies:C});
this.state=this.STATES.READY;
this.element.down("input[type=button]").enable();
this.element.down("label").removeClassName("loading");
}});
Component.ActorSearchForm=Class.create({STATES:{READY:0,SEARCHING:1},initialize:function(A){this.element=$(A);
this.element.observe("button:click",this.onSearch.bindAsEventListener(this));
this.element.observe("keypress:enter",this.onSearch.bindAsEventListener(this));
this.state=this.STATES.READY;
},onSearch:function(C){C.stop();
if(this.state==this.STATES.READY){this.state=this.STATES.SEARCHING;
this.element.down("input[type=button]").disable();
this.element.down("label").addClassName("loading");
var B=$(this.element).select(".results").first();
new View.LoadingView(B,{message:"Searching actors..."});
var A=$F(this.element.down(".search"));
ActorsApi.findActors(A,this.onSuccess.bind(this));
}},onSuccess:function(A){var D=$A(A.responseText.evalJSON());
var C=$(this.element).select(".results").first();
var B=$(this.element).readAttribute("name");
new View.ActorSearchResultsView(C,{name:B,actors:D});
this.state=this.STATES.READY;
this.element.down(".button").enable();
this.element.down("label").removeClassName("loading");
}});
Component.SearchField=Class.create(Component.TextField,{initialize:function($super,A){$super(A);
this.element.observe("keypress",this.onEnter.bindAsEventListener(this));
},onEnter:function(A){if(A.keyCode==Event.KEY_RETURN){A.stop();
this.element.fire("keypress:enter");
return false;
}else{return true;
}}});
View.MovieSearchResultsView=Class.create({initialize:function(A,C){if(C.movies.length>0){var B="";
C.movies.each(function(D){B+="<label><input type='radio' name='"+C.name+"' value='"+D.id+"' /> "+D.title+"</label>";
}.bind(this));
$(A).update(B);
}else{new View.EmptySearchResultsView(A);
}}});
View.ActorSearchResultsView=Class.create({initialize:function(A,C){if(C.actors.length>0){var B="";
C.actors.each(function(D){B+="<label><input type='radio' name='"+C.name+"' value='"+D.id+"' /> "+D.name+"</label>";
}.bind(this));
$(A).update(B);
}else{new View.EmptySearchResultsView(A);
}}});
View.EmptySearchResultsView=Class.create({initialize:function(A){$(A).update("<p class='empty'>No results.</p>");
}});
Component.BaseQuizShare=Class.create(Component,{initialize:function($super,A){$super(A);
this.friends=A.friends;
this.pendingFriends=A.pendingFriend;
Event.observe("selectAll","click",this.onSelectAll.bindAsEventListener(this));
A.observe("submit",this.onSubmit.bindAsEventListener(this));
A.observe("form:submit",this.onSubmit.bindAsEventListener(this));
},onSelectAll:function(A){if(this.friends!=null){FormUtils.checkAll(this.friends);
}if(this.pendingFriends!=null){FormUtils.checkAll(this.pendingFriends);
}},onSubmit:function(A){return true;
}});
Component.QuizShare=Class.create(Component.BaseQuizShare,{initialize:function($super,A){$super(A);
if($("confirmationToggle")!=null){Event.observe("confirmationToggle","click",this.onToggleConfirmation.bindAsEventListener(this));
}Event.observe("publishBtn","click",this.onPublish.bindAsEventListener(this));
},onToggleConfirmation:function(A){Element.show("friendsPane");
Element.show("submitShare");
Element.hide("confirmation");
},onPublish:function(A){if(FormUtils.isAtleastOneChecked(this.friends)||FormUtils.isAtleastOneChecked(this.pendingFriends)){this.element.fire("form:submit");
}else{alert("Whoops, you forgot to choose the friends to share with.");
Event.stop(A);
}},getSource:function(){return"Share";
}});
Component.QuizEasyShare=Class.create(Component.BaseQuizShare,{initialize:function($super,C){$super(C);
Event.observe("unselectAll","click",this.onUnselectAll.bindAsEventListener(this));
var B=this.friends.length==undefined?1:this.friends.length;
for(var A=0;
A<B;
A++){Event.observe("thumbnail"+A,"click",this.onThumbnailClick.bindAsEventListener(this));
}},onUnselectAll:function(A){if(this.friends!=null){FormUtils.uncheckAll(this.friends);
}if(this.pendingFriends!=null){FormUtils.uncheckAll(this.pendingFriends);
}},onThumbnailClick:function(C){var B=Event.element(C);
var A=B.id.substring(9);
$("friend"+A).click();
},getSource:function(){return"EasyShare";
}});
Component.QuizShareFromResults=Class.create(Component,{initialize:function($super,A){$super(A);
Event.observe("selectAll","click",this.onSelectAll.bindAsEventListener(this));
A.observe("submit",this.onSubmit.bindAsEventListener(this));
},onSelectAll:function(A){FormUtils.checkAll(this.element.friends);
},onSubmit:function(A){if(FormUtils.isAtleastOneChecked(this.element.friends)){return true;
}else{A.stop();
alert("Whoops, you forgot to choose the friends to share with.");
}}});
Component.ForgotPassword=Class.create({MARKER_START:'<div id="passwordStatus">',MARKER_END:"</div>",initialize:function(A){this.element=$(A);
this.element.observe("click",this.onClick.bindAsEventListener(this));
},onClick:function(A){var C=$F("userauthEmail");
if(!TextUtils.hasText(C)){$("regStatus").update("Please enter your username or email address below to retrieve your password.");
$("regStatus").style.color="red";
showRow("statusRow");
}else{$("regStatus").update("Retrieving password...");
$("regStatus").style.color="green";
showRow("statusRow");
var B=Form.serialize("forgotPasswordForm")+"&userauthEmail="+C;
new Ajax.Request($("forgotPasswordForm").action,{parameters:B,onSuccess:this.processPasswordResponse.bind(this),onTimeout:this.onTimeout.bind(this),onFailure:this.onFailure.bind(this)});
}},processPasswordResponse:function(A){var D=A.responseText.indexOf(this.MARKER_START)+this.MARKER_START.length;
var B=A.responseText.indexOf(this.MARKER_END,D);
var C=A.responseText.substring(D,B).strip();
$("regStatus").update(C);
showRow("statusRow");
},onTimeout:function(A){$("regStatus").update("Whoops, your request timed out. Please check your network connection and try again.");
$("regStatus").style.color="red";
showRow("statusRow");
},onFailure:function(A){$("regStatus").update("Whoops, our servers coughed.  Please try again.");
$("regStatus").style.color="red";
showRow("statusRow");
}});
var quizWidget={STATES:{READY:0,SUBMITTING:1},ANON_SUBMISSION_TYPE:{REG:0,LOGIN:1},UPDATE_MSG_INTERVAL:1500,MARKER_START:'<div id="authStatus">',MARKER_END:"</div>",handleAnonSubmit:function(A){if(this.anonSubmissionType==this.ANON_SUBMISSION_TYPE.REG&&!validateForm(A)){return false;
}this.state=this.STATES.SUBMITTING;
var B=Form.serialize("anonRegForm");
new Ajax.Request($("anonRegForm").action,{parameters:B,onSuccess:this.processAuthenticationResponse.bind(this),onTimeout:this.onTimeout.bind(this),onFailure:this.onFailure.bind(this)});
$("quizSubmitBtn").disabled=true;
$("mptQuiz").style.cursor="wait";
showRow("statusRow");
if(this.anonSubmissionType==this.ANON_SUBMISSION_TYPE.REG){$("regStatus").update("Processing registration");
Tracker.trackPageview("MPT_Viral_Action_Register");
}else{if(this.anonSubmissionType==this.ANON_SUBMISSION_TYPE.LOGIN){$("regStatus").update("Attempting to log you in");
Tracker.trackPageview("MPT_Viral_Action_Login");
}}$("regStatus").style.color="green";
Clicker.counter=0;
this.drawSubmissionTicker();
return false;
},drawSubmissionTicker:function(){if(quizWidget.state==quizWidget.STATES.SUBMITTING){$("regStatus").innerHTML=$("regStatus").innerHTML+". ";
setTimeout(function(){quizWidget.drawSubmissionTicker();
},quizWidget.UPDATE_MSG_INTERVAL);
}},processAuthenticationResponse:function(A){var D=A.responseText.indexOf(this.MARKER_START)+this.MARKER_START.length;
var C=A.responseText.indexOf(this.MARKER_END,D);
var B=A.responseText.substring(D,C).strip();
$("regStatus").update(B);
showRow("statusRow");
if(B.search(/successful/i)>=0){$("regStatus").style.color="green";
this.state=this.STATES.SUBMITTING;
this.drawSubmissionTicker();
setTimeout(function(){quizWidget.handleQuizSubmit();
},500);
}else{this.allowPostErrorResubmission();
}},allowPostErrorResubmission:function(){$("regStatus").style.color="red";
this.state=this.STATES.READY;
$("quizSubmitBtn").disabled=false;
$("mptQuiz").style.cursor="default";
if($("captchaFields")){$("captchaFields").down(".captcha img").fire("captcha:refresh");
}},onTimeout:function(A){$("regStatus").update("Whoops, your request timed out. Please check your network connection and try again.");
showRow("statusRow");
this.allowPostErrorResubmission();
},onFailure:function(A){$("regStatus").update("Whoops, our servers coughed.  Please try again.");
showRow("statusRow");
this.allowPostErrorResubmission();
},toggleAnonAuth:function(B,A){if(B!=null){Event.stop(B);
}if(this.state==this.STATES.SUBMITTING){alert("Sorry, we are currently processing your prior "+(this.anonSubmissionType==this.ANON_SUBMISSION_TYPE.REG?"registration":"login")+" attempt.");
return false;
}$("regStatus").innerHTML="";
if(A){$("loginToggle").style.display="block";
$("registerToggle").style.display="none";
$("regTableTitle").update("Save your results");
$("usernameLabel").update("Email");
$("passwordLabel").update("Choose<br/>Password");
showRow("regSpecificFields");
showRow("disclaimer");
if($("captchaFields")){showRow("captchaFields");
}$("newsletter").style.display="inline";
$("forgotPassword").style.display="none";
$("anonRegForm").action="/userAuth.do?userauthAction=doRegister&flowType=MPT";
$("anonSubmitType").value="reg";
this.anonSubmissionType=this.ANON_SUBMISSION_TYPE.REG;
}else{$("loginToggle").style.display="none";
$("registerToggle").style.display="block";
$("regTableTitle").update("Login to save your results");
$("usernameLabel").update("Username");
$("passwordLabel").update("Password");
$("regSpecificFields").style.display="none";
if($("captchaFields")){$("captchaFields").style.display="none";
}$("disclaimer").style.display="none";
$("newsletter").style.display="none";
$("forgotPassword").style.display="inline";
$("anonRegForm").action="/userAuth.do?userauthAction=doLogin&flowType=MPT";
$("anonSubmitType").value="login";
this.anonSubmissionType=this.ANON_SUBMISSION_TYPE.LOGIN;
}return false;
},handleQuizSubmit:function(){$("mptQuizForm").submit();
},handleNewsletterCheck:function(){}};
quizWidget.anonSubmissionType=quizWidget.ANON_SUBMISSION_TYPE.REG;
function quizInvitePageToggleAddressBook(A){$("instructionAddressBookType").innerHTML=A;
}



