function key_exists(array, id)
{
    if (array) {
        if (array.indexOf(id) != -1) {
            return true
        }
    }
    return false;
}

function empty(array, id)
{
    if (array && array != 'undefined') {
        if (id) {
            if (array[id] && array[id] != "undefined") {
                return false;
            } else {
                return true;
            }
        }
        return false;
    }
    return true;
}

function unset(array, Index)
{
	var output=[];
	for (var i in array) {
		if (i != Index) {
			output[i]=array[i];
		}
	}
	return output;
}

function getParentElement(elem, searchtag)
{
    elem = elem.parentNode;
    while (elem.tagName != searchtag) {
        if (!elem.parentNode)
            return false;
        elem = elem.parentNode;
    }
    return elem;
}

function setOpacity(obj, opacity)
{
  opacity = (opacity == 100)?99.999:opacity;
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

var myThis;

function callbackTimer()
{
    myThis.callbackTimer();
}

function getScrollXY()
{
    var scrOfX = 0, scrOfY = 0;
    if ( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}

function getPageSize()
{
    var myWidth = 0, myHeight = 0;
    if (typeof(window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
}

function FitToPage()
{
    //redim col_gauche
    var h = pageHeight - 100;
    document.getElementById('col_gauche').style.height = h + 'px';
    //redim content
    document.getElementById('content').style.height = h + 'px';
    document.getElementById('content').style.width = (pageWidth - 260 - 10) + 'px';
    //redim toolbox
    document.getElementById('toolbox').style.width = (pageWidth - 260 - 10) + 'px';
    //mask éventulle
    oMasksHandler.fitToPage();
}

function initMask2(str)
{
    oDialogBox.addMsg(str);
    /*if (str) {
        $('msg2').innerHTML = str+'<span class="old">'+$('msg2').innerHTML+'</span>';
    }
    var o = document.getElementById("msg2");
    if (o.innerHTML) {
        document.getElementById("msg2").style.display = 'block';
        clearTimeout(timerMask2);
        timerMask2 = setTimeout(callback_stopMask2, 10000);
    }*/
}

function callback_stopMask2()
{
    var o = document.getElementById("msg2");
    o.style.display = 'none';
    o.innerHTML = '';
}

function closeMask(id)
{
    oMasksHandler.close(id);
}

function filtreIwih(iwih)
{
    refreshProduits('', 1, 'iwih='+encodeURIComponent(iwih));
}

function activate(id)
{
    var o = $(id);
    if (o) {
        o.src = base_url+'images/remove.gif';
    }
}

function desactivate(id)
{
    var o = $(id);
    if (o) {
        o.src = base_url+'images/show.gif';
    }
}

function useFiltre(id)
{
    var i = document.getElementById('div_'+id);
    if (i) {
	    if (!i.style.height || i.style.height == '0px' || i.style.display == 'none') {
	        showFiltre(id);
	    } else {
	        hideFiltre(id);
	    }
    } else {
        alert('Désolé, une erreur est survenue');
    }
}

function showFiltre(id)
{
    var i = document.getElementById('div_'+id);
    //rescaleFiltre(id);
    if (!i.style.height || i.style.height == '0px' || i.style.display == 'none') {//alert(i.style.height);
        i.style.height = '0px';
        i.style.display = 'block';
        Effect.SlideDown('div_'+id, {scaleMode: 'content', restoreAfterFinish: false});
        if (document.getElementById('img_'+id)) {
        	if (document.getElementById('img_'+id).src.indexOf('fleche') != -1) {
        		document.getElementById('img_'+id).src = base_url+'images/fleche_bas.gif';
        	} else {
	            document.getElementById('img_'+id).src = base_url+'images/up.gif';
            }
        }
    } else {
        rescaleFiltre(id);
    }
}

function hideFiltre(id)
{
    var i = document.getElementById('div_'+id);
    if (!(!i.style.height || i.style.height == '0px' || i.style.display == 'none')) {
        Effect.SlideUp('div_'+id);
        if (document.getElementById('img_'+id)) {
        	if (document.getElementById('img_'+id).src.indexOf('fleche') != -1) {
        		document.getElementById('img_'+id).src = base_url+'images/fleche.gif';
        	} else {
	            document.getElementById('img_'+id).src = base_url+'images/down.gif';
            }
        }
    }
}

function rescaleFiltre(id)
{
    var i = document.getElementById('div_'+id);
    if (!(!i.style.height || i.style.height == '0px' || i.style.display == 'none')) {
        i.style.height = '0px';
        new Effect.Scale(i, 100, {scaleX: false, scaleMode: "contents"});
    }
}

function filtreType(id)
{
    refreshProduits('', 1, 'idtype='+encodeURIComponent(id));
}

function filtreAutreType(sig)
{
    refreshProduits('', 1, 'autretype='+encodeURIComponent(sig));
}

function affFiltreCaract(id)
{
    if (!$("div_caract_"+id).innerHTML) {
        $("div_caract_"+id).style.display = 'block';
        $("img_caract_"+id).src = base_url+'images/up.gif';
        ajax_updater("div_caract_"+id, 'aj_types/aj_caract/', 'idtype='+encodeURIComponent(id));
    } else {
        $("div_caract_"+id).style.display = 'none';
        $("img_caract_"+id).src = base_url+'images/down.gif';
        $("div_caract_"+id).innerHTML = "";
        rescaleFiltre('filtre_types');
        refreshProduits('', 1, 'resetcaract='+encodeURIComponent(id));
    }
}

function refreshFiltreCaract(id)
{
    if (id) {
        ajax_updater("div_caract_"+id, 'aj_types/aj_caract/', 'idtype='+encodeURIComponent(id));
    }
}

function filtreCaract(id, code)
{
    var o = $("filtre_champ_"+code);
    if (o) {
        var value = o.options[o.selectedIndex].value;
        refreshProduits('', 1, 'idtype='+encodeURIComponent(id)+'&codechamp='+encodeURIComponent(code)+'&codechampvalue='+encodeURIComponent(value));
    }
}

function initFiltreChamps()
{
    activate('img_filtre_img_0');
    activate('img_filtre_img_1');
    activate('img_filtre_url_1');
    activate('img_filtre_url_1');
}

function filtreChamp(champ, value)
{
    if (champ) {
        var data = 'champ='+encodeURIComponent(champ);
        if (value != '') {
            data += '&vchamp='+encodeURIComponent(value);
        }
        refreshProduits('', 1, data);
    }
}

function setFiltreChamp(champ, value)
{
    var c = document.getElementById('filtreChamp_'+champ);
    if (c) {
        c.value = value;
    }
}

function orderBy(order)
{
    refreshProduits('', 1, 'order='+encodeURIComponent(order));
}

function ascdesc(s)
{
    refreshProduits('', 1, 'ascdesc='+encodeURIComponent(s));
}

function affMask(id, url, data, w, h)
{
    if (!data) data = '';
    if (!w) w = 400;
    if (!h) h = 200;
    var m = oMasksHandler.add(id, w, h);
    m.setAjaxContent(url, data, 'post');
}

function submitMask(url)
{
    var data = concatFields();
    ajax_request(url, data, eval_request);
}

function concatFields(aFieldsIn)
{
    var data = '';
    if (!aFieldsIn && aFields) {
        aFieldsIn = aFields;
    }
    for (var i = 0 ; i < aFieldsIn.length ; i++) {
        o = document.getElementById(aFieldsIn[i]);
        if (o) {
            if (data) {
                data += "&";
            }
            if (o.tagName == 'SELECT' || o.tagName == 'select') {
                data += aFieldsIn[i]+'='+encodeURIComponent(o.options[o.selectedIndex].value);
            } else if ((o.tagName == 'INPUT' || o.tagName == 'input') && o.getAttribute('type') == 'checkbox') {
                if (o.checked) {
                    data += aFieldsIn[i]+'='+encodeURIComponent(o.value);
                }
            } else {
                data += aFieldsIn[i]+'='+encodeURIComponent(o.value);
            }
        }
    }
    return data;
}

function countCharMsg(o)
{
    var str = o.value;
    if (str.length > 300) {
        o.value = str.substr(0, 300);
    }
    document.getElementById("charCount").innerHTML = o.value.length;
}

/**
 * MaskHandler
 */
var MasksHandler = Class.create();

MasksHandler.prototype = {

    aMasks: new Array(),
    aMasksIndex: new Array(),
    crtMask: null,
    nbrMasks: 0,

    initialize: function() {},

    add: function(id, w, h, ligth) {
        if (this.aMasksIndex.indexOf(id) == -1) {
            this.aMasks[id] = new Mask(id, w, h, ligth);
            this.aMasksIndex.push(id);
            this.setCrt(id);
        }
        return this.aMasks[id];
    },

    remove: function(id) {
        if (this.aMasksIndex.indexOf(id) != -1) {
            this.aMasks = unset(this.aMasks, id);
            this.aMasksIndex = unset(this.aMasksIndex, this.aMasksIndex.indexOf(id));
            if (this.crtMask == id) {
                this.crtMask = null;
            }
        }
    },

    setClass: function(id, className) {
        if (this.aMasksIndex.indexOf(id) != -1) {
            this.aMasks[id].setClass(className);
        }
    },

    show: function(id) {
        if (id) {
            if (this.aMasksIndex.indexOf(id) != -1) {
                this.setCrt(id);
                this.aMasks[id].show();
            } else {
                alert('Une erreur est survenue (show : id inconnu ['+id+'])');
            }
        } else if (id = this.crtMask) {
            this.aMasks[id].show();
        }
    },

    showMsg: function(id) {
        if (id) {
            if (this.aMasksIndex.indexOf(id) != -1) {
                this.aMasks[id].showMsg();
            } else {
                alert('Une erreur est survenue (showMsg)');
            }
        } else if (id = this.crtMask) {
            this.aMasks[id].showMsg();
        }
    },

    setCrt: function(id) {
        if (this.aMasksIndex.indexOf(id) != -1) {
            this.crtMask = id;
        } else {
            alert('Une erreur est survenue (setCrt)');
        }
    },

    isId: function(id) {
        if (this.aMasksIndex.indexOf(id) != -1) {
            return true;
        } else {
            return false;
        }
    },

    close: function(id) {
        if (id) {
            if (this.aMasksIndex.indexOf(id) != -1) {
                this.aMasks[id].close();
                this.remove(id);
            } else {
                alert('Une erreur est survenue (close)');
            }
        } else {
            if (id = this.crtMask) {
                this.aMasks[id].close();
                this.remove(id);
            }
        }
    },

    fitToPage: function() {
        var aI = this.aMasksIndex;
        var l = aI.length;
        for (var i = 0 ; i < l ; i++) {
            this.aMasks[aI[i]].fitToPage();
        }
    },

    setDim: function (width, height, id) {
        if (id) {
            if (this.aMasksIndex.indexOf(id) != -1) {
                 this.aMasks[id].setDim(width, height);
            } else {
                alert('Une erreur est survenue (setDim : id inconnu ['+id+'])');
            }
        } else if (id = this.crtMask) {
            this.aMasks[id].setDim(width, height);
        }
        this.aMasks[id].fitToPage();
    },

    onScroll: function() {
        if (this.crtMask) {
            this.fitToPage();
        }
    },

    getCrt: function() {
        return this.crtMask;
    },

    setAjaxContent: function(id, url, data, methode) {
        if (this.aMasksIndex.indexOf(id) != -1) {
            this.setCrt(id);
            this.aMasks[id].setAjaxContent(url, data, methode);
        } else {
            alert('Une erreur est survenue (setAjaxContent)');
        }
    },

    setTitle: function(id, title) {
        if (this.aMasksIndex.indexOf(id) != -1) {
            this.aMasks[id].setTitle(title);
        } else {
            alert('Une erreur est survenue (setTitle)');
        }
    },

    setButtons: function(id, aButtons) {
        if (this.aMasksIndex.indexOf(id) != -1) {
            this.aMasks[id].setButtons(aButtons);
        } else {
            alert('Une erreur est survenue (setButtons)');
        }
    },

    setContent: function(id, content) {
        if (this.aMasksIndex.indexOf(id) != -1) {
            this.aMasks[id].setContent(content);
        } else {
            alert('Une erreur est survenue (setContent)');
        }
    },

    setMsg: function(id, aMsg) {
        if (this.aMasksIndex.indexOf(id) != -1) {
            this.aMasks[id].setMsg(aMsg);
        } else {
            alert('Une erreur est survenue (setMsg)');
        }
    },

    affMaskMsg: function(aMsg) {
        if (aMsg.length)  {
            var m = this.add('maskMsg', 500, 300);
            m.setTitle('Information');
            m.setContentMsg(aMsg);
        }
    }
}

/**
 * Mask */
var Mask = Class.create();

Mask.prototype = {

    id: '',
    light: false,
    dv: null,
    timer: null,
    width: null,
    height: null,
    minTop: 100,
    minLeft: null,

    initialize: function(id, w, h, light) {
        var dv;

        if (id) {
            this.id = id;
            if (light) {
                this.light = true;
            }

            this.dv = dv = document.createElement('div');
            dv.setAttribute('id', id);
            dv.className = "mask2";

            var html = "";

            if (!this.light) {
                html += '<div id="'+id+'_diag_container" class="diag_mask"><div id="'+id+'_msg" class="diag_mask_msg"></div></div>';
            }
            html += '<div id="'+id+'_content" class="content">';
            if (!this.light) {
                html += '<div id="'+id+'_title" class="title">';
                    html += '<div class="close_alert">';
                        html += '<a onclick="closeMask(\''+id+'\');"><img src="'+base_url+'images/close.gif" alt="close" border="0" /></a>';
                    html += '</div>';
                    html += '<div id="'+id+'_title_content"></div>';
                html += '</div>';
            }
                html += '<div id="'+id+'_form" class="form_content"></div>';
            if (!this.light) {
                html += '<div id="'+id+'_foot" class="foot"></div>';
            }
            html += '</div>';

            html += '<div id="'+id+'_transp" class="mask_transp"></div>';

            dv.innerHTML = html;
            dv.style.height = pageHeight + 'px';
            document.getElementsByTagName('body')[0].appendChild(dv);
            setOpacity(document.getElementById(id+'_transp'), 75);

            if (w && h) {
                this.setDim(w, h);
            }
        }
    },

    setClass: function(className) {
        this.dv.className = className;
        alert(this.dv.className);
    },

    getId: function() {
        return this.id;
    },

    show: function() {
        this.fitToPage();
        this.dv.style.display = 'block';
        document.getElementById(this.id+'_content').style.display = 'none';
        Effect.Appear(this.id+'_content');
        
    },

    close: function() {
        this.dv.style.display = 'none';
        this.dv.innerHTML = '';
        clearTimeout(this.timer);
        document.getElementsByTagName('body')[0].removeChild(this.dv);
    },

   showMsg: function() {
        document.getElementById(this.id+'_diag_container').style.display = 'block';
        clearTimeout(this.timer);
        myThis = this;
        this.timer = setTimeout(callbackTimer, 10000);
    },

    callbackTimer: function() {
        var o = document.getElementById(this.id+'_diag_container');
        o.style.display = 'none';
        document.getElementById(this.id+'_msg').innerHTML = '';
    },

    setDim: function(width, height, minLeft, minTop) {
        this.width = width;
        this.height = height;
        if (minLeft != null && minLeft != 'undefined')
            this.minLeft = minLeft;
        if (minTop != null && minTop != 'undefined')
            this.minTop = minTop;
    },

    fitToPage: function() {
        var d = document.getElementById(this.id+'_content');
        if (d) {
            var style = d.style;
            if (pageWidth && this.width) {
                style.marginLeft = style.marginRight = '0';

                var left = Math.abs((pageWidth - this.width)/2);
                if (left < this.minLeft)
                    left = this.minLeft;
                style.left = left + 'px';

                if (left + this.width > pageWidth)
                    style.width = (pageWidth - left - 10) + 'px';
                else
                    style.width = this.width + 'px';
            }
            if (pageHeight && this.height) {
                style.marginTop = style.marginBottom = '0';

                var top = (pageHeight - this.height)/2 + pageScroll[1];
                if (top < this.minTop) {
                    top = this.minTop;
                }
                style.top = top + 'px';

                var newHeight = 0;
                if (top + this.height > pageHeight + pageScroll[1])
                    newHeight = pageHeight - top - 10;
                else
                    newHeight = this.height;
                style.height = newHeight + 'px';

                //diag
                if (!this.light) {
                    var styledc = document.getElementById(this.id+'_diag_container').style;
                    styledc.marginTop = styledc.marginBottom = '0';
                    styledc.top = (top - 100) + 'px';
                }

                //mask_form
                var stylef = document.getElementById(this.id+'_form').style;
                if (!this.light) {
                    newHeight = newHeight - 25 - 29;
                }
                stylef.height = newHeight + 'px';

                //calque
                var m = document.getElementById(this.id);
                m.style.width = '100%';
                m.style.height = (pageHeight + pageScroll[1])+'px';
            }
        }
    },

    setAjaxContent: function(url, data, methode) {
        this.show();
        ajax_updater(this.id+'_form', url, data, methode);
    },

    setTitle: function(title) {
        document.getElementById(this.id+'_title_content').innerHTML = '<span class="first">'+title.substr(0, 1)+'</span>'+title.substr(1, title.length);
    },

    setButtons: function(aButtons) {
        if (aButtons.length) {
            var html = '<div class="petits_boutons"><table cellspacing="0"><tr><td><img src="'+base_url+'images/bouton_bord_gauche.gif" alt="" /></td>';
            for (var i = 0 ; i < aButtons.length ; i++) {
                html += '<td';
                if (aButtons[i].id) {
                    html += ' id="'+aButtons[i].id+'"';
                }
                if (aButtons[i].style) {
                    html += ' style="'+aButtons[i].style+'"';
                }
                html += '>';
                html += '<a ';
                if (aButtons[i].href) {
                    html += 'href="'+aButtons[i].href+'" ';
                }
                if (aButtons[i].onclick) {
                    html += 'onclick="'+aButtons[i].onclick+'" ';
                }
                if (aButtons[i].title) {
                    html += 'title="'+aButtons[i].title+'"'
                }
                html += '>'+aButtons[i].label+'</a></td>';
            }
            html += '<td><img src="'+base_url+'images/bouton_bord_droite.gif" alt="" /></td></tr></table></div>';
            document.getElementById(this.id+'_foot').innerHTML = html;
        }
    },

    setContent: function(content) {
        document.getElementById(this.id+'_form').innerHTML = content;
    },

    setMsg: function(aMsg) {
        if (aMsg.length) {
            var oMsg = document.getElementById(this.id+'_msg');
            if (oMsg.innerHTML) {
                oMsg.innerHTML = '<span class="old">'+oMsg.innerHTML+'</span>';
            }
            var str = '<ul>';
            for (var i = 0 ; i < aMsg.length ; i++) {
                str += '<li>'+aMsg[i]+'</li>';
            }
            str += '</ul>';
            oMsg.innerHTML = str + oMsg.innerHTML;
            this.showMsg();
        }
    },

    setContentMsg: function(aMsg) {
        if (aMsg.length) {
            var str = '<ul>';
            for (var i = 0 ; i < aMsg.length ; i++) {
                str += '<li>'+aMsg[i]+'</li>';
            }
            str += '</ul>';
            this.setContent(str);
            this.show();
        }
    }
};

function affNum(nbr, lib)
{
    $("toolbox_num").innerHTML = nbr+' '+lib+(nbr > 1 ? 's' : '');
}

function affPagi(nbr_lignes, nbr_pages, page, nbr_aff_pages)
{
    if (page) {
        crtPage = page;
    }
    if (!nbr_aff_pages) {
        nbr_aff_pages = 3;
    }
    var output = '';

    if (page > nbr_pages || page < 1) {
        page = 1;
    }
    //calcul du numÃ©ro de la premiÃ¨re page de l'Ã©cart. ex: 3 dans 1 ... 3 4 5 ... 7
    var page_deb = page - Math.floor(nbr_aff_pages / 2);
    if (page_deb > (nbr_pages - nbr_aff_pages + 1))
        page_deb = nbr_pages - nbr_aff_pages + 1;
    if (page_deb < 1)
        page_deb = 1;
    if (page > 1) {
        output += '<a onclick="refreshProduits(0,'+(page-1)+')"><img src="'+base_url+'images/gauche.gif" style="vertical-align: bottom;" border="0" alt="gauche" /></a>&nbsp;';
    }
    output += '<span class="pages">';
    //premiere page
    if (page_deb > 1) {
        output += '<a onclick="refreshProduits(0,1)">1</a>';
        output += page_deb - 1 > 1 ? ' ... ' : '&nbsp;';
    }
    //pages "centrales"
    for (var i = page_deb ; i < page_deb+nbr_aff_pages && i <= nbr_pages ; i++) {
        output += i == page ? '<span class="crt_page">'+i+'</span>' : '<a onclick="refreshProduits(0,'+i+')">'+i+'</a>';
        if (i + 1 < page_deb + nbr_aff_pages && i + 1 <= nbr_pages) {
            output += "&nbsp;";
        }
    }
    //derniÃ¨re page
    if (i <= nbr_pages) {
        output += i == nbr_pages ? "&nbsp;" : "&nbsp;...&nbsp;";
        output += '<a onclick="refreshProduits(0,'+nbr_pages+')">'+nbr_pages+'</a>';
    }
    output += '</span>';
    if (page < nbr_pages) {
        output += '&nbsp;<a onclick="refreshProduits(0,'+(page+1)+')"><img src="'+base_url+'images/droite.gif" style="vertical-align: bottom;" border="0" alt="droite" /></a>';
    }
    $("toolbox_pagi").innerHTML = output;
}

var DialogBox = {};
DialogBox = Class.create();

DialogBox.prototype = {
    h: 100,
    w: 400,
    m: 15,
    mainClass: 'dialog_box',
    tabClass: 'dialog_box_tab',
    varName: 'oDialogBox',
    
    dv: null,
    dvm: null,
    dvt: null,
    ul: null,
    top: 0,
    left: 0,
    state: 0,
    timer: null,
    
    initialize: function() {
        this.top = -2 - this.h;
        this.dv = document.createElement('div');
        this.dv.style.width = this.w+'px';
        this.dv.style.height = (this.h+this.m)+'px';
        this.dv.style.top = this.top+'px';
        this.dv.style.position = 'absolute';
        this.setPosition();
        
        this.dvm = document.createElement('div');
        this.dvm.id = "contentDialogBox";
        this.dvm.className = this.mainClass;
        this.dvm.style.overflow = 'auto';
        this.dvm.style.height = this.h+'px';
        this.dvm.innerHTML = '<div style="text-align: center;">Les informations s\'afficheront dans cette zone.';
        this.dv.appendChild(this.dvm);
        
        this.dvt = document.createElement('div');
        this.dvt.className = this.tabClass;
        this.dvt.style.height = this.m+'px';
        this.dvt.innerHTML = '<a onclick="'+this.varName+'.action();" style="display: block; width: 100%; height: '+this.m+'px;"></a>';
        this.dv.appendChild(this.dvt);
        
        document.getElementsByTagName('body')[0].appendChild(this.dv);
    },
    
    setPosition: function() {
        this.left = pageWidth / 2 - (this.w / 2);
        this.dv.style.left = this.left+'px';
    },
    
    action: function() {
        if (this.state) {
            this.up();
        } else {
            this.down(true);
        }
    },
    
    down: function(keep) {
        if (keep) {
            clearInterval(this.timer);
        }
        if (!this.state) {
	        new Effect.MoveBy(this.dv, -1, this.left, {mode: 'absolute'});
	        this.state = 1;
        }
        if (!keep) {
            My = this;
            clearInterval(this.timer);
            this.timer = setInterval("My.up(My)", 10000);
        }
    },
    
    up: function(My) {
        if (!My) {
            My = this;
        }
        if (My.state) {
	        new Effect.MoveBy(My.dv, My.top, this.left, {mode: 'absolute'});
	        My.state = 0;
        }
        clearInterval(My.timer);
    },
    
    addMsg: function(msg) {
        if (!this.ul) {
            this.dvm.innerHTML = '';
            this.ul = document.createElement('ul');
            this.dvm.appendChild(this.ul);
        }
        if (!this.dvm.getElementsByTagName('UL').length) {
            this.dvm.innerHTML = '';
            this.dvm.appendChild(this.ul);
        }
        if (msg instanceof Array) {
            for (var i = 0; i < msg.length; ++i) {
                this.addLi(msg[i]);
            }
        } else {
            this.addLi(msg);
        }
        this.down();
    },
    
    addLi: function(msg) {
        var li = document.createElement('li');
        var MaDate = new Date();
        li.innerHTML = MaDate.getHours()+":"+MaDate.getMinutes()+" - "+msg;
        this.ul.insertBefore(li, this.ul.firstChild);
        this.dvm.scrollTop = 0;
    },
    
    addContent: function(content) {
        this.dvm.innerHTML = content;
    },
    
    addAjaxContent: function(url, data) {
        ajax_updater(this.dvm.id, url, data, 'post', true);
        this.down(true);
    }
};