/* Account
-------------------------------------------------------------------------- */

var ViewAccount = {

  loginInlay: {

    guid: 'account-login',
    url: '/shared/fetch/account/login/login.html',
    doScrollToTop: function() { return false; },
    onopen: function(params) {
      if (!params || !params.errorText)
        return ;
        
      $('#modlog_' + this.guid + ' .mlBody div.errorText').css({display:'block'}).html(params.errorText);
    }
  },

  resetPasswordInlay: {

    guid: 'account-resetpassword',
    url: '/shared/fetch/account/resetpassword/resetpassword.html',
    doScrollToTop: function() { return true; }
  },

  signupInlay: {

    guid: 'account-signup',
    url: '/shared/fetch/account/signup/signup.html',
    doScrollToTop: function() { return false; }
  },

  changeInlay: {

    guid: 'account-change',
    url: '/shared/fetch/account/change/change.html',
    doScrollToTop: function() { return true; }
  },

  settingsInlay: {

    guid: 'account-settings',
    url: '/shared/fetch/account/settings/settings.html',
    width: '600px',
    doScrollToTop: function() { return true; },

    onbeforeclose: function() {
      if (WR.Settings.focusedSomething)
        return confirm('You are about to close the dialog. Everything you have entered will be lost! Please confirm.');
        
      return true;
    },
    
    onclose: function() {
      loginState.unregister('ApiAccount.getSettings');
    }

  },

  infoInlay: {

    guid: 'account-info',
    url: '/shared/fetch/account/info/info.html',
    doScrollToTop: function() { return false; }
  }
}


/* Base
-------------------------------------------------------------------------- */

var ViewBase = {

  captchaInlay: {

    guid: 'base-captcha',
    url: '/shared/fetch/base/captcha/captcha.html',
    doScrollToTop: function() {return false;}, // !

    onbeforeclose: function() {
      return confirm('You are about to close the dialog. The whole process will be cancelled! Please confirm.');
    }
  },

  notifyInlay: {

    guid: 'base-notify',
    doScrollToTop: function() {return false;}, // !

    onopen: function(params) {
      if ((params.alert ? params.alert : false)) {
        $('#modlog_' + ViewBase.notifyInlay.guid + '').css({'background':'url(/shared/img/modlogCoverFailure.png)'});
        $('#modlog_' + ViewBase.notifyInlay.guid + ' .mlInner').css({'borderColor':'#C03'});
        $('#modlog_' + ViewBase.notifyInlay.guid + ' .mlHeader').css({'backgroundColor':'#C03'});
      }

      $('#mlTitle_'  + ViewBase.notifyInlay.guid).html(params.title);
      $('#mlBody_'  + ViewBase.notifyInlay.guid).html(params.text +
        '<div style="margin-top:20px"><input type="button" id="btn_' + this.guid + '" value=" ' + (params.btn ? params.btn : 'OK') + ' " onclick="Modlog.close(Modlog.CLOSE_MODE_CANCEL)" /></div>');
      delayedFocus('btn_' + this.guid);
    }
  },


  avatarInlay: {

    guid: 'account-avatar',
    width: '400px',
    doScrollToTop: function() { return true; },

    onopen: function(params) { // ausnahme, wegen parameter
      $('#mlBody_' + this.guid).load('/shared/fetch/base/avatar/avatar.php?type=' + params.type);
    }
  }
}


/* Board
-------------------------------------------------------------------------- */

var ViewBoard = {
  topicInlay: {

    guid: 'board-topic',
    url: '/shared/fetch/board/topic/topic.html',
    doScrollToTop: function() { return true; },

    onbeforeclose: function() {
      var subject = $('#topic-subject');
      var text    = $('#topic-text');
      
      if (subject.val() !== '' || text.val() !== '') {
        return confirm('Your entries will be lost! Please confirm.');
      }
      return true;
    }
    
  }
}


/* Account
-------------------------------------------------------------------------- */

var ViewCoop = {

  dol2dayInlay: {

    guid: 'coop-dol2day',
    width: '800px',
    url: '/shared/fetch/coop/dol2day/dol2day.html',
    doScrollToTop: function() { return false; }
  }
}


/* Forum
-------------------------------------------------------------------------- */

var ViewForum = {

  help: function() {
    new Modlog.construct(ViewBase.notifyInlay, {
      'title': 'Text formatting',
      'text' : '<span style="line-height:1.5em"><strong>Citation</strong><br />[cite]Citated text[/cite]<br /><strong>Images</strong><br />[img]http://example.org/me.png[/img]<br /><strong>Linking</strong><br />[url]http://example.org[/url] or [url=http://example.org]Example[/url]<br /><strong>Code</strong><br />[code]<br />var a = b + c;<br />[/code]</span>',
      'btn'  : 'Close'
    }).open();
  }
}

/* Group
-------------------------------------------------------------------------- */

var ViewGroup = {

  editInlay: {

    guid: 'group-edit',
    url: '/shared/fetch/group/edit/edit.html',
    doScrollToTop: function() { return false; }
  }
}


/* Mailbox
-------------------------------------------------------------------------- */

var ViewMailbox = {
  mailboxInlay: {

    guid: 'mailbox-mailbox',
    url: '/shared/fetch/mailbox/mailbox/mailbox.html',
    width:'650px',
    doScrollToTop: function() { return true; },

    onopen: function() {
      $('#mailbox-href img').get(0).src = '/shared/img/mailbox_small_off.gif'; // unreadMessages = 0
    }
  },
  
  messageInlay: {
    guid: 'mailbox-message',
    url: '/shared/fetch/mailbox/message/message.html',
    doScrollToTop: function() { return false; },
    
    onbeforeclose: function() {
      var text = $('#message-text');
      
      if (text.val() !== '') {
        return confirm('Your message will be lost! Please confirm.');
      }
      return true;
    }
  }
}


/* Report
-------------------------------------------------------------------------- */

var ViewReport = {

  reportInlay: {

    guid: 'report-report',
    url: '/shared/fetch/report/report/report.html',
    doScrollToTop: function() { return false; },

    onclose: function() {
    }
  }
}


/* Subscription
-------------------------------------------------------------------------- */

var ViewSubscription = {
  drawSubscriptionLink: function() {
    if (!global.accountId) {
      $('#subunsub').html('Subscribe');
      return ;
    }

    ApiSubscription.refresh();
  }
}


/* Tagging
-------------------------------------------------------------------------- */

var ViewTagging = {

  selectorInlay: {

    guid: 'tagging-selector',
    url: '/shared/fetch/tagging/selector/selector.html',
    maxWidth: '300px',
    doScrollToTop: function() { return false; }
  }
}

