﻿// JScript File
//Uses yahoo-min for Event Handling
//Uses event-min for Event Handling
//Uses prototype for AJAX Requests Library
//Uses scroller	for Scrolling DIV
//Uses slider for Scrolling DIV
//Uses AJAXMessage to Include Messages
//Uses modal-message to Display Modal Messages
//Uses tooltip-v0.2	for Tooltips
//Uses Tooltip for Tooltips

var bHasScrollStyle = false;
var _vmiddle = 'middle';
var _vHeader = 'Header';
var _vFooter = 'Footer';
var _vTarget = 'target';
var _vContentArea = 'ContentArea';
var _vArea = 'Area';
var _vOuterContent = 'OuterContent';
var _vCMS_Menu = 'CMS_Menu';
var _vCMS_ListMenu = 'CMS_ListMenu';
var _vcontent = 'contentMenu';
var _vScroller = 'Scroller';
var _vCMS_ContentText = 'CMS_ContentText';
var _vStatusArea = "StatusArea";
var _vResizeArea = "ResizeArea";
var _iframeIEHack = "myIframe";
var _vPrint= "DivPrint";
var _vclassPrint= "print section";

var _id = null;
var _voptions = null;
var _voptionsFuncs =  null;
var _voptionsParams = null;
var _voptionsTips =  null;
var _vContentAreawidth = null;
var _vContentAreaheight = null;
var _vWithScroll = false;
var _vAJAXMessage = null;
var _vWindowIsOpen = false;
var _vDataFetchedSubscribed = false;

var _vMinContentAreawidth = '680px';
var _vMinContentAreaheight = '300px';

var tt_flagOpacity; // Opacity support: 1=IE, 2=Khtml, 3=KHTML, 4=Moz, 5=W3C
var tt_u = "undefined";

var fadeInOut = false; // EJR - 11/02/2009: variável que controla a existencia de fadeIn e fadeOut da modal


function get_OpaSupport()
{
	tt_body = (document.getElementsByTagName ? document.getElementsByTagName("body")[0]
				: (document.body || null));

	var css = tt_body.style;

	tt_flagOpacity = (typeof(css.filter) != tt_u) ? 1
				: (typeof(css.KhtmlOpacity) != tt_u) ? 2
				: (typeof(css.KHTMLOpacity) != tt_u) ? 3
				: (typeof(css.MozOpacity) != tt_u) ? 4
				: (typeof(css.opacity) != tt_u) ? 5
				: 0;
}

function OpenWindowNovidades(id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight, WithScroll, singleTon)
{ 
    if (typeof NovidadesWindow == 'undefined'  )
        {
            NovidadesWindow = new AJAXWindow (id,'' , '', '' , '', '' , '0px', '0px', "False", "False","True", "True");
            NovidadesWindow.SetLocalValues (id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight, WithScroll)
            NovidadesWindow.AJAXWindowinitOut();
        }
        else
            {
                if (NovidadesWindow.id == id)
                    {
                        NovidadesWindow.AJAXWindowinitOut();
                    }
                    else
                    {
                        NovidadesWindow = new AJAXWindow (id,'' , '', '' , '', '' , '0px', '0px', "False", "False","True", "True");
                        NovidadesWindow.SetLocalValues (id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight, WithScroll)
                        NovidadesWindow.AJAXWindowinitOut();
                    }                   
            }
}

function WindowNovidades(id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight, WithScroll, singleTon )
{   
    this.id = id;
    this.options = options;
    this.optionsFuncs = optionsFuncs;
    this.optionsParams = optionsParams;
    this.optionsTips = optionsTips;
    this.Type = Type;
    this.ContentAreawidth = ContentAreawidth;
    this.ContentAreaheight = ContentAreaheight;
    this.WithScroll = WithScroll;
    this.singleTon = singleTon;
}
 
WindowNovidades.prototype.OpenWindow = function (ConnectedWindow, readCond) 
{
    this.readCond = readCond;
    OpenWindowNovidades(this.id , this.options , this.optionsFuncs , this.optionsParams , this.optionsTips , this.Type , this.ContentAreawidth , this.ContentAreaheight , this.WithScroll , this.singleTon );
    if (typeof ConnectedWindow != 'undefined'  )
        {
            NovidadesWindow.InitEventClose(readCond);
            this.InitEvents(NovidadesWindow);
        }
}

WindowNovidades.prototype.InitEvents = function (objSubscribe) 
{
    objSubscribe.WindowClosed.subscribe(this.fnSubscriberonWindowClosed, this);      
}

WindowNovidades.prototype.fnSubscriberonWindowClosed = function(type, args, me) 
{   
    var read = args[0];
    var readCond = args[1];
    if (read)
        {
            document.getElementById(this.readCond).value = "1";
        }
}  

WindowNovidades.prototype.setUrl= function(url, IsRelative, Type, content) 
{
    var innerOptionsParams = this.optionsParams.split('~');
    var inneroptionsParams_0 = innerOptionsParams[0];
    var inneroptionsParams_2 = innerOptionsParams[2];
    inneroptionsParams_0 = url ;
    if (Type== "HTML")
        {
            inneroptionsParams_2 = inneroptionsParams_2 + "?HTML=" + content; 
        }
        else
        {
            if (IsRelative == "true")
                {
                    inneroptionsParams_2 = inneroptionsParams_2 + "?File=" + url;
                }
            else
                {
                    inneroptionsParams_2 = inneroptionsParams_2 + "?URL=" + url;
                }
        }
    this.optionsParams = inneroptionsParams_0 + "~" + innerOptionsParams[1] + "~" + inneroptionsParams_2 + "~" + innerOptionsParams[3] ;
}

WindowNovidades.prototype.setNewParam= function(id) 
{
    var innerOptionsParams = this.optionsParams.split('~');
    var inneroptionsParams_0 = innerOptionsParams[0];
    var inneroptionsParams_2 = innerOptionsParams[2];
    inneroptionsParams_0 = inneroptionsParams_0.replace("{ID}", id)         
    inneroptionsParams_2 = inneroptionsParams_2.replace("{ID}", id)         
    this.optionsParams = inneroptionsParams_0 + "~" + innerOptionsParams[1] + "~" + inneroptionsParams_2 + "~" + innerOptionsParams[3] ;
}

function AJAXWindowProps(id,options, optionsFuncs , optionsParams , optionsTips , ContentAreawidth, ContentAreaheight, WithScroll, singleTon , WithMessage, WithResize)
{
    this.id = id;
    this.ContentAreawidth = ContentAreawidth;
    this.ContentAreaheight = ContentAreaheight;
    this._vMinContentAreawidth = _vMinContentAreawidth;
    this._vMinContentAreaheight = _vMinContentAreaheight;
    this.options =  options; 
    this.optionsFuncs =  optionsFuncs; 
    this.optionsParams = optionsParams; 
    this.optionsTips = optionsTips;
    this.WithScroll = WithScroll;
    this.WithMessage = WithMessage;
    this.WithResize = WithResize;
    this.AJAXMessage = null;
    this.WindowIsOpen = false;
    this.DataFetchedSubscribed = false;
}

function AJAXWindow(id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight,  WithScroll, singleTon, WithMessage, WithResize)
{
    if (singleTon == "True")
        {
            if (typeof AJAXWindow._singleTon != 'undefined'  )
            {
                return AJAXWindow._singleTon
            }
            else
            {              
                this.SetGlobalValues(id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight,  WithScroll, WithMessage, WithResize);
                AJAXWindow._singleTon = this;
            }
        }
    else
        {
            this.SetGlobalValues(id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight,  WithScroll, WithMessage, WithResize);
        }
}

AJAXWindow.prototype.SetGlobalValues = function (id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight, WithScroll, WithMessage, WithResize)
{
    _vid = id;
    _vContentAreawidth = ContentAreawidth;
    _vContentAreaheight = ContentAreaheight;
    _voptions =  options; 
    _voptionsFuncs =  optionsFuncs; 
    _voptionsParams = optionsParams; 
    _voptionsTips = optionsTips; 
    _vWithScroll = WithScroll;
    _vWithMessage = WithMessage;
    _vWithResize = WithResize;
           
    this.SetLocalValues(id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight,  WithScroll, WithMessage, WithResize);
}

AJAXWindow.prototype.SetUniqueIds = function ()
{
    this.OuterContent = _vOuterContent ;   
    this.Header = _vHeader ;   
    this.CMS_ListMenu = _vCMS_ListMenu;
    this.Scroller = _vScroller + this.id;

    this.middle = _vmiddle + this.id;
    this.ContentArea = _vContentArea  + this.id;
    this.CMS_Menu = _vCMS_Menu  + this.id;
    this.content = _vcontent + this.id;
    this.Target = _vTarget + this.id;
    this.CMS_ContentText = _vCMS_ContentText + this.id;

    this.Footer = _vFooter ;
    this.StatusArea = _vStatusArea ;
    this.ResizeArea = _vResizeArea ; 
    this.Print = _vPrint ;   
    this.IframeIEHack = _iframeIEHack + this.id;
}

