WWindow76.prototype = new WContainer76();
WWindow76.prototype.constructor = WWindow76;
WWindow76.superclass = WContainer76.prototype;  

function WWindow76()
{
    this.owner = null;
    this.level_gather_of_state = 0;
    this.is_link_state = false;
    this.url_to_images = '';
    
    this.linked_children = new Array();
}

WWindow76.prototype.windowResize = function()
{
    for(var i = 0; i < window.win_coll.length; i++)
    {
        var win = window.win_coll[i];
        if (win.bk2)
        {
            win.bk2.style.width = document.body.clientWidth;//-2;
            win.bk2.style.height = document.body.clientHeight;//-2;
        }
    }
}

WWindow76.prototype.init = function(ControlID, Prefix, controls_xml)
{
    WWindow76.superclass.init.call(this, ControlID, Prefix, controls_xml);
    
    this.posX = 0;
    this.posY = 0;
    
    this.header = document.getElementById(this.Prefix + '_h');
    this.bk2 = document.getElementById(this.Prefix + '_bk2');
    if (this.bk2)
    {
        this.bk2.style.width = 50;
        this.bk2.style.height = 50;
    }
    this.main_cont2 = document.getElementById(this.Prefix + '_main2');
    this.width = 0;
    this.height = 0;
    this.set_bk_size();
    this.is_close_callback = false;
    
    this.s_elem_to_hide = '';
    this.s_elem_to_show = '';
    this.s_parent_elem = '';
    
    this.elem_to_hide = null;
    this.elem_to_show = null;
    this.parent_elem = null;
    
    if (window.win_coll == null)
    {
        window.win_coll = new Array();
        window.win_coll.length = 0;
    }
    window.win_coll[window.win_coll.length] = this;
    
    this.set_z_index(window.win_coll.length - 1);
    
    window.onresize = this.windowResize;
}

WWindow76.prototype.test = function()
{
    if (this.bk2)
        return 'modal\n';
    else
        return 'unmodal\n';
}

WWindow76.prototype.get_elem_to_hide = function()
{
    if (!this.elem_to_hide && this.s_elem_to_hide != '')
        this.elem_to_hide = document.getElementById(this.s_elem_to_hide);
    return this.elem_to_hide;
}

WWindow76.prototype.get_elem_to_show = function()
{
    if (!this.elem_to_show && this.s_elem_to_show != '')
        this.elem_to_show = document.getElementById(this.s_elem_to_show);
    return this.elem_to_show;
}

WWindow76.prototype.get_parent_elem = function()
{
    if (!this.parent_elem && this.s_parent_elem != '')
        this.parent_elem = document.getElementById(this.s_parent_elem);
    return this.parent_elem;
}

WWindow76.prototype.set_z_index = function(index)
{
    this.z_index = index;
    var abs_idx = this.z_index * 4;
    
    this.main_cont.style.zIndex = abs_idx + 4; //(this.z_index + 1) * 2;
    if (this.main_cont2) this.main_cont2.style.zIndex = abs_idx + 3; //(this.z_index + 1) * 2;
    if (this.bk2) this.bk2.style.zIndex = abs_idx + 1;
}

WWindow76.prototype.set_to_top = function()
{
    for(var i = this.z_index + 1; i < window.win_coll.length; i++)
        window.win_coll[i - 1] = window.win_coll[i];
    window.win_coll[window.win_coll.length-1] = this;
    
    for(var i = 0; i < window.win_coll.length; i++)
    {
        var win = window.win_coll[i];
        win.set_z_index(i);
    }
}

WWindow76.prototype.dragStart = function(event)
{
    this.set_to_top();
    this.header.style.cursor = 'move';
    
    window.WWindow76_obj = this;

    if (document.attachEvent)
    {
        document.attachEvent('onmouseup',   this.dragStop); 
  	    document.attachEvent('onmousemove', this.dragMove);
    }
    else
    {
        document.addEventListener('mouseup',   this.dragStop, false);
  	    document.addEventListener('mousemove', this.dragMove, false);
    }          	    

    //this.posY = parseInt(event.y) - parseInt(this.main_cont.offsetTop); 
    //this.posX = parseInt(this.main_cont.offsetLeft) - parseInt(event.x);
    
    this.posY = parseInt(event.screenY) - parseInt(this.main_cont.offsetTop); 
    this.posX = parseInt(this.main_cont.offsetLeft) - parseInt(event.screenX);

    event.cancelBubble = true;
    event.returnValue = false;
}

