function User(){}(function(A){A("body").ready(function(){User.enableAskForm();User.enableSuperUserForm();});User.loadMyArticles=function(C,B){forward.getWidget("user/article?id="+C+"&p="+B,function(D){A("#article_user_container").html(D);});};User.enableAskForm=function(){if(A("#user_ask_form")!=null&&A("#user_ask_form").is("*")){var B=false;
A("#ask_input").focus(function(){if(!B){A("#ask_input").val("");B=true;}});A("#user_ask_form").validate({rules:{ask_input:{required:{depends:function(C){return(A("#ask_input").val()!=A("#_default_input").val());}}},minlength:10,maxlength:1000},errorContainer:"#ask_error_container",submitHandler:function(C){dialogAction.sendMessage(A("#_user_id").val(),A("#ask_input").val(),null,function(){A("#ask_input").val("");
A("#user_ask_confirmation_container").show().fadeOut(5000);});}});}};User.enableSuperUserForm=function(){if(A("#user_superuser_form")!=null&&A("#user_superuser_form").is("*")){A("#user_type").change(function(){if(A("#user_type").val()=="AGENT"){A("#_user_representing_type").val("AGENT");A("#user_representing_name").flushCache();
A("#_user_representing_id").val("");A("#_user_representing_id").rules("add",{required:true,minlength:1});}else{if(A("#user_type").val()=="OFFICIAL"){A("#_user_representing_type").val("UNIVERSITY");A("#user_representing_name").flushCache();A("#_user_representing_id").val("");A("#_user_representing_id").rules("add",{required:true,minlength:1});
}else{if(A("#user_type").val()=="ORGANIZATION_OWNER"){A("#_user_representing_type").val("OTHER");A("#user_representing_name").flushCache();A("#_user_representing_id").val("");A("#_user_representing_id").rules("add",{required:true,minlength:1});}else{A("#_user_representing_id").val("");A("#_user_representing_id").rules("remove");
}}}});A("#user_representing_name").autocomplete("/autocomplete/search",{minChars:2,matchContains:true,extraParams:{type:function(){return A("#_user_representing_type").val();}},formatItem:function(D,C,B){return D[0];},formatResult:function(B){if(B[2]>0){return B[0];}else{return B[1];}}}).result(function(B,D,C){A("#_user_representing_id").val(D[2]);
});A(".representing_name").each(function(B,C){A(this).autocomplete("/autocomplete/search",{minChars:2,matchContains:true,extraParams:{type:function(){return A("#_user_representing_type").val();}},formatItem:function(F,E,D){return F[0];},formatResult:function(D){if(D[2]>0){return D[0];}else{return D[1];
}}}).result(function(E,G,F){var D=A(this).attr("rel");A("#_user_representing_id_"+D).val(G[2]);});});A(".representing_update_link").each(function(B,C){A(this).click(function(){var D=A(this).attr("rel");A("#user_superuser_representing_form_"+D).validate({errorLabelContainer:"#user_superuser_error_container",submitHandler:function(E){dialogAction.addUserRepresenting(A("#_user_id").val(),A("#user_type").val(),A("#_user_representing_id_"+D).val(),function(F){if(F==true){alert("successful update");
window.location.reload();}else{alert("error");}});return false;}});A("#_user_representing_id_"+D).rules("add",{required:true});A("#user_superuser_representing_form_"+D).submit();});});A(".representing_delete_link").each(function(B,C){A(this).click(function(){var D=A(this).attr("rel");dialogAction.deleteUserRepresenting(A("#_user_id").val(),A("#_user_representing_id_"+D).val(),function(E){if(E==true){alert("successful update");
window.location.reload();}else{alert("error");}});});});A("#representing_add_link").click(function(){A("#user_superuser_representing_form").validate({errorLabelContainer:"#user_superuser_error_container",rules:{_user_representing_id:{required:true}},submitHandler:function(B){dialogAction.addUserRepresenting(A("#_user_id").val(),A("#user_type").val(),A("#_user_representing_id").val(),function(C){if(C==true){alert("successful update");
window.location.reload();}else{alert("error");}});return false;}});A("#user_superuser_representing_form").submit();});A("#user_superuser_form").validate({errorLabelContainer:"#user_superuser_error_container",submitHandler:function(C){var B=0;if(A("#user_reset").is(":checked")){B=1;}dialogAction.updateUser(A("#_user_id").val(),A("#user_status").val(),A("#user_type").val(),B,function(D){if(D==true){alert("successful update");
window.location.reload();}else{alert("error");}});return false;}});}};})(jQuery);