TT_MainPageForm = Class.create();
TT_MainPageForm.prototype = {
  	initialize: function(info) {
  		this.Info = info!=undefined ? info : {
  			'id'			:'',
  			'title'			:'',
        	'browsertitle'	:''
        },
        this.tt_buildGUI();
        this.tt_bindFunctions();
        this.tt_registerEvents();
  	},

    tt_bindFunctions: function () {
        this.tt_handleYesClick = this.tt_handleYesClick.bindAsEventListener(this);
        this.tt_handleNoClick  = this.tt_handleNoClick.bindAsEventListener(this);
    },

	tt_buildGUI: function () {
        var btnNo  = {id: 'no',  value : 'no'};
        var btnYes = {id: 'yes', value : 'yes', isDefault: true};
        this.dialog = new TT_Dialog (' Edit Uebersicht', '', [btnYes, btnNo], 500);
//        this.dialog.tt_textField('title', 'Title', this.Info['title']);
        this.dialog.tt_textField('browsertitle', 'Browser Title', this.Info['browsertitle']);
        this.dialog.onEsc = this.tt_handleNoClick.bind(this);
        this.dialog.onEnter = this.tt_handleYesClick.bind(this);     
    },

    tt_registerEvents: function () {
        Event.observe($('btnyes'), 'click', this.tt_handleYesClick, false);
        Event.observe($('btnno'), 'click', this.tt_handleNoClick, false);
    },
    
    tt_handleYesClick: function () {
        if ($('haendlers_menu'))  var hId = $('haendlers_menu').value;
        if ($('parent_menu')) var pId = $('parent_menu').value;
        pId = pId!='' ? pId : null;
        
        if (this.editor!=undefined) {
            var textContent = this.editor.getContent();
            textContent = textContent.stripScripts();
            textContent = textContent.gsub('<br>', TT_SYMBOL);
        } else {var textContent = ''}        

        var uebersichts = {
            'id'			: this.Info['id'],
//            'title'			: $('title').value,
			'browsertitle'	: $('browsertitle').value,            
        }
        this.dialog.tt_closeDialog();
        TT_Event.notify(this, 'ok', uebersichts);
    },
    
    tt_handleNoClick: function () {
        this.dialog.tt_closeDialog();
    }
}