WWindow76.prototype.dragMove = function(event)
{
    var win = window.WWindow76_obj;
    //win.main_cont.style.top = event.y - win.posY;
    //win.main_cont.style.left = event.x + win.posX;
    
    win.main_cont.style.top = event.screenY - win.posY;
    win.main_cont.style.left = event.screenX + win.posX;
    
    if (win.main_cont2)
    {
        win.main_cont2.style.top = win.main_cont.style.top;
        win.main_cont2.style.left = win.main_cont.style.left;
    }

    event.cancelBubble = true;
    event.returnValue = false;
}

WWindow76.prototype.dragStop = function(event)
{
    
    var win = window.WWindow76_obj;
    if (document.detachEvent)
    {
        document.detachEvent("onmousemove", win.dragMove);
        document.detachEvent("onmouseup",   win.dragStop);
    }
    else
    {        
        this.removeEventListener('mousemove', win.dragMove, false);
        this.removeEventListener('mouseup', win.dragStop, false);
    }
    win.header.style.cursor = 'pointer';
}

WWindow76.prototype.tug_visible = function()
{
    1;
    if (this.main_cont.style.display == 'block')
        this.set_visible('True', 1);
}

WWindow76.prototype.set_visible = function(visible, force)
{
    var dis = visible == 'True' ? 'block' : 'none';
    if (!force && this.main_cont.style.display == dis)
        return;
        
    this.main_cont.style.display = dis;
    if (this.main_cont2) this.main_cont2.style.display = dis;
    if (this.bk2) this.bk2.style.display = dis;
   
    this.prepare_context(visible);
    if (visible == 'True')
    {
        this.set_bk_size();
        
        this.set_to_top();
        if (this.bk2)
        {
            this.bk2.style.width = this.width-2;
            this.bk2.style.height = this.height-2;
        }
    }

    if (visible == 'True')
        this.set_by_center();
    else 
    {
        if (this.is_close_callback)
            this.CallServer(this.ControlID, '', 'Close', this, this.close_callback, this.close_callback, null, this.clear_context);
        else if (this.ControlID.indexOf('__message_box_id') < 0 && this.ControlID.indexOf('__content_box_id') < 0)
            this.clear_context();
    }
}

WWindow76.prototype.close_window = function()
{
    this.set_visible('False', false);
}

WWindow76.prototype.set_by_center = function()
{
    if (typeof(this.main_cont.style.pixelHeight) != 'undefined')
    {
        this.main_cont.style.top = (this.height -  this.main_cont.style.pixelHeight) / 2;
        this.main_cont.style.left = (this.width - this.main_cont.style.pixelWidth) / 2;
    }
    else
    {
        this.main_cont.style.top = (this.height -  this.main_cont.offsetHeight) / 2;
        this.main_cont.style.left = (this.width - this.main_cont.offsetWidth) / 2;
    }
    
    if (this.main_cont.style.posTop < 0) this.main_cont.style.top = 0;
    if (this.main_cont.style.posLeft < 0) this.main_cont.style.left = 0;
    
    if (this.main_cont2)
    {
        this.main_cont2.style.top = this.main_cont.style.top;
        this.main_cont2.style.left = this.main_cont.style.left;
    }

    this.windowResize();
}

WWindow76.prototype.clear_context = function()
{
	this.workarea.innerHTML = '';
}

WWindow76.prototype.close_callback = function(val, context)
{
    if (context.owner)
        context.owner.disable_child_containers('none');
}