AJAXWindow.prototype.SetLocalValues = function (id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight,  WithScroll)
{
    this.id = id;
    this.ContentAreawidth = ContentAreawidth;
    this.ContentAreaheight = ContentAreaheight;
    this._vMinContentAreawidth = _vMinContentAreawidth;
    this._vMinContentAreaheight = _vMinContentAreaheight;
    this.options =  options; 
    this.optionsFuncs =  optionsFuncs; 
    this.optionsParams = optionsParams; 
    this.optionsTips = optionsTips;
    this.Type = Type;
    this.WithScroll = WithScroll;   
    this.WindowIsOpen = _vWindowIsOpen;
    this.DataFetchedSubscribed = _vDataFetchedSubscribed
    this.AJAXMessage = _vAJAXMessage;
    this.WithMessage = _vWithMessage;
    this.WithResize = _vWithResize;
}

AJAXWindow.prototype.CreateClone = function (id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight, WithScroll, WithMessage, WithResize)
{
    MyInnerWindowProps = new AJAXWindowProps(id,options, optionsFuncs , optionsParams , optionsTips , Type , ContentAreawidth, ContentAreaheight, WithScroll, WithMessage, WithResize);
}

AJAXWindow.prototype.AJAXWindowinit = function () 
{
    this.addLoadEvent(this.DefineWindow , this)	
}

AJAXWindow.prototype.AJAXWindowinitOut = function () 
{  
   if  (! this.WindowIsOpen)
    {
        this.newoptions = this.options.split('~');
        this.newoptionsFuncs = this.optionsFuncs.split('~');
        this.newoptionsParams = this.optionsParams.split('~');
        this.newoptionsTips = this.optionsTips.split('~');
        _voptions =  this.options; 
        _voptionsFuncs =  this.optionsFuncs; 
        _voptionsParams = this.optionsParams;
        this.SetUniqueIds();
        this.InitEvents();
        this.DefineWindow (this);
        this.fireMyPopup(this);

        this.WindowIsOpen = true;
    }
    else
    {
        AJAXModalMessageobj = new AJAXModalMessage('Por favor, feche primeiro a janela.',400,400,this, 'Atenção', 'Modal');	// We only create one object of this class
        AJAXModalMessageobj.displayStaticMessage();
    }
}

AJAXWindow.prototype.setDOMContent = function(content) 
{
    document.getElementById(this.content).appendChild (content); 
}

AJAXWindow.prototype.getDOMContent = function() 
{
    return document.getElementById(this.content).innerHTML; 
}

AJAXWindow.prototype.setContent = function(content) 
{
    document.getElementById(this.CMS_ContentText).innerHTML = content;
}

AJAXWindow.prototype.setOptions = function(options, optionsFuncs, optionsParams,optionsTips) 
{
    this.options = options;
    this.optionsFuncs = optionsFuncs;
    this.optionsParams = optionsParams;
    this.optionsTips = optionsTips;
}

AJAXWindow.prototype.PositionWindow = function() 
{
    if ((this.Type == "HTML") && (! (this._override == "True")))
        {
            this.overrideSize(GetcenterX() - 200 + 'px' , GetcenterY() - 200 + 'px');
        }
    else
        {
        }
}

AJAXWindow.prototype.overrideLeft = function(elem) 
{       
    var left =  - ((GetcenterX() - document.getElementById(this.ContentArea).style.width.split("px")[0]) / 2) + findPosX(document.getElementById(elem)) + 250 + 'px';
    var top =  findPosY(document.getElementById(elem)) + 100 + 'px';
    document.getElementById(this.middle).style.left = left;
    document.getElementById(this.middle).style.top = top;
}

AJAXWindow.prototype.overrideSize = function(width, height) 
{
    this._vMinContentAreawidth = width;
    this._vMinContentAreaheight = height;
    this._override="True";
}

//Run onload
AJAXWindow.prototype.addLoadEvent = function (func, outer ) 
{
    var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
	    window.onload = function() 
	    {
		    func(outer);
        }
    }
    else 
        {
            window.onload = function() {
		    oldonload();
		    func(outer);
        }
    }
}

AJAXWindow.prototype.InitEvents = function () 
{
    this.ResponseBack = new YAHOO.util.CustomEvent("ResponseBack", this); 
}

AJAXWindow.prototype.InitEventClose = function (readCond) 
{
    this.WindowClosed = new YAHOO.util.CustomEvent("WindowClosed", this); 
    this.readCond = readCond;
}

AJAXWindow.prototype.InitEventDataFetched = function () 
{
    this.DataFetched = new YAHOO.util.CustomEvent("DataFetched", this); 
    this.DataFetchedSubscribed = true;
}

AJAXWindow.prototype.InitWindowCloseEvents = function (objSubscribe) 
{
    objSubscribe.CloseModalWindow.subscribe(this.fnSubscriberonCloseModalWindow, this);      
}

AJAXWindow.prototype.fnSubscriberonCloseModalWindow = function(type, args, me) 
{   
    //me.ShowCompleteWindow();
}  

//Sets AJAXWindow attributes
AJAXWindow.prototype.DefineWindow = function (outer)
{    

    this.PositionWindow ();
    var iframecontent = null
    if (IsIE())
    {
        iframecontentnew = new AJAXDiv('iframehack',0,0);     
        iframecontent = iframecontentnew.CreateframeforIEHack(outer.IframeIEHack);
        document.body.appendChild (iframecontent);
        iframecontent.className = "iframeNoPrint";
    }

    var MyAJAXWindow = document.createElement('div');
    MyAJAXWindow.id = outer.id;
    MyAJAXWindow.className = 'print section noprint';
    document.body.appendChild (MyAJAXWindow);
   
    objMiddle = document.createElement('div');
    var objMiddle = document.createElement('div');
    objMiddle.id = this.middle;
    objMiddle.className = _vmiddle + "_ModalWindow";

    MyAJAXWindow.appendChild (objMiddle);

    var objContentAreanew = new AJAXDiv(this.ContentArea ,  this._vMinContentAreawidth , this._vMinContentAreaheight );
    objContentArea = objContentAreanew.CreateContentArea(); 
    objMiddle.appendChild (objContentArea);
    
    var objOuterContent = document.createElement('div');
    objOuterContent.id = this.OuterContent;
    objContentArea.appendChild (objOuterContent);
       
    var objCMS_Menunew = new AJAXDiv(this.CMS_Menu,0,0);
    objCMS_Menu = objCMS_Menunew.CreateCMS_Menu();
    objOuterContent.appendChild(objCMS_Menu);

    var objCMS_ListMenunew = new AJAXDiv(this.CMS_ListMenu ,0,0);
    objCMS_ListMenu = objCMS_ListMenunew.CreateCMS_ListMenu();
    objCMS_Menu.appendChild(objCMS_ListMenu);

    objCMS_Menunew.DefineEventsforMove(objMiddle , objCMS_Menu , outer, iframecontent);

	var elementsArrayLength = outer.newoptions.length;

    var id = this.id;

    for (i=1; i < elementsArrayLength; i++) 
    {
        var linew = new AJAXDiv(outer.newoptions[i],0,0);
        li = linew.CreateCMS_ListMenuItem();       
	    objCMS_ListMenu.appendChild(li);
	    
        var anew = new AJAXDiva('a' + id + outer.newoptions[i],0,0 , outer.newoptions[i]);     
	    a = anew.CreateCMS_ListMenuItema();
        if (i==0)
	    {
	        anew.ListMenuItemaSetSelected(a);
	    }

        a.href = "#";
        if ((outer.newoptionsFuncs[i] == "Save") )
            {
                a.href = this.newoptionsParams[0];
                if (/WebKit/i.test(navigator.userAgent))
                {
                    a.onclick = (function(context , elem, clicked, func, param) 
	                   {
                            return function()
                                {
                                    if (event.button == 2)
                                        {
                                            context.SetSelected(id, "'" + "li" + "'","'" + "a" + "'", clicked);
                                        }
                                    else
                                        { 
                                            return false;
                                        }
                                }
                        })(anew , a, a.id, this.newoptionsParams[i], outer.newoptionsParams[0]);               
                }
                else
                {
                    a.onclick = (function(context , outer , func, param,  id, clicked) 
	                    {
                            return function()
                                { 
                                    context.SetSelected(id, "'" + "li" + "'","'" + "a" + "'", clicked);                               // top=5000: Abre escondida
                                    var newwindow = popitup(func , "MetaData", "height=1,width=1,status=no,toolbar=no,menubar=no,location=no,top=10000");
                                    return false;
                                }
                        })(anew , outer , outer.newoptionsParams[i], outer.newoptionsParams[0] ,  objCMS_ListMenu.id, a.id);               
                }               
            }
            else
            {                   
                a.onclick = (function(context , outer , func, param,  tip , id, clicked) 
	                {
                        return function()
                            { 
                                context.SetSelected(id, "'" + "li" + "'","'" + "a" + "'", clicked);
                                outer.CallFunction (func, param, tip , outer, clicked);
                            }
                    })(anew , outer , outer.newoptionsFuncs[i], outer.newoptionsParams[i] ,  outer.newoptionsTips[i] , objCMS_ListMenu.id, a.id);
            }
        a.appendChild(document.createTextNode(unescape(li.id)));
        li.appendChild(a);
    }
   
    var objHeader = document.createElement('div');
    objHeader.id = this.Header;
    objOuterContent.appendChild (objHeader);

    var objScrollernew = new AJAXDiv(this.Scroller,0,this._vMinContentAreaheight);     
	objScroller = objScrollernew.CreateScroller();
    objHeader.appendChild (objScroller);
    
    var objScrollAreanew = new AJAXDiv(this.Scroller,this._vMinContentAreawidth,this._vMinContentAreaheight);     
	objScrollArea = objScrollAreanew.CreateScrollArea();
    objScroller.appendChild (objScrollArea);

    var objScrollerAreanew = new AJAXDiv(this.Scroller ,this._vMinContentAreawidth,this._vMinContentAreaheight);     
	objScrollerArea = objScrollerAreanew.CreateScrollerArea();
    objScrollArea.appendChild (objScrollerArea);
    
    var objcontentnew = new AJAXDiv(this.content,0,this._vMinContentAreaheight);     
	objcontent = objcontentnew.Createcontent();

    objcontent.style.width = (this.ContentAreawidth.split("px")[0] - 30) + 'px'	;

    objScroller.appendChild(objcontent);

    if (this.Type == "HTML")
        {
            iobjcontentnew = new AJAXDiv(this.IframeIEHack + this.Type ,this._vMinContentAreawidth,this._vMinContentAreaheight);     
            iobjcontent = iobjcontentnew.CreateObjectforHTMLwIFrame(this.newoptionsParams[0] , this._vMinContentAreawidth , this._vMinContentAreaheight);           
            objcontent.appendChild(iobjcontent);
            this.returnedContent = iobjcontent;
        }

    var objCMS_ContentTextnew = new AJAXDiv(this.CMS_ContentText,0,this._vMinContentAreaheight);     
    objCMS_ContentText = objCMS_ContentTextnew.CreateContentText();
    objcontent.appendChild(objCMS_ContentText);

    var objFooter = document.createElement('div');
    objFooter.id = this.Footer;
    objHeader.appendChild (objFooter);
    
    var objCMS_StatusAreanew = new AJAXDiv(this.StatusArea,0,0);    
    objCMS_StatusArea = objCMS_StatusAreanew.CreateStatusArea();
    
    if (this.WithMessage == 'True')
        {
            MyAJAXMessage = this.SetMessage('AJAXMessage' + this.id);
            outer.AJAXMessage = 'AJAXMessage' + this.id;
            objCMS_StatusArea.appendChild(document.getElementById('AJAXMessage' + this.id));   
            MyAJAXMessage.InitEvents(outer);
        }
    objFooter.appendChild(objCMS_StatusArea);

    if (this.WithResize == "True")
        {
            this.ScrollControl = new ScrollControl(outer);
            var objCMS_ResizeAreanew = new AJAXDiv(this.ResizeArea,0,0);    
            objCMS_ResizeArea = objCMS_ResizeAreanew.CreateResizeArea(objContentArea, outer.ContentArea, outer.content, outer.id, outer.IframeIEHack , outer.IframeIEHack + outer.Type , outer.Type, outer.ScrollControl);
            objFooter.appendChild(objCMS_ResizeArea);
            objCMS_ResizeArea.onmousedown = objCMS_ResizeAreanew.setupdrag ;
        }
               
    document.getElementById(outer.CMS_ListMenu).href = "#";
    
    for (i=1; i < elementsArrayLength; i++) 
    {
	    if (outer.newoptionsTips[i] !=  "")
	        {
	            var anew = document.getElementById('a' + id + outer.newoptions[i]);
                var my_other_tooltip = new ToolTipT(anew.id, outer.newoptionsTips[i])
	        }
    }
}

