var LoginFormController=function(){var _self=this;var _messages;this.setMessages=function(messages){_messages=messages;}
this.isFormOpened=function(){return!$("#divLoginForm").hasClass("hide");}
this.registerFormOpenEvent=function(){$("#linkLogin").bind("click",_openLoginForm);}
var _openLoginForm=function(){$("#divRegistrationForm").addClass("hide");if(_self.isFormOpened())return;_drawLoginForm();_registerSubmitEvent();_registerFormCloseEvent();}
var _drawLoginForm=function(){var width=145;$("#divLoginForm").removeClass("hide");$("#fieldLogin").focus();}
var _registerFormCloseEvent=function(){$("#linkCloseLoginForm").click(function(){$("#divLoginForm").addClass("hide");});}
var _registerSubmitEvent=function(){$("#divLoginForm form").bind("submit",_submitEvent);}
var _submitEvent=function(event){$("#divLoginForm p.error").remove();var errors=_validate();if(errors.length){_drawErrors(errors);return false;}
$("#divLoginForm input[type=submit]").attr("disabled",true);return true;}
var _validate=function(){var errors=[];if(!$("#divLoginForm input[name=login]").val()){errors.push("illegal_login");}
if(!$("#divLoginForm input[name=password]").val()){errors.push("illegal_password");}
return errors;}
var _drawErrors=function(errors){_translate(errors);$.each(errors,function(idx,error){$("#divLoginForm legend").after('<p class="error">'+error+'</p>');});}
var _translate=function(errors){for(var i=0;i<errors.length;i++){errors[i]=_messages.loginErrors[errors[i]];}}}
$(document).ready(function(){$("#linkLogin").attr("href","javascript:void(0);");var lfc=new LoginFormController();lfc.setMessages(messages);lfc.registerFormOpenEvent();});if(!Memori)var Memori={}
Memori.RegistrationFormController=function(item,div){var _self=this;var _messages;var _item=item;var _div=div;var _errors=[];var _err_login;var _err_password;var _err_rep_password;var _err_email;this.isFormOpened=function(){return!_div.hasClass("hide");}
this.registerFormOpenEvent=function(){_item.attr("href","javascript:void(0);");_item.bind("click",_openRegistrationForm);}
var _openRegistrationForm=function(){if(_self.isFormOpened())return;_drawRegistrationForm();_registerSubmitEvent();_registerFormCloseEvent();}
var _drawRegistrationForm=function(){_div.removeClass("hide");$("#divLoginForm").addClass("hide");_div.find("#userLogin").focus();}
var _registerFormCloseEvent=function(){$("#linkCloseRegistrationForm").click(function(){_div.addClass("hide");});}
var _registerSubmitEvent=function(){_div.find("#btnRegister").bind("click",_submitEvent);}
var _submitEvent=function(event){_errors=[];_err_login="";_err_password="";_err_rep_password="";_err_email="";_validate();if(_errors.length){_drawErrors();return false;}
return false;}
var _validate=function(){var login=_div.find("input[name=login]").val();var password=_div.find("input[name=password]").val();var confirm_password=_div.find("input[name=password_confirm]").val();var email=_div.find("input[name=email]").val();if(login&&password&&confirm_password&&email){var request='?login='+login+'&password='+password+'&confirm_password='+confirm_password+'&email='+email;_div.find("#btnRegister").attr('disabled',true);$.getJSON("/suggestedregformajax/"+request,_validateResponse);}else{if(!login)_checkLogin();if(!password)_checkPas();if(!email)_checkEmail();if(password&&!confirm_password)_checkPasConfirm();}}
var _validateResponse=function(response){_div.find("#btnRegister").attr('disabled','');if(response.login!=0){_err_login="Введите корректный логин<br />";_errors.push("illegal_login");}
if(response.password!=0){_err_password="Введите корректный пароль<br />";_errors.push("illegal_password");}else if(response.confirm_password!=0){_err_rep_password="Повтор Пароля и Пароль не совпадают<br /><br />";_errors.push("illegal_confirm_password");}
if(response.email!=0){_err_email="Введите корректный e-mail<br />";_errors.push("illegal_email");}
if(!_errors.length){_div.find("form").submit();}else{_drawErrors();}}
var _checkLogin=function(){var login=_div.find("input[name=login]").val();if(login==''){_err_login="Введите логин<br />";_errors.push("illegal_login");}}
var _checkPas=function(){var password=_div.find("input[name=password]").val();if(password==''){_err_password="Введите пароль<br />";_errors.push("illegal_password");}
else if(_div.find("input[name=password_confirm]").val()){_checkPasConfirm();}else{_err_rep_password="Повторите пароль<br />";_errors.push("illegal_password_confirm");}}
var _checkPasConfirm=function(){if(_div.find("input[name=password]").val()!=_div.find("input[name=password_confirm]").val()){_err_rep_password="Повтор Пароля и Пароль не совпадают<br />";_errors.push("illegal_password_confirm");}}
var _checkEmail=function(){var email=_div.find("input[name=email]").val();if(!email.match("^([a-zA-Z0-9_!\"\.\#\$\%\&\'\*\+\/\=\?\{\|\}\~\`-]+?)@([a-zA-Z0-9_-]+\.){1,3}([a-zA-Z]){2,4}$")){_err_email="Введите корректный e-mail<br />";_errors.push("illegal_email");}}
var _drawErrors=function(errors){_div.find("#loginError").html(_err_login);_div.find("#emailError").html(_err_email);_div.find("#pasError").html(_err_password);_div.find("#confirmPasError").html(_err_rep_password);}}
$(document).ready(function(){if($("div.reg").length==0){var regfc=new Memori.RegistrationFormController($("#linkRegistration"),$("#divRegistrationForm"));regfc.registerFormOpenEvent();}});if(Memori==undefined)var Memori={}
Memori.UrlObject=function(urlElement){var _urlElement=urlElement;var _conteiner=Memori.AddLinkController.getController();var _inProcess=0;function _validate(){function _timeOutValidate(){url=_urlElement.val();if(_validateUrl(url)){_conteiner.sendMessage({text:'url valid'});}else{_conteiner.sendMessage({text:'url invalid'});}
_inProcess=0;}
if(_inProcess==0){_inProcess=1;setTimeout(_timeOutValidate,1000);}}
function _urlKeyUp(ev){var key=(window.event)?window.event.keyCode:ev.keyCode;var TAB=9;var ESC=27;switch(key){case TAB:return true;case ESC:return true;}
_validate();}
function _validateUrl(url){return url.match(/^(?:(?:https?|ftp|telnet|):\/\/(?:[a-zA-Z0-9_-]{1,32}(?::[a-zA-Z0-9_-]{1,32})?@)?)?(?:(?:[a-zA-Z0-9-]{1,128}\.)+(?:com|net|org|mil|edu|arpa|ru|gov|biz|info|aero|inc|name|[a-zA-Z]{2})|(?!0)(?:(?!0[^.]|255)[0-9]{1,3}\.){3}(?!0|255)[0-9]{1,3})(?:\/[)(a-zA-Zа-яА-Я0-9.,_@%&?+=\[\]\~\/-]*)?(?:#[^\'\"&<>]*)?$/i);}
var _preValidate=function(){url=_urlElement.val();if(url&&!_validateUrl(url)){_conteiner.sendMessage({text:'url valid'});}}
_urlElement.bind("keydown",_urlKeyUp).bind('input',_validate).bind('paste',_validate);_urlElement.bind('blur',_preValidate);return{notify:function(message){},run:function(){if(_urlElement.val()){_conteiner.sendMessage({text:'url valid'});}},getSiteName:function(){return _urlElement.val();}}}
Memori.UrlObject.instance=null;Memori.UrlObject.getObject=function(urlElement){if(!Memori.UrlObject.instance){Memori.UrlObject.instance=new Memori.UrlObject(urlElement);}
return Memori.UrlObject.instance;}
Memori.AllowDownloadSiteNameDiv=function(elementToDownLoad,titleElement){var _elementToDownLoad=elementToDownLoad;var _titleElement=titleElement;var _link=$('#'+_elementToDownLoad.attr('id')+'>a');function _allowDownLoadName(){_elementToDownLoad.show();_link.bind("click",_getSiteName);}
function _denideDownLoadName(){_elementToDownLoad.hide();_link.unbind("click",_getSiteName);}
function _getSiteName(){$.getJSON('/getsitenameajax',{siteName:Memori.UrlObject.getObject().getSiteName()},_setSiteName);}
function _setSiteName(js){if(js.success==1){_titleElement.val(js.siteName);_titleElement.keyup();}else{alert(js.formErrors);}}
function _doAction(message){message=message.text;switch(message){case'url valid':_allowDownLoadName();break;case'url invalid':_denideDownLoadName();break;}}
var _checkOnAutoload=function(){if($('#loadSiteName').val()){_getSiteName();}}
_checkOnAutoload();return{notify:function(message){_doAction(message);},run:function(){}}}
Memori.TagsLinksLoader=function(tagsElement,headerElement,selectorPopular,selectorAll,loader,popularRate,selectorLast,autoCompleteController){var _tagsElementId=tagsElement.attr('id');var _tagsElement=tagsElement;var _selectorPopular=selectorPopular;var _selectorAll=selectorAll;var _selectorLast=selectorLast||$('#noElement');var _headerElement=headerElement;var _loader=loader||'gettagspromting';var _popularRate=popularRate;var _autoCompleteController=autoCompleteController;var _tagIdPrefix=_tagsElement.attr('id')+"_tag";var _tags={};var _countAll=0;function _getTagsForUrl(){$.getJSON('/'+_loader,{siteName:Memori.UrlObject.getObject().getSiteName()},_fillTagsList);}
function _fillTagsList(js){_tags=[];if(js.success==1){_countAll=0;_tagsElement.text('');if(js.tags.length){for(var k in js.tags){if(js.tags[k]){link=$("<a class=\"control\" href=\"javascript:void(0);\" id=\""+_tagIdPrefix+k+"\" countLinks="+js.tags[k].count+"></a>");link.text(js.tags[k].name)
_tags[k]={text:js.tags[k].name,countLinks:js.tags[k].count,link:link,isShow:true,isLast:js.tags[k].last,isPopular:js.tags[k].popular};_countAll+=js.tags[k].count;}}
_tagsElement.show();_headerElement.show();_addCommasAfterLinks();switch(_getSelectorCondition()){case'popular':_popularRate?_showOnlyPopularTagsByRate():_showOnlyPopularTags();break;case'last':_showOnlyLastTags();break;case'all':_showAllTags();break;}}else{_tagsElement.show();_headerElement.show();_tagsElement.text('Тэгов не найдено');}}}
function _addCommasAfterLinks(){var isElementInserted=false;_tagsElement.empty();for(var k in _tags){if(_tags[k].isShow){_tagsElement.append(_tags[k].link);if(isElementInserted){_tags[k].link.before(', ');}
_tags[k].link.bind('click',{tagId:k},_changeTag);isElementInserted=true;}}}
function _changeTag(event){link=_tags[event.data.tagId].link;elementId=_tagIdPrefix+event.data.tagId;if(!_isChecked(link)){_checkLink(link);Memori.conteiner.sendMessage({text:'addTag',tagId:elementId});}else{_uncheckLink(link);Memori.conteiner.sendMessage({text:'deleteTagFromTextarea',tagId:elementId});}}
function _isChecked(link){return link.hasClass('actvtag');}
function _checkLink(link){link.addClass('actvtag');}
function _uncheckLink(link){link.removeClass('actvtag');}
function _actionOnInvalidUrl(){_tagsElement.hide();_headerElement.hide();}
function _doAction(message){switch(message.text){case'url valid':_getTagsForUrl();break;case'url invalid':_actionOnInvalidUrl();break;case'tags area edited':_synchronizeTagsListWithTextArea(message.data);_setAutoComplete(message.data,message.noAutoComplete);break;case'addTag':if(_tags[message.tagId]){_checkLink(_tags[message.tagId].link);}
break;case'deleteTagFromTextarea':if(_tags[message.tagId]){_uncheckLink(_tags[message.tagId].link);}
break;}}
function _showOnlyPopularTagsByRate(){for(var k in _tags){if(_tags[k].countLinks/_countAll>=_popularRate){_tags[k].isShow=true;}else{_tags[k].isShow=false;}}
_addCommasAfterLinks();}
function _showOnlyPopularTags(){for(var k in _tags){if(_tags[k].isPopular){_tags[k].isShow=true;}else{_tags[k].isShow=false;}}
_addCommasAfterLinks();}
function _showOnlyLastTags(){for(var k in _tags){_tags[k].isShow=_tags[k].isLast?true:false;}
_addCommasAfterLinks();}
function _showAllTags(){for(var k in _tags){_tags[k].isShow=true;}
_addCommasAfterLinks();}
function _synchronizeTagsListWithTextArea(tagsList){tagsString=','+tagsList.join(',')+',';for(var k in _tags){if(tagsString.indexOf(','+_tags[k].text+',')>-1){_checkLink(_tags[k].link);}else{_uncheckLink(_tags[k].link);}}}
var _setAutoComplete=function(tagsList,noAutoComplete){if(_autoCompleteController){if(!noAutoComplete){var noShowTags=new Array();for(var k in _tags){if(!_isChecked(_tags[k].link)){noShowTags.push(_tags[k]);}}
_autoCompleteController.setTags(noShowTags,_synchronizeTagsListWithTextArea);tagsList.length?_autoCompleteController.generate(tagsList[tagsList.length-1]):_autoCompleteController.clear();}else{_autoCompleteController.clear();}}
return true;}
function _checkPopularSelector(){$.cookie(_tagsElementId,'popular',{expires:365,path:"/"});_selectorPopular.addClass('checkedTagsSelector');_uncheckAllSelector();_uncheckLastSelector();_selectorAll.bind('click',_checkAllSelector);_selectorLast.bind('click',_checkLastSelector);_selectorPopular.unbind('click',_checkPopularSelector);_popularRate?_showOnlyPopularTagsByRate():_showOnlyPopularTags();}
function _uncheckPopularSelector(){_selectorPopular.removeClass('checkedTagsSelector');}
function _checkLastSelector(){$.cookie(_tagsElementId,'last',{expires:365,path:"/"});_selectorLast.addClass('checkedTagsSelector');_uncheckAllSelector();_uncheckPopularSelector();_selectorAll.bind('click',_checkAllSelector);_selectorPopular.bind('click',_checkPopularSelector);_selectorLast.unbind('click',_checkLastSelector);_showOnlyLastTags();}
function _uncheckLastSelector(){_selectorLast.removeClass('checkedTagsSelector');}
function _checkAllSelector(){$.cookie(_tagsElementId,'all',{expires:365,path:"/"});_selectorAll.addClass('checkedTagsSelector');_uncheckPopularSelector();_uncheckLastSelector();_selectorPopular.bind('click',_checkPopularSelector);_selectorLast.bind('click',_checkLastSelector);_selectorAll.unbind('click',_checkAllSelector);_showAllTags();}
function _uncheckAllSelector(){_selectorAll.removeClass('checkedTagsSelector');}
function _getSelectorCondition(){if(_selectorPopular.attr('class')=='checkedTagsSelector'){return'popular';}else if(_selectorAll.attr('class')=='checkedTagsSelector'){return'all';}else if(_selectorLast.attr('class')=='checkedTagsSelector'){return'last';}}
if(!$.cookie(_tagsElementId)||$.cookie(_tagsElementId)=='popular'){_selectorPopular.addClass('checkedTagsSelector');_selectorAll.bind('click',_checkAllSelector);_selectorLast.bind('click',_checkLastSelector);}else if($.cookie(_tagsElementId)=='all'){_selectorPopular.bind('click',_checkPopularSelector);_selectorAll.addClass('checkedTagsSelector');_selectorLast.bind('click',_checkLastSelector);}else{_selectorPopular.bind('click',_checkPopularSelector);_selectorAll.bind('click',_checkAllSelector);_selectorLast.addClass('checkedTagsSelector');}
return{notify:function(message){_doAction(message);},run:function(){}}}
Memori.TagsLinksLoader.instance=null;Memori.TagsLinksLoader.getInstance=function(element,headerElement,selectorPopular,selectorAll){if(!Memori.TagsLinksLoader.instance){Memori.TagsLinksLoader.instance=new Memori.TagsLinksLoader(element,headerElement,selectorPopular,selectorAll);}
return Memori.TagsLinksLoader.instance;}
Memori.TagsTextArea=function(element,maxTagsCount,informerForTagsCount){var _element=element;var _actvtags={};var _tagsArray=new Array();var _conteiner=Memori.AddLinkController.getController();var _maxTagsCount=maxTagsCount;var _informerForTagsCount=informerForTagsCount;this.getObject=function(){return _element;}
function _getTagText(tagId){return $('#'+tagId).text();}
function _addTag(tagId){text=_getTagText(tagId);_actvtags[tagId]=text;if(_element.val()!=''){text=', '+text;}
_element.val(_element.val()+text);_sendSynchrinizeMessage();}
function _deleteTag(tagId){_setTagsArray(_getTagText(tagId))
_showTags();_sendSynchrinizeMessage();}
function _setTagsArray(tagTextToDel){tempTagsArray=element.val().split(',');_tagsArray=new Array();for(var k in tempTagsArray){temp=Memori.trim(tempTagsArray[k]);if(temp!=''&&temp!=tagTextToDel){_tagsArray.push(temp);}}}
function _showTags(){_element.val(_tagsArray.join(', '));}
function _doAction(message){switch(message.text){case'addTag':_addTag(message.tagId);break;case'deleteTagFromTextarea':_deleteTag(message.tagId);break;}}
function _synchronizeTagsList(){setTimeout(_sendSynchrinizeMessage,10);}
var _checkOnTagsCount=function(){if(_tagsArray.length<_maxTagsCount){_informerForTagsCount.attr('class','');}else if(_tagsArray.length==_maxTagsCount){_informerForTagsCount.attr('class','bold');}else{_informerForTagsCount.addClass('error');}}
function _sendSynchrinizeMessage(){_setTagsArray();_conteiner.sendMessage({text:'tags area edited',data:_tagsArray});_checkOnTagsCount();}
_element.bind('keydown',_synchronizeTagsList).bind('input',_synchronizeTagsList).bind('paste',_synchronizeTagsList);return{notify:function(message){_doAction(message);},run:function(){}}
_sendSynchrinizeMessage}
Memori.TagsTextArea.instance=null;Memori.TagsTextArea.getInstance=function(element,maxTagsCount,informerForTagsCount){if(!Memori.TagsTextArea.instance){Memori.TagsTextArea.instance=Memori.TagsTextArea(element,maxTagsCount,informerForTagsCount);}
return Memori.TagsTextArea.instance;}
Memori.LinkHistoryBlock=function(div){var _div=div;var _getHtml=function(){$.getJSON('/getLinkInfo/?siteName='+Memori.UrlObject.getObject().getSiteName(),_refreshHtml);}
var _refreshHtml=function(response){if(response.success){_div.html(response.html);_bindEvents();}}
var _bindEvents=function(){_div.find('#showOtherDescription').bind('click',function(){_div.find('div.popblock').toggle();});_div.find('a[@name^="add-"]').bind('click',function(){var id=$(this).attr('name').replace('add-','');$('#description').attr('value',_div.find('#desc-'+id).text());_div.find('div.popblock').hide();});_div.find('a.cross').bind('click',function(){_div.find('div.popblock').hide();});}
var _showBlock=function(){_getHtml();_div.show();}
var _hideBlock=function(){_div.hide();_div.html('');}
var _doAction=function(message){message=message.text;switch(message){case'url valid':_showBlock();break;case'url invalid':_hideBlock();break;}}
return{notify:function(message){_doAction(message);},run:function(){}}}
Memori.LinkHistoryBlock.instance=null;Memori.LinkHistoryBlock.getInstance=function(element){if(!Memori.LinkHistoryBlock.instance){Memori.LinkHistoryBlock.instance=Memori.LinkHistoryBlock(element);}
return Memori.LinkHistoryBlock.instance;}
Memori.TagsAutocomplete=function(div,textarea){var _div=div;var _textarea=textarea;var _tags={};var _callback;this.setTags=function(tags,callback){_tags=tags;if(!_callback){_callback=callback;}}
this.generate=function(tagName){this.clear();if(_textarea.val().match(/, *$/i))return;tagName=tagName.toLowerCase();var tempArray=new Array()
if(tagName.length>1){for(var k in _tags){if(_tags[k].text.toLowerCase().indexOf(tagName)===0){tempArray.push("<a class=\"control\" href=\"javascript:void(0);\">"+_tags[k].text+"</a>");}}
_updateBlock(tempArray);}
return true;}
this.clear=function(){_div.html('');}
var _updateBlock=function(completeTags){if(completeTags.length){_div.html(completeTags.join(', '));_div.find('a.control').bind('click',function(){var arr=_textarea.val().split(',');_tagsArray=new Array();for(var k in arr){temp=Memori.trim(arr[k]);if(temp!=''){_tagsArray.push(temp);}}
_tagsArray[_tagsArray.length-1]=$(this).text();_textarea.val(_tagsArray.join(', '));Memori.AddLinkController.getController().sendMessage({text:'tags area edited',data:_tagsArray,noAutoComplete:true});});}}}
Memori.StarsArea=function(div,hiddenValue){var _div=div;var _hiddenValue=hiddenValue;var _titles=new Array('Ужасно','Плохо','Нормально','Хорошо','Отлично');var _bindFormEvents=function(){_bindMarkMouseOverOutEvents();_div.find("img[src$='bigstar_empty.gif']").bind("click",_pick);_div.find("img[src$='bigstar_picked.gif']").bind("click",_pick);_div.find("a").bind("click",_release);}
var _bindMarkMouseOverOutEvents=function(){_div.find("img[src$='bigstar_empty.gif']").bind("mouseover",_mouseOver);_div.find("img[src$='bigstar_picked.gif']").bind("mouseover",_mouseOver);_div.find("img[src$='bigstar_empty.gif']").bind("mouseout",_mouseOutEmpty);_div.find("img[src$='bigstar_picked.gif']").bind("mouseout",_mouseOutPicked);}
var _unbindMarkMouseOverOutEvents=function(){_div.find("img[src$='bigstar_empty.gif']").unbind("mouseover",_mouseOver);_div.find("img[src$='bigstar_picked.gif']").unbind("mouseover",_mouseOver);_div.find("img[src$='bigstar_empty.gif']").unbind("mouseout",_mouseOutEmpty);_div.find("img[src$='bigstar_picked.gif']").unbind("mouseout",_mouseOutPicked);}
var _mouseOver=function(event){event.target.src="/images/bigstar_hl.gif";$(event.target).prevAll('[@src="/images/bigstar_empty.gif"]').attr("src","/images/bigstar_hl.gif");}
var _mouseOutEmpty=function(event){event.target.src="/images/bigstar_empty.gif";_div.find('img[@src="/images/bigstar_hl.gif"]').attr("src","/images/bigstar_empty.gif");}
var _mouseOutPicked=function(event){event.target.src="/images/bigstar_picked.gif";$(event.target).bind("mouseover",_mouseOver).bind("mouseout",_mouseOutPicked);}
var _release=function(){_hiddenValue.attr('value','');_div.find("img").remove();for(var i=0;i<5;i++){img=$('<img title="'+_titles[i]+'">').attr("src","/images/bigstar_empty.gif").bind("click",_pick);_div.find("br").before(img);}
_bindMarkMouseOverOutEvents();}
var _pick=function(event){$(event.target).attr("src","/images/bigstar_picked.gif");$(event.target).siblings().attr("src","/images/bigstar_empty.gif").unbind("mouseout",_mouseOutPicked).unbind("mouseout",_mouseOutPicked);$(event.target).prevAll().attr("src","/images/bigstar_picked.gif");_hiddenValue.attr('value',$(event.target).prevAll().length+1);_unbindMarkMouseOverOutEvents();_bindMarkMouseOverOutEvents();}
var _fillBookmark=function(){var nb={};nb.mark=_div.find("img[src='/images/bigstar_picked.gif']").length;return nb;}
var _initStarsDiv=function(){mark=_hiddenValue.attr('value')!=''?_hiddenValue.attr('value'):0;for(var i=0;i<5;i++){img=i<mark?$('<img title="'+_titles[i]+'">').attr("src","/images/bigstar_picked.gif"):$('<img title="'+_titles[i]+'">').attr("src","/images/bigstar_empty.gif");_div.find("br").before(img);}}
_initStarsDiv();_bindFormEvents();}
if(Memori==undefined)var Memori={};Memori.trim=function(text){return text.replace(/^\s+|\s+$/g,"");}
Memori.AddLinkController=function(){var _objectConteiner=new Array();return{addElement:function(element){_objectConteiner.push(element)},sendMessage:function(message){for(var k in _objectConteiner){_objectConteiner[k].notify(message);}},process:function(){for(var k in _objectConteiner){_objectConteiner[k].run();}}}}
Memori.AddLinkController.instance=null;Memori.AddLinkController.getController=function(){if(!Memori.AddLinkController.instance){Memori.AddLinkController.instance=new Memori.AddLinkController()}
return Memori.AddLinkController.instance;}
Memori.conteiner=null;$(document).ready(function(){Memori.conteiner=Memori.AddLinkController.getController();Memori.conteiner.addElement(Memori.UrlObject.getObject($("#url")));Memori.conteiner.addElement(new Memori.AllowDownloadSiteNameDiv($("#downLoadLinkSpan"),$('#title')));var tagsTextArea=Memori.TagsTextArea.getInstance($('#tags'),10,$("#noMoreTags"));var otherUsersTags=$("#tagsOtherUsersList");if(otherUsersTags.length>0){Memori.conteiner.addElement(new Memori.TagsLinksLoader(otherUsersTags,$("#tagsOtherUsersListHeader"),$('#showPopularTags'),$('#showAllTags'),null,0.03));}
var currentUserTags=$("#tagsCurrentUsersList");if(currentUserTags.length){var autoComplete=new Memori.TagsAutocomplete($('#tagAutoComplete'),$('#tags'));Memori.conteiner.addElement(new Memori.TagsLinksLoader(currentUserTags,$("#tagsCurrentUsersListHeader"),$('#showCurrentUserPopularTags'),$('#showCurrentUserAllTags'),'getusertagspromting',0,$('#showCurrentUserLastTags'),autoComplete));}
Memori.conteiner.addElement(tagsTextArea);Memori.conteiner.addElement(Memori.LinkHistoryBlock.getInstance($('#linkHistoryBlock')));Memori.conteiner.process();new Memori.StarsArea($('div.mark'),$('#mark'));var _setFieldLength=function(checkElement,maxLength,displayElement){var length=checkElement.val().length;if(length>maxLength){checkElement.attr('value',checkElement.val().substring(0,maxLength));length=maxLength;}
displayElement.attr('value',maxLength-length);}
var _descriptionLength=function(){_setFieldLength($('#description'),255,$('#descLength'));}
var _titleLength=function(){_setFieldLength($('#title'),200,$('#titleLength'));}
$('#title').bind('paste',_titleLength).bind('input',_titleLength).bind('keyup',_titleLength);$('#description').bind('paste',_descriptionLength).bind('input',_descriptionLength).bind('keyup',_descriptionLength);$('#addHdesc').click(function(){$('#hideDescr').slideToggle('slow');});$('input[@name="hidden"]').change(function(){if($(this).attr('checked')){$('#showToFriendsLabel').removeClass('hide');}else{$('#showToFriendsLabel').addClass('hide');$('input[@name="showToFriends"]').attr('checked','');}});});