var Captcha={ label:null, init:function() { $e.on({ '.reset_check':this.reload_capcha, '* .reset_check':this.reload_capcha },this); this.label=new dLabel({ el:$q.down(document.body,'.checkcode_label') }); }, destroy:function() { $e.un({ '.reset_check':this.reload_capcha, '* .reset_check':this.reload_capcha },this); this.label.destroy(); this.label=null; }, reload_capcha:function(el) { var img=$('check_code_img'); if(!img) return true; var url=img.src.split('?')[0]; img.src=url+'?reload=1&rand='+Math.random(); } }; Captcha=new $class(dPage,Captcha); var Clipboard={ copyMsg:null, defaultCopyMsg:'Copied to clipboard', timestamp:0, msgElement:null, hash:null, init:function() { var a = $q.select(document, ".copy_text"); if (a.length == 0) return; for (var i=0, n = a.length; i < n; i++) { var el = a[i]; $e.add (el, 'focus', this.focus, this); } if (!Flash.init(7)) return; var flashSrc = JSRoot + "flash/__clipboard.swf"; var hash = {}; for (var i=0, n = a.length; i < n; i++) { var el = a[i]; var text2Copy = encodeURIComponent(el.value); var flashId = "clipboardMC" + i; hash[flashId] = el; var flashVars = "clipboard=" + text2Copy + "&id=" + flashId; var flashStr = Flash.draw(flashSrc, "100%", "100%", "transparent", flashVars, true); var flashCont = $u.el('div',{ id:flashId, className:'copy_icon', innerHTML: flashStr }); var inputCont = el.parentNode.parentNode; inputCont.parentNode.insertBefore(flashCont, inputCont); } this.hash = hash; }, focus: function(el) { setTimeout(function(){ el.select(); }, 1); }, getTooltipText: function() { if (this.copyMsg) return this.copyMsg; var clipboard_text = $('clipboard_text'); this.copyMsg=clipboard_text ? clipboard_text.title : this.defaultCopyMsg; return this.copyMsg; }, showMsg: function(flashContId) { var flashCont = $(flashContId); if (!flashCont) return; if(!this.msgElement){ this.msgElement=$u.el('div',{ id:'clipboard_title', innerHTML:'<div class="bln_info pngbox">\ <div class="tpt">\ <div class="bpt">\ <div class="cont">' + this.getTooltipText() + '</div>\ <div class="bpc"></div>\ </div>\ </div>\ <div class="tcn"></div>\ <div class="bcn"></div>\ </div>' }); document.body.appendChild(this.msgElement); } if(this.msgElement.style.display=='block') clearTimeout(this.timestamp); var tl=$el.cumulativeOffset(flashCont); $config(this.msgElement.style,{ display:'block', top:tl.top+12+'px', left:tl.left+16+'px' }); var inpuitEl = this.hash[flashContId]; if (inpuitEl) inpuitEl.select(); this.timestamp=setTimeout('$("clipboard_title").style.display="none"', 1800); } }; Clipboard=new $class(dPage,Clipboard); var EmailMisprint={ name:'EmailMisprint', el:null, url:'', error_tpl:'', er:null, email:'', corrected_email:'', _cache:{}, init:function() { this.el=$q.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=$q.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'; } }; EmailMisprint=new $class(dPage,EmailMisprint); var ChangeEmail = { init:function() { $e.on({ '#change_address':this.change_address },this); var ce=$('change_email'); var ca=$('change_address_div'); ce && !$el.hasClassName(ce,'not_hidden') && $el.addClassName(ce,'hidden') || (ca && $el.addClassName(ca,'hidden')); }, change_address:function(el) { $el.toggleClassName($('change_email'),'hidden'); $el.toggleClassName($('change_address'), 'showmore'); var t=$('change_address_div'); t && $el.toggleClassName(t, 'hidden'); t=$('open_email_service'); t && $el.toggleClassName(t,'hidden'); } }; ChangeEmail=new $class(dPage,ChangeEmail); var dSuggest=$class({ _1:true, target:null, timeout: 250, url:'', url_params:null, msgs:{ note:'Start typing and select your city from the list', loading:'Loading...', nothing_found:'Nothing found' }, validate:false, initial_data:null, del:false, autocomplete_onblur:true, _focused:false, _timer:null, _form:null, _list:null, _value:'', _sel_length:0, _sel_item:0, _items:null, _show_loading:true, _load_progress:false, _store: {}, constructor:function(config) { this.url_params={}; $config(this,config); this.init(); }, init:function() { var target=this.target=$(this.target); if(!this.target) return; target.setAttribute("autocomplete", "off"); this._value=target.value; this._list=$u.el('ul',{className:'hidden'}); target.parentNode.appendChild(this._list); if(this.del){ this._del=$u.el('div'); target.parentNode.appendChild(this._del); } this._form=this._form||$q.up(target,'form'); if(!this._hid){ var hid=this._form.elements[target.name+'_id']; if(!hid){ hid=$u.el('input',{ name:(target.name+'_id'), type:'hidden' }); target.parentNode.insertBefore(hid,target); } this._hid=hid; } this._suggest_fn=this.suggest.bind(this); $e.add(target,'keyup',this.suggest_delayed,this); $e.add(target,'keydown',this.highlight_kbd,this); $e.add(this._list,'mouseover',this.highlight_mouse,this); $e.add(target,'blur',this.blur,this); $e.add(target,'focus',this.focus,this); if(this.del) $e.add(this._del,'click',this.clear,this); if(!this.autocomplete_onblur) $e.add(this._list,'click',this.onClick,this); $e.add(this._form,'submit',this.onSubmit,this); if(!this.initial_data) this._1=false; if(this.initial_data) this.parse_results(this.initial_data); }, destroy:function() { var target=this.target; clearTimeout(this._timer); $e.del(target,'keyup',this.suggest_delayed,this); $e.del(target,'keydown',this.highlight_kbd,this); $e.del(this._list,'mouseover',this.highlight_mouse,this); $e.del(target,'blur',this.blur,this); $e.del(target,'focus',this.focus,this); if(this.del) $e.del(this._del,'click',this.clear,this); if(!this.autocomplete_onblur) $e.del(this._list,'click',this.onClick,this); $e.del(this._form,'submit',this.onSubmit,this); this._form=this._hid=this.target=null; }, focus:function() { if(this._focused) return true; this.target.select(); this._focused=true; this.layout(); return true; }, blur:function() { this._focused=false; if(this.autocomplete_onblur) this.select(); this.onError(!this._hid.value); this.layout(); return true; }, clear:function() { this._value=this.target.value=""; this._hid.value=''; if(this._transport){ this._transport.abort(); this._transport=null; } this.target.focus(); }, highlight:function(i,renew) { if(!this._items) return; if(!renew) $el.removeClassName(this._list.childNodes[this._sel_item],'selected'); if(i<0) i=this._sel_length+i; this._sel_item=i%this._sel_length; var list=this._list; var item=list.childNodes[this._sel_item]; $el.addClassName(item,'selected'); if(this._list.className) return; if(item.offsetTop<list.scrollTop){ list.scrollTop=item.offsetTop; }else if(item.offsetTop+item.offsetHeight>list.scrollTop+list.offsetHeight){ list.scrollTop=item.offsetTop-list.offsetHeight+item.offsetHeight; } }, highlight_mouse:function(el) { if(!this._items || !el) return; if(el.nodeName!='LI'){ el=el.parentNode; if(el.nodeName!='LI'){ return; } } $el.removeClassName(this._list.childNodes[this._sel_item],'selected'); this._sel_item=0; var i=el; while(i.previousSibling){ i=i.previousSibling; if(i.nodeName=='LI') this._sel_item++; } $el.addClassName(this._list.childNodes[this._sel_item],'selected'); }, highlight_kbd:function() { var e=$e.e; var code=e.charCode||e.keyCode||e.which||0; switch(code){ case 40: this.highlight(this._sel_item+1); return; case 38: this.highlight(this._sel_item-1); return; case 13: this.select(); return; } return true; }, onClick:function(el) { var onSelectDisabled = el && $el.hasClassName (el, 'change'); this.select(onSelectDisabled); return true; }, select:function(onSelectDisabled) { if(this._items){ var _=/^dsi_([\d_]+)$/.exec(this._list.childNodes[this._sel_item].id); if(!_) return true; var id=_[1]; if(this._1 && id==0) return true; var v=this._items[id].split(', '); if((this._items[id].unique) && v.length==3) v.splice(1,1); v=v.join(', '); this._value=this.target.value=v; if(this.url) this._items=null; this._hid.value=id; } if(this._hid.value) { this.onError(false); if (!onSelectDisabled) this.onSelect(); } this.layout(); return true; }, suggest_delayed:function() { if(this._value==this.target.value) return; this._hid.value=''; clearTimeout(this._timer); this._timer=null; if(this.target.value.length<2){ if(this.url) this._items=null; this._value=''; }else{ if(this.url) this._timer=setTimeout(this._suggest_fn,this.timeout); } this.layout(); }, suggest:function() { this._timer=null; if(this._value==this.target.value){ this.layout(); return; } this._value=this.target.value; if(this._transport){ this._transport.abort(); this._transport=null; } if(this.target.value){ this._load_progress=true; var q=this.target.value.replace(/(^[\s,]+|[\s,]+$)/g,''); if(q in this._store){ setTimeout(this.parse_results.bind(this,this._store[q]),0); }else{ this.url_params.q=q; this._transport=new $r(this.url,{ method:'get', params:this.url_params, ready:this.suggest_ready, error:this.response_error },this); } } this.layout(); }, suggest_ready:function(res) { this.parse_results(res); this._transport=null; }, response_error:function() { this._load_progress=false; this.layout(); }, parse_results:function(res,no_layout) { if(!res) return; this._store[res.q]=res; this._load_progress=false; var locations=res.locations; if('length' in locations){ this._items=null; this._sel_item=null; this._sel_length=0; }else{ var q=res.q; var html=[]; var j=false; if(this._2){ html=['<li class="info_li" id="dsi_0">'+this.msgs.note+'</li>']; j=!j; } var filter_data=res.filter && this.filters[res.filter]; if(filter_data) locations=filter_data(locations); this._items=locations; var re=new RegExp('('+q+')','i'); for(var i in locations){ html[html.length]='<li id="dsi_'+i+'"'+(j?'class="bg"':'')+'>'+(q?locations[i].replace(re,'<span>$1</span>'):locations[i])+'</li>'; j=!j; } this._sel_length=html.length; this._list.innerHTML=html.join(''); this.highlight(0,1); if(!this._focused && html.length==1){ this.select(); } } if(!no_layout) this.layout(); }, filters:{ rm_region:function(data) { var res={}; var idx={}; for(var i in data){ var v=data[i].split(', '); v[3]=v[2] ? (v[0]+v[2]) : data[i]; res[i]=v; idx[v[3]]=(idx[v[3]]||0)+1; } for(var i in res){ var v=res[i]; if(idx[v[3]]==1){ res[i]=v[2] ? (v[0]+', '+v[2]) : v[3]; res[i].unique=true; }else{ res[i]=v[2] ? (v[0]+', '+v[1]+', '+v[2]) : v[3]; } } return res; } }, external_set:function(id,text) { var v=text.split(', '); if(v.length==3){ v.splice(1,1); text=v.join(', '); } this._value=this.target.value=text; this._hid.value=id; if(this.url) this._items=null; this.onError(!this._hid.value); this.layout(); }, onSelect:function() { }, onError:function(error) { if(error) $el.addClassName(this.target,'error_location'); else $el.removeClassName(this.target,'error_location'); }, onSubmit:function() { if(window.opera && this._focused){ return; } if(!this.validate || this.onValidate()) return true; if(this.target.offsetHeight) this.target.focus(); }, onValidate:function() { if(this._hid.value){ this.onError(false); return true; }else{ this.onError(true); return false; } }, layout:function() { clearTimeout(this._del_timer); if(!this._focused){ this._del_timer=setTimeout((function(){ this._list.className='hidden'; if(this.del) this._del.className='hidden'; }).bind(this),200); if(this._load_progress){ $el.addClassName(this.target.parentNode,'dSuggest-loading'); }else{ $el.removeClassName(this.target.parentNode,'dSuggest-loading'); } if(this._hid.value) $el.addClassName(this.target,'selected'); return; } $el.removeClassName(this.target,'selected'); if(this._hid.value) this._list.className='hidden'; else this._list.className=''; var msg=''; if(this.target.value.length<2 || this._value.length<2){ if(this._1){ this._2=1; this.parse_results(this.initial_data,true); if (this.encLocMode) this._list.className=''; this._2=0; }else{ msg=('<li class="info_li">'+this.msgs.note+'</li>'); if (this.encLocMode) this._list.className=''; } if(this.del) this._del.className='hidden'; this._show_loading=true; }else if(this._load_progress && this._show_loading){ msg=('<li class="info_li">'+this.msgs.loading+'</li>'); this._show_loading=false; }else if(!this._hid.value && !this._items){ msg=('<li class="info_li">'+this.msgs.nothing_found+'</li>'); this._show_loading=true; } if(msg) this._list.innerHTML=msg; if(this._load_progress){ if(this.del) this._del.className='hidden'; $el.addClassName(this.target.parentNode,'dSuggest-loading'); }else{ if(this.target.value) if(this.del) this._del.className=''; $el.removeClassName(this.target.parentNode,'dSuggest-loading'); } } }); var LocationSuggest=$class(dSuggest,{ timeout:250, onError:function(error) { var el=$('suggest_location_error'); if(el){ if(error) $el.removeClassName(el,'hidden'); else $el.addClassName(el,'hidden'); } }, validate:true, _invalid_flag:false, onValidate:function() { if(this._hid.value){ this.onError(false); $u.startWaiting('create_profile'); return true; }else{ if(!this._items){ if(this._invalid_flag) this.validate=false; else this._invalid_flag=true; }else{ this._invalid_flag=false; } this.onError(true); $u.stopWaiting('create_profile'); if(!this.validate) return true; return false; } } }); var MsgClose={ init:function() { $e.on('.msg-close', this.msg_close, this); }, msg_close:function(el) { el=$q.up(el,'.container_confirmation'); 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); } }) ] }); } }; MsgClose=new $class(dPage,MsgClose); var Signup=new $class(dPage, { name:'Signup', location_ws_url:'/location-ws.phtml', init:function() { $e.on({ '#more_location':this.openLocation, '#more_location2':this.openLocation, '#geo_suggest_sp':this.setLocation },this); var inp=$('signup_form'); if(inp){ inp=$q.down(inp,'input[tabindex=1]'); inp && inp.focus(); } var sloc=$('suggest_location'); if(sloc){ this.location_suggest=new LocationSuggest({ target:$q.down(sloc,'input'), url:this.location_ws_url, msgs:vars.location, initial_data:(vars.suggest_data||null) }); }else{ $u.form_submit($('signup_form')); } if($('for_upload_to_flash') && Flash.init(10)){ $('for_upload_to_flash').innerHTML=Flash.draw(JSRoot + "flash/UploadInvite.swf", "100%", "100%", "#ffffff", null, true); } if ($('icq')) { if(/*@cc_on!@*/false) $e.add($('icq'), 'click', this.toggleICQ, this); else $e.add($('icq'), 'change', this.toggleICQ, this); } }, toggleICQ:function() { if ($('icq_have').checked) { $el.addClassName($('icq'),'icq_there'); } else { $el.removeClassName($('icq'),'icq_there'); } return true; }, setLocation:function(el) { if($el.hasClassName(el.parentNode,'disabled')) return; var ar=$q.select($('geo_suggest'), 'input'); if(ar.length) this.location_suggest.external_set(ar[0].value, ar[1].value) }, openLocation: function(el) { dOvl.open_ex({ type:'loc-ovl', cfg:{ wizard_url: vars.location.wizard_url, callback: this.add_city, scope: this } }); }, add_city: function (vvalue, vtext) { vvalue=vvalue.split('_')[2] || -1; this.location_suggest.external_set(vvalue, vtext); }, setupNumPhotos: function (v) { if ($('photo_quant_field')) $('photo_quant_field').value = v; } }); var 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]; } }); $e.onload(function() { var js_pw_input=$('js_pw_input'); if(!js_pw_input) return; new PasswordStrength({ target:js_pw_input, msg_target:$('js_pw_tooltip'), min_chars:5 }); },PasswordStrength);