WWindow76.prototype.prepare_context = function(visible)
{
    var e_h = this.get_elem_to_hide();
    var e_s = this.get_elem_to_show();
    var p_e = this.get_parent_elem();
    
    if (!p_e)
        p_e = theForm;
    
    if (visible == 'True')
    {
        if (e_h) e_h.style.display = 'none';
        if (e_s) e_s.style.display = 'block';
        if (p_e && this.main_cont.parentElement != p_e)
        {
            this.stored_parent = this.main_cont.parentElement;
            //this.stored_parent.removeChild(this.main_cont);
            
            if (this.bk2) p_e.appendChild(this.bk2);

            p_e.appendChild(this.main_cont);
            this.main_cont.style.top = 0;
            this.main_cont.style.left = 0;
            if (this.main_cont2) 
            {
                p_e.appendChild(this.main_cont2);
                this.main_cont2.style.top = 0;
                this.main_cont2.style.left = 0;
            }
            
           /* if (!this.sizing_flag)
            {
                if (this.main_cont.style.width.indexOf('%') != -1)
                {
                    this.main_cont.style.pixelWidth = document.body.clientWidth * this.main_cont.style.posWidth / 100;
                    if (this.main_cont2) this.main_cont2.style.pixelWidth = this.main_cont.style.pixelWidth;
                }
                if (this.main_cont.style.height.indexOf('%') != -1)
                {
                    this.main_cont.style.pixelHeight = document.body.clientHeight * this.main_cont.style.posHeight / 100;
                    if (this.main_cont2) this.main_cont2.style.pixelHeight = this.main_cont.style.pixelHeight;
                }
                this.sizing_flag = 1;
            }*/
        }
    }
    else
    {
        if (e_h) e_h.style.display = 'block';
        if (e_s) e_s.style.display = 'none';
        if (p_e && this.stored_parent)
        {
            if (this.bk2) this.stored_parent.appendChild(this.bk2);
            this.stored_parent.appendChild(this.main_cont);
            if (this.main_cont2) this.stored_parent.appendChild(this.main_cont2);
            this.stored_parent = null;
        }
    }
}

WWindow76.prototype.set_bk_size = function()
{
    AddLog('Begin set_bk_size');
    this.width = document.body.clientWidth;                         
    this.height = document.body.clientHeight;                       
    AddLog('End set_bk_size');
}

function Controls76_WWindow76_Builder(name, obj_id)
{
    this.name = name;
    
    try { this.obj = eval(obj_id); }
    catch (ex) { this.obj = null; }
    
    this.properties = new Array('IsUserVisible', 'Caption', 'Width', 'Height');
    
    this.get_prop = function(prop_name)
    {
        0;
        if (this.obj != null)
        {
            switch(prop_name)
            {
                case 'IsUserVisible':
                    return this.obj.main_cont.style.display == 'none' ? 'False' : 'True';
                case 'Caption':
                    if (this.obj.header.rows.length > 0)
                        return this.obj.header.rows[0].cells[1].innerText;
                    break;
                case 'Width':
                    return this.obj.main_cont.style.width;
                case 'Height':
                    return this.obj.main_cont.style.height;
            }
            return '';
        }
    }
    
    this.set_prop = function(prop_name, prop_value)
    {
        0;
        if (this.obj != null)
        {
            switch(prop_name)
            {
                case 'IsUserVisible':
                    var st = this.obj.is_close_callback;
                    this.obj.is_close_callback = false;
                    this.obj.set_visible(prop_value);
                    this.obj.is_close_callback = st;
                    break;
                case 'Caption':
                    if (this.obj.header.rows.length > 0)
                        this.obj.header.rows[0].cells[1].innerText = prop_value;
                    break;
                case 'Width':
                    this.obj.main_cont.style.width = prop_value;
                    if (this.obj.main_cont2) this.obj.main_cont2.style.width = prop_value;
                    this.obj.set_by_center();
                    break;
                case 'Height':
                    this.obj.main_cont.style.height = prop_value;
                    if (this.obj.main_cont2) this.obj.main_cont2.style.height = prop_value;
                    this.obj.set_by_center();
                    break;
            }
        }
    }
}
