<h1>[%l('TERMS ADD NEW')%]</h1>

<form action="terms/add" method="POST" name="new_terms">
<table>
  <tr>
    <td colspan="2">
      <textarea name="new_site_terms" id="new_site_terms" cols="60" rows="20" class="input_text" /></textarea>
    </td>
  </tr>

  <tr>
    <td colspan="2" style="text-align: center;">
      <input type="button" value="[%l('Preview')%]"        name="post_reply" class="input_button" id="message_preview" />
      <input type="submit" value="[%l('Post New Terms')%]" name="post_reply" class="input_button" />
    </td>
  </tr>
</table>


<style type="text/css">
	.yui-overlay { position:absolute;background:transparent;border:none;padding:none;margin:none; }
</style>

<!-- message preview majick -->
<script type="text/javascript">
    (function () {
        ParleyMessagePreview = function() {
            var Dom         = YAHOO.util.Dom,
                YU          = YAHOO.util;

            this.config = {
                trigger     : 'message_preview',
                user_input  : 'new_site_terms',
                container   : 'message_container',
                trigger_evt : 'click'
            };
            this.message_source  = false;
            this.message_preview = false;

            this.handleSuccess = function(o) {
                var data = eval('(' + o.responseText + ')');
                var obj = o.argument.obj;

                if (data.formatted) {
                    obj.previewElId = YU.Dom.generateId();

                    obj.user_input.style.visibility     = 'hidden';

                    /* create a panel to show the preview in */
                    var pWidth          = obj.user_input.clientWidth,
                        pHeight         = obj.user_input.clientHeight,
                        pLeft           = obj.user_input.offsetLeft,
                        pTop            = obj.user_input.offsetTop;

                    obj.preview_overlay = new YAHOO.widget.Overlay(
                        "preview_overlay",
                        {
                            context:        [obj.config.user_input, 'tl', 'tl'],
                            visible:        true,
                            width:          obj.user_input.clientWidth  + 'px',
                            height:         obj.user_input.clientHeight + 'px'
                        }
                    );

                    obj.preview_overlay.setBody(data.formatted);
                    obj.preview_overlay.render(document.body);
                    Dom.get('preview_overlay').style.overflow = 'auto';


                    // update the button
                    obj.trigger.value = '[%l('Edit')%]';

                    YU.Event.removeListener( obj.trigger, 'click' );
                    YU.Event.addListener(
                        obj.trigger,
                        obj.config.trigger_evt,
                        obj.edit,
                        obj,
                        true
                    );

                }
            };
            this.handleFailure = function(o) {
            };

            this.edit = function() {
                // update the button
                this.trigger.value = '[%l('Preview')%]';

                this.user_input.style.visibility     = 'visible';
                this.preview_overlay.destroy();

                YU.Event.removeListener( this.trigger, 'click' );
                YU.Event.addListener(
                    this.trigger,
                    this.config.trigger_evt,
                    this.preview,
                    this,
                    true
                );
            };

            this.preview = function() {
                var request = YU.Connect.asyncRequest(
                    'POST',
                    // '/forumcode/preview',
                    "[%c.uri_for('/forumcode/preview')%]",
                    {
                        success: this.handleSuccess,
                        failure: this.handleFailure,
                        argument: {
                            obj: this
                        }
                    },
                    'msg_source=' + escape(this.user_input.value)
                );
            };

            this.init = function() {
                this.container  = Dom.get( this.config.container );
                this.user_input = Dom.get( this.config.user_input );
                this.trigger    = Dom.get( this.config.trigger );

                YU.Event.addListener(
                    this.trigger,
                    this.config.trigger_evt,
                    this.preview,
                    this,
                    true
                );
            };
        };
    })();

    var MessagePreview = new ParleyMessagePreview();
    MessagePreview.init();
</script>
<!-- (end) message preview majick -->
