var backupSt=null;var mail=null;var memberId;var password=null;var restaurant=null;var promotion=null;var zip=null;var st={};var url;var CMD_SIGNUP="signup";var CMD_PROMOPREPROCESS="promoPreProcess";var mode=null;var loginForm=null;function showMessage(b,c,a){messageDialog.message.innerHTML=b;messageDialog.execute(c);messageDialog.afterFocused=a}function goNext(){switch(mode){case"ownerRestaurant":window.location.assign(RESTAURANT_CONTEXT_PATH+"owner");break;case"loginRestaurant":case"signUpRestaurant":window.location.assign(RESTAURANT_CONTEXT_PATH+"promo?step=mbT1&restaurant_name="+restaurant+"&member_id="+memberId+"&agree_policy=1&promotion="+promotion+"&email="+mail+"&zip="+zip);break;case"invitationLogin":loginForm.onSuccessLogin();break;default:alert("Mode is undefined.")}}function onInvitationLogin(){mode="invitationLogin";loginForm=this.owner;var b=this.owner.email;var a=this.owner.password;if(!validateEP(b,a)){return}st={email:mail,password:password};url=LOGIN;sendRequest()}function toOwnerPage(){mode="ownerRestaurant";var b=document.getElementById("email_1");var a=document.getElementById("password");if(!validateEP(b,a)){return}st={email:mail,password:password};url=LOGIN;sendRequest()}function validateEP(b,a){mail=b.value;password=a.value;if(mail.length<3){required.field="E-Mail";showMessage(required.toString(),null,b);return false}else{if(mail.length>99){big_length_message.el_name="E-mail";big_length_message.count="100";showMessage(big_length_message.count.toString(),null,b);return false}else{if(mail.indexOf("@")<1){wrong.field="E-Mail";showMessage(wrong.toString(),null,b);return false}}}if(password.length<1){required.field="Password";showMessage(required.toString(),null,a);return false}else{if(password.length>9){big_length_message.el_name="Password";big_length_message.count="10";showMessage(big_length_message.count.toString(),null,a);return false}}return true}function sendRequest(){requestHandler={onAcceptData:requestServer(st,url)}}function showRedirectMessage(){showMessage(UAreRegMember)}function onIfYouAreNot(){deleteCookie("cookie","/");window.location=RESTAURANT_CONTEXT_PATH+"owner"}function toSelectRestaurant(){restaurant=document.getElementById("restaurant_name").value.toString();if(restaurant.length<1){showMessage("Restaurant Name required",null,document.getElementById("restaurant_name"));return}if(restaurant.length>80){big_length_message.el_name="Restaurant Name";big_length_message.count="80";showMessage(big_length_message.toString(),null,document.getElementById("restaurant_name"));return}zip=document.getElementById("zipId").value;if(zip.length>0){var a=validateZip(zip);if(a!=0){processZipError(a,document.getElementById("zipId"));return}}mail=document.getElementById("2email").value;if(mail.length<3){showMessage("E-Mail required",null,document.getElementById("2email"));return}else{if(mail.length>100){big_length_message.el_name="E-Mail";big_length_message.count="100";showMessage(big_length_message.toString(),null,document.getElementById("2email"));return}else{if(mail.indexOf("@")<1){wrong.field="E-Mail";showMessage(wrong.toString(),null,document.getElementById("2email"));return}}}promotion=document.getElementById("promotion").value;if(promotion.length>20){big_length_message.el_name="Promotion";big_length_message.count="20";showMessage(big_length_message.toString(),null,document.getElementById("promotion"));return}if(!document.getElementById("agree_policy").checked){showMessage(agree,null,document.getElementById("agree_policy"));return}st={cmd:CMD_PROMOPREPROCESS,member_id:"undefined",email:mail,restaurant_name:restaurant,promotion:promotion,agree_policy:1,zip:zip};url=secureRestaurantControllerUrl;mode="signUpRestaurant";requestHandler={onAcceptData:requestServer(st,url)}}function requestServer(d,b){if(d==null){d=backupSt}if(d.handler==null){d.handler=respDefault}var c=new StRpcStub();c.setUrl(b);for(val in d){if(val!="handler"&&val!="cases"){var a=encodeURIComponent(d[val]);c.params.set(val,a)}}switch(mode){case"invitationLogin":c.fetchAsyncText(processQuiteLogin,this);break;case"ownerRestaurant":c.fetchAsyncText(processQuiteLogin,this);break;case"signUpRestaurant":c.fetchAsyncXml(makeCookie,this);break;case"loginRestaurant":c.fetchAsyncText(processQuiteLogin,this);break;default:alert("Mode is not defined.")}}function respDefault(a){responseXML=a}function processQuiteLogin(a){var b=evalJSON(a);if(b&&b.result=="ok"){memberId=b.member.id;goNext();return}switch(b.errorCode){case 1:showMessage(login_incorrect,null,loginDialog.email);break;case 3:verificationDialog.resendVerify.style.display="";verificationDialog.emailText.innerHTML=userEmail;verificationDialog.execute();showMessage(login_incorrect3,null,verificationDialog.verificationCode);break;default:showMessage(internalError+"
"+b.message)}}function makeCookie(b){var c=xPath.selectSingleNode(b,"/rsm_response/result/result_code/@value").value*1;if(c==0){a()}else{if(c==1){showMessage(emailIsNotPresent,null,document.getElementById("email_1"));return}else{if(c==2){if(url==controllerUrl){showMessage(noSuchMail);return}else{showRedirectMessage()}}else{if(c==3){showMessage(login_incorrect3)}else{if(c==7){showMessage(newMember);st={email:mail,password:""};mode="loginRestaurant";requestHandler={onAcceptData:requestServer(st,LOGIN)}}else{if(c==8){showMessage(error_message2,null,document.getElementById("2email"))}}}}}}function a(){var d=new StStringTemplate("{$member_id}##{$random_member_id}##{$coord_lon1}:{$coord_lat1}##{$coord_lon2}:{$coord_lat2}##{$first_name}##{$last_name}##{$city}");memberId=xPath.selectSingleNode(b,"/rsm_response/member_info/@member_id").value*1;d.member_id=xPath.selectSingleNode(b,"/rsm_response/member_info/@member_id").value;d.random_member_id=xPath.selectSingleNode(b,"/rsm_response/member_info/@random_member_id").value;d.coord_lon1=xPath.selectSingleNode(b,"/rsm_response/member_info/@coord_lon1").value;d.coord_lat1=xPath.selectSingleNode(b,"/rsm_response/member_info/@coord_lat1").value;d.coord_lon2=xPath.selectSingleNode(b,"/rsm_response/member_info/@coord_lon2").value;d.coord_lat2=xPath.selectSingleNode(b,"/rsm_response/member_info/@coord_lat2").value;d.first_name=xPath.selectSingleNode(b,"/rsm_response/member_info/@first_name").value;d.last_name=xPath.selectSingleNode(b,"/rsm_response/member_info/@last_name").value;d.city=xPath.selectSingleNode(b,"/rsm_response/member_info/@city").value;setCookie("cookie="+d,"/");goNext()}};