//Adicionado em 23-01-2009 (RGA Alteração da Scroll da Iframe)        
function harmonizacaoScroll(iframe, outer) 
{
    var localIsPDF = false;
    //localIsPDF = (outer.optionsParams.toUpperCase().indexOf(".PDF") < outer.optionsParams.toUpperCase().indexOf("~~"));
    if ((outer.optionsParams.toUpperCase().indexOf(".PDF") > 0) &&
        (outer.optionsParams.toUpperCase().indexOf(".PDF") < outer.optionsParams.toUpperCase().indexOf("~~")))
        localIsPDF = true;
    if(document.getElementById("myIframe" + outer.id + "HTML"))
    //if (document.getElementById("myIframe" + outer.id + "HTML") && !(localIsPDF))
    {
      if (!localIsPDF)
      {
        if (document.getElementById("myIframe" + outer.id + "HTML").contentWindow.document.readyState != "complete")
        {
            setTimeout( function() { this.harmonizacaoScroll(this.returnedContent, outer)},500);
        }
        else
        {
            outer.ScrollControl = new ScrollControl(outer);
            outer.ScrollControl.DefineControl();
            document.getElementById("myIframe" + outer.id + "HTML").contentWindow.document.body.style.overflow = "hidden";
            document.getElementById("myIframe" + outer.id + "HTML").parentElement.style.width = "100%";
        }
      }
      else
      {
            outer.ScrollControl = new ScrollControl(outer);
            outer.ScrollControl.DefineControl();
            //document.getElementById("myIframe" + outer.id + "HTML").contentWindow.document.body.style.overflow = "hidden";
            document.getElementById("myIframe" + outer.id + "HTML").parentElement.style.width = "100%";
      }

    }

}
//fim de alteracao
_hSize = 0;

function harmonizacaoScrollOnLoad(iframe, outer) 
{
    if(document.getElementById("myIframe" + outer.id + "HTML"))
    {
        _newH = document.getElementById("myIframe" + outer.id + "HTML").contentWindow.document.body.scrollHeight; 
        
        if (_newH != _hSize)
        {
            _hSize = _newH;
            setTimeout( function() { this.harmonizacaoScrollOnLoad(this.returnedContent, outer)},500);
        }
        else // iguais
        {   
            _hSize = _newH;
            outer.ScrollControl = new ScrollControl(outer);
            outer.ScrollControl.DefineControl();

            //document.getElementById("myIframe" + outer.id + "HTML").contentWindow.document.body.style.overflow = "hidden";

            document.getElementById("myIframe" + outer.id + "HTML").style.overflow = "hidden";
            document.getElementById("contentMenu"+outer.id).style.width = "100%";
        }
    }

}


AJAXWindow.prototype.SetMessage = function (id) 
{
    var MyMessageProps = new AJAXMessageProps();
    var MyAJAXMessage = new AJAXMessage(id, MyMessageProps.ImgWait ,MyMessageProps.ImgOk, MyMessageProps.ImgNok, MyMessageProps.CSSImgWait , MyMessageProps.CSSImgOk , MyMessageProps.CSSImgNok , MyMessageProps.AJAXMessagePosImg, MyMessageProps.AJAXMessagePosMsg, MyMessageProps.Message, MyMessageProps.MessageOk ,MyMessageProps.MessageNOk , "False" , this, false);
    MyAJAXMessage.AJAXMessageinitOut();
    return MyAJAXMessage;
}

AJAXWindow.prototype.OverrideMessage = function (msg, img) 
{
    if (img == null)
        {
            this.ResponseBack.fire(msg,null);
        }
        else
            {
                if (img == "default")
                    {
                        this.ResponseBack.fire(msg,MyAJAXMessage.CSSImgOk);
                    }       
                else
                    {
                        this.ResponseBack.fire(msg,img);
                    }       
            }
}

// Prototype Window Functions
AJAXWindow.prototype.CallFunction  =  function    (func, param,  tip , outer, elem)
{
    switch (func)
        {
            case "Close_and_Notify": 
                { 
                    togglePrintIFrame("print");
                    outer.fadeOutMyPopup(outer);
                    this.WindowClosed.fire("True", this.readCond);  
//Adicionado em 17-12-2008 (RGA para retirar a DIV de impressão do documento)
                    if (printDIV != null)
                    {
                        document.body.removeChild(printDIV);
                    }
//fim de bloco adicionado
                    break;
                }
        
            case "Close": 
                { 
                    outer.fadeOutMyPopup(outer);
                    var printDIV = document.getElementById(this.Print)
//Adicionado em 17-12-2008 (RGA para retirar a DIV de impressão do documento)
                    if (printDIV != null)
                    {
                        document.body.removeChild(printDIV);
                    }
//fim de bloco adicionado
                    break;
                }
            case "Print": 
                { 
                    //Scroller.reset(outer.content) ;
                    if (this.Type == "HTML")
                        {
                            togglePrintDiv(this.content,  "print section print" , "print section noprint");
                            var objToPrint = window.frames[this.IframeIEHack + this.Type];
                            objToPrint.focus(); 
                            objToPrint.print(); 
                        }
                        else
                        {
                            if(!document.getElementById(this.Print))
                            {
                                var objDivPrintnew = new AJAXDiv(this.Print,0,0);     
                                objDivPrint = objDivPrintnew.CreateContentPrint();
                                document.body.appendChild(objDivPrint);
                            }
                            newContent = document.getElementById(this.CMS_ContentText).cloneNode(true);
                            newContent.id += "_PRINT";
                            var dest = document.getElementById(this.Print)
	                        nObj = dest.cloneNode(false);
	                        dest.parentNode.insertBefore(nObj,dest);
	                        dest.parentNode.removeChild(dest);
	                        newContent.style.top = '0px';
                            document.getElementById(this.Print).appendChild(newContent);

                            window.print();
                        }
                    break;
                }
            case "Save": 
                {  
                    if (this.Type == "Server")
                    {
                        this.saveHTML(this.content);
                    }
                    else
                    {
                        elem.href = "#";
                        window.open(param + "?File=" + this.newoptionsParams[0], null, "height=1,width=1,status=no,toolbar=no,menubar=no,location=no"); 
                        return false
                    }
                    break;
                }
            case "GetData": 
                { 
                    this.getData(param,outer);
                    break;
                }
            case "GetDataPOST": 
                { 
                    this.getDataPOST(param,outer);
                    break;
                }
            case "getDataHTML": 
                { 
                    this.getDataHTML(this, param);
                    break;
                }
            case "showDataHTML": 
                { 
                    this.showDataHTML(this, param);
                    break;
                }
            case "HTMLObject": 
                { 
                    break;
                }
            case "dummy":
                {
                    break;
                }
            }
}

