/**
 * QLIB 1.0 Text Label
 * Copyright (C) 2002 2003, Quazzle.com Serge Dolgov
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * http://qlib.quazzle.com
 */

function QLabel_set_ie(value, nomClass)
{
    //QLabel_set_dom2(value, nomClass)
    
    //alert ("value=" + value + "\n"
    //      +"nomClass=" + nomClass + "\n"
    //      +"id=" + this.id + "\n"
    //      +"label=" + this.label + "\n"
    //      +"null=" + (this.label==null) + "\n"
    //      +"name=" + this.label.name);
    
    this.label.innerText = (this.value = value) || "\xA0";
    //this.label.innerHTML = (this.value = value) || "\xA0";
    
    //this.value = value;
    ////this.label.innerText = value;
    //this.label.innerHTML = value;
    if (nomClass != null && nomClass != '' && typeof(nomClass) != 'undefined')
    	this.label.className = nomClass;
}

function QLabel_set_dom2(value, nomClass)
{
    with (this.label)
    {
    	// On supprime tous les nodes enfants pour les recréer
        if (hasChildNodes && removeChild)
        {
			while (hasChildNodes())
			{
				removeChild(firstChild);
			}
		}
        appendChild(this.document.createTextNode((this.value = value) || "\xA0"));
        if (nomClass != null && nomClass != '' && typeof(nomClass) != 'undefined')
        	className = nomClass;
    }
}

function QLabel_set_ns4(value, nomClass)
{
    this.value = value || "";
    if (nomClass == null || nomClass == '' || typeof(nomClass) == 'undefined')
    	nomClass = 'qLabel';
    	
    with (this)
    {
        document.open();
        document.write('<div class="' + nomClass +'">' + (clickable ? '<a href="#" title="' + tooltip + '" onClick="return ' +
            name + '.doEvent()" onMouseOut="window.top.status=\'\'" onMouseOver="window.top.status=' + name +
            '.tooltip;return true">' + value + '</a>' : value) + '</div>');
        document.close();
    }
}

function QLabel_doEvent()
{
    this.onClick(this.value, this.tag);
    return false;
}

function QLabel(parent, name, value, clickable, tooltip, nomClass)
{
    this.init(parent, name);
    this.value = value || "";
    this.clickable = clickable || false;
    this.tooltip = tooltip || "";
    this.doEvent = QLabel_doEvent;
    this.onClick = QControl.event;
    if (nomClass == null || nomClass == '' || typeof(nomClass) == 'undefined')
    	nomClass = 'qLabel';
    	
    with (this)
    {
        if (document.getElementById || document.all)
        {
            document.write (clickable ? '<div class="'+nomClass+'" unselectable="on"><a href="#" title="' +
                tooltip + '" onClick="return ' + name + '.doEvent()" onMouseOver="window.top.status=' + name +
                '.tooltip;return true" onMouseOut="window.top.status=\'\'" hidefocus="true" unselectable="on">' +
                '<span  id="' + this.id + '">' + (value || '&nbsp;') + '</span></a></div>' :
                '<div id="' + this.id + '" class="'+nomClass+'" unselectable="on">' +
                (value || '&nbsp;') + '</div>');
            this.label = document.getElementById ? document.getElementById(this.id) :
                (document.all.item ? document.all.item(id) : document.all[this.id]);
            this.set = (label && (label.innerText ? QLabel_set_ie :
                (label.replaceChild && QLabel_set_dom2))) || QControl.nop;
        }
        else if (document.layers)
        {
            var suffix = "";
            for (var j=value.length; j<QLabel.TEXTQUOTA; j++) suffix += " &nbsp;";
            document.write('<div><ilayer id="i' + this.id + '"><layer id="' + this.id + '"><div class="'+nomClass+'">' +
                (clickable ? '<a href="#" title="' + tooltip + '" onClick="return ' + name +
                '.doEvent()" onMouseOver="window.top.status=' + name +
                '.tooltip;return true" onMouseOut="window.top.status=\'\'">' + value + suffix + '</a>' :
                value + suffix) + '</div></layer></ilayer></div>');
            this.label = (this.label = document.layers["i" + this.id]) && label.document.layers[this.id];
            this.document = label && label.document;
            this.set = (label && document) ? QLabel_set_ns4 : QControl.nop;
        }
        else
        {
            document.write("Object non support&eacute;");
        }
    }
}
QLabel.prototype = new QControl();
QLabel.TEXTQUOTA = 50;
