function sendFriendRequest(a){var b=new Ajax.Request("/contacts/friends/send-friend-request.ajax",{method:"get",parameters:{act:"friendInvite",subject:Event.element(a).readAttribute("rel")},overlayer:{id:"usersContainer"},onSuccess:function(c){if(c.responseText=="OK"){alert("Invitatia a fost trimisa.");getResults(null,true);Paginators.get().refresh()}}})}function changeForms(a){$("addFromMail").toggle();
$("addFew").toggle();$(Event.element(a).readAttribute("rel")).down("form").focusFirstElement()}document.observe("dom:loaded",function(){var a;var c;if($("contactsSelection")){if($("selectAllContacts")){Event.observe("selectAllContacts","click",function(d){selectAllContacts()});Event.observe("deselectAllContacts","click",function(d){deselectAllContacts()})}if($("invertAllContacts")){Event.observe("invertAllContacts","click",function(d){invertAllContacts()
})}}if($("addSchool")){Event.observe("addSchool","click",function(d){$("optionSchool").show()})}if(Object.isFunction(Element.delegate)){var b=function(d){d.findElement("div").next(".viewStare").toggle()};if(c=$("users")){c.delegate("mouseover",{".emoticons":b});c.delegate("mouseout",{".emoticons":b})}}});function selectAllContacts(){var a=$$("#users input");a.each(function(b){b.checked=1})}function deselectAllContacts(){var a=$$("#users input");
a.each(function(b){b.checked=0})}function invertAllContacts(){var a=$$("#users input");a.each(function(b){if(b.checked==1){b.checked=0}else{b.checked=1}})}document.observe("friendDialog:show",function(a){ajaxAddFriend(a.memo,"usersContainer",contactsListingSuccessHandler,contactsListingErrorHandler)});Search={type:null,form:null,filterSection:null,refreshParams:$H({}),CONTAINER:"searchResult",FILTERS_CONTAINER:"searchNavigation",FILTER_SEL_CLASS:"selected",init:function(){if($(this.FILTERS_CONTAINER)){this.form=$(this.FILTERS_CONTAINER).down("form");
this.autoSelectSection();$(this.FILTERS_CONTAINER).delegate("click",{".title.switchable":this.changeSection.bindAsEventListener(this),".myworkclass a":function(a){a.element().up().toggleClassName("subselected")}})}$(this.CONTAINER).select("select.refresh").each(function(a){a.observe("change",this.refreshResultsHandler.bindAsEventListener(this))}.bind(this));document.observe("search:update-filter",this.updateFilterHandler.bindAsEventListener(this));
document.delegate("click",{".do-add-friend":this.clickAddFriend.bindAsEventListener(this),".do-add-institution":this.clickAddCommunity.bindAsEventListener(this),".do-view-connections":this.clickViewMutualConnections.bindAsEventListener(this),"#addAd":this.addNewAd.bindAsEventListener(this),"#addAd *":this.addNewAd.bindAsEventListener(this)})},addNewAd:function(){if(!this.form){return}var a=this.form.query;
if(a.value){window.location.href="/search/ads/new-ad?search="+a.value}else{window.location.href="/search/ads/new-ad"}},autoSelectSection:function(){if(!this.form||!this.form.target.value){return}var b=this.form.target.value;var a=$("sectionsFilter").select("li").find(function(c){if(c.down("a").readAttribute("rel")==b){return true}return false});if(Object.isUndefined(a)){return}this.filterSection=a.addClassName(this.FILTER_SEL_CLASS);
this.filterSection.insert(this.form)},clickAddFriend:function(b){var c=b.element();var a=c.readAttribute("rel");ajaxAddFriend(a,null,function(){c.hide()})},clickAddCommunity:function(c){var f=Paginators.get().getParameters();var b=f.get("region")?f.get("region"):1;var d=f.get("city")?f.get("city"):324;var a=c.element();showAddCommunityDialog(0,b,d,function(){a.remove()},Prototype.emptyFunction)},clickViewMutualConnections:function(d){var c=d.element();
var b=null;if(c.hasClassName("friends")){b="friends"}else{b="communities"}var a=c.readAttribute("rel").split("|");var f=Object.toQueryString({type:b,userId:a[1],friendId:a[2],commTypes:"1,2"});new Dialog.Confirm.ajax("/contacts/index/get-connectivity.ajax?"+f,{width:"300px",height:"150px",title:a[0]})},changeSection:function(f){f.stop();var d=f.element();var b=this.filterSection;var c=d.readAttribute("rel");
if(d.up().hasClassName(this.FILTER_SEL_CLASS)){c=null;d.up().removeClassName(this.FILTER_SEL_CLASS);this.filterSection=d.up("ul").down("li.form-container")}else{this.filterSection=d.up().addClassName(this.FILTER_SEL_CLASS)}this.form.reset();this.filterSection.insert(this.form);this.form.target.value=c;var a=this.form.select(".myworkclass");var g=a.size();a.each(function(e){if(g==1){if(!e.hasClassName("subselected")){e.addClassName("subselected")
}}else{e.removeClassName("subselected")}});if(b&&b.hasClassName(this.FILTER_SEL_CLASS)){b.removeClassName(this.FILTER_SEL_CLASS)}this._updateFilter("region");this._updateFilter("city","region");this.refreshResultsHandler(f)},updateFilterHandler:function(g){var f=g.memo.evalJSON();var d=this.form.down("[name="+f.name+"]");if(!d){return}if(!Object.isArray(f.values)){var a=new Hash(f.values);$A(d.options).each(function(e){if(e.value){e.remove()
}});a.keys().each(function(e){d.insert(new Element("option",{value:e}).update(a.get(e)))});d.up(".filter-details").show();d.enable()}else{d.disable();d.up(".filter-details").hide()}var c=false;var b=d.up("div");b.select(".filter-details").each(function(e){if(e.visible()){c=true;throw $break}});if(!c){b.hide()}else{b.show()}this.refreshParams.get("update-filter").unset(f.name)},refreshResultsHandler:function(b){var f=Paginators.get();
var c=f.getParameters();var a=b.element();c.update(this.form.serialize(true));if(a.readAttribute("name")=="order"){c.set("order",a.value)}if(a.hasClassName("update-next")){var d=a.up().next(".filter-details").down(".update-with-prev")||{};if(d.name){c.unset(d.name)}this._updateFilter(d.name,a.name)}c.set("refresh-params",this.refreshParams.toJSON());c.set("page",1);c.set("cacheId",null);f.refresh(c)
},_updateFilter:function(a,b){if(Object.isUndefined(this.refreshParams.get("update-filter"))){this.refreshParams.set("update-filter",new Hash())}var c=this.refreshParams.get("update-filter");c.set(a,b||false);this.refreshParams.set("update-filter",c)}};document.observe("dom:loaded",function(){Search.init()});function showAddFriendDialog(b,c){if(!b){alert("Trebuie specificat utilizatorul pentru adaugarea ca prieten");
return}var a="/contacts/dialog-add?subject="+b;Dialog.Confirm.ajax(a,{modal:true,title:"Adauga ca prieten",zindex:2,width:500,height:450,id:"addFriendWindow",onClose:function(){if(!Object.isUndefined(SelectCollection)){SelectCollection.unregisterAllUnder("#addFriendWindow")}},onSuccess:function(){c()}},{onComplete:function(d){d.responseText.evalScripts()}})}function ajaxAddFriend(a,b,d,c){showAddFriendDialog(a,d)
}function ajaxRemoveFriend(a,b,d,c){if(!confirm("Esti sigur ca vrei sa stergi acest prieten ?")){return}ajaxContactsAction("/contacts/friends/remove",{subject:a},b,d,c)}function ajaxRecommendFriend(a,b,c,e,d){ajaxContactsAction("/contacts/friends/recommend-friend",{"for":a,subject:b},c,e,d)}function ajaxAcceptFriendRequest(a,b,e,c,d){ajaxContactsAction("/contacts/friends/accept-request",{subject:a},b,e,c,d)
}function ajaxRejectFriendRequest(a,b,d,c){ajaxContactsAction("/contacts/friends/refuse-request",{subject:a},b,d,c)}function ajaxCancelFriendRequest(a,b,d,c){ajaxContactsAction("/contacts/friends/cancel-request",{subject:a},b,d,c)}function ajaxRejectSuggestion(a,b,d,c){ajaxContactsAction("/contacts/friends/refuse-suggestion",{subject:a},b,d,c)}function friendRequestSuccessHandler(b,a){if(!b.responseJSON){a();
return}Dialog.Confirm.show(b.responseJSON.message,{width:350,height:100,modal:true,title:b.responseJSON.title,onSuccess:a})}function ajaxContactsAction(f,g,d,c,a,e){e=e||Prototype.emptyFunction;var b={method:"get",parameters:g,onSuccess:function(i){var h=i.responseJSON;if(!h||!h.success){(a||Prototype.emptyFunction)(i,e)}else{(c||Prototype.emptyFunction)(i,e)}}};if(d!=null){b.overlayer={id:d,autoReposition:true}
}new Ajax.Request(f+".ajax",b)}function showConnectivityDialog(e,d,c){var b={type:e,userId:d,friendId:c};var a=(e=="interests"?300:160);var f="Legaturi";switch(e){case"friends":f="Prieteni comuni";break;case"communities":f="Institutii comune";break;case"interests":f="Interese comune";break}Dialog.Confirm.ajax("/contacts/index/get-connectivity.ajax?"+Object.toQueryString(b),{modal:true,closable:true,title:f,width:350,height:a})
}function showAddCommunityDialog(b,d,f,e,c){var a="/community/dialog-add?type="+b+"&region="+d+"&city="+f;Dialog.Confirm.ajax(a,{modal:true,title:"Adauga comunitate",zindex:2,width:550,height:480,id:"addCommunityWindow",onClose:function(){(c||Prototype.emptyFunction).wrap(function(g){if(!Object.isUndefined(SelectCollection)){SelectCollection.unregisterAllUnder("#addCommunityWindow")}AddCommunityDialog.deattachObservers();
PhotoUploader.deattachObservers();g()})()},onSuccess:function(){PhotoUploader.deattachObservers();AddCommunityDialog.deattachObservers();e(AddCommunityDialog.lastAddedId)}},{onComplete:function(g){g.responseText.evalScripts()}})}var Paginators={paginators:new Hash(),group:new Hash(),add:function(b,a){this.paginators.set(b,a);if(Object.isUndefined(this.group.get(b))){this.group.set(b,[a])}else{this.group.get(b).push(a)
}return a},get:function(a){a=a||"default";return this.paginators.get(a)},getGroup:function(a){a=a||"default";return this.group.get(a)}};var Paginator=Class.create({sliderMinWidth:20,STYLE_SEO:"pagination-seo",STYLE_CLASSIC:"pagination-lite",STYLE_SLIDER:"pagination-slider",initialize:function(e,f,b){this.group=e||"default";Paginators.add(this.group,this);this.uniqueId=this.group+f;this.handler=b;this.handler.parameters=$H(this.handler.parameters);
this.currentPage=this.handler.config.currentPage;this.totalPages=this.handler.config.totalPages;this.page=null;this.refreshPagination=false;this.loading=false;if(this.totalPages>1){this.visible=true}else{this.hide()}var d=new RegExp("(pagination-(seo|lite|slider))","g");var c=$("paginationContainer_"+this.uniqueId).className;var a=d.exec(c);if(a){this.style=a[1]}else{this.style=this.STYLE_SLIDER}if(this.style!=this.STYLE_SEO){this.goTo=$("goTo_"+this.uniqueId);
if(this.style==this.STYLE_SLIDER){this.initSlider()}}},initSlider:function(){this.navigationBar=$("navigationBar_"+this.uniqueId);this.slider=$("slider_"+this.uniqueId);this.leftArrow=$("left_"+this.uniqueId);this.rightArrow=$("right_"+this.uniqueId);this.pageNumber=$("pageNumber_"+this.uniqueId);if(this.visible){this.calculateWidths(true)}this.mouseXPos=0;this.clickXPos=0;this.startPos=0},calculateWidths:function(){this.barWidth=this.navigationBar.getWidth();
this.sliderWidth=this.barWidth/this.totalPages;if(this.sliderWidth<this.sliderMinWidth){this.sliderWidth=this.sliderMinWidth;this.stepWidth=(this.barWidth-this.sliderWidth)/this.totalPages}else{this.stepWidth=this.sliderWidth}this.slider.style.width=this.sliderWidth+"px";this.moveSlider("init",this.currentPage)},addListeners:function(a){if(this.style==this.STYLE_SEO){return}if(!a){this.bGoToPage=this.goToPage.bindAsEventListener(this)
}if(this.style==this.STYLE_CLASSIC){Event.observe("form_goTo_"+this.uniqueId,"submit",this.bGoToPage)}else{if(!a){this.bClickOnBar=this.clickOnBar.bindAsEventListener(this);this.bMoveLeft=this.moveLeft.bindAsEventListener(this);this.bMoveRight=this.moveRight.bindAsEventListener(this);this.bMouseDown=this.mouseDown.bindAsEventListener(this)}Event.observe(this.navigationBar.identify(),"mousedown",this.bClickOnBar);
Event.observe(this.leftArrow.identify(),"click",this.bMoveLeft);Event.observe(this.rightArrow.identify(),"click",this.bMoveRight);Event.observe("lnk_"+this.goTo.identify(),"click",this.bGoToPage);Event.observe(this.slider.identify(),"mousedown",this.bMouseDown)}},findPos:function(a){var b=curtop=0;if(a.offsetParent){b=a.offsetLeft;curtop=a.offsetTop;while(a=a.offsetParent){b+=a.offsetLeft;curtop+=a.offsetTop
}}return[b,curtop]},getXOffset:function(){var b=this.findPos(this.navigationBar);var a=this.mouseXPos-b[0];if(a<0){a=0}if(a>=this.barWidth){a=this.barWidth}return a},getTargetPage:function(b){switch(b){case"click":var c=this.getXOffset();var d={page:Math.ceil(this.totalPages*(c/this.barWidth)),xOffset:c};if(d.page>this.currentPage){d.page=this.currentPage+1}if(d.page<this.currentPage){d.page=this.currentPage-1
}return d;break;default:var a;if((a=this.startPos+(this.mouseXPos-this.clickXPos))<=this.barWidth&&a>=18){a=(a<(this.barWidth/2)?a-9:a+9);return{page:Math.ceil(this.totalPages*((a-9)/this.barWidth))}}else{if(a<18){return{page:1}}return{page:this.totalPages}}break}},updateCaption:function(a){this.page=a;$(this.pageNumber).update(a+"/"+this.totalPages)},moveSlider:function(b,d){if(this.style!=this.STYLE_SLIDER){return
}var c=(d?{page:parseInt(d)}:this.getTargetPage(b,d));if(!c.page){return null}else{if(b=="click"||d){if(Object.isUndefined(this.stepWidth)){return}this.slider.style.left=(18+(c.page-1)*parseFloat(this.stepWidth))+"px"}else{var a;var e=(this.mouseXPos-this.clickXPos);if((a=this.startPos+e)>18&&a<(this.barWidth-this.sliderWidth+18)){this.slider.style.left=a+"px"}}}this.currentPage=d;this.updateCaption(c.page)
},clickOnBar:function(a){this.mouseXPos=Event.pointerX(a);this.moveSlider("click");this.go()},mouseDown:function(a){Event.stop(a);this.clickXPos=Event.pointerX(a);this.startPos=parseFloat(this.slider.style.left);this.bMouseMove=this.mouseMove.bindAsEventListener(this);this.bMouseUp=this.mouseUp.bindAsEventListener(this);Event.observe(document.body,"mousemove",this.bMouseMove);Event.observe(document.body,"mouseup",this.bMouseUp)
},mouseMove:function(a){this.mouseXPos=Event.pointerX(a);this.moveSlider()},mouseUp:function(a){Event.stopObserving(document.body,"mousemove",this.mouseMoveBinded);if(!this.page){return}Event.stopObserving(document.body,"mousemove",this.bMouseMove);Event.stopObserving(document.body,"mouseup",this.bMouseUp);this.slider.style.left=18+(this.page-1)*this.stepWidth+"px";this.go()},moveLeft:function(a){if(this.currentPage==1){Event.stop(a);
return}var b=this.currentPage;this.slider.style.left=18+(b-2)*this.stepWidth+"px";this.updateCaption(--b);this.go(b)},moveRight:function(a){if(this.currentPage==this.totalPages){Event.stop(a);return}var b=this.currentPage;this.slider.style.left=18+b*this.stepWidth+"px";this.updateCaption(++b);this.go(b)},goToPage:function(b){b.stop();var a=parseInt(this.goTo.value);if((0<a)&&(a<=this.totalPages)){this.moveSlider("goTo",a);
this.go(a)}else{this.goTo.select()}},go:function(page){if(this.loading){return}if(this.style==this.STYLE_CLASSIC){window.location.replace(this.handler.url+"?"+(this.handler.queryString.length?this.handler.queryString+"&":"")+"page="+page);return}this.loading=true;if(!page){page=this.page}var createHandler=eval(this.handler.onCreate)||Prototype.emptyFunction;var failureHandler=eval(this.handler.onFailure)||Prototype.emptyFunction;
this.handler.parameters.set("page",page);this.handler.parameters.set("paginator",this.group);if(this.refreshPagination){this.handler.parameters.unset("cacheId");this.handler.parameters.set("refreshPagination",this.group)}else{this.handler.parameters.unset("refreshPagination")}createHandler(this);this.handler.parameters.each(function(item){if(item.value&&item.value.toString()=="[object Object]"){this.unset(item.key);
$H(item.value).each(function(it){var newKey=item.key+"["+it.key+"][]";this.set(newKey,it.value)},this)}},this.handler.parameters);var ajaxParameters={method:"get",parameters:this.handler.parameters,onSuccess:function(tr){var successHandler=!(Object.isFunction(this.handler.onSuccess))?eval(this.handler.onSuccess)||Prototype.emptyFunction:this.handler.onSuccess;var response=null;try{response=tr.responseText.evalJSON()
}catch(ex){if(window.console){window.console.error("The pagination response is not a valid JSON")}}this.loading=false;try{successHandler(tr,response);this.handleUpdate(response)}catch(ex){if(window.console){console.log(ex)}}}.bind(this),onFailure:function(tr){this.loading=false;failureHandler(tr)}};if(!Object.isUndefined(this.handler.parameters.get("overlayer"))){ajaxParameters.overlayer={id:this.handler.parameters.get("overlayer"),autoReposition:!this.handler.fixedHeight}
}else{if(this.handler.update){ajaxParameters.overlayer={id:this.handler.update,autoReposition:!this.handler.fixedHeight}}}if(this.handler.message){ajaxParameters.message=this.handler.message}new Ajax.Request(this.handler.url,ajaxParameters);this.currentPage=page;this.updateFriends(page)},handleUpdate:function(a){if(this.handler.update){$(this.handler.update).update(a.results)}if(this.refreshPagination){Paginators.getGroup(this.group).each(function(b){b.rewind(a.handler.config);
b.setParameters(a.handler.parameters)});this.refreshPagination=false}},refresh:function(a){this.refreshPagination=true;if(!Object.isUndefined(a)){if(!Object.isHash(a)){throw ("'newParameters' must be a Hash object!")}this.setParameters(a);this.currentPage=0;var b=a.get("page");if(Object.isUndefined(b)){this.go(1)}else{this.go(b)}}else{this.go(this.currentPage)}},getHandler:function(){return this.handler
},setHandler:function(a){this.handler=a},setParameters:function(a){this.handler.parameters=$H(a);this.handler.queryString=Object.toQueryString(this.handler.parameters)},getParameters:function(){return this.handler.parameters},getCurrentPage:function(){return this.currentPage},updateFriends:function(a){$A(Paginators.getGroup(this.group)).each(function(b){b.moveSlider("goTo",a)})},hide:function(){$("paginationContainer_"+this.uniqueId).hide();
this.visible=false},show:function(){if(this.visible==false){$("paginationContainer_"+this.uniqueId).show();this.visible=true}},rewind:function(a){if(parseInt(a.totalPages)<2){this.hide()}else{this.show();this.totalPages=a.totalPages;this.currentPage=(a.currentPage?a.currentPage:1);this.calculateWidths();this.moveSlider("rewind",(a.currentPage?a.currentPage:1))}},_garbageCollector:function(){Event.stopObserving(this.navigationBar.identify(),"mousedown",this.bClickOnBar);
Event.stopObserving(this.leftArrow.identify(),"click",this.bMoveLeft);Event.stopObserving(this.rightArrow.identify(),"click",this.bMoveRight);Event.stopObserving("lnk_"+this.goTo.identify(),"click",this.bGoToPage);Event.stopObserving(this.slider.identify(),"mousedown",this.bMouseDown)}});