AJAXWindow.prototype.saveHTML = function (elem)
{
    var tDiv = document.getElementById(elem);
    iobjcontentnew = new AJAXDiv(this.IframeIEHack + this.Type ,this._vMinContentAreawidth,this._vMinContentAreaheight);     
    iobjcontent = iobjcontentnew.CreateObjectforHTMLwIFrame(this.newoptionsParams[0] , this._vMinContentAreawidth , this._vMinContentAreaheight);           
    objcontent.appendChild(iobjcontent);
    var tFrame = iobjcontent;
    this.resizeIFrame();
    var doc = tFrame.contentDocument;
    if (doc == undefined || doc == null)
        doc = tFrame.contentWindow.document;
    doc.open();
    doc.write(tDiv.innerHTML);
    var newwindow = popitup(func + "?File=" + param, "MetaData", "height=1,width=1,status=no,toolbar=no,menubar=no,location=no,top=-500");
    doc.close();       
    iobjcontent.style.visibility="visible";
}

AJAXDiv.prototype.DefineEventsforMove = function (objMiddle , objCMS_Menu, outer , iframe)
{
    objCMS_Menu[_vTarget]   = objMiddle.id ;
    if (IsIE())
        {
            objCMS_Menu[_iframeIEHack]   = iframe.id ;
        }
    objCMS_Menu.onmousedown = popup_mousedown;
    
    if(window.addEventListener)
        { 
	        document.addEventListener('mousedown', popup_mousepos, false);
	        document.addEventListener('mousemove', popup_mousemove, false);
	        document.addEventListener('mouseup', popup_mouseup, false);
        } 
    else 
        {
	        document.attachEvent('onmousedown', popup_mousepos);
            document.attachEvent('onmousemove', popup_mousemove);
            document.attachEvent('onmouseup', popup_mouseup);
        }        
}

// Prototype Window Functions

function AJAXDiv(elem, Areawidth, Areaheight)
{
    this.elem = null;
    this.Areawidth = null;
    this.Areaheight = null;

    this.elem = elem;
    this.Areawidth = Areawidth;
    this.Areaheight = Areaheight;
}

AJAXDiv.prototype.CreateContentArea  = function () 
{
    var objContentArea = document.createElement('div');
    objContentArea.id= this.elem ;
    
    objContentArea.className = _vContentArea + "_ModalWindow";

    objContentArea.style.width = this.Areawidth ;

    objContentArea.style.marginLeft = (this.Areawidth.split("px")[0] / 2) * (-1) + 'px';
    objContentArea.style.top = ((this.Areaheight.split("px")[0] / 2) * (-1)) - 50 + 'px';
    return objContentArea;
}

AJAXDiv.prototype.CreateCMS_Menu  = function () 
{
    var objCMS_Menu = document.createElement('div');
    objCMS_Menu.id = this.elem;
    objCMS_Menu.className = _vCMS_Menu;
    return objCMS_Menu;
}

AJAXDiv.prototype.CreateCMS_ListMenu  = function () 
{
    var objCMS_ListMenu = document.createElement('ul');
    objCMS_ListMenu.id = this.elem;
    return objCMS_ListMenu;
}

AJAXDiv.prototype.CreateCMS_ListMenuItem  = function () 
{
    var li = document.createElement('li');
    li.id = this.elem;
    return li;
}

AJAXDiv.prototype.CreateScrollArea  = function () 
{
    var scrollAreaWW = document.createElement('div');
    scrollAreaWW.id = this.elem + "1";
    scrollAreaWW.style.height = this.Areaheight;
    scrollAreaWW.style.left = parseFloat(this.Areawidth.split('px')[0]) - 20 + 'px';
    scrollAreaWW.className = "scrollAreaWW" + "_ModalWindow";
    
    return scrollAreaWW;
}

AJAXDiv.prototype.CreateScrollerArea  = function () 
{
    var scrollerWW = document.createElement('div');
    scrollerWW.id = this.elem + "2";
    scrollerWW.className = "scrollerWW" + "_ModalWindow";
    return scrollerWW;
}

AJAXDiv.prototype.CreateScroller  = function () 
{
    var objScroller = document.createElement('div');
    objScroller.id = this.elem;
    objScroller.style.height = this.Areaheight;
    objScroller.className = "Scroller" + "_ModalWindow";

    return objScroller;   
}

AJAXDiv.prototype.Createcontent  = function () 
{
    var objcontent = document.createElement('div');
    objcontent.id = this.elem;
    objcontent.style.height = parseFloat(this.Areaheight.split('px')[0]) - 4 + 'px';

    objcontent.className = "makeScroll1_ModalWindow";

    objcontent.setAttribute('HasData', false);
    return objcontent;
}


function IsIE()
{
    return ( navigator.appName=="Microsoft Internet Explorer" );
}

AJAXDiv.prototype.CreateframeforIEHack  = function (id) 
{
    var iFrame = document.createElement("IFRAME");
    iFrame.setAttribute("src", "");
    iFrame.frameBorder="0";
    iFrame.id = id ;
    iFrame.style.position="absolute";
    iFrame.style.top = 0; 
    iFrame.style.left = 0;
    iFrame.style.width = "0px"; 
    iFrame.style.height = "0px"; 
    
    return iFrame;
}

AJAXDiv.prototype.CreateObjectforHTML = function (url, Areawidth , Areaheight) 
{
    var iObject = document.createElement("object");
    iObject.setAttribute("data",url);
    iObject.style.frameBorder = "0";
    iObject.scrolling="no";
    iObject.style.textAlign = 'justify';
    iObject.style.fontSize = 'x-small';
    iObject.type="text/html";
    iObject.style.overflow = "scroll";
    iObject.style.width = Areawidth ;
    iObject.style.height = Areaheight ;
    iObject.id = this.elem ;
    iObject.style.position="absolute";
    
    return iObject;
}

AJAXDiv.prototype.CreateObjectforHTMLwIFrame = function (url, Areawidth , Areaheight) 
{
    var iObject = document.createElement("iframe");
    iObject.id = this.elem ;
    iObject.name = this.elem ;
    iObject.setAttribute("src", '');
    iObject.style.frameBorder = "0";
    iObject.style.textAlign = 'justify';
    iObject.style.fontSize = 'x-small';
    iObject.type="text/html";
    iObject.style.width = Areawidth;
    iObject.style.height = Areaheight;
    iObject.style.position="absolute";
    
    return iObject;
}

AJAXDiv.prototype.setContentAreaStyle = function (id) 
{
    oContentArea = document.getElementById(id);
    if (! (bHasScrollStyle)) 
        {
            if ((oContentArea.body != null) && (oContentArea.body.scroll != null)) 
                {
                    bHasScrollStyle = true;                  
                    oContentArea.body.scroll = "auto";                  
                    oContentArea.body.style.scrollbarFaceColor = "#005A9C";                  
                    oContentArea.body.style.scrollbarArrowColor = "#005A9C";                  
                    oContentArea.body.style.scrollbarTrackColor = "#005A9C";                  
                    oContentArea.body.style.scrollbarShadowColor = "#005A9C";                  
                    oContentArea.body.style.scrollbarHighlightColor = "#005A9C";                  
                    oContentArea.body.style.scrollbar3dlightColor = "#005A9C";                  
                    oContentArea.body.style.scrollbarDarkshadowColor = "#005A9C";              
                    
                } 
            else 
                {
                    setTimeout("setContentAreaStyle();", 500);              
                }
        }
}

AJAXDiv.prototype.CreateContentText  = function () 
{
    var objContentText = document.createElement('div');
    objContentText.id = this.elem;
    objContentText.className = _vCMS_ContentText + "_ModalWindow";
    return objContentText;
}

AJAXDiv.prototype.CreateContentPrint  = function () 
{
    var objContentPrint = document.createElement('div');
    objContentPrint.id = this.elem;
    objContentPrint.className = _vclassPrint;
    return objContentPrint;
}

AJAXDiv.prototype.CreateStatusArea  = function () 
{
    var objStatusArea  = document.createElement('div');
    objStatusArea.id = this.elem;
    objStatusArea.className = "drag-statusarea"; 
    return objStatusArea;
}

