Ext.namespace("APP");APP.Course={getcurrencyinfo:function(){this.cur1=Ext.get("cur1").getValue().split("_");this.cur2=Ext.get("cur2").getValue().split("_");return{cur1_id:this.cur1[0],cur2_id:this.cur2[0],cur1_alias:this.cur1[1],cur2_alias:this.cur2[1],cur1_name:this.cur1[2],cur2_name:this.cur2[2]}},getcourse:function(){if(Ext.get("cur1")&&Ext.get("cur2")){this.currency=APP.Course.getcurrencyinfo();if(this.currency.cur1_id!=this.currency.cur2_id){Ext.Ajax.request({url:"/exchange/getcourserelations/",success:APP.Course.setcourse,params:{cur1_id:this.currency.cur1_id,cur2_id:this.currency.cur2_id}})}else{Ext.get("course").dom.innerHTML="В выбранном направлении обмена нет";Ext.get("reserve").dom.innerHTML=""}}},setcourse:function(a){if(a.responseText){Ext.get("course").dom.innerHTML=""+a.responseText+"";this.currency=APP.Course.getcurrencyinfo();if(Ext.get(""+this.currency.cur2_alias+"")){Ext.get("reserve").dom.innerHTML=Ext.get(""+this.currency.cur2_alias+"").dom.value+" "+this.currency.cur2_name}else{Ext.get("reserve").dom.innerHTML="0.00 "+this.currency.cur2_name}}},navigation:function(){this.currency=APP.Course.getcurrencyinfo();window.location="/exchange/calculate/from/"+this.currency.cur1_id+"/to/"+this.currency.cur2_id}};APP.Calculate={init:function(){Ext.get("amount_cur1").focus();APP.Calculate.calcfrom()},checknumber:function(b,a){if(a!=null){if((a>45&&a<=57&&a!=47)||a==0||a==8||a==13){RetVal=true}else{RetVal=false}}else{if((b>45&&b<=57&&b!=47)||b==13||b==8){RetVal=true}else{RetVal=false}}return RetVal},calcfrom:function(){if(Ext.get("amount_cur1").getValue()&&Ext.get("amount_cur1").getValue()>=0.01){var k=Ext.get("course_cur1").getValue();var i=Ext.get("course_cur2").getValue();var p=Ext.get("course_real").getValue();var d=Ext.get("commission_limit").getValue();var b=Ext.get("cur1_primecost_percent").getValue();var o=Ext.get("cur2_primecost_percent").getValue();var h=Ext.get("cur1_primecost_limit_to").getValue();var a=Ext.get("cur2_primecost_limit_to").getValue();if(k==1){var n=Ext.get("amount_cur1").getValue();var l=n*i;var r=n*p}else{var n=Ext.get("amount_cur1").getValue();var l=n/k;var r=n/p}var e=r-l;var f=r*b/100;var j=r*o/100;if(f>h&&h!=0){r=r-h;l=r;f=h}if(j>a&&a!=0){r=r-a;l=r;j=a}if(e>d&&d!=0){l=r-d;e=d}this.discount=Ext.get("discount").getValue();if(this.discount!=0){l=l+(l*this.discount/100)}var c=n*Ext.get("cur1_primecost_percent_from").getValue()/100;var q=Math.round(Ext.get("cur1_primecost_limit_from").getValue());if(c>q){var m=1*n+1*q}else{if(c<0.01){c=0.01}var m=1*n+1*c}Ext.get("amount_cur1_com").dom.value=m.toFixed(2);Ext.get("commission").dom.value=e;var g=f*1+j*1;Ext.get("prime_cost").dom.value=g;Ext.get("amount_cur2").dom.value=l.toFixed(4)}else{Ext.get("amount_cur2").dom.value=0;Ext.get("amount_cur1_com").dom.value=0}},calcto:function(){if(Ext.get("amount_cur2").getValue()&&Ext.get("amount_cur2").getValue()>=0.01){var k=Ext.get("course_cur1").getValue();var i=Ext.get("course_cur2").getValue();var p=Ext.get("course_real").getValue();var d=Ext.get("commission_limit").getValue();var b=Ext.get("cur1_primecost_percent").getValue();var o=Ext.get("cur2_primecost_percent").getValue();var h=Ext.get("cur1_primecost_limit_from").getValue();var a=Ext.get("cur2_primecost_limit_from").getValue();if(k==1){var l=Ext.get("amount_cur2").getValue();var n=l/i;var r=l/p;d=d/p}else{var l=Ext.get("amount_cur2").getValue();var n=l*k;var r=l*p;d=d*p}var e=n-r;var f=r*b/100;var j=r*o/100;if(f>h&&h!=0){r=r+h*1;n=r;f=h}if(j>a&&a!=0){r=r+a*1;n=r;j=a}if(e>d&&d!=0){n=r+d;e=d}if(k==1){e=e*p;var g=f*p+j*p}else{e=e/p;var g=f/p+j/p}Ext.get("commission").dom.value=e;Ext.get("prime_cost").dom.value=g;this.discount=Ext.get("discount").getValue();if(this.discount!=0){n=n-(n*this.discount/100)}Ext.get("amount_cur1").dom.value=n.toFixed(4);var c=n*Ext.get("cur1_primecost_percent_from").getValue()/100;var q=Math.round(Ext.get("cur1_primecost_limit_from").getValue());if(c>q){var m=1*n+1*q}else{if(c<0.01){c=0.01}var m=1*n+1*c}Ext.get("amount_cur1_com").dom.value=m.toFixed(2)}else{Ext.get("amount_cur1").dom.value=0;Ext.get("amount_cur1_com").dom.value=0}},cur1blur:function(){if(Ext.get("amount_cur1").getValue()&&Ext.get("amount_cur1").getValue()<0.01){Ext.get("amount_cur1").dom.value=0;Ext.get("amount_cur2").dom.value=0}},cur2blur:function(){if(Ext.get("amount_cur2").getValue()&&Ext.get("amount_cur2").getValue()<0.01){Ext.get("amount_cur1").dom.value=0;Ext.get("amount_cur2").dom.value=0}},check_account_number:function(){this.type=Ext.get("account_number").getValue().substring(0,1);this.wm=Ext.get("name_cur2").getValue().substring(0,2);this.wm_type=Ext.get("name_cur2").getValue().substring(2,3);if(this.wm=="WM"&&this.type.toUpperCase()!=this.wm_type){Ext.get("progress").dom.style.display="none";Ext.get("eError").dom.innerHTML="Ошибка! Неверно указан номер кошелека"}else{Ext.Ajax.request({url:"/exchange/check_account_number/",success:APP.Calculate.handle_response,params:{account_number:Ext.get("account_number").getValue(),currency_id_to:Ext.get("cur2").getValue()}})}},handle_response:function(a){if(a.responseText){var b=Ext.util.JSON.decode(a.responseText);Ext.get("progress").dom.style.display="none";Ext.get("eError").dom.innerHTML="Ошибка! "+b.message+"";APP.Personal.getcaptcha()}else{APP.Calculate.check_email()}},check_email:function(){Ext.Ajax.request({url:"/exchange/check_email/",success:APP.Calculate.handle_email,params:{email:Ext.get("email").getValue()}})},handle_email:function(a){if(a.responseText){var b=Ext.util.JSON.decode(a.responseText);Ext.get("progress").dom.style.display="none";Ext.get("eError").dom.innerHTML="Ошибка! "+b.message+"";APP.Personal.getcaptcha()}else{APP.Calculate.check_captha()}},check_captha:function(){Ext.Ajax.request({url:"/exchange/check_captha/",success:APP.Calculate.handle_captha,params:{keystring:Ext.get("keystring").getValue()}})},handle_captha:function(a){if(a.responseText){var b=Ext.util.JSON.decode(a.responseText);Ext.get("progress").dom.style.display="none";Ext.get("eError").dom.innerHTML="Ошибка! "+b.message+"";APP.Personal.getcaptcha()}else{document.forms.calculate.submit()}},check_amount:function(){this.error=false;Ext.get("progress").dom.style.display="";if(Ext.get("amount_cur1").getValue()&&Ext.get("amount_cur1").getValue()<0.01){this.error=true;Ext.get("progress").dom.style.display="none";Ext.get("eError").dom.innerHTML="Ошибка! Минимальная сумма обмена 0.01 "+Ext.get("name_cur1").getValue();Ext.get("amount_cur1").dom.value=0.01;APP.Calculate.calcfrom();APP.Personal.getcaptcha()}if(Ext.get("amount_cur2").getValue()&&Ext.get("amount_cur2").getValue()<0.01&&!this.error){this.error=true;Ext.get("progress").dom.style.display="none";Ext.get("eError").dom.innerHTML="Ошибка! Минимальная сумма обмена 0.01 "+Ext.get("name_cur2").getValue();Ext.get("amount_cur2").dom.value=0.01;APP.Calculate.calcto();APP.Personal.getcaptcha()}if(Ext.get("amount_cur1").getValue()<parseFloat(Ext.get("min_amount").getValue())&&Ext.get("min_amount").getValue()!=0&&!this.error){this.error=true;Ext.get("progress").dom.style.display="none";Ext.get("eError").dom.innerHTML="Ошибка! Минимальная сумма обмена "+Ext.get("min_amount").getValue()+" "+Ext.get("name_cur1").getValue();Ext.get("amount_cur1").dom.value=Ext.get("min_amount").getValue();APP.Calculate.calcfrom();APP.Personal.getcaptcha()}if(Ext.get("amount_cur1").getValue()>parseFloat(Ext.get("max_amount").getValue())&&Ext.get("max_amount").getValue()!=0&&!this.error){this.error=true;Ext.get("progress").dom.style.display="none";Ext.get("eError").dom.innerHTML="Ошибка! Максимальная сумма обмена "+Ext.get("max_amount").getValue()+" "+Ext.get("name_cur1").getValue();Ext.get("amount_cur1").dom.value=Ext.get("max_amount").getValue();APP.Calculate.calcfrom();APP.Personal.getcaptcha()}if(!this.error){Ext.Ajax.request({url:"/exchange/check_amount/",success:APP.Calculate.handle_amount,params:{primecost:Ext.get("cur1_primecost_percent_from").getValue(),cur2:Ext.get("cur2").getValue(),amount_cur2:Ext.get("amount_cur2").getValue()}})}},handle_amount:function(a){if(a.responseText){var b=Ext.util.JSON.decode(a.responseText);Ext.get("progress").dom.style.display="none";Ext.get("eError").dom.innerHTML="Ошибка! "+b.message+""}else{APP.Calculate.check_account_number()}}};APP.Preview={edit:function(){this.cur1=Ext.get("cur1").getValue();this.cur2=Ext.get("cur2").getValue();this.req=Ext.get("req").getValue();if(this.cur1&&this.cur2&&this.req){window.location="/exchange/calculate/from/"+this.cur1+"/to/"+this.cur2+"/req/"+this.req}else{window.location="/"}}};APP.Personal={auth:function(){Ext.Ajax.request({url:"/user/auth/login",success:APP.Personal.login,params:{email:Ext.get("email").getValue(),password:Ext.get("password").getValue()}})},login:function(a){if(a.responseText){var b=Ext.util.JSON.decode(a.responseText);Ext.get("eError").dom.innerHTML="Ошибка! "+b.message+"";Ext.get("enter").setStyle({background:"url(/images/enter_error-bg.png)",backgroundRepeat:"no-repeat"})}else{window.location="/user/personal"}},catchIEenter:function(){if(event.keyCode==13){APP.Personal.auth()}},catchFFenter:function(a){if(a.which==13){APP.Personal.auth()}},init:function(){if(Ext.isIE){document.onkeypress=APP.Personal.catchIEenter}else{document.onkeypress=APP.Personal.catchFFenter}var a=""+window.location+"";var b=a.split("auth/");if(b[1]){Ext.get("email").focus()}else{Ext.get("editemail").focus()}},getcaptcha:function(){Ext.get("captcha").dom.src="/user/captcha?math="+Math.random()*100000000},getpassword:function(){this.re_str=/[^\s+]/;this.email1=/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;this.email2=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;this.email=Ext.get("editemail").getValue();this.keystring=Ext.get("keystring").getValue();if(this.email1.test(this.email)||!this.email2.test(this.email)){Ext.get("eError").dom.innerHTML="Ошибка! E-mail введен некорректено";Ext.get("enter").setStyle({background:"url(/images/enter_error-bg.png)",backgroundRepeat:"no-repeat"});APP.Personal.getcaptcha()}else{if(!this.re_str.test(this.keystring)){Ext.get("eError").dom.innerHTML="Ошибка! Введите код защиты";Ext.get("enter").setStyle({background:"url(/images/enter_error-bg.png)",backgroundRepeat:"no-repeat"});APP.Personal.getcaptcha()}else{Ext.Ajax.request({url:"/user/auth/getpassword",success:APP.Personal.getresponse,params:{email:this.email,keystring:this.keystring}})}}},getresponse:function(a){if(a.responseText){var b=Ext.util.JSON.decode(a.responseText);Ext.get("eError").dom.innerHTML="Ошибка! "+b.message;Ext.get("enter").setStyle({background:"url(/images/enter_error-bg.png)",backgroundRepeat:"no-repeat"});APP.Personal.getcaptcha()}else{Ext.get("eError").dom.innerHTML="Новый пароль выслан на указанный e-mail";Ext.get("enter").setStyle({background:"url(/images/enter_error-bg.png)",backgroundRepeat:"no-repeat"});Ext.get("email").dom.value="";Ext.get("password").dom.value="";Ext.get("editemail").dom.value="";Ext.get("keystring").dom.value=""}},checkform:function(){var d=/[^\s+]/;var b=/^([\wA-Za-z0-9][-_]?)+$/;var f=/^([\wА-Яа-яA-Za-z0-9][-_ ]?)+$/;var e=/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;var c=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;var a=/^([\w0-9][-]?)+$/;if(e.test(Ext.get("email").getValue())||!c.test(Ext.get("email").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! E-mail введен некорректено"}else{if(!d.test(Ext.get("password").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Введите пароль"}else{if(Ext.get("password").getValue().length<6){Ext.get("eError").dom.innerHTML="Ошибка! Пароль должен быть не меньше 6 символов"}else{if(Ext.get("password").getValue().length>15){Ext.get("eError").dom.innerHTML="Ошибка! Пароль не должен превышать 15 символов"}else{if(!d.test(Ext.get("confirm_password").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Повторите пароль"}else{if(Ext.get("password").getValue()!=Ext.get("confirm_password").getValue()){Ext.get("eError").dom.innerHTML="Ошибка! Пароли не совпадают"}else{if(!f.test(Ext.get("last_name").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Фамилия введена некорректно"}else{if(!f.test(Ext.get("first_name").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Имя введено некорректно"}else{if(!a.test(Ext.get("phone_number").getValue())&&Ext.get("phone_number").getValue()){Ext.get("eError").dom.innerHTML="Ошибка! Номер телефона введен некорректено"}else{if(isNaN(Ext.get("icq").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Номер ICQ введен некорректено"}else{if(!d.test(Ext.get("keystring").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Введите код защиты";return false}else{Ext.get("eError").dom.innerHTML="";Ext.get("progress").dom.style.display="";APP.Personal.registration()}}}}}}}}}}}},checkeditform:function(){var d=/[^\s+]/;var b=/^([\wA-Za-z0-9][-_]?)+$/;var f=/^([\wА-Яа-яA-Za-z0-9][-_ ]?)+$/;var e=/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;var c=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;var a=/^([\w0-9][-]?)+$/;if(Ext.get("password").getValue()!=Ext.get("confirm_password").getValue()){Ext.get("eError").dom.innerHTML="Ошибка! Пароли не совпадают"}else{if(!f.test(Ext.get("last_name").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Фамилия введена некорректно"}else{if(!f.test(Ext.get("first_name").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Имя введено некорректно"}else{if(!a.test(Ext.get("phone_number").getValue())&&Ext.get("phone_number").getValue()){Ext.get("eError").dom.innerHTML="Ошибка! Номер телефона введен некорректено"}else{if(isNaN(Ext.get("icq").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Номер ICQ введен некорректено"}else{if(!d.test(Ext.get("keystring").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Введите код защиты";return false}else{Ext.get("eError").dom.innerHTML="";APP.Personal.edit()}}}}}}},registration:function(){Ext.Ajax.request({url:"/user/registration/doreg",success:APP.Personal.regResponse,params:{password:Ext.get("password").getValue(),confirm_password:Ext.get("confirm_password").getValue(),last_name:Ext.get("last_name").getValue(),first_name:Ext.get("first_name").getValue(),email:Ext.get("email").getValue(),phone_number:Ext.get("phone_number").getValue(),icq:Ext.get("icq").getValue(),keystring:Ext.get("keystring").getValue()}})},regResponse:function(a){Ext.get("progress").dom.style.display="none";if(a.responseText){var b=Ext.util.JSON.decode(a.responseText);Ext.get("eError").dom.innerHTML="Ошибка! "+b.message;APP.Personal.getcaptcha()}else{alert("Вы успешно зарегистрированы\nНа указанный e-mail выслана ссылка для активации Вашего аккаунта");window.location="/"}},edit:function(){Ext.Ajax.request({url:"/user/profile/edit",success:APP.Personal.editResponse,params:{password:Ext.get("password").getValue(),confirm_password:Ext.get("confirm_password").getValue(),last_name:Ext.get("last_name").getValue(),first_name:Ext.get("first_name").getValue(),phone_number:Ext.get("phone_number").getValue(),icq:Ext.get("icq").getValue(),keystring:Ext.get("keystring").getValue()}})},editResponse:function(a){if(a.responseText){var b=Ext.util.JSON.decode(a.responseText);Ext.get("eError").dom.innerHTML="Ошибка! "+b.message;APP.Personal.getcaptcha()}else{Ext.get("eError").dom.innerHTML="Данные успешно сохранены.<BR/>Для вступления изменений необходимо перезайти в систему";APP.Personal.getcaptcha()}}};APP.Auth={auth:function(){Ext.Ajax.request({url:"/user/auth/login",success:APP.Auth.login,params:{email:Ext.get("email").getValue(),password:Ext.get("password").getValue()}})},login:function(a){if(a.responseText){var b=Ext.util.JSON.decode(a.responseText);alert(b.message)}else{window.location="/"}},logout:function(){Ext.Ajax.request({url:"/user/auth/logout",success:APP.Auth.refresh,params:{main:1}})},refresh:function(){window.location="/"},authcheck:function(b,a){if(a!=null){if(a==13){APP.Auth.auth()}}else{if(b==13){APP.Auth.auth()}}}};APP.FAQ={send_q:function(){var b=/[^\s+]/;var d=/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;var a=/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;var c=/^([\wА-Яа-яA-Za-z0-9][-_ ]?)+$/;if(!c.test(Ext.get("username").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Имя введено некорректно"}else{if(d.test(Ext.get("email").getValue())||!a.test(Ext.get("email").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! E-mail введен некорректено"}else{if(Ext.get("category").getValue()==0){Ext.get("eError").dom.innerHTML="Ошибка! Выберите категорию"}else{if(!b.test(Ext.get("question").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Введите вопрос"}else{if(!b.test(Ext.get("keystring").getValue())){Ext.get("eError").dom.innerHTML="Ошибка! Введите код защиты"}else{Ext.Ajax.request({url:"/faq/record",success:APP.FAQ.getresponse,params:{email:Ext.get("email").getValue(),username:Ext.get("username").getValue(),categories_id:Ext.get("category").getValue(),title:Ext.get("question").getValue(),keystring:Ext.get("keystring").getValue()}})}}}}}},getresponse:function(a){if(a.responseText){var b=Ext.util.JSON.decode(a.responseText);Ext.get("eError").dom.innerHTML="Ошибка! "+b.message;APP.Personal.getcaptcha()}else{Ext.get("username").dom.value="";Ext.get("category").dom.value=0;Ext.get("email").dom.value="";Ext.get("question").dom.value="";Ext.get("keystring").dom.value="";Ext.get("eError").dom.innerHTML="Ваш вопрос будет рассмотрен в ближайшее время"}}};

