function display(){}
display.smiles=[
    ['23.gif',':-)',[/((:|=)[-]?|-)\)/gi]],
    ['24.gif',':-(',[/(:|=)[-]?\(/gi]],
    ['10.gif','',[/(\>|&gt;)\:\)/gi]],
    ['09.gif',':((',[/\:\(\(/gi]],
    ['01.gif','(a)',[/\(a\)/gi]],
    ['02.gif','(banghead)',[/\(banghead\)/gi]],
    ['03.gif','($)',[/\(\$\)/gi]],
    ['04.gif','(U)',[/\(U\)/gi]],
    ['06.gif','(^)',[/\(\^\)/gi]],
    ['07.gif','(CENSORED)',[/\(CENSORED\)/gi]],
    ['08.gif',':-s',[/\:\-s/gi]],
    ['11.gif','(diabolo)',[/\(diabolo\)/gi]],
    ['12.gif',':$',[/\:\$/gi]],
    ['13.gif','(!)',[/\(\!\)/gi]],
    ['14.gif','(fried)',[/\(fried\)/gi]],
    ['15.gif','(L)',[/\(l\)/gi]],
    ['16.gif','(hi)',[/\(hi\)/gi]],
    ['17.gif','(k)',[/\(k\)/gi]],
    ['18.gif','(lol)',[/(\(lol\)|(:|=)[-]?\)\))/gi]],
    ['19.gif','(loser)',[/\(loser\)/gi]],
    ['20.gif','(ok)',[/\(ok\)/gi]],
    ['21.gif',':o',[/\:o/gi]],
    ['22.gif','(oops)',[/\(oops\)/gi]],
    ['25.gif','(scared)',[/\(scared\)/gi]],
    ['26.gif','B-)',[/b\-\)/gi]],
    ['27.gif','(silence)',[/\(silence\)/gi]],
    ['28.gif','(sleeping)',[/\(sleeping\)/gi]],
    ['29.gif','(squeezed)',[/\(squeezed\)/gi]],
    ['30.gif',':D',[/\:d/gi]],
    ['31.gif','(thanks)',[/\(thanks\)/gi]],
    ['32.gif',':P',[/\:p/gi]],
    ['33.gif','(uzi)',[/\(uzi\)/gi]],
    ['34.gif',':|',[/\:\|/gi]],
    ['35.gif','(rose)',[/\(rose\)/gi]],
    ['36.gif',';)',[/\;\)/gi]],
    ['37.gif',':-/',[/\:\-\//gi]],
    ['05.gif','I-)',[/I\-\)/gi]]
];

display.changeSmiles=function(element, path){
    var x,y,z,regs,tag;
    var content = element.innerHTML;

    for (var x=this.smiles.length-1; x >= 0; --x){
        tag = '@@@@SMILE' + x + '@@@@';
        regs = this.smiles[x][2];
        for (y=regs.length; --y>=0;){
            content = content.replace(regs[y], tag);
        }
    }
    for (x = 0; x < this.smiles.length; x++){
        z=this.smiles[x];
        regs = new RegExp('@@@@SMILE' + x + '@@@@', 'g');
        tag='<img title="' + z[1] + '" src="' + path + z[0] + '" />';
        content = content.replace(regs, tag);
    }

    element.innerHTML = content;
}