AJAXDiv.prototype.CreateResizeArea  = function (outer, ContentArea, content, id, IFrame, IFrameType, Type , ScrollControl) 
{
    var objResizeArea  = document.createElement('div');
    objResizeArea.id = this.elem;
    objResizeArea.className = "drag-resizearea";  
    objResizeArea._parent = outer //same
    objResizeArea._ContentArea = ContentArea //same
    objResizeArea._IFrame = IFrame //same
    objResizeArea._IFrameType = IFrameType //same
    objResizeArea._Type = Type //same
    objResizeArea._content = content //same
    objResizeArea._id = id;
    objResizeArea._ScrollControl = ScrollControl //same
    /*objResizeArea.style.width = "100px"; 
    objResizeArea.style.height = "100px";
    objResizeArea.style.position = "relative";
    objResizeArea.style.right = "-90px";
    objResizeArea.style.border = "solid";
    */

    return objResizeArea;
}

function AJAXDiva(elem, Areawidth, Areaheight, func)
{
    this.elem = null;
    this.Areawidth = null;
    this.Areaheight = null;

    this.elem =  elem;
    this.Areawidth = Areawidth;
    this.Areaheight = Areaheight;
    this.func = func;
}

// Set Window TAB Options currently selected
AJAXDiva.prototype.SetSelected  = function  (elem, optionli, optiona, clicked)
{
    var li = document.getElementById(elem);
    li.setAttribute("class", "");
	li.setAttribute("className", "");
    var lis = document.getElementById(elem).getElementsByTagName("li");
    for (var i=0; i < lis.length; i++)
        {
        var as = document.getElementById(lis[i].id).getElementsByTagName("a");
        for (var j=0; j < as.length; j++)
            {
            if (as[j].id == clicked)
                {
                    as[j].setAttribute("class", "selected");
                    as[j].setAttribute("className", "selected");
                }
                else
                {
                    as[j].setAttribute("class", "");
                    as[j].setAttribute("className", "");
                }
            }
        }
}

AJAXDiva.prototype.CreateCMS_ListMenuItema  = function () 
{
    var a = document.createElement('a');
    a.id = this.elem;
    return a;
}

AJAXDiva.prototype.ListMenuItemaSetSelected  = function (elem) 
{
    elem.setAttribute("class", "selected");
	elem.setAttribute("className", "selected");
}

// Browser safe opacity handling function

function setOpacity( ContentArea , value ) 
{
    if(document.getElementById(ContentArea) != null)
    {
	    if(tt_flagOpacity == 1)
	    {
		    // Hack for bugs of IE:
		    // A DIV cannot be made visible in a single step if an opacity < 100
		    // has been applied while the DIV was hidden.
		    // Moreover, in IE6, applying an opacity < 100 has no effect if the
		    // concerned element has no layout (position, size, zoom, ...).
		    if(value < 100)
		    {
			    var bVis = document.getElementById(ContentArea).style.visibility != "hidden";
			    document.getElementById(ContentArea).style.zoom = "100%";
			    if(!bVis)
				    document.getElementById(ContentArea).style.visibility = "visible";
			    document.getElementById(ContentArea).style.filter = "alpha(opacity=" + (value * 10) + ")";
			    if(!bVis)
				    document.getElementById(ContentArea).style.visibility = "hidden";
		    }
		    else
			    document.getElementById(ContentArea).style.filter = "";
	    }
	    else
	    {
		    //value /= 100.0;
		    switch(tt_flagOpacity)
		    {
		    case 2:
			    document.getElementById(ContentArea).style.KhtmlOpacity = value / 10; break;
		    case 3:
			    document.getElementById(ContentArea).style.KHTMLOpacity = value / 10; break;
		    case 4:
			    document.getElementById(ContentArea).style.MozOpacity = value / 10; break;
		    case 5:
                document.getElementById(ContentArea).style.opacity = value / 10 ; break;
		    }
	    }
    }
}

AJAXWindow.prototype.fadeInMyPopup = function (ContentArea) 
{
    get_OpaSupport();
    var outer = this;
    setTimeout( function() { document.getElementById(ContentArea).style.display = "block"}, 10);
    setTimeout( function() { outer.resizeIFrame()}, 10);
    if (outer.Type == 'HTML')
        {
            setTimeout( function() { outer.resizeHTMLFrame(outer.IframeIEHack + outer.Type)}, 10);
        }
    var _ContentArea = ContentArea;
    for( var i = 0 ; i <= 100 && fadeInOut ; i++ )
        {
            setTimeout( 'setOpacity(' + "'" + _ContentArea + "'," + (i / 10) + ')' , 20 * i );
        }
    setTimeout( function() { outer.CallFunction(outer.newoptionsFuncs[0] , outer.newoptionsParams[0] , outer.newoptionsTips[0], outer, null)}, 2100);
}

function setHeightScroll( value , outer) 
{
    document.getElementById(_vHeader).style.height = value + 'px' ;
}

minimize = function (outer) 
{
    var j = document.getElementById(_vHeader).style.height.split("px")[0];
    for (i=0; i < 100; i++) 
    {
        setTimeout('setHeightScroll(' + (j - (10 * i)) + "," + outer.id + ')', 800 );
    }

}

AJAXWindow.prototype.fadeOutMyPopup = function (outer) 
{
    var _ContentArea = outer.ContentArea;
    if (document.getElementById(_ContentArea) != null)
        {
        if (IsIE())
        {   
            document.body.removeChild (document.getElementById(outer.IframeIEHack));
        }   
        var refPass = this;
        for( var i = 0 ; i <= 100 && fadeInOut ; i++ ) 
        {
            setTimeout( 'setOpacity(' + "'" + _ContentArea + "'," + (10 - i / 10) + ')' , 20 * i );
        }
        if( fadeInOut )
        {
            setTimeout('closeMyPopup(' + "'" + outer.id + "','" + outer.AJAXMessage + "','" + _ContentArea + "'" + ')', 2000 );
            setTimeout(function() {refPass.WindowIsOpen = false}, 2000);
        }
        else
        {
            closeMyPopup(outer.id, outer.AJAXMessage, _ContentArea);
            refPass.WindowIsOpen = false;
        }
    }
}

closeMyPopup = function (AJAXWindow , AJAXMessage , ContentArea) 
{
    document.getElementById(ContentArea).style.display = "none"
    var MyAJAXMessage  = document.getElementById(AJAXMessage);
    var MyAJAXWindow  = document.getElementById(AJAXWindow);
    MyAJAXMessage.parentNode.removeChild (MyAJAXMessage);
    MyAJAXWindow.parentNode.removeChild (MyAJAXWindow);
}


AJAXWindow.prototype.fireMyPopup  = function (outer) 
{
	//document.getElementById(outer.ContentArea).style.display = "block";
	this.fadeInMyPopup(outer.ContentArea, outer.IframeIEHack + outer.Type );
}

// Browser safe opacity handling function

// Browser move window

AJAXWindow.prototype.getData = function (param,outer)
{
    this.returnedCallback = 
     {
        success: function(o) 
        {
            outer.complete(o);
        },
        failure: function(o) 
        {
            outer.ShowCallBackError(o);
        }
    }
    //YAHOO.util.Connect.setDefaultPostHeader(false);
    //YAHOO.util.Connect.initHeader("Content-Type", "text/xml; charset=utf-8"); 

    this.getXML = YAHOO.util.Connect.asyncRequest("GET",param,this.returnedCallback); 
}

AJAXWindow.prototype.getDataPOST = function (param,outer)
{
    this.returnedCallback = 
     {
        success: function(o) 
        {
            outer.complete(o);
		    //YAHOO.util.Connect.resetFormState();
        },
        failure: function(o) 
        {
            outer.ShowCallBackError(o);
		    //YAHOO.util.Connect.resetFormState();
        }
    }

    this.getXML = YAHOO.util.Connect.asyncRequest("POST",param,this.returnedCallback); 
    
}

AJAXWindow.prototype.getDataHTML = function (outer , param)	
{
    if (document.getElementById(this.content) != null)
    {
        document.getElementById(this.content).setAttribute('HasData', true);
        this.returnedContent.setAttribute("src",this.newoptionsParams[0]);

        if (this.WithMessage == 'True')
            {
                this.ResponseBack.fire(MyAJAXMessage.MessageOk,MyAJAXMessage.CSSImgOk); 
                FadeMessage(this.AJAXMessage, "True", 1);
            }
            if(navigator.appName != "Netscape")
            {
                setTimeout( function() { this.harmonizacaoScroll(this.returnedContent, outer)},500);
            }
            else
            {//registar o onLoad
                if (!((outer.optionsParams.toUpperCase().indexOf(".PDF") > 0) &&
                    (outer.optionsParams.toUpperCase().indexOf(".PDF") < outer.optionsParams.toUpperCase().indexOf("~~"))))
                {                    
                    _hSize = 0;
                    document.getElementById("myIframe" + outer.id + "HTML").contentWindow.document.body.onload = harmonizacaoScrollOnLoad(this.returnedContent, outer);
                }
            }
    }
}

AJAXWindow.prototype.showDataHTML = function (outer , param)	
{
    document.getElementById(this.content).setAttribute('HasData', true);
    //document.getElementById(this.CMS_ContentText).style.display = "block";
    if (this.WithMessage == 'True')
        {
            this.ResponseBack.fire(MyAJAXMessage.MessageOk,MyAJAXMessage.CSSImgOk); 
        }
}
         
