B.UCounter = new $class(B.Page, { name: "UCounter", value: null, speed: null, url_sync: null, spf: 3000, step_to_sync: 10, els: {}, timer: null, step_num: 0, digits_value: null, init: function() { this.digits_value = this.value.toString().split("").reverse(); for (var i=0; i < this.digits_value.length; i++) { this.els[i] = $("mp_cnt_pos_"+i); if (!this.els[i]) return; } this.timer = new $t(this.step, this); this.run(); }, run: function() { this.ups = this.spf/1000*this.speed; this.delta = this.ups * 0.3; this.ups = this.ups * 0.7; this.timer.set(this.spf); }, step: function() { this.step_num++; this.value += this.ups + this.delta * Math.sin(this.step_num / this.step_to_sync * Math.PI * 2); var value = Math.floor(this.value); this.refreshDigits(value); this.step_num == this.step_to_sync ? this.sync() : this.timer.set(this.spf); }, refreshDigits: function(newvalue) { newvalue = newvalue.toString().split("").reverse(); var need_change = {}; for (var i=0; i <= newvalue.length; i++) if (newvalue[i] != this.digits_value[i]) need_change[i] = {from: this.digits_value[i], to: newvalue[i]}; this.digits_value = newvalue; this.timer_animate = new $t(this.animate, this); this.animate(need_change, 0); }, animate: function(data, state, isdata) { state = state == 2 ? 0 : state+1; for (var r in data) { isdata = 1; if (state == 0) data[r].from = data[r].from == 9 ? 0: +data[r].from +1; this.els[r].className = "mp_cnt_d mp_cnt_d_" + data[r].from +(state ? ("_" + state): ""); if (data[r].from == data[r].to) delete(data[r]); } if (isdata) this.timer_animate.set(40, data, state); }, sync: function() { new $r(this.url_sync, { ready: this.sync_ready },this); }, sync_ready: function(res) { this.step_num = 0; this.value = res.value; this.speed = res.speed; this.run(); } }); B.UploadFbc={ fb_ready:function(url) { setTimeout(function(){ dOvl.open_ex({type:'upload-import-fbc', url:url+'&ws=1'}); }, 100); }, fb_import_ready:function() { var form=$el.up($('fb_import_iframe'), 'form'); if(B.Import) B.Import._import_forms[1].submit() ; else if(B.UploadImport) B.UploadImport._import_forms[1].submit() ; } }; $u.autofocus=function(w){ var el=$el.down(w,'.autofocus'); try{ el && el.focus(); }catch(er){} }; $e.onload($u.autofocus); B.Captcha=new $class(B.Page, { init:function() { $e.on('.reset_check,* .reset_check', this.reload_capcha, this); }, reload_capcha:function(el) { var img=$('check_code_img'), inp=$('checkcode'), src; if(!img) return true; src=img.src, img.src=JSRoot+'i/blank.png', img.src=src.split('?')[0]+'?reload=1&rand='+Math.random(); inp.value=''; inp.focus(); } }); $u.Suggest=$class({ w:null, el:null, id:null, n:0, constructor:function(w,url) { if(!w || !url) return; this.w=w; this.el=$el.down(w,'.ds_input'); this.id=$el.down(w,'.ds_id'); this.res=$el.down(w,'.ds_res'); this.ovl=$el.down(w,'.ds_ovl'); this.geo=$el.down(w,'.ds_geo_simple'); this._cache={ '':{ q:'', locations:this.res.innerHTML, n:this.n=($el.select(this.res,'li')).length } }; this._v=this.el.value; this.t=new $r(url,{ auto:false, method:'get', ready:this.ready, error:this.error },this); this.timer=new $t(this.suggest,this,250); $e.add(this.el,'keydown',this.keydown,this); $e.add(this.el,'focus',this.focus,this); $e.add(this.res,'mouseover',this.hover,this); $e.add(this.res,'click',this.click,this); this.ovl && $e.add(this.ovl,'click',this.ovl_open,this); this.geo && $e.add(this.geo,'click',this.geo_click,this); }, destroy:function() { this.timer.clear(); this.t.abort(); $e.del(this.el,'keydown',this.keydown,this); $e.del(this.el,'focus',this.focus,this); $e.del(this.res,'mouseover',this.hover,this); $e.del(this.res,'click',this.click,this); $e.del(this.ovl,'click',this.ovl_open,this); this.geo && $e.del(this.geo,'click',this.geo_click,this); this.w=this.el=this.id=this.res=this.ovl=this.geo=this.t=null; }, focus:function(el) { if(!el || $e.e.type!='focus') this.el.focus(); if(!this._active){ this._active=true; this.el.select(); this.draw(); } return true; }, suggest:function() { var v=this.el.value; v=v.replace(/(^[\s,]+|[\s,]+$)/g,''); if(this._v==v) return; this.id.value=''; if(v.length<2){ this._v=''; this.ready(this._cache['']); return; } this._v=v; var res=this._cache[v]; if(res) this.ready(res); else this.t.request({q:v}); }, ready:function(res) { this._cache[res.q]=res; this.res.innerHTML=res.locations; this.n=res.n; this.draw(); }, error:function(er) { this.res.innerHTML=''; this.n=0; this.draw(); }, select:function(el) { var i=el||$el.down(this.res,'.selected'); if(!i) return; this.set(i.id.replace('dsi_',''), i.textContent || i.innerText); return true; }, keydown:function() { var e=$e.e, code=e.charCode||e.keyCode||e.which||0; switch(code){ case 40: this.highlight(+1); break; case 38: this.highlight(-1); break; case 13: if(!this.select()) return; this._active=false; this.draw(); this.el.blur(); break; default: this.timer.set(); return true; } }, highlight:function(d) { var els=$el.select(this.res,'li'), n=els.length, idx=-1; if(!n) return; for(var i=0; i<n; i++){ if(els[i].className=='selected'){ els[i].className=''; idx=i; break; } } i=(idx+d)%n; if(i<0) i=n-1; els[i].className='selected'; this.select(els[i]); }, hover:function(el) { if(!this.n||!el) return; while(el && el.nodeName!='LI'){ if(el==this.res) return; el=el.parentNode; } if(el){ var o=$el.down(this.res,'.selected'); if(o==el) return; $el.del(o,'selected'); el.className='selected'; } }, click:function(el) { if(!this.n||!el) return true; while(el && el.nodeName!='LI'){ if(el==this.res) return true; el=el.parentNode; } if(el){ if(!this.select(el)) return; this._active=false; this.draw(); } }, draw:function() { this.w.className='dSuggest '+(this._active && 'ds_focus ' || '')+(!this.n && this._v && 'ds_nothing ' || ''); }, geo_click:function(el) { this.set(el.rel,el.rev); }, ovl_open:function(el) { dOvl.open_ex({ type:'loc-ovl', url:el.rev, set_location:this.set_close.bind(this) }); }, set:function(id,text) { this.id.value=id; this.el.value=this._v=text; $el.add($el.down(this.w,'.input_error'),'hidden'); }, set_close:function(id,text) { this.set(id,text); this._active=false; this.draw(); } }); B.MsgClose=new $class(B.Page, { shown:false, init:function() { $e.on('.msg-close', this.msg_close, this); setTimeout(this.show.bind(this), 500); }, show:function() { if(this.shown) return; this.shown=true; var el=$el.down(document.body,'.valert'); if(!el) return; new $fx.effect({ wait:false, duration:500, items:[ new $fx.style({ el:el, prop:'height', from:0, start:function() { this.el.style.height='0'; this.el.style.display='block'; this.to=this.el.scrollHeight; }, end:function() { this.el.style.height=''; } }) ] }); }, msg_close:function(a) { var el=$el.up(a,'.cfm'); if(!el) return; new $fx.effect({ wait:false, duration:300, items:[ new $fx.style({ el:el, prop:'height', start:function() { this.from=this.el.offsetHeight; this.el.style.overflow='hidden'; }, end:function() { this.el.parentNode.removeChild(this.el); } }) ] }); if(a.rev) new $r(a.rev); } }); B.EmailMisprint=new $class(B.Page, { name:'EmailMisprint', el:null, url:'', error_tpl:'', er:null, email:'', corrected_email:'', _cache:{}, init:function() { this.el=$el.down(document.body,'.email_misprint'); if(!this.el || !this.url) return; this._cache[this.email]=true; this._cache[this.corrected_email]=true; if(this.corrected_email) this.er=$el.down(this.el.parentNode,'.input_error_blue'); $e.on('.email_misprint_revert',this.revert,this); $e.add(this.el,'blur',this.correct,this); }, correct:function(el) { var q=this.el.value; if(q in this._cache) return; if(!q || q==this.email || q==this.corrected_email) return; this._cache[q]=true; if(this._loading) this._transport.abort(); this._loading=true; this.email=q; this._transport=new $r(this.url,{ params:{q:q}, ready:this.loaded, error:this.load_error },this); }, revert:function(el) { if(this._loading){ this._transport.abort(); this._loading=false; } this.el.value=this.email; this.hide_error(); new $r(this.url,{ params:{change_back:this.email} }); }, loaded:function(res) { this._loading=false; if(!res.errno) this.hide_error(); else this.show_error(res.q,res.email); }, load_error:function() { this._loading=false; }, show_error:function(email,corrected_email) { if(this.el.value!=email) return; this._cache[corrected_email]=true; this.corrected_email=corrected_email; this.el.value=corrected_email; if(!this.er){ this.er=$u.tpl2el(this.error_tpl); this.el.parentNode.insertBefore(this.er,this.el); } this.er.style.display='block'; }, hide_error:function() { if(this.er) this.er.style.display='none'; } }); B.Signup=new $class(B.Page, { name:'Signup', passwd_min:5, focused:false, init:function() { this.form=$('signup_form'); if(!this.form) return; $e.on({ '.show_interest':this.show_interest },this); var el=$el.down(this.form,'.dSuggest'); if(el) this.suggest=new $u.Suggest(el,$vars['Suggest']['url']); $e.add(this.form,'submit',this.submit,this); $('email') && $e.add($('email'),'focus',this.focus,this); $('first_name') && $e.add($('first_name'),'focus',this.focus,this); el=$('js_pw_input'); if(el) new $u.PasswordStrength({ target:el, msg_target:$('js_pw_tooltip'), min_chars:this.passwd_min }); }, submit:function() { if(!this.focused) this.focus(); if(this.form.elements['location_id'].value){ $el.add(this.form,'el-loading'); return true; } var er=$el.down(this.form,'.dSuggest .input_error'); $el.del(er,'hidden'); this.suggest.focus(); }, focus:function() { $('email') && $e.del($('email'),'focus',this.focus,this); $('first_name') && $e.del($('first_name'),'focus',this.focus,this); $el.add(this.form, 'view_all_fields'); this.focused=true; }, setupNumPhotos:function(v) { if($('photo_quant_field')) $('photo_quant_field').value=v; }, show_interest:function() { $e.un('.show_interest', this.show_interest, this); var el=$el.down(null,'.w_interest'); if(!el) return true; new $fx.effect({ wait:false, duration:200, items:[ new $fx.style({ el:el, prop:'height', start:function() { this.from=0; var s=this.el.style; s.overflow='hidden'; s.height=this.from+'px'; this.to=this.el.scrollHeight; } }) ] }); return true; } }); $u.PasswordStrength=$class({ target :null, msg_target :null, min_chars :5, messages : ['js_pw_info','js_pw_toshort', 'js_pw_weak', 'js_pw_medium', 'js_pw_strong'], character_classes : [ /[a-z]/, /[A-Z]/, /\d/, /\s/, /[-!"#$%&'()*+,.\/:;<=>?@[\\\]_`{|}~]/, /[^a-zA-Z\d\s-!"#$%&'()*+,.\/:;<=>?@[\\\]_`{|}~]/ ], constructor:function(config) { $config(this, config); this.init(); }, init:function() { if(!this.target||!this.msg_target) return; if(this.target.value) this.test(); $e.add(this.target,'keyup',this.test,this); }, test:function(el) { var re=this.character_classes; var v=this.target.value; var idx=1; if(v.length<this.min_chars){ idx=v?1:0; }else{ for(var i=0, n=re.length; i<n; i++){ if(re[i].test(v)) idx++; } idx=(idx>4?4:idx); } this.msg_target.className=this.messages[idx]; } }); if (!B.Likes) B.Likes = new $class(B.Page, { name: 'Likes', init: function(){}, google: function(btn, cfg) { btn.onmouseover = null; cfg.btn = btn; this.google_cfg = cfg; if(window.gapi){ this.google_render(); return; } window.___gcfg={ lang: cfg.lang_code, parsetags:'explicit' }; $r.script(document.location.protocol+'\/\/apis.google.com/js/plusone.js', this.google_render, this ); }, google_render:function() { if(!window.gapi) return; var cfg = this.google_cfg; var pl = cfg.btn.nextSibling; pl.id+=Math.floor(Math.random()*1000000); gapi.plusone.render(pl.id, { href: cfg.liked_url, callback: this.google_log.bind(this, cfg), size:'medium', annotation:'bubble', expandto:'top', count:true }); new $t(function() { var ifr = pl.firstChild; ifr ? ifr.onload = this.google_clear.bind(this, cfg) : this.google_clear(cfg); }, this).set(5); }, google_log: function(response, cfg) { new $r(cfg.log_url,{ params:{href:response.href} }); }, google_clear: function(cfg) { var btn = cfg.btn; btn.parentNode.removeChild(btn); }, facebook: function(btn, cfg) { btn.onmouseover = null; cfg.btn = btn; this.facebook_cfg = cfg; var fblike_tpl='<iframe src="{url}" onload="B.Likes.facebook_render()" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>'; var fblike_url='http:\/\/www.facebook.com/plugins/like.php?href={liked_url}&amp;send=false&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;height=21&amp;locale={locale}'; var fbl = btn.nextSibling; fbl.innerHTML = $u.tpl(fblike_tpl, {url: $u.tpl(fblike_url, {liked_url: cfg.liked_url, locale: cfg.locale})}); }, facebook_render: function() { var btn = this.facebook_cfg.btn; btn.parentNode.removeChild(btn); }, tweeter: function(btn) { btn.onmouseover = null; $r.script('http:\/\/platform.twitter.com/widgets.js', function(){}, this ); }, vkontakte: function(btn, cfg) { btn.onmouseover = null; this.vkontakte_cfg = cfg; $r.script("http:\/\/userapi.com/js/api/openapi.js?32", this.vkontakte_render, this ); }, vkontakte_render: function() { var cfg = this.vkontakte_cfg; VK.init({ apiId: cfg.api_id, onlyWidgets: true }); VK.Widgets.Like('vk_like', { type: cfg.type, pageTitle: cfg.title, pageDescription: cfg.description, pageUrl: cfg.url, pageImage: cfg.image, pageId: cfg.page_id }, 1); }, nasaklassa: function(btn, cfg) { btn.onmouseover = null; $r.script(JSRoot+'js/facebook/nk.js', function () { nk_cfg = { url: cfg.url, type: cfg.type, color: cfg.color, title:cfg.title, image:cfg.image, description:cfg.description, wid:cfg.wid }; new nk_fajne(nk_cfg); }); }, hyves: function(btn, cfg) { btn.onmouseover = null; cfg.btn = btn; this.hyves_cfg = cfg; var tpl = "<iframe onload='B.Likes.hyves_clear()' src='http:\/\/www.hyves.nl/respect/button?url={url}' style='border: medium none; overflow:hidden; width:150px; height:21px; background: transparent;' allowTransparency='true' transparent='transparent' scrolling='no' frameborder='0'></iframe>"; var el=$('hyves_like'); el.innerHTML = $u.tpl(tpl,{ url:$u.tpl(cfg.url,{}) }); }, hyves_clear: function() { var btn = this.hyves_cfg.btn.nextSibling; btn.parentNode.removeChild(btn); } }); B.Slider=new $class(B.Page, { name: 'Slider', scrollDelay: 5000, timer: null, interactive: false, nextSlide: null, curSlide: null, slides: ['map','chat','game','phone'], url: '/index-ws.phtml', slidesNum: {}, isSlideContent: {}, loadingTpl: '<div class="mp_slide_waiting"></div>', init: function() { if (!this.curSlide || this.slides.length == 1) return; this.isSlideContent[this.curSlide] = true; $e.on('.mp_slide_btn', this.set_slide, this); for (var num=0; num<this.slides.length; num++) this.slidesNum[this.slides[num]] = num; this.timer = new $t(this.autoScroll, this); var slidecont = $("mp_slider"); $e.add(slidecont, "mouseout", this.allowAnimation, this); $e.add(slidecont, "mouseover", this.denyAnimation, this); this.allowAnimation(); }, allowAnimation: function() { this.timer.set(this.scrollDelay, 'preload'); }, denyAnimation: function() { this.timer.clear(); }, autoScroll: function(mode) { var slide = this.slides[(this.slidesNum[this.curSlide]+1) % this.slides.length]; if (mode=='preload') { if (!this.isSlideContent[slide]) this.load_content(slide); this.timer.set(1000, 'animate'); } else if (mode=='animate'){ this.set_button(slide); this.animation(slide, 1); } }, set_slide: function(el) { var slide = el.rel; if (this.curSlide == slide) return; this.set_button(slide); if (this.interactive) { this.nextSlide = slide; } else { this.animation(slide); } }, set_button: function(slide) { $el.del($el.down(document, ".mp_slider_button .active"), "active"); $el.add($("mp_slide_btn_"+slide), "active"); }, animation: function(slide, direction) { this.timer.clear(); this.interactive = true; if (!this.isSlideContent[slide]) this.load_content(slide); var oldPage = $("mp_slide_"+this.curSlide); var newPage = $("mp_slide_"+slide); oldPage.style.left = 0; $el.del(oldPage, "active"); if (!direction) direction = this.slidesNum[this.curSlide] > this.slidesNum[slide] ? -1 : 1; new $fx.effect({ wait:false, duration:500, items:[ new $fx.style({ el:oldPage, prop:'left', from: 0, to: -800*direction }), new $fx.style({ el:newPage, prop:'left', from: 800*direction, to: 0 }) ], onEnd: this.animation_end, scope:this }); this.curSlide = slide; }, animation_end: function () { this.interactive = false; if (this.nextSlide) { this.animation(this.nextSlide); this.nextSlide = null; } else { this.timer.set(this.scrollDelay, 'preload'); } }, load_content: function(slide) { var slide_container = $("mp_slidecont_"+slide); slide_container.innerHTML = this.loadingTpl; new $r(this.url, { params:{slide: slide}, ready: this.load_content_ready.bind(this, slide_container) },this); this.isSlideContent[slide] = true; }, load_content_ready: function(slide_container, response) { slide_container.innerHTML = response.content; } });