display.URL2Hyperlink = function(s, functionName){
    var prefix = (functionName != null ? '#" onclick="return ' + functionName + '(\'' : null);
    s = s.replace(/\0link\0([^\0]+)\0([^\0]+)\0([^\0]+)\0/g, '<a href="$1" target="$3">$2</a>');
    s = s.replace(/(^|[\n ])((http|https):\/\/([a-z0-9][a-z0-9\-\_]*\.([a-z0-9][a-z0-9\-\_]*\.)*[a-z0-9][a-z0-9\-]+)(:(\d+))?\/[^ ,\"\s<]*)/gi,
                  '$1 <a href="' + (prefix != null ? prefix + '$2\');' : '$2') + '">$2</a>');
    s = s.replace(/(^|[\n ])((http|https):\/\/([a-z0-9][a-z0-9\-\_]*\.([a-z0-9][a-z0-9\-\_]*\.)*[a-z0-9][a-z0-9\-]+)(:(\d+))?)[\s|\n]/gi, 
                  '$1 <a href="' + (prefix != null ? prefix + '$2\');' : '$2') + '">$2</a>');
    s = s.replace(/(^|[\n ])((www|www\-[a-z0-9]+)\.(([a-z0-9][a-z0-9\-\_]*\.)*[a-z0-9][a-z0-9\-]+)(:(\d+))?\/[^ ,\"\s<]*)/gi, 
                  '$1 <a href="' + (prefix != null ? prefix + 'http://$2\');' : 'http://$2') + '">$2</a> ');
    s = s.replace(/(^|[\n ])((www|www\-[a-z0-9]+)\.(([a-z0-9][a-z0-9\-\_]*\.)*[a-z0-9][a-z0-9\-]+)(:(\d+))?)[\s]/gi,
                  '$1 <a href="' + (prefix != null ? prefix + 'http://$2\');' : 'http://$2') + '">$2</a> ');
    s = s.replace(/(^|[\n ])([\w&\-_.]+?)@([a-z0-9][a-z0-9\-\_]+\.([a-z0-9][a-z0-9\-\_]*\.)*[a-z0-9][a-z0-9\-\_]*)/gi,
                  '$1<a href="mailto:$2@$3">$2@$3</a>');
    return s;
}

display.createElement = function(type, parent, properties, style){
    var r = null, x;

/*    if (document.createElementNS){
        r = document.createElementNS("http://www.w3.org/1999/html", type);
    } else {*/
        r = document.createElement(type);
//    }

    if (parent){
        parent.appendChild(r);
    }

    if (properties){
        for (x in properties){
            r[x] = properties[x];
        }
    }

    if (style){
        for (x in style){
            r.style[x] = style[x];
        }
    }
    return r;
}

display.generatePopupMenu = function(parent, menuHash){
    var div = this.createElement('div', parent, {},
                                    {position: 'absolute', top: '0px', left: '0px', visibility: 'hidden', zIndex: '+1', 
                                    border: '1px solid #f90', backgroundColor: '#fff', padding: '1px 1px 3px 3px'});
    div.id = menuHash['params']['name'];
    div.name = div.id;
    div.menuWidth = menuHash['params']['width'];
    div.menuHeight = menuHash['params']['height'];
    div.addX = menuHash['params']['addX'];
    div.addY = menuHash['params']['addY'];
    div.style.width = div.menuWidth + 'px';
    div.style.height = div.menuHeight + 'px';
        
    div.onmouseover = function(){
        display._mouseOverDiv = true;
    }

    div.onmouseout = function(){
        display._mouseOverDiv = false;
        setTimeout('display.hidePopupMenus()', 500);
    }

    var table = this.createElement('table', div, {}, {padding: '1px'});
    var tbody = this.createElement('tbody', table);
    var row = this.createElement('tr', tbody);
    this.createElement('td', row);

    for (i in menuHash){
        if (i == 'params') continue;
        this._createMenuItem(tbody,
                             menuHash[i]['imgIcon'],
                             menuHash[i]['label'],
                             menuHash[i]['callback']);
        if (menuHash[i]['submenu']){
            this.generatePopupMenu(parent, menuHash[i]['submenu']);
        }
    }
    return div;
}

display.hidePopupMenus = function(){
    var i, div;
    if (!this._mouseOverDiv){
        for (i in this._popupMenusVisible){
            div = document.getElementById(i);
            div.style.visibility = "hidden";
            this._popupMenusVisible[i] = null;
        }
    }
}

display._createMenuItem = function(body, icon, label, callback){
    
    var row = this.createElement('tr', body);
    var cell1 = this.createElement('td', row);
    if (icon)
        var img = this.createElement('img', cell1, {src: icon});
    var cell2 = this.createElement('td', row, {className:'smallnormal'});
    cell2.onmouseover = function(event){
        this.style.backgroundColor="#ffffd6";
        return false;
    }
    cell2.onmouseout = function(event){
        this.style.backgroundColor="#fff";
        return false;
    }
    var a = this.createElement('a', cell2, {href:'#', innerHTML: label});
    a.onclick=callback;
}

display._popupMenusVisible = {};
display._mouseOverDiv = false;

display.showPopupMenu = function(name, event){
    var div = document.getElementById(name);
    event || (event = window.event);
    var x = event.clientX;
    var y = event.clientY;
    var obj = event2Object(event);
    var x = objectPosXGet(obj);
    var y = objectPosYGet(obj);

    if (document.body.clientWidth &&
        document.body.clientWidth - x < div.menuWidth){
        x = x - div.menuWidth;
    } else {
        x = x + div.addX;
    }

    if (document.body.clientHeight &&
        document.body.clientHeight - y < div.menuHeight){
        y = y - div.menuHeight;
    } else {
        y = y + div.addY;
    }

    if (document.body.scrollLeft){
        x = x + document.body.scrollLeft;
    }

    if (document.body.scrollTop){
        y = y + document.body.scrollTop;
    }


    div.style.left = x + 'px';
    div.style.top = y + 'px';
    div.style.visibility = "visible";
    this._popupMenusVisible[name] = true;
    display._mouseOverDiv = false;
    setTimeout('display.hidePopupMenus()', 2000);
}

myFunction = function(){
    alert('aa');
}

var exampleMenu = {
    name: 'mnuOptions',
    width: 150,
    height: 100,
    a: {imgIcon: null,
        label: 'Emoticons list',
        callback: function(){ alert('emoticons'); }
       },
    b: {imgIcon: null,
        label: 'Font size',
        callback: function(){ alert('showFonts'); } /*,
        submenu: {
            name: 'mnuFonts',
            width: 100,
            height: 100,
            a: {imgIcon2: '/img/a.jpg',
                label: 'test',
                callback: myFunction},
            b: {imgIcon: '/img/a.jpg',
                label: 'test',
                callback: myFunction}
        }*/
       },
    c: {imgIcon: null,
        label: 'New Message Alert',
        callback: function(){ alert('new message alert');}
       }
};