AJAXWindow.prototype.complete = function (response)	
{   
    if(document.getElementById(this.CMS_ContentText) != null)
    {
        if ((response.responseText.indexOf('<metadatalink>') >= 0) &&
           (response.responseText.indexOf('</metadatalink>') > 0))
        {
            // var pagelink = xmlDoc.getElementsByTagName("metadatalink")[0].childNodes[0].nodeValue;
            if (response.responseXML.getElementsByTagName("metadatalink")[0] == null)
                return;

            var pagelink = response.responseXML.getElementsByTagName("metadatalink")[0].childNodes[0].nodeValue;
            var newoptionsFuncs = "getDataHTML" + this.optionsFuncs.substring(this.optionsFuncs.indexOf("~"));
            var newoptionsParams = pagelink + "~~ServerSaveFile.aspx?FILE=" + pagelink + "~";

            OpenWindowNovidades(this.id + "new" , this.options , newoptionsFuncs , newoptionsParams , this.optionsTips , "HTML" , this.ContentAreawidth , this.ContentAreaheight , this.WithScroll , this.singleTon );
            
            this.fadeOutMyPopup(this);
            var printDIV = document.getElementById(this.Print)
            if (printDIV != null)
            {
                    document.body.removeChild(printDIV);
            }
            return;
        }
        document.getElementById(this.CMS_ContentText).innerHTML = response.responseText;
        this.ScrollControl.DefineControl();
        document.getElementById(this.content).setAttribute('HasData', true);
        if (this.WithMessage == 'True')
            {
                this.ResponseBack.fire(MyAJAXMessage.MessageOk,MyAJAXMessage.CSSImgOk); 
                FadeMessage(this.AJAXMessage, "True", 1); 
            }
        var innerContent = this.content;
        var CMS_ContentText = this.CMS_ContentText; 
        var outer = this;
        //setTimeout( function() { Scroller.reset(innerContent)}, 100);
        if (this.DataFetchedSubscribed == true)
            {
                this.DataFetched.fire(1);
            }
        //setTimeout( function() { outer.ShowCompleteWindow()}, 100);
    }
}

AJAXWindow.prototype.completeFile= function (response)	
{   
    //window.open("ServerSaveFile.aspx?File=Metadataitens/Help_PT.pdf")
}

AJAXWindow.prototype.resizeIFrame = function ()	
{   
    if (IsIE())
        {
            document.getElementById(this.IframeIEHack).style.top = findPosY(document.getElementById(this.ContentArea)) + 'px';
            document.getElementById(this.IframeIEHack).style.left = findPosX(document.getElementById(this.ContentArea))  + 'px';
            document.getElementById(this.IframeIEHack).style.width = document.getElementById(this.ContentArea).style.width; 
            document.getElementById(this.IframeIEHack).style.height = findPosY(document.getElementById(this.Footer)) - findPosY(document.getElementById(this.ContentArea)) + 35 + 'px';
        }
}

AJAXWindow.prototype.resizeHTMLFrame = function (iframe)	
{   
    document.getElementById(iframe).style.width = document.getElementById(this.ContentArea).style.width.split('px')[0] - 25 + 'px'; 
    document.getElementById(iframe).style.border="0px";
    //document.getElementById(iframe).style.top="100px";
    //document.getElementById(iframe).style.height = document.getElementById(this.ContentArea).style.height.split('px')[0] - 125 + 'px'; 
}

AJAXWindow.prototype.ShowCompleteWindow = function ()	
    {   
        var currentwidth = parseFloat(this._vMinContentAreawidth.split('px')[0]);
        var currentheight = parseFloat(this._vMinContentAreaheight.split('px')[0]);
        var Lastwidth = parseFloat(this.ContentAreawidth.split('px')[0]);
        var Lastheight = parseFloat(this.ContentAreaheight.split('px')[0]);
        var leftOffset = GetscrolledX() + (GetcenterX() - Lastwidth ) / 2 ;
        var topOffset = GetscrolledY() + (GetcenterY() - Lastheight ) / 2;
        var currenleftOffset = GetscrolledX() + (GetcenterX() - currentwidth ) / 2 ;
        var currentopOffset = GetscrolledY() + (GetcenterY() - currentheight ) / 2;
        var d = document.getElementById(this.middle);
        d.style.left = "0px";
        for (i= 0; i < ((Lastwidth-currentwidth) / 2) ; i++) 
        {
            setTimeout('SetScrollWidth  (document.getElementById(' + "'" + this.ContentArea + "'" + ")," + 
                                        'document.getElementById(' + "'" + this.content + "'" + ")," + 
                                        'document.getElementById(' + "'" + this.Scroller + "'" + ")," + 
                                        'document.getElementById(' + "'" + this.middle + "'" + ")," 
                                        + Lastwidth + "," + 
                                        + Lastheight + "," + 
                                        + topOffset + "," + 
                                            + (currentwidth + ( i * 2)) + "," 
                                            + (currentheight + ((250 / 380) * i * 2)) + "," 
                                            + (currentopOffset - ((125 / 380) * i * 2)  ) + "," 
                                            + ( - ((0.5) * i * 2) ) + ");" , (i ));
            //setTimeout('alert(' + "'" + "hi" + "');" , (3000 * i));
        }
        //setTimeout('Scroller.updateAll()', (Lastwidth-currentwidth) * 1);
        //setTimeout('document.getElementById(' + "'" + this.middle + "'" + ".style.display = " + "'" + "block" + "');" , 300);
        //document.getElementById(this.middle).style.display = "block";
        var outer = this;
        setTimeout( function() { outer.resizeIFrame()}, (Lastwidth-currentwidth) * 1);
}


SetScrollWidth = function (ContentArea , content , inScroller , middle , Lastwidth, Lastheight, topOffset, currentwidth, currentheight , currentopOffset , leftOffset)
{
    ContentArea.style.width = Math.min(currentwidth , Lastwidth) + "px";
    ContentArea.style.height = Math.min(currentheight , Lastheight) + "px";
    content.style.height = Math.min(currentheight , Lastheight) + 'px';
    inScroller.style.height =  Math.min(currentheight , Lastheight) + 'px';
    middle.style.top = Math.max(currentopOffset , 225) + 'px' ;   
    middle.style.left = Math.max(leftOffset , - (Lastwidth / 2)) + 'px';   
}

GetscrolledX = function ()	
{
    var scrolledX;
    if( self.pageYOffset ) 
        {
            scrolledX = self.pageXOffset;
        } 
        else 
        if ( document.documentElement && document.documentElement.scrollTop ) 
            {
                scrolledX = document.documentElement.scrollLeft;
            } 
            else if
                ( document.body ) 
                    {
                        scrolledX = document.body.scrollLeft;
                    }
    return scrolledX;
}
 
 GetscrolledY = function ()	
{
    var scrolledY;
    if( self.pageYOffset ) 
        {
            scrolledY = self.pageYOffset;
        } 
        else 
        if ( document.documentElement && document.documentElement.scrollTop ) 
            {
                scrolledY = document.documentElement.scrollTop;
            } 
            else if
                ( document.body ) 
                    {
                        scrolledY = document.body.scrollTop;
                    }
    return scrolledY;
}   

GetcenterX = function ()	
{
    var centerX ;
        if( self.innerHeight ) 
            {
                centerX = self.innerWidth;
            } 
            else if( document.documentElement && document.documentElement.clientHeight ) 
                {
                    centerX = document.documentElement.clientWidth;
                } 
                else if( document.body ) 
                    {
                        centerX = document.body.clientWidth;
                    }
    return centerX;
}

GetcenterY = function ()	
{
    var centerY;
        if( self.innerHeight ) 
            {
                centerY = self.innerHeight;
            } 
            else if( document.documentElement && document.documentElement.clientHeight ) 
                {
                    centerY = document.documentElement.clientHeight;
                } 
                else if( document.body ) 
                    {
                        centerY = document.body.clientHeight;
                    }
    return centerY;
}
    
    function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

AJAXWindow.prototype.ShowCallBackError = function (t)	
    {   
        document.getElementById(this.content).innerHTML = "";
        document.getElementById(this.content).setAttribute('HasData', false);
        //Scroller.reset(this.content) ;
        //this.resizeIFrame(); 
        if (this.WithMessage == 'True')
            {
                this.ResponseBack.fire(MyAJAXMessage.MessageNOk + ': ' + t.status + ',' + t.statusText, MyAJAXMessage.CSSImgNok);          
            }
    if (this.DataFetchedSubscribed)
        {
            this.DataFetched.fire(0);
        }
    }
   
// ----- popup_mousepos --------------------------------------------------------
var popup_dragging = false;
var popup_oldfunction;
var popup_mouseposX;
var popup_mouseposY;
var popup_target;
var popup_Iframe_target;

function createResizeFullDiv()
{
    var objResizeAreaFullDiv  = document.createElement('div');
    objResizeAreaFullDiv.id = "divResizeFullScreen";  
    objResizeAreaFullDiv.name = "divResizeFullScreen";
    
    objResizeAreaFullDiv.style.width = "100%"; 
    objResizeAreaFullDiv.style.height = "100%";
    objResizeAreaFullDiv.style.position = "absolute";
    objResizeAreaFullDiv.style.opacity = "1";
    objResizeAreaFullDiv.style.border = "solid lime 0px";
    objResizeAreaFullDiv.style.top = 0;
    
    document.body.appendChild(objResizeAreaFullDiv);
    objResizeAreaFullDiv.style.cssFloat = "left";
    objResizeAreaFullDiv.style.styleFloat = "left";
}

