loadScript("messages_uri.stu");loadScript("dialogs/navigator.stu");loadScript("dialogs/signup/signup_dialog.stu");loadScript("dialogs/signupshort/signupshort_dialog.stu");loadScript("dialogs/reenter_address/reenter_address_dialog.stu");loadScript("dialogs/reenter_short_address/reenter_short_address_dialog.stu");loadScript("dialogs/get_password/get_password_dialog.stu");loadScript("dialogs/login/login_dialog.stu");loadScript("dialogs/verification/verification_dialog.stu");loadScript("dialogs/message/message_dialog.stu");loadScript("dialogs/progress/progress_dialog.stu");loadScript("st_tools.stu");var GlobalZip="";var GlobalAddress="";var userEmail="UserEmail";var userName="UserName";var signupForm=null;var invitationLogin=false;var signupInv=null;function validateDialog(a){if(a.email&&a.email.value==""){var b=validationHeader+" Email "+validationFooter;showMessage(b,null,a.email);return false}if(a.first_name){forbidden_symbol.symbol=validateErrorSymbolsStandard(a.first_name.value);if(forbidden_symbol.symbol!="ok"){forbidden_symbol.field="First Name";showMessage(forbidden_symbol.toString(),null,a.first_name);return false}}if(a.first_name&&a.first_name.value==""){var b=validationHeader+" First Name "+validationFooter;showMessage(b,null,a.first_name);return false}if(a.first_name&&a.first_name.value.length>15){big_length_message.el_name="First Name";big_length_message.count="15";b=big_length_message.toString();showMessage(b,null,a.first_name);return false}if(a.last_name&&a.last_name.value.length>15){big_length_message.el_name="Last Name";big_length_message.count="15";b=big_length_message.toString();showMessage(b,null,a.last_name);return false}if(a.last_name&&a.last_name.value==""){var b=validationHeader+" Last Name "+validationFooter;showMessage(b,null,a.last_name);return false}if(a.last_name){forbidden_symbol.symbol=validateErrorSymbolsStandard(a.last_name.value);if(forbidden_symbol.symbol!="ok"){forbidden_symbol.field="Last Name";showMessage(forbidden_symbol.toString(),null,a.last_name);return false}}if(a.pass&&a.pass.value.length>10){big_length_message.el_name="Password";big_length_message.count="10";b=big_length_message.toString();showMessage(b,null,a.pass);return false}if(a.pass&&a.pass.value==""){var b=validationHeader+" Password "+validationFooter;showMessage(b,null,a.pass);return false}if(a.re_pass&&a.re_pass.value==""){var b=validationHeader+" Retype Password "+validationFooter;showMessage(b,null,a.re_pass);return false}if(a.pass&&a.re_pass&&a.pass.value!=a.re_pass.value){var b=passDiff;showMessage(b,null,a.pass);a.pass.value="";a.re_pass.value="";return false}if(a.gender_male&&a.gender_female&&!a.gender_male.checked&&!a.gender_female.checked){var b=validationHeader+" Gender "+validationFooter;showMessage(b,null,a.gender_male);return false}if(a.agreement&&!a.agreement.checked){showMessage(agree,null,a.agreement);return false}return true}function validateDialog1(a){if(a.zip){var c=validateZip(a.zip.value);processZipError(c,a.zip);if(c!=0){return false}}if(a.address&&a.address.value.length>100){big_length_message.el_name="Address";big_length_message.count="100";b=big_length_message.toString();showMessage(b,null,a.address);return false}if(a.address&&a.address.value==""){var b=validationHeader+" Street Address "+validationFooter;showMessage(b,null,a.address);return false}return true}function sendSignupCutCommand(){if(this.owner.name){if(this.owner.name=="invitationSignup"){signupInv=true}}if(validateDialog(this.owner)){showProgress(((NavigatorProperties.product=="Opera")?"":'
')+progress);var b=new StRpcStub();b.setUrl(SIGN_UP);b.params.set("email",encodeURIComponent(this.owner.email.value));userEmail=this.owner.email.value;userName=this.owner.first_name.value;b.params.set("fsrc","signup2");b.params.set("firstName",encodeURIComponent(this.owner.first_name.value));b.params.set("lastName",encodeURIComponent(this.owner.last_name.value));var a=getCookie("esrcCookie");if(a){b.params.set("esrc",a);deleteCookie("esrcCookie")}else{b.params.set("esrc",encodeURIComponent(document.location))}b.params.set("password",encodeURIComponent(this.owner.pass.value));b.params.set("isrc",encodeURIComponent(document.location));b.fetchAsyncText(onSignUpShort,this)}}function onSignUpShort(d){var c=evalJSON(d);progressDialog.close();switch(c.errorCode){case 1:showMessage(error_message1,null,signUpShortDialog.email);break;case 3:showMessage(error_message2,null,signUpShortDialog.email);break;case 4:var e=c.member;Application.afterSignUpMemberId=e.id*1;Application.afterSignUpMemberFullId=e.id+"c"+e.randomId;signUpShortDialog.close();if(Signuper.message({msg:"S_OK",from:"onSignUpShort@crazymenu_uri_logic.stu"})){return}if(!signupInv){reEnterShortAddressDialog.execute()}else{signupForm.sgn_state1.style.display="none";signupForm.sgn_state2.style.display="block";var a=$("loginForm");var b=$("signupLaterForm");var h=$("dottedLine");var g=$("dottedLine1");a.style.display="none";if(b){b.style.display="none"}h.style.display="none";g.style.display="none"}break;case 5:error_message3.userEmail=userEmail;showMessage(error_message3,null,signUpDialog.email);break;default:showMessage(internalError+"
"+c.message)}}function validateDialog2(a){if(a.country&&!a.country.value){required.field="Country";showMessage(required.toString(),null,a.country);return false}if(a.city&&a.city.value.length>50){big_length_message.el_name="City";big_length_message.count="50";b=big_length_message.toString();showMessage(b,null,a.city);return false}if(a.city&&a.city.value==""){var b=validationHeader+" City "+validationFooter;showMessage(b,null,a.city);return false}if(a.city){forbidden_symbol.symbol=validateErrorSymbolsStandard(a.city.value);if(forbidden_symbol.symbol!="ok"){forbidden_symbol.field="City";showMessage(forbidden_symbol.toString(),null,a.city);return false}}return true}function sendReenterAddress(){var a=null;if(!signupInv){signupForm=reEnterAddressDialog}if(!this.owner.countryCheck.checked){a=validateDialog1(this.owner)}else{a=validateDialog2(this.owner)}if(a){showProgress(((NavigatorProperties.product=="Opera")?"":'
')+progress);var b=new StRpcStub();b.setUrl(ADD_MEMBER_ADDRESS);if(!signupForm.countryCheck.checked){b.params.set("zip",encodeURIComponent(this.owner.zip.value));b.params.set("streetAddress",encodeURIComponent(this.owner.address.value));GlobalZip=this.owner.zip.value;GlobalAddress=this.owner.address.value}else{b.params.set("country",encodeURIComponent(this.owner.country.value));b.params.set("city",encodeURIComponent(this.owner.city.value))}b.fetchAsyncText(onReEnterAddress,this)}}function onReEnterAddress(a){progressDialog.close();var b=evalJSON(a);if(b.result=="ok"){reEnterAddressDialog.close();clearReEnterAddressDialog();if(Signuper.message({msg:"S_FO",from:"onReEnterAddress@crazymenu_uri_logic.stu"})){return}if(!signupInv){verificationDialog.resendVerify.style.display="none";verificationDialog.emailText.innerHTML=userEmail;verificationDialog.execute()}else{signupForm.verification(userEmail)}congratuation.userName=userName;congratuation.userEmail=userEmail;showMessage(congratuation,DIALOG_TIMEOUT,verificationDialog.verificationCode);return}switch(b.errorCode){case 1:showMessage(address_error1,null,reEnterAddressDialog.address);break;case 3:showMessage(addAddressForbidden);break;default:showMessage(internalError)}}function validateDialog3(a){if(a.gender_male&&a.gender_female&&!a.gender_male.checked&&!a.gender_female.checked){var c=validationHeader+" Gender "+validationFooter;showMessage(c,null,a.gender_male);return false}if(a.address&&a.address.value.length>100){big_length_message.el_name="Address";big_length_message.count="100";c=big_length_message.toString();showMessage(c,null,a.address);return false}if(a.zip){var b=validateZip(a.zip.value);processZipError(b,a.zip);if(b!=0){return false}}if(a.address&&a.address.value==""){var c=validationHeader+" Street Address "+validationFooter;showMessage(c,null,a.address);return false}return true}function sendReenterAddressShort(){f=validateDialog3(this.owner);if(f){showProgress(((NavigatorProperties.product=="Opera")?"":'
')+progress);var a=new StRpcStub();a.setUrl(ADD_MEMBER_ADDRESS);var b=0;if(this.owner.gender_male.checked){b=0}if(this.owner.gender_female.checked){b=1}a.params.set("gender",b);a.params.set("zip",encodeURIComponent(this.owner.zip.value));a.params.set("streetAddress",encodeURIComponent(this.owner.address.value));GlobalZip=this.owner.zip.value;GlobalAddress=this.owner.address.value;a.fetchAsyncText(onReenterAddressShort,this)}}function onReenterAddressShort(a){progressDialog.close();var b=evalJSON(a);if(b.result=="ok"){clearReEnterShortAddressDialog();reEnterShortAddressDialog.close();congratuation.userName=userName;congratuation.userEmail=userEmail;if(Signuper.message({msg:"S_FO",from:"onReenterAddressShort@crazymenu_uri_logic.stu"})){return}if(!signupInv){verificationDialog.resendVerify.style.display="none";verificationDialog.emailText.innerHTML=userEmail;verificationDialog.execute();showMessage(congratuation,DIALOG_TIMEOUT,verificationDialog.verificationCode)}else{signupForm.verification(userEmail)}return}switch(b.errorCode){case 1:if(!signupInv){reEnterShortAddressDialog.close();clearReEnterAddressDialog();reEnterAddressDialog.execute()}else{signupForm.onNotValidZipUSA()}showMessage(address_error1,null,(signupInv)?null:reEnterAddressDialog.address);break;case 3:showMessage(addAddressForbidden);break;default:showMessage(internalError)}}function clearReEnterAddressDialog(){reEnterAddressDialog.hide();reEnterAddressDialog.countryCheck.checked=false;reEnterAddressDialog.zip.value=GlobalZip;reEnterAddressDialog.address.value=GlobalAddress;reEnterAddressDialog.zip.disabled=false;reEnterAddressDialog.address.disabled=false;reEnterAddressDialog.country.value="";reEnterAddressDialog.country.disabled=true;reEnterAddressDialog.city.value="";reEnterAddressDialog.city.disabled=true}function clearReEnterShortAddressDialog(){reEnterShortAddressDialog.hide();reEnterShortAddressDialog.zip.value="";reEnterShortAddressDialog.address.value="";reEnterShortAddressDialog.gender_male.checked=false;reEnterShortAddressDialog.gender_female.checked=false}function closeAll(){signUpDialog.hide();signUpDialog.clear();signUpShortDialog.hide();signUpShortDialog.clear();clearReEnterAddressDialog();clearReEnterShortAddressDialog();getPasswordDialog.hide();getPasswordDialog.clear();loginDialog.hide();loginDialog.clear();messageDialog.hide();progressDialog.hide();verificationDialog.hide();verificationDialog.clear()}function login(){Signuper.doSignUp({switchDialog:false,closeEnabled:true,login:true,inviteFriendDialog:true,needToReloadPage:Application.needToReloadPage})}function sendLoginCommand(){if(validateDialog(this.owner)){showProgress(((NavigatorProperties.product=="Opera")?"":'
')+progress);var a=new StRpcStub();a.setUrl(LOGIN);a.params.set("email",encodeURIComponent(this.owner.email.value));userEmail=this.owner.email.value;a.params.set("password",encodeURIComponent(this.owner.pass.value));a.params.set("remember",this.owner.rememberMe.checked);writeObjectToLog(a,"Send login: ");a.fetchAsyncText(onLogin,this)}}var COOKIE_TEMPLATE=new StStringTemplate("{$member_id}##{$random_member_id}##{$coord_lon1}:{$coord_lat1}##0:0##{$first_name}##{$last_name}##{$city}");function onLogin(a){verificationDialog.close();progressDialog.close();writeObjectToLog(a,"onLogin: ");var b=evalJSON(a);if(b.result=="ok"){var c=b.member;loginDialog.close();setNav1();loginSuccess.userName=c.firstName;if(Signuper.loginSuccessDialog){showMessage(loginSuccess,DIALOG_TIMEOUT)}Signuper.message({msg:"L_OK",from:"onLogin@crazymenu_uri_logic.stu"});return}switch(b.errorCode){case 1:showMessage(login_incorrect,null,loginDialog.email);break;case 3:verificationDialog.resendVerify.style.display="";verificationDialog.emailText.innerHTML=userEmail;loginDialog.close(false);verificationDialog.execute();showMessage(login_incorrect3,null,verificationDialog.verificationCode);break;default:showMessage(internalError+"
"+b.message)}}function sendGetPasswordCommand(){if(validateDialog(this.owner)){showProgress(((NavigatorProperties.product=="Opera")?"":'
')+progress);var a=new StRpcStub();a.setUrl(REMIND_PASSWORD);a.params.set("email",encodeURIComponent(this.owner.email.value));userEmail=this.owner.email.value;a.fetchAsyncText(onGetPassword,this)}}function onGetPassword(a){progressDialog.close();var b=evalJSON(a);if(b.result=="ok"){getPasswordDialog.close();showMessage(request_for_password_confirm);return}var c="";switch(b.errorCode){case 1:c=request_for_password_error;break;default:c=internalError+"
"+b.message}showMessage(c,null,getPasswordDialog.email)}function showMessage(b,c,a){messageDialog.message.innerHTML=b;messageDialog.execute(c);messageDialog.afterFocused=a}function showProgress(a){if((progressDialog.isVisible())&&(progressDialog.message.innerHTML==a)){return}if(!a){a="Processing..."}progressDialog.close();progressDialog.message.innerHTML=a;progressDialog.execute()}function signup(a){Signuper.doSignUp({switchDialog:false,closeEnabled:!a})}function reenter(){closeAll();reEnterAddressDialog.execute()}function getpass(){closeAll();getPasswordDialog.execute()}function sendVerificationRequest(){showProgress(((NavigatorProperties.product=="Opera")?"":'
')+progress);var a=new StRpcStub();a.setUrl(RESEND_VERIFICATION);a.params.set("email",userEmail);a.fetchAsyncText(onVerifyRequest,this)}function onVerifyRequest(b){progressDialog.close();var a=evalJSON(b);if(a.result=="ok"){showMessage(send_verification_message)}else{showMessage(internalError)}}function sendVerificationCommand(){if(getCookie("toShowFiendDial")){Application.toShowFD=true}if(!signupInv){signupForm=verificationDialog}if(!signupForm.verificationCode.value==""){showProgress(((NavigatorProperties.product=="Opera")?"":'
')+progress);var a=new StRpcStub();a.setUrl(VERIFY_MEMBER);a.params.set("vps",signupForm.verificationCode.value.replace(/ /g,""));a.fetchAsyncText(onVerify,this)}else{var b=validationHeader+" Verification code "+validationFooter;showMessage(b)}}function startVerificationDialog(a){verificationDialog.emailText.innerHTML=a;verificationDialog.execute()}function startVerificationImDialog(a){Application.imType=a;verificationDialog.emailText.innerHTML="your "+a+" Screenname";verificationDialog.mode="im";verificationDialog.execute()}function sendVerificationImCommand(){if(verificationDialog.verificationCode.value==null||verificationDialog.verificationCode.value.length<1){showMessage("Please, fill verification code.");return}var a=new StRpcStub();a.setUrl(VERIFY_IM);a.params.set("imType",Application.imType);a.params.set("verificationCode",verificationDialog.verificationCode.value);a.fetchAsyncText(onSendVerImCommand,this)}onSendVerImCommand=function(a){var b=evalJSON(a);if(b.result=="ok"){showMessage(verificationIMok);reloadPage(window.location.href)}else{if(b.errorCode==1){verificationDialog.mode="email";Signuper.doSignUp({closeEnabled:true,login:true,forceSignout:true})}else{if(b.errorCode==3){showMessage(verificationIMbad)}else{showMessage(internalError)}}}};function resendVerificationImCode(){var a=new StRpcStub();a.setUrl(RESEND_IM_VERIFICATION);a.params.set("imType",Application.imType);a.fetchAsyncText(onResendVerImCommand,this)}onResendVerImCommand=function(a){var b=evalJSON(a);if(b.result=="ok"){showMessage(verificationIMlookForCode)}else{if(b.errorCode==1){Signuper.doSignUp({closeEnabled:true,login:true,forceSignout:true})}else{showMessage(internalError)}}};function onVerify(a){progressDialog.close();var b=evalJSON(a);writeLog("onverify: "+b.errorCode);if(b.result=="ok"){messageDialog.close();verificationDialog.close();setNav1();if(Application.toShowFD){if(needShowFDCookie()){showFDCookie();return}}if(signupInv&&signupForm){signupForm.onSuccessSignup()}if(Signuper.message({msg:"V_OK",from:"onVerify@crazymenu_uri_logic.stu"})){writeLog("Signuper.message({msg:'V_OK',from:'onVerify@crazymenu_uri_logic.stu'}) -- true")}else{if(invitationLogin){loginForm.onSuccessLogin()}if(signupForm){signupForm.close()}}return}var c="";if(b.errorCode==2){c=b.message}else{c=verification_incorrect}showMessage(c,null,(signupInv)?null:verificationDialog.verificationCode);if(!signupInv){verificationDialog.close();loginDialog.close(true);verificationDialog.resendVerify.style.display="";verificationDialog.execute()}}function signOut(){showProgress(((NavigatorProperties.product=="Opera")?"":'
')+progress);var a=new StRpcStub();a.setUrl(SIGN_OUT);a.fetchAsyncText(onSignOut)}function onSignOut(a){progressDialog.close();var b=evalJSON(a);if(b&&b.result=="ok"){setNav2();if(Application.needToReloadPage){reloadPage(document.location.href)}}}var SIGNUPER_SENDERS=["S","L","V"];function SignupMediator(a){this.forceSignout=false;this.switchDialog=false;this.prefill=null;this.closeEnabled=true;this.callbacks={};this.callbackObject=null;this.ifCookieReturnFunction=null;this.login=false;this.needToReloadPage=false;this.showWarningOnClose=false;this.loginSuccessDialog=true;this.inviteFriendDialog=false;if(a!=null){for(val in a){this[val]=a[val]}}this.message=SignupMediator_DispatchMessage;this.doSignUp=SignupMediator_DoSignUp;this.initForm=SignupMediator_InitForm}var Signuper=new SignupMediator();function SignupMediator_DispatchMessage(a){writeLog("SignupMediator: Dispatcher got message "+a.msg+" from "+a.from);var c=a.msg;var b=false;var e=false;for(val in this.callbacks){if(c==val){var d=null;if(a.fromContext){d=this.callbacks[val].call(a.fromContext,this.callbackObject)}else{if(this.callbacksContext){d=this.callbacks[val].call(this.callbacksContext,this.callbackObject)}else{d=this.callbacks[val](this.callbackObject)}}if(d){b=true}e=true}}if(c=="L"||c=="S"){this.initForm()}if(needShowFDCookie()&&this.inviteFriendDialog&&(c=="L_OK")){showFDCookie();return}if(this.needToReloadPage&&(c=="L_OK"||c=="V_OK")){reloadPage(document.location.href.replace("login=true","login=false"))}if(c=="S_OK"){setTempFDCookie()}if(e==false){writeLog("SignupMediator: WARNING - unable to dispatch message "+c)}return b}function testF(a){writeLog("Test handler "+a);Signuper.initForm()}function SignupMediator_DoSignUp(a){if(a.forceSignout){writeLog("doSignUp: forced Sign out !!!");deleteCookie("cookie","/");setNav2()}if(getCookie("cookie")!=null){if(a.ifCookieReturnFunction!=null){a.ifCookieReturnFunction(a.callbackObject)}return}this.forceSignout=false;this.switchDialog=false;this.prefill=null;this.closeEnabled=true;this.callbacks={};this.callbacksContext=null;this.callbackObject=null;this.ifCookieReturnFunction=null;this.login=false;this.needToReloadPage=false;this.showWarningOnClose=false;this.loginSuccessDialog=true;this.inviteFriendDialog=false;if(a!=null){for(val in a){this[val]=a[val]}}if(this.showWarningOnClose&&this.callbacks){for(var b=0;b100)?100:SIGNUP_SHOW_PERCENT;SIGNUP_SHOW_PERCENT=(SIGNUP_SHOW_PERCENT<0)?0:SIGNUP_SHOW_PERCENT;if(b<(SIGNUP_SHOW_PERCENT/100)){signUpDialog.execute()}else{signUpShortDialog.execute()}}}function SignupMediator_InitForm(){if(this.switchDialog){signUpDialog.switchFooter(true);signUpShortDialog.switchFooter(true);loginDialog.changeDialog.style.display="inline"}else{signUpDialog.switchFooter(false);signUpShortDialog.switchFooter(false);loginDialog.changeDialog.style.display="none"}signUpDialog.setTopButtonsVisible(this.closeEnabled);loginDialog.setTopButtonsVisible(this.closeEnabled);getPasswordDialog.setTopButtonsVisible(this.closeEnabled);signUpShortDialog.setTopButtonsVisible(this.closeEnabled);reEnterAddressDialog.setTopButtonsVisible(this.closeEnabled);reEnterShortAddressDialog.setTopButtonsVisible(this.closeEnabled);verificationDialog.setTopButtonsVisible(this.closeEnabled);for(val in this.prefill){writeLog("* InitForm@SM: prefill - "+val+" = "+this.prefill[val]);setTextForNode(signUpDialog[val],this.prefill[val]);setTextForNode(signUpShortDialog[val],this.prefill[val]);setTextForNode(loginDialog[val],this.prefill[val])}}function directSignup(){Signuper.doSignUp({switchDialog:false,closeEnabled:true,inviteFriendDialog:true})}function setTempFDCookie(){var a=new StStringTemplate("{$member_id}");a.member_id=Application.afterSignUpMemberId;setCookie("toShowFiendDial="+a,"/")}function needShowFDCookie(){var d=0;var b=getCookie("cookie");if(b!=null){var c=b.split("#");d=encodeURIComponent(c[0])}if(getCookie("toShowFiendDial")&&(getCookie("toShowFiendDial")==d)&&Signuper.inviteFriendDialog){return true}else{return false}}function showFDCookie(){Application.reloadAfterIFD=true;deleteCookie("toShowFiendDial");startInviteFriendsNewDialog()};