if(typeof ISSUU=="undefined"){var ISSUU={}}if(typeof ISSUU.factory=="undefined"){ISSUU.factory={}}ISSUU.factory.validateform=function(C,A){var B={compareWithMemory:function(){var F=B.collectAllFieldValues();var E;var D=true;for(E in F){if(F[E]!=B.memory[E]){D=false}}return D},memorize:function(){B.memory=B.collectAllFieldValues()},revert:function(){var D;for(D in B.memory){B.setInputField(D,B.memory[D])}},collectAllFieldValues:function(){var D={};$("#"+B.formId+" :input").each(function(){D[this.name]=B.getUserInput(this.name)});return D},getUserInput:function(D){var F=$("#"+B.formId+' [name="'+D+'"]');if(F.is('[type="hidden"]')){return F.val()}if(F.is('[type="password"]')){return F.val()}if(F.is('[type="text"]')){return F.val()}else{if(F.is("select")){return F.val()}else{if(F.is('[type="radio"]')){var E=false;F.each(function(){if($(this).attr("checked")==true){E=$(this).attr("value")}});return E}else{if(F.is('[type="checkbox"]')){return F.attr("checked")}else{if(F.is("textarea")){return F.val()}}}}}},setInputField:function(D,E){var F=$("#"+B.formId+' [name="'+D+'"]');if(F.is('[type="hidden"]')){F.val(E)}if(F.is('[type="password"]')){F.val(E)}if(F.is('[type="text"]')){F.val(E)}else{if(F.is("select")){$('select[name="'+D+'"] option[value="'+E+'"]').attr("selected","selected")}else{if(F.is('[type="radio"]')){$('input[name="'+D+'"][value="'+E+'"]').attr("checked","checked")}else{if(F.is('[type="checkbox"]')){F.attr("checked","checked")}else{if(F.is("textarea")){F.val(E)}}}}}},takeStringFromArray:function(D,F){for(var E=0;E<=F.length-1;E++){if(F[E]==D){F.splice(E,1)}}return F},getCaptcha:function(){if($("#captcha").length>0){$(".captchaSpinner").fadeIn(125);$("#captchaSolution").val("");$.getJSON("http://api."+ISSUU.server.model.domain+"/query?action=issuu.captcha.get&format=json&jsoncallback=?",function(E){if(E.rsp.stat!="ok"){alert("sorry we have problem getting the captcha image..")}else{var D=E.rsp._content.captcha.url;$("#captcha").attr("src",D);$("#captchaId").val(E.rsp._content.captcha.id)}})}},startValidationProcess:function(G){B.todolist=[];var F=[];if(G=="-ALL_NO_SUBMIT-"){B.validationMode=G;for(D in B.formRules){F.push(D)}}else{if(G=="-ALL-"){B.validationMode=G;var D;for(D in B.formRules){F.push(D)}}else{if(typeof G==="string"){B.validationMode=null;F.push(G)}else{if(Object.prototype.toString.apply(G)==="[object Array]"){B.validationMode=null;F=G}}}}var E;for(E=0;E<=F.length-1;E++){B.todolist.push(F[E])}for(E=0;E<=F.length-1;E++){B.validateOneField(F[E])}if(B.formRulesLength()==0&&G=="-ALL-"){$("#"+B.formId).trigger("valid-submitted-form-event")}},validateOneField:function(D){if(!B.formRules.hasOwnProperty(D)||!B.formRules[D].hasOwnProperty("localTests")){B.checkSeverTests(D);return }else{var F=B.formRules[D].localTests;var E;for(E in F){B.runOneLocalTest(D,F[E],E)}if(B.isThisFieldGood(D)){B.checkSeverTests(D);return }else{$("#"+B.formId).trigger("one-field-answer",[{field:D,result:"fail"}]);return }}},runOneLocalTest:function(L,N,O){var G=$("#"+L);if(G.length<1){}var M=B.getUserInput(L);if(N.condition&&M){var H=false;if(M.toString().search(N.condition)>0){H=true}if(!(H==N.conditionval)){B.setError(L,O,"good");return }}switch(O){case"required":if($(G).val()==""){B.setError(L,O,"error")}else{B.setError(L,O,"good")}break;case"requiredCheckbox":if(M!=true){B.setError(L,O,"error")}else{B.setError(L,O,"good")}break;case"email":result=B.validateEmail($(G).val());if(result){B.setError(L,O,"good")}else{B.setError(L,O,"error")}break;case"sameAs":var D=$("input[name='"+N.compareTo+"']");if($(D).val()==$(G).val()){B.setError(L,O,"good")}else{B.setError(L,O,"error")}break;case"minLength":if(M.length<N.minimum){B.setError(L,O,"error")}else{B.setError(L,O,"good")}break;case"maxLength":if(M.length>N.maximum){B.setError(L,O,"error")}else{B.setError(L,O,"good")}break;case"phoneNumber":pattern=/[^0-9 \-]/;if(pattern.test(M)){B.setError(L,O,"error")}else{B.setError(L,O,"good")}break;case"canNotBe":if(M==N.value){B.setError(L,O,"error")}else{B.setError(L,O,"good")}break;case"loggedInUser":if(ISSUU.utils.User.isLoggedin()){B.setError(L,O,"good")}else{B.setError(L,O,"error")}break;case"validUrl":var F=$(G).val();var J=/http:\/\/[A-Za-z]+\.[A-Za-z]+/;if(J.test(F)){B.setError(L,O,"good")}else{B.setError(L,O,"error")}break;case"tinyUrl":var K=new RegExp("^(\\*\\.)?([a-z0-9-]+\\.)+[a-z]+$","i");if(K.test(M)){B.setError(L,O,"good")}else{B.setError(L,O,"error")}break;case"validURLFilename":var E=/[^A-Za-z0-9_.\-]+/i;var I=E.exec(M);if(I){B.setError(L,O,"error")}else{B.setError(L,O,"good")}break;default:B.setError(L,O,"error");break}},runOneServerTest:function(D,I,H){$("#"+B.formId+' [name="'+D+'"]').attr("disabled","disabled");B.disableSubmitButton();var G=new Date();var F=G.getTime();$("label[for='"+D+"']").parent().append('<span id ="'+F+'"><img style="display: inline;" class="float" src="http://static.issuu.com/html/v1.1.17/staticFiles/img/spinners/spinner12x12.gif" ></span>').fadeIn("slow");var E=$("#"+D);switch(H){case"issuu.user.email_available":$.getJSON("http://api."+ISSUU.server.model.domain+"/query?action=issuu.user.email_available&format=json&email="+encodeURIComponent(E.val())+"&jsoncallback=?",function(J){$("#"+F).remove();if(J.rsp.stat=="ok"){B.setError(D,H,"good");$("#"+B.formId).trigger("one-field-answer",[{field:D,result:"ok",type:"server"}])}else{B.setError(D,H,"error",{code:J.rsp._content.error.code,field:encodeURIComponent(J.rsp._content.error.field)});$("#"+B.formId).trigger("one-field-answer",[{field:D,result:"fail",type:"server"}])}$("#"+B.formId+' [name="'+D+'"]').removeAttr("disabled");B.enableSubmitButton()});break;case"issuu.user.username_available":$.getJSON("http://api."+ISSUU.server.model.domain+"/query?action=issuu.user.username_available&format=json&username="+encodeURIComponent(E.val())+"&jsoncallback=?",function(J){$("#"+F).fadeOut(125);if(J.rsp.stat=="ok"){B.setError(D,H,"good");$("#"+B.formId).trigger("one-field-answer",[{field:D,result:"ok",type:"server"}])}else{B.setError(D,H,"error",{code:J.rsp._content.error.code,field:J.rsp._content.error.field});$("#"+B.formId).trigger("one-field-answer",[{field:D,result:"fail",type:"server"}])}$("#"+B.formId+' [name="'+D+'"]').removeAttr("disabled");B.enableSubmitButton()});break;default:return false}},validateEmail:function(E){if(typeof E==="undefined"){return false}var D=/^[a-zA-Z0-9]{1}[a-zA-Z0-9\._+\-]*@[a-zA-Z0-9]{1}[a-zA-Z0-9\._+\-]*\.[a-zA-Z]{2,6}$/;return D.test(E)},setError:function(F,G,D,E){if(typeof B.errors[F]!="object"){B.errors[F]=[]}if(!B.errors[F][G]){B.errors[F][G]={}}B.errors[F][G].result=D;if(E){B.errors[F][G].error=E}if(E){}},errorsToConsole:function(){var E;for(E in B.errors){var D;for(D in B.errors[E]){if(B.errors[E][D].error){}}}},returnErrors:function(){return B.errors},isFormFreeOfRecordedErrors:function(){var E=true;var D;for(D in B.formRules){if(!B.isThisFieldGood(D)){E=false}}return E},isThisFieldGood:function(D){if(B.errors.hasOwnProperty(D)){var F=true;var E;for(E in B.errors[D]){if(B.errors[D][E].result!=="good"){F=false}}return F}else{return true}},checkSeverTests:function(D){if(!B.formRules.hasOwnProperty(D)||!B.formRules[D].hasOwnProperty("serverTests")){$("#"+B.formId).trigger("one-field-answer",[{field:D,result:"ok"}]);return }else{var E=B.formRules[D].serverTests;var F;for(F in E){B.runOneServerTest(D,E[F],F)}}},printErrorsForField:function(E){var H="";var D=E+"-error_ms";var G;loop:for(G in B.errors[E]){if(B.errors[E][G].result!="good"){var F=B.generateErrorMessage(E,G,B.errors[E][G]);H+=F;break loop}}$("span."+D).html(H);if(H!=""){$("#"+E).addClass("err")}else{$("#"+E).removeClass("err")}},generateErrorMessage:function(J,K,G){var I;if(G.error){I=B.messages[K][G.error.code]}else{I=B.messages[K].defaultMsg}var H=I.match(/<#[\w\.]+#>/g);if(H&&typeof H=="object"){for(var F=0;F<H.length;F++){var E=H[F];E=E.replace("<#","");E=E.replace("#>","");var D=J+"."+E;value=B.getValueFromRules(D);I=I.replace(H[F],value)}}H=I.match(/<%[\w\.]+%>/g);if(H&&typeof H=="object"){for(var F=0;F<H.length;F++){var E=H[F];E=E.replace("<%","");E=E.replace("%>","");I=I.replace(H[F],G.error[E])}}return I},getValueFromRules:function(F){var D=F.split(".");var E;switch(D.length){case 1:E=B.formRules[D[0]];break;case 2:E=B.formRules[D[0]][D[1]];break;case 3:E=B.formRules[D[0]][D[1]][D[2]];break;case 4:E=B.formRules[D[0]][D[1]][D[2]][D[3]];break;case 5:E=B.formRules[D[0]][D[1]][D[2]][D[3]][D[4]];break}return E},messages:{required:{defaultMsg:"<#nicename#> missing. "},email:{defaultMsg:"<#nicename#> must be valid e-mail (e.g. name@company.com). "},sameAs:{defaultMsg:"<#nicename#> and <#localTests.sameAs.compareTo#> are not identical. "},minLength:{defaultMsg:"<#nicename#> must be at least <#localTests.minLength.minimum#> characters. "},maxLength:{defaultMsg:"<#nicename#> must be maximum <#localTests.maxLength.maximum#> characters. "},phoneNumber:{defaultMsg:"Please enter a valid phone number. "},canNotBe:{defaultMsg:"Please make a selection for <#nicename#>. "},validUrl:{defaultMsg:"<#nicename#>  must be a valid url. "},validURLFilename:{defaultMsg:"Use only a-z, 0-9 and  -_. (no spaces) for <#nicename#>."},usernameAvailable:{defaultMsg:"<#nicename#> not available"},emailAvailable:{defaultMsg:"<#nicename#> not available"},captcha:{defaultMsg:"Please enter the four letters in the image."},"issuu.user.username_available":{"100":"<#nicename#> not available"},"issuu.user.email_available":{"004":'Did you just try to sign up with this email? <a href="/resendemail?username=<%field%>">Resend confirmation email</a>',"101":"<#nicename#> not available","306":"Too many preregistrations"},requiredCheckbox:{defaultMsg:"<#localTests.requiredCheckbox.message#>"},loggedInUser:{defaultMsg:"You must be logged in to use this <#nicename#>. "},tinyUrl:{defaultMsg:"<#nicename#> must be in the format: <i>domain.topleveldomain</i>"}},findPos:function(D){var E;curtop=0;if(D.offsetParent){do{E+=D.offsetLeft;curtop+=D.offsetTop}while(D=D.offsetParent);return[E,curtop]}},scrollToTopError:function(){var D={name:false,offset:false};var E=B.getBadFieldsList();for(var G in E){var F=$("#"+E[G]).get(0);var H=B.findPos(F);if(H){H=H[1];if(H<D.offset||D.offset==false){D.offset=H;D.name=E[G]}}else{}}B.scrollToField(D.name)},scrollToField:function(F){var D="#"+F;var E=-Math.floor($(window).height()/3);$.scrollTo(D,400,{offset:E})},getBadFieldsList:function(){var F=[];var G;for(G in B.errors){var E=true;var D;for(D in B.errors[G]){if(B.errors[G][D].result=="error"){E=false}}if(E!=true){F.push(G)}}return F},changeRules:function(D){B.removeAllErrormessagesOnScreen();B.formRules=D;B.errors={}},removeAllErrormessagesOnScreen:function(){for(var D in B.formRules){$("#"+D).removeClass("err");$("."+D+"-error_ms").html(" ")}}};B.formId=C;B.formRules=A;B.formRulesLength=function(){var D=0;for(var E in B.formRules){D++}return D};B.errors={};B.memory={};B.todolist=[];B.validationMode=null;B.submitfunction=function(E){E.preventDefault();var D="#"+B.formId+" a.submitbutton";if(ISSUU.utils.button){ISSUU.utils.button.disable(D)}else{$(D).unbind("click")}$("#buttonErrorMs").html("");$("#"+B.formId).submit();return false};B.enableSubmitButton=function(){var D="#"+B.formId+" a.submitbutton";if(ISSUU.utils.button){ISSUU.utils.button.enable(D,B.submitfunction)}else{$(D).bind("click",B.submitfunction)}};B.disableSubmitButton=function(){if(ISSUU.utils.button){var D="#"+B.formId+" a.submitbutton";ISSUU.utils.button.disable(D)}else{$("#"+B.formId+" a.submitbutton").unbind("click",B.submitfunction)}};B.enableSubmitButton();$("#"+B.formId).submit(function(D){D.stopPropagation();D.preventDefault();B.errors={};B.startValidationProcess("-ALL-");return false});$("#"+B.formId+" :radio").bind("click.vaidator",function(D){$("#"+B.formId).trigger("form-change",[D]);B.errors[this.name]=[];B.startValidationProcess(this.name)});$("#"+B.formId+" :checkbox").bind("click.validator",function(D){$("#"+B.formId).trigger("form-change",[D]);B.errors[this.name]=[];B.startValidationProcess(this.name)});$("#"+B.formId+" :text").bind("change.validator",function(D){$("#"+B.formId).trigger("form-change",[D]);B.errors[this.name]=[];B.startValidationProcess(this.name)});$("#"+B.formId+" :password").bind("change.validator",function(D){$("#"+B.formId).trigger("form-change",[D]);B.errors[this.name]=[];B.startValidationProcess(this.name)});$("#"+B.formId+" select").bind("change.validator",function(D){$("#"+B.formId).trigger("form-change",[D]);B.errors[this.name]=[];B.startValidationProcess(this.name)});$("#"+B.formId+" textarea").bind("change.validator",function(D){$("#"+B.formId).trigger("form-change",[D]);B.errors[this.name]=[];B.startValidationProcess(this.name)});$("#"+B.formId).bind("one-field-answer",function(E,D){if(D.result=="fail"){B.printErrorsForField(D.field);$("."+D.field+"-available_ms").html("")}else{if(D.result=="ok"){$("#"+D.field).removeClass("err");$("."+D.field+"-error_ms").html(" ");if(D.type=="server"){$("."+D.field+"-available_ms").html(B.formRules[D.field].nicename+" available");$("#"+D.field).addClass("inputGreen")}}}B.takeStringFromArray(D.field,B.todolist);if(B.todolist.length===0){if(B.validationMode=="-ALL-"){B.validationMode=null;if(B.isFormFreeOfRecordedErrors()){$("#"+B.formId).trigger("valid-submitted-form-event")}else{B.enableSubmitButton();B.scrollToTopError()}}else{if(B.validationMode=="-ALL_NO_SUBMIT-"){B.validationMode=null}}}else{}});$("#"+B.formId).bind("valid-submitted-form-event",function(E,D){$("#"+B.formId).trigger(B.formId+"-valid-submitted",B.collectAllFieldValues())});B.getCaptcha();$(".refreshCaptcha").click(function(){B.getCaptcha();return false});$("#captcha").load(function(D){$(".captchaSpinner").fadeOut(125)});B.stopValidation=function(){$("#"+B.formId).unbind();$("#"+B.formId+" :radio").unbind("click.validator");$("#"+B.formId+" :checkbox").unbind("click.validator");$("#"+B.formId+" :text").unbind("change.validator");$("#"+B.formId+" :password").unbind("change.validator");$("#"+B.formId+" select").unbind("change.validator");$("#"+B.formId+" textarea").unbind("change.validator")};return B};if(typeof ISSUU=="undefined"){var ISSUU={}}ISSUU.login=function(){var A;var C={username:{nicename:"This field",localTests:{required:{},minLength:{minimum:"4"},maxLength:{maximum:"30",condition:/@/,conditionval:false},validURLFilename:{condition:/@/,conditionval:false},email:{condition:/@/,conditionval:true}}},password:{nicename:"Password",localTests:{required:{},minLength:{minimum:"4"},maxLength:{maximum:"30"}}}};$(document).ready(function(){A=ISSUU.factory.validateform("myForm",C);$("#myForm :disabled").each(function(){$(this).removeAttr("disabled")});$('#myForm input[name="username"]').focus();$("#myForm :input").keypress(function(D){if((D.which&&D.which==13)||(D.keyCode&&D.keyCode==13)){ISSUU.utils.log("enter button");$("#myForm a.submitbutton").click();return false}else{return true}});$("#myForm").bind("myForm-valid-submitted",function(E,D){$("img.mainSpinner").fadeIn("125");D.format="json";D.permission="f";if(D.username.search(/@/)>0){D.email=D.username;delete D.username;D.action="issuu.user.login_email"}else{D.action="issuu.user.login"}$("#myForm :input").attr("disabled","disabled");ISSUU.utils.api({data:D,always:function(){A.enableSubmitButton();$("#myForm :input").removeAttr("disabled");$("img.mainSpinner").css("display","none")},onOk:function(F){$("img.mainSuccess").show();var G={username:F._content.user.username,explicit:F._content.user.explicit,zoomMode:F._content.user.zoomMode,zoomLevel:F._content.user.zoomLevel};ISSUU.utils.User.concludeLogin(G);var H=ISSUU.utils.UrlHelper.getUrlHashMap();if(typeof H.onLogin!="undefined"){window.location.href=H.onLogin}else{window.location.href="/home"}},onFail:function(F){var G="";var H={E000:"Login failed"};if(F&&F.code&&F.code=="004"){H.E004='Email unconfirmed. <a href="/resendemail?username='+encodeURIComponent(F.field)+'">Resend confirmation email</a>'}if(F&&F.code){G=H["E"+F.code]}else{G="Oops, something went wrong, please try again: "+F.code}$("#buttonErrorMs").html(G)},onTrouble:function(F){$("span.mainSpinner").fadeOut("250");$("#buttonErrorMs").html("Having trouble connecting to the server "+F);$("#myForm :input").removeAttr("disabled")},config:{username:false,token:false}})})});var B={};return B}();