function removeResizeFullDiv()
{
    document.body.removeChild(document.getElementById("divResizeFullScreen"));
}

AJAXDiv.prototype.setupdrag = function  (e)
{
    //criação da iframe de resize - ecran total com 1% de transparência
    if(!document.getElementById("divResizeFullScreen"))
    {
        createResizeFullDiv();
    }
    //fim da criação da iframe de resize
    
	var t = this._parent //reference dhtml window div
	var d=document.getElementById(this._ContentArea); //reference dhtml window object
	var dd = document.getElementById(this._content);
	d.etarget=this //remember div mouse is currently held down on ("handle" or "resize" div)
    var e=window.event || e
    obj = document.getElementById(this.id);
    d.initmousex=e.clientX //store x position of mouse onmousedown
	d.initmousey=e.clientY
    d.initx=parseInt(t.offsetLeft) //store offset x of window div onmousedown
	d.inity=parseInt(t.offsetTop)
    d.width=parseInt(t.offsetWidth) //store width of window div
	d.contentheight=parseInt(dd.offsetHeight) //store height of window div's content div
	document['WindowID'] = this._id;
	document['IFrameID'] = this._IFrame;
	document['IFrameType'] = this._IFrameType;
	document['Type'] = this._Type;
	document['ScrollControl'] = this._ScrollControl;
	document.onmousemove=getdistance //get distance travelled by mouse as it moves
	var setupdragContentArea = this._ContentArea;
	var setupdragcontent = this._content;

    document.onmouseup=function()
	    {
            stop(setupdragContentArea,obj)
	    }
	return false
}

function getdistance (e)
{
    var i = this['WindowID'];
    var innerIFrame = this['IFrameID']
    var innerIFrameType = this['IFrameType']
    var innerScrollControl = this['ScrollControl']
    var Type = this['Type']
    var d=document.getElementById(_vContentArea + i);
	var e=window.event || e
    var etarget=d.etarget;

	d.distancex=e.clientX-d.initmousex //horizontal distance travelled relative to starting point
	d.distancey=e.clientY-d.initmousey

	if (etarget.className=="drag-resizearea") //if target element is "handle" div
	    {
	        ContentAreaDiv = _vContentArea + i;
	        contentMenuDiv = _vcontent + i;
	        ScrollerDiv = _vScroller + i;
            ScrollerDivA = _vScroller + i + "1" ;
            ScrollerControl = innerScrollControl;
	        IFrameDiv = innerIFrame;
	        IFrameDivType = innerIFrameType;
	        IFrameType = Type;
		    resize(etarget._parent, e , ContentAreaDiv, contentMenuDiv, ScrollerDiv, ScrollerDivA , ScrollerControl , IFrameDiv, IFrameDivType , Type)
	    }    
	return false //cancel default dragging behavior
}

function resize(t, e, ContentAreaDiv, contentMenuDiv, ScrollerDiv, ScrollerDivA , ScrollerControl , IFrameDiv, IFrameType, Type)
{
    var d=document.getElementById(ContentAreaDiv);
    var dd=document.getElementById(contentMenuDiv);
    var ddd=document.getElementById(ScrollerDiv);
    var dddW=document.getElementById(ScrollerDivA);
	t.style.width=Math.max(d.width + d.distancex , 250)  +"px"
	dd.style.height=Math.max(d.contentheight+d.distancey, 10)+"px"
	dd.style.width = t.style.width.split("px")[0] - 25 + 'px';
	ddd.style.height=Math.max(d.contentheight+d.distancey, 10)+"px"
	ddd.style.width = t.style.width.split("px")[0] - 25 + 'px';
	dddW.style.height = Math.max(d.contentheight+d.distancey, 10)+"px"
    dddW.style.left = parseFloat(t.style.width.split("px")[0]) - 20 + 'px';
    if (IsIE())
    {
        var dddd = document.getElementById(IFrameDiv);
    	dddd.style.width=Math.max(d.width + d.distancex , 250)  + "px"
    	dddd.style.height=Math.max(d.contentheight+d.distancey , 10) + "px"
    }
    if (Type == "HTML")
        {
    	    var ddddd = document.getElementById(IFrameType);
            ddddd.style.width=Math.max(d.width + d.distancex - 20 , 250)  + "px"
            ddddd.style.height=Math.max(d.contentheight+d.distancey , 10) + "px"
        }
    //resetScrollbar(ScrollerDiv)
    //Scroller.updateAll();
    ScrollerControl.ResizeControl();
    ScrollerControl.ResizeControl();
}

function stop(ContentArea,obj)
{
    //se existir uma iframe de resize removêmo-la
    if(document.getElementById("divResizeFullScreen"))
    {
        removeResizeFullDiv();
    }
    //fim
	var d=document.getElementById(ContentArea);
	d.etarget=0 //clean up
    document.onmousemove=null;
    document.onmouseup=null
}

function popup_mousepos(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  popup_mouseposX = ie ? window.event.clientX : e.clientX;
  popup_mouseposY = ie ? window.event.clientY : e.clientY;
}

// ----- popup_mouseup ---------------------------------------------------------

function popup_mouseup(e)
{
    if (!popup_dragging) return;
    popup_dragging = false;

    var ie      = navigator.appName == "Microsoft Internet Explorer";
    var element = document.getElementById(popup_target);
    if (IsIE())
        {
            var elementIFrame = document.getElementById(popup_Iframe_target);
        }

    if (ie)
        document.onselectstart = popup_oldfunction;
    else document.onmousedown   = popup_oldfunction;
}

// ----- popup_mousemove -------------------------------------------------------

function popup_mousemove(e)
{
    if (!popup_dragging) return;

    var ie      = navigator.appName == "Microsoft Internet Explorer";
    var element = document.getElementById(popup_target);

    var mouseX = ie ? window.event.clientX : e.clientX;
    var mouseY = ie ? window.event.clientY : e.clientY;

    element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
    element.style.top  = (element.offsetTop +mouseY-popup_mouseY)+'px';

    if (IsIE())
        {
            var elementIFrame = document.getElementById(popup_Iframe_target);
            elementIFrame.style.left = (elementIFrame.offsetLeft+mouseX-popup_mouseX)+'px';
            elementIFrame.style.top  = (elementIFrame.offsetTop +mouseY-popup_mouseY)+'px';
        }

    popup_mouseX = ie ? window.event.clientX : e.clientX;
    popup_mouseY = ie ? window.event.clientY : e.clientY;
}

// ----- popup_mousedown -------------------------------------------------------

function popup_mousedown(e)
{
    var ie = navigator.appName == "Microsoft Internet Explorer";

    if ( ie && window.event.button != 1) return;
    if (!ie && e.button            != 0) return;

    popup_dragging = true;
    popup_target   = this[_vTarget];
    if (IsIE())
        {
            popup_Iframe_target = this[_iframeIEHack];
        }

    popup_mouseX   = ie ? window.event.clientX : e.clientX;
    popup_mouseY   = ie ? window.event.clientY : e.clientY;

    if (ie)
        popup_oldfunction      = document.onselectstart;
    else popup_oldfunction      = document.onmousedown;

    if (ie)
        document.onselectstart = new Function("return false;");
    else document.onmousedown   = new Function("return false;");
}

//var g_AjaxWindow1 =  new AJAXWindow ('ContentArea','Glosssario~Print~Save~Close', 'GetData~Print~Save~Close' , 'GlossarioTermos.aspx~http://rde.bportugal.pt/estatisticasweb/GLOSSARIOTERMOS.ASP~~' , '680px', '400px', true);
 
function ScrollControl(outer)
{    
    this.docH = 0;
    this.contH = 0;
    this.scrollAreaH = 0;
    this.scrollH = 0;
    this.scrollDist = 0;    
  
//Alterado em 26-01-2009 (RGA para corrigir problema com calendário e Ajuda)    
    if(outer.Type == "HTML")   
    {
        this.CMS_ContentText = outer.IframeIEHack + "HTML";
        this.content = outer.content;
    }
    else
    {    
        this.CMS_ContentText = outer.CMS_ContentText;
        this.content = outer.content;
    }
//fim de alteracao    
    this.Scroller1 = outer.Scroller + "1";
    this.Scroller2 = outer.Scroller + "2";
    this.outer = outer;
}

