Kwo.Community = {
  
  "Account": {

    "clean": function() {
      $("comment_message").hide();
    },

    "view": function(page) {
      var url = "/community/account";
      if (page !== undefined) {
        url = url+"#"+page;
      }
      Kwo.go(url);
    },
    
    "refresh": function(msg) {
      Kwo.Community.Account.setMessage(msg);
      elt = $("account").select(".page_link")[0];
      Kwo.exec(elt.getAttribute("action"), {"page": elt.id}, {"container": "kwo-account-content"});
      setTimeout(function() { $("comment_message").hide(); }, 30000);
    },
    
    "exec": function(name) {
      Kwo.Community.Account.clean();
      $("kwo-account-content").update('<img src="/app/sys/pix/throbber2.gif" />');
      elt = $(name);
      if (window.location.hash.length >= 2) {
        window.location.href = window.location.href.replace(window.location.hash, "#"+elt.id); 
      }
      else {
        window.location.href += "#"+elt.id;
      }
      $("account").select(".page_link").each(function (e) { e.removeClassName("on"); });
      elt.addClassName('on');
      Kwo.exec(elt.getAttribute("action"), {"page": elt.id}, {"container": "kwo-account-content"});
    },

    "setMessage": function(msg, error) {
      error = error || false;
      msg = (msg === undefined) ? "ok" : msg;
      $("comment_message").show();
      $("comment_message").update('<img src="/app/sys/pix/ok.gif" id="emblem" />'+msg.ucfirst()
                                  +'<div style="clear:both;"></div>');
    },

    "storeProfile": function(args) {
      Kwo.exec("/community/user.store_profile", args);
    }
    
  },
  
  "Friend": {
    "add": function(user_id) {
      
    },

    "remove": function(user_id) {
      if (!confirm("êtes vous sûr ?".ucfirst())) return;
      Kwo.exec("/community/user.remove_friend", 
               {"user_id": user_id});
    }
  },

  "changeEmail": function(args) {
    Kwo.exec("/community/user.change_email", args, {"toggle": "panel_throbber", "reset": true});
  },
    
  "changePassword": function(args) {
    Kwo.exec("/community/user.change_password", args, {"reset": true});
  },  

  "forgotPassword": function() {
    new Kwo.Dialog('/community/visitor.forgot_password');
  },

  "initAuthBox": function() {
    Kwo.exec("/community/widget.auth", null, {"container":"kwo-auth-box"});
    return false;
  },

  "login": function(args) {
    Kwo.exec("/community/login", args);
    return false;
  },
  
  "logout": function(args) {
    Kwo.exec("/community/logout", null, {"confirm": args});
  },

  "sendPassword": function(args) {
    Kwo.exec("/community/visitor.send_password", args);
    if ($("forget_area")) {
      $("forget_area").toggle();
      if ($("login")) $("login").focus();
    }
  },

  "signin": function(args) {
    if ($("terms_of_use") && !$("terms_of_use").checked) {
      return Kwo.warn(msg_accept_terms_of_user.ucfirst());
    }
    Kwo.exec("/community/login", args);
  },
  
  "signup": function () {
    Kwo.go("/community/signup");
  }

};