ScrollControl.prototype.DefineControl = function  ()
{ 
//Alterado em 26-01-2009 (RGA para corrigir problema com calendário e Ajuda)    
    var scrollYAnt = 0;
    var scrollTopAnt = 0;
    var localIsPDF = false;
    if ((this.outer.optionsParams.toUpperCase().indexOf(".PDF") > 0) &&
        (this.outer.optionsParams.toUpperCase().indexOf(".PDF") < this.outer.optionsParams.toUpperCase().indexOf("~~")))
        localIsPDF = true;

    if(this.outer.Type == 'HTML' && !localIsPDF)
    //if(this.outer.Type == 'HTML')
    {
        docH = document.getElementById(this.CMS_ContentText).contentWindow.document.body.scrollHeight + 20;
        contH = document.getElementById(this.CMS_ContentText).offsetHeight;        
    }
    else
    {
        docH = document.getElementById(this.CMS_ContentText).offsetHeight;
        contH = document.getElementById(this.content).offsetHeight;
    }
//fim de alteracao    

    scrollAreaH = document.getElementById(this.Scroller1).offsetHeight;     
    //calculate height of scroller and resize the scroller div
    //(however, we make sure that it isn't to small for long pages)
//Alterado em 26-01-2009 (RGA para corrigir problema com calendário e Ajuda)    
    scrollH = (contH * scrollAreaH) / docH;
    if(scrollH < 40) scrollH = 40;
//fim de alteracao    
    
    document.getElementById(this.Scroller2).style.height = Math.round(scrollH) + "px";

    //what is the effective scroll distance once the scoller's height has been taken into account
    this.scrollDist = Math.round(scrollAreaH - scrollH);

    //make the scroller div draggable
    
    Drag.init(document.getElementById(this.Scroller2),null,0,0,-1,this.scrollDist);
    
    //add ondrag function
    var innerScroller2 = this.Scroller2;
    var innerCMS_ContentText = this.CMS_ContentText;
    var innerscrollDist = this.scrollDist;
    

//Alterado em 12-12-2008 (RGA para não mostrar a scroll quando o conteúdo é menor que o espaço reservado)
    var innerAjax = this.outer;
    if(docH < contH || localIsPDF)
    {
        document.getElementById(this.Scroller1).style.visibility = "hidden";
        document.getElementById(this.Scroller2).style.visibility = "hidden";
    }

    document.getElementById(this.Scroller2).onDrag = function (x,y) 
    {
        if(innerAjax.Type == 'HTML')
        {
            this.CMS_ContentText = innerAjax.IframeIEHack + "HTML";
           
            docH = document.getElementById(this.CMS_ContentText).contentWindow.document.body.scrollHeight + 10;
            contH = document.getElementById(this.CMS_ContentText).offsetHeight; 
            var scrollY = parseInt(document.getElementById(innerScroller2).style.top);   
            var docY = (scrollY - scrollYAnt) * (docH - contH) / innerscrollDist;
           
            var scrollTop = document.getElementById(this.CMS_ContentText).contentWindow.document.body.scrollTop;
            if (scrollTop != scrollTopAnt)
            {
                document.getElementById(this.CMS_ContentText).contentWindow.document.body.scrollTop = scrollTopAnt;
                if ((scrollTop - scrollTopAnt) >= 0)
                {
                    Drag.adjust((((scrollTop - scrollTopAnt) * innerscrollDist) / (docH - contH)) + scrollYAnt);
                    scrollY = (((scrollTop - scrollTopAnt) * innerscrollDist) / (docH - contH)) + scrollYAnt;
                }
                else
                {
                    Drag.adjust((((scrollTopAnt - scrollTopAnt) * innerscrollDist) / (docH - contH)) + scrollYAnt);
                    scrollY = (((scrollTopAnt - scrollTopAnt) * innerscrollDist) / (docH - contH)) + scrollYAnt;
                }
                docY = (scrollTop - scrollTopAnt);
            }
            scrollYAnt = scrollY;
            document.getElementById(innerCMS_ContentText).contentWindow.scrollBy(0,docY);
            scrollTopAnt = document.getElementById(this.CMS_ContentText).contentWindow.document.body.scrollTop;           
        }
        else
        {
            this.CMS_ContentText = innerAjax.CMS_ContentText;
            this.content = innerAjax.content;
            docH = document.getElementById(this.CMS_ContentText).offsetHeight + 10;
            contH = document.getElementById(this.content).offsetHeight;
            var scrollY = parseInt(document.getElementById(innerScroller2).style.top);
            var docY = 0 - (scrollY * (docH - contH) / innerscrollDist);
            document.getElementById(innerCMS_ContentText).style.top = docY + "px";
        }
    }
//fim de alteracao    
}

ScrollControl.prototype.ResizeControl = function()
{    
//Alterado em 26-01-2009 (RGA para corrigir problema com calendário e Ajuda)    
    var scrollYAnt = 0;
    var scrollTopAnt = 0;    
    var localIsPDF = false;
    if ((this.outer.optionsParams.toUpperCase().indexOf(".PDF") > 0) &&
        (this.outer.optionsParams.toUpperCase().indexOf(".PDF") < this.outer.optionsParams.toUpperCase().indexOf("~~")))
        localIsPDF = true;
    if(this.outer.Type == 'HTML' && !localIsPDF)
    {
        docH = document.getElementById(this.CMS_ContentText).contentWindow.document.body.scrollHeight;
        contH = document.getElementById(this.CMS_ContentText).offsetHeight;        
    }
    else
    {
        docH = document.getElementById(this.CMS_ContentText).offsetHeight;
        contH = document.getElementById(this.content).offsetHeight;
    }
//fim de alteracao    

    scrollAreaH = document.getElementById(this.Scroller1).offsetHeight;
      
    //calculate height of scroller and resize the scroller div
    //(however, we make sure that it isn't to small for long pages)
//Alterado em 26-01-2009 (RGA para corrigir problema com calendário e Ajuda)    
    scrollH = (contH * scrollAreaH) / docH;
    if(scrollH < 40) scrollH = 40;
//fim de alteracao    

    document.getElementById(this.Scroller2).style.height = Math.round(scrollH) + "px";
    
    //what is the effective scroll distance once the scoller's height has been taken into account
    this.scrollDist = Math.round(scrollAreaH - scrollH);
    
    //make the scroller div draggable
    Drag.init(document.getElementById(this.Scroller2),null,0,0,-1,this.scrollDist);
    
    //add ondrag function
    var innerScroller2 = this.Scroller2;
    var innerCMS_ContentText = this.CMS_ContentText;
    var innerscrollDist = this.scrollDist;

//Alterado em 12-12-2008 (RGA para não mostrar a scroll quando o conteúdo é menor que o espaço reservado)
    var innerAjax = this.outer;
    if(docH < contH)
    {
        document.getElementById(this.Scroller1).style.visibility = "hidden";
        document.getElementById(this.Scroller2).style.visibility = "hidden";
    }
    else
    {
        document.getElementById(this.Scroller1).style.visibility = "visible";
        document.getElementById(this.Scroller2).style.visibility = "visible";
    }
    
    document.getElementById(this.Scroller2).onDrag = function (x,y) 
    {
      if(innerAjax.Type == 'HTML')
        {
            this.CMS_ContentText = innerAjax.IframeIEHack + "HTML";
            docH = document.getElementById(this.CMS_ContentText).contentWindow.document.body.scrollHeight + 10;
            contH = document.getElementById(this.CMS_ContentText).offsetHeight; 
            var scrollY = parseInt(document.getElementById(innerScroller2).style.top);   
            var docY = (scrollY - scrollYAnt) * (docH - contH) / innerscrollDist;

            var scrollTop = document.getElementById(this.CMS_ContentText).contentWindow.document.body.scrollTop;
            if (scrollTop != scrollTopAnt)
            {
                document.getElementById(this.CMS_ContentText).contentWindow.document.body.scrollTop = scrollTopAnt;
                if ((scrollTop - scrollTopAnt) >= 0)
                {
                    Drag.adjust((((scrollTop - scrollTopAnt) * innerscrollDist) / (docH - contH)) + scrollYAnt);
                    scrollY = (((scrollTop - scrollTopAnt) * innerscrollDist) / (docH - contH)) + scrollYAnt;
                }
                else
                {
                    Drag.adjust((((scrollTopAnt - scrollTopAnt) * innerscrollDist) / (docH - contH)) + scrollYAnt);
                    scrollY = (((scrollTopAnt - scrollTopAnt) * innerscrollDist) / (docH - contH)) + scrollYAnt;
                }
                docY = (scrollTop - scrollTopAnt);
            }
            
            scrollYAnt = scrollY;
            document.getElementById(innerCMS_ContentText).contentWindow.scrollBy(0,docY);
            scrollTopAnt = document.getElementById(this.CMS_ContentText).contentWindow.document.body.scrollTop;           
        }
        else
        {
            this.CMS_ContentText = innerAjax.CMS_ContentText;
            this.content = innerAjax.content;
            docH = document.getElementById(this.CMS_ContentText).offsetHeight + 10;
            contH = document.getElementById(this.content).offsetHeight;
            var scrollY = parseInt(document.getElementById(innerScroller2).style.top);
            var docY = 0 - (scrollY * (docH - contH) / innerscrollDist);
            document.getElementById(innerCMS_ContentText).style.top = docY + "px";
        }
    }
//fim de alteracao  
}

/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	adjust : function(ny)
	{
	    //debugger;
	    //var o = Drag.obj = this;
		//o.root = oRoot && oRoot != null ? oRoot : o ;

		//if (Drag.obj.hmode  && isNaN(parseInt(Drag.obj.root.style.left  ))) Drag.obj.root.style.left   = "0px";
		//if (Drag.obj.vmode  && isNaN(parseInt(Drag.obj.root.style.top   ))) Drag.obj.root.style.top    = "100px";
		//if (!Drag.obj.hmode && isNaN(parseInt(Drag.obj.root.style.right ))) Drag.obj.root.style.right  = "0px";
		//if (!Drag.obj.vmode && isNaN(parseInt(Drag.obj.root.style.bottom))) Drag.obj.root.style.bottom = "0px";
	
		Drag.obj.root.style["top"] = ny + "px";
		Drag.obj.root.style["bottom"] = "0px";
		document.onmousemove = null;
		document.onmouseup   = null;
		//Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
		